Oracle JVM Garbage collectors Available from JDK 1.7.0_04 and after

Source: Internet
Author: User
Tags deprecated garbage collection

Jack Shirazi tells you garbage collectors and garbage collector combinations is available from the Oracle Java 7 Update 4 JVM and onwards, including Java 8 and Java 9.

Published June, Updated September, Author Jack Shirazi

--from http://www.fasterj.com/articles/oraclecollectors1.shtml. Combine Zhou zhiming ' s understaning JVM with the article to help us practise GC garbage exercises.

Note, this have been updated for changes to Java 8 and Java 9

With G1 finally being officially supported-i.e. No longer a experimental garbage collector-in the 1.7.0_04 (Java 7 Up Date 4) Release, it ' s worth taking stock of what we now has available in terms of garbage collectors in the Sun JVM. All the following details is relevant specifically to the Sun JVMs from 1.7.0_04 on.

There is now seven primary garbage collection algorithms, one of the which (PS scavenge) has both modes that is sufficiently Different that I would call them II different algorithms (that's, with and without adaptive GC), and another (the Concur Rent collector) which has a huge number of options the makes it actually at least half a dozen algorithms in one! It's useful to list the garbage collectors so that's what I'll do here.

First I ' ll characterise the actual different primary garbage collectors. There is seven (I ' m counting the G1 collector as one):

Young Generation Collectors

Copy (Enabled WITH-XX:+USESERIALGC) -
The serial copy collector, uses one thread to copy surviving objects from Eden to Survivor spaces and between Surviv or spaces until it decides they ' ve been there long enough, at which point it copies them to the old generation.
PS scavenge (enabled WITH-XX:+USEPARALLELGC) -
The parallel scavenge collector, like the Copy collector, but uses multiple threads in parallel and have s ome knowledge of the old generation are collected (essentially written to work with the serial and PS old Gen collector s).
parnew (Enabled WITH-XX:+USEPARNEWGC) -
The
parallel copy collector, like the copy collector, but uses multiple threads in parallel and have an in Ternal ' callback ' that allows a old generation collector to operate on the objects it collects (really written to work WI Th the concurrent collector).
G1 Young Generation (enabled WITH-XX:+USEG1GC) -
The garbage first collector, uses the ' garbage first ' algorithm which splits up the heap into lots of smaller spaces , but these is still separated into Eden and Survivor spaces in the young generation for G1.

Old Generation Collectors

marksweepcompact (Enabled WITH-XX:+USESERIALGC) -
the serial mark-sweep collector, the daddy of them all, uses a serial (one thread) full mark-sweep garbage Collectio n algorithm, with optional compaction.
PS marksweep (enabled WITH-XX:+USEPARALLELOLDGC) -
the parallel scavenge mark-sweep collector, parallelised version (i.e. uses multiple threads) of the MarkSweep Compact.
concurrentmarksweep (Enabled WITH-XX:+USECONCMARKSWEEPGC) -
The concurrent collector, a garbage collection algorithm that attempts to does most of the garbage collection work in The background without stopping application threads while it works (there is still phases where it has to stop applicatio n threads, but these phases is attempted to being kept to a minimum). Note If the concurrent collector fails to keep and the garbage, it fails over to the serial MARKSWEEPCOMPACT collector for (just) the next GC.
G1 Mixed Generation (enabled WITH-XX:+USEG1GC) -
The garbage first collector, uses the ' garbage first ' algorithm which splits up the heap into lots of smaller spaces .

All of the garbage collection algorithms except concurrentmarksweep is stop-the-world, i.e. they stop all applic ation threads while they operate-the stop is known as ' pause ' time. The Concurrentmarksweep tries to does most of it's work on the background and minimize the pause time, but it also Have a stop-the-world phase and can fail into the marksweepcompact which is fully stop-the-world. (The G1 collector has a concurrent phase and is currently mostly Stop-the-world).

Combinations of garbage collectors

That's the set of garbage collectors available, but they operate in both different heap spaces and it's the combination tha T is the "What we actually end" with for a particular JVM setting, so I'll also list the combinations that's possible. It doesn ' t explode into a dozen combinations because isn't all of the these collectors work with each other. G1 is effectively a antisocial collector that doesn ' t like working with anyone else; The serial collectors is the "Last Man picked" collectors; The ' PS ' collectors like-to-work with all other; and Parnew and Concurrent like into work together. From Java 9 That's pretty much it (with the addition of being able to turn off adaptive sizing policy) before that it wasn ' t quite as simple as--here's the list of what I consider was the main options in terms of garbage collection ALG Orithm options. As an aside-those who-like a bit of trivia, we had actually lost one garbage collection algorithm over time, the "Tra In "(incremental) garbage CollEctor which is available in various JVMs AS-XINCGC And-xx:+usetraingc-these flags is no longer useful, the former FL AG is just silently converted to using parnew and Concurrent, while the latter flag would cause a startup error in this J VMS, and from Java 9 We also lose the incremental algorithm in the concurrent collector.

The full list of possible GC algorithm combinations This can work is:

Command options* resulting Collector combination
-xx:+useserialgc Young Copy and old marksweepcompact
-xx:+useg1gc Young G1 Young and old G1 Mixed
-xx:+useparallelgc-xx:+useparalleloldgc-xx:+useadaptivesizepolicy Young PS scavenge old PS MarkSweep with adaptive sizing
-xx:+useparallelgc-xx:+useparalleloldgc-xx:-useadaptivesizepolicy Young PS scavenge old PS MarkSweep, no adaptive sizing
-XX:+USEPARNEWGC (deprecated in Java 8 and removed in Java 9-for parnew see the line below which are not deprecated ) Young parnew old marksweepcompact
-xx:+useconcmarksweepgc-xx:+useparnewgc Young parnew old concurrentmarksweep* *
-XX:+USECONCMARKSWEEPGC-XX:-USEPARNEWGC (deprecated in Java 8 and removed in Java 9) Young Copy old concurrentmarksweep* *
*all the combinations listed here would fail to let the JVM start if you add another GC algorithm not listed, with the Exce Ption OF-XX:+USEPARNEWGC which is only combinable WITH-XX:+USECONCMARKSWEEPGC
**there is many many options for use WITH-XX:+USECONCMARKSWEEPGC which change the algorithm, e.g.
  • -xx:+/-cmsincrementalmode (deprecated in Java 8 and removed in Java 9)-uses or disables an incremental Concurre NT GC algorithm
  • -xx:+/-cmsconcurrentmtenabled-uses or disables parallel (multiple threads) concurrent GC algorithm
  • -xx:+/-usecmscompactatfullcollection-uses or disables a compaction when a full GC occurs

Other options equivalent to one of the above:

Command Options used on their Own equivalent to Entry in Table Above
-xx:+useparallelgc -xx:+useparallelgc-xx:+useparalleloldgc
-xx:+useparalleloldgc -xx:+useparallelgc-xx:+useparalleloldgc
-XINCGC (deprecated in Java 8 and removed in Java 9) -xx:+useparnewgc-xx:+useconcmarksweepgc
-xx:+useconcmarksweepgc -xx:+useparnewgc-xx:+useconcmarksweepgc
No option on the most Windows -XX:+USEG1GC from Java 9, or before THAT-XX:+USESERIALGC (see also this page)
No option on Unix -XX:+USEG1GC from Java 9, or before That-xx:+useparallelgc-xx:+useparalleloldgc-xx:+useadaptivesizepolicy (see also thi S page)
-xx:+aggressiveheap -xx:+useparallelgc-xx:+useparalleloldgc-xx:+useadaptivesizepolicy with a bunch of the other options related to sizing memory and threads and how they interact with the OS

Oracle JVM Garbage collectors Available from JDK 1.7.0_04 and after

Related Article

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.