next up previous contents
Next: The Instruction Set Up: The JVM Instruction Previous: The JVM Instruction

Typed Instructions

Most of the JVM instructions operate on one specific type. Almost all those instructions have the type they operate on encoded in their name:

For example, the instructions used to add two values of type int, long, double or float, are respectively iadd, ladd, dadd and fadd.

There is no JVM instruction that operates on type boolean. All variables of type boolean use the int data type, and therefore also the int instructions. The newarray instruction that is used to create arrays of some kind, can create arrays of type boolean, but there are no instructions to access or modify elements of boolean arrays. Instead instructions that operate on type byte are used.

There are also not many instructions for types byte, char and short. For writing to local variables and operand stacks, values of types byte and short are sign-extended internally to type int and values of type char are zero-extended to type int. This means most of the operations on values of these types are performed by instructions operating on type int.

All JVM instructions have an opcode size of one byte and so do all the operands. Remember that values of type long or double take up two positions on the operand stack (i.e. value.word1, value.word2).

If an entry in the constant_pool[] has an index that can not be contained in one byte, it has a wide index. Because the size of an operand is only one byte, the index is divided into two operands when an instruction needs this index as its operand. From these operands ( indexbyte1 and indexbyte2) the index can be reconstructed by the formula ( indexbyte1 8)| indexbyte2.

For branching instructions, the same formula is used to construct the signed 16-bit offset out of the operands branchbyte1 and branchbyte2. If the offset is a wide offset, a signed 32-bit offset, it is constructed out of the operands branchbyte1, branchbyte2, branchbyte3 and branchbyte4 by the formula ( branchbyte4 24)|( branchbyte3 16)|( branchbyte2 8)| branchbyte1.

When the index of local variables in the local variable table is a wide index, the wide instruction is used to let an instruction that normally has a one-byte index as its operand have a wide index as its operands. The wide instruction is discussed in subsection 4.2.9.



next up previous contents
Next: The Instruction Set Up: The JVM Instruction Previous: The JVM Instruction



mark@bottom.xs4all.nl