What is an operand stack?

后端 未结 3 1916
醉话见心
醉话见心 2021-01-30 16:52

I am reading about JVM architecture. Today I read about the concept of the Operand Stack. According to an article:

The operand stack is used during the ex

3条回答
  •  梦如初夏
    2021-01-30 17:02

    Operand stack holds the operand used by operators to perform operations. Each entry on the operand stack can hold a value of any Java Virtual Machine type.

    From JVM specifications,

    Java Virtual Machine instructions take operands from the operand stack, operate on them, and push the result back onto the operand stack. The operand stack is also used to prepare parameters to be passed to methods and to receive method results.

    For example, iadd instruction will add two integer values, so it will pop top two integer values from operand stack and will push result into operand stack after adding them.

    For more detailed reference, you can check JVMS#2.5 : Run-Time Data Areas

    Summarizing it in context of Operand stack,

        _______________________________
       |        _____________________  |
       |       |         + --------+ | |
       |  JVM  |         | Operand | | | 
       | Stack |  FRAME  |  Stack  | | |
       |       |         +---------+ | |
       |       |_____________________| |
       |_______________________________|
    
    • JVM supports multithreaded execution environment. Each thread of execution has its private java virtual machine stack (JVM Stack) created at the same time of thread creation.
    • This Java virtual machine stack stores frames. Frame holds data, partial results, method return values and performs dynamic linking.
    • Each frame contains stack, known as Operand stack, which holds the operand values of JVM types. A depth of operand stack is determined at compile time and updated with operators.

提交回复
热议问题