java.lang.VerifyError: Expecting a stackmap frame occuring with ASM generated byte code

自闭症网瘾萝莉.ら 提交于 2019-12-11 00:34:00

问题


I generated java byte code in main.class as follows using ASM 5.0.

Here is the code I've generated:

javap -c _main.class output

  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

but when executing,

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

I know that branch operations must not change stack size whether the condition is satisfied.

But in the line 35 the if_icmpeq operation just jumps to the next operation, so it won't affect the stack.

I am using Java 1.6. Can anybody give a detailed explanation about the instruction verification rule or where to find the documents.

Thanks a lot.


回答1:


I solved my problem.

When the load/store instructions have TypeCast issues, the ASM can't generate corrent stackmap frame.

So next time you see there's a message

java.lang.VerifyError: Expecting a stackmap frame at branch target 45

check the types of load/store instructions.



来源:https://stackoverflow.com/questions/32904113/java-lang-verifyerror-expecting-a-stackmap-frame-occuring-with-asm-generated-by

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