prev next contents
ifnull

jump if null

Jasmin Syntax


    ifnull <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack

Before

After
objectref
...
...

Description

ifnull pops the top object reference off the operand stack. If the object reference is to the special object null, execution branches to the address (pc + branchoffset), where pc is the address of the ifnull opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifnull opcode in the bytecode. If the object reference on the stack is not null, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example


    aload_1         ; push the object reference in local variable 1 onto the stack
    ifnull Label    ; if local variable 1 is null, jump to Label
    return          ; return if local variable 1 isn't null
Label:
    ; execution continues here if local variable 1 is null...
Bytecode

Type

Description
u1
ifnull opcode = 0xC6 (198)
s2
branch-offset
See Also

ifeq, iflt, ifle, ifne, ifnonnull, ifgt, ifge

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).


prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates