ldc 0x12

Pushes a constant from the constant pool (index in one byte).

Opcode
0x12 (18)
Family
Constants
Operands
  • 1 byte: constant pool index
Length
2 bytes
Operand stack
… → …, value
Can throw
nothing at run time (beyond linking errors)

What it does

Pushes a constant from the constant pool: an Integer, Float or String; a Class (Java 5 and later, for Foo.class); a MethodType or MethodHandle (Java 7); or a Dynamic constant (Java 11). Strings come back interned: every ldc of the same String constant pushes the same object.

The index is one byte, so ldc reaches only the first 255 constants. javac uses ldc_w for the rest.

How often javac uses it

In JDK 25.0.5's java.base module, ldc appears 41,535 times in 3,729 of its 7,391 classes: 2.1% of all instructions, the 15th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getInIfOpen, java.io.BufferedOutputStream.<init>, java.io.BufferedReader.<init>, java.io.BufferedWriter.<init>.

Examples

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

private static String hidden() in Nestmates, compiled by javac 25
6return "hidden";
0ldc #13// "hidden"

Open in the viewer

static String json() in TextBlock, compiled by javac 25
5return """
0ldc #7// "{\n \"name\": \"carafe\",\n \"kind\": \"jvm\"\n}\n"

Open in the viewer

Related instructions

ldc_w Pushes a constant from the constant pool (index in two bytes).ldc2_w Pushes a long or double constant from the constant pool.bipush Pushes a byte, sign-extended to int.

Specification: JVMS §6.5, ldc (Java SE 25).