Find what type of garbage collector works.

Post JSE 5 ergonomics is designed to automatically select the right type of garbage collector for you (among other things).

I would like to know if there is a way to confirm / find out the type of garbage collector and the selected performance goals / current set by the ergonomics of the JVM.

+46
java jvm
Feb 17 2018-11-11T00:
source share
8 answers
java -XX:+PrintCommandLineFlags -version 

will show you the default garbage collector. I also found the following useful page that details the default garbage collector for various operating systems.

http://www.techpaste.com/2012/02/default-jvm-settings-gc-jit-java-heap-sizes-xms-xmx-operating-systems/#more-3569

+52
Apr 02 2018-12-12T00:
source share
 import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; import java.util.List; public class GCInformation { public static void main(String[] args) { try { List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcMxBean : gcMxBeans) { System.out.println(gcMxBean.getName()); System.out.println(gcMxBean.getObjectName()); } } catch (RuntimeException re) { throw re; } catch (Exception exp) { throw new RuntimeException(exp); } } } 

eg. try running commands to find out different types of GC

 java -XX:+PrintCommandLineFlags GCInformation java -XX:+PrintCommandLineFlags -XX:+UseParallelGC GCInformation java -XX:+PrintCommandLineFlags -XX:+UseConcMarkSweepGC -XX:+UseParNewGC GCInformation java -XX:+PrintCommandLineFlags -XX:+UseConcMarkSweepGC -XX:-UseParNewGC GCInformation 
+11
Nov 07 '13 at 13:43
source share

Not a direct answer to your question, but I believe that this is what you are looking for.

According to the Java 6 documentation 1 and 2 (and not just Java 5):

Link 1 says:

On server class machines running the VM server, the garbage collector (GC) has changed from the previous collector [...] to the parallel collector

Link 2 says:

Starting from J2SE 5.0, when the application starts, the launcher may try to determine if the application is running on the server-class machine, and if so, use the Java HotSpot Virtual Server (VM server) instead of the Java HotSpot Client Virtual Machine (client virtual machine) )

Also, link 2 says:

Note. For Java SE 6, the definition of a server-class machine is one with less than 2 CPUs and at least 2 GB of physical memory.

From this information you can know that if the field is a server (according to 2 ), then it will use a parallel GC. You can also conclude that it will not change the GC at runtime.

You may find the right answer for non-server machines if you delve deeper into the documentation.

+9
Mar 03 '11 at 1:10
source share
 -XX:+PrintGC -XX:+PrintGCDetails 

This will print GC. In my case, it prints:

 [GC (Allocation Failure) [PSYoungGen: 348192K->32K(348672K)] 356792K->8632K(1048064K), 0.0111518 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

This means that the Parallel Garbage team is being used for the younger generation. “Refusal of distribution” means that garbage collection has begun because of a lack of space in the heap of the younger generation.

+1
May 19 '16 at 12:56
source share

This command prints the GC type of the running JVM:

jmap -heap <pid> | grep GC

For a modern computer (multiple processor, large memory), the JVM will detect it as a server machine and use Parallel GC by default, unless you specify which gc to use explicitly through the JVM flags.

eg

jmap -heap 26806 | grep GC

Output:

Parallel GC with 8 threads

+1
Feb 15 '17 at 12:42 on
source share
0
Feb 20 '11 at 17:20
source share

Here is some information on how to programmatically obtain GC information, but it looks like she might need the GC name in advance. Inconvenient.

http://blogs.oracle.com/poonam/entry/how_to_programmatically_obtain_gc

Edit: try ManagementFactory.getGarbageCollectorMXBeans() and iterate over the returned list. One of them will be active.

0
Mar 03 '11 at 1:30
source share

You can use the -XX flag for the JRE to select the garbage collector of your choice.

Set up a garbage collection with a JavaTM VM 5.0

Alternatively, you can use JConsole to monitor garbage collection.

-one
Feb 17 2018-11-11T00:
source share



All Articles