| A Pietu Pohjalainen 2005-07-24, 8:59 pm |
| Scott Nicol <snicol@apk.net> wrote:
> I haven't used CUP/LEX, but I'm quite familiar with the "code too
> large" error in Java. Java has a limit of 64k code per method (you,
> like I, might be wondering what was being smoked when that decision
> was made).
This 64k code per method limit seems really accidental. In Java class
files, the actualy bytecode is stored in an attribute named 'Code'. This
attribute has a specified structure, as defined in JVM spec § 4.7.3,
which is as follows:
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];
}
So, in the attribute structure, there is four bytes allocated for the
length of the actual content (code_length). However, there is another
constraint at JVM spec § 4.8.1, which states that "The value of the
code_length item must be less than 65536."
If the specification was internally coherent, the type of code_length
would be u2, wouldn't it? With this structure, there's a huge
unnecessary overhead of two bytes per method in the class file. ;)
br,
Pietu Pohjalainen
|