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

标签 java class bytecode javac

我们注意到,当我们在 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/

相关文章:

javascript - 当 `new constructor()` 与 mocha 和 chai 时,我如何断言抛出

java - Java 中的静态类有什么用?

java - 查找 Java 方法的字节码大小

使用操作数堆栈和局部变量可视化进行 Java 字节代码调试?

class - JVM 如何决定一个类 “belongs”(例如内部类或嵌套类)是否属于另一个类?

java - Jruby "RuntimeHelpers"类已弃用

java - 我们可以在 android 上运行 opencv java 吗?

java - 是否存在 Objective-Java 集成库?

java - 如果它的参数称为尾递归,是否有一个方法调用?

java - 自定义 Java 类加载器未用于加载依赖项?