方法代码太大!使用ASM的异常 [英] Method code too large! exception using ASM

查看:41
本文介绍了方法代码太大!使用ASM的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASM代码遍历一个类,而无需处理任何字节代码.但是当我将类编写器转换为bytearray(cw.toByteArray())时,我得到了方法代码太大!

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"

推荐答案

Java中的某些方法已经相当大,对其进行检测会增加其大小,从而进一步引起您所观察到的异常.如果我没记错的话,JVM会在任何方法的大小上施加65535字节的大小.

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.

一个试图解决此问题的解决方案/项目着眼于拆分有问题的方法...这是其git存储库的链接:

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.

这篇关于方法代码太大!使用ASM的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆