JVM ---- new generation, old time, permanent behalf

  From the perspective of Java heap GC can also be broken down into: the new generation (Eden District, From Survivor To Survivor district and region) and the old year .


 

 

 

  Cenozoic:

    The object is used to store the newborn. General occupy 1/3 of the heap space. Due to the frequent create an object, so the new generation will frequently trigger MinorGC garbage collection. Eden Cenozoic is divided into zones, ServivorFrom, ServivorTo 3 districts.


Minor GC and Major GC differences:

Minor GC: GC simple to understand what happened to the young generation. Three steps ( copy - Empty - swap)
  Minor GC trigger conditions are:

    When generating a new object, the new object preferentially partitioned Eden area. If the object does not fit Eden area, the opportunity to use virtual copy algorithm occurs once Minor GC, clearing out unwanted objects, live objects while moving to one of the region Survivor (fromspace tospace area or region).

    Virtual machine for each object defines a target age (Age) counters, objects in the area every Survivor "get through" a GC, the age will be +1. Until the age reaches a certain age (the default is 15 years old), the virtual machine will move objects to the old generation.

    If a newborn object when Eden area can not allocate space, then Minor GC occurs. It occurred MinorGC, the object will enter the area from Eden District Survivor, Survivor if the zone does not fit the object came from the Eden area, this time using the allocation guarantee mechanism moves the object directly to the old generation.

    1. First Yong GC (Minor GC), Eden area also live objects copied to the region Surviver "To" area, "From" area also live objects copied to "To" region,

    2. From then empty the Eden area and the area, so that is equivalent to "From" area is completely empty, while the "To" area there will be no memory fragmentation produced,

    3. When the second Yong GC wait, "From" area and "To" area the roles were reversed, a good solution to the problem of memory fragmentation.

  Major GC trigger conditions:

    Major GC also known as Full GC. The year when the old generation of space is not enough, the opportunity to use the virtual "flag - Clear" or "mark - finishing" algorithm to clean up a continuous memory space allocated objects.

  

  Old year:

  The main application is stored in a long life cycle memory object.

   Object old age is relatively stable, so MajorGC not be performed frequently. MajorGC before making generally first conducted a MinorGC, makes the new generation of objects joined the old era, when space is not enough to trigger leads.

   When you can not find a large enough contiguous space to allocate a large newly created object will trigger a MajorGC advance for garbage collection to free up space.

   MajorGC using mark sweep algorithm : first scans once all the old era, marked survival of the subject, and then recovering the object is not marked. MajorGC relatively long time-consuming, because you want to scan recycling. MajorGC will produce memory fragmentation, in order to reduce memory consumption, we generally need to be merged or marked for next direct distribution. When the old year was full fit and they will throw OOM (Out of Memory) anomalies .

 

  Permanent Generation:

Refers to a permanent memory storage area, the main information is stored and Class Meta (metadata), is placed permanently Class region when loaded, and it is different and the storage area for example, the main program will not run on the GC permanent area clean. So this also led to permanent generation area will be loaded with the increase of the Class of fullness and eventually throws OOM exception.

    JAVA8 metadata:

    In Java8, permanent behalf has been removed, "it is referred to as a meta data area " ( metaSpace region) replaced.

    Yuan and permanent nature of space to like, the biggest difference between the yuan and the permanent space on behalf of that: Yuan is not space in a virtual machine, but the use of local memory . Therefore, by default, the size of the element space only by the local memory limit.

    Class metadata into native memory, static class variable string into pools and java heap , so that the metadata can be loaded class number is no longer controlled by the MaxPermSize, and the actual space available is controlled by the system.

 

Guess you like

Origin www.cnblogs.com/crazy-lc/p/12636927.html