ldc2_w 0x14

Pushes a long or double constant from the constant pool.

Opcode
0x14 (20)
Family
Constants
Operands
  • 2 bytes: constant pool index
Length
3 bytes
Operand stack
… → …, value (long or double)
Can throw
nothing at run time (beyond linking errors)

What it does

Pushes a Long or Double constant from the constant pool, taking two stack slots. There is no one-byte-index form: long and double constants always use ldc2_w.

Only values other than 0L, 1L, 0.0 and 1.0 need it; those have lconst_* and dconst_*.

How often javac uses it

In JDK 25.0.5's java.base module, ldc2_w appears 9,670 times in 562 of its 7,391 classes: 0.50% of all instructions, the 42nd most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.transferTo, java.io.File.getTotalSpace, java.io.FileDescriptor.<init>, java.io.FileInputStream.traceRead0.

Examples

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

static double doubles(double a, double b) in Tour, compiled by javac 25
… 6 instructions before
31double x = a + b - a * b;
7dstore 4// x
32x = x / b % 7;
9dload 4// x
11dload_2 // b
12ddiv
13ldc2_w #14// 7
16drem
17dstore 4// x
33return -x + 0d + 1d;
19dload 4// x
21dneg
23dadd
… 3 instructions after

Open in the viewer

static double area(Shapes$Shape s) in Shapes, compiled by javac 25
… 15 instructions before
8return switch (s) {
50invokespecial #19// new MatchException(String, Throwable)
9case Circle c -> Math.PI * c.r() * c.r();
55checkcast #22// Shapes$Circle
58astore_3 // c
59ldc2_w #26// 3.141592653589793
62aload_3 // c
63invokevirtual #28// Shapes$Circle.r() : double
66dmul
67aload_3 // c
68invokevirtual #28// Shapes$Circle.r() : double
71dmul
… 48 instructions after

Open in the viewer

Related instructions

lconst_0 Pushes the long constant 0.dconst_0 Pushes the double constant 0.ldc Pushes a constant from the constant pool (index in one byte).

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