if_icmpeq 0x9f
Pops two ints; jumps if the first is equal to the second.
- Opcode
0x9f(159)- Family
- Branches and switches
- Operands
- 2 bytes: signed branch offset
- Length
- 3 bytes
- Operand stack
…, value1 (int), value2 (int) → …- Can throw
- nothing at run time (beyond linking errors)
- Spec name
if_icmp<cond>
What it does
Pops two ints and jumps if the first is == the second.
As with every branch, javac tends to emit the opposite of the source condition and jump past the body. A loop such as for (int i = 0; i < n; i++) tests if_icmpge at the top to leave the loop, and ends with a goto back to the test.
How often javac uses it
In JDK 25.0.5's java.base module, if_icmpeq appears 3,295 times in 865 of its 7,391 classes: 0.17% of all instructions, the 69th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedReader.readLine, java.io.ByteArrayInputStream.transferTo, java.io.DataInputStream.readLine, java.io.File.<init>.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; if_icmpeq is highlighted.
static int whileLoop(int n) in Loops, compiled by javac 25Related instructions
if_icmpne Pops two ints; jumps if the first is not equal to the second.ifeq Pops an int; jumps if it is equal to zero.goto Jumps unconditionally.
Specification: JVMS §6.5, if_icmp<cond> (Java SE 25).