Maximum size of a method in 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 ?


In my experience the 64KB limit is only a problem for generated code. esp. when intiialising large arrays (which is done in code)

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.

EDIT:

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)

If possible you want to limit your methods to 8 K rather than 64 K.


64k is quite a lot, if you exceed it you may think about reorganizing you code.

In my project I met this constraint once in generated sources. Solved by just splitting one method to several.


If your method is longer than 50 lines including inside comments - split it. In this case you will never reach any limitation (even if one exists).

I personally saw 1000 lines long methods (written by criminals that call themselves programmers :) ) but did not see such kind of limitation.