我使用ASM 5.0生成了main.class
中的java字节代码,如下所示。
以下是我生成的代码:
javap -c _main.class
输出
public jcalc.lang.CalcObject call();
Code:
0: ldc #9 // String _main/max
2: invokestatic #28 // Method jcalc/lang/Binding.getBindingFromMain:(Ljava/lang/String;)Ljcalc/lang/Binding;
5: ldc #20 // String A
7: invokevirtual #38 // Method jcalc/lang/Binding.refVariable:(Ljava/lang/String;)Ljcalc/lang/CalcObject;
10: checkcast #40 // class jcalc/lang/CalcNumber
13: ldc #9 // String _main/max
15: invokestatic #28 // Method jcalc/lang/Binding.getBindingFromMain:(Ljava/lang/String;)Ljcalc/lang/Binding;
18: ldc #22 // String B
20: invokevirtual #38 // Method jcalc/lang/Binding.refVariable:(Ljava/lang/String;)Ljcalc/lang/CalcObject;
23: checkcast #40 // class jcalc/lang/CalcNumber
26: invokevirtual #44 // Method jcalc/lang/CalcNumber.operatorGreaterThan:(Ljcalc/lang/CalcNumber;)Ljcalc/lang/CalcBoolean;
29: dup
30: astore_3
31: instanceof #46 // class jcalc/lang/CalcBoolean
34: iconst_0
35: if_icmpeq 38
38: aload_3
39: invokevirtual #52 // Method jcalc/lang/CalcObject.isNonNull:()I
42: istore_2
43: aload_3
44: if_icmpeq 61
47: ldc #9 // String _main/max
49: invokestatic #28 // Method jcalc/lang/Binding.getBindingFromMain:(Ljava/lang/String;)Ljcalc/lang/Binding;
52: ldc #20 // String A
54: invokevirtual #38 // Method jcalc/lang/Binding.refVariable:(Ljava/lang/String;)Ljcalc/lang/CalcObject;
57: astore_1
58: goto 72
61: ldc #9 // String _main/max
63: invokestatic #28 // Method jcalc/lang/Binding.getBindingFromMain:(Ljava/lang/String;)Ljcalc/lang/Binding;
66: ldc #22 // String B
68: invokevirtual #38 // Method jcalc/lang/Binding.refVariable:(Ljava/lang/String;)Ljcalc/lang/CalcObject;
71: astore_1
72: aload_1
73: areturn
但执行时,
Caused by: java.lang.VerifyError: Expecting a stackmap frame at branch target 38
Exception Details:
Location:
_main/max.call()Ljcalc/lang/CalcObject; @35: if_icmpeq
Reason:
Expected stackmap frame at this location.
Bytecode:
0x0000000: 1209 b800 1c12 14b6 0026 c000 2812 09b8
0x0000010: 001c 1216 b600 26c0 0028 b600 2c59 4ec1
0x0000020: 002e 039f 0003 2db6 0034 3d2d 9f00 1112
0x0000030: 09b8 001c 1214 b600 264c a700 0e12 09b8
0x0000040: 001c 1216 b600 264c 2bb0
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at jcalc.lang.Binding.defineFunction(Binding.java:87)
at _main.call(Unknown Source)
... 7 more
我知道无论条件是否满足,分支操作都不能改变堆栈大小。
但是在第35行中if_icmpeq
操作只是跳转到下一个操作,所以它不会影响堆栈。
我正在使用Java 1.6。 任何人都可以详细解释说明验证规则或在哪里找到文件。
非常感谢。
答案 0 :(得分:3)
我解决了我的问题。
当加载/存储指令出现TypeCast问题时,ASM无法生成相应的stackmap帧。
所以下次你看到有消息
java.lang.VerifyError:期望分支目标45处的堆栈图帧
检查加载/存储指令的类型。