The Java Virtual runtime divides the memory used by the JVM into different areas, each of which is responsible for the different functions and the creation of each region, and the destruction varies.
is the partition of the memory data area of the JVM runtime,
Figure 1, JVM runtime data area
1. Program Counter
Each thread has a separate program counter that records the bytecode instructions that are being executed by the current thread, which is "thread-private" memory.
2. Virtual Machine Stack
This area is also called stack memory (corresponding to Java heap memory), which is not exactly the correct one, but can be easily understood.
The zone is also thread-private and is the same as the thread's life cycle.
Mainly responsible for the memory part of the method execution , in each method execution will create a stack pin store local variables, operands and other methods related information, each time the call to completion of the method, all corresponding to a stack in the virtual machine stack in the process of entering and exiting the stack.
The zone throws Stackoverflowerror and OutOfMemoryError errors
Stackoverflowerror is a thread request with a stack depth greater than the virtual machine allows, as in the following code
public static void Main (string[] args) {teststackoverflow ();} public static void Teststackoverflow () {System.out.println ("StackOverflow"); Teststackoverflow ();}
OutOfMemoryError error is the stack space overflow, such as too many local variables, too much memory, will produce no examples
3. Local method Stack
Similar to the virtual machine stack, only responsible for the local native method , but also throws Stackoverflowerror and outofmemoryerror errors, such as IO common file read and write operation native method, It may be the implementation of a C language or other language.
4. Java Heap (Java heap), GC heap
The Java heap is the memory that the Java Virtual Machine manages, the biggest, the most important part, is the area that all threads share,
is also the main recycling part of GC (garbage collection),
then the division can be divided into Cenozoic, Laosheng generation (old age); The Cenozoic can be divided into: eden,from survivor,to Survivor
The main storage object instance , can be configured to set different generations of size and garbage collection policy, many optimizations are also implemented on the heap.
detailed description of the heap: HTTP://WWW.BEGINCODE.NET/BLOG/47
The zone throws a OutOfMemoryError exception
5. Method area, non-heap, permanent generation
This area is also a thread-shared memory area, which is also garbage collected, but negligible because the effect is difficult to satisfy
Main storage virtual Machine load class information, constants, static variables, etc.
The zone throws an OutOfMemoryError exception, which is mainly the classes that need to be loaded at startup, constants, static variables, and so on, which exceeds the memory space set by the locale and throws an exception.
You can look at the Eclipse memory settings and throw the memory overflow exception if the memory settings are very small
http://www.begincode.net/blog/50
Run a constant pool: is part of the method area, and mainly stores the string constants that are generated by the Intern method that runs a constant amount, such as String.
6. Direct Memory
Direct memory is not shown in the diagram, assuming that he is not part of the data area when the virtual machine is running, and is not managed by the VM, but the memory area also appears OutOfMemoryError exception.
the use of the zone, primarily in the NIO buffer, will use the system's direct memory, because the memory allocated through the local method throws a memory overflow exception when the machine is unable to allocate more memory
Java memory area and usage assignment