astore_1 0x4c

Pops a reference into local variable 1.

Opcode
0x4c (76)
Family
Stores
Operands
none
Length
1 byte
Operand stack
…, value (reference) → …
Can throw
nothing at run time (beyond linking errors)
Spec name
astore_<n>

What it does

Pops a reference into local variable 1.

Slots 0 to 3 each have a one-byte instruction; the general astore takes a one-byte slot number, and wide extends that to two bytes.

astore can also store a return address left by jsr, which only matters for very old class files.

How often javac uses it

In JDK 25.0.5's java.base module, astore_1 appears 5,553 times in 1,871 of its 7,391 classes: 0.28% of all instructions, the 60th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getInIfOpen, java.io.BufferedReader.read, java.io.BufferedReader$1.hasNext, java.io.BufferedWriter.flushBuffer.

Examples

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; astore_1 is highlighted.

static int oldStyle(Object o) in InstanceofPattern, compiled by javac 25
12if (o instanceof String) {
0aload_0 // o
1instanceof #7// String
13String s = (String) o;
7aload_0 // o
8checkcast #7// String
11astore_1 // s
14return s.length();
12aload_1 // s
13invokevirtual #13// String.length() : int
16return -1;

Open in the viewer

public static void main(String[] args) in Hello, compiled by javac 25
3String who = args.length > 0 ? args[0] : "world";
0aload_0 // args
5aload_0 // args
11ldc #7// "world"
13astore_1 // who
4System.out.println("Hello, " + who + "!");
14getstatic #9// System.out : PrintStream
17aload_1 // who
18invokedynamic #15// makeConcatWithConstants(String) : String ⇐ StringConcatFactory.makeConcatWithConstants "Hello, \1!"
23invokevirtual #19// PrintStream.println(String) : void
5}

Open in the viewer

Related instructions

aload_1 Pushes the reference in local variable 1.astore Pops a reference into local variable (operand).wide Makes the next instruction take a two-byte local index (and a two-byte iinc constant).

Specification: JVMS §6.5, astore_<n> (Java SE 25).