if_acmpne 0xa6

Pops two references; jumps if they are different objects.

Opcode
0xa6 (166)
Family
Branches and switches
Operands
  • 2 bytes: signed branch offset
Length
3 bytes
Operand stack
…, value1 (reference), value2 (reference) → …
Can throw
nothing at run time (beyond linking errors)
Spec name
if_acmp<cond>

What it does

Pops two references and jumps if they are not the same object. This is Java's == on references, which compares identity, not equals.

It is the instruction behind the classic Integer-cache surprise: two boxed Integers compare equal with == for small values (the same cached object) and unequal for large ones.

How often javac uses it

In JDK 25.0.5's java.base module, if_acmpne appears 2,945 times in 839 of its 7,391 classes: 0.15% of all instructions, the 76th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getBufIfOpen, java.io.BufferedOutputStream.<init>, java.io.ByteArrayInputStream.transferTo, java.io.File.isInvalid.

Example

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

static boolean same(Integer a, Integer b) in Boxing, compiled by javac 25
23return a == b;
0aload_0 // a
1aload_1 // b

Open in the viewer

Related instructions

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

Specification: JVMS §6.5, if_acmp<cond> (Java SE 25).