Method code too large! exception using ASM

匿名 (未验证) 提交于 2019-12-03 02:31:01

问题:

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" 

回答1:

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://bitbucket.org/sperber/asm-method-size. It is based off ASM itself. Hope this helps.



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