java中方法的最大大小? [英] Maximum size of a method in java?
问题描述
我知道java中方法的最大大小是64k。如果它超过,我们将得到一个编译器警告,如代码太大而无法编译。所以我们可以用这么少的内存来称之为java的缺点。
I come to know that the maximum size of a method in java is 64k. And if it exceeds, we'll get a compiler warning like "Code too large to compile". So can we call this a drawback of java with this small amount of memory.
我们可以增加这个大小限制还是真的可以增加?
Can we increase this size limit or is it really possible to increase ?
关于此方法大小的更多想法?
Any more idea regarding this method size ?
推荐答案
根据我的经验,64KB限制只是生成代码的一个问题。 ESP。在对大型数组进行实体化时(在代码中完成)
In my experience the 64KB limit is only a problem for generated code. esp. when intiialising large arrays (which is done in code)
在结构良好的代码中,每个方法都是可管理的长度,并且远小于此限制。可以从非Java文件(如文本或二进制文件)中读取要加载到数组中的大量数据。
In well structured code, each method is a manageable length and is much smaller than this limit. Large pieces of data, to be loaded into arrays, can be read from a non Java files like a text or binary file.
编辑:
JIT不会编译大于8 K的方法,这是值得的。这意味着代码运行速度较慢并且可能影响GC时间(因为搜索调用堆栈的效率较低)使用非编译方法的线程esp big)
It is worth nothing that the JIT won't compile methods larger than 8 K. This means the code runs slower and can impact the GC times (as it is less efficient to search the call stack of a thread with methods which are not compiled esp big ones)
如果可能,您希望将方法限制为8 K而不是64 K.
If possible you want to limit your methods to 8 K rather than 64 K.
这篇关于java中方法的最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!