Maximum size of a method in Java 7 and 8

前端 未结 5 1740
情歌与酒
情歌与酒 2020-11-27 04:27

I know that a method cannot be larger than 64 KB with Java. The limitation causes us problems with generated code from a JavaCC grammar. We had problems with Java 6 and

5条回答
  •  情话喂你
    2020-11-27 05:23

    Andremoniy has answered the java 7 part of this question already, but seems at that time it was soon to decide about java 8 so I complete the answer to cover that part:

    Quoting from jvms:

    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.

    As you see seems this historical problem doesn't seem to remedy at least in this version (java 8).

提交回复
热议问题