The Artima Developer Community
Sponsored Link

Control Flow in the Java Virtual Machine
Java Bytecodes that Deal with Control Flow
by Bill Venners
First Published in JavaWorld, March 1997

<<  Page 3 of 5  >>


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.

Unconditional branch
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.

<<  Page 3 of 5  >>

Sponsored Links

Copyright © 1996-2018 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use