Skip to content

Commit

Permalink
8286940: [IR Framework] Allow IR tests to build and use Whitebox with…
Browse files Browse the repository at this point in the history
…out -DSkipWhiteBoxInstall=true

Reviewed-by: kvn, thartmann
  • Loading branch information
chhagedorn committed Jun 7, 2022
1 parent dbf0905 commit b647a12
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
Expand Up @@ -34,7 +34,7 @@
* @build sun.hotspot.WhiteBox
* @requires vm.compiler2.enabled
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling
*/

public class TestSuperwordFailsUnrolling {
Expand Down
35 changes: 31 additions & 4 deletions test/hotspot/jtreg/compiler/lib/ir_framework/TestFramework.java
Expand Up @@ -23,11 +23,13 @@

package compiler.lib.ir_framework;

import compiler.lib.ir_framework.driver.*;
import compiler.lib.ir_framework.driver.FlagVMProcess;
import compiler.lib.ir_framework.driver.TestVMException;
import compiler.lib.ir_framework.driver.TestVMProcess;
import compiler.lib.ir_framework.driver.irmatching.IRMatcher;
import compiler.lib.ir_framework.driver.irmatching.IRViolationException;
import compiler.lib.ir_framework.shared.*;
import compiler.lib.ir_framework.test.*;
import compiler.lib.ir_framework.test.TestVM;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.helpers.ClassFileInstaller;
Expand All @@ -36,6 +38,10 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -137,7 +143,6 @@ public class TestFramework {
public static final boolean EXCLUDELIST = !System.getProperty("Exclude", "").isEmpty();
private static final boolean REPORT_STDOUT = Boolean.getBoolean("ReportStdout");
// Only used for internal testing and should not be used for normal user testing.
private static final boolean SKIP_WHITEBOX_INSTALL = Boolean.getBoolean("SkipWhiteBoxInstall");

private static final String RERUN_HINT = """
#############################################################
Expand Down Expand Up @@ -314,7 +319,7 @@ public TestFramework addScenarios(Scenario... scenarios) {
* set test class.
*/
public void start() {
if (!SKIP_WHITEBOX_INSTALL) {
if (shouldInstallWhiteBox()) {
installWhiteBox();
}
disableIRVerificationIfNotFeasible();
Expand All @@ -336,6 +341,28 @@ public void start() {
}
}

/**
* Try to load the Whitebox class from the user directory with a custom class loader. If the user has already built the
* Whitebox, we can load it. Otherwise, the framework needs to install it.
*
* @return true if the framework needs to install the Whitebox
*/
private boolean shouldInstallWhiteBox() {
try {
URL url = Path.of(System.getProperty("user.dir")).toUri().toURL();
URLClassLoader userDirClassLoader =
URLClassLoader.newInstance(new URL[] {url}, TestFramework.class.getClassLoader().getParent());
Class.forName(WhiteBox.class.getName(), false, userDirClassLoader);
} catch (MalformedURLException e) {
throw new TestFrameworkException("corrupted user.dir property", e);
} catch (ClassNotFoundException e) {
// We need to manually install the WhiteBox if we cannot load the WhiteBox class from the user directory.
// This happens when the user test does not explicitly install the WhiteBox as part of the test.
return true;
}
return false;
}

/**
* Set a new default warm-up (overriding the framework default of 2000 at
* {@link TestVM#WARMUP_ITERATIONS}) to be applied for all tests that do not specify an explicit
Expand Down
Expand Up @@ -37,7 +37,7 @@
* @library /test/lib /
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* -Xbatch -XX:+WhiteBoxAPI ir_framework.tests.TestCompLevels
*/

Expand Down
Expand Up @@ -41,7 +41,7 @@
* @library /test/lib /
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* -Xbatch -XX:+WhiteBoxAPI ir_framework.tests.TestControls
*/

Expand Down
Expand Up @@ -43,7 +43,7 @@
* @library /test/lib /testlibrary_tests /
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=240 -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* @run main/othervm/timeout=240 -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -DPrintIREncoding=true ir_framework.tests.TestIRMatching
*/

Expand Down

0 comments on commit b647a12

Please sign in to comment.