sastore 0x56
Pops an array, an index and a short value; stores the value in the array.
- Opcode
0x56(86)- Family
- Arrays
- Operands
- none
- Length
- 1 byte
- Operand stack
…, arrayref, index, value (int) → …- Can throw
NullPointerException,ArrayIndexOutOfBoundsException
What it does
Pops an array (short[]), an index and a value; stores the value at that index, truncating the int to the element type.
How often javac uses it
In JDK 25.0.5's java.base module, sastore appears 3,244 times in 18 of its 7,391 classes: 0.17% of all instructions, the 70th most common of 194 opcodes in use. Some of the methods that use it: java.io.ObjectInputStream$BlockDataInputStream.readShorts, java.lang.invoke.MethodHandleImpl$ArrayAccessor.setElementS, java.lang.invoke.VarHandleShorts$Array.set, java.nio.HeapShortBuffer.put.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; sastore is highlighted.
static int arrays(int n) in Tour, compiled by javac 25Related instructions
saload Pops an array and an index; pushes the short element.arraylength Pops an array; pushes its length.newarray Pops a length; pushes a new array of a primitive type.
Specification: JVMS §6.5, sastore (Java SE 25).