8343633: The ClassLoader::print_counters() prints to stdout when logging is enabled.

Reviewed-by: iklam, ccheung
This commit is contained in:
Coleen Phillimore 2024-11-14 12:40:22 +00:00
parent 8ccc48c9c8
commit 6757994ad9
3 changed files with 39 additions and 17 deletions

View File

@ -140,9 +140,6 @@ PerfCounter* ClassLoader::_perf_resolve_mh_count = nullptr;
PerfCounter* ClassLoader::_perf_resolve_mt_count = nullptr;
void ClassLoader::print_counters(outputStream *st) {
// The counters are only active if the logging is enabled, but
// we print to the passed in outputStream as requested.
if (log_is_enabled(Info, perf, class, link)) {
st->print_cr("ClassLoader:");
st->print_cr(" clinit: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", ClassLoader::class_init_time_ms(), ClassLoader::class_init_count());
st->print_cr(" link methods: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_ik_link_methods_time->get_value()) , _perf_ik_link_methods_count->get_value());
@ -153,7 +150,6 @@ void ClassLoader::print_counters(outputStream *st) {
st->print_cr(" CP_MethodHandle: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_mh_time->get_value()) , _perf_resolve_mh_count->get_value());
st->print_cr(" CP_MethodType: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_mt_time->get_value()) , _perf_resolve_mt_count->get_value());
st->cr();
}
}
GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = nullptr;

View File

@ -359,7 +359,11 @@ void print_statistics() {
ThreadsSMRSupport::log_statistics();
ClassLoader::print_counters(tty);
if (log_is_enabled(Info, perf, class, link)) {
LogStreamHandle(Info, perf, class, link) log;
log.print_cr("At VM exit:");
ClassLoader::print_counters(&log);
}
}
// Note: before_exit() can be executed only once, if more than one threads

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2024, 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
@ -24,7 +24,7 @@
/*
* @test ClassResolutionTest
* @bug 8144874
* @bug 8144874 8343633
* @requires vm.flagless
* @modules java.base/jdk.internal.misc
* @library /test/lib
@ -36,6 +36,10 @@ import jdk.test.lib.process.ProcessTools;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class ClassResolutionTest {
public static class ClassResolutionTestMain {
@ -57,6 +61,15 @@ public class ClassResolutionTest {
}
}
public static void checkOutput(String file, String decorators) throws Exception {
List<String> allLines = Files.readAllLines(Path.of(file));
for (String line : allLines) {
if (!line.contains(decorators)) {
throw new RuntimeException("Logging should contain decorators " + decorators);
}
}
}
public static void main(String... args) throws Exception {
// (1) class+resolve should turn on.
@ -74,6 +87,15 @@ public class ClassResolutionTest {
o = new OutputAnalyzer(pb.start());
o.shouldHaveExitValue(0);
o.shouldNotContain("[class,resolve]");
// (3) Test perf+class+link writes to a file, not tty.
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-Xlog:perf+class+link:output.log",
ClassResolutionTestMain.class.getName());
o = new OutputAnalyzer(pb.start());
o.shouldHaveExitValue(0);
o.shouldNotContain("[perf,class,link]");
checkOutput("output.log", "[perf,class,link]");
};
}