Skip to content

Commit 1fd0ea7

Browse files
committed
8256382: Use try_lock for hs_err EventLog printing
Reviewed-by: stuefe
1 parent bff68f1 commit 1fd0ea7

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/hotspot/share/utilities/events.hpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,38 @@ inline void Events::log_deopt_message(Thread* thread, const char* format, ...) {
311311

312312
template <class T>
313313
inline void EventLogBase<T>::print_log_on(outputStream* out, int max) {
314-
if (Thread::current_or_null() == NULL) {
315-
// Not yet attached? Don't try to use locking
314+
struct MaybeLocker {
315+
Mutex* const _mutex;
316+
bool _proceed;
317+
bool _locked;
318+
319+
MaybeLocker(Mutex* mutex) : _mutex(mutex), _proceed(false), _locked(false) {
320+
if (Thread::current_or_null() == NULL) {
321+
_proceed = true;
322+
} else if (VMError::is_error_reported()) {
323+
if (_mutex->try_lock_without_rank_check()) {
324+
_proceed = _locked = true;
325+
}
326+
} else {
327+
_mutex->lock_without_safepoint_check();
328+
_proceed = _locked = true;
329+
}
330+
}
331+
~MaybeLocker() {
332+
if (_locked) {
333+
_mutex->unlock();
334+
}
335+
}
336+
};
337+
338+
MaybeLocker ml(&_mutex);
339+
340+
if (ml._proceed) {
316341
print_log_impl(out, max);
317342
} else {
318-
MutexLocker ml(&_mutex, Mutex::_no_safepoint_check_flag);
319-
print_log_impl(out, max);
343+
out->print_cr("%s (%d events):", _name, _count);
344+
out->print_cr("No events printed - crash while holding lock");
345+
out->cr();
320346
}
321347
}
322348

0 commit comments

Comments
 (0)