我们注意到,当我们在 Java 6 上编译我们的类时,它们总是比 Java 5 大。
我知道到目前为止字节码没有变化,所以我假设 Java 6 编译器加入了更多内容。这是所有必需的,还是有任何方法可以关闭它并仍然编译 Java 6 源代码?
最佳答案
版本 6 javac 正在类文件中生成额外的“堆栈映射”属性,以使 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.
关于java - 为什么 Java 6 编译的类大小大于 Java 5?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5637118/