getstatic 0xb2
Pushes the value of a static field.
- Opcode
0xb2(178)- Family
- Fields
- Operands
- 2 bytes: constant pool index
- Length
- 3 bytes
- Operand stack
… → …, value- Can throw
- nothing at run time (beyond linking errors)
What it does
Pushes the value of a static field, named by a Fieldref. The first use initialises the field's class if it has not been already, running its static initialiser. System.out is the getstatic everyone has written.
A static final field with a compile-time constant value is not read with getstatic at all: javac copies the value into the code that uses it.
How often javac uses it
In JDK 25.0.5's java.base module, getstatic appears 43,153 times in 2,999 of its 7,391 classes: 2.2% of all instructions, the 14th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getBufIfOpen, java.io.ByteArrayInputStream.transferTo, java.io.Console.instantiateConsole, java.io.Console$1.console.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; getstatic is highlighted.
public static EnumSwitch$Size[] values() in EnumSwitch.Size, compiled by javac 25enum Size { SMALL, MEDIUM, LARGE }private static void lambda$hello$0() synthetic in Lambda, compiled by javac 25return () -> System.out.println("hello");Related instructions
putstatic Pops a value into a static field.getfield Pops an object; pushes the value of one of its fields.putfield Pops an object and a value; stores the value in the field.
Specification: JVMS §6.5, getstatic (Java SE 25).