Reference articles:
1.Java Cenozoic, old age, lasting generation and meta space
2.Java Memory and garbage collection tuning
3. The class information of the method area, also known as the permanent generation, belongs to the Java heap.
The heap in Java is the largest chunk of memory that the JVM manages, and is primarily used to hold instance objects for various classes, as shown in the following illustration:
In Java, the heap is divided into two distinct regions: the Cenozoic (Young) and the old. The New Generation (young) is divided into three regions: Eden, S0, and S1. The purpose of this division is to enable the JVM to better manage objects in heap memory, including allocation of memory and recycling.
The heap in Java is also the main area of GC garbage collection. GC is divided into two types: Minor GC, full GC (or Major GC).
1. Young Generation
The younger generation is used to store newly created objects, the size of which varies with the size of the heap, and the default value is 1/15 of the heap size, which can be set by the-XMN parameter to a fixed size of young, or by-xx:newratio to set the size of the younger generation and the older generation. The young generation is characterized by fast object updating and a large number of "death objects" in a short period of time.
The young generation is characterized by a large number of dead objects, and if there is continuous space available, the replication cleanup algorithm and the parallel collector are used for garbage collection. The generation of garbage collection is known as primary recycling (minor GC).
The primary recovery divides the young generation into three regions, a new generation, 2 generations of the same size, applications can only use a new generation and a resurrection generation, when a primary garbage collection occurs, the GC suspends the program, and then copies the surviving objects in the Cenozoic and resurrection generations to another inactive resurrection generation. Then the new generation and resurrection are cleared once, and the original non resurrection Mark becomes the active resurrection generation. The objects that still exist after the specified number of recoveries are moved into the old age, after the primary recovery, to get an empty usable cenozoic.
The new generation is almost always where all Java objects are born, that is, the memory that the Java object applies to, and the storage is in this place. Most objects in Java usually do not need to live long, and have the nature of facing off in the sunset. When an object is judged to be "dead", the GC has the responsibility to reclaim the memory space of this part of the object. The Cenozoic is a frequent area of GC collection of rubbish. When the object is born in Eden, after a Minor GC, if the object survives and can be accommodated by another Survivor area, use the replication algorithm to copy the still surviving objects to another Survivor area, then clean up the used Eden and S Urvivor area, and the age of these objects is set to 1, after the object in the Survivor area every Minor GC, the object's age + 1, when the object's age reached a certain value (the default is 15 years old, you can pass the parameter-xx:maxtenuringthresho LD to set up), these objects will become the old age. But this is not certain, for some larger objects (that is, the need to allocate a large contiguous memory space) is directly into the old age.
2. The old age
The full GC is a garbage collection action that takes place in the old age, using the tag-purge algorithm.
In real life, people in the old age usually "die early" than the new generation of people. The old age in heap memory is different from this, in the old age, almost all of the objects in the Survivor area, they are not so easy to "die". As a result, the full GC occurs less frequently than the Minor GC, and it takes longer to do a full GC than a Minor GC. In addition, the tag-purge algorithm generates a lot of memory fragmentation (i.e., discontinuous memory space) when collecting garbage, and when it is necessary to allocate memory space for larger objects, the collection action of GC is triggered in advance if sufficient contiguous memory space is not found.
3. The permanent generation
Permanent generation is a unique concept of the Hotspot virtual machine, an implementation of the method area, which no other JVM has. In Java 8, the permanent generation is completely removed and replaced by another local memory-the meta space-that is not connected to the heap. The
permanent generation or "Perm Gen" contains the application metadata required by the JVM, which describes the classes and methods used in the application. Note that the permanent generation is not part of the Java heap memory. A permanent generation holds the classes used by the JVM runtime. The permanent generation also contains classes and methods for the Java SE library. Objects of the permanent generation are garbage collected at full GC.