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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With