Reference: Instant Messenger software Enthusiast ~ recently researched JVM
Instant Messenger software enthusiasts ~ Recently researched the JVM, is a very good software, here with you to study the use of this software.
8 minutes ago Upload Download Attachments (22.36 KB)
Method areas and heaps are shared by all threads, and other areas are thread private
Program counter (Counter Register)Similar to the PC register, is a small area of memory, through the value of the program counter to find the code to execute the bytecode, because the switch between multiple threads to restore the current execution location of each thread, so each thread has its own program calculator. There will be no outofmemeryerror in this area. When executing a Java method, the address of the executed instruction is stored here, and if the local method is executed, the value here is undefined.
Virtual machine stack (Java stack)The virtual machine stack is also thread-private, each creation of a thread, the virtual machine will create a virtual machine stack for this thread, the virtual machine stack represents the Java method execution of the memory model, each call to a method, will generate a stack frame for the storage method of the local variable table, the Operation Stack, Method export information, when this method is finished, the corresponding stack frame will be popped.
If the requested stack depth is too large, the virtual machine may throwStackoverflowerrorException, if virtual machine stacks are allowed to dynamically expand in the implementation of the virtual machine, when the memory is not sufficient to expand the stack, it throwsOutOfMemoryErrorAbnormal.
stack frames (stack frame)The stack frame is divided into three parts: the local variable area (locally Variables), the operand stack (Operand stack), and the frame data area.
local variable area (Loca Variables)The local variable area is organized into a 0-based word group, where byte, short, and Char are converted to Int,boolean before being stored and converted to int,0 for false, not 0 for True,long and double to occupy two words in length.
operand stack (Operand stack)The operand stack is also organized into a word group, but unlike a local variable area, it is not accessed by an array subscript, but is able to push and pop operations over the stack, and the previous action push data can be used by the next action pop.
Frame Data areaThe role of this part is mainly in three parts:
The parsing method of the data in the constant pool executes the post-processing method, returns the exception handling when the caller throws an exception in the field method execution, stores an exception table, and when an exception occurs, the virtual machine looks for the corresponding exception table to see if there is a corresponding catch statement, and if there is no exception, abort this method call
The local method stack (Native) is similar to a virtual machine stack, and is used only when the local method is executed.
The method area is used to store information such as type information, constants, static variables, immediately compiled code, and so on, that have been loaded by the virtual machine.
The method area is shared between threads, and when two threads need to load one type at the same time, only one class requests ClassLoader loading and the other thread waits.
For each loaded type, the following information is saved in the method area:
The fully qualified name of the class and its parent class (Java.lang.Object No parent Class) class type (class or Interface) access modifier (public, abstract, final) the fully qualified list of interfaces implemented by the constant pool field information method information in addition to constants The static variable ClassLoader reference class reference
For each field, the following information is saved in the method area (the field declaration order is also saved):
Modifier for Field Name field (public, private, protected, static, final, volatile, transient)
For each method, the following information is saved in the method area (the method declaration order is also saved):
Method Name method returns the type (or void) parameter information method modifier (public, private, protected, static, final, synchronized, native, abstract)
If the method is not an abstract method and is not a local method (Native), the following information is also saved:
The byte-code local variable table of the method and the size exception table of the operand stack
The
Virtual machine needs to store some data to quickly access a method in a class object, typically implemented as a method table. Another part of the
Method area is the run constant pool, which is used primarily to store literal and symbolic references generated at compile time, and constants can also be generated at run time, such as the Intern method of string. There may also be GC in the
method area, but the virtual machine specification does not require it, mainly to reclaim some constants and unload some of the unused type information, but the conditions for unloading a class are difficult to achieve, and in some cases GC does not actually reclaim much memory.
Heap The place where objects and array instances are stored in a virtual machine, where the primary area of garbage collection is (and possibly the method area).
If garbage collection algorithms are collected on a per-generation basis (most of the time), this section can be subdivided into the new generation and the old age. The
Cenozoic may also be classified as Eden, from survivor and to survivor, primarily for garbage collection. All threads share the Java heap, where you can also divide the thread-private buffers (thread Local Allocation buffer,tlab). The
Java heap is only required to be logically contiguous and can be discontinuous on the physical space.
Direct Memory NiO is referenced in JDK1.4 and the channel and buffer are referenced, and the native library can be used to directly allocate out-of-heap memory and operate through a Directbytebuffer object stored in the Java heap as a reference to this memory.
Object Access When you create a new object, it allocates memory for the object in the heap, and there is a reference to the object in the stack, in addition to this object in the Java heap to find its type information (object type, parent class, implemented interface, Contains fields and methods, and so on). The
reference is defined in a Java virtual machine as a reference to an object, but there is no definition of how this reference should be implemented.
An implementation is an address that reference directly stores objects within the heap, and the type information of an object can be stored in the memory layout of the object in the heap, such as at the beginning of the object's memory. The
Other implementation is reference points to a position in a handle table that holds the actual location of the object and the type information it corresponds to. The advantage of using a handle is that when you move an object in memory, you only need to update the contents of the handle table, you do not need to change the reference value, but there is more memory access overhead, and the pros and cons of the direct reference are the opposite.