Program counter

It records the line numbers and instructions that the program executes bytecode, and the bytecode interpreter’s job is to change the value of the program counter to switch the next instruction to execute (branch, loop, jump, exception, etc.). Java virtual machine is multi-threaded implementation by means of rotating switch CPU time slice, at the same time, the CPU will only perform a command in one thread, every time to switch back to the execution of the right position, each thread will have a separate thread counter, each counter will not influence each other, and is private to the thread. Since it is not a developer operation, no exception will be generated.

The virtual machine stack

The virtual machine stack is also thread private, and its declaration cycle is the same as that of the thread. A StackOverFlow error is reported if the thread request stack is deeper than the virtual machine allows. If the virtual machine can be dynamically expanded, an OutOfMemoryError will be reported if memory cannot be obtained after the expansion. The Java virtual machine stack describes the memory model of Java method execution. Each method execution creates a stack frame. For our purposes, the focus is on stack memory, which is also a local variable within the method.

The stack frame

Stack frame A data structure for method invocation and method execution by a virtual machine. It is a stack element in the data area of the virtual machine stack when the virtual machine is running. The stack frame stores the method’s local variable table, operand stack, dynamic link, and method return address information. At program compile time, how much local variable-table memory is required for the stack frame, and how deep the operand stack is determined. In an active thread, the stack frame at the top of the stack is valid. The stack frame is associated with the current method, and all bytecode instructions run by the execution engine only apply to the current stack frame.

Local method stack

The local method stack and the virtual machine stack function much the same. The difference is that the local method stack executes Native method services, while the virtual machine stack executes Java methods. In HotSpot VM, the local method stack and the virtual machine stack are combined.


When a thread calls a local method, it enters a world that is not constrained by the Java Virtual Machine and has the same permissions as the virtual machine. Local method You can access the data area when a VM is running through a local interface. It can directly use the registers of the local processor. Not all JVMS support native methods. If the JVM product is not intended to support Native methods, the Native method stack may not be implemented.