Control transfer instructions

Jumps take a virtual address of the instruction to jump to. Compares content of top of stack with some value. Several kinds are available:

  • conditional compares to zero
  • conditional compare to null
  • compare top two elements on the stack
  • unconditional transfer

Stack manipulation

dup, swap, and pop are some self-explanatory instruction examples.

Method invocation

Each method invocation causes a new frame to be created. Local variables are copied into a “local variable” array.

Object Instantiation

Call new with the name of the class. Then call dup to duplicate the reference on top of the stack, since one reference will be consumed in the call to init. This happens when the method invocation invokespecial is called, for example.

JVM verification

It verifies the source code via type-checking. Typical errors:

  • “falling off the end of the code” - missing return statement
  • “unequal stack sizes” problem is that there is branching code where the alt paths have diff effects on the stack. Likely caused by if and while statements.

Tools

  • javap is a CLI tool for parsing class files.
  • Eclipse has a byte-code viewer.