iconst_1 0x04
Pushes the int constant 1.
- Opcode
0x04(4)- Family
- Constants
- Operands
- none
- Length
- 1 byte
- Operand stack
… → …, 1 (int)- Can throw
- nothing at run time (beyond linking errors)
- Spec name
iconst_<i>
What it does
Pushes the int 1. Only -1 to 5 have one-byte instructions; any other int constant needs bipush (-128 to 127), sipush (-32768 to 32767) or ldc of an Integer constant.
javac also uses iconst_0 and iconst_1 for false and true: booleans are ints in bytecode. It picks the shortest encoding for every int constant, which is why these are among the most common instructions.
How often javac uses it
In JDK 25.0.5's java.base module, iconst_1 appears 39,832 times in 3,527 of its 7,391 classes: 2.0% of all instructions, the 16th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getBufIfOpen, java.io.BufferedOutputStream.growIfNeeded, java.io.BufferedReader.read, java.io.BufferedReader$1.hasNext.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; iconst_1 is highlighted.
static boolean same(Integer a, Integer b) in Boxing, compiled by javac 25static { … } in Asserts, compiled by javac 25Related instructions
bipush Pushes a byte, sign-extended to int.sipush Pushes a short, sign-extended to int.ldc Pushes a constant from the constant pool (index in one byte).
Specification: JVMS §6.5, iconst_<i> (Java SE 25).