Search code examples
javamultithreadingmemory-managementjvmallocation

The Internal Java Memory Model for Thread Stacks


I was reading article about Internal Java Memory Model. There is one point I want to ask about :

Each thread running in the Java virtual machine has its own thread stack. The thread stack contains information about what methods the thread has called to reach the current point of execution.

Why each thread needs to save information about what methods has been executed(!) ? If it's related to context-switching then (if I'm not wrong) thread must save the information about method which is currently being executed. What is actual need for save already executed method's information?


Solution

  • This is referring to the currently active methods. Note that there can be several methods in a thread active at the same time (A calls B calls C, ...). The stack does not contain information about methods that have already completed.