Talking about the java memory structures

java memory structures

Today we talk about the memory structure of java, learn java, when we all know java memory heap and stack structure roughly divided into two parts, but powerful java can not be that simple, then we talk about the detail of java memory structure, look at the pictures, but also look a little sloppy haha.
Here Insert Picture Description
1. Class loader: Used responsible for loading the .class file into memory, about the class loader will be explained in detail in the next chapter.

2. Method region (permanent generation): it is called after jdk1.8 element space, which is shared by the threads, not part of the heap, and method area various information stored in the loaded class, such as fully qualified class name, the fully qualified name of the parent class, modifiers, etc., internal methods have a constant pool area, he saved the constants class runtime required information literal, static variables.
jvm can be dynamically adjusted according to application needs area method, area method may not be continuous, may manually configure memory region when the memory can not meet the needs OutOfMemoryError is thrown.

VM stack 3: First, it is a thread private, not visible to each other between the threads, a linear structure, to maintain the last-out principle, the main storage reference a local variable, the basic variable data types and objects.
When a method to perform this method will be described to the stack and heap objects and associates, we called him push tube.
At the end of a method that will pop up from the top of the stack, we called him the tube popped.
StackOverflowError exception is thrown when the stack memory does not meet the need.

4. The native method stacks: thread private, it is the underlying java method for the local service, it is to call the bottom of the c language, native method stacks StackOverflowError will throw an exception.

5. Program Counter: it is a small memory space, the recording position of the bytecode execution of the current thread, each thread has a separate counter, so it must be private to the thread, since the thread is executing the current byte when the code is in turn switched, which requires the program counter to record the current thread of execution to the place, the next time the thread will grab the cpu time slice execution continues from somewhere.
6. heap: All objects are created out of storage in the heap area, stack area is also an area resident gc (garbage collector), the heap is shared by all threads in the area, heap area is divided into: mainly divided into the old and the young generation's, the young generation is divided into: Eden district, from district to district and, if memory does not meet the needs OutOfMemoryError is thrown. Let's look at Fig.
Here Insert Picture Description
Eden Area: The main object stored new born, that he just created objects will be here, this area is also very active gc place.
and from region to region: the two areas the same size, when the Eden area is full will to survive object into one of the two regions, specifically how storage and operating mechanism of gc about, gc using replication algorithm, the overall survival of an object to another area, then this area cleared.
Old Age: The storage area for the survival of long objects, this area relative to the number of the young generation gc appear relatively small.

JVM guarantee mechanism: when the young generation is not enough space to store a new object when, JVM will be transferred to the object as a whole old's go inside.
When storing very large objects when, JVM found that the created objects in the Eden area is too large to be transferred to or from region to region, and the object just newly created and they add up to more than the younger generation of memory space, JVM will the original object directly into the old era, vacated the young generation is used to allocate space for new objects created.

A white, if it wrong please correct the great God, thanks for reading.

Guess you like

Origin blog.csdn.net/weixin_45118251/article/details/90552363