As I understand it, the JVM has a limit of 64KB of compiled code per method. I have a tool which generates Java code to be run, and sometimes the generated code contains methods which are longer than this.
Does there exist an automated way of transforming a Java class file with overly long methods into one which produces the same results but which can be compiled?
In a simple example, the following code:
public void longMethod
{
doSomething1();
doSomething2();
/* snip */
doSomething20000();
}
might be transformed into:
public void longMethod
{
longMethod_part1();
longMethod_part2();
/* snip */
longMethod_part10();
}
public void longMethod_part1()
{
doSomething1();
/* snip */
doSomething1000();
}
/* snip */
public void longMethod_part10()
{
doSomething9001();
/* snip */
doSomething10000();
}
However, there are complications, e.g. the long method might be an extremely long if
/else if
chain. A best-efforts tool would be of interest even if the general case is too difficult.
EDIT: Several kind and well-meaning people have suggested fixing the tool which generates these long methods. While this is an excellent idea, it is not one I can take advantage of. I would still welcome any ideas for the general problem I pose above.