dup_x2 0x5b
Duplicates the top value and inserts it three slots down.
- Opcode
0x5b(91)- Family
- Stack manipulation
- Operands
- none
- Length
- 1 byte
- Operand stack
…, value3, value2, value1 → …, value1, value3, value2, value1- Can throw
- nothing at run time (beyond linking errors)
What it does
Duplicates the top value and puts the copy beneath the next three slots (or beneath a long or double and one value). javac uses it when an array element assignment is used as a value, as in return a[i] = v;: the copy goes beneath the array and index that iastore will consume.
How often javac uses it
In JDK 25.0.5's java.base module, dup_x2 appears 57 times in 39 of its 7,391 classes: <0.01% of all instructions, the 166th most common of 194 opcodes in use. Some of the methods that use it: java.io.StreamTokenizer.toString, java.lang.invoke.ClassSpecializer$SpeciesData.transformHelper, java.lang.invoke.DirectMethodHandle.makePreparedFieldLambdaForm, java.lang.invoke.Invokers.setCachedInvoker.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; dup_x2 is highlighted.
static int assignElement(int[] a, int v) in Tour, compiled by javac 25Related 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_x2 (Java SE 25).