How to circumvent the “Method too large” error in Java Compilation?

一世执手 提交于 2020-06-23 06:58:06

问题


I have a parser written in bigloo scheme functional language which I need to compile into a java class. The whole of the parser is written as a single function. Unfortunately this is causing the JVM compiler to throw a "Method too large" warning and later give "far label in localvar" error. Is there any possible way where I can circumvent this error? I read somewhere about a DontCompileHugeMethods option, does it work? Splitting the function doesnt seem to be a viable option to me :( !!


回答1:


Is there any possible way where I can circumvent this error?

Well, the root cause of this compiler error is that there are hard limits in the format of bytecode files. In this case, the problem is that a single method can consist of at most 65536 bytes of bytecodes. (See the JVM spec).

The only workaround is to split the method.




回答2:


Split the method in related operations or splitting utilities separately.




回答3:


Well, the case is a bit different here, the method only consists of a single function call. Now this function has a huge parameter list(the whole of the parser actually!!). So I have no clues how to split this!!

The way to split up such a beast could be:

  • define data holder objects for your parameters (put sets of parameters in objects according to the ontology of your data model),
  • build those data holder objects in their own context
  • pass the parameter objects to the function



回答4:


Quick and Dirty: Assign all your parameters to class variables of the same name (you must rename your parameters) at the beginning of your function and start chopping up your function in pieces and put those pieces in functions. This should guarantee that your function will basically operate with the same semantics.

But, this will not lead to pretty code!



来源:https://stackoverflow.com/questions/3192896/how-to-circumvent-the-method-too-large-error-in-java-compilation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!