Contents Prev Next Up


3.14 Manipulating Object Fields

putfield

Set field in object
 
putfield = 181
indexbyte1
indexbyte2

Stack: ..., objectref, value => ...

OR

Stack: ..., objectref, value-word1, value-word2 => ...

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The constant pool item will be a field reference to a class name and a field name. The item is resolved to a field block pointer which has both the field width (in bytes) and the field offset (in bytes).

The field at that offset from the start of the object referenced by objectref will be set to the value on the top of the stack.

This instruction deals with both 32-bit and 64-bit wide fields.

If objectref is null, a NullPointerException is generated.

If the specified field is a static field, an IncompatibleClassChangeError is thrown.

getfield

Fetch field from object
 
getfield = 180
indexbyte1
indexbyte2

Stack: ..., objectref => ..., value 

OR

Stack: ..., objectref => ..., value-word1, value-word2

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The constant pool item will be a field reference to a class name and a field name. The item is resolved to a field block pointer which has both the field width (in bytes) and the field offset (in bytes).

objectref must be a reference to an object. The value at offset into the object referenced by objectref replaces objectref on the top of the stack.

This instruction deals with both 32-bit and 64-bit wide fields.

If objectref is null, a NullPointerException is generated.

If the specified field is a static field, an IncompatibleClassChangeError is thrown.

putstatic

Set static field in class
 
putstatic = 179
indexbyte1
indexbyte2

Stack: ..., value => ...

OR

Stack: ..., value-word1, value-word2 => ...

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The constant pool item will be a field reference to a static field of a class. That field will be set to have the value on the top of the stack.

This instruction works for both 32-bit and 64-bit wide fields.

If the specified field is a dynamic field, an IncompatibleClassChangeError is thrown.

getstatic

Get static field from class
 
getstatic = 178
indexbyte1
indexbyte2

Stack: ..., => ..., value 

OR

Stack: ..., => ..., value-word1, value-word2

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The constant pool item will be a field reference to a static field of a class.

This instruction deals with both 32-bit and 64-bit wide fields.

If the specified field is a dynamic field, an IncompatibleClassChangeError is generated.


Contents Prev Next Up