prev next contents
dup

duplicate top single-word item on the stack

Jasmin Syntax


    dup

Stack

Before

After
item
item
...
item

...
Description

This pops the top single-word value off the operand stack, and then pushes that value twice - i.e. it makes an extra copy of the top item on the stack.

This instruction cannot be used to duplicate two-word items (longs or doubles) - use dup2 instead.

Example


; This is like the java expression:
;
;   StringBuffer x = new StringBuffer();
;

; Make a new StringBuffer object and leave a reference to it
; on the stack:
new java/lang/StringBuffer

; [ Stack now contains: objectref ]

; Duplicate the object reference:
dup

; [ Stack now contains: objectref objectref ]

; Invoke the object's initializer:
invokespecial java/lang/StringBuffer/<init>()V

; [ Stack now contains: objectref ]

; Store the objectref in local variable 1.
astore_1

; [ Stack is now empty. ]

Bytecode

Type

Description
u1
dup opcode = 0x59 (89)
See Also

dup2, dup_x1, dup2_x1, dup2_x2


prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates