Skip to content

Commit b647a12

Browse files
committed
8286940: [IR Framework] Allow IR tests to build and use Whitebox without -DSkipWhiteBoxInstall=true
Reviewed-by: kvn, thartmann
1 parent dbf0905 commit b647a12

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

test/hotspot/jtreg/compiler/c2/irTests/TestSuperwordFailsUnrolling.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @build sun.hotspot.WhiteBox
3535
* @requires vm.compiler2.enabled
3636
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
37-
* @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling
37+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling
3838
*/
3939

4040
public class TestSuperwordFailsUnrolling {

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323

2424
package compiler.lib.ir_framework;
2525

26-
import compiler.lib.ir_framework.driver.*;
26+
import compiler.lib.ir_framework.driver.FlagVMProcess;
27+
import compiler.lib.ir_framework.driver.TestVMException;
28+
import compiler.lib.ir_framework.driver.TestVMProcess;
2729
import compiler.lib.ir_framework.driver.irmatching.IRMatcher;
2830
import compiler.lib.ir_framework.driver.irmatching.IRViolationException;
2931
import compiler.lib.ir_framework.shared.*;
30-
import compiler.lib.ir_framework.test.*;
32+
import compiler.lib.ir_framework.test.TestVM;
3133
import jdk.test.lib.Platform;
3234
import jdk.test.lib.Utils;
3335
import jdk.test.lib.helpers.ClassFileInstaller;
@@ -36,6 +38,10 @@
3638
import java.io.PrintWriter;
3739
import java.io.StringWriter;
3840
import java.lang.reflect.Method;
41+
import java.net.MalformedURLException;
42+
import java.net.URL;
43+
import java.net.URLClassLoader;
44+
import java.nio.file.Path;
3945
import java.util.*;
4046
import java.util.stream.Collectors;
4147

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

142147
private static final String RERUN_HINT = """
143148
#############################################################
@@ -314,7 +319,7 @@ public TestFramework addScenarios(Scenario... scenarios) {
314319
* set test class.
315320
*/
316321
public void start() {
317-
if (!SKIP_WHITEBOX_INSTALL) {
322+
if (shouldInstallWhiteBox()) {
318323
installWhiteBox();
319324
}
320325
disableIRVerificationIfNotFeasible();
@@ -336,6 +341,28 @@ public void start() {
336341
}
337342
}
338343

344+
/**
345+
* Try to load the Whitebox class from the user directory with a custom class loader. If the user has already built the
346+
* Whitebox, we can load it. Otherwise, the framework needs to install it.
347+
*
348+
* @return true if the framework needs to install the Whitebox
349+
*/
350+
private boolean shouldInstallWhiteBox() {
351+
try {
352+
URL url = Path.of(System.getProperty("user.dir")).toUri().toURL();
353+
URLClassLoader userDirClassLoader =
354+
URLClassLoader.newInstance(new URL[] {url}, TestFramework.class.getClassLoader().getParent());
355+
Class.forName(WhiteBox.class.getName(), false, userDirClassLoader);
356+
} catch (MalformedURLException e) {
357+
throw new TestFrameworkException("corrupted user.dir property", e);
358+
} catch (ClassNotFoundException e) {
359+
// We need to manually install the WhiteBox if we cannot load the WhiteBox class from the user directory.
360+
// This happens when the user test does not explicitly install the WhiteBox as part of the test.
361+
return true;
362+
}
363+
return false;
364+
}
365+
339366
/**
340367
* Set a new default warm-up (overriding the framework default of 2000 at
341368
* {@link TestVM#WARMUP_ITERATIONS}) to be applied for all tests that do not specify an explicit

test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestCompLevels.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @library /test/lib /
3838
* @build sun.hotspot.WhiteBox
3939
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
40-
* @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
40+
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
4141
* -Xbatch -XX:+WhiteBoxAPI ir_framework.tests.TestCompLevels
4242
*/
4343

test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestControls.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @library /test/lib /
4242
* @build sun.hotspot.WhiteBox
4343
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
44-
* @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
44+
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
4545
* -Xbatch -XX:+WhiteBoxAPI ir_framework.tests.TestControls
4646
*/
4747

test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestIRMatching.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* @library /test/lib /testlibrary_tests /
4444
* @build sun.hotspot.WhiteBox
4545
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
46-
* @run main/othervm/timeout=240 -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
46+
* @run main/othervm/timeout=240 -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
4747
* -XX:+WhiteBoxAPI -DPrintIREncoding=true ir_framework.tests.TestIRMatching
4848
*/
4949

0 commit comments

Comments
 (0)