我正在使用 ASM 代码迭代一个类,而无需操作任何字节代码。 但是当我将 classwriter 转换为 bytearray(cw.toByteArray()) 时,我得到 方法代码太大!异常。
谁能告诉我这是什么时候发生的..
我的代码片段如下---
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 字节的大小。
一个试图克服这个问题的解决方案/项目着眼于拆分有问题的方法……这里是它的 git 存储库的链接:https://github.com/ThexXTURBOXx/asm-method-size .它基于 ASM 本身。希望这会有所帮助。
关于java - 方法代码太大!使用 ASM 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18870226/