10

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?

Victor Grazi
  • 15,563
  • 14
  • 61
  • 94

2 Answers2

14

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.

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
2

Dump the contents of the files with the javap command to see if anything obvious stands out. There might be some extra attributes in Java 6 class files.

James
  • 9,064
  • 3
  • 31
  • 49