6.1 How the Verification Algorithm Works

Section 4.8 of The Java Virtual Machine Specification contains a large set of rules that programs must follow if they want to run in the machine. It is the job of the verification algorithm to prove that each and every one of these rules has been followed. These rules were designed to be verifiable by just examining each class, without resorting to running the class.

The verification algorithm works by asking a set of questions about the class file. These questions fall into five general categories.

  1. Is it a structurally valid class file?

  2. Are all constant references correct?

  3. Are the instructions valid?

  4. Will the stack and local variables always contain values of the appropriate types?

  5. Do the classes used really exist, and do they have the necessary methods and fields?

These questions can be answered statically, that is, from looking at the bytecodes without executing the program. This enables the virtual machine to stop a badly behaving program before it starts. It also permits faster execution, because the virtual machine doesn't have to check some kinds of errors as the program runs. If the program has passed verification, then these errors cannot occur.

Programming for the Java Virtual Machine
Programming for the Javaв„ў Virtual Machine
ISBN: 0201309726
EAN: 2147483647
Year: 1998
Pages: 158
Authors: Joshua Engel

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net