if_icmpge 0xa2

Pops two ints; jumps if the first is greater than or equal to the second.

Opcode
0xa2 (162)
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_icmpge appears 5,779 times in 1,381 of its 7,391 classes: 0.30% of all instructions, the 58th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.read1, java.io.BufferedOutputStream.growIfNeeded, java.io.BufferedReader.read, java.io.BufferedWriter.growIfNeeded.

Examples

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

static boolean inRange(int x, int lo, int hi) in Conditions, compiled by javac 25
4return x >= lo && x < hi;
0iload_0 // x
1iload_1 // lo
5iload_0 // x
6iload_2 // hi

Open in the viewer

static String repeat(String s, int times) in Concat, compiled by javac 25
8String out = "";
0ldc #11// ""
2astore_2 // out
9for (int i = 0; i < times; i++) {
4istore_3 // i
5iload_3 // i
6iload_1 // times
10out += s;
10aload_2 // out
11aload_0 // s
12invokedynamic #13// makeConcatWithConstants(String, String) : String ⇐ StringConcatFactory.makeConcatWithConstants "\1\1"
17astore_2 // out
9for (int i = 0; i < times; i++) {
18iinc 3, 1// i
12return out;
24aload_2 // out

Open in the viewer

Related instructions

if_icmplt Pops two ints; jumps if the first is less than the second.ifge Pops an int; jumps if it is greater than or equal to zero.goto Jumps unconditionally.

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