1997 The McGraw-Hill Companies, Inc. All rights reserved. Any use of this Beta Book is subject to the rules stated in the Terms of Use. |
Appendix A lists Java Virtual Machine instructions in alphabetical order by opcode mnemonic. All 201 instructions that may legally appear in the bytecode streams stored in Java class files are described in detail in Appendix A.
Besides the opcodes for the 201 instructions that may appear in class files, the Java Virtual Machine specification describes two other families of opcodes: the reserved opcodes and the " _quick " opcodes. None of these opcodes can legally appear in the bytecode streams of Java class files.
The Java Virtual Machine specification lists three reserved opcodes, which are shown in Table A-1. These opcodes are reserved for internal use by Java Virtual Machine implementations and tools. The specification guarantees that these three opcodes will not be part of any future extension of the Java Virtual Machine s instruction set. As you may have guessed, the intended purpose of the breakpoint opcode is to provide a way for debuggers to implement breakpoints. The intended purpose of the other two reserved opcodes, impdep1 and impdep2 , is to serve as "back doors" to implementation-dependent software functionality or "traps" to implementation-dependent hardware functionality.
Table A-1. The reserved opcodes
mnemonic | byte value |
breakpoint | 202 (0xca) |
impdep1 | 254 (0xfe) |
impdep2 | 255 (0xff) |
The Java Virtual Machine specification also lists 25 " _quick " opcodes, which Sun s virtual machine implementation uses internally to speed up the interpreted execution of bytecodes. This optimization technique is described in general in this book in Chapter 8, "The Linking Model," but the individual " _quick " instructions are not described in detail in Appendix A. (The " _quick " opcodes do appear in Appendix C, which lists their mnemonics and corresponding opcode byte values.) Like the reserved opcodes, the " _quick " opcodes may not legally appear in Java class files. But unlike the reserved opcodes, the Java Virtual Machine specification leaves open the possibility that these opcodes will take on new meanings in future extensions of the instruction set.
For each instruction listed in Appendix A, you will find the following information:
The format of each instruction appears as a list of comma-separated items next to the label "Instruction Format," with each item representing one byte in the bytecode stream. The opcode mnemonic appears first (in fixed-width font), followed by any operands (shown in italics).
For each instruction, Appendix A shows two snapshots of the operand stack. One snapshot, labelled "Before," shows the contents of the current method s operand stack just before the instruction is executed. The other snapshot, labelled "After," shows the operand stack immediately after execution of the instruction. In both snapshots, the operand stack appears as a list of comma-separated items, with each item representing one word. Although everywhere else in this book the operand stack is shown growing downwards (the top of the stack appears at the bottom of the picture), in Appendix A the operand stack is shown growing sideways , from left to right. In each snapshot, the top of the stack is the rightmost item shown. Unaffected portions of the operand stack are shown as an elipsis, "...".
For each instruction, the section labelled "Description" combines three kinds of information: constraints, the process of execution, and exceptions and errors. As mentioned in Chapter 3, "Security," Java Virtual Machine implementations are required to enforce at run-time certain constraints on the bytecodes of every method they execute. Whenever you see the word "must" in an instruction s description in Appendix A, you are reading about a constraint every implementation must enforce when executing the instruction. For example, the goto instruction, which causes an unconditional jump, may only cause a jump to another opcode of the same method. In Appendix A s description for goto , this constraint is stated as, "The target address must be the address of an opcode within the same method as the goto opcode."
The designers of each individual Java Virtual Machine implementation can decide how and when to detect violations of the bytecode constraints. If any implementation detects a constraint violation, it must report the violation by throwing a VerifyError when (and if) the running program attempts to execute the instruction.
In addition to describing the constraints placed on each instruction, Appendix A describes the process of executing each instruction and lists any errors or exceptions that may be thrown during the course of executing the instruction. Besides the errors and exceptions explicitly listed in the instruction descriptions, one other family of errors, subclasses of VirtualMachineError , can be thrown at any time as the result of executing any instruction. Four subclasses of VirtualMachineError , and the circumstances under which they will be thrown, are:
Before: ..., arrayref, index
After: ..., value
To execute the iaload instruction, the Java Virtual Machine first pops two words from the operand stack. The arrayref word must be a reference that refers to an array of reference s. The index word must be an int . The virtual machine retrieves from the arrayref array the reference value specified by index and pushes it onto the operand stack.
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the aaload instruction, see Chapter 15, "Objects and Arrays."
Before: ..., arrayref, index, value
After: ...
To execute the aaload instruction, the Java Virtual Machine first pops three words from the operand stack. The arrayref word must be a reference that refers to an array of float s. The index word must be an int , and the value word must be a reference . The type of value must be assignment compatible with the component type of the arrayref array. The virtual machine stores reference value into the arrayref array location specified by index .
If arrayref is null , the Java Virtual Machine throws NullPointerException . Else, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException . Otherwise, if the actual type of value is not assignment compatible with the actual type of the components of the arrayref array, the virtual machine throws ArrayStoreException .
For more information about the aastore instruction, see Chapter 15, "Objects and Arrays."
Before: ...
After: ..., null
To execute the aconst_null instruction, the Java Virtual Machine pushes a null object reference onto the operand stack. (Note that the Java Virtual Machine specification does not dictate any actual value for null . The specification leaves that decision to the designers of each individual implementation.)
For more information about the aconst_null instruction, see Chapter 10, "Stack Operations."
Before:...
After: ..., value
The index operand, which serves as an 8-bit unsigned index into the local variables of the current frame, must specify a local variable word that contains a reference . To execute the aload instruction, the Java Virtual Machine pushes onto the operand stack the reference contained in the local variable word specified by index .
Note that the wide instruction can precede the aload instruction, to allow a local variable to be accessed with a 16-bit unsigned offset.
Note also that even though the astore instruction may be used to pop a returnAddress value off the operand stack and into a local variable, the aload instruction cannot be used to push a returnAddress value back onto the operand stack. For more information about the use of returnAddress , see Chapter 18, "Finally Clauses."
For more information about the aload instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value
The local variable word at index zero must contain a reference . To execute the aload_0 instruction, the Java Virtual Machine pushes onto the operand stack the reference value contained in the local variable word zero.
Note that even though the astore_0 instruction may be used to pop a returnAddress value off the operand stack and into a local variable, the aload_0 instruction cannot be used to push a returnAddress value back onto the operand stack. For more information about the use of returnAddress , see Chapter 18, "Finally Clauses."
For more information about the aload_0 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value
The local variable word at index one must contain a reference . To execute the aload_1 instruction, the Java Virtual Machine pushes onto the operand stack the reference value contained in the local variable word one.
Note that even though the astore_1 instruction may be used to pop a returnAddress value off the operand stack and into a local variable, the aload_1 instruction cannot be used to push a returnAddress value back onto the operand stack. For more information about the use of returnAddress , see Chapter 18, "Finally Clauses."
For more information about the aload_1 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value
The local variable word at index two must contain a reference . To execute the aload_2 instruction, the Java Virtual Machine pushes onto the operand stack the reference value contained in the local variable word two.
Note that even though the astore_2 instruction may be used to pop a returnAddress value off the operand stack and into a local variable, the aload_2 instruction cannot be used to push a returnAddress value back onto the operand stack. For more information about the use of returnAddress , see Chapter 18, "Finally Clauses."
For more information about the aload_2 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value
The local variable word at index three must contain a reference . To execute the aload_3 instruction, the Java Virtual Machine pushes onto the operand stack the reference value contained in the local variable word three.
Note that even though the astore_3 instruction may be used to pop a returnAddress value off the operand stack and into a local variable, the aload_3 instruction cannot be used to push a returnAddress value back onto the operand stack. For more information about the use of returnAddress , see Chapter 18, "Finally Clauses."
For more information about the aload_3 instruction, see Chapter 10, "Stack Operations."
Before:..., count
After: arrayref
The top word of the operand stack, count , must be an int . To execute the anewarray instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 . The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Class_info entry. If it hasn t already, the virtual machine resolves the entry. The entry may be a class, interface, or array type.
If the resolution is successful, the Java Virtual Machine pops count and creates on the heap an array of size count of the reference type specified by the resolved CONSTANT_Class_info entry. The virtual machine initializes each array element to its default initial value ( null ) and pushes arrayref , a reference to the new array, onto the operand stack.
As a result of executing this instruction, the Java Virtual Machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Class_info entry. If resolution succeeds, but count is less than zero, the virtual machine throws NegativeArraySizeException .
For more information about the anewarray instruction, see Chapter 15, "Objects and Arrays."
Before: ..., objectref
After: [empty]
The return type of the returning method must be reference . The top word of the operand stack, objectref , must be a reference that is assignment compatible with the type represented by the returning method s descriptor. To execute the areturn instruction, the Java Virtual Machine pops objectref from the operand stack of the current frame and pushes it onto the operand stack of the invoking method s frame. The virtual machine discards any other words that may still be on the returning method s frame. If the returning method is synchronized, the monitor that was acquired when the method was invoked is released. The invoking method s frame is made current, and the virtual machine continues execution in the invoking method.
For more information about monitors , see Chapter 20, "Thread Synchronization." For more information about the areturn instruction, see Chapter 19, "Method Invocation and Return."
Before: ..., arrayref
After: ..., length
The top word of the operand stack, arrayref , must be a reference that points to an array. To execute the arraylength instruction, the Java Virtual Machine pops arrayref and pushes the length of the array pointed to by arrayref .
If arrayref is null , the Java Virtual Machine throws NullPointerException .
For more information about the arraylength instruction, see Chapter 15, "Objects and Arrays."
Before:..., value
After: ...
The index operand must specify a valid 8-bit unsigned index into the local variables of the current frame. The value on the top of the operand stack must be a reference or a returnAddress . To execute the astore instruction, the Java Virtual Machine pops the reference or returnAddress value from the top of the operand stack and stores it into the local variable word specified by index .
Note that the wide instruction can precede the astore instruction, to enable a value to be stored into a local variable specified by a 16-bit unsigned offset.
For more information about the astore instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index zero must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be a reference or a returnAddress . To execute the astore_0 instruction, the Java Virtual Machine pops the reference or returnAddress value from the top of the operand stack and stores it into the local variable word at index zero.
For more information about the astore_0 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index one must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be a reference or a returnAddress . To execute the astore_1 instruction, the Java Virtual Machine pops the reference or returnAddress value from the top of the operand stack and stores it into the local variable word at index one.
For more information about the astore_1 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index two must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be a reference or a returnAddress . To execute the astore_2 instruction, the Java Virtual Machine pops the reference or returnAddress value from the top of the operand stack and stores it into the local variable word at index two.
For more information about the astore_2 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index three must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be a reference or a returnAddress . To execute the astore_3 instruction, the Java Virtual Machine pops the reference or returnAddress value from the top of the operand stack and stores it into the local variable word at index three.
For more information about the astore_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., objectref
After objectref
Note that "Before" shows the operand stack of the frame belonging to the method containing the athrow instruction being executed. "After" shows the operand stack of the frame belonging to the method in which the catch clause is found, if a catch clause is found. If no catch clause is found, the thread exits and there are no more operand stacks for that thread.
The top word of the operand stack, objectref , must be a reference that points either to an instance of class java.lang.Throwable or to an instance of some subclass of java.lang.Throwable . To execute the athrow instruction, the Java Virtual Machine pops objectref from the operand stack. The virtual machine "throws" the exception by searching through the current method s exception table for the most recent catch clause that catches either the class of the throwable object pointed to by objectref , or a subclass of the throwable object s class. If the current method s exception table contains a matching entry, the virtual machine extracts the address of the handler to jump to from the matching exception table entry. The virtual machine pops any words remaining on the operand stack, pushes the objectref , sets the program counter to the handler address, and continues execution there. If the current method s exception table doesn t have a matching catch clause, the virtual machine pops the current method s entire frame and rethrows the exception in the previous method. This process repeats until either a matching catch clause is found or the stack frames for all the methods along the current thread s call stack have been popped. If no catch clause is found by this process, the current thread exits.
If the objectref word is null , the virtual machine throws NullPointerException .
For more information about the athrow instruction, see Chapter 17, "Exceptions."
Before: ..., arrayref, index
After: ..., value
To execute the baload instruction, the Java Virtual Machine first pops two words from the operand stack. The arrayref word must be a reference that refers to an array of byte s or boolean s. The index word must be an int . The virtual machine retrieves from the arrayref array the byte or boolean value specified by index , sign-extends it to an int , and pushes it onto the operand stack.
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the baload instruction, see Chapter 15, "Objects and Arrays."
Before: ..., arrayref, index, value
After: ...
To execute the bastore instruction, the Java Virtual Machine first pops three words from the operand stack. The arrayref word must be a reference that refers to an array of byte s or boolean s. The index and value words must be int s. The virtual machine truncates the int value to a byte and stores it into the arrayref array location specified by index .
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the bastore instruction, see Chapter 15, "Objects and Arrays."
Before:...
After: ..., value
To execute the bipush instruction, the Java Virtual Machine first sign-extends operand byte , an 8-bit signed integer, to an int . The virtual machine then pushes the resulting int value onto the operand stack.
For more information about the bipush instruction, see Chapter 10, "Stack Operations."
Before: ..., arrayref, index
After: ..., value
To execute the caload instruction, the Java Virtual Machine first pops two words from the operand stack. The arrayref word must be a reference that refers to an array of char s. The index word must be an int . The virtual machine retrieves from the arrayref array the char value specified by index , zero-extends it to an int , and pushes it onto the operand stack.
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the caload instruction, see Chapter 15, "Objects and Arrays."
Before: ..., arrayref, index, value
After: ...
To execute the castore instruction, the Java Virtual Machine first pops three words from the operand stack. The arrayref word must be a reference that refers to an array of char s. The index and value words must be int s. The virtual machine truncates the int value to a char and stores it into the arrayref array location specified by index .
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the castore instruction, see Chapter 15, "Objects and Arrays."
Before: ..., objectref
After: ..., objectref
The top word of the stack, objectref , must be a reference . To execute the checkcast instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Class_info entry. If it hasn t already, the virtual machine resolves the entry. The entry may be a class, interface, or array type. If objectref is null or if objectref can be cast to the resolved type, the stack remains unchanged. Otherwise, the virtual machine throws ClassCastException .To determine whether the object pointed to by objectref can be cast to the resolved type, the virtual machine first determines whether the object is a class instance or array. (It can t be an interface instance, because interfaces can t be instantiated .) If it is a class instance, and the resolved type is a class, not an interface, the object can be cast to the resolved class if the object s class is the resolved class or a subclass of the resolved class. Else, if it is a class instance, and the resolved type is an interface, not an class, the object can be cast to the resolved interface if the object s class implements the resolved interface. Otherwise, the object is an array. If the resolved type is a class, it must be java.lang.Object . Else, if the resolved type is an array of primitive types, the object must be an array of the same primitive type. Otherwise, the resolved type must be an array with a component type of some reference type, and the object must be an array with a component type that can be cast to the component type of the resolved array type. (Note that the dimension of an array doesn t enter into the checkcast check, only the component type of the array.)
As a result of executing this instruction, the virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Class_info entry. If resolution succeeds, but the resolved type cannot be cast to the resolved type, the virtual machine throws an ClassCastException .
For more information about the checkcast instruction, see Chapter 15, "Objects and Arrays."
Before: ..., value.word1, value.word2
After: ..., result
The top two words of the operand stack must be a double . To execute the d2f instruction, the Java Virtual Machine pops the double value from the operand stack, converts the double to a float , and pushes the float result .
To convert the double value to float , the Java Virtual Machine first checks to see if the value equals NaN (Not a Number). If so, the float result is also NaN. Else, if the magnitude of the double value is too small to be represented by a float , the float result is a zero of the same sign. Else, if the magnitude of the double value is too large to be represented by a float , the float result is an infinity of the same sign. Otherwise, the virtual machine converts the double value to float zero using IEEE 754 round-to- nearest mode.
Note that this instruction performs a narrowing primitive conversion. Because not all double values are representable by a float , the conversion may result in a loss of magnitude and precision.
For more information about the d2f instruction, see Chapter 11, "Type Conversion."
Before: ..., value.word1, value.word2
After: ..., result
The top two words of the operand stack must be a double . To execute the d2i instruction, the Java Virtual Machine pops the double value from the operand stack, converts the double to an int , and pushes the int result .
To convert the double value to int , the Java Virtual Machine first checks to see if the value equals NaN (Not a Number). If so, the int result is zero. Else, if the double value is not a positive or negative infinity, the virtual machine rounds the value towards zero using IEEE 754 round-towards-zero mode. If the resulting integral value can be exactly represented by an int , the int result is that integral value. Otherwise, the magnitude of the double value is too great be represented in an int . If value is positive, the int result is the largest positive integer representable in an int . If value is negative, the int result is the smallest negative integer representable in an int .
Note that this instruction performs a narrowing primitive conversion. Because not all double values are representable by an int , the conversion may result in a loss of magnitude and precision.
For more information about the d2i instruction, see Chapter 11, "Type Conversion."
Before: ..., value.word1, value.word2
After: ..., result.word1, result.word2
The top two words of the operand stack must be a double . To execute the d2l instruction, the Java Virtual Machine pops the double value from the operand stack, converts the double to a long , and pushes the long result .
To convert the double value to long , the Java Virtual Machine first checks to see if the value equals NaN (Not a Number). If so, the long result is zero. Else, if the double value is not a positive or negative infinity, the virtual machine rounds the value towards zero using IEEE 754 round-towards-zero mode. If the resulting integral value can be exactly represented by a long , the long result is that integral value. Otherwise, the magnitude of the double value is too great be represented in a long . If value is positive, the long result is the largest positive integer representable in a long . If value is negative, the long result is the smallest negative integer representable in an long .
Note that this instruction performs a narrowing primitive conversion. Because not all double values are representable by a long , the conversion may result in a loss of magnitude and precision.
For more information about the d2l instruction, see Chapter 11, "Type Conversion."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two double s, value1 and value2 . To execute the dadd instruction, the Java Virtual Machine pops value1 and value2 , adds them, and pushes the double result . The result produced by the dadd instruction is governed by the rules of IEEE 754 floating point arithmetic.
For more information about the dadd instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., arrayref, index
After: ..., value.word1, value.word2
To execute the daload instruction, the Java Virtual Machine first pops two words from the operand stack. The arrayref word must be a reference that refers to an array of double s. The index word must be an int . The virtual machine retrieves from the arrayref array the double value specified by index and pushes it onto the operand stack.
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the daload instruction, see Chapter 15, "Objects and Arrays."
Before: ..., arrayref, index, value.word1, value.word2
After: ...
To execute the daload instruction, the Java Virtual Machine first pops four words from the operand stack. The arrayref word must be a reference that refers to an array of double s. The index word must be an int , and the value words must be a double . The virtual machine stores double value into the arrayref array location specified by index .
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the dastore instruction, see Chapter 15, "Objects and Arrays."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result
The top four words of the operand stack must be two double s, value1 and value2 . To execute the dcmpg instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 equals value2 , the virtual machine pushes onto the operand stack int result zero. Else, if value1 is greater than value2 , the virtual machine pushes onto the operand stack int result one. Otherwise, if value1 is less than value2 , the virtual machine pushes onto the operand stack int result negative one. If either value1 or value2 equals NaN (Not a Number), the virtual machine pushes onto the operand stack int result one.
The result produced by the fcmpg instruction is governed by the rules of IEEE 754 floating point arithmetic. Note that the dcmpg instruction differs from the the dcmpl instruction only in its treatment of NaN. For more information about the dcmpg instruction, see Chapter 16, "Control Flow."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result
The top four words of the operand stack must be two double s, value1 and value2 . To execute the dcmpg instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 equals value2 , the virtual machine pushes onto the operand stack int result zero. Else, if value1 is greater than value2 , the virtual machine pushes onto the operand stack int result one. Otherwise, if value1 is less than value2 , the virtual machine pushes onto the operand stack int result negative one. If either value1 or value2 equals NaN (Not a Number), the virtual machine pushes onto the operand stack int result negative one.
The result produced by the fcmpl instruction is governed by the rules of IEEE 754 floating point arithmetic. Note that the dcmpl instruction differs from the the dcmpg instruction only in its treatment of NaN. For more information about the dcmpl instruction, see Chapter 16, "Control Flow."
Before: ...
After: ..., <0.0-word1, <0.0-word2
To execute the dconst_0 instruction, the Java Virtual Machine pushes the double constant 0.0 onto the operand stack.
For more information about the dconst_0 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., <1.0-word1, <1.0-word2
To execute the dconst_1 instruction, the Java Virtual Machine pushes the double constant 1.0 onto the operand stack.
For more information about the dconst_1 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two double s, value1 and value2 . To execute the ddiv instruction, the Java Virtual Machine pops value1 and value2 , divides value1 by value2 ( value1 / value2 ), and pushes the double result . The result produced by the ddiv instruction is governed by the rules of IEEE 754 floating point arithmetic.
For more information about the ddiv instruction, see Chapter 14, "Floating Point Arithmetic."
Before:...
After: ..., value.word1, value.word2
The index operand, which serves as an 8-bit unsigned index into the local variables of the current frame, must specify the first of two consecutive local variable words that contain a double . To execute the dload instruction, the Java Virtual Machine pushes onto the operand stack the double contained in the two consecutive local variable words specified by index and index + 1 .
Note that the wide instruction can precede the lload instruction, to allow a local variable to be accessed with a 16-bit unsigned offset.
For more information about the dload instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value.word1, value.word2
The two consecutive local variable words at indexes zero and one must contain a double . To execute the dload_0 instruction, the Java Virtual Machine pushes onto the operand stack the double value contained in local variable words zero and one.
For more information about the dload_0 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value.word1, value.word2
The two consecutive local variable words at indexes one and two must contain a double . To execute the dload_1 instruction, the Java Virtual Machine pushes onto the operand stack the double value contained in local variable words one and two.
For more information about the dload_1 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value.word1, value.word2
The two consecutive local variable words at indexes two and three must contain a double . To execute the dload_2 instruction, the Java Virtual Machine pushes onto the operand stack the double value contained in local variable words two and three.
For more information about the dload_2 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value.word1, value.word2
The two consecutive local variable words at indexes three and four must contain a double . To execute the dload_3 instruction, the Java Virtual Machine pushes onto the operand stack the double value contained in local variable words three and four.
For more information about the dload_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two double s, value1 and value2 . To execute the dmul instruction, the Java Virtual Machine pops value1 and value2 , multiplies them, and pushes the double result . The result produced by the dmul instruction is governed by the rules of IEEE 754 floating point arithmetic.
For more information about the dmul instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., value.word1, value.word2
After: ..., result.word1, result.word2
The top two words of the operand stack must be a double . To execute the dneg instruction, the Java Virtual Machine pops value , negates it, and pushes the double result . The result produced by the dneg instruction is governed by the rules of IEEE 754 floating point arithmetic.
Note that the result produced by a dneg instruction is not always the same as the number that would be produced by subtracting value from zero with the dsub instruction. The range of IEEE 754 floating point numbers includes two zeros, a positive zero and a negative zero. When value is +0.0, the result of the dneg instruction is -0.0. By contrast, when subtracting +0.0 from +0.0, the dsub instruction yields +0.0.
For more information about the dneg instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two double s, value1 and value2 . To execute the drem instruction, the Java Virtual Machine pops value1 and value2 , calculates the remainder, and pushes the double result . The remainder equals value1 - (value1 / value2) * value2 , where value1 / value2 is a truncating division, rather than the rounding division required by IEEE 754.
The behavior of drem is comparable to that of the C library function fmod() .The remainder of two double s can be calculated according to IEEE 754 floating point standard via the IEEERemainder() method of class java.lang.Math .
For more information about the drem instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., value.word1, value.word2
After: [empty]
The return type of the returning method must be double . The top two words of the operand stack must be a double . To execute the dreturn instruction, the Java Virtual Machine pops double value from the operand stack of the current frame and pushes it onto the operand stack of the invoking method s frame. The virtual machine discards any other words that may still be on the returning method s frame. If the returning method is synchronized, the monitor that was acquired when the method was invoked is released. The invoking method s frame is made current, and the virtual machine continues execution in the invoking method.
For more information about monitors, see Chapter 20, "Thread Synchronization." For more information about the dreturn instruction, see Chapter 19, "Method Invocation and Return."
Before:..., value.word1, value.word2
After: ...
The index operand must specify a valid 8-bit unsigned index into the local variables of the current frame. The top two words of the operand stack must be a double . To execute the dstore instruction, the Java Virtual Machine pops the double value from the top of the operand stack and stores it into the two consecutive local variable words at indexes index and index + 1 .
Note that the wide instruction can precede the dstore instruction, to enable a value to be stored into a local variable specified by a 16-bit unsigned offset.
For more information about the dstore instruction, see Chapter 10, "Stack Operations."
Before: ..., value.word1, value.word2
After: ...
The indexes zero and one must be valid indexes into the local variables of the current stack frame. The top two words on the operand stack must be a double . To execute the dstore_0 instruction, the Java Virtual Machine pops the double value from the top of the operand stack and stores it into the two consecutive local variable words at indexes zero and one.
For more information about the dstore_0 instruction, see Chapter 10, "Stack Operations."
Before: ..., value.word1, value.word2
After: ...
The indexes one and two must be valid indexes into the local variables of the current stack frame. The top two words on the operand stack must be a double . To execute the dstore_1 instruction, the Java Virtual Machine pops the double value from the top of the operand stack and stores it into the two consecutive local variable words at indexes one and two.
For more information about the dstore_1 instruction, see Chapter 10, "Stack Operations."
Before: ..., value.word1, value.word2
After: ...
The indexes two and three must be valid indexes into the local variables of the current stack frame. The top two words on the operand stack must be a double . To execute the dstore_2 instruction, the Java Virtual Machine pops the double value from the top of the operand stack and stores it into the two consecutive local variable words at indexes two and three.
For more information about the dstore_2 instruction, see Chapter 10, "Stack Operations."
Before: ..., value.word1, value.word2
After: ...
The indexes three and four must be valid indexes into the local variables of the current stack frame. The top two words on the operand stack must be a double . To execute the dstore_3 instruction, the Java Virtual Machine pops the double value from the top of the operand stack and stores it into the two consecutive local variable words at indexes three and four.
For more information about the dstore_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two double s, value1 and value2 . To execute the dsub instruction, the Java Virtual Machine pops value1 and value2 , subtracts value2 from value1 ( value1 - value2 ), and pushes the double result . The result produced by the dsub instruction is governed by the rules of IEEE 754 floating point arithmetic.
For more information about the dsub instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., word
After: ..., word, word
To execute the dup instruction, the Java Virtual Machine duplicates the top word of the operand stack and pushes the duplicate. This instruction can be used to duplicate any single-word value from the top of the operand stack. It must not be used to duplicate half of a dual word value ( long or double ) that occupies the top of the operand stack.
For more information about the dup instruction, see Chapter 10, "Stack Operations."
Before: ..., word2, word1
After: ..., word1, word2, word1
To execute the dup_x1 instruction, the Java Virtual Machine duplicates the top word of the operand stack and inserts the duplicate two words down. Both word1 and word2 must be single-word values.
For more information about the dup_x1 instruction, see Chapter 10, "Stack Operations."
Before: ..., word3, word2, word1
After: ..., word1, word3, word2, word1
To execute the dup_x2 instruction, the Java Virtual Machine duplicates the top word of the operand stack and inserts the duplicate three words down. word1 must be a single-word value. Both word2 and word3 must be single-word values, or together constitute one dual-word value (a long or double ).
For more information about the dup_x2 instruction, see Chapter 10, "Stack Operations."
Before: ..., word2, word1
After: ..., word2, word1, word2, word1
To execute the dup2 instruction, the Java Virtual Machine duplicates the top two words of the operand stack and pushes the duplicate. This instruction may be used to duplicate any dual-word value or any two single-word values that occupy the top of the operand stack. It must not be used if one single-word value and half of a dual-word value ( long or double ) occupies the top of the operand stack.
For more information about the dup2 instruction, see Chapter 10, "Stack Operations."
Before: ..., word3, word2, word1
After: ..., word2, word1, word3, word2, word1
To execute the dup2_x1 instruction, the Java Virtual Machine duplicates the top two words of the operand stack and inserts the duplicate three words down. word3 must be a single-word value. Both word1 and word2 must be single-word values, or together constitute one dual-word value (a long or double ).
For more information about the dup2_x1 instruction, see Chapter 10, "Stack Operations."
Before: ..., word4, word3, word2, word1
After: ..., word2, word1, word4, word3, word2, word1
To execute the dup2_x2 instruction, the Java Virtual Machine duplicates the top two words of the operand stack and inserts the duplicate four words down. word3 must be a single-word value. Both word1 and word2 must be single-word values, or together constitute one dual-word value (a long or double ). Likewise, both word3 and word4 must be single-word values, or together constitute one dual-word value.
For more information about the dup2_x2 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ..., result.word1, result.word2
The top word of the operand stack, value , must be a float . To execute the f2d instruction, the Java Virtual Machine pops float value from the operand stack, converts the float to a double , and pushes the double result .
Note that this instruction performs a widening primitive conversion. Because all float values are representable by a double , the conversion is exact.
For more information about the f2d instruction, see Chapter 11, "Type Conversion."
Before: ..., value
After: ..., result
The top word of the operand stack, value , must be a float . To execute the f2i instruction, the Java Virtual Machine pops the float value from the operand stack, converts the float to an int , and pushes the int result .
To convert the float value to int , the Java Virtual Machine first checks to see if the value equals NaN (Not a Number). If so, the int result is zero. Else, if the float value is not a positive or negative infinity, the virtual machine rounds the value towards zero using IEEE 754 round-towards-zero mode. If the resulting integral value can be exactly represented by an int , the int result is that integral value. Otherwise, the magnitude of the float value is too great be represented in an int . If value is positive, the int result is the largest positive integer representable in an int . If value is negative, the int result is the smallest negative integer representable in an int .
Note that this instruction performs a narrowing primitive conversion. Because not all float values are representable by an int , the conversion may result in a loss of magnitude and precision.
For more information about the f2i instruction, see Chapter 11, "Type Conversion."
Before: ..., value
After: ..., result.word1, result.word2
The top word of the operand stack, value , must be a float . To execute the f2l instruction, the Java Virtual Machine pops the float value from the operand stack, converts the float to a long , and pushes the long result .
To convert the float value to long , the Java Virtual Machine first checks to see if the value equals NaN (Not a Number). If so, the long result is zero. Else, if the float value is not a positive or negative infinity, the virtual machine rounds the value towards zero using IEEE 754 round-towards-zero mode. If the resulting integral value can be exactly represented by a long , the long result is that integral value. Otherwise, the magnitude of the float value is too great be represented in a long . If value is positive, the long result is the largest positive integer representable in a long . If value is negative, the int result is the smallest negative integer representable in a long .
Note that this instruction performs a narrowing primitive conversion. Because not all float values are representable by a long , the conversion may result in a loss of magnitude and precision.
For more information about the f2l instruction, see Chapter 11, "Type Conversion."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be float s. To execute the fadd instruction, the Java Virtual Machine pops value1 and value2 , adds them, and pushes the float result . The result produced by the fadd instruction is governed by the rules of IEEE 754 floating point arithmetic.
For more information about the fadd instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., arrayref, index
After: ..., value
To execute the faload instruction, the Java Virtual Machine first pops two words from the operand stack. The arrayref word must be a reference that refers to an array of float s. The index word must be an int . The virtual machine retrieves from the arrayref array the float value specified by index and pushes it onto the operand stack.
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the faload instruction, see Chapter 15, "Objects and Arrays."
Before: ..., arrayref, index, value
After: ...
To execute the faload instruction, the Java Virtual Machine first pops three words from the operand stack. The arrayref word must be a reference that refers to an array of float s. The index word must be an int , and the value word must be a float . The virtual machine stores float value into the arrayref array location specified by index .
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, the virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the fastore instruction, see Chapter 15, "Objects and Arrays."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be two float s. To execute the fcmpg instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 equals value2 , the virtual machine pushes onto the operand stack int result zero. Else, if value1 is greater than value2 , the virtual machine pushes onto the operand stack int result one. Otherwise, if value1 is less than value2 , the virtual machine pushes onto the operand stack int result negative one. If either value1 or value2 equals NaN (Not a Number), the virtual machine pushes onto the operand stack int result one.
The result produced by the fcmpg instruction is governed by the rules of IEEE 754 floating point arithmetic. Note that the fcmpg instruction differs from the the fcmpl instruction only in its treatment of NaN. For more information about the fcmpg instruction, see Chapter 16, "Control Flow."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be two float s. To execute the fcmpl instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 equals value2 , the virtual machine pushes onto the operand stack int result zero. Else, if value1 is greater than value2 , the virtual machine pushes onto the operand stack int result one. Otherwise, if value1 is less than value2 , the virtual machine pushes onto the operand stack int result negative one. If either value1 or value2 equals NaN (Not a Number), the virtual machine pushes onto the operand stack int result negative one.
The result produced by the fcmpl instruction is governed by the rules of IEEE 754 floating point arithmetic. Note that the fcmpl instruction differs from the the fcmpg instruction only in its treatment of NaN. For more information about the fcmpl instruction, see Chapter 16, "Control Flow."
Before: ...
After: ..., <0.0
To execute the fconst_0 instruction, the Java Virtual Machine pushes the float constant 0.0 onto the operand stack.
For more information about the fconst_0 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., <1.0
To execute the fconst_1 instruction, the Java Virtual Machine pushes the float constant 1.0 onto the operand stack.
For more information about the fconst_1 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., <2.0
To execute the fconst_2 instruction, the Java Virtual Machine pushes the float constant 2.0 onto the operand stack.
For more information about the fconst_2 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be float s. To execute the fdiv instruction, the Java Virtual Machine pops value1 and value2 , divides value1 by value2 ( value1 / value2 ), and pushes the float result . The result produced by the fdiv instruction is governed by the rules of IEEE 754 floating point arithmetic.
For more information about the fdiv instruction, see Chapter 14, "Floating Point Arithmetic."
Before:...
After: ..., value
The index operand, which serves as an 8-bit unsigned index into the local variables of the current frame, must specify a local variable word that contains an float . To execute the fload instruction, the Java Virtual Machine pushes onto the operand stack the float contained in the local variable word specified by index .
Note that the wide instruction can precede the fload instruction, to allow a local variable to be accessed with a 16-bit unsigned offset.
For more information about the fload instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value
The local variable word at index zero must contain a float . To execute the fload_0 instruction, the Java Virtual Machine pushes onto the operand stack the float value contained in local variable word zero.
For more information about the fload_0 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value
The local variable word at index one must contain a float . To execute the fload_1 instruction, the Java Virtual Machine pushes onto the operand stack the float value contained in local variable word one.
For more information about the fload_1 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value
The local variable word at index two must contain a float . To execute the fload_2 instruction, the Java Virtual Machine pushes onto the operand stack the float value contained in local variable word two.
For more information about the fload_2 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value
The local variable word at index three must contain a float . To execute the fload_3 instruction, the Java Virtual Machine pushes onto the operand stack the float value contained in local variable word three.
For more information about the fload_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be float s. To execute the fmul instruction, the Java Virtual Machine pops value1 and value2 , multiplies them, and pushes the float result . The result produced by the fmul instruction is governed by the rules of IEEE 754 floating point arithmetic.
For more information about the fmul instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., value
After: ..., result
The top word of the operand stack, value , must be a float . To execute the fneg instruction, the Java Virtual Machine pops value , negates it, and pushes the float result . The result produced by the fneg instruction is governed by the rules of IEEE 754 floating point arithmetic.
Note that the result produced by an fneg instruction is not always the same as the number that would be produced by subtracting value from zero with the fsub instruction. The range of IEEE 754 floating point numbers includes two zeros, a positive zero and a negative zero. When value is +0.0, the result of the fneg instruction is -0.0. By contrast, when subtracting +0.0 from +0.0, the fsub instruction yields +0.0.
For more information about the fneg instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be float s. To execute the frem instruction, the Java Virtual Machine pops value1 and value2 , calculates the remainder, and pushes the float result . The remainder equals value1 - (value1 / value2) * value2 , where value1 / value2 is a truncating division, rather than the rounding division required by IEEE 754.
The behavior of frem is comparable to that of the C library function fmod() .The remainder of two float s can be calculated according to IEEE 754 floating point standard via the IEEERemainder() method of class java.lang.Math .
For more information about the frem instruction, see Chapter 14, "Floating Point Arithmetic."
Before: ..., value
After: [empty]
The return type of the returning method must be float . The top word of the operand stack, value , must be a float . To execute the freturn instruction, the Java Virtual Machine pops float value from the operand stack of the current frame and pushes it onto the operand stack of the invoking method s frame. The virtual machine discards any other words that may still be on the returning method s frame. If the returning method is synchronized, the monitor that was acquired when the method was invoked is released. The invoking method s frame is made current, and the virtual machine continues execution in the invoking method.
For more information about monitors, see Chapter 20, "Thread Synchronization." For more information about the freturn instruction, see Chapter 19, "Method Invocation and Return."
Before:..., value
After: ...
The index operand must specify a valid 8-bit unsigned index into the local variables of the current frame. The value on the top of the operand stack must be a float . To execute the fstore instruction, the Java Virtual Machine pops the float value from the top of the operand stack and stores it into the local variable word specified by index .
Note that the wide instruction can precede the fstore instruction, to enable a value to be stored into a local variable specified by a 16-bit unsigned offset.
For more information about the fstore instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index zero must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be a float . To execute the fstore_0 instruction, the Java Virtual Machine pops the float value from the top of the operand stack and stores it into the local variable word at index zero.
For more information about the fstore_0 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index one must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be a float . To execute the fstore_1 instruction, the Java Virtual Machine pops the float value from the top of the operand stack and stores it into the local variable word at index one.
For more information about the fstore_1 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index two must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be a float . To execute the fstore_2 instruction, the Java Virtual Machine pops the float value from the top of the operand stack and stores it into the local variable word at index two.
For more information about the fstore_2 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index three must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be a float . To execute the fstore_3 instruction, the Java Virtual Machine pops the float value from the top of the operand stack and stores it into the local variable word at index three.
For more information about the fstore_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be float s. To execute the fsub instruction, the Java Virtual Machine pops value1 and value2 , subtracts value2 from value1 ( value1 - value2 ), and pushes the float result . The result produced by the fsub instruction is governed by the rules of IEEE 754 floating point arithmetic.
For more information about the fsub instruction, see Chapter 14, "Floating Point Arithmetic."
Before:..., objectref
After: ..., value
or
Before: ..., objectref
After: ..., value.word1, value.word2
The top word of the stack, objectref , must be a reference . To execute the getfield instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Fieldref_info entry. If it hasn t already, the virtual machine resolves the entry, which yields the field s width and the field s offset from the beginning of the object image. If the resolution is successful, the virtual machine pops the objectref and fetches the field from the object pointed to by objectref . If the type of the field is byte , short , or char , the virtual machine sign-extends the field s value to an int and pushes the single-word int value onto the operand stack. Else, if the type is int , boolean , float , or reference , the virtual machine pushes the single-word value onto the operand stack. Otherwise, the type is long or double , and the virtual machine pushes the dual-word value onto the operand stack.As a result of executing this instruction, the virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Fieldref_info entry. As part of the process of resolving the CONSTANT_Fieldref_info entry, the virtual machine checks whether the field s access permission enables the current class to access the field. If the field is protected, the virtual machine makes certain the field is a member of the either the current class or a superclass of the current class, and that the class of the object pointed to by objectref is either the current class or a subclass of the current class. If not (or if there is any other access permission problem), the virtual machine throws IllegalAccessError . Else, if the field exists and is accessible from the current class, but the field is static, the virtual machine throws IncompatibleClassChangeError . Otherwise, if objectref is null , the virtual machine throws NullPointerException .
For more information about the getfield instruction, see Chapter 15, "Objects and Arrays."
Before:...
After: ..., value
or
Before: ...
After: ..., value.word1, value.word2
To execute the getstatic instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Fieldref_info entry. If it hasn t already, the virtual machine resolves the entry. If the resolution is successful, the virtual machine fetches the value of the static field. If the type of the field is byte , short , or char , the virtual machine sign-extends the field s value to int and pushes the single-word int value onto the operand stack. Else, if the type is int , boolean , float , or reference the virtual machine pushes the single-word value onto the operand stack. Otherwise, the type is long or double , and the virtual machine pushes the dual-word value onto the operand stack.As a result of executing this instruction, the virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Fieldref_info entry. As part of the process of resolving the CONSTANT_Fieldref_info entry, the virtual machine checks whether the field s access permission enables the current class to access the field. If the field is protected, the virtual machine makes certain the field is a member of the either the current class or a superclass of the current class. If not (or if there is any other access permission problem), the virtual machine throws IllegalAccessError . Else, if the field exists and is accessible from the current class, but the field is not static, the virtual machine throws IncompatibleClassChangeError .
For more information about the getstatic instruction, see Chapter 15, "Objects and Arrays."
No change
To execute the goto instruction, the Java Virtual Machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 .
The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the goto opcode. The target address must be the address of an opcode within the same method as the goto opcode. The virtual machine jumps to the target address and continues execution there.For more information about the goto instruction, see Chapter 16, "Control Flow."
No change
To execute the goto_w instruction, the Java Virtual Machine forms a signed 32-bit offset by calculating (branchbyte1 24) | (branchbyte2 16) | (branchbyte3 8) | branchbyte4 .
The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the goto_w opcode. The target address must be the address of an opcode within the same method as the goto_w opcode. The virtual machine jumps to the target address and continues execution there.Note that despite the 32-bit offset of the goto_w instruction, Java methods are currently (in both the 1.0 and 1.1 releases) limited to 65,535 bytes by three items in the Java class file format: the sizes of the indexes in the LineNumberTable attribute, the LocalVariableTable attribute, and the Code attribute s exception_table item. According to the Java Virtual Machine specification, the 65,536 byte limit to Java methods may be raised in a future release. For more information about the goto_w instruction, see Chapter 16, "Control Flow."
Before: ..., value
After: ..., result
The top word of the operand stack, value , must be an int . To execute the i2b instruction, the Java Virtual Machine pops int value from the operand stack, truncates the int to a byte , sign-extends the result back to an int , and pushes the int result .
Note that this instruction performs a narrowing primitive conversion. As a result of this conversion, magnitude information may be lost and the sign bit may change.
For more information about the i2b instruction, see Chapter 11, "Type Conversion."
Before: ..., value
After: ..., result
The top word of the operand stack, value , must be an int . To execute the i2c instruction, the Java Virtual Machine pops int value from the operand stack, truncates the int to a char , zero-extends the result back to an int , and pushes the int result .
Note that this instruction performs a narrowing primitive conversion. As a result of this conversion, magnitude information may be lost and, as the result is always positive, the sign bit may change.
For more information about the i2c instruction, see Chapter 11, "Type Conversion."
Before: ..., value
After: ..., result.word1, result.word2
The top word of the operand stack, value , must be an int . To execute the i2d instruction, the Java Virtual Machine pops int value from the operand stack, sign-extends the int to a double , and pushes the double result .
Note that this instruction performs a widening primitive conversion. Because all int values are representable by a double , the conversion is exact.
For more information about the i2d instruction, see Chapter 11, "Type Conversion."
Before: ..., value
After: ..., result
The top word of the operand stack, value , must be an int . To execute the i2f instruction, the Java Virtual Machine pops int value from the operand stack, converts the int to a float using the IEEE round-to-nearest mode, and pushes the float result .
Note that this instruction performs a widening primitive conversion. Because not all int values are exactly representable by a float , the conversion may result in a loss of precision.
For more information about the i2f instruction, see Chapter 11, "Type Conversion."
Before: ..., value
After: ..., result.word1, result.word2
The top word of the operand stack, value , must be an int . To execute the i2l instruction, the Java Virtual Machine pops int value from the operand stack, sign-extends the int to a long , and pushes the long result .
Note that this instruction performs a widening primitive conversion. Because all int values are representable by a long , the conversion is exact.
For more information about the i2l instruction, see Chapter 11, "Type Conversion."
Before: ..., value
After: ..., result
The top word of the operand stack, value , must be an int . To execute the i2s instruction, the Java Virtual Machine pops int value from the operand stack, truncates the int to a short , sign-extends the result back to an int , and pushes the int result .
Note that this instruction performs a narrowing primitive conversion. As a result of this conversion, magnitude information may be lost and the sign bit may change.
For more information about the i2s instruction, see Chapter 11, "Type Conversion."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the iadd instruction, the Java Virtual Machine pops value1 and value2 , adds them, and pushes the int result . If overflow occurs, result is the 32 lowest order bits of the true mathematical result represented in a sufficiently wide two s-complement format, and the sign of result is different from that of the true mathematical result.
For more information about the iadd instruction, see Chapter 12, "Integer Arithmetic."
Before: ..., arrayref, index
After: ..., value
To execute the iaload instruction, the Java Virtual Machine first pops two words from the operand stack. The arrayref word must be a reference that refers to an array of int s. The index word must be an int .
The virtual machine retrieves from the arrayref array the int value specified by index and pushes it onto the operand stack.If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array,
The virtual machine throws ArrayIndexOutOfBoundsException .For more information about the iaload instruction, see Chapter 15, "Objects and Arrays."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the iand instruction, the Java Virtual Machine pops value1 and value2 , bitwise ANDs them, and pushes the int result .
For more information about the iand instruction, see Chapter 13, "Logic."
Before: ..., arrayref, index, value
After: ...
To execute the iastore instruction, the Java Virtual Machine first pops three words from the operand stack. The arrayref word must be a reference that refers to an array of int s. The index and value words must be int s.
The virtual machine stores int value into the arrayref array location specified by index .If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array,
The virtual machine throws ArrayIndexOutOfBoundsException .For more information about the iastore instruction, see Chapter 15, "Objects and Arrays."
Before: ...
After: ..., 0
To execute the iconst_0 instruction, the Java Virtual Machine pushes the int constant 0 onto the operand stack.
For more information about the iconst_0 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., 1
To execute the iconst_1 instruction, the Java Virtual Machine pushes the int constant 1 onto the operand stack.
For more information about the iconst_1 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., 2
To execute the iconst_2 instruction, the Java Virtual Machine pushes the int constant 2 onto the operand stack.
For more information about the iconst_2 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., 3
To execute the iconst_3 instruction, the Java Virtual Machine pushes the int constant 3 onto the operand stack.
For more information about the iconst_3 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., 4
To execute the iconst_4 instruction, the Java Virtual Machine pushes the int constant 4 onto the operand stack.
For more information about the iconst_4 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., 5
To execute the iconst_5 instruction, the Java Virtual Machine pushes the int constant 5 onto the operand stack.
For more information about the iconst_5 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., -1
To execute the iconst_m1 instruction, the Java Virtual Machine pushes the int constant -1 onto the operand stack.
For more information about the iconst_m1 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the idiv instruction, the Java Virtual Machine pops value1 and value2 , integer divides value1 by value2 ( value1 / value2 ), and pushes the int result .
Integer division rounds the magnitude of the true mathematical quotient towards zero to the nearest integer. If the magnitude of the denominator is greater than that of the numerator, the int result is zero. Else, with one special exception, the sign of result is positive if the signs of the numerator and denominator are the same, negative if they are different. The exception to this rule is when the numerator is the smallest negative integer that can be represented by an int and the denominator is -1. For this division, the true mathematical result is one greater than the largest positive integer that can be represented by an int . As a consequence, the division overflows and the result is equal to the numerator.
If value2 (the denominator) is zero, the Java Virtual Machine throws ArithmeticException .
For more information about the idiv instruction, see Chapter 12, "Integer Arithmetic."
Before:..., value
After: ...
The top word of the operand stack, value , must be an int . To execute the ifeq instruction, the Java Virtual Machine pops value off the operand stack and compares it against zero. If value equals zero,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the ifeq opcode. The target address must be the address of an opcode within the same method as the ifeq opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value does not equal zero, The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the ifeq instruction.For more information about the ifeq instruction, see Chapter 16, "Control Flow."
Before:..., value
After: ...
The top word of the operand stack, value , must be an int . To execute the ifge instruction, the Java Virtual Machine pops value off the operand stack and compares it against zero. If value is greater than or equal to zero,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the ifge opcode. The target address must be the address of an opcode within the same method as the ifge opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not greater than or equal to zero, The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the ifge instruction.For more information about the ifge instruction, see Chapter 16, "Control Flow."
Before:..., value
After: ...
The top word of the operand stack, value , must be an int . To execute the ifgt instruction, the Java Virtual Machine pops value off the operand stack and compares it against zero. If value is greater than zero,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the ifgt opcode. The target address must be the address of an opcode within the same method as the ifgt opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not greater than zero, The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the ifgt instruction.For more information about the ifgt instruction, see Chapter 16, "Control Flow."
Before:..., value
After: ...
The top word of the operand stack, value , must be an int . To execute the ifle instruction, the Java Virtual Machine pops value off the operand stack and compares it against zero. If value is less than or equal to zero,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the ifle opcode. The target address must be the address of an opcode within the same method as the ifle opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not less than or equal to zero, The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the ifle instruction.For more information about the ifle instruction, see Chapter 16, "Control Flow."
Before:..., value
After: ...
The top word of the operand stack, value , must be an int . To execute the iflt instruction, the Java Virtual Machine pops value off the operand stack and compares it against zero. If value is less than zero,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the iflt opcode. The target address must be the address of an opcode within the same method as the iflt opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not less than zero, The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the iflt instruction.For more information about the iflt instruction, see Chapter 16, "Control Flow."
Before:..., value
After: ...
The top word of the operand stack, value , must be an int . To execute the ifne instruction, the Java Virtual Machine pops value off the operand stack and compares it against zero. If value does not equal zero,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the ifne opcode. The target address must be the address of an opcode within the same method as the ifne opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value does equal zero, The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the ifne instruction.For more information about the ifne instruction, see Chapter 16, "Control Flow."
Before:..., value
After: ...
The top word of the operand stack, value , must be a reference . To execute the ifnonnull instruction, the Java Virtual Machine pops value off the operand stack and compares it against null . If value is not null ,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the ifnonnull opcode. The target address must be the address of an opcode within the same method as the ifnonnull opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is null , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the ifnonnull instruction.For more information about the ifnonnull instruction, see Chapter 16, "Control Flow."
Before:..., value
After: ...
The top word of the operand stack, value , must be a reference . To execute the ifnull instruction, the Java Virtual Machine pops value off the operand stack and compares it against null . If value is null ,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the ifnull opcode. The target address must be the address of an opcode within the same method as the ifnull opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not null , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the ifnull instruction.For more information about the ifnull instruction, see Chapter 16, "Control Flow."
Before:..., value1, value2
After: ...
The top two words of the operand stack, value1 and value2 , must be reference s. To execute the if_acmpeq instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 equals value2 (in other words, if they both point to exactly the same object or are both null ),
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the if_acmpeq opcode. The target address must be the address of an opcode within the same method as the if_acmpeq opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value does not equal value2 , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the if_acmpeq instruction.For more information about the if_acmpeq instruction, see Chapter 16, "Control Flow."
Before:..., value1, value2
After: ...
The top two words of the operand stack, value1 and value2 , must be reference s. To execute the if_acmpne instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 does not equal value2 (in other words, if they don t both point to exactly the same object and they aren t both null ),
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the if_acmpne opcode. The target address must be the address of an opcode within the same method as the if_acmpne opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value equals value2 , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the if_acmpne instruction.For more information about the if_acmpne instruction, see Chapter 16, "Control Flow."
Before:..., value1, value2
After: ...
The top two words of the operand stack, value1 and value2 , must be int s. To execute the if_icmpeq instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 equals value2 ,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the if_icmpeq opcode. The target address must be the address of an opcode within the same method as the if_icmpeq opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value does not equal value2 , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the if_icmpeq instruction.For more information about the if_icmpeq instruction, see Chapter 16, "Control Flow."
Before:..., value1, value2
After: ...
The top two words of the operand stack, value1 and value2 , must be int s. To execute the if_icmpge instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 is greater than or equal to value2 ,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the if_icmpge opcode. The target address must be the address of an opcode within the same method as the if_icmpge opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not greater than or equal to value2 , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the if_icmpge instruction.For more information about the if_icmpge instruction, see Chapter 16, "Control Flow."
Before:..., value1, value2
After: ...
The top two words of the operand stack, value1 and value2 , must be int s. To execute the if_icmpgt instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 is greater than value2 ,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the if_icmpgt opcode. The target address must be the address of an opcode within the same method as the if_icmpgt opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not greater than value2 , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the if_icmpgt instruction.For more information about the if_icmpgt instruction, see Chapter 16, "Control Flow."
Before:..., value1, value2
After: ...
The top two words of the operand stack, value1 and value2 , must be int s. To execute the if_icmple instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 is less than or equal to value2 ,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the if_icmple opcode. The target address must be the address of an opcode within the same method as the if_icmple opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not less than or equal to value2 , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the if_icmple instruction.For more information about the if_icmple instruction, see Chapter 16, "Control Flow."
Before:..., value1, value2
After: ...
The top two words of the operand stack, value1 and value2 , must be int s. To execute the if_icmplt instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 is less than value2 ,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the if_icmplt opcode. The target address must be the address of an opcode within the same method as the if_icmplt opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value is not less than value2 , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the if_icmplt instruction.For more information about the if_icmplt instruction, see Chapter 16, "Control Flow."
Before:..., value1, value2
After: ...
The top two words of the operand stack, value1 and value2 , must be int s. To execute the if_icmpne instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 does not equal value2 ,
The virtual machine forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the if_icmpne opcode. The target address must be the address of an opcode within the same method as the if_icmpne opcode. The virtual machine jumps to the target address and continues execution there. Otherwise, if value1 equals value2 , The virtual machine does not take the jump. It simply continues execution at the instruction immediately following the if_icmpne instruction.For more information about the if_icmpne instruction, see Chapter 16, "Control Flow."
No change
The index operand must specify a valid 8-bit unsigned index into the local variables of the current frame. To execute the iinc instruction, the Java Virtual Machine adds the 8-bit signed increment const to the local variable word specified by index.
Note that the wide instruction can precede the iinc instruction, to enable a local variable specified by a 16-bit unsigned offset to be incremented by a signed 16-bit constant.
For more information about the iinc instruction, see Chapter 12, "Integer Arithmetic."
Before:...
After: ..., value
The index operand, which serves as an 8-bit unsigned index into the local variables of the current frame, must specify a local variable word that contains an int . To execute the iload instruction, the Java Virtual Machine pushes onto the operand stack the int value contained in the local variable word specified by index .
Note that the wide instruction can precede the iload instruction, to allow a local variable to be accessed with a 16-bit unsigned offset.
For more information about the iload instruction, see Chapter 10, "Stack Operations."
Before: ..
After: ..., value
The local variable word at index zero must contain an int . To execute the iload_0 instruction, the Java Virtual Machine pushes onto the operand stack the int value contained in the local variable word zero.
For more information about the iload_0 instruction, see Chapter 10, "Stack Operations."
Before: ..
After: ..., value
The local variable word at index one must contain an int . To execute the iload_1 instruction, the Java Virtual Machine pushes onto the operand stack the int contained in the local variable word one.
For more information about the iload_1 instruction, see Chapter 10, "Stack Operations."
Before: ..
After: ..., value
The local variable word at index two must contain an int . To execute the iload_2 instruction, the Java Virtual Machine pushes onto the operand stack the int value contained in the local variable word two.
For more information about the iload_2 instruction, see Chapter 10, "Stack Operations."
Before: ..
After: ..., value
The local variable word at index three must contain an int . To execute the iload_3 instruction, the Java Virtual Machine pushes onto the operand stack the int value contained in the local variable word three.
For more information about the iload_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the imul instruction, the Java Virtual Machine pops value1 and value2 , multiplies them, and pushes the int result . If overflow occurs, result is the 32 lowest order bits of the true mathematical result represented in a sufficiently wide two s-complement format, and the sign of result may be different from that of the true mathematical result.
For more information about the imul instruction, see Chapter 12, "Integer Arithmetic."
Before: ..., value
After: ..., result
The top word of the operand stack, value , must be an int . To execute the ineg instruction, the Java Virtual Machine pops value , negates it, and pushes the int result .
The result produced by an ineg instruction is the same number that would be produced by subtracting value from zero with the isub instruction. As a consequence, when value is the smallest negative integer that can be represented by an int , the negation overflows. For this negation, the true mathematical result is one greater than the largest positive integer that can be represented by an int , and the actual result is equal to value with no change in sign.
For more information about the ineg instruction, see Chapter 12, "Integer Arithmetic."
Before:..., objectref
After: ..., result
The top word of the stack, objectref , must be a reference . To execute the instanceof instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Class_info entry. If it hasn t already, The virtual machine resolves the entry. The entry may be a class, interface, or array type. If objectref is not null and the object pointed to by objectref is an "instance of" the resolved type, The virtual machine pushes an int one result onto the operand stack. Otherwise, The virtual machine machine pushes an int zero result onto the operand stack.To determine whether the object pointed to by objectref is an "instance of" the resolved type, The virtual machine first determines whether the object is a class instance or array. (It can t be an interface instance, because interfaces can t be instantiated.) If it is a class instance, and the resolved type is a class, not an interface, the object is "an instance" of the resolved class if the object s class is the resolved class or a subclass of the resolved class. Else, if it is a class instance, and the resolved type is an interface, not an class, the object is "an instance" of the resolved interface if the object s class implements the resolved interface. Otherwise, the object is an array. If the resolved type is a class, it must be java.lang.Object . Else, if the resolved type is an array of primitive types, the object must be an array of the same primitive type. Otherwise, the resolved type must be an array with a component type of some reference type, and the object must be an array with a component type that is an "instance of" the component type of the resolved array type. (Note that the dimension of an array doesn t enter into the instanceof check, only the component type of the array.)
As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Class_info entry.
For more information about the instanceof instruction, see Chapter 15, "Objects and Arrays."
Before:..., objectref, [arg1, [arg2 ...]]
After: ...
To execute the invokeinterface instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_InterfaceMethodref_info entry. If it hasn t already, The virtual machine resolves the entry. The resolved method s descriptor must exactly match the descriptor of one of the methods declared in the resolved interface. The method must not be an instance initialization method, " <init ", or a class initialization method, " <clinit ."The nargs operand is an unsigned byte that indicates the number of words of parameters required by the method being invoked (including the hidden this reference). The operand stack must contain nargs - 1 words of parameters and the objectref word. The parameter words must match the order and type of parameters required by the resolved method. The objectref word, the reference to the object upon which to invoke the instance method, must be a reference . If the resolution is successful, The virtual machine pops nargs - 1 parameter words and objectref .
To invoke the method, The virtual machine retrieves the direct reference to the instance method to invoke from a method table. It locates the method table for the class of object pointed to by objectref and searches through it for a method with a name and descriptor that matches exactly the name and descriptor of the resolved method. (If the object s class is an array type, The virtual machine uses the method table for class java.lang.Object . An array type, of course, can only implement an interface if Object itself implements the interface.)
If the method is synchronized, the Java Virtual Machine, on behalf of the current thread, acquires the monitor associated with objectref .
If the method to invoke is not native, The virtual machine creates a new stack frame for the method and pushes the new stack frame onto the current thread s Java stack. The virtual machine then places the objectref word and nargs - 1 parameter words that it popped from the operand stack of the calling method s frame into the local variables of the new stack frame. It places objectref into local variable position zero, arg1 into local variable position one, and so on. ( objectref is the hidden this reference passed to all instance methods.) The virtual machine makes the new stack frame current, sets the program counter to the address of the first instruction in the new method, and continues execution there.
If the method to invoke is native, The virtual machine invokes the native method in an implementation-dependent manner.
As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_InterfaceMethodref_info entry. If no method exists in the object s class with the required name and descriptor, The virtual machine throws IncompatibleClassChangeError . Else, if the method exists but is static, The virtual machine throws IncompatibleClassChangeError . Else, if the method exists, but is not public, the virtual machine throws IllegalAccessError . Else, if the method is abstract, The virtual machine throws AbstractMethodError . Else, if the method is native and the native implementation of the method can t be loaded or linked, The virtual machine throws UnsatisfiedLinkError . Otherwise, if objectref is null , The virtual machine throws NullPointerException .
For more information about the invokeinterface instruction, see Chapter 19, "Method Invocation and Return."
Before:..., objectref, [arg1, [arg2 ...]]
After: ...
To execute the invokespecial instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Methodref_info entry. If it hasn t already, The virtual machine resolves the entry, which yields a direct reference to the method s data, including the number of words of parameters to the method, nargs . The resolved method s descriptor must exactly match the descriptor of one of the methods declared in the resolved class. The method must not be a class initialization method, " <clinit ."The invokespecial instruction is used to invoke three special kinds of instance methods: superclass methods, private methods, and instance initialization methods. invokespecial contrasts with invokevirtual in the way it invokes an instance method. Whereas invokevirtual always selects the method to invoke at run-time based on the class of the object (dynamic binding), invokespecial normally (with one exception) selects the method to invoke at compile-time based on the type of the reference (static binding).
The one exception to invokespecial s pure static binding behavior occurs if
o the resolved method is not private and is not an instance initialization method,
o the resolved method s class is a superclass of the current method s class,
o and the ACC_SUPER flag is set in the current method s class.
In this situation, the Java Virtual Machine dynamically selects at run-time the method to invoke by finding the method in the closest superclass that has a descriptor that exactly matches the resolved method s descriptor, irrespective of the class of the resolved method. In the majority of cases, the class of the selected method will most likely be the class of the resolved method anyway, but it is possible that it could be some other class.
For example, imagine you create an inheritance hierarchy of three classes: Animal , Dog , and CockerSpaniel . Assume class Dog extends class Animal , class CockerSpaniel extends class Dog , and that a method defined in CockerSpaniel uses invokespecial to invoke a non-private superclass method named walk() . Assume also that when you compiled CockerSpaniel , the compiler set the ACC_SUPER flag. In addition, assume that when you compiled CockerSpaniel , class Animal defined a walk() method, but Dog didn t. In that case, the symbolic reference from CockerSpaniel to the walk() method would give Animal as its class. When the invokespecial instruction in CockerSpaniel s method is executed, The virtual machine would dynamically select and invoke Animal s walk() method.
Now imagine that later, you added a walk() method to Dog , and recompiled Dog , but didn t recompile CockerSpaniel . CockerSpaniel s symbolic reference to the superclass walk() method still claims Animal as its class, even though there is now an implementation of walk() in Dog s class file. Nevertheless, when the invokespecial instruction in CockerSpaniel s method is executed, The virtual machine would dynamically select and invoke Dog s implementation of the walk() method.
This special (not static binding) treatment of superclass invocations was the motivation for adding the ACC_SUPER flag to the class access_flags item of class files, and for changing the name of this opcode from its original name, invokenonvirtual , to its current name, invokespecial . If the CockerSpaniel class of the previous example had been compiled by an old compiler that didn t set the ACC_SUPER flag, The virtual machine would invoke Animal s implementation of walk() regardless of whether Dog declared a walk() . As mentioned in Chapter 6, "The Java Class File," all new Java compilers should set the ACC_SUPER flag in every class file they generate.
If the resolved method is an instance initialization method, " <init ," the method must be invoked only once on each uninitialized (except to default initial values) object. In addition, an instance initialization method must be invoked on each uninitialized object before the first backwards branch. In other words, the bytecodes of a method need not call an <init method with invokespecial right after a new instruction. Other instructions could intervene between the new and the invokespecial for the <init , but none of those instructions may branch backwards (such as a goto to the beginning of the method).
The operand stack must contain nargs - 1 words of parameters and the objectref word. The parameter words must match the order and type of parameters required by the resolved method. The objectref word, the reference to the object upon which to invoke the instance method, must be a reference . If the resolution is successful, The virtual machine pops nargs - 1 parameter words and objectref .
If the method is synchronized, the Java Virtual Machine, on behalf of the current thread, acquires the monitor associated with objectref .
If the method to invoke is not native, The virtual machine creates a new stack frame for the method and pushes the new stack frame onto the current thread s Java stack. The virtual machine then places the objectref word and nargs - 1 parameter words that it popped from the operand stack of the calling method s frame into the local variables of the new stack frame. It places objectref into local variable position zero, arg1 into local variable position one, and so on. ( objectref is the hidden this reference passed to all instance methods.) The virtual machine makes the new stack frame current, sets the program counter to the address of the first instruction in the new method, and continues execution there.
If the method to invoke is native, The virtual machine invokes the native method in an implementation-dependent manner.
As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Methodref_info entry. As part of the process of resolving the CONSTANT_Methodref_info entry, The virtual machine checks whether the method s access permission enables the current class to access the method. If the method is protected, The virtual machine makes certain the method is a member of the either the current class or a superclass of the current class, and that the class of the object pointed to by objectref is either the current class or a subclass of the current class. If not (or if there is any other access permission problem), The virtual machine throws IllegalAccessError . Else, if the method exists and is accessible from the current class, but the method is static, The virtual machine throws IncompatibleClassChangeError . Else, if the method is abstract, The virtual machine throws AbstractMethodError . Else, if the method is native and the native implementation of the method can t be loaded or linked, The virtual machine throws UnsatisfiedLinkError . Otherwise, if objectref is null , The virtual machine throws NullPointerException .
For more information about the invokespecial instruction, see Chapter 19, "Method Invocation and Return."
Before:..., [arg1, [arg2 ...]
After: ...
To execute the invokestatic instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Methodref_info entry. If it hasn t already, The virtual machine resolves the entry, which yields a direct reference to the method s data, including the number of words of parameters to the method, nargs . The resolved method s descriptor must exactly match the descriptor of one of the methods declared in the resolved class. The method must not be an instance initialization method, " <init ", or a class initialization method, " <clinit ."The operand stack must contain nargs words of parameters. The parameter words must match the order and type of parameters required by the resolved method. If the resolution is successful, The virtual machine pops the nargs parameter words.
If the method is synchronized, the Java Virtual Machine, on behalf of the current thread, acquires the monitor associated with the Class instance that represents the resolved method s class.
If the method to invoke is not native, The virtual machine creates a new stack frame for the method and pushes the new stack frame onto the current thread s Java stack. The virtual machine then places the nargs parameter words that it popped from the operand stack of the calling method s frame into the local variables of the new stack frame. It places arg1 into local variable position zero, arg2 into local variable position one, and so on. The virtual machine makes the new stack frame current, sets the program counter to the address of the first instruction in the new method, and continues execution there.
If the method to invoke is native, The virtual machine invokes the native method in an implementation-dependent manner.
As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Methodref_info entry. As part of the process of resolving the CONSTANT_Methodref_info entry, The virtual machine checks whether the method s access permission enables the current class to access the method. If the method is protected, The virtual machine makes certain the method is a member of the either the current class or a superclass of the current class. If not (or if there is any other access permission problem), The virtual machine throws IllegalAccessError . Else, if the method exists and is accessible from the current class, but the method is not static, The virtual machine throws IncompatibleClassChangeError . Else, if the method is abstract, The virtual machine throws AbstractMethodError . Otherwise, if the method is native and the native implementation of the method can t be loaded or linked, The virtual machine throws UnsatisfiedLinkError .
For more information about the invokestatic instruction, see Chapter 19, "Method Invocation and Return."
Before:..., objectref, [arg1, [arg2 ...]]
After: ...
To execute the invokevirtual instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Methodref_info entry. If it hasn t already, The virtual machine resolves the entry, which yields the method s method table index, index , and the number of words of parameters to the method, nargs . The resolved method s descriptor must exactly match the descriptor of one of the methods declared in the resolved class. The method must not be an instance initialization method, " <init ", or a class initialization method, " <clinit ."The operand stack must contain nargs - 1 words of parameters and the objectref word. The parameter words must match the order and type of parameters required by the resolved method. The objectref word, the reference to the object upon which to invoke the instance method, must be a reference . If the resolution is successful, The virtual machine pops nargs - 1 parameter words and objectref .
To invoke the method, The virtual machine retrieves the direct reference to the instance method to invoke from a method table. It locates the method table for the class of object pointed to by objectref and looks up the direct reference that occupies method table position index . (If the object s class is an array type, The virtual machine uses the method table for class java.lang.Object .)
If the method is synchronized, the Java Virtual Machine, on behalf of the current thread, acquires the monitor associated with objectref .
If the method to invoke is not native, The virtual machine creates a new stack frame for the method and pushes the new stack frame onto the current thread s Java stack. The virtual machine then places the objectref word and nargs - 1 parameter words that it popped from the operand stack of the calling method s frame into the local variables of the new stack frame. It places objectref into local variable position zero, arg1 into local variable position one, and so on. ( objectref is the hidden this reference passed to all instance methods.) The virtual machine makes the new stack frame current, sets the program counter to the address of the first instruction in the new method, and continues execution there.
If the method to invoke is native, The virtual machine invokes the native method in an implementation-dependent manner.
As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Methodref_info entry. As part of the process of resolving the CONSTANT_Methodref_info entry, The virtual machine checks whether the method s access permission enables the current class to access the method. If the method is protected, The virtual machine makes certain the method is a member of the either the current class or a superclass of the current class, and that the class of the object pointed to by objectref is either the current class or a subclass of the current class. If not (or if there is any other access permission problem), The virtual machine throws IllegalAccessError . Else, if the method exists and is accessible from the current class, but the method is static, The virtual machine throws IncompatibleClassChangeError . Else, if the method is abstract, The virtual machine throws AbstractMethodError . Else, if the method is native and the native implementation of the method can t be loaded or linked, The virtual machine throws UnsatisfiedLinkError . Otherwise, if objectref is null , The virtual machine throws NullPointerException .
For more information about the invokevirtual instruction, see Chapter 19, "Method Invocation and Return."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the ior instruction, the Java Virtual Machine pops value1 and value2 , bitwise ORs them, and pushes the int result .
For more information about the ior instruction, see Chapter 13, "Logic."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the irem instruction, the Java Virtual Machine pops value1 and value2 , calculates the integer remainder, and pushes the int result . The integer remainder equals value1 - (value1 / value2) * value2 .
The irem instruction implements Java s remainder operator: % . The irem behaves such that the Java expression shown below is always true , where n and d are any two int s:
begin
(n/d)*d + (n%d) == n
end
This behavior means that the result of an irem instruction always takes the same sign as the numerator, which is popped off the operand stack as value1 .
If value2 (the denominator) is zero, the Java Virtual Machine throws ArithmeticException .
For more information about the irem instruction, see Chapter 12, "Integer Arithmetic."
Before: ..., value
After: [empty]
The return type of the returning method must be byte , short , int , or char . The top word of the operand stack, value , must be an int . To execute the ireturn instruction, the Java Virtual Machine pops int value from the operand stack of the current frame and pushes it onto the operand stack of the invoking method s frame. The virtual machine discards any other words that may still be on the returning method s frame. If the returning method is synchronized, the monitor that was acquired when the method was invoked is released. The invoking method s frame is made current, and The virtual machine continues execution in the invoking method.
For more information about the ireturn instruction, see Chapter 19, "Method Invocation and Return." For more information about monitors, see Chapter 20, "Thread Synchronization."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the ishl instruction, the Java Virtual Machine pops value1 and value2 , shifts value1 left by the number of bits specified in the 5 lowest order bits of value2 (from 0 to 31 bit positions ), and pushes the int result .
For more information about the ishl instruction, see Chapter 13, "Logic."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the ishr instruction, the Java Virtual Machine pops value1 and value2 , shifts value1 right with sign extension by the number of bits specified in the 5 lowest order bits of value2 (from 0 to 31 bit positions), and pushes the int result .
For more information about the ishr instruction, see Chapter 13, "Logic."
Before:..., value
After: ...
The index operand must specify a valid 8-bit unsigned index into the local variables of the current frame. The value word on the top of the operand stack must be an int . To execute the istore instruction, the Java Virtual Machine pops the int value from the top of the operand stack and stores it into the local variable word specified by index .
Note that the wide instruction can precede the istore instruction, to enable a value to be stored into a local variable specified by a 16-bit unsigned offset.
For more information about the istore instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index zero must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be an int . To execute the istore_0 instruction, the Java Virtual Machine pops the int value from the top of the operand stack and stores it into the local variable word at index zero.
For more information about the istore_0 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index one must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be an int . To execute the istore_1 instruction, the Java Virtual Machine pops the int value from the top of the operand stack and stores it into the local variable word at index one.
For more information about the istore_1 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index two must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be an int . To execute the istore_2 instruction, the Java Virtual Machine pops the int value from the top of the operand stack and stores it into the local variable word at index two.
For more information about the istore_2 instruction, see Chapter 10, "Stack Operations."
Before: ..., value
After: ...
The index three must be a valid index into the local variables of the current stack frame, and the value word on the top of the operand stack must be an int . To execute the istore_3 instruction, the Java Virtual Machine pops the int value from the top of the operand stack and stores it into the local variable word at index three.
For more information about the istore_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the isub instruction, the Java Virtual Machine pops value1 and value2 , subtracts value2 from value1 ( value1 - value2 ), and pushes the int result . If overflow occurs, result is the 32 lowest order bits of the true mathematical result represented in a sufficiently wide two s-complement format, and the sign bit of result may be different from the true mathematical result.
For more information about the isub instruction, see Chapter 12, "Integer Arithmetic."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the iushr instruction, the Java Virtual Machine pops value1 and value2 , shifts value1 right with zero extension by the number of bits specified in the 5 lowest order bits of value2 (from 0 to 31 bit positions), and pushes the int result .
For more information about the iushr instruction, see Chapter 13, "Logic."
Before: ..., value1, value2
After: ..., result
The top two words of the operand stack, value1 and value2 , must be int s. To execute the ixor instruction, the Java Virtual Machine pops value1 and value2 , bitwise exclusive ORs them, and pushes the int result .
For more information about the ixor instruction, see Chapter 13, "Logic."
Before:...
After: ..., address
To execute the jsr instruction, the Java Virtual Machine pushes the (program counter) address of the opcode immediately following the jsr instruction, the address word, onto the operand stack.
The virtual machine then forms a signed 16-bit offset by calculating (branchbyte1 8) | branchbyte2 . It calculates a target (program counter) address by adding the calculated offset to the address of the jsr opcode. The target address must be the address of an opcode within the same method as the jsr opcode. The virtual machine jumps to the target address and continues execution there.For more information about the jsr instruction, see Chapter 18, "Finally Clauses."
Before:...
After: ..., address
To execute the jsr_w instruction, the Java Virtual Machine pushes the (program counter) address of the opcode immediately following the jsr_w instruction, the address word, onto the operand stack.
The virtual machine then forms a signed 32-bit offset by calculating (branchbyte1 24) | (branchbyte2 16) | (branchbyte3 8) | branchbyte4 . The virtual machine then calculates a target (program counter) address by adding the calculated offset to the address of the jsr_w opcode. The target address must be the address of an opcode within the same method as the jsr_w opcode. The virtual machine jumps to the target address and continues execution there.Note that despite the 32-bit offset of the jsr_w instruction, Java methods are currently (in both the 1.0 and 1.1 releases) limited to 65,535 bytes by three items in the Java class file format: the sizes of the indexes in the LineNumberTable attribute, the LocalVariableTable attribute, and the Code attribute s exception_table item. According to the Java Virtual Machine specification, the 65,536 byte limit to Java methods may be raised in a future release. For more information about the jsr_w instruction, see Chapter 18, "Finally Clauses."
Before: ..., value.word1, value.word2
After: ..., result.word1, result.word2
The top two words of the operand stack must be a long . To execute the l2d instruction, the Java Virtual Machine pops the long value from the operand stack, converts the long to a double using the IEEE round-to-nearest mode, and pushes the double result .
Note that this instruction performs a widening primitive conversion. Because not all long values are exactly representable by a double , the conversion may result in a loss of precision.
For more information about the l2d instruction, see Chapter 11, "Type Conversion."
Before: ..., value.word1, value.word2
After: ..., result
The top two words of the operand stack must be a long . To execute the l2f instruction, the Java Virtual Machine pops the long value from the operand stack, converts the long to a float using the IEEE round-to-nearest mode, and pushes the float result .
Note that this instruction performs a widening primitive conversion. Because not all long values are exactly representable by a float , the conversion may result in a loss of precision.
For more information about the l2f instruction, see Chapter 11, "Type Conversion."
Before: ..., value.word1, value.word2
After: ..., result
The top two words of the operand stack must be a long . To execute the l2i instruction, the Java Virtual Machine pops long value from the operand stack, truncates the long to a int , and pushes the int result .
Note that this instruction performs a narrowing primitive conversion. As a result of this conversion, magnitude information may be lost and the sign bit may change.
For more information about the l2i instruction, see Chapter 11, "Type Conversion."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two long s, value1 and value2 . To execute the ladd instruction, the Java Virtual Machine pops value1 and value2 , adds them, and pushes the long result . If overflow occurs, result is the 64 lowest order bits of the true mathematical result represented in a sufficiently wide two s-complement format, and the sign of result is different from that of the true mathematical result.
For more information about the ladd instruction, see Chapter 12, "Integer Arithmetic."
Before: ..., arrayref, index
After: ..., value.word1, value.word2
To execute the laload instruction, the Java Virtual Machine first pops two words from the operand stack. The arrayref word must be a reference that refers to an array of long s. The index word must be an int . The virtual machine retrieves from the arrayref array the long value specified by index and pushes it onto the operand stack.
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, The virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the laload instruction, see Chapter 15, "Objects and Arrays."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two long s, value1 and value2 . To execute the land instruction, the Java Virtual Machine pops value1 and value2 , bitwise ANDs them, and pushes the long result .
For more information about the land instruction, see Chapter 13, "Logic."
Before: ..., arrayref, index, value.word1, value.word2
After: ...
To execute the laload instruction, the Java Virtual Machine first pops four words from the operand stack. The arrayref word must be a reference that refers to an array of long s. The index word must be an int , and the value words must be a long . The virtual machine stores long value into the arrayref array location specified by index .
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, The virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the lastore instruction, see Chapter 15, "Objects and Arrays."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result
The top four words of the operand stack must be two long s, value1 and value2 . To execute the lcmp instruction, the Java Virtual Machine pops value1 and value2 off the operand stack and compares one against the other. If value1 equals value2 , The virtual machine pushes onto the operand stack int result zero. Else, if value1 is greater than value2 , The virtual machine pushes onto the operand stack int result one. Otherwise, if value1 is less than value2 , The virtual machine pushes onto the operand stack int result negative one.
For more information about the lcmp instruction, see Chapter 16, "Control Flow."
Before: ...
After: ..., <0-word1, <0-word2
To execute the lconst_0 instruction, the Java Virtual Machine pushes the long constant 0 onto the operand stack.
For more information about the lconst_0 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., <1-word1, <1-word2
To execute the lconst_1 instruction, the Java Virtual Machine pushes the long constant 1 onto the operand stack.
For more information about the lconst_1 instruction, see Chapter 10, "Stack Operations."
Before:...
After: ..., item
The index operand must be a valid unsigned 8-bit index into the current constant pool. To execute the ldc instruction, the Java Virtual Machine first looks up the constant pool entry specified by the index operand. At constant pool entry index ,
The virtual machine must find either a CONSTANT_Integer_info , CONSTANT_Float_info , or CONSTANT_String_info entry. If it hasn t already, The virtual machine resolves the entry. If the entry is a CONSTANT_Integer_info , The virtual machine pushes the int value represented by the entry onto the operand stack. Else, if the entry is a CONSTANT_Float_info , The virtual machine pushes the float value represented by the entry onto the operand stack. Otherwise, the entry is a CONSTANT_String_info entry, and The virtual machine pushes a reference to the interned String object that was produced by the process of resolving the entry onto the operand stack.Note that the ldc_w instruction performs the same function, but offers a wide (16-bit) constant pool index.
For more information about the ldc instruction, see Chapter 10, "Stack Operations."
Before:...
After: ..., item
To execute the ldc_w instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be either a CONSTANT_Integer_info , a CONSTANT_Float_info , or a CONSTANT_String_info entry. If it hasn t already, The virtual machine resolves the entry. If the entry is a CONSTANT_Integer_info , The virtual machine pushes the int value represented by the entry onto the operand stack. Else, if the entry is a CONSTANT_Float_info , The virtual machine pushes the float value it represents onto the operand stack. Otherwise, the entry is a CONSTANT_String_info , and The virtual machine pushes a reference to the interned String object that was produced by the process of resolving the entry onto the operand stack.Note that the ldc_w instruction performs the same function as ldc , but offers a wide (16-bit) constant pool index as opposed to ldc s 8-bit constant pool index.
For more information about the ldc_w instruction, see Chapter 10, "Stack Operations."
Before:...
After: ..., item.word1, item.word2
To execute the ldc2_w instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be either a CONSTANT_Long_info or CONSTANT_Double_info entry. The virtual machine resolves the entry. If the entry is a CONSTANT_Long_info , The virtual machine pushes the long value represented by the entry onto the operand stack. Otherwise, it is a CONSTANT_Double_info entry, and The virtual machine pushes the double value represented by the entry onto the operand stack.Note that there is no " ldc2 " instruction that performs the same function as ldc2_w but with an 8-bit constant pool index. All two-word constants must be retrieved from the constant pool with an ldc2_w instruction, which has a wide (16-bit) constant pool index.
For more information about the ldc2_w instruction, see Chapter 10, "Stack Operations."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two long s, value1 and value2 . To execute the ldiv instruction, the Java Virtual Machine pops value1 and value2 , integer divides value1 by value2 ( value1 / value2 ), and pushes the long result .
Integer division rounds the magnitude of the true mathematical quotient towards zero to the nearest integer. If the magnitude of the denominator is greater than that of the numerator, the long result is zero. Else, with one special exception, the sign of result is positive if the signs of the numerator and denominator are the same, negative if they are different. The exception to this rule is when the numerator is the smallest negative integer that can be represented by a long and the denominator is -1. For this division, the true mathematical result is one greater than the largest positive integer that can be represented by a long . As a consequence, the division overflows and the result is equal to the numerator.
If value2 (the denominator) is zero, the Java Virtual Machine throws ArithmeticException .
For more information about the ldiv instruction, see Chapter 12, "Integer Arithmetic."
Before:...
After: ..., value.word1, value.word2
The index operand, which serves as an 8-bit unsigned index into the local variables of the current frame, must specify the first of two consecutive local variable words that contain a long . To execute the lload instruction, the Java Virtual Machine pushes onto the operand stack the long contained in the two consecutive local variable words specified by index and index + 1 .
Note that the wide instruction can precede the lload instruction, to allow a local variable to be accessed with a 16-bit unsigned offset.
For more information about the lload instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value.word1, value.word2
The two consecutive local variable words at indexes zero and one must contain a long . To execute the lload_0 instruction, the Java Virtual Machine pushes onto the operand stack the long value contained in local variable words zero and one.
For more information about the lload_0 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value.word1, value.word2
The two consecutive local variable words at indexes one and two must contain a long . To execute the lload_1 instruction, the Java Virtual Machine pushes onto the operand stack the long value contained in local variable words one and two.
For more information about the lload_1 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value.word1, value.word2
The two consecutive local variable words at indexes two and three must contain a long . To execute the lload_2 instruction, the Java Virtual Machine pushes onto the operand stack the long value contained in local variable words two and three.
For more information about the lload_2 instruction, see Chapter 10, "Stack Operations."
Before: ...
After: ..., value.word1, value.word2
The two consecutive local variable words at indexes three and four must contain a long . To execute the lload_3 instruction, the Java Virtual Machine pushes onto the operand stack the long value contained in local variable words three and four.
For more information about the lload_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two long s, value1 and value2 . To execute the lmul instruction, the Java Virtual Machine pops value1 and value2 , multiplies them, and pushes the long result . If overflow occurs, result is the 64 lowest order bits of the true mathematical result represented in a sufficiently wide two s-complement format, and the sign of result may be different from that of the true mathematical result.
For more information about the lmul instruction, see Chapter 12, "Integer Arithmetic."
Before: ..., value.word1, value.word2
After: ..., result.word1, result.word2
The top two words of the operand stack must be a long , value . To execute the lneg instruction, the Java Virtual Machine pops value , negates it, and pushes the long result .
The result produced by an lneg instruction is the same number that would be produced by subtracting value from zero with the lsub instruction. As a consequence, when value is the smallest negative integer that can be represented by an long , the negation overflows. For this negation, the true mathematical result is one greater than the largest positive integer that can be represented by an long , and the actual result is equal to value with no change in sign.
For more information about the lneg instruction, see Chapter 12, "Integer Arithmetic."
Before:..., key
After: ...
The lookupswitch
opcode is followed by zero to three bytes of padding--enough so that the byte immediately following the padding starts at an address that is a multiple of four bytes from the beginning of the method. Each padding byte is a zero. Immediately following the padding is a signed 32-bit default branch offset, default . Following default is npairs , a signed count of the number of case value/branch offset pairs embedded in this lookupswitch instruction. The value of
npairs must be greater than or equal to zero. Following npairs are the case value/branch offset pairs themselves . For each pair, the signed 32-bit case value, match , precedes the signed 32-bit branch offset, offset .
The top word of the operand stack, key , must be an int . To execute the lookupswitch instruction, the Java Virtual Machine pops
key off the operand stack and compares it to the match values. If the key is equal to one of the match values, The virtual machine calculates a target (program counter) address by adding the signed offset that corresponds to the matching match value to the address of the lookupswitch opcode. The target address must be the address of an opcode within the same method as the lookupswitch opcode. The virtual machine jumps to the target address and continues execution there.
For more information about the lookupswitch instruction, see Chapter 16, "Control Flow."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two long s, value1 and value2 . To execute the lor instruction, the Java Virtual Machine pops value1 and value2 , bitwise ORs them, and pushes the long result .
For more information about the lor instruction, see Chapter 13, "Logic."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two long s, value1 and value2 . To execute the lrem instruction, the Java Virtual Machine pops value1 and value2 , calculates the integer remainder, and pushes the long result . The integer remainder equals value1 - (value1 / value2) * value2 .
The lrem instruction implements Java s remainder operator, % , on long s. The lrem behaves such that the Java expression shown below is always true , where n and d are any two long s:
begin
(n/d)*d + (n%d) == n
end
This behavior means that the result of an lrem instruction always takes the same sign as the numerator, which is popped off the operand stack as value1 .
If value2 (the denominator) is zero, the Java Virtual Machine throws ArithmeticException .
For more information about the lrem instruction, see Chapter 12, "Integer Arithmetic."
Before: ..., value.word1, value.word2
After: [empty]
The return type of the returning method must be long . The top two words of the operand stack must be a long . To execute the lreturn instruction, the Java Virtual Machine pops the long value from the operand stack of the current frame and pushes it onto the operand stack of the invoking method s frame. The virtual machine discards any other words that may still be on the returning method s frame. If the returning method is synchronized, the monitor that was acquired when the method was invoked is released. The invoking method s frame is made current, and The virtual machine continues execution in the invoking method.
For more information about monitors, see Chapter 20, "Thread Synchronization." For more information about the lreturn instruction, see Chapter 19, "Method Invocation and Return."
Before: ..., value1.word1, value1.word2, value2
After: ..., result.word1, result.word2
The top word of the operand stack, value2 , must be an int . The next two words down must be a long , value1 . To execute the lshl instruction, the Java Virtual Machine pops value1 and value2 , shifts value1 left by the number of bits specified in the 6 lowest order bits of value2 (from 0 to 63 bit positions), and pushes the long result .
For more information about the lshl instruction, see Chapter 13, "Logic."
Before: ..., value1.word1, value1.word2, value2
After: ..., result.word1, result.word2
The top word of the operand stack, value2 , must be an int . The next two words down must be a long , value1 . To execute the lshr instruction, the Java Virtual Machine pops value1 and value2 , shifts value1 right with sign extension by the number of bits specified in the 6 lowest order bits of value2 (from 0 to 63 bit positions), and pushes the long result .
For more information about the lshr instruction, see Chapter 13, "Logic."
Before:..., value.word1, value.word2
After: ...
The index operand must specify a valid 8-bit unsigned index into the local variables of the current frame. The top two words of the operand stack must be a long . To execute the lstore instruction, the Java Virtual Machine pops the long value from the top of the operand stack and stores it into the two consecutive local variable words at indexes index and index + 1 .
Note that the wide instruction can precede the lstore instruction, to enable a value to be stored into a local variable specified by a 16-bit unsigned offset.
For more information about the lstore instruction, see Chapter 10, "Stack Operations."
Before: ..., value.word1, value.word2
After: ...
The indexes zero and one must be valid indexes into the local variables of the current stack frame. The top two words on the operand stack must be a long . To execute the lstore_0 instruction, the Java Virtual Machine pops the long value from the top of the operand stack and stores it into the two consecutive local variable words at indexes zero and one.
For more information about the lstore_0 instruction, see Chapter 10, "Stack Operations."
Before: ..., value.word1, value.word2
After: ...
The indexes one and two must be valid indexes into the local variables of the current stack frame. The top two words on the operand stack must be a long . To execute the lstore_1 instruction, the Java Virtual Machine pops the long value from the top of the operand stack and stores it into the two consecutive local variable words at indexes one and two.
For more information about the lstore_1 instruction, see Chapter 10, "Stack Operations."
Before: ..., value.word1, value.word2
After: ...
The indexes two and three must be valid indexes into the local variables of the current stack frame. The top two words on the operand stack must be a long . To execute the lstore_2 instruction, the Java Virtual Machine pops the long value from the top of the operand stack and stores it into the two consecutive local variable words at indexes two and three.
For more information about the lstore_2 instruction, see Chapter 10, "Stack Operations."
Before: ..., value.word1, value.word2
After: ...
The indexes three and four must be valid indexes into the local variables of the current stack frame. The top two words on the operand stack must be a long . To execute the lstore_3 instruction, the Java Virtual Machine pops the long value from the top of the operand stack and stores it into the two consecutive local variable words at indexes three and four.
For more information about the lstore_3 instruction, see Chapter 10, "Stack Operations."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two long s, value1 and value2 . To execute the lsub instruction, the Java Virtual Machine pops value1 and value2 , subtracts value2 from value1 ( value1 - value2 ), and pushes the long result . If overflow occurs, result is the 64 lowest order bits of the true mathematical result represented in a sufficiently wide two s-complement format, and the sign bit of result is different from the true mathematical result.
For more information about the lsub instruction, see Chapter 12, "Integer Arithmetic."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top word of the operand stack, value2 , must be an int . The next two words down must be a long , value1 . To execute the lushr instruction, the Java Virtual Machine pops value1 and value2 , shifts value1 right with zero extension by the number of bits specified in the 6 lowest order bits of value2 (from 0 to 63 bit positions), and pushes the long result .
For more information about the lushr instruction, see Chapter 13, "Logic."
Before: ..., value1.word1, value1.word2, value2.word1, value2.word2
After: ..., result.word1, result.word2
The top four words of the operand stack must be two long s, value1 and value2 . To execute the lxor instruction, the Java Virtual Machine pops value1 and value2 , bitwise exclusive ORs them, and pushes the long result .
For more information about the lxor instruction, see Chapter 13, "Logic."
Before: ..., objectref
After: ...
The top word of the operand stack, objectref , must be a reference .To execute the monitorenter instruction, the Java Virtual Machine pops objectref and, on behalf of the current thread, acquires the monitor associated with objectref .
If the objectref word is null ,
The virtual machine throws NullPointerException .For more information about the monitorenter instruction, see Chapter 20, "Thread Synchronization."
Before: ..., objectref
After: ...
The top word of the operand stack, objectref , must be a reference .To execute the monitorenter instruction, the Java Virtual Machine pops objectref and, on behalf of the current thread, releases and exits the monitor associated with objectref .
If the objectref word is null , The virtual machine throws NullPointerException .
For more information about the monitorexit instruction, see Chapter 20, "Thread Synchronization."
Before:..., count1, [count2,...]
After: arrayref
The dimensions operand, an unsigned byte that indicates the number of dimensions in the array to create, must be greater than or equal to one. The top dimensions words of the operand stack, count1, [count2,...] , must contain int s that have nonnegative values. Each of these words gives the number of elements in one dimension of the array. For example, consider an array declared as:
begin cc .
int[][][] example = new int[3][4][5];
end
For this array, dimensions would be equal to three and the operand stack would contain three "count" words. The count1 word would be three, count2 four, and count3 five.
To execute the multianewarray instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Class_info entry. If it hasn t already, The virtual machine resolves the entry. The entry must be an array type of dimensionality greater than or equal to dimensions .If the resolution is successful, the Java Virtual Machine creates the dimensions -dimensional array on the heap. The virtual machine initializes the elements of the first-dimension array with references to the second-dimension arrays; it initializes the elements of each of the second-dimension array with references to the third-dimension arrays, and so on. The virtual machine initializes the elements of the last-dimension arrays with their default initial values. Lastly, the Java Virtual Machine pushes a reference to the new dimensions -dimensional array onto the operand stack.
As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Class_info entry. If resolution succeeds and the array s component type is a reference type, but the current class does not have permission to access that reference type, The virtual machine throws IllegalAccessError . Otherwise, if any of the counts popped off of the operand stack have a negative value, the Java Virtual Machine throws NegativeArraySizeException .
Note that the dimensionality of the array type specified in the resolved CONSTANT_Class_info entry need not be equal to the dimensions operand--it can also be greater than dimensions . For example, the name of the array class for a three-dimensional array of int s is " [[[I ." The actual constant pool entry referenced by a multianewarray instruction that creates a three-dimensional array of int s must have at least three dimensions, but may have more. For instance, resolved array types of " [[[I ," " [[[[I ," and " [[[[[[[[I " would all yield three-dimensional arrays of int so long as the dimensions operand is three. This flexibility in specifying multidimensional array types to the multianewarray instruction can reduce the number of entries required in the constant pool of some classes.
For more information about the multianewarray instruction, see Chapter 15, "Objects and Arrays."
Before:...
After: ..., objectref
To execute the new instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Class_info entry. If it hasn t already, The virtual machine resolves the entry. The entry must be a class type, not an interface or array type. The virtual machine allocates sufficient memory from the heap for the new object s image, and sets the object s instance variables to their default initial values. Lastly, The virtual machine pushes objectref , a reference to the new object, onto the operand stack.As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Class_info entry. If resolution succeeds, but the resolved type is an interface, abstract class, or array, The virtual machine throws an InstantiationError . Else, if the current class doesn t have permission to access the resolved class, The virtual machine throws an IllegalAccessError .
For more information about the new instruction, see Chapter 15, "Objects and Arrays."
Before:..., count
After: arrayref
The top word of the operand stack, count , must be an int . The atype operand, which is used to indicate the array type, must take one of the values shown in Table A-2. To execute the newarray instruction, the Java Virtual Machine pops count and creates on the heap an array of size count of the primitive type specified by atype .
The virtual machine initializes each array element to its default initial value and pushes arrayref , a reference to the new array, onto the operand stack.Table A-2. Values for atype
2 columns
Array Type atype
T_BOOLEAN 4
T_CHAR 5
T_FLOAT 6
T_DOUBLE 7
T_BYTE 8
T_SHORT 9
T_INT 10
T_LONG 11
end table
If count is less than zero, the Java Virtual Machine throws NegativeArraySizeException .
For more information about the newarray instruction, see Chapter 15, "Objects and Arrays."
No change
To execute the nop instruction, the Java Virtual Machine takes a coffee break.
For more information about the nop instruction, see Chapter 10, "Stack Operations."
Before: ..., word
After: ...
To execute the pop instruction, the Java Virtual Machine pops the top word from the operand stack. This instruction can be used to pop any single-word value from the top of the operand stack. It must not be used to remove half of a dual word value ( long or double ) from the top of the operand stack.
For more information about the pop instruction, see Chapter 10, "Stack Operations."
Before: ..., word2, word1
After: ...
To execute the pop2 instruction, the Java Virtual Machine pops the top two words from the operand stack. This instruction can be used to pop any dual-word value from the top of the operand stack, or any two single-word values. It must not be used to remove one single-word value and half of a dual word value ( long or double ) from the top of the operand stack.
For more information about the pop2 instruction, see Chapter 10, "Stack Operations."
Before:..., objectref, value
After: ...
or
Before: ..., objectref, value.word1, value.word2
After: ...
To execute the putfield instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Fieldref_info entry. If it hasn t already, The virtual machine resolves the entry, which yields the field s width and the field s offset from the beginning of the object image.The type of the single or double-word value occupying the top of the stack must be compatible with the descriptor of the resolved field. If the resolved field s descriptor is byte , short , char , boolean , or int , the type of value must be int . If the resolved field s descriptor is long , the type of value must be long . If the resolved field s descriptor is float , the type of value must be float . If the resolved field s descriptor is double , the type of value must be double . If the resolved field s descriptor is a reference type, the type of value must be reference and must be assignment-compatible the resolved descriptor type. The objectref word must be a reference .
The virtual machine pops value and objectref and assigns value to the appropriate field in the object pointed to by objectref .
As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Fieldref_info entry. As part of the process of resolving the CONSTANT_Fieldref_info entry, The virtual machine checks whether the field s access permission enables the current class to access the field. If the field is protected, The virtual machine makes certain the field is a member of the either the current class or a superclass of the current class, and that the class of the object pointed to by objectref is either the current class or a subclass of the current class. If not (or if there is any other access permission problem), The virtual machine throws IllegalAccessError . Else, if the field exists and is accessible from the current class, but the field is static, The virtual machine throws IncompatibleClassChangeError . Otherwise, if objectref is null , The virtual machine throws NullPointerException .
For more information about the putfield instruction, see Chapter 15, "Objects and Arrays."
Before:..., value
After: ...
or
Before: ..., value.word1, value.word2
After: ...
To execute the putstatic instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the constant pool by calculating (indexbyte1 8) | indexbyte2 .
The virtual machine then looks up the constant pool entry specified by the calculated index. The constant pool entry at that index must be a CONSTANT_Fieldref_info entry. If it hasn t already, The virtual machine resolves the entry.The type of the single or double-word value occupying the top of the stack must be compatible with the descriptor of the resolved field. If the resolved field s descriptor is byte , short , char , boolean , or int , the type of value must be int . If the resolved field s descriptor is long , the type of value must be long . If the resolved field s descriptor is float , the type of value must be float . If the resolved field s descriptor is double , the type of value must be double . If the resolved field s descriptor is a reference type, the type of value must be reference and must be assignment-compatible the resolved descriptor type.
The virtual machine pops and assigns value to the appropriate static field.
As a result of executing this instruction, The virtual machine may throw any of the linking errors listed in Chapter 8, "The Linking Model," as possible during resolution of a CONSTANT_Fieldref_info entry. As part of the process of resolving the CONSTANT_Fieldref_info entry, The virtual machine checks whether the field s access permission enables the current class to access the field. If the field is protected, The virtual machine makes certain the field is a member of the either the current class or a superclass of the current class. If not (or if there is any other access permission problem), The virtual machine throws IllegalAccessError . Else, if the field exists and is accessible from the current class, but the field is not static, The virtual machine throws IncompatibleClassChangeError .
For more information about the putstatic instruction, see Chapter 15, "Objects and Arrays."
No change
The index operand is an 8-bit unsigned offset into the local variables. The local variable word specified by index must be a returnAddress . To execute the ret instruction, the Java Virtual Machine sets the program counter to the returnAddress value stored in local variable index, and continues execution there. (In other words,
The virtual machine jumps to the returnAddress .)Note that the wide instruction can precede the ret instruction, to allow a local variable to be accessed with a 16-bit unsigned offset.
For more information about the ret instruction, see Chapter 18, "Finally Clauses."
Before: ...
After: [empty]
The return type of the returning method must be void .To execute the return instruction, the Java Virtual Machine discards any words that may still be on the returning method s frame. If the returning method is synchronized, the monitor that was acquired when the method was invoked is released. The invoking method s frame is made current, and The virtual machine continues execution in the invoking method.
For more information about monitors, see Chapter 20, "Thread Synchronization." For more information about the return instruction, see Chapter 19, "Method Invocation and Return."
Before: ..., arrayref, index
After: ..., value
To execute the saload instruction, the Java Virtual Machine first pops two words from the operand stack. The arrayref word must be a reference that refers to an array of short s. The index word must be an int . The virtual machine retrieves from the arrayref array the short value specified by index , sign-extends it to an int , and pushes it onto the operand stack.
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, The virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the saload instruction, see Chapter 15, "Objects and Arrays."
Before: ..., array, index, value
After: ...
To execute the sastore instruction, the Java Virtual Machine first pops three words from the operand stack. The arrayref word must be a reference that refers to an array of short s. The index and value words must be int s. The virtual machine truncates the int value to a short and stores it into the arrayref array location specified by index .
If arrayref is null , the Java Virtual Machine throws NullPointerException . Otherwise, if index is not a legal index into the arrayref array, The virtual machine throws ArrayIndexOutOfBoundsException .
For more information about the sastore instruction, see Chapter 15, "Objects and Arrays."
Before:...
After: ..., value
To execute the sipush instruction, the Java Virtual Machine first forms an intermediate 16-bit signed integer from byte1 and byte2 by calculating (byte1 8) | byte2 .
The virtual machine then sign-extends the intermediate 16-bit signed integer to an int , and pushes the resulting int value onto the operand stack.For more information about the sipush instruction, see Chapter 10, "Stack Operations."
Before: ..., word2, word1
After: ..., word1, word2
To execute the swap instruction, the Java Virtual Machine swaps the top two words of the operand stack. Both word1 and word2 must be single-word values.
For more information about the swap instruction, see Chapter 10, "Stack Operations."
Before:..., index
After: ...
The tableswitch
opcode is followed by zero to three bytes of padding--enough so that the byte immediately following the padding starts at an address that is a multiple of four bytes from the beginning of the method. Each padding byte is a zero. Immediately following the padding is a signed 32-bit default branch offset, default . Following default are two signed 32-bit endpoints of the range of case values embedded in this tableswitch instruction:
low , the low endpoint, and high , the high endpoint . The value of
low must be less than or equal to the value of high . Following low and high are high - low + 1 signed 32-bit branch offsets--one branch offset for high, one for low, and one for each integer case value in between high and low. These offsets serve as a zero-based jump table. The branch offset for low , the first entry in the jump table, immediately follows the high endpoint value.
The top word of the operand stack, index , must be an int . To execute the tableswitch instruction, the Java Virtual Machine pops
index off the operand stack, compares it to low and high , and selects a branch offset. If index is less than low and greater than high , The virtual machine selects default as the branch offset. Else, The virtual machine selects the branch offset at position index - low in the jump table. Once it has selected a branch offset, The virtual machine calculates a target (program counter) address by adding the signed branch offset to the address of the tableswitch opcode. The target address must be the address of an opcode within the same method as the tableswitch opcode. The virtual machine jumps to the target address and continues execution there.
For more information about the tableswitch instruction, see Chapter 16, "Control Flow."
wide , <opcode , indexbyte1 , indexbyte2
or
wide , iinc , indexbyte1 , indexbyte2 , constbyte1 , constbyte2
To see how the stack changes when an instruction is modified by wide , see the entry for the unmodified instruction. The stack change for an instruction modified by wide is identical to the stack change for that same instruction unmodified.
The wide opcode modifies instructions that reference the local variables, extending the modified instruction s unsigned 8-bit local variable index to an unsigned 16-bit index. As shown above, a wide instruction comes in two formats. When the wide opcode modifies iload , fload , aload , lload , dload , istore , fstore , astore , lstore , dstore , or ret , the instruction has the first format. When the wide opcode modifies iinc , the instruction has the second format.
To execute any wide instruction, the Java Virtual Machine first forms an unsigned 16-bit index into the local variables by calculating (indexbyte1 8) | indexbyte2 . Irrespective of the opcode that wide modifies, the calculated index must be a valid index into the local variables of the current frame. If the wide opcode modifies lload , dload , lstore , or dstore , then one more than the calculated index must also be a valid index into the local variables. Given a valid unsigned 16-bit (wide) local variable index, The virtual machine executes the modified instruction using the wide index.
When a wide opcode modifies an iinc instruction, the format of the iinc instruction changes. An unmodified iinc instruction has two operands, an 8-bit unsigned local variable index , and an 8-bit signed increment const . When modified by wide , however, both the iinc instruction s local variable index and its increment are extended by an extra byte. To execute this instruction, The virtual machine forms a signed 16-bit increment by calculating (constbyte1 8) | constbyte2 .
Note that from the perspective of the bytecode verifier, the opcode modified by wide is seen as an operand to the wide opcode. The bytecodes are not allowed to treat opcodes modified by wide independently. For example, it is illegal for a goto instruction to jump directly to an opcode modified by wide .
For more information about the wide instruction, see Chapter 10, "Stack Operations."
COMPUTING MCGRAW-HILL | Beta Books | Contact Us | Order Information | Online Catalog
Computing McGraw-Hill is an imprint of the McGraw-Hill Professional Book Group.