Java 7 和 8 中方法的最大大小 [英] Maximum size of a method in Java 7 and 8

查看:20
本文介绍了Java 7 和 8 中方法的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用 Java 的方法不能大于 64 KB.该限制导致我们从 JavaCC 语法生成代码的问题.我们在 Java 6 中遇到了问题,并且能够通过更改语法来解决这个问题.Java 7 的限制是否已更改,还是计划用于 Java 8?

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 were able to fix this by changing the grammar. Has the limit been changed for Java 7 or is it planned for Java 8?

只是为了说清楚.我自己不需要大于 64 KB 的方法.但是我写了一个语法,它编译成一个非常大的方法.

Just to make it clear. I don't need a method larger than 64 KB by myself. But I wrote a grammar which compiles to a very large method.

推荐答案

根据 JVMS7 :

end_pc 是独占的这一事实是Java虚拟机的设计:如果Java虚拟机代码因为一个方法的长度正好是 65535 字节,并以一条指令结束即 1 个字节长,则该指令不能由异常处理程序.编译器编写者可以通过以下方式解决此错误限制生成的 Java 虚拟机代码的最大大小对于任何方法、实例初始化方法或静态初始化程序(任何代码数组的大小)到 65534 字节.

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.

但这是关于 Java 7.Java 8 没有最终规范,所以没有人(除了开发人员)可以回答这个问题.

UPD (2015-04-06) 根据 JVM8 对于 Java 8 也是如此.

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

这篇关于Java 7 和 8 中方法的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆