Virtual machine stack in runtime memory data area - operand stack

operand stack

  • In addition to the local variable table, each independent stack frame also contains a last-in-first-out (Last-In-First-Out) operand stack, which can also be called an expression stack (Expression Stack).
  • The operand stack, in the process of method execution, writes data or extracts data into the stack according to bytecode instructions, that is, push/pop.
    • Some bytecode instructions push values ​​onto the operand stack, others pop operands off the stack. After using them, push the result onto the stack.
    • For example: perform operations such as copying, exchanging, and summing

     

for example:

 

  • The operand stack is mainly used to save the intermediate results of the calculation process, and at the same time as a temporary storage space for variables during the calculation process .
  • The operand stack is a working area of ​​the JVM execution engine. When a method starts to execute, a new stack frame will be created accordingly. The operand stack of this method is empty.
  • Each operand stack will have a clear stack depth for storing values. The maximum depth required is defined at compile time and stored in the code attribute of the method, which is the value of max stack.
  • Any element in the stack can be any Java data type.
    • The 32bit type occupies a stack unit depth
    • The 64bit type occupies two stack unit depths
  • The operand stack does not access data by accessing the index, but can only complete a data access through standard push and pop operations.
  • If the called method has a return value, its return value will be pushed into the operand stack of the current stack frame, and the next bytecode instruction to be executed in the PC register will be updated.
  • The data type of the elements in the operand stack must strictly match the sequence of bytecode instructions, which is verified by the compiler during the compiler, and verified again during the data flow analysis stage of the class verification stage in the class loading process.
  • In addition, we say that the interpretation engine of the Java virtual machine is a stack-based execution engine, where the stack refers to the operand stack.

 

Guess you like

Origin blog.csdn.net/m0_73843666/article/details/130091330