diff --git a/src/hotspot/share/utilities/events.cpp b/src/hotspot/share/utilities/events.cpp index b4d46d79ffa..1185e349b53 100644 --- a/src/hotspot/share/utilities/events.cpp +++ b/src/hotspot/share/utilities/events.cpp @@ -151,7 +151,9 @@ void UnloadingEventLog::log(Thread* thread, InstanceKlass* ik) { ik->name()->print_value_on(&st); } -void ExceptionsEventLog::log(Thread* thread, Handle h_exception, const char* message, const char* file, int line) { +void ExceptionsEventLog::log(Thread* thread, Handle h_exception, + const char* message, const char* file, int line, + int message_length_limit) { if (!should_log()) return; double timestamp = fetch_timestamp(); @@ -163,8 +165,11 @@ void ExceptionsEventLog::log(Thread* thread, Handle h_exception, const char* mes _records[index].data.size()); st.print("Exception <"); h_exception->print_value_on(&st); - st.print("%s%s> (" PTR_FORMAT ") \n" + if (message != nullptr) { + int len = message_length_limit > 0 ? message_length_limit : (int)strlen(message); + st.print(": %.*s", len, message); + } + st.print("> (" PTR_FORMAT ") \n" "thrown [%s, line %d]", - message ? ": " : "", message ? message : "", p2i(h_exception()), file, line); } diff --git a/src/hotspot/share/utilities/events.hpp b/src/hotspot/share/utilities/events.hpp index 4470002a1e3..cbbed7232fb 100644 --- a/src/hotspot/share/utilities/events.hpp +++ b/src/hotspot/share/utilities/events.hpp @@ -207,7 +207,9 @@ class ExceptionsEventLog : public ExtendedStringEventLog { ExceptionsEventLog(const char* name, const char* short_name, int count = LogEventsBufferEntries) : ExtendedStringEventLog(name, short_name, count) {} - void log(Thread* thread, Handle h_exception, const char* message, const char* file, int line); + // Message length limit of zero means no limit. + void log(Thread* thread, Handle h_exception, const char* message, + const char* file, int line, int message_length_limit = 0); }; @@ -275,7 +277,7 @@ class Events : AllStatic { // Log exception related message static void log_exception(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3); - static void log_exception(Thread* thread, Handle h_exception, const char* message, const char* file, int line); + static void log_exception(Thread* thread, Handle h_exception, const char* message, const char* file, int line, int message_length_limit = 0); static void log_redefinition(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3); @@ -345,9 +347,11 @@ inline void Events::log_exception(Thread* thread, const char* format, ...) { } } -inline void Events::log_exception(Thread* thread, Handle h_exception, const char* message, const char* file, int line) { +inline void Events::log_exception(Thread* thread, Handle h_exception, + const char* message, const char* file, + int line, int message_length_limit) { if (LogEvents && _exceptions != nullptr) { - _exceptions->log(thread, h_exception, message, file, line); + _exceptions->log(thread, h_exception, message, file, line, message_length_limit); } } diff --git a/src/hotspot/share/utilities/exceptions.cpp b/src/hotspot/share/utilities/exceptions.cpp index 034444839ab..f730b37b8ff 100644 --- a/src/hotspot/share/utilities/exceptions.cpp +++ b/src/hotspot/share/utilities/exceptions.cpp @@ -183,7 +183,7 @@ void Exceptions::_throw(JavaThread* thread, const char* file, int line, Handle h thread->set_pending_exception(h_exception(), file, line); // vm log - Events::log_exception(thread, h_exception, message, file, line); + Events::log_exception(thread, h_exception, message, file, line, MAX_LEN); }