Java Memory Management 3-Reading notes

Source: Internet
Author: User

Before introducing the three garbage collection algorithms, let's say the difference between the three GC types:

MINORGC: Young Generation Space Recycling

MAJORGC: Space recycling in the old age

FULLGC: Entire heap space reclamation

Classification of garbage collection algorithms

1.Serial Collector

The default GC mode for the JVM in client mode. The JVM configuration parameter:-XX:+USESERIALGC Specifies that the GC uses the collection algorithm. All the objects we created are created in the Eden area, MINORGC will be triggered if there is not enough space in the Eden area. However, before each MINORGC, the size of each promotion object exceeds the remaining space in the old area, if it is greater then the FULLGC is triggered once, if it is less than To see the value of the Handlepromotionfailure parameter (-xx:-handlepromotionfailure), if true, only MINORGC is triggered, or the FULLGC is triggered again.

2.Parallel Collector

The Parallel GC is divided into three different types depending on the minor GC and the full GC.

1) PARNEWGC

The-XX:USEPARNEWGC parameter specifies that its object allocation and recycling policy is similar to serial collector, except that the recycled thread is a multithreaded parallel collection.

2) PARALLELGC

Under the default GC mode under the server, the number of threads that can be reclaimed by the-XX:USEPARALLELGC parameter is enforced by the-xx:parallelgcthreads, which has a calculation formula, if the CPU and the number of cores are less than 8, the number of threads is the same as the number of cores , if greater than 8, the value is core*5 (CPU)/8

3) PARALLELOLDGC

By forcing the specified by the-XX:USEPARALLELOLDGC parameter, similar to the above, the number of threads that are recycled in parallel can be made by-xx:parallelgcthreads, which has a calculation formula, if the CPU and the number of cores is less than 8, the number of threads is the same as the number of cores, if greater than 8 , the value is core*5 (CPU)/8

3.CMS Collector

You can specify by-XX:USECONCMARKSWEEPGC that the number of concurrent threads defaults to 4 (parallel GC threads +3), or you can specify them through Parallelcmsthreads. The CMS GC is based on a GC between MINORGC and FULLGC. Its trigger rule is to check the old area or the utilization rate of the perm area, when a certain percentage of the trigger CMS GC, the trigger will reclaim the old area of memory space. Triggering CMSGC Recycling is only the old and perm areas of the garbage object, at the time of recycling and before the MINORGC, FULLGC basically does not matter.

Two scenarios for triggering FULLGC:

A.eden allocation failed, after triggering the MINORGC to Space,to Space is not enough to allocate to the old area, the old area is not enough to trigger the full GC.

B. The full GC is triggered directly when the CMS GC is failing to request memory from the old zone.

4. Combined user three GC

5. Advantages and disadvantages of three GC

6.GC Log Output parameters

    • -VERBOSE:GC, can assist in outputting some detailed GC information.
    • -xx:+printgcdetails, the output GC details.
    • -xx:+printgcapplicationstoppedtime, the output GC causes the application to pause for a time.
    • -XX:+PRINTGCDATESTAMPS,GC The time information that occurred.
    • -XX:+PRINTHEAPATGC, the size of each area in the heap before and after the GC is output.
    • -xloggc:[file], output GC information to a separate file.

Java Memory Management 3-Reading notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.