|
|
|
Advertisement
|
It's unconditional: goto opcodes
Those are all of the opcodes that cause the Java virtual machine to
branch conditionally. One other family of opcodes, however, causes the
JVM to branch unconditionally. Not surprisingly, these opcodes are
called "goto." Although goto is a
reserved word in the Java programming language, it can't be used in
your programs because it won't compile. The reason goto
is a reserved word is so that a mischievous programmer can't make a
variable named "goto" in order to freak out
their peers. But, when you compile a Java program, the bytecodes
generated will likely contain lots of goto instructions.
| Opcode | Operand(s) | Description |
|---|---|---|
goto |
branchbyte1, branchbyte2 | branch to offset |
goto_w |
branchbyte1, branchbyte2, branchbyte3, branchbyte4 | branch to offset |
The above opcodes, which perform comparisons and both conditional
and unconditional branches, are sufficient to express to a Java virtual
machine the desired control flow indicated in Java source code. They
achieve this with an if, if-else,
while, do-while, or for
statement. The above opcodes also could be used to express a
switch statement, but the JVM's instruction set includes
two opcodes specially designed for the switch statement:
tableswitch and lookupswitch.
|
Sponsored Links
|