Regarding the ability to catch exceptions on final instruction with exclusive end_pc
Robert Grosse
n210241048576 at gmail.com
Tue Jan 13 06:27:26 UTC 2015
The JVM specification says
The fact that end_pc is exclusive is a historical mistake in the design of
the Java
Virtual Machine: if the Java Virtual Machine code for a method is exactly
65535 bytes
long and ends with an instruction that is 1 byte long, then that
instruction cannot be
protected by an exception handler. A compiler writer can work around this
bug by
limiting the maximum size of the generated Java Virtual Machine code for
any method,
instance initialization method, or static initializer (the size of any code
array) to 65534
bytes.
However, code_length is actually limited to 65535, which means the final
instruction is at index 65534 and can be covered by an exception handler
with no problems. To confirm this, I tested it myself. A method with 65536
bytes of bytecode is rejected. A method with exactly 65535 bytes of
bytecode ending in a one byte athrow instruction still successfully catches
the thrown exception with an exception handler where end_pc=65535.
Does anyone know why the specification says this? What is going on?
More information about the hotspot-dev
mailing list