8294759: Print actual lock/monitor ranking
Reviewed-by: coleenp, dholmes
This commit is contained in:
parent
7012d4ba55
commit
e38ae8a651
src/hotspot/share/runtime
test/hotspot/jtreg/runtime/logging
@ -24,6 +24,9 @@
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "gc/shared/gc_globals.hpp"
|
||||
#include "logging/log.hpp"
|
||||
#include "logging/logStream.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "memory/universe.hpp"
|
||||
#include "runtime/javaThread.hpp"
|
||||
#include "runtime/mutexLocker.hpp"
|
||||
@ -380,6 +383,16 @@ void mutex_init() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void MutexLocker::post_initialize() {
|
||||
// Print mutex ranks if requested.
|
||||
LogTarget(Info, vmmutex) lt;
|
||||
if (lt.is_enabled()) {
|
||||
ResourceMark rm;
|
||||
LogStream ls(lt);
|
||||
print_lock_ranks(&ls);
|
||||
}
|
||||
}
|
||||
|
||||
GCMutexLocker::GCMutexLocker(Mutex* mutex) {
|
||||
if (SafepointSynchronize::is_at_safepoint()) {
|
||||
_locked = false;
|
||||
@ -409,3 +422,39 @@ void print_owned_locks_on_error(outputStream* st) {
|
||||
}
|
||||
if (none) st->print_cr("None");
|
||||
}
|
||||
|
||||
void print_lock_ranks(outputStream* st) {
|
||||
st->print_cr("VM Mutex/Monitor ranks: ");
|
||||
|
||||
#ifdef ASSERT
|
||||
// Be extra defensive and figure out the bounds on
|
||||
// ranks right here. This also saves a bit of time
|
||||
// in the #ranks*#mutexes loop below.
|
||||
int min_rank = INT_MAX;
|
||||
int max_rank = INT_MIN;
|
||||
for (int i = 0; i < _num_mutex; i++) {
|
||||
Mutex* m = _mutex_array[i];
|
||||
int r = (int) m->rank();
|
||||
if (min_rank > r) min_rank = r;
|
||||
if (max_rank < r) max_rank = r;
|
||||
}
|
||||
|
||||
// Print the listings rank by rank
|
||||
for (int r = min_rank; r <= max_rank; r++) {
|
||||
bool first = true;
|
||||
for (int i = 0; i < _num_mutex; i++) {
|
||||
Mutex* m = _mutex_array[i];
|
||||
if (r != (int) m->rank()) continue;
|
||||
|
||||
if (first) {
|
||||
st->cr();
|
||||
st->print_cr("Rank \"%s\":", m->rank_name());
|
||||
first = false;
|
||||
}
|
||||
st->print_cr(" %s", m->name());
|
||||
}
|
||||
}
|
||||
#else
|
||||
st->print_cr(" Only known in debug builds.");
|
||||
#endif // ASSERT
|
||||
}
|
||||
|
@ -175,6 +175,7 @@ extern Mutex* tty_lock; // lock to synchronize output.
|
||||
// Print all mutexes/monitors that are currently owned by a thread; called
|
||||
// by fatal error handler.
|
||||
void print_owned_locks_on_error(outputStream* st);
|
||||
void print_lock_ranks(outputStream* st);
|
||||
|
||||
char *lock_name(Mutex *mutex);
|
||||
|
||||
@ -225,6 +226,8 @@ class MutexLocker: public StackObj {
|
||||
_mutex->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
static void post_initialize();
|
||||
};
|
||||
|
||||
// A MonitorLocker is like a MutexLocker above, except it allows
|
||||
|
@ -647,6 +647,7 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
|
||||
|
||||
LogConfiguration::post_initialize();
|
||||
Metaspace::post_initialize();
|
||||
MutexLocker::post_initialize();
|
||||
|
||||
HOTSPOT_VM_INIT_END();
|
||||
|
||||
|
51
test/hotspot/jtreg/runtime/logging/MutexRankTest.java
Normal file
51
test/hotspot/jtreg/runtime/logging/MutexRankTest.java
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Red Hat, Inc. 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8294759
|
||||
* @summary Verify mutex rank logging works
|
||||
* @requires vm.flagless
|
||||
* @library /test/lib
|
||||
* @run driver MutexRankTest
|
||||
*/
|
||||
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.Platform;
|
||||
|
||||
public class MutexRankTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:vmmutex",
|
||||
"-version");
|
||||
OutputAnalyzer oa = new OutputAnalyzer(pb.start());
|
||||
oa.shouldContain("VM Mutex/Monitor ranks:");
|
||||
if (Platform.isDebugBuild()) {
|
||||
oa.shouldContain("Rank \"safepoint\"");
|
||||
oa.shouldContain("Heap_lock");
|
||||
} else {
|
||||
oa.shouldContain("Only known in debug builds");
|
||||
}
|
||||
oa.shouldHaveExitValue(0);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user