Maximum size of a method in Java 7 and 8

前端 未结 5 1742
情歌与酒
情歌与酒 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:03

    It has not changed. The limit of code in methods is still 64 KB in both Java 7 and Java 8.

    References:

    1. From the Java 7 Virtual Machine Specification (4.9.1 Static Constraints):

    The static constraints on the Java Virtual Machine code in a class file specify how Java Virtual Machine instructions must be laid out in the code array and what the operands of individual instructions must be.

    The static constraints on the instructions in the code array are as follows:

    • The code array must not be empty, so the code_length item cannot have the value 0.
    • The value of the code_length item must be less than 65536.
    1. From the Java 8 Virtual Machine Specification (4.7.3 The Code Attribute):

    The value of the code_length item gives the number of bytes in the code array for this method.

    The value of code_length must be greater than zero (as the code array must not be empty) and less than 65536.

提交回复
热议问题