Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5d36f14
JDK-8351952
eme64 Mar 13, 2025
44ca80d
allowed
eme64 Mar 13, 2025
35a71b1
more impl
eme64 Mar 14, 2025
b155e51
make pass
eme64 Mar 14, 2025
0e10870
per method annotation
eme64 Mar 14, 2025
cc669c5
use per method annotation
eme64 Mar 14, 2025
8b62b98
check annotation
eme64 Mar 14, 2025
03047b6
rounte allowNotCompilable to visitMethodNotCompiled
eme64 Mar 14, 2025
e7dbc76
renaming
eme64 Mar 14, 2025
e62639a
improved the test
eme64 Mar 17, 2025
4e76b7c
rm old impl
eme64 Mar 17, 2025
ae9d1d0
wip second impl
eme64 Mar 17, 2025
ffb9e65
Revert "wip second impl"
eme64 Mar 17, 2025
a59890c
Revert "rm old impl"
eme64 Mar 17, 2025
017f26e
now passes with IR rules
eme64 Mar 17, 2025
6dff7c9
rm old class
eme64 Mar 17, 2025
381db05
fix tests, and impl with MethodNotCompilableException
eme64 Mar 17, 2025
a0a2e7b
more documentation
eme64 Mar 17, 2025
744c353
refactor with NotCompilableIRMethod
eme64 Mar 17, 2025
bf0bc03
minor fixes
eme64 Mar 17, 2025
499bc31
more documentation
eme64 Mar 17, 2025
c9c6c79
fix test
eme64 Mar 17, 2025
6e42ee3
copyright years
eme64 Mar 17, 2025
7bb8c9c
typo
eme64 Mar 17, 2025
618913b
improve test with @Run
eme64 Mar 17, 2025
ce40f14
restrict test
eme64 Mar 17, 2025
e98dd89
documentation from Christian
eme64 Mar 18, 2025
c50d82f
Update test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestPh…
eme64 Mar 18, 2025
f3bdccf
more for Christian
eme64 Mar 18, 2025
f3bdb54
Merge branch 'JDK-8351952-IR-Framework-not-compilable' of https://git…
eme64 Mar 18, 2025
259a476
Apply suggestions from code review
eme64 Mar 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion test/hotspot/jtreg/compiler/lib/ir_framework/Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -84,4 +84,12 @@
* available level which is usually {@link CompLevel#C2}.
*/
CompLevel compLevel() default CompLevel.ANY;

/**
* In rare cases, methods may not be compilable because of a compilation bailout. By default, this leads to a
* test failure. However, if such cases are expected in a specific test, this flag can be set to true, which
* allows the test to pass even if there is no compilation. Any associated {@link IR} rule is only executed
* if the test method was compiled, and else it is ignored silently.
*/
boolean allowNotCompilable() default false;
}
18 changes: 16 additions & 2 deletions test/hotspot/jtreg/compiler/lib/ir_framework/TestFramework.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public class TestFramework {
private List<String> flags;
private int defaultWarmup = -1;
private boolean testClassesOnBootClassPath;
private boolean isAllowNotCompilable = false;

/*
* Public interface methods
Expand Down Expand Up @@ -409,6 +410,19 @@ public TestFramework setDefaultWarmup(int defaultWarmup) {
return this;
}

/**
* In rare cases, methods may not be compilable because of a compilation bailout. By default, this leads to a
* test failure. However, if such cases are expected in multiple methods in a test class, this flag can be set to
* true, which allows any test to pass even if there is a compilation bailout. If only selected methods are prone
* to bail out, it is preferred to use {@link Test#allowNotCompilable()} instead for more fine-grained control.
* By setting this flag, any associated {@link IR} rule of a test is only executed if the test method was compiled,
* and else it is ignored silently.
*/
public TestFramework allowNotCompilable() {
this.isAllowNotCompilable = true;
return this;
}

/**
* Get the VM output of the test VM. Use {@code -DVerbose=true} to enable more debug information. If scenarios
* were run, use {@link Scenario#getTestVMOutput()}.
Expand Down Expand Up @@ -773,10 +787,10 @@ private List<String> anyNonWhitelistedJTregVMAndJavaOptsFlags() {

private void runTestVM(List<String> additionalFlags) {
TestVMProcess testVMProcess = new TestVMProcess(additionalFlags, testClass, helperClasses, defaultWarmup,
testClassesOnBootClassPath);
isAllowNotCompilable, testClassesOnBootClassPath);
if (shouldVerifyIR) {
try {
TestClassParser testClassParser = new TestClassParser(testClass);
TestClassParser testClassParser = new TestClassParser(testClass, isAllowNotCompilable);
Matchable testClassMatchable = testClassParser.parse(testVMProcess.getHotspotPidFileName(),
testVMProcess.getIrEncoding());
IRMatcher matcher = new IRMatcher(testClassMatchable);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -65,11 +65,12 @@ public class TestVMProcess {
private String irEncoding;

public TestVMProcess(List<String> additionalFlags, Class<?> testClass, Set<Class<?>> helperClasses, int defaultWarmup,
boolean testClassesOnBootClassPath) {
boolean allowNotCompilable, boolean testClassesOnBootClassPath) {
this.cmds = new ArrayList<>();
TestFrameworkSocket socket = new TestFrameworkSocket();
try (socket) {
prepareTestVMFlags(additionalFlags, socket, testClass, helperClasses, defaultWarmup, testClassesOnBootClassPath);
prepareTestVMFlags(additionalFlags, socket, testClass, helperClasses, defaultWarmup,
allowNotCompilable, testClassesOnBootClassPath);
start();
}
processSocketOutput(socket);
Expand All @@ -93,7 +94,8 @@ public static String getLastTestVMOutput() {
}

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

if (allowNotCompilable) {
cmds.add("-DAllowNotCompilable=true");
}

cmds.add(TestVM.class.getName());
cmds.add(testClass.getName());
if (helperClasses != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. 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.
*/

package compiler.lib.ir_framework.driver.irmatching.irmethod;

import compiler.lib.ir_framework.IR;
import compiler.lib.ir_framework.Run;
import compiler.lib.ir_framework.RunMode;

import java.lang.reflect.Method;

/**
* This class represents a special IR method which was not compiled by the IR framework, but this was explicitly allowed
* by "allowNotCompilable". This happens when the compiler bails out of a compilation (i.e. no compilation) but we treat
* this as valid case. Any associated IR rules pass silently.
*
* @see IR
* @see Test
*/
public class NotCompilableIRMethod implements IRMethodMatchable {
private final Method method;
private final int ruleCount;

public NotCompilableIRMethod(Method method, int ruleCount) {
this.method = method;
this.ruleCount = ruleCount;
}

@Override
public String name() {
return method.getName();
}

/**
* Directly return a {@link NotCompilableIRMethodMatchResult} as we do not need to match IR rules individually.
*/
@Override
public NotCompilableIRMethodMatchResult match() {
return new NotCompilableIRMethodMatchResult(method, ruleCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. 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.
*/

package compiler.lib.ir_framework.driver.irmatching.irmethod;

import compiler.lib.ir_framework.Run;
import compiler.lib.ir_framework.RunMode;
import compiler.lib.ir_framework.driver.irmatching.MatchResult;
import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor;

import java.lang.reflect.Method;

/**
* This class represents a special matching result of an IR method where the compilation output was completely empty,
* but this was exlicitly allowed by "allowNotCompilable". This happens when the compiler bails out of a compilation
* (i.e. no compilation) but we treat this as valid case. Any associated IR rules pass silently.
*
* @see NotCompilableIRMethod
* @see Test
*/
public class NotCompilableIRMethodMatchResult implements MatchResult {
private final Method method;
private final int failedIRRules;

public NotCompilableIRMethodMatchResult(Method method, int failedIRRules) {
this.method = method;
this.failedIRRules = failedIRRules;
}

@Override
public boolean fail() {
return false;
}

@Override
public void accept(MatchResultVisitor visitor) {
visitor.visitMethodNotCompilable(method, failedIRRules);
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. 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
Expand All @@ -23,10 +23,13 @@

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

import compiler.lib.ir_framework.Test;
import compiler.lib.ir_framework.TestFramework;
import compiler.lib.ir_framework.driver.irmatching.Compilation;
import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethod;
import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethodMatchable;
import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompiledIRMethod;
import compiler.lib.ir_framework.driver.irmatching.irmethod.NotCompilableIRMethod;
import compiler.lib.ir_framework.driver.irmatching.parser.hotspot.HotSpotPidFileParser;
import compiler.lib.ir_framework.driver.irmatching.parser.hotspot.LoggedMethod;
import compiler.lib.ir_framework.driver.irmatching.parser.hotspot.LoggedMethods;
Expand All @@ -41,10 +44,12 @@
class IRMethodBuilder {
private final Map<String, LoggedMethod> loggedMethods;
private final TestMethods testMethods;
private final boolean allowNotCompilable;

public IRMethodBuilder(TestMethods testMethods, LoggedMethods loggedMethods) {
public IRMethodBuilder(TestMethods testMethods, LoggedMethods loggedMethods, boolean allowNotCompilable) {
this.testMethods = testMethods;
this.loggedMethods = loggedMethods.loggedMethods();
this.allowNotCompilable = allowNotCompilable;
}

/**
Expand All @@ -64,7 +69,13 @@ private IRMethodMatchable createIRMethod(String methodName, TestMethod testMetho
return new IRMethod(testMethod.method(), testMethod.irRuleIds(), testMethod.irAnnos(),
new Compilation(loggedMethod.compilationOutput()), vmInfo);
} else {
return new NotCompiledIRMethod(testMethod.method(), testMethod.irRuleIds().length);
Test[] testAnnos = testMethod.method().getAnnotationsByType(Test.class);
boolean allowMethodNotCompilable = allowNotCompilable || testAnnos[0].allowNotCompilable();
if (allowMethodNotCompilable) {
return new NotCompilableIRMethod(testMethod.method(), testMethod.irRuleIds().length);
} else {
return new NotCompiledIRMethod(testMethod.method(), testMethod.irRuleIds().length);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -42,9 +42,11 @@
*/
public class TestClassParser {
private final Class<?> testClass;
private final boolean allowNotCompilable;

public TestClassParser(Class<?> testClass) {
public TestClassParser(Class<?> testClass, boolean allowNotCompilable) {
this.testClass = testClass;
this.allowNotCompilable = allowNotCompilable;
}

/**
Expand All @@ -68,7 +70,7 @@ public Matchable parse(String hotspotPidFileName, String irEncoding) {
* with the parsed compilation output from {@link HotSpotPidFileParser}.
*/
private Matchable createTestClass(TestMethods testMethods, LoggedMethods loggedMethods, VMInfo vmInfo) {
IRMethodBuilder irMethodBuilder = new IRMethodBuilder(testMethods, loggedMethods);
IRMethodBuilder irMethodBuilder = new IRMethodBuilder(testMethods, loggedMethods, allowNotCompilable);
SortedSet<IRMethodMatchable> irMethods = irMethodBuilder.build(vmInfo);
TestFormat.throwIfAnyFailures();
return new TestClass(irMethods);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. 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
Expand All @@ -25,6 +25,7 @@

import compiler.lib.ir_framework.CompilePhase;
import compiler.lib.ir_framework.IR;
import compiler.lib.ir_framework.shared.TestFrameworkException;
import compiler.lib.ir_framework.driver.irmatching.MatchResult;
import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType;
import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure;
Expand Down Expand Up @@ -121,6 +122,11 @@ public void visitMethodNotCompiled(Method method, int failedIRRules) {
output.append("<empty>").append(System.lineSeparator());
}

@Override
public void visitMethodNotCompilable(Method method, int failedIRRules) {
throw new TestFrameworkException("Sould not reach here");
}

@Override
public void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno) {
acceptChildren.accept(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -63,6 +63,11 @@ public void visitMethodNotCompiled(Method method, int failedIRRules) {
irRuleCount += failedIRRules;
}

@Override
public void visitMethodNotCompilable(Method method, int failedIRRules) {
irMethodCount++;
}

public int getIrRuleCount() {
return irRuleCount;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. 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
Expand All @@ -25,6 +25,7 @@

import compiler.lib.ir_framework.CompilePhase;
import compiler.lib.ir_framework.IR;
import compiler.lib.ir_framework.shared.TestFrameworkException;
import compiler.lib.ir_framework.driver.irmatching.MatchResult;
import compiler.lib.ir_framework.driver.irmatching.irrule.checkattribute.CheckAttributeType;
import compiler.lib.ir_framework.driver.irmatching.irrule.constraint.CountsConstraintFailure;
Expand Down Expand Up @@ -97,6 +98,10 @@ public void visitMethodNotCompiled(Method method, int failedIRRules) {
indentation.sub();
}

public void visitMethodNotCompilable(Method method, int failedIRRules) {
throw new TestFrameworkException("Sould not reach here");
}

@Override
public void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno) {
indentation.add();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -39,6 +39,7 @@ public interface MatchResultVisitor {
void visitTestClass(AcceptChildren acceptChildren);
void visitIRMethod(AcceptChildren acceptChildren, Method method, int failedIRRules);
void visitMethodNotCompiled(Method method, int failedIRRules);
void visitMethodNotCompilable(Method method, int failedIRRules);
void visitIRRule(AcceptChildren acceptChildren, int irRuleId, IR irAnno);
void visitCompilePhaseIRRule(AcceptChildren acceptChildren, CompilePhase compilePhase, String compilationOutput);
void visitNoCompilePhaseCompilation(CompilePhase compilePhase);
Expand Down
Loading