Branch if reference
comparison succeeds
Bytecode
Type | Description |
u1 | if_acmpeq opcode = 0xA5 (165) |
s2 | branchoffset |
Type | Description |
u1 | if_acmpne opcode = 0xA6 (166) |
s2 | branchoffset |
Stack ..., value1, value2 => ...
if_acmpeq pops the top two object references off the stack and compares them. If the two object references are equal (i.e. if they both refer to the same object), execution branches to the address (pc + branchoffset), where pc is the address of the if_acmpeq opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_acmpeq opcode in the bytecode. If the object references refer to different objects, execution continues at the next instruction.
if_acmpne pops the top two object references off the stack and compares them. If the two object references are not equal (i.e. if they refer to different objects), execution branches to the address (pc + branchoffset), where pc is the address of the if_acmpne opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_acmpne opcode in the bytecode. If the object references refer to the same object, execution continues at the next instruction.
Both value1 and value2 must be of type reference
. They are
both popped from the operand stack and compared. The results of the comparison are as
follows:
Otherwise, if the comparison fails, execution proceeds at the address of the instruction following this if_acmp<cond> instruction.
Example
aload_1 ; push the object reference in local variable 1 onto stack aload_2 ; push the object reference in local variable 2 onto stack if_acmpne Label ; if the two references on the stack differ, jump to Label return ; return if local variables 1 and 2 are the same object Label: ; execution continues here if local variables 1 and 2 refer to the different objects
Notes
Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).