15

I see there are six thread types implemented into the HotSpot JVM: VMThread, CGCThread, PGCThread, JavaThread, CompilerThread and WatcherThread. However I don't know which thread type is doing what exactly. Here is what I understood so far:

  • VMThread: run VM tasks like the garbage collector.
  • CGCThread: Concurrent garbage collector.
  • PGCThread: Parallel garbage collector (differences with CGC?).
  • JavaThread: Program's threads, I guess.
  • CompilerThread: A thread for the compiler?
  • WatcherThread: ?

Additional question: what about other JVMs?

Florian Richoux
  • 1,543
  • 1
  • 14
  • 28
  • 2
    Parallel vs concurrent: http://stackoverflow.com/questions/1897993/difference-between-concurrent-programming-and-parallel-programming – m0skit0 Mar 06 '13 at 15:37
  • 1
    PCG vs CGC in Hotspot: http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors – assylias Mar 06 '13 at 15:54
  • 2
    The CompilerThread is for the JIT compiler. – Chochos Mar 07 '13 at 04:30
  • 1
    Some info about the WatcherThread here: https://blogs.oracle.com/ksrini/entry/we_take_java_performance_very – assylias Mar 07 '13 at 13:49

3 Answers3

5

You can find a brief explanation on the OpenJDK website:

The main kinds of VM threads are as follows:

  • VM thread: This singleton instance of VMThread is responsible for executing VM operations, which are discussed below
  • Periodic task thread: This singleton instance of WatcherThread simulates timer interrupts for executing periodic operations within the VM
  • GC threads: These threads, of different types, support parallel and concurrent garbage collection
  • Compiler threads: These threads perform runtime compilation of bytecode to native code
  • Signal dispatcher thread: This thread waits for process directed signals and dispatches them to a Java level signal handling method

You might want to read the whole Thread Management paragraph since it continues further explanations, e.g. what the VM thread is responsible for.

box
  • 3,156
  • 3
  • 26
  • 36
3

Ok, thanks to comments, we have the beginning of an answer:

1) Since the garbage collector has a stop-the-world mecanism, there exist besides tunings two ways to reduce these pauses:

  • With parallel GCs running via PGCThreads such that, if n cores are available, then n threads can be run during pauses to shorten them.
  • With a concurrent GC, running via a CGCThread and finishing the job of the regular GC off pauses, concurrently with the main program thread.

2) The CompilerThread runs the Just-In-Time compiler.

3) The WatcherThread simulates timer interrupts every 50ms to run periodic operations in the VM.

Florian Richoux
  • 1,543
  • 1
  • 14
  • 28
1

And I would add that there are 7 threads type in JVM! Don't miss os_thread

path: Defined in: /hotspot/src/share/vm/runtime/os.hpp

  enum ThreadType {
    vm_thread,
    cgc_thread,        // Concurrent GC thread
    pgc_thread,        // Parallel GC thread
    java_thread,       // Java, CodeCacheSweeper, JVMTIAgent and Service threads.
    compiler_thread,
    watcher_thread,
    os_thread
  };
skytree
  • 1,060
  • 2
  • 13
  • 38