Default garbage collector for Java 8
Asked Answered
C

4

119

What is the default garbage collector for Java 8?

When I check the JMX Beans, they reveal it to be the parallel collector for the new generation and the old serial collector for the old generation.

Chuckhole answered 19/10, 2015 at 3:44 Comment(0)
T
164

Default garbage collectors:

  • Java 7 - Parallel GC
  • Java 8 - Parallel GC
  • Java 9 - G1 GC
  • Java 10 - G1 GC
Trillium answered 19/4, 2017 at 5:21 Comment(2)
JEP 248: Make G1 the Default Garbage CollectorFunnel
No source added by the author for this answer.Aloe
N
92

Selecting the default garbage collector (among other things) is what's called the ergonomics process of the JVM. This process depends on the class of your machine.

  • For server-class machine, defined as a machine with 2 or more physical processors and 2 or more GB of physical memory (regardless of the platform), the default garbage collector is the parallel collector (also known as throughput collector).
  • For client-class machine, defined as a 32-bit platform on Windows or a single-processor machine, the default garbage collector is the serial collector.

Since practically all machines have 2 or more CPU, a machine is practically always considered server-class by the JVM. That's why you will find a lot of references considering the parallel collector to be the default garbage collector.

Nameplate answered 19/10, 2015 at 9:9 Comment(0)
C
80

Java has four types of garbage collectors(Up to version 10),but after stable release of java 11 , it would be 5 types. These are:-

  1. Serial Garbage Collector- S GC
  2. Parallel Garbage Collector- P GC
  3. CMS Garbage Collector- CMS GC
  4. G1 Garbage Collector- G1 GC
  5. The Z Garbage Collector- ZGC

Default implementations of GC in java -

JVM GC

 Java 7 - P GC       
 Java 8 - P GC
 Java 9 - G1 GC
 Java 10- G1 GC
 Java 11- Z GC(I am not sure but it would be default GC of java 11)

More details for ZGC,please visit

http://openjdk.java.net/projects/zgc/

https://www.opsian.com/blog/javas-new-zgc-is-very-exciting/

Note: If you want to verify, which GC is currently being used by JVM,you can go for following command to show default GC:-

$ java -XX:+PrintCommandLineFlags -version 

If you want to set GC according to your need, you can do this by following command. Here I am going to set G1 GC as default GC.

$ java -XX:+UseG1GC -XX:+PrintCommandLineFlags -version 

enter image description here

For more details , please visit 

https://javapapers.com/java/types-of-java-garbage-collectors/

https://alvinalexander.com/java/java-jvm-how-show-which-garbage-collector-running

Cacophony answered 23/7, 2018 at 9:46 Comment(6)
Would be useful to mention the source of the diagram for further detailsMolecular
hi @Molecular here is source url javapapers.com/java/types-of-java-garbage-collectorsCacophony
@Cacophony I don't think ZGC is default GC of JDK 11. Open JDK wiki(wiki.openjdk.java.net/display/zgc/Main) states "Use the -XX:+UnlockExperimentalVMOptions -XX:+UseZGC options to enable ZGC." that means it's not the default.Attar
No it is not the default of JDK11. -XX:+UnlockExperimentalVMOptions -XX:+UseZGC options to enable ZGC to unlock ZGCCommendatory
The flow diagrams of the picture are really useful to explain the difference between "serial", "parallel", and "concurrent" garbage collectors, but it gets really nonsensical with these nine colored squares for the G1 collector. What are they supposed to mean? Threads become squares?Draughtboard
By default Java 11 uses G1 GC too as printed by the command you provided: java -XX:+PrintCommandLineFlags -version .Lemal
Q
1

Since Java 9 until Java 15 the G1GC is the default even on Java 15 which adds two new generation Garbage collectors the one that Oracle develop ZGC and a red hat implementation which is Shenandoah both are production ready in Java 15 september of 2020. ZGC is available on OPEN JDK https://wiki.openjdk.java.net/display/zgc/Main

Quinsy answered 18/9, 2020 at 10:46 Comment(4)
1. Shenandoah only applies for OpenJDK, Oracle does not have it. 2. ZGC is not the default GC forJDK 8, nor 11, one still needed to use UnlockExperimentalVMOptions, but on jdk 15 not anymore. 3. ParallelGC is the default GC for JDK 8, which is actually the question here.Antiquary
Im stating that since Java 9 until Java 15 G1GC is still the default... even when 2 new GC was added recently..Quinsy
No. You said Since Java 8 until Java 15 the G1GC is the default even on Java 15, the phrasing is incorrect. JDK 8 default is Parallel, you said it yourself as comment the answer still wrong. Shenandoah can be used in JDK 8 and JDK 11, it was back ported.Antiquary
Yes sorry i really mean from Java 9Quinsy

© 2022 - 2024 — McMap. All rights reserved.