Maximum size of a method in Java 7 and 8

前端 未结 5 1743
情歌与酒
情歌与酒 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 04:59

    According to JVMS7 :

    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.

    But this is about Java 7. There is no final specs for Java 8, so nobody (except its developers) could answer this question.

    UPD (2015-04-06) According to JVM8 it is also true for Java 8.

提交回复
热议问题