Search code examples
javaperformancegarbage-collectionvisualvm

Does the parallel garbage collector runs on a separate thread alongside the main program


I am using the JKD8 and as I see with the following command by default the JVM use the parallel garbage collector. How can I observe if the garbage runs on a separate thread alongside the main program? Is there any parameter just like -XX:-PrintGCDetails option?

By the way, I am using Visual VM also can I observe it from there? For example in the ->"Threads" tab section because I can't find it.

java -XX:+PrintCommandLineFlags  -XX:-PrintGCDetails -version
-XX:InitialHeapSize=535233856 -XX:MaxHeapSize=8563741696 -XX:+PrintCommandLineFlags -XX:-PrintGCDetails -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Solution

  • Garbage collectors run in a separate thread. You can observe this in a thread dump:

    ...
    
    "VM Thread" os_prio=0 tid=0x00007f4fec078000 nid=0x74c9 runnable 
    
    "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f4fec01f800 nid=0x74c5 runnable 
    
    "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f4fec021800 nid=0x74c6 runnable 
    
    "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f4fec023000 nid=0x74c7 runnable 
    
    "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007f4fec025000 nid=0x74c8 runnable 
    
    ...
    

    You can generate a thread dump by sending SIGQUIT (3) to the process:

    kill -SIGQUIT <pid>
    

    See RedHat for this: https://access.redhat.com/solutions/18178