JVM Garbage Collection

In general (since I know that there is a standard JVM implementation from Oracle / sun and other third parties, as well as MS), does the JVM create only one Garbage collection thread, run as a daemon to collect garbage objects, or does the JVM spawn more than one thread, to perform garbage collection?

+6
source share
3 answers

The skip collector, which is enabled with -XX:+UseParallelGC and is the default collector, uses multiple threads. A "parallel low-level collector" enabled with -XX:+UseConcMarkSweepGC uses a single thread for a parallel collector, but its stop-the-world collections are parallel.

Only the rarely used single-threaded gc -XX:+UseSerialGC is single-threaded.

http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

+6
source

-XX: ConcGCThreads = n - The number of threads collected together with garbage collectors will be used. The default value depends on the platform on which the JVM is running.

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html#G1Options

There may be more garbage collector threads, but you should not rely on their number, execution sequence or anything else. However, there are essential things you can rely on. for example: Object.finalize () will be called once and only once.

Also check out the garbage collector setting, about the question:

http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html#1.1.%20Types%20of%20Collectors%7Coutline

+1
source

The Oracle Garbage-First GC algorithm (available in Java 8 and the default option in Java 9) is a parallel / parallel GC algorithm, so more than one thread is involved. In particular, there are a number of threads for garbage collection:

  • ParallelGC Threads are the threads that are used during the β€œstop the world” collection phase.
  • Parallel marking streams (or parallel GC streams) are streams used to mark regions as candidates for cleaning and starting without stopping application streams.
  • Joint refinement G1 Themes are responsible for marking changes in a separate register, marked by a set of links

G1GC can be enabled by setting -XX:+UseG1GC (note that although it was available in Java 7 G1GC at that time was unreliable, so do not use it during production (and since Java 7 is complete, you should not use this in production)).

sources https://blogs.oracle.com/g1gc/entry/g1gc_faq and http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html

+1
source

Source: https://habr.com/ru/post/918189/


All Articles