111.

prev next contents
ldc

push single-word constant onto stack

Jasmin Syntax
     ldc <value> 
<value> is an int, a float, or a quoted (i.e. literal) string.

Stack

Before

After
...
<value>

...
Description

ldc pushes a one-word constant onto the operand stack. ldc takes a single parameter, <value>, which is the value to push. The following Java types can be pushed using ldc:

int
float
String

Pushing a String causes a reference to a java.lang.String object to be constructed and pushed onto the operand stack. Pusing an int or a float causes a primitive value to be pushed onto the stack.

Example

 ldc "Hello World"     ; push string "Hello World" onto stack ldc 10                ; push the integer 10 ldc 1.54              ; push the single-precision float 1.54 
Exceptions

OutOfMemoryError - not enough memory to allocate a reference to a String

Bytecode

In bytecode, the ldc opcode is followed by an 8-bit unsigned integer. This integer is the index of an entry in the constant pool of the current class. The entry is tagged as a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String entry. The data field of the entry contains <value> (in the case of a CONSTANT_String, the entry identifies a CONSTANT_Utf8 entry that contains the characters of the string).

Type

Description
u1
ldc opcode = 0x12 (18)
u1
index
See Also

bipush, sipush, ldc_w, ldc2_w, aconst_null, iconst_m1, iconst_<n>, lconst_<l>, fconst_<f>, dconst_<d>

Notes

1. Where possible, its more efficient to use one of bipush, sipush, or one of the const instructions instead of ldc.

2. If the same string constant (i.e. a string with the same sequence of characters) appears in several different class files, only one String instance is built for that constant. The String.intern() method can be used to retrieve the instance used for a given sequence of characters.


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


Java Virtual Machine
Java Virtual Machine (Java Series)
ISBN: 1565921941
EAN: 2147483647
Year: 1996
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net