|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. 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 | +package compiler.oracle; |
| 25 | + |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +import jdk.test.lib.process.OutputAnalyzer; |
| 30 | +import jdk.test.lib.process.ProcessTools; |
| 31 | + |
| 32 | +import compiler.lib.ir_framework.CompilePhase; |
| 33 | + |
| 34 | +/** |
| 35 | + * @test |
| 36 | + * @bug 8372097 |
| 37 | + * @summary Checks that -XX:CompileCommand=PhasePrintLevel,... interacts with |
| 38 | + * -XX:PrintPhaseLevel as expected. |
| 39 | + * @library /test/lib / |
| 40 | + * @requires vm.debug & vm.compiler2.enabled & vm.flagless |
| 41 | + * @run driver compiler.oracle.TestPhasePrintLevel |
| 42 | + */ |
| 43 | + |
| 44 | +public class TestPhasePrintLevel { |
| 45 | + |
| 46 | + static final String level1Phase = CompilePhase.FINAL_CODE.getName(); |
| 47 | + static final String level2Phase = CompilePhase.GLOBAL_CODE_MOTION.getName(); |
| 48 | + |
| 49 | + public static void main(String[] args) throws Exception { |
| 50 | + // Test flag level < 0: nothing should be printed regardless of the compile command level. |
| 51 | + test(-1, -1, null, level1Phase); |
| 52 | + test(-1, 0, null, level1Phase); |
| 53 | + test(-1, 1, null, level1Phase); |
| 54 | + |
| 55 | + // Test flag level = 0: the compile command level should determine what is printed. |
| 56 | + test(0, -1, null, level1Phase); |
| 57 | + test(0, 0, null, level1Phase); |
| 58 | + test(0, 1, level1Phase, null); |
| 59 | + test(0, 2, level2Phase, null); |
| 60 | + |
| 61 | + // Test flag level > 0: the compile command level should take precedence. |
| 62 | + test(1, -1, null, level1Phase); |
| 63 | + test(1, 0, null, level1Phase); |
| 64 | + test(1, 1, level1Phase, null); |
| 65 | + test(2, 1, level1Phase, level2Phase); |
| 66 | + test(1, 2, level2Phase, null); |
| 67 | + } |
| 68 | + |
| 69 | + static void test(int flagLevel, int compileCommandLevel, String expectedPhase, String unexpectedPhase) throws Exception { |
| 70 | + List<String> options = new ArrayList<String>(); |
| 71 | + options.add("-Xbatch"); |
| 72 | + options.add("-XX:CompileOnly=" + getTestName()); |
| 73 | + options.add("-XX:PrintPhaseLevel=" + flagLevel); |
| 74 | + options.add("-XX:CompileCommand=PhasePrintLevel," + getTestName() + "," + compileCommandLevel); |
| 75 | + options.add(getTestClass()); |
| 76 | + OutputAnalyzer oa = ProcessTools.executeTestJava(options); |
| 77 | + oa.shouldHaveExitValue(0) |
| 78 | + .shouldContain("CompileCommand: PhasePrintLevel compiler/oracle/TestPhasePrintLevel$TestMain.test intx PhasePrintLevel = " + compileCommandLevel) |
| 79 | + .shouldNotContain("CompileCommand: An error occurred during parsing") |
| 80 | + .shouldNotContain("# A fatal error has been detected by the Java Runtime Environment"); |
| 81 | + if (expectedPhase != null) { |
| 82 | + oa.shouldContain(expectedPhase); |
| 83 | + } |
| 84 | + if (unexpectedPhase != null) { |
| 85 | + oa.shouldNotContain(unexpectedPhase); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + static String getTestClass() { |
| 90 | + return TestMain.class.getName(); |
| 91 | + } |
| 92 | + |
| 93 | + static String getTestName() { |
| 94 | + return getTestClass() + "::test"; |
| 95 | + } |
| 96 | + |
| 97 | + static class TestMain { |
| 98 | + public static void main(String[] args) { |
| 99 | + for (int i = 0; i < 10_000; i++) { |
| 100 | + test(i); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + static void test(int i) { |
| 105 | + if ((i % 1000) == 0) { |
| 106 | + System.out.println("Hello World!"); |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments