Division of JVM memory area (memory structure or memory model) Division of JVM memory area (memory structure or memory model)

JVM memory area division (memory structure or memory model)

 

Runtime data area:

According to the JVM specification, JVM memory is divided into five parts: virtual machine stack, heap, method area, program counter, and local method stack.

Program counter (thread private):

  It is the line number indicator of the bytecode executed by the current thread. Each thread must have an independent program counter. This type of memory is also called "thread private" memory.

  When a java method is being executed, the counter records the address of the virtual machine bytecode instruction (the address of the current instruction) . If it is still a Native method, it is empty .

  This memory region is the only region in the virtual machine that does not specify any OutOfMemoryError conditions.

 

Java virtual machine stack (thread private):

  Also thread private.

  When each method is executed, a stack frame is created, which stores the local variable table, operand stack, dynamic connection, method return address , etc.

  From invocation to completion of execution, each method corresponds to the stacking and popping of a stack frame in the virtual machine stack.

  The so-called stack generally refers to the local variable table part in the virtual machine stack.

  The memory required for the local variable table is allocated during compilation.

  StackOverflowError if the thread's requested stack depth is greater than that allowed by the virtual machine.

    If the virtual machine stack can be dynamically expanded and cannot apply for enough memory, an OutOfMemoryError occurs.

 

Native method stack (thread private):

  Similar to the virtual machine stack, it mainly serves the Native methods used by the virtual machine.

  Also throws StackOverflowError and OutOfMemoryError.

 

Java heap (thread shared):

  A memory area shared by all threads, created when the virtual machine starts, to store object instances .

  The heap can be implemented as extensible (controlled by -Xmx and -Xms)

  An OutOfMemoryError exception is thrown when there is no memory in the heap to allocate to the instance and it cannot be expanded any more.

 

Method area (thread sharing):

  A memory area shared by all threads.

  Used to store class information, constants, static variables, etc. that have been loaded by the virtual machine.

  The memory reclamation targets in this area are mainly for the reclamation of the constant pool and the unloading of types.

  When the method area cannot meet the memory allocation requirements, an OutOfMemoryError exception is thrown.

  In the HotSpot virtual machine, the permanent generation is used to implement the method area, and the GC generational collection is extended to the method area, but it is easy to encounter the problem of memory overflow.

  In JDK1.7, the string constant pool in the permanent generation has been moved to the heap.

  JDK1.8 revokes the permanent generation and introduces metaspace.

 

Runtime constant pool:

  It is part of the method area and is used to store various literals and symbolic references generated at compile time .

  When the constant pool can no longer apply for memory, an OutOfMemoryError exception is thrown.

 

Direct memory:

  Not part of the runtime data area, but may also throw OutOfMemoryError exceptions.

  The newly added NOI class in JDK1.4 introduces an I/O method based on channels and buffers, which can directly allocate off-heap memory using Native functions.

Then operate through a DirectByteBuffer object stored in the Java heap as a reference to this memory.

Runtime data area:

According to the JVM specification, JVM memory is divided into five parts: virtual machine stack, heap, method area, program counter, and local method stack.

Program counter (thread private):

  It is the line number indicator of the bytecode executed by the current thread. Each thread must have an independent program counter. This type of memory is also called "thread private" memory.

  When a java method is being executed, the counter records the address of the virtual machine bytecode instruction (the address of the current instruction) . If it is still a Native method, it is empty .

  This memory region is the only region in the virtual machine that does not specify any OutOfMemoryError conditions.

 

Java virtual machine stack (thread private):

  Also thread private.

  When each method is executed, a stack frame is created, which stores the local variable table, operand stack, dynamic connection, method return address , etc.

  From invocation to completion of execution, each method corresponds to the stacking and popping of a stack frame in the virtual machine stack.

  The so-called stack generally refers to the local variable table part in the virtual machine stack.

  The memory required for the local variable table is allocated during compilation.

  StackOverflowError if the thread's requested stack depth is greater than that allowed by the virtual machine.

    If the virtual machine stack can be dynamically expanded and cannot apply for enough memory, an OutOfMemoryError occurs.

 

Native method stack (thread private):

  Similar to the virtual machine stack, it mainly serves the Native methods used by the virtual machine.

  Also throws StackOverflowError and OutOfMemoryError.

 

Java heap (thread shared):

  A memory area shared by all threads, created when the virtual machine starts, to store object instances .

  The heap can be implemented as extensible (controlled by -Xmx and -Xms)

  An OutOfMemoryError exception is thrown when there is no memory in the heap to allocate to the instance and it cannot be expanded any more.

 

Method area (thread sharing):

  A memory area shared by all threads.

  Used to store class information, constants, static variables, etc. that have been loaded by the virtual machine.

  The memory reclamation targets in this area are mainly for the reclamation of the constant pool and the unloading of types.

  When the method area cannot meet the memory allocation requirements, an OutOfMemoryError exception is thrown.

  In the HotSpot virtual machine, the permanent generation is used to implement the method area, and the GC generational collection is extended to the method area, but it is easy to encounter the problem of memory overflow.

  In JDK1.7, the string constant pool in the permanent generation has been moved to the heap.

  JDK1.8 revokes the permanent generation and introduces metaspace.

 

Runtime constant pool:

  It is part of the method area and is used to store various literals and symbolic references generated at compile time .

  When the constant pool can no longer apply for memory, an OutOfMemoryError exception is thrown.

 

Direct memory:

  Not part of the runtime data area, but may also throw OutOfMemoryError exceptions.

  The newly added NOI class in JDK1.4 introduces an I/O method based on channels and buffers, which can directly allocate off-heap memory using Native functions.

Then operate through a DirectByteBuffer object stored in the Java heap as a reference to this memory.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325412364&siteId=291194637