게시물의 맨 아래에 테스트 케이스가 있습니다. 다음과 같은 오류가 발생합니다. 그러나 나는 new ClassWriter(ClassWriter.COMPUTE_MAXS)
을 자동으로 최대 스택을 계산하고 올바르게 설정하지 않아야한다고 설정 했습니까?ASM COMPUTE_MAXS가 기본 테스트 케이스에서 작동하지 않습니까?
Exception in thread "main" java.lang.RuntimeException: Error at instruction 2: Insufficient maximum stack size. testMethod()Ljava/lang/Object;
00000 : : L0
00001 : : LINENUMBER 22 L0
00002 : : ACONST_NULL
00003 ? : ARETURN
테스트 케이스 :
public static void main(String[] args) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
CheckClassAdapter cv = new CheckClassAdapter(cw);
cv.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "path/Cls", null, "java/lang/Object", null);
{
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(RETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "L" + "path/Cls" + ";", null, l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
MethodVisitor mv = cv
.visitMethod(ACC_PUBLIC + ACC_STATIC, "testMethod", "()Ljava/lang/Object;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(22, l0);
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0); // Same error even if this is commented out
mv.visitEnd();
}
byte[] byteArray = cw.toByteArray();
}