DEV Community

ChelseaLiu0822
ChelseaLiu0822

Posted on

Stack and stack frame

Stack memory is for threads. After each thread is started, the virtual machine will allocate a piece of stack memory for it.
Each stack consists of multiple stack frames, corresponding to the memory occupied by each method call.
Each thread can only have one active stack frame, corresponding to the method currently being executed.
Thread Context Switch
Reasons that cause the CPU to no longer execute the current thread and instead execute the code of another thread:
The thread's CPU time is exhausted
Garbage collection
There are higher priority threads that need to run
The thread itself calls methods such as sleep, yield, wait, join, park, synchronized, and lock.
When a Context Switch occurs, the operating system is required to save the state of the current thread and restore the state of another thread.
Status, the corresponding concept in Java is Program Counter (Program Counter Register), its function is
Remember the execution address of the next jvm instruction, which is private to the thread.
The status includes the program counter, information about each stack frame in the virtual machine stack, local variables, operand stack, and return address.
wait
Frequent occurrence of Context Switch will affect performance

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay