JVM misconceptions (Re: [Mono-list] Re: can you explain what you mean?)

Rhys Weatherley rweather@zip.com.au
Mon, 16 Jul 2001 09:10:02 +1000

Miguel de Icaza wrote:

> I tried looking those up in google, on the Java VM spec from Sun, and
> being imaginative and I can not find anything.  Maybe you can point me
> to these?

"Java Virtual Machine Specification, Second Editon", page 133 and
following.  Contains a large number of conditions that must be
satisfied for bytecode to be considered legal.  e.g. "iload 5" is only
legal if there are 6 or more locals AND local 5 contains a value
compatible with "int".  In the case of your example code, the
relevant paragraph is:

     If an instruction can be executed along several different
     execution paths, the operand stack must have the same
     depth prior to the execution of the instruction, regardless
     of the path taken.

Because your first loop adds extra values to the stack on each
iteration, it breaks this constraint.  i.e. the stack has different
depths at the start of each loop iteration.  The bytecode verifier
will reject your example.

In addition, all methods have a maximum stack height that cannot
be exceeded.  Your example also infringes this because it is
impossible to statically determine how many values will be
pushed or popped.

> > These restrictions don't sound any different from what the JVM
> > imposes and documents.  In fact, I suspect that Microsoft based
> > their VM on the Java VM and simply adopted the restrictions that the
> > JVM already imposes.
> I have been unable to track down any restrictions on the JVM of this
> kind.  Please, give me a link.

I've cited the paper copy above, but the book should be somewhere
http://java.sun.com for download.