dup
duplicate top single-word item on the stack
1.Stack
Before | After |
---|---|
item | item |
… | item |
… |
2.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.
3.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. ]