Search code examples
javajvmbytecodegoto

What is the number after "GOTO" in Java bytecode?


Java version: 1.8.0_73-b02 64bit

Why command GOTO 10's bytecode is A7 FF F7?
Is A7 corresponds to goto, and FF F7 corresponds to 10?

Why A7 FF F7 is GOTO 10?


Solution

  • Those two bytes identify the memory address of the next intended instruction. Take a look at the description for GOTO in this bytecode listing:

    goes to another instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2)

    Or, see here in the official javadoc

    The unsigned bytes branchbyte1 and branchbyte2 are used to construct a signed 16-bit branchoffset, where branchoffset is (branchbyte1 << 8) | branchbyte2. Execution proceeds at that offset from the address of the opcode of this goto instruction. The target address must be that of an opcode of an instruction within the method that contains this goto instruction.