Java中"代码太大"编译错误解析
1. 概述
当Java方法超过65535字节时,我们会收到“代码太大”的编译错误。本文将讨论这个错误发生的原因以及如何解决它。
2. JVM限制
Code_attribute 是JVM规范中_method_info_结构的可变长度表。这个结构包含了一个方法的JVM指令,可以是一个常规方法,也可以是一个实例、类或接口的初始化方法:
Code_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 max_stack;
u2 max_locals;
u4 code_length;
u1 code[code_length];
u2 exception_table_length;
{
u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
}
exception_table[exception_table_length];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
大约 3 分钟