dup2 0x5c
Duplicates the top two slots (or one long or double).
- Opcode
0x5c(92)- Family
- Stack manipulation
- Operands
- none
- Length
- 1 byte
- Operand stack
…, value2, value1 → …, value2, value1, value2, value1- Can throw
- nothing at run time (beyond linking errors)
What it does
Duplicates the top two slots: two one-slot values, or one long or double. javac uses it for a[i]++ (to keep the array and index for the store after the load) and to copy a long or double result, as in return ++counter; on a long field.
How often javac uses it
In JDK 25.0.5's java.base module, dup2 appears 1,462 times in 163 of its 7,391 classes: 0.07% of all instructions, the 99th most common of 194 opcodes in use. Some of the methods that use it: java.io.StreamTokenizer.wordChars, java.lang.FdLibm$KernelRemPio2.__kernel_rem_pio2, java.lang.FdLibm$Tan.__kernel_tan, java.lang.invoke.CallSite.getTargetOffset.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; dup2 is highlighted.
static long staticLong() in Increments, 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, dup2 (Java SE 25).