Operand stack (source code)

= Operand stack

An <operand stack> holds intermediate values used by <bytecode> operations in a <Java virtual machine> method invocation. Each <stack frame> has its own last-in-first-out <operand stack>, initially empty; its maximum depth is recorded in the class file. Values can be loaded from <local variables>, consumed by operations and replaced by results.<The Java Virtual Machine Specification Java SE 25>[§2.6.2, Operand Stacks]{ref}

Starting from an empty <operand stack>, `iconst_2; iconst_3; iadd` produces the successive contents `2`, `2,3` and `5`, with the top shown at the right. The addition consumes both operands. This abstract execution rule does not require a physical memory push for each operation: <just-in-time compilation> may retain values in <processor registers> while preserving the specified behavior.