为什么Java 6编译的类大小大于Java 5?

我们注意到,当我们在
Java 6上编译我们的类时,它们始终大于Java 5.

我明白到目前为止,字节码没有改变,所以我认为Java 6编译器正在投入更多的东西.这是否需要,还是有什么办法把它关闭,仍然编译Java 6源代码?

解决方法

版本6 javac正在类文件中生成额外的“Stack Map”属性,以使jvm的验证更容易,更快.我怀疑这个数量太大了,你可以通过使用-target 1.5选项来生成与之前版本相同的字节码.

编辑:有关此新属性的详细信息,请参见jsr 202的4.8.4节

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.

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。