|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 IBM Corporation. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/** |
| 25 | + * @test |
| 26 | + * @bug 8382777 |
| 27 | + * @summary Test that PrintMethodData output matches expectations |
| 28 | + * @requires vm.flagless |
| 29 | + * @modules java.base/jdk.internal.misc |
| 30 | + * @library /test/lib / |
| 31 | + * @run driver ${test.main.class} |
| 32 | + */ |
| 33 | + |
| 34 | +package compiler.profiling; |
| 35 | + |
| 36 | +import compiler.lib.generators.Generator; |
| 37 | +import compiler.lib.generators.Generators; |
| 38 | +import jdk.test.lib.process.OutputAnalyzer; |
| 39 | +import jdk.test.lib.process.ProcessTools; |
| 40 | + |
| 41 | +public class TestPrintMethodData { |
| 42 | + public static void main(String[] args) throws Exception { |
| 43 | + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( |
| 44 | + "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintMethodData", |
| 45 | + "-XX:CompileCommand=compileonly,compiler.profiling.TestPrintMethodData::test*", |
| 46 | + Launcher.class.getName()); |
| 47 | + |
| 48 | + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); |
| 49 | + analyzer.shouldHaveExitValue(0); |
| 50 | + analyzer.shouldContain("BranchData"); |
| 51 | + analyzer.shouldMatch("taken\\(\\d+\\)"); |
| 52 | + } |
| 53 | + |
| 54 | + static long testLongReductionSimpleMax(long[] array) { |
| 55 | + long result = Long.MIN_VALUE; |
| 56 | + for (int i = 0; i < array.length; i++) { |
| 57 | + var v = array[i]; |
| 58 | + result = Math.max(v, result); |
| 59 | + } |
| 60 | + return result; |
| 61 | + } |
| 62 | + |
| 63 | + static class Launcher { |
| 64 | + private static final Generator<Long> GEN_LONG = Generators.G.longs(); |
| 65 | + private static final int SIZE = 1024; |
| 66 | + |
| 67 | + static void main(String[] args) throws Exception { |
| 68 | + long[] longs = new long[SIZE]; |
| 69 | + Generators.G.fill(GEN_LONG, longs); |
| 70 | + |
| 71 | + for (int i = 0; i < 20_000; i++) { |
| 72 | + testLongReductionSimpleMax(longs); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments