From 6afb11c8d1f2adf8b1d26a606dfc7fb06eaf4d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarre=C3=B1o?= Date: Mon, 11 May 2026 10:04:18 +0000 Subject: [PATCH] 8382777: PrintMethodData not showing BranchData Reviewed-by: phubner, roland, coleenp --- src/hotspot/share/runtime/java.cpp | 3 +- .../profiling/TestPrintMethodData.java | 76 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 test/hotspot/jtreg/compiler/profiling/TestPrintMethodData.java diff --git a/src/hotspot/share/runtime/java.cpp b/src/hotspot/share/runtime/java.cpp index 03910aadc75..e501930b3a0 100644 --- a/src/hotspot/share/runtime/java.cpp +++ b/src/hotspot/share/runtime/java.cpp @@ -29,6 +29,7 @@ #include "cds/dynamicArchive.hpp" #include "classfile/classLoader.hpp" #include "classfile/classLoaderDataGraph.hpp" +#include "classfile/classPrinter.hpp" #include "classfile/javaClasses.hpp" #include "classfile/stringTable.hpp" #include "classfile/symbolTable.hpp" @@ -157,7 +158,7 @@ static void print_method_profiling_data() { m->method_data()->parameters_type_data()->print_data_on(&ss); } // Buffering to a stringStream, disable internal buffering so it's not done twice. - m->print_codes_on(&ss, 0, false); + m->print_codes_on(&ss, ClassPrinter::PRINT_METHOD_DATA, false); tty->print("%s", ss.as_string()); // print all at once total_size += m->method_data()->size_in_bytes(); } diff --git a/test/hotspot/jtreg/compiler/profiling/TestPrintMethodData.java b/test/hotspot/jtreg/compiler/profiling/TestPrintMethodData.java new file mode 100644 index 00000000000..9e14cd6ea4b --- /dev/null +++ b/test/hotspot/jtreg/compiler/profiling/TestPrintMethodData.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2026 IBM Corporation. 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 8382777 + * @summary Test that PrintMethodData output matches expectations + * @requires vm.flagless + * @modules java.base/jdk.internal.misc + * @library /test/lib / + * @run driver ${test.main.class} + */ + +package compiler.profiling; + +import compiler.lib.generators.Generator; +import compiler.lib.generators.Generators; +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class TestPrintMethodData { + public static void main(String[] args) throws Exception { + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintMethodData", + "-XX:CompileCommand=compileonly,compiler.profiling.TestPrintMethodData::test*", + Launcher.class.getName()); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(0); + analyzer.shouldContain("BranchData"); + analyzer.shouldMatch("taken\\(\\d+\\)"); + } + + static long testLongReductionSimpleMax(long[] array) { + long result = Long.MIN_VALUE; + for (int i = 0; i < array.length; i++) { + var v = array[i]; + result = Math.max(v, result); + } + return result; + } + + static class Launcher { + private static final Generator GEN_LONG = Generators.G.longs(); + private static final int SIZE = 1024; + + static void main(String[] args) throws Exception { + long[] longs = new long[SIZE]; + Generators.G.fill(GEN_LONG, longs); + + for (int i = 0; i < 20_000; i++) { + testLongReductionSimpleMax(longs); + } + } + } +}