23
23
24
24
package compiler .lib .ir_framework ;
25
25
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 ;
27
29
import compiler .lib .ir_framework .driver .irmatching .IRMatcher ;
28
30
import compiler .lib .ir_framework .driver .irmatching .IRViolationException ;
29
31
import compiler .lib .ir_framework .shared .*;
30
- import compiler .lib .ir_framework .test .* ;
32
+ import compiler .lib .ir_framework .test .TestVM ;
31
33
import jdk .test .lib .Platform ;
32
34
import jdk .test .lib .Utils ;
33
35
import jdk .test .lib .helpers .ClassFileInstaller ;
36
38
import java .io .PrintWriter ;
37
39
import java .io .StringWriter ;
38
40
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 ;
39
45
import java .util .*;
40
46
import java .util .stream .Collectors ;
41
47
@@ -137,7 +143,6 @@ public class TestFramework {
137
143
public static final boolean EXCLUDELIST = !System .getProperty ("Exclude" , "" ).isEmpty ();
138
144
private static final boolean REPORT_STDOUT = Boolean .getBoolean ("ReportStdout" );
139
145
// 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" );
141
146
142
147
private static final String RERUN_HINT = """
143
148
#############################################################
@@ -314,7 +319,7 @@ public TestFramework addScenarios(Scenario... scenarios) {
314
319
* set test class.
315
320
*/
316
321
public void start () {
317
- if (! SKIP_WHITEBOX_INSTALL ) {
322
+ if (shouldInstallWhiteBox () ) {
318
323
installWhiteBox ();
319
324
}
320
325
disableIRVerificationIfNotFeasible ();
@@ -336,6 +341,28 @@ public void start() {
336
341
}
337
342
}
338
343
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
+
339
366
/**
340
367
* Set a new default warm-up (overriding the framework default of 2000 at
341
368
* {@link TestVM#WARMUP_ITERATIONS}) to be applied for all tests that do not specify an explicit
0 commit comments