8381145: Missing ResourceMark in Mutex::print_on()

Reviewed-by: stefank, pchilanomate, dholmes
This commit is contained in:
Coleen Phillimore 2026-04-17 16:12:21 +00:00
parent 26ccc2eaa4
commit 7f90efd7d4
3 changed files with 26 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -293,7 +293,8 @@ Mutex::Mutex(Rank rank, const char * name, bool allow_vm_block) : _owner(nullptr
_rank = rank;
_skip_rank_check = false;
assert(_rank >= static_cast<Rank>(0) && _rank <= safepoint, "Bad lock rank %s: %s", rank_name(), name);
assert(_rank >= static_cast<Rank>(0) && _rank <= safepoint, "Bad lock rank %d outside [0, %d]: %s",
static_cast<int>(rank), static_cast<int>(safepoint), name);
// The allow_vm_block also includes allowing other non-Java threads to block or
// allowing Java threads to block in native.
@ -324,25 +325,33 @@ static const char* _rank_names[] = { "event", "service", "stackwatermark", "tty"
static const int _num_ranks = 7;
static const char* rank_name_internal(Mutex::Rank r) {
static void print_rank_name_internal(outputStream* st, Mutex::Rank r) {
// Find closest rank and print out the name
stringStream st;
for (int i = 0; i < _num_ranks; i++) {
if (r == _ranks[i]) {
return _rank_names[i];
st->print("%s", _rank_names[i]);
} else if (r > _ranks[i] && (i < _num_ranks-1 && r < _ranks[i+1])) {
int delta = static_cast<int>(_ranks[i+1]) - static_cast<int>(r);
st.print("%s-%d", _rank_names[i+1], delta);
return st.as_string();
st->print("%s-%d", _rank_names[i+1], delta);
}
}
return "fail";
}
// Requires caller to have ResourceMark.
static const char* rank_name_internal(Mutex::Rank r) {
stringStream st;
print_rank_name_internal(&st, r);
return st.as_string();
}
const char* Mutex::rank_name() const {
return rank_name_internal(_rank);
}
// Does not require caller to have ResourceMark.
void Mutex::print_rank_name(outputStream* st) const {
print_rank_name_internal(st, _rank);
}
void Mutex::assert_no_overlap(Rank orig, Rank adjusted, int adjust) {
int i = 0;
@ -364,7 +373,8 @@ void Mutex::print_on(outputStream* st) const {
if (_allow_vm_block) {
st->print("%s", " allow_vm_block");
}
DEBUG_ONLY(st->print(" %s", rank_name()));
st->print(" ");
DEBUG_ONLY(print_rank_name(st));
st->cr();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -130,9 +130,11 @@ class Mutex : public CHeapObj<mtSynchronizer> {
return _skip_rank_check;
}
const char* rank_name() const;
void print_rank_name(outputStream* st) const;
public:
Rank rank() const { return _rank; }
const char* rank_name() const;
Mutex* next() const { return _next; }
#endif // ASSERT

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -323,11 +323,12 @@ TEST_VM_ASSERT_MSG(MutexSafepoint, possible_safepoint_lock,
".* Possible safepoint reached by thread that does not allow it") {
JavaThread* thread = JavaThread::current();
ThreadInVMfromNative in_native(thread);
MutexLocker ml(new Mutex(Mutex::nosafepoint, "SpecialTest_lock"),
MutexLocker ml(new Mutex(Mutex::nosafepoint-2, "SpecialTest_lock"),
Mutex::_no_safepoint_check_flag);
thread->print_thread_state_on(tty);
// If the lock above succeeds, try to safepoint to test the NSV implied with this nosafepoint lock.
ThreadBlockInVM tbivm(thread);
thread->print_thread_state_on(tty);
}
#endif // ASSERT