test/hotspot/jtreg/runtime/appcds/SpecifySysLoaderProp.java
changeset 48979 514c73a1955b
parent 48469 7312ae4465d6
child 49931 840e26123940
equal deleted inserted replaced
48978:93996c47d36f 48979:514c73a1955b
    49     String warning = "VM warning: UseAppCDS is disabled because the java.system.class.loader property is specified";
    49     String warning = "VM warning: UseAppCDS is disabled because the java.system.class.loader property is specified";
    50 
    50 
    51 
    51 
    52     // (0) Baseline. Do not specify -Djava.system.class.loader
    52     // (0) Baseline. Do not specify -Djava.system.class.loader
    53     //     The test class should be loaded from archive
    53     //     The test class should be loaded from archive
    54     OutputAnalyzer output = TestCommon.execCommon(
    54     TestCommon.run(
    55         "-verbose:class",
    55         "-verbose:class",
    56         "-cp", appJar,
    56         "-cp", appJar,
    57         "ReportMyLoader");
    57         "ReportMyLoader")
    58     TestCommon.checkExec(output,
    58       .assertNormalExit("[class,load] ReportMyLoader source: shared objects file",
    59                          "[class,load] ReportMyLoader source: shared objects file",
    59                         "ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@");
    60                          "ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@");
       
    61 
    60 
    62     // (1) Try to execute the archive with -Djava.system.class.loader=no.such.Klass,
    61     // (1) Try to execute the archive with -Djava.system.class.loader=no.such.Klass,
    63     //     it should fail
    62     //     it should fail
    64     output = TestCommon.execCommon(
    63     TestCommon.run(
    65         "-cp", appJar,
    64         "-cp", appJar,
    66         "-Djava.system.class.loader=no.such.Klass",
    65         "-Djava.system.class.loader=no.such.Klass",
    67         "ReportMyLoader");
    66         "ReportMyLoader")
    68     try {
    67       .assertAbnormalExit(output -> {
    69         output.shouldContain(warning);
    68           output.shouldContain(warning);
    70         output.shouldContain("ClassNotFoundException: no.such.Klass");
    69           output.shouldContain("ClassNotFoundException: no.such.Klass");
    71     } catch (Exception e) {
    70         });
    72         TestCommon.checkCommonExecExceptions(output, e);
       
    73     }
       
    74 
    71 
    75     // (2) Try to execute the archive with -Djava.system.class.loader=TestClassLoader,
    72     // (2) Try to execute the archive with -Djava.system.class.loader=TestClassLoader,
    76     //     it should run, but AppCDS should be disabled
    73     //     it should run, but AppCDS should be disabled
    77     output = TestCommon.execCommon(
    74     TestCommon.run(
    78         "-verbose:class",
    75         "-verbose:class",
    79         "-cp", appJar,
    76         "-cp", appJar,
    80         "-Djava.system.class.loader=TestClassLoader",
    77         "-Djava.system.class.loader=TestClassLoader",
    81         "ReportMyLoader");
    78         "ReportMyLoader")
    82     TestCommon.checkExec(output,
    79       .assertNormalExit("ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@", //<-this is still printed because TestClassLoader simply delegates to Launcher$AppLoader, but ...
    83                          "ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@", //<-this is still printed because TestClassLoader simply delegates to Launcher$AppLoader, but ...
    80              "TestClassLoader.called = true", //<-but this proves that TestClassLoader was indeed called.
    84                          "TestClassLoader.called = true", //<-but this proves that TestClassLoader was indeed called.
    81              "TestClassLoader: loadClass(\"ReportMyLoader\",") //<- this also proves that TestClassLoader was indeed called.
    85                          "TestClassLoader: loadClass(\"ReportMyLoader\","); //<- this also proves that TestClassLoader was indeed called.
    82       .assertNormalExit(output -> {
    86     try {
       
    87         output.shouldMatch(".class,load. TestClassLoader source: file:");
    83         output.shouldMatch(".class,load. TestClassLoader source: file:");
    88         output.shouldMatch(".class,load. ReportMyLoader source: file:.*" + jarFileName);
    84         output.shouldMatch(".class,load. ReportMyLoader source: file:.*" + jarFileName);
    89     } catch (Exception e) {
    85         });
    90         TestCommon.checkCommonExecExceptions(output, e);
       
    91     }
       
    92 
    86 
    93     // (3) Try to change the java.system.class.loader programmatically after
    87     // (3) Try to change the java.system.class.loader programmatically after
    94     //     the app's main method is executed. This should have no effect in terms of
    88     //     the app's main method is executed. This should have no effect in terms of
    95     //     changing or switching the actual system class loader that's already in use.
    89     //     changing or switching the actual system class loader that's already in use.
    96     output = TestCommon.execCommon(
    90     TestCommon.run(
    97         "-verbose:class",
    91         "-verbose:class",
    98         "-cp", appJar,
    92         "-cp", appJar,
    99         "TrySwitchMyLoader");
    93         "TrySwitchMyLoader")
   100     TestCommon.checkExec(output,
    94       .assertNormalExit("[class,load] ReportMyLoader source: shared objects file",
   101                          "[class,load] ReportMyLoader source: shared objects file",
    95              "TrySwitchMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@",
   102                          "TrySwitchMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@",
    96              "ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@",
   103                          "ReportMyLoader's loader = jdk.internal.loader.ClassLoaders$AppClassLoader@",
    97              "TestClassLoader.called = false");
   104                          "TestClassLoader.called = false");
       
   105   }
    98   }
   106 }
    99 }