ifnull 0xc6

Pops a reference; jumps if it is null.

Opcode
0xc6 (198)
Family
Branches and switches
Operands
  • 2 bytes: signed branch offset
Length
3 bytes
Operand stack
…, value (reference) → …
Can throw
nothing at run time (beyond linking errors)

What it does

Pops a reference and jumps if it is null. javac uses it for x == null and x != null, usually inverted to skip the then-part.

How often javac uses it

In JDK 25.0.5's java.base module, ifnull appears 9,072 times in 1,699 of its 7,391 classes: 0.46% of all instructions, the 44th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.read, java.io.BufferedReader.readLine, java.io.BufferedReader$1.hasNext, java.io.BufferedWriter.close.

Example

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; ifnull is highlighted.

public Comparable max() in Numbers, compiled by javac 25
… 9 instructions before
22for (T t : items) if (best == null || t.compareTo(best) > 0) best = t;
22invokeinterface #36, 1// Iterator.next() : Object
27checkcast #40// Comparable
30astore_3 // t
31aload_1 // best
35aload_3 // t
36aload_1 // best
37invokeinterface #42, 2// Comparable.compareTo(Object) : int
42ifle 47
45aload_3 // t
46astore_1 // best
… 3 instructions after

Open in the viewer

Related instructions

ifnonnull Pops a reference; jumps if it is not null.if_acmpeq Pops two references; jumps if they are the same object.aconst_null Pushes null.

Specification: JVMS §6.5, ifnull (Java SE 25).