Java Virtual Machine (JVM) Stack Area


Following are some key points to undertstand JVM Stack Area −

  • During the creation of a thread, the Java Virtual Machine creates a separate stack.

  • The JVM performs only two operations upon this stack. The operations are push (i.e insert) and pop (i.e delete).

  • When a thread is currently in execution, the stack associated with it is known as runtime stack.

  • Every method call done by the thread, intermediate calculations, assignment of local variables, calling parameters etc, are stored as an operation in the runtime stack.

  • Once the thread stops or completes executing, the respective part from the stack is deleted.

  • Once all the calls by the thread are complete, the stack becomes empty, and is deleted.

  • Just before terminating the thread, JVM destructs the stack associated with the thread.

  • The stack that stores data associated with a thread is exclusively available only to that specific thread, and unaccessible to other threads.

  • This indicates that the data in the stack is thread-safe.

  • Every data in the stack associated with the thread is known as activation record or stack frame.

Note − It is not compulsory for JVM stack to have contiguous memory locations.

The structure of the activation record/stack frame

It consists of three constituents −

  • Local variable array,

  • Operand stack, and

  • Frame data

  • The JVM creates a stack frame of the required size by examining the class data.

  • The Operand Stack functions like a workspace to the JVM- it is used to store intermediate computational results. It is structured like a variable array locally, but can be accessed by performing push and pop operations on the stack.

  • Frame data − It contains constant data values and method returned data. In addition to this, it contains a reference to the Exception table that has all the information about catch block when exceptions need to be caught and relevant messages need to be shown on the console.

Updated on: 07-Jul-2020

683 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements