VerifyError: Stack size too large (what does it mean?)

拥有回忆 提交于 2019-12-11 00:02:04

问题


I'm fairly new to Java bytecode. I'm using BCEL to generate bytecode, but I get an error message when I try to use the generated code. (In hindsight, it looks like ObjectWeb ASM is more advanced and more commonly used than BCEL.)

Here is the error message:

Exception in thread "main" java.lang.VerifyError: 
(class: cb/io/FileDescriptor, method: set 
 signature: (I)J) 
Stack size too large

Here is the method:

// Method descriptor #4 (I)J
// Stack: 0, Locals: 1
private static long set(int arg1);
  0  lconst_0
  1  lreturn
    Local variable table:
      [pc: 0, pc: 2] local: arg1 index: 0 type: int

From what I understand, the local variable table is correct because it matches the input parameter. I haven't added a 'this' variable because the method is static.

If I'm not mistaken, lconst_0 loads a long value of 0 onto the stack, and lreturn consumes that value and returns it.

What am I doing wrong? Is there enough information here to tell?

Thanks!


回答1:


Your have to declare the maximum stack size you use for every Java method. ASM for example can calculate the values automatically, which saves you a lot of trouble. The maximum stack size is the absolute maximum amount of slots you use in the method (at once, not accumulated). The calculations can get very tricky when doing branching.

You're loading a long value here, longs consume 2 stack slots (in fact, every 64 bit value (except pointers) consume 2 stack slots), so you have to set a maximum stack size of 2 here.

The Stack size too large just tells you that your method consumes more stack slots as are specified in the method descriptor.



来源:https://stackoverflow.com/questions/15270807/verifyerror-stack-size-too-large-what-does-it-mean

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