getfield


Operation Fetch field from object

getfield
indexbyte1
indexbyte2


Forms getfield = 180 (0xb4)

Stack ..., objectref ..., value

OR

Stack ..., objectref ..., value.word1, value.word2

Description The objectref, which must be of type reference, is popped from the operand stack. The unsigned indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class (§3.6), where the index is (indexbyte1 << 8) | indexbyte2. The constant pool item at the index must be a CONSTANT_Fieldref (§4.4.2), a reference to a class name and a field name. If the field is protected (§4.6), then it must be either a member of the current class or a member of a superclass of the current class, and the class of objectref must be either the current class or a subclass of the current class.

The item is resolved (§5.2), determining both the field width and the field offset. The value at that offset into the class instance referenced by objectref is fetched and pushed onto the operand stack.

Linking Exceptions During resolution of the CONSTANT_Fieldref constant pool item, any of the errors documented in §5.2 can be thrown.

Otherwise, if the specified field exists but is a static field, getfield throws an IncompatibleClassChangeError.

Runtime Exception Otherwise, if objectref is null, the getfield instruction throws a NullPointerException.

Notes The getfield instruction operates on both one- and two-word wide fields.