One study notes: program counter, the virtual machine stack and native method stacks

First, the program counter

       Program counter (Program Counter Register) is a small memory space, the line number counter can be seen as bytecode executed by the current thread. In the conceptual model of a virtual machine's (only a conceptual model, a variety of virtual machine might go through some achieve more efficient way), when the bytecode interpreter at work is to be selected by changing the value of a counter to be executed bytecode instructions, branching, looping, branching, exception handling, and other basic functions thread recovery relies on the counter to complete.

       Since the multi-threaded Java Virtual Machine is in turn switched mode execution time and processor allocation by threads to achieve, at any time a determined, a processor (for multi-core processors is a kernel) will only execute a thread of instructions. Therefore, in order to restore the thread switch to the correct execution position, each thread requires a separate program counter, independently of each other between the threads, independent store, said this type of memory area for the "thread private" RAM.

       If the thread is executing a Java method, the counter records the address of the virtual machine bytecode instruction being executed; if the method is being performed Native, this counter value is null (Undefined). This memory area is the only one not specify any area OutOfMemoryError situation in the Java Virtual Machine Specification.

Two, Java virtual machine stack

       Like the program counter, Java Virtual Machine stack (Java Virtual Machine Stacks) is also a thread private , its life cycle and the same thread . Virtual machine memory model described Java method executed: Each method creates a stack frame while performing for the local variable table information is stored, the operand stack, dynamic linking, method exports. Each method until the completion of the execution procedure is called, a corresponding stack frame to push the stack in a virtual machine process stack.

       Commonly referred to as the stack memory in the "stack", it is the virtual stack machine, or a virtual machine stack local variable table section.

       Local variable table stored in the known compile all the basic data structures (boolean, byte, char, shortobject reference (reference type, it is not equivalent to the object itself, may be a pointer to the object start address pointer reference, it may also be representative of a point or object handle associated with this other position of the object) and returnAddress type (address pointing to a byte code instruction).

       Space: wherein the long and double-length 64-bit data occupies two local variable space (Slot), the remaining data occupies only one type. Memory space required for the completion of the local variable table assigned during compilation, when entering a method, this method requires much space for local variables allocated in the frame is completely determined during operation of the method does not change the size of the local variable table .

       Abnormal situation: the Java Virtual Machine Specification, this area provides two anomalies: If the stack depth is greater than the depth of the thread requested virtual machine allowed StackOverflowError will throw an exception; if the virtual machine can dynamically expand the stack, if extended not apply when enough memory, it will throw an OutOfMemoryError.

Third, the native method stacks

       Native method stacks (Native Method Stack) and the role played by the virtual machine stack is very similar, the difference between them is the virtual machine execution stack for the Java Virtual Machine method (ie bytecode) services, native method stacks, compared with virtual Native method of using the machine to the service.

       Native method stacks of language used in the method, and use the data structure is not mandatory in the virtual machine specification, a specific virtual machine and therefore free to implement it. Even some virtual machines (such as Sun HotSpot VM) directly put into one native method stacks and stacks virtual machine. Like the virtual machine stack, native method stacks area StackOverflowError and an OutOfMemoryError will be thrown.

Guess you like

Origin www.cnblogs.com/lveyHang/p/11831532.html