Skip to content

Commit ea33709

Browse files
author
David Holmes
committed
8328880: Events::log_exception should limit the size of the logging message
Reviewed-by: shade, kvn
1 parent c89a1c3 commit ea33709

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/hotspot/share/utilities/events.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ void UnloadingEventLog::log(Thread* thread, InstanceKlass* ik) {
151151
ik->name()->print_value_on(&st);
152152
}
153153

154-
void ExceptionsEventLog::log(Thread* thread, Handle h_exception, const char* message, const char* file, int line) {
154+
void ExceptionsEventLog::log(Thread* thread, Handle h_exception,
155+
const char* message, const char* file, int line,
156+
int message_length_limit) {
155157
if (!should_log()) return;
156158

157159
double timestamp = fetch_timestamp();
@@ -163,8 +165,11 @@ void ExceptionsEventLog::log(Thread* thread, Handle h_exception, const char* mes
163165
_records[index].data.size());
164166
st.print("Exception <");
165167
h_exception->print_value_on(&st);
166-
st.print("%s%s> (" PTR_FORMAT ") \n"
168+
if (message != nullptr) {
169+
int len = message_length_limit > 0 ? message_length_limit : (int)strlen(message);
170+
st.print(": %.*s", len, message);
171+
}
172+
st.print("> (" PTR_FORMAT ") \n"
167173
"thrown [%s, line %d]",
168-
message ? ": " : "", message ? message : "",
169174
p2i(h_exception()), file, line);
170175
}

src/hotspot/share/utilities/events.hpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ class ExceptionsEventLog : public ExtendedStringEventLog {
207207
ExceptionsEventLog(const char* name, const char* short_name, int count = LogEventsBufferEntries)
208208
: ExtendedStringEventLog(name, short_name, count) {}
209209

210-
void log(Thread* thread, Handle h_exception, const char* message, const char* file, int line);
210+
// Message length limit of zero means no limit.
211+
void log(Thread* thread, Handle h_exception, const char* message,
212+
const char* file, int line, int message_length_limit = 0);
211213
};
212214

213215

@@ -275,7 +277,7 @@ class Events : AllStatic {
275277

276278
// Log exception related message
277279
static void log_exception(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
278-
static void log_exception(Thread* thread, Handle h_exception, const char* message, const char* file, int line);
280+
static void log_exception(Thread* thread, Handle h_exception, const char* message, const char* file, int line, int message_length_limit = 0);
279281

280282
static void log_redefinition(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
281283

@@ -345,9 +347,11 @@ inline void Events::log_exception(Thread* thread, const char* format, ...) {
345347
}
346348
}
347349

348-
inline void Events::log_exception(Thread* thread, Handle h_exception, const char* message, const char* file, int line) {
350+
inline void Events::log_exception(Thread* thread, Handle h_exception,
351+
const char* message, const char* file,
352+
int line, int message_length_limit) {
349353
if (LogEvents && _exceptions != nullptr) {
350-
_exceptions->log(thread, h_exception, message, file, line);
354+
_exceptions->log(thread, h_exception, message, file, line, message_length_limit);
351355
}
352356
}
353357

src/hotspot/share/utilities/exceptions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void Exceptions::_throw(JavaThread* thread, const char* file, int line, Handle h
183183
thread->set_pending_exception(h_exception(), file, line);
184184

185185
// vm log
186-
Events::log_exception(thread, h_exception, message, file, line);
186+
Events::log_exception(thread, h_exception, message, file, line, MAX_LEN);
187187
}
188188

189189

0 commit comments

Comments
 (0)