Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method code too large! exception using ASM

I am iterating over one class using ASM code without manipulating any byte code. But when I am converting classwriter to bytearray(cw.toByteArray()), I am getting Method code too large! exception.

Can anybody tell me when does this happen ..

My code snippet is as follows ---

InputStream in= new FileInputStream("D:/AshiqWorkspace/RandD/ByteCodeStudy/temp/GameManager.class");
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS|ClassWriter.COMPUTE_FRAMES);
ClassVisitor ca = null;
ca = new CustomClassNode(cw);  // CustomClassNode class extends ClassNode implements Opcodes
cr.accept(ca, 0);   
File outputDir=new File("D:/AshiqWorkspace/RandD/ByteCodeStudy/out");
outputDir.mkdirs();
DataOutputStream dout=new DataOutputStream(new FileOutputStream(new File(outputDir,"GameManager.class")));
dout.write(cw.toByteArray()); // on this line "method code too large exception coming"
like image 459
Ashiq Sayyad Avatar asked Sep 18 '13 10:09

Ashiq Sayyad


1 Answers

Certain methods in Java are already quite large, and instrumenting them increases their size further causing the exception that you observe. If i am not wrong the JVM imposes a size of 65535 bytes on the size of any method.

One solution/project that tries to overcome this problem looks at splitting the offending methods ... here is the link to its git repository: https://github.com/ThexXTURBOXx/asm-method-size. It is based off ASM itself. Hope this helps.

like image 109
vijay Avatar answered Oct 03 '22 18:10

vijay