dup_x1 0x5a

Duplicates the top value and inserts it two slots down.

Opcode
0x5a (90)
Family
Stack manipulation
Operands
none
Length
1 byte
Operand stack
…, value2, value1 → …, value1, value2, value1
Can throw
nothing at run time (beyond linking errors)

What it does

Duplicates the top value and puts the copy beneath the second value. javac uses it when an assignment to an instance field is itself used as a value, as in return count = v; or return field++;: the copy left under the object reference is the expression's result after putfield consumes the rest.

How often javac uses it

In JDK 25.0.5's java.base module, dup_x1 appears 868 times in 352 of its 7,391 classes: 0.04% of all instructions, the 113th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.read, java.io.BufferedOutputStream.write, java.io.BufferedReader.<init>, java.io.BufferedWriter.write.

Examples

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

int assignField(int v) in Tour, compiled by javac 25
74return count = v;
0aload_0 // this
1iload_1 // v
3putfield #31// Tour.count : int

Open in the viewer

int field() in Increments, compiled by javac 25
14return field++;
0aload_0 // this
1dup
2getfield #7// Increments.field : int
8putfield #7// Increments.field : int

Open in the viewer

Related instructions

pop Discards the top stack slot.pop2 Discards the top two stack slots (or one long or double).dup Duplicates the top of the stack.

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