Skip to content
This repository has been archived by the owner before Nov 9, 2022. It is now read-only.
Permalink
Browse files
8256382: Use try_lock for hs_err EventLog printing
Reviewed-by: stuefe
  • Loading branch information
stefank committed Dec 2, 2020
1 parent bff68f1 commit 1fd0ea703522472a14d1d02fe5290e710d7858b1
Showing 1 changed file with 30 additions and 4 deletions.
@@ -311,12 +311,38 @@ inline void Events::log_deopt_message(Thread* thread, const char* format, ...) {

template <class T>
inline void EventLogBase<T>::print_log_on(outputStream* out, int max) {
if (Thread::current_or_null() == NULL) {
// Not yet attached? Don't try to use locking
struct MaybeLocker {
Mutex* const _mutex;
bool _proceed;
bool _locked;

MaybeLocker(Mutex* mutex) : _mutex(mutex), _proceed(false), _locked(false) {
if (Thread::current_or_null() == NULL) {
_proceed = true;
} else if (VMError::is_error_reported()) {
if (_mutex->try_lock_without_rank_check()) {
_proceed = _locked = true;
}
} else {
_mutex->lock_without_safepoint_check();
_proceed = _locked = true;
}
}
~MaybeLocker() {
if (_locked) {
_mutex->unlock();
}
}
};

MaybeLocker ml(&_mutex);

if (ml._proceed) {
print_log_impl(out, max);
} else {
MutexLocker ml(&_mutex, Mutex::_no_safepoint_check_flag);
print_log_impl(out, max);
out->print_cr("%s (%d events):", _name, _count);
out->print_cr("No events printed - crash while holding lock");
out->cr();
}
}

0 comments on commit 1fd0ea7

Please sign in to comment.