Skip to content

Commit 60ee062

Browse files
eme64chhagedorn
andcommitted
8351952: [IR Framework]: allow ignoring methods that are not compilable
Co-authored-by: Christian Hagedorn <[email protected]> Reviewed-by: chagedorn, thartmann
1 parent 5a5b342 commit 60ee062

17 files changed

+442
-27
lines changed

test/hotspot/jtreg/compiler/lib/ir_framework/Test.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -84,4 +84,12 @@
8484
* available level which is usually {@link CompLevel#C2}.
8585
*/
8686
CompLevel compLevel() default CompLevel.ANY;
87+
88+
/**
89+
* In rare cases, methods may not be compilable because of a compilation bailout. By default, this leads to a
90+
* test failure. However, if such cases are expected in a specific test, this flag can be set to true, which
91+
* allows the test to pass even if there is no compilation. Any associated {@link IR} rule is only executed
92+
* if the test method was compiled, and else it is ignored silently.
93+
*/
94+
boolean allowNotCompilable() default false;
8795
}

test/hotspot/jtreg/compiler/lib/ir_framework/TestFramework.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public class TestFramework {
175175
private List<String> flags;
176176
private int defaultWarmup = -1;
177177
private boolean testClassesOnBootClassPath;
178+
private boolean isAllowNotCompilable = false;
178179

179180
/*
180181
* Public interface methods
@@ -409,6 +410,19 @@ public TestFramework setDefaultWarmup(int defaultWarmup) {
409410
return this;
410411
}
411412

413+
/**
414+
* In rare cases, methods may not be compilable because of a compilation bailout. By default, this leads to a
415+
* test failure. However, if such cases are expected in multiple methods in a test class, this flag can be set to
416+
* true, which allows any test to pass even if there is a compilation bailout. If only selected methods are prone
417+
* to bail out, it is preferred to use {@link Test#allowNotCompilable()} instead for more fine-grained control.
418+
* By setting this flag, any associated {@link IR} rule of a test is only executed if the test method was compiled,
419+
* and else it is ignored silently.
420+
*/
421+
public TestFramework allowNotCompilable() {
422+
this.isAllowNotCompilable = true;
423+
return this;
424+
}
425+
412426
/**
413427
* Get the VM output of the test VM. Use {@code -DVerbose=true} to enable more debug information. If scenarios
414428
* were run, use {@link Scenario#getTestVMOutput()}.
@@ -773,10 +787,10 @@ private List<String> anyNonWhitelistedJTregVMAndJavaOptsFlags() {
773787

774788
private void runTestVM(List<String> additionalFlags) {
775789
TestVMProcess testVMProcess = new TestVMProcess(additionalFlags, testClass, helperClasses, defaultWarmup,
776-
testClassesOnBootClassPath);
790+
isAllowNotCompilable, testClassesOnBootClassPath);
777791
if (shouldVerifyIR) {
778792
try {
779-
TestClassParser testClassParser = new TestClassParser(testClass);
793+
TestClassParser testClassParser = new TestClassParser(testClass, isAllowNotCompilable);
780794
Matchable testClassMatchable = testClassParser.parse(testVMProcess.getHotspotPidFileName(),
781795
testVMProcess.getIrEncoding());
782796
IRMatcher matcher = new IRMatcher(testClassMatchable);

test/hotspot/jtreg/compiler/lib/ir_framework/driver/TestVMProcess.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -65,11 +65,12 @@ public class TestVMProcess {
6565
private String irEncoding;
6666

6767
public TestVMProcess(List<String> additionalFlags, Class<?> testClass, Set<Class<?>> helperClasses, int defaultWarmup,
68-
boolean testClassesOnBootClassPath) {
68+
boolean allowNotCompilable, boolean testClassesOnBootClassPath) {
6969
this.cmds = new ArrayList<>();
7070
TestFrameworkSocket socket = new TestFrameworkSocket();
7171
try (socket) {
72-
prepareTestVMFlags(additionalFlags, socket, testClass, helperClasses, defaultWarmup, testClassesOnBootClassPath);
72+
prepareTestVMFlags(additionalFlags, socket, testClass, helperClasses, defaultWarmup,
73+
allowNotCompilable, testClassesOnBootClassPath);
7374
start();
7475
}
7576
processSocketOutput(socket);
@@ -93,7 +94,8 @@ public static String getLastTestVMOutput() {
9394
}
9495

9596
private void prepareTestVMFlags(List<String> additionalFlags, TestFrameworkSocket socket, Class<?> testClass,
96-
Set<Class<?>> helperClasses, int defaultWarmup, boolean testClassesOnBootClassPath) {
97+
Set<Class<?>> helperClasses, int defaultWarmup, boolean allowNotCompilable,
98+
boolean testClassesOnBootClassPath) {
9799
// Set java.library.path so JNI tests which rely on jtreg nativepath setting work
98100
cmds.add("-Djava.library.path=" + Utils.TEST_NATIVE_PATH);
99101
// Need White Box access in test VM.
@@ -128,6 +130,10 @@ private void prepareTestVMFlags(List<String> additionalFlags, TestFrameworkSocke
128130
cmds.add("-DWarmup=" + defaultWarmup);
129131
}
130132

133+
if (allowNotCompilable) {
134+
cmds.add("-DAllowNotCompilable=true");
135+
}
136+
131137
cmds.add(TestVM.class.getName());
132138
cmds.add(testClass.getName());
133139
if (helperClasses != null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.lib.ir_framework.driver.irmatching.irmethod;
25+
26+
import compiler.lib.ir_framework.IR;
27+
import compiler.lib.ir_framework.Run;
28+
import compiler.lib.ir_framework.RunMode;
29+
30+
import java.lang.reflect.Method;
31+
32+
/**
33+
* This class represents a special IR method which was not compiled by the IR framework, but this was explicitly allowed
34+
* by "allowNotCompilable". This happens when the compiler bails out of a compilation (i.e. no compilation) but we treat
35+
* this as valid case. Any associated IR rules pass silently.
36+
*
37+
* @see IR
38+
* @see Test
39+
*/
40+
public class NotCompilableIRMethod implements IRMethodMatchable {
41+
private final Method method;
42+
private final int ruleCount;
43+
44+
public NotCompilableIRMethod(Method method, int ruleCount) {
45+
this.method = method;
46+
this.ruleCount = ruleCount;
47+
}
48+
49+
@Override
50+
public String name() {
51+
return method.getName();
52+
}
53+
54+
/**
55+
* Directly return a {@link NotCompilableIRMethodMatchResult} as we do not need to match IR rules individually.
56+
*/
57+
@Override
58+
public NotCompilableIRMethodMatchResult match() {
59+
return new NotCompilableIRMethodMatchResult(method, ruleCount);
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.lib.ir_framework.driver.irmatching.irmethod;
25+
26+
import compiler.lib.ir_framework.Run;
27+
import compiler.lib.ir_framework.RunMode;
28+
import compiler.lib.ir_framework.driver.irmatching.MatchResult;
29+
import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor;
30+
31+
import java.lang.reflect.Method;
32+
33+
/**
34+
* This class represents a special matching result of an IR method where the compilation output was completely empty,
35+
* but this was exlicitly allowed by "allowNotCompilable". This happens when the compiler bails out of a compilation
36+
* (i.e. no compilation) but we treat this as valid case. Any associated IR rules pass silently.
37+
*
38+
* @see NotCompilableIRMethod
39+
* @see Test
40+
*/
41+
public class NotCompilableIRMethodMatchResult implements MatchResult {
42+
private final Method method;
43+
private final int failedIRRules;
44+
45+
public NotCompilableIRMethodMatchResult(Method method, int failedIRRules) {
46+
this.method = method;
47+
this.failedIRRules = failedIRRules;
48+
}
49+
50+
@Override
51+
public boolean fail() {
52+
return false;
53+
}
54+
55+
@Override
56+
public void accept(MatchResultVisitor visitor) {
57+
visitor.visitMethodNotCompilable(method, failedIRRules);
58+
}
59+
}
60+

test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/IRMethodBuilder.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,10 +23,13 @@
2323

2424
package compiler.lib.ir_framework.driver.irmatching.parser;
2525

26+
import compiler.lib.ir_framework.Test;
27+
import compiler.lib.ir_framework.TestFramework;
2628
import compiler.lib.ir_framework.driver.irmatching.Compilation;
2729
import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethod;
2830
import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethodMatchable;
2931
import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompiledIRMethod;
32+
import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompilableIRMethod;
3033
import compiler.lib.ir_framework.driver.irmatching.parser.hotspot.HotSpotPidFileParser;
3134
import compiler.lib.ir_framework.driver.irmatching.parser.hotspot.LoggedMethod;
3235
import compiler.lib.ir_framework.driver.irmatching.parser.hotspot.LoggedMethods;
@@ -41,10 +44,12 @@
4144
class IRMethodBuilder {
4245
private final Map<String, LoggedMethod> loggedMethods;
4346
private final TestMethods testMethods;
47+
private final boolean allowNotCompilable;
4448

45-
public IRMethodBuilder(TestMethods testMethods, LoggedMethods loggedMethods) {
49+
public IRMethodBuilder(TestMethods testMethods, LoggedMethods loggedMethods, boolean allowNotCompilable) {
4650
this.testMethods = testMethods;
4751
this.loggedMethods = loggedMethods.loggedMethods();
52+
this.allowNotCompilable = allowNotCompilable;
4853
}
4954

5055
/**
@@ -64,7 +69,13 @@ private IRMethodMatchable createIRMethod(String methodName, TestMethod testMetho
6469
return new IRMethod(testMethod.method(), testMethod.irRuleIds(), testMethod.irAnnos(),
6570
new Compilation(loggedMethod.compilationOutput()), vmInfo);
6671
} else {
67-
return new NotCompiledIRMethod(testMethod.method(), testMethod.irRuleIds().length);
72+
Test[] testAnnos = testMethod.method().getAnnotationsByType(Test.class);
73+
boolean allowMethodNotCompilable = allowNotCompilable || testAnnos[0].allowNotCompilable();
74+
if (allowMethodNotCompilable) {
75+
return new NotCompilableIRMethod(testMethod.method(), testMethod.irRuleIds().length);
76+
} else {
77+
return new NotCompiledIRMethod(testMethod.method(), testMethod.irRuleIds().length);
78+
}
6879
}
6980
}
7081
}

test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/TestClassParser.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,9 +42,11 @@
4242
*/
4343
public class TestClassParser {
4444
private final Class<?> testClass;
45+
private final boolean allowNotCompilable;
4546

46-
public TestClassParser(Class<?> testClass) {
47+
public TestClassParser(Class<?> testClass, boolean allowNotCompilable) {
4748
this.testClass = testClass;
49+
this.allowNotCompilable = allowNotCompilable;
4850
}
4951

5052
/**
@@ -68,7 +70,7 @@ public Matchable parse(String hotspotPidFileName, String irEncoding) {
6870
* with the parsed compilation output from {@link HotSpotPidFileParser}.
6971
*/
7072
private Matchable createTestClass(TestMethods testMethods, LoggedMethods loggedMethods, VMInfo vmInfo) {
71-
IRMethodBuilder irMethodBuilder = new IRMethodBuilder(testMethods, loggedMethods);
73+
IRMethodBuilder irMethodBuilder = new IRMethodBuilder(testMethods, loggedMethods, allowNotCompilable);
7274
SortedSet<IRMethodMatchable> irMethods = irMethodBuilder.build(vmInfo);
7375
TestFormat.throwIfAnyFailures();
7476
return new TestClass(irMethods);

test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/CompilationOutputBuilder.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525

2626
import compiler.lib.ir_framework.CompilePhase;
2727
import compiler.lib.ir_framework.IR;
28+
import compiler.lib.ir_framework.shared.TestFrameworkException;
2829
import compiler.lib.ir_framework.driver.irmatching.MatchResult;
2930
import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType;
3031
import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure;
@@ -121,6 +122,11 @@ public void visitMethodNotCompiled(Method method, int failedIRRules) {
121122
output.append("<empty>").append(System.lineSeparator());
122123
}
123124

125+
@Override
126+
public void visitMethodNotCompilable(Method method, int failedIRRules) {
127+
throw new TestFrameworkException("Sould not reach here");
128+
}
129+
124130
@Override
125131
public void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno) {
126132
acceptChildren.accept(this);

test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailCountVisitor.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -63,6 +63,11 @@ public void visitMethodNotCompiled(Method method, int failedIRRules) {
6363
irRuleCount += failedIRRules;
6464
}
6565

66+
@Override
67+
public void visitMethodNotCompilable(Method method, int failedIRRules) {
68+
irMethodCount++;
69+
}
70+
6671
public int getIrRuleCount() {
6772
return irRuleCount;
6873
}

test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/report/FailureMessageBuilder.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525

2626
import compiler.lib.ir_framework.CompilePhase;
2727
import compiler.lib.ir_framework.IR;
28+
import compiler.lib.ir_framework.shared.TestFrameworkException;
2829
import compiler.lib.ir_framework.driver.irmatching.MatchResult;
2930
import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType;
3031
import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure;
@@ -97,6 +98,10 @@ public void visitMethodNotCompiled(Method method, int failedIRRules) {
9798
indentation.sub();
9899
}
99100

101+
public void visitMethodNotCompilable(Method method, int failedIRRules) {
102+
throw new TestFrameworkException("Sould not reach here");
103+
}
104+
100105
@Override
101106
public void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno) {
102107
indentation.add();

test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/visitor/MatchResultVisitor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,6 +39,7 @@ public interface MatchResultVisitor {
3939
void visitTestClass(AcceptChildren acceptChildren);
4040
void visitIRMethod(AcceptChildren acceptChildren, Method method, int failedIRRules);
4141
void visitMethodNotCompiled(Method method, int failedIRRules);
42+
void visitMethodNotCompilable(Method method, int failedIRRules);
4243
void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno);
4344
void visitCompilePhaseIRRule(AcceptChildren acceptChildren, CompilePhase compilePhase, String compilationOutput);
4445
void visitNoCompilePhaseCompilation(CompilePhase compilePhase);

0 commit comments

Comments
 (0)