Skip to content

Commit 6fc8e49

Browse files
committed
8372097: C2: PhasePrintLevel requires setting PrintPhaseLevel explicitly to be active
Reviewed-by: mhaessig, chagedorn
1 parent 852141b commit 6fc8e49

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

src/hotspot/share/opto/c2_globals.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
"0=print nothing except PhasePrintLevel directives, " \
429429
"6=all details printed. " \
430430
"Level of detail of printouts can be set on a per-method level " \
431-
"as well by using CompileCommand=PrintPhaseLevel.") \
431+
"as well by using CompileCommand=PhasePrintLevel.") \
432432
range(-1, 6) \
433433
\
434434
develop(bool, PrintIdealGraph, false, \

src/hotspot/share/opto/compile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5233,7 +5233,7 @@ void Compile::end_method() {
52335233

52345234
#ifndef PRODUCT
52355235
bool Compile::should_print_phase(const int level) const {
5236-
return PrintPhaseLevel > 0 && directive()->PhasePrintLevelOption >= level &&
5236+
return PrintPhaseLevel >= 0 && directive()->PhasePrintLevelOption >= level &&
52375237
_method != nullptr; // Do not print phases for stubs.
52385238
}
52395239

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)