11#ifndef JAVA_PROFILER_LIBRARY_THREAD_STATE_H
22#define JAVA_PROFILER_LIBRARY_THREAD_STATE_H
33
4- #include " jvmti.h"
54
65enum class OSThreadState : int {
76 UNKNOWN = 0 ,
@@ -26,48 +25,6 @@ enum class ExecutionMode : int {
2625 SYSCALL = 5
2726};
2827
29- static ExecutionMode convertJvmExecutionState (int state) {
30- switch (state) {
31- case 4 :
32- case 5 :
33- return ExecutionMode::NATIVE ;
34- case 6 :
35- case 7 :
36- return ExecutionMode::JVM ;
37- case 8 :
38- case 9 :
39- return ExecutionMode::JAVA ;
40- case 10 :
41- case 11 :
42- return ExecutionMode::SAFEPOINT ;
43- default :
44- return ExecutionMode::UNKNOWN ;
45- }
46- }
47-
48- /* *
49- * Determines the execution mode from a VMThread's state.
50- *
51- * This function distinguishes Java threads from JVM internal threads based on their state.
52- * Java threads have states in [_thread_in_native, _thread_max_state) range [4, 12).
53- * JVM internal threads (GC, Compiler) have state 0 or outside this range.
54- *
55- * CRITICAL: This function is safe to call from signal handlers. It does NOT call VM::jni()
56- * which would trigger __tls_get_addr for thread-local JNIEnv lookup. If the signal interrupts
57- * during TLS initialization (e.g., ForkJoinWorkerThread startup), VM::jni() would cause
58- * re-entrant TLS allocation and heap corruption.
59- *
60- * Thread states are defined in OpenJDK:
61- * https://github.com/openjdk/jdk/blob/master/src/hotspot/share/utilities/globalDefinitions.hpp
62- * Search for "enum JavaThreadState"
63- *
64- * @param vm_thread The VMThread pointer (can be null)
65- * @return ExecutionMode::UNKNOWN if vm_thread is null,
66- * ExecutionMode::JVM for JVM internal threads,
67- * or the appropriate execution mode for Java threads
68- */
69- class VMThread ;
70-
7128inline ExecutionMode getThreadExecutionMode ();
7229
7330#endif // JAVA_PROFILER_LIBRARY_THREAD_STATE_H
0 commit comments