Re: [BCEL-info]setting of maxstack in helloify.java
Brought to you by:
dahm
|
From: Enver H. <eh...@in...> - 2002-07-29 16:55:53
|
On Sat, 27 Jul 2002, Aarti Thorat wrote: > > Hence i changed it to 2 * no of times method call inserted, it worked > fine. But the lower limit for which the classfile works fine is 3. > > I am a little confused, as to what exactly the max stack depends on, the > number of arguments taken by the method or the code length of the method. > Can any one please throw some light on this issue ? The JVM works stack-based, i.e. many instructions auch as IADD expect arguments on the stack and/or put arguments on the stack. MaxStack is all about the argument stack; arguments meaning arguments to the instructions, not the method parameters! This is the stack size in question here. For example, IADD does push(pop() + pop()); Usually, one would implement "2+3+4" as iconst_2 ; push "2" onto stack iconst_3 iadd iconst_4 iadd You have at most two stack slots used here (an int uses one slot); so maxStack = 2. but you could also iconst_2 iconst_3 iconst_4 iadd iadd Here, there are three stack slots used at one time, so maxStack = 3. Hope the example helps. If unsure, just increase the maxStack. The calculation in Method.java also sometimes is a little off, better add some slots to be on the safe side. Enver |