The basic concept of JVM garbage collection mechanism (a)

1. What is the JVM? 3W1H
   definition:
    jvm is a fictional computer, is on the actual computer simulation illustrating the functions of various computer-implemented.
   What is the use:
    Java language the most important feature is the cross-platform, cross-platform Java program mainly refers to bytecode files can be run on any computer or electronic device with a Java virtual machine, using the JVM is to support independent of the operating system, Cross-platform.
   JVM memory Zoning:
    Class loader subsystem runtime data area, the execution engine.
    (A) a class loader subsystem:
     It is responsible for loading types (classes and interfaces) program, and given a unique name. JVM two class loader comprising: a boot class loader and the user-defined class loader, the boot class loader is part of the JVM implementations, user-defined class loader is part of the Java program must be a subclass ClassLoader class .
    (Ii) execution engine:
     Action: execute bytecode and native methods.
     Execution Engine Classification: 1 The simplest explanation is the one-time bytecode.
             2. The time compiler: faster, more memory, the first byte code is executed will be compiled to native machine code. Compile the native machine code is cached, when the method is called later can be reused.
             3. The adaptive optimizer: In this method, when the beginning of the virtual machine bytecode interpretation, but will monitor program running activities, and record the most frequently used code segments. When the program runs, the virtual machine only those most active code is compiled to native code, the use of other code is not very frequent, remain to bytecode, they went on to explain by the virtual machine. An adaptive optimization may be such that the Java virtual machine executes the native code optimized at 80% to 90% of the time, but only the compiled code affect performance 10% to 20%.
    (C) the runtime data area: comprising: a method area, heap, Java stacks, PC registers, native method stacks.
JVM's garbage collection mechanism:
    The new generation of heap memory is divided into (Adam and Eve) and the old year
 
    The newly created object
      First, the new generation of Adam Area
      ------ (a) minerGC recovery
     Cenozoic Eve area
      ------ (repeatedly) minerGC recovery
     Years old
 
     
    Adam is full ------> Eve area is full ------> Eve another area filled -----> before Eve's will to old
 
 
    Copy the young generation algorithm:
     Memory is divided into two, each occupying one.
     This one runs out, put alive copied to another block.
     
    The newly created object
     First, the new generation of Adam zone, called From Eve area
       ---------- minerGC recovery
       The new era of Adam zone -> Eve area called To the
       To the district named Eve - (ages ok) - years old
       At this point, eden region and called from survior area has been cleared, will be exchanged from and to their role, which is new to that from before the last GC
 
   
   
        
    Minor GC: from the young generation to reclaim memory  
    Full GC: to clean up the entire heap including the young generation and the old era.
 
 
 
    When the trigger:
      minerGC: When there is no memory space Adam Fires
      FullGC: Old's not enough space
      
  
  
  
  
    Before MinorGC occurs, the virtual machine to check whether old's maximum available contiguous space larger than the new generation of the total space of all objects.
    If greater than for Minor GC, to see if it is less than HandlePromotionFailure is to allow security failure (no directly FullGC)
    If allowed, it will continue to check old's maximum available contiguous space is larger than the previous promotion to the average size of the object's old, if more than
    Try minor gc (If the attempt fails also trigger Full GC), if it were less than Full GC.
    However, exactly when to perform, this is to be determined by the system, is unpredictable.
   
   
   
   
    To anything:
    Mainly based on reachability analysis algorithm, if an object is unreachable, then that can be recycled, if an object up, then the object can not be recycled,
    For reachability analysis algorithm, it is the starting point for the most by a series called "GC Roots" object, when an object GC Roots does not have any contact when referring to the chain,
    Then the object is unreachable, it can be recycled.
 
 
 
    Do anything:
    The main object is to do a clean-up, finishing work memory. Java heap into the new generation and the old era, with a different way of recycling.
    For example, using a new generation of replication algorithm, we use tags to organize decade old law. In the new generation, a divided region and two Survior ede
    Area, using a real eden region, and a Survior area, GC time, will live objects placed into another Survior area,
    And then clear the area and Survior eden region. So for old time, it uses tags to organize hair, marked the first live objects,
    Then move to the section. This will help reduce memory fragmentation.
    MARKER: Marks process is actually, through all the gc root and then all the gc root reachable target object is marked for survival
    Clear: Clear the process will iterate all heap objects, all the unmarked objects removed
    The main drawback: mark and sweep process efficiency is not high, a large amount of discrete memory fragmentation after marking Clear
     However, the old era because of the high survival rate of the object, there is no extra space to carry out his assignment guarantee, you must use tags to organize algorithm
    Collation Algorithm mark marking operation and "mark - Clear the" consensus algorithm, the subsequent clean-up operation is not only a direct object, but the clean-up
    After the completion of all useless objects surviving objects are moved to another section and the update of the reference object pointer
    The main drawback: on the basis of clear mark on the need to carry on moving objects, the cost is relatively high, relatively high cost, the benefit is no memory fragmentation.

Guess you like

Origin www.cnblogs.com/wzdnwyyu/p/11163027.html