Skip to content

Commit 406f1bc

Browse files
Alex MenkovAlan Bateman
andcommitted
8357650: ThreadSnapshot to take snapshot of thread for thread dumps
Co-authored-by: Alan Bateman <[email protected]> Co-authored-by: Alex Menkov <[email protected]> Reviewed-by: sspitsyn, kevinw
1 parent e984fa7 commit 406f1bc

File tree

10 files changed

+716
-4
lines changed

10 files changed

+716
-4
lines changed

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ ByteSize java_lang_Thread::thread_id_offset() {
18721872
}
18731873

18741874
oop java_lang_Thread::park_blocker(oop java_thread) {
1875-
return java_thread->obj_field(_park_blocker_offset);
1875+
return java_thread->obj_field_access<MO_RELAXED>(_park_blocker_offset);
18761876
}
18771877

18781878
oop java_lang_Thread::async_get_stack_trace(oop java_thread, TRAPS) {

src/hotspot/share/classfile/vmSymbols.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,12 @@ class SerializeClosure;
742742
template(jdk_internal_vm_ThreadDumper, "jdk/internal/vm/ThreadDumper") \
743743
template(dumpThreads_name, "dumpThreads") \
744744
template(dumpThreadsToJson_name, "dumpThreadsToJson") \
745+
template(jdk_internal_vm_ThreadSnapshot, "jdk/internal/vm/ThreadSnapshot") \
746+
template(jdk_internal_vm_ThreadLock, "jdk/internal/vm/ThreadSnapshot$ThreadLock") \
747+
template(jdk_internal_vm_ThreadLock_signature, "Ljdk/internal/vm/ThreadSnapshot$ThreadLock;") \
748+
template(jdk_internal_vm_ThreadLock_array, "[Ljdk/internal/vm/ThreadSnapshot$ThreadLock;") \
749+
template(java_lang_StackTraceElement_of_name, "of") \
750+
template(java_lang_StackTraceElement_of_signature, "([Ljava/lang/StackTraceElement;)[Ljava/lang/StackTraceElement;") \
745751
\
746752
/* jcmd Thread.vthread_scheduler and Thread.vthread_pollers */ \
747753
template(jdk_internal_vm_JcmdVThreadCommands, "jdk/internal/vm/JcmdVThreadCommands") \

src/hotspot/share/include/jvm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ JVM_HoldsLock(JNIEnv *env, jclass threadClass, jobject obj);
301301
JNIEXPORT jobject JNICALL
302302
JVM_GetStackTrace(JNIEnv *env, jobject thread);
303303

304+
JNIEXPORT jobject JNICALL
305+
JVM_CreateThreadSnapshot(JNIEnv* env, jobject thread);
306+
304307
JNIEXPORT jobjectArray JNICALL
305308
JVM_GetAllThreads(JNIEnv *env, jclass dummy);
306309

src/hotspot/share/prims/jvm.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,6 +2961,15 @@ JVM_ENTRY(jobject, JVM_GetStackTrace(JNIEnv *env, jobject jthread))
29612961
return JNIHandles::make_local(THREAD, trace);
29622962
JVM_END
29632963

2964+
JVM_ENTRY(jobject, JVM_CreateThreadSnapshot(JNIEnv* env, jobject jthread))
2965+
#if INCLUDE_JVMTI
2966+
oop snapshot = ThreadSnapshotFactory::get_thread_snapshot(jthread, THREAD);
2967+
return JNIHandles::make_local(THREAD, snapshot);
2968+
#else
2969+
return nullptr;
2970+
#endif
2971+
JVM_END
2972+
29642973
JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
29652974
// We don't use a ThreadsListHandle here because the current thread
29662975
// must be alive.

src/hotspot/share/prims/jvmtiThreadState.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class JvmtiEnvThreadStateIterator : public StackObj {
7777
//
7878
// Virtual Thread Mount State Transition (VTMS transition) mechanism
7979
//
80-
class JvmtiVTMSTransitionDisabler {
80+
class JvmtiVTMSTransitionDisabler : public AnyObj {
8181
private:
8282
static volatile int _VTMS_transition_disable_for_one_count; // transitions for one virtual thread are disabled while it is positive
8383
static volatile int _VTMS_transition_disable_for_all_count; // transitions for all virtual threads are disabled while it is positive

src/hotspot/share/services/diagnosticCommand.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ void DCmd::register_dcmds(){
127127
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export, true, false));
128128
#endif // INCLUDE_JVMTI
129129
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
130+
#if INCLUDE_JVMTI
130131
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpToFileDCmd>(full_export, true, false));
132+
#endif // INCLUDE_JVMTI
131133
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VThreadSchedulerDCmd>(full_export, true, false));
132134
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VThreadPollersDCmd>(full_export, true, false));
133135
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));

0 commit comments

Comments
 (0)