Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Java 6 compiled class size larger than Java 5?

We are noticing that when we compile our classes on Java 6, they are consistently larger than Java 5.

I understand that there has not been a change to the byte code to date, so I assume the Java 6 compiler is throwing in more stuff. Is that all required, or is there any way to turn that off and still compile Java 6 source code?

like image 239
Victor Grazi Avatar asked Apr 12 '11 14:04

Victor Grazi


1 Answers

The version 6 javac is generating additional "Stack Map" attributes in the class files to make verification by the jvm easier and faster. I doubt this amounts too much size difference, you could alway use the -target 1.5 option to make it generate the same bytecode as earlier in versions.

Edit: Details on this new attribute can be found in section 4.8.4 of jsr 202

4.8.4 The StackMapTable Attribute

The stack map attribute is a variable-length attribute in the attributes table of a Code attribute. The name of the attribute is StackMapTable. This attribute is used during the process of verification by typechecking (§4.11.1).

A stack map attribute consists of zero or more stack map frames. Each stack map frame specifies (either explicitly or implicitly) a bytecode offset, the verification types (§4.11.1) for the local variables, and the verification types for the operand stack.

like image 161
Jörn Horstmann Avatar answered Sep 28 '22 07:09

Jörn Horstmann