getfield 0xb4
Pops an object; pushes the value of one of its fields.
- Opcode
0xb4(180)- Family
- Fields
- Operands
- 2 bytes: constant pool index
- Length
- 3 bytes
- Operand stack
…, objectref → …, value- Can throw
NullPointerException
What it does
Pops an object reference and pushes the value of one of its instance fields, named by a Fieldref. Inside the class, this.x is aload_0 then getfield.
Since Java 11, an inner class reads its outer class's private fields directly with getfield; before that, javac generated access$000 methods to do it.
How often javac uses it
In JDK 25.0.5's java.base module, getfield appears 73,588 times in 3,970 of its 7,391 classes: 3.8% of all instructions, the 5th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getInIfOpen, java.io.BufferedOutputStream.flushBuffer, java.io.BufferedReader.ensureOpen, java.io.BufferedReader$1.hasNext.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; getfield is highlighted.
public int x() in Point, compiled by javac 25synchronized int get() in Sync, compiled by javac 25Related instructions
getstatic Pushes the value of a static field.putstatic Pops a value into a static field.putfield Pops an object and a value; stores the value in the field.
Specification: JVMS §6.5, getfield (Java SE 25).