From 8efb01693dd198540d437d5f2867011fa1ca486d Mon Sep 17 00:00:00 2001
Date: Thu, 14 May 2026 16:37:14 +0800
Subject: Print class loading details when enable TraceClassLoading
src/hotspot/share/oops/instanceKlass.cpp | 20 ++++++++++++++++++++
src/hotspot/share/runtime/globals.hpp | 8 ++++++++
2 files changed, 28 insertions(+)
@@ -3883,6 +3883,14 @@ void InstanceKlass::print_class_load_logging(ClassLoaderData* loader_data,
if (log_is_enabled(Debug, class, load)) {
stringStream debug_stream;
+ if (PrintClassLoadingDetails) {
+ debug_stream.date_stamp(true);
+ OSThread* osThread = Thread::current()->osthread();
+ if (osThread != NULL) {
+ debug_stream.print(" tid: %d", osThread->thread_id());
+ }
+ }
+
// Class hierarchy info
debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT,
p2i(this), p2i(superklass()));
@@ -3910,6 +3918,18 @@ void InstanceKlass::print_class_load_logging(ClassLoaderData* loader_data,
cfs->length()));
}
+ if (PrintClassLoadingDetails) {
+ const char* klass_name = external_name();
+ Thread* current = Thread::current();
+ if (PrintThreadStackOnLoadingClass != NULL && klass_name != NULL &&
+ strstr(klass_name, PrintThreadStackOnLoadingClass) && current->is_Java_thread()) {
+ JavaThread* javaThread = JavaThread::cast(current);
+ debug_stream.print("\n");
+ javaThread->print_on(&debug_stream);
+ javaThread->print_stack_on(&debug_stream);
+ }
+ }
+
msg.debug("%s", debug_stream.as_string());
}
}
@@ -703,6 +703,14 @@ const int ObjectAlignmentInBytes = 8;
develop(bool, UsePrivilegedStack, true, \
"Enable the security JVM functions") \
\
+ product(bool, PrintClassLoadingDetails, false, MANAGEABLE, \
+ "Print class loading details (including date stamps, thread id " \
+ "and effective class loaders) when enable TraceClassLoading") \
+ \
+ product(ccstr, PrintThreadStackOnLoadingClass, NULL, MANAGEABLE, \
+ "Print thread stack when the specified class is loaded when " \
+ "enable PrintClassLoadingDetails") \
+ \
product(bool, ClassUnloading, true, \
"Do unloading of classes") \
\
--
2.17.1