1

The concept of mutator thread is related to Garbage Collection.

The basic threading model in Hotspot is a 1:1 mapping between Java threads (an instance of java.lang.Thread) and native operating system threads.

What do the different (HotSpot) JVM thread types do?

In hotspot/src/share/vm/runtime/thread.hpp

// Class hierarchy
// - Thread
//   - NamedThread
//     - VMThread
//     - ConcurrentGCThread
//     - WorkerThread
//       - GangWorker
//       - GCTaskThread
//   - JavaThread
//     - various subclasses eg CompilerThread, ServiceThread
//   - WatcherThread

JavaThread is the nearest one to mutator thread. However, JavaThread has some children classes:

  • CodeCacheSweeperThread,
  • CompilerThread, // Usually I see C1, C2 compiler in JVM
  • jmitiAgentThread,
  • ServiceThread.

I don't think CodeCacheSweeperThread, CompilerThread, jmitiAgentThread are mutator threads... But how is ServiceThread?

Besides, I think CompilerThread should be an internal thread of JVM but not a mutator thread.

How to distinguish a mutator thread that is a Java program, say which thread does service the following single thread program (1:1 mapping)?

public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}
skytree
  • 1,060
  • 2
  • 13
  • 38

2 Answers2

2

The concept of mutator thread is related to Garbage Collection.

AFAIK, It's not a term generally associated with Java as every thread is assumed to be able to modify the heap. There are exceptions such as the compiler threads which only modify the native code translations.

In general, I would assume any thread can modify state unless you have a specific reason to believe otherwise.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • That's a bit broad of a statement. You have to consider JNI for example or application-embedded java runtimes (i.e. reverse JNI). Native code could start additional threads that will not have to coordinate with the GC. – the8472 Dec 04 '17 at 18:49
  • @Peter Lawrey So do you mean aside from GC Thread, other threads are mutators? – skytree Dec 04 '17 at 19:58
  • 1
    @skytree that depends on your definition. From a GC perspective you could say the mutators are the GC threads which alter the heap. For the JVM that is typically all of them. If you include non gc threads, again nearly all alter tge heap. – Peter Lawrey Dec 04 '17 at 20:20
  • 1
    @skytree: keep in mind that the JVM is in full control of the heap. Even native code has to go through a specific interface, e.g. JNI, to perform heap modifications. So it’s perfectly possible that for some implementations, no thread is considered a “mutator thread” during gc until their first attempt to perform an actual modification. For such an implementation, “mutator threads” are threads actually trying to perform a heap modification during the marking phase and only those need to be suspended. Could be potentially all threads, but may turn out to be no thread. – Holger Dec 05 '17 at 16:31
0

It is related to JVM internal threads more precisely to GC.

jaksky
  • 3,305
  • 4
  • 35
  • 68