|Contents | Prev | Next | Index
|The JavaTM Virtual Machine Specification
A Java Virtual Machine instruction consists of an opcode specifying the operation to be performed, followed by zero or more operands embodying values to be operated upon. This chapter gives details about the format of each Java Virtual Machine instruction and the operation it performs.
int." The constraints of Chapter 4 guarantee that all such expectations will in fact be met. If some constraint (a "must" or "must not") in an instruction description is not satisfied at run time, the behavior of the Java Virtual Machine is undefined.
The Sun implementation of the Java Virtual Machine checks that all untrusted Java Virtual Machine code satisfies the static and structural constraints at load time using a
class file verifier (see Section 4.9, "Verification of class Files"). Thus, Sun's Java Virtual Machine will only see valid
class files. Performing most verification at
class file load time is attractive in that the checks are performed just once, substantially reducing the amount of work that must be done at run time. Other implementation strategies are possible, provided that they comply with Chapter 12 of The Java Language Specification.
Alternatively, a naive Java Virtual Machine implementation may check static and structural constraints at run time. However, this lazier approach may have serious performance implications.
class files (see Chapter 4, "The class File Format"), three opcodes are
reserved for internal use by a Java Virtual Machine implementation. If Sun extends
the instruction set of the Java Virtual Machine in the future, these reserved opcodes
are guaranteed not to be used.
Two of the reserved opcodes, numbers 254 (0xfe) and 255 (0xff), have the mnemonics impdep1 and impdep2, respectively. These instructions are intended to provide "back doors" or traps to implementation-specific functionality implemented in software and hardware, respectively. The third reserved opcode, number 202 (0xca), has the mnemonic breakpoint and is intended to be used by debuggers to implement breakpoints.
Although these opcodes have been reserved, they may only be used inside a Java Virtual Machine implementation. They cannot appear in valid
class files. Tools such as debuggers or JIT code generators (§3.12) that might directly interact with Java Virtual Machine code that has been already loaded and executed may encounter these opcodes. Such tools should attempt to behave gracefully if they encounter any of these reserved instructions.
VirtualMachineError when an internal error or resource limitation prevents it from
implementing the semantics of the Java Language. The Java Virtual Machine specification cannot predict where resource limitations or internal errors may be encountered and does not mandate precisely when they can be reported. Thus, any of the
virtual machine errors listed as subclasses of
VirtualMachineError in §2.15.4 may be
thrown at any time during the operation of the Java Virtual Machine.
Each cell in the instruction format diagram represents a single 8-bit byte. The instruction's mnemonic is its name. Its opcode is its numeric representation and is given in both decimal and hexadecimal forms. Only the numeric representation is actually present in the Java Virtual Machine code in a
Keep in mind that there are "operands" generated at compile time and embedded within Java Virtual Machine instructions, as well as "operands" calculated at run time and supplied on the operand stack. Although they are supplied from several different areas, all these operands represent the same thing: values to be operated upon by the Java Virtual Machine instruction being executed. By implicitly taking many of its operands from its operand stack, rather than representing them explicitly in its compiled code as additional operand bytes, register numbers, etc., the Java Virtual Machine's code stays compact.
Some instructions are presented as members of a family of related instructions sharing a single description, format, and operand stack diagram. As such, a family of instructions includes several opcodes and opcode mnemonics; only the family mnemonic appears in the instruction format diagram, and a separate forms line lists all member mnemonics and opcodes. For example, the forms line for the lconst_<l> family of instructions, giving mnemonic and opcode information for the two instructions in that family (lconst_0 and lconst_1), is
|lconst_0 = 9 (0x9),
|lconst_1 = 10 (0xa)
In the description of the Java Virtual Machine instructions, the effect of an instruction's execution on the operand stack (§3.6.2) of the current frame (§3.6) is represented textually, with the stack growing from left to right and each word (§3.4) represented separately. Thus,
|..., value1, value2
shows an operation that begins by having a one-word value2 on top of the operand stack with a one-word value1 just beneath it. As a result of the execution of the instruction, value1 and value2 are popped from the operand stack and replaced by a one-word result, which has been calculated by the instruction. The remainder of the operand stack, represented by an ellipsis (...), is unaffected by the instruction's execution.
double take two words on the operand stack. In the operand stack representation, each word is represented separately using a dot notation:
|..., value1.word1, value1.word2, value2.word1, value2.word2
|..., result.word1, result.word2
The Java Virtual Machine specification does not mandate how the two words are
used to represent the 64-bit
double value; it only requires that a particular
implementation be internally consistent.
Contents | Prev | Next | Index
Java Virtual Machine Specification
Copyright © 1996, 1997 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to [email protected]