Skip to content

Commit

Permalink
8254877: GCLogPrecious::_lock rank constrains what locks you are allo…
Browse files Browse the repository at this point in the history
…wed to have when crashing

Reviewed-by: eosterlund
  • Loading branch information
stefank committed Dec 2, 2020
1 parent 1fd0ea7 commit 287b829
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/hotspot/share/gc/shared/gcLogPrecious.cpp
Expand Up @@ -33,7 +33,7 @@ Mutex* GCLogPrecious::_lock = NULL;
void GCLogPrecious::initialize() {
_lines = new (ResourceObj::C_HEAP, mtGC) stringStream();
_temp = new (ResourceObj::C_HEAP, mtGC) stringStream();
_lock = new Mutex(Mutex::tty,
_lock = new Mutex(Mutex::event, /* The lowest lock rank I could find */
"GCLogPrecious Lock",
true,
Mutex::_safepoint_check_never);
Expand Down Expand Up @@ -77,11 +77,23 @@ void GCLogPrecious::vwrite_and_debug(LogTargetHandle log,
}

void GCLogPrecious::print_on_error(outputStream* st) {
if (_lines != NULL) {
MutexLocker locker(_lock, Mutex::_no_safepoint_check_flag);
if (_lines->size() > 0) {
st->print_cr("GC Precious Log:");
st->print_cr("%s", _lines->base());
}
st->print_cr("GC Precious Log:");

if (_lines == NULL) {
st->print_cr("<Not initialized>\n");
return;
}

if (!_lock->try_lock_without_rank_check()) {
st->print_cr("<Skipped>\n");
return;
}

if (_lines->size() == 0) {
st->print_cr("<Empty>\n");
} else {
st->print_cr("%s", _lines->base());
}

_lock->unlock();
}

0 comments on commit 287b829

Please sign in to comment.