fconst_2 0x0d
Pushes the float constant 2.
- Opcode
0x0d(13)- Family
- Constants
- Operands
- none
- Length
- 1 byte
- Operand stack
… → …, 2 (float)- Can throw
- nothing at run time (beyond linking errors)
- Spec name
fconst_<f>
What it does
Pushes the float 2.0f. Only 0, 1 and 2 have one-byte instructions; any other float constant needs ldc of a Float constant.
How often javac uses it
In JDK 25.0.5's java.base module, fconst_2 appears 10 times in 7 of its 7,391 classes: <0.01% of all instructions, the 186th most common of 194 opcodes in use. Some of the methods that use it: java.lang.classfile.CodeBuilder.loadConstant, jdk.internal.classfile.impl.BytecodeHelpers.intrinsicConstantValue, jdk.internal.util.random.RandomSupport.boundedNextFloat, sun.nio.cs.DoubleByte$Encoder_DBCSONLY.<init>.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; fconst_2 is highlighted.
static float floats(float a, float b) in Tour, compiled by javac 25Related instructions
ldc Pushes a constant from the constant pool (index in one byte).fload Pushes the float in local variable (operand).
Specification: JVMS §6.5, fconst_<f> (Java SE 25).