< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/customLoader/LoaderSegregationTest.java

Print this page




  46 import sun.hotspot.WhiteBox;
  47 
  48 /**
  49  * See "Handling of the classes in the AppCDS archive" at the top of
  50  * systemDicrionatyShared.hpp.
  51  *
  52  * This test ensure that the 2 types of archived classes (BUILTIN and UNREGISTERED)
  53  * are segregated at both dump-time and run time:
  54  *
  55  * [A] An archived BUILTIN class cannot be a subclass of a non-BUILTIN class.
  56  * [B] An archived BUILTIN class cannot implement a non-BUILTIN interface.
  57  * [C] BUILTIN and UNREGISTERED classes can be loaded only by their corresponding
  58  *     type of loaders.
  59  *
  60  */
  61 public class LoaderSegregationTest {
  62     public static void main(String[] args) throws Exception {
  63         String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
  64         String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
  65 
  66         String appJar = JarBuilder.build("LoaderSegregation_app", "LoaderSegregation",
  67                                          "CustomLoadee", "CustomLoadee2", "CustomLoadee3Child", "CustomInterface2_ia",
  68                                          "OnlyBuiltin", "Util");
  69 
  70         String app2Jar = JarBuilder.build("LoaderSegregation_app2", "CustomLoadee3", "CustomInterface2_ib");
  71 
  72         String customJarPath = JarBuilder.build("LoaderSegregation_custom", "CustomLoadee",
  73                                                 "CustomLoadee2", "CustomInterface2_ia", "CustomInterface2_ib",
  74                                                 "CustomLoadee3", "CustomLoadee3Child",
  75                                                 "OnlyBuiltin", "OnlyUnregistered");
  76 
  77         // Dump the archive
  78         String classlist[] = new String[] {
  79             "LoaderSegregation",
  80             "java/lang/Object id: 1",
  81 
  82             // These are the UNREGISTERED classes: they have "source:"
  83             // but they don't have "loader:".
  84             "CustomLoadee id: 2 super: 1 source: " + customJarPath,
  85 
  86             "CustomInterface2_ia id: 3 super: 1 source: " + customJarPath,


  93             // At dump time, the following BUILTIN classes are loaded after the UNREGISTERED
  94             // classes from above. However, at dump time, they cannot use the UNREGISTERED classes are their
  95             // super or interface.
  96             "CustomLoadee",          // can be loaded at dump time
  97             "CustomLoadee2",         // cannot be loaded at dump time (interface missing)
  98             "CustomLoadee3Child",    // cannot be loaded at dump time (super missing)
  99 
 100             // Check that BUILTIN and UNREGISTERED classes can be loaded only by their
 101             // corresponding type of loaders.
 102             "OnlyBuiltin",
 103             "OnlyUnregistered id: 9 super: 1 source: " + customJarPath,
 104         };
 105 
 106         OutputAnalyzer output;
 107         TestCommon.testDump(appJar, classlist,
 108                             // command-line arguments ...
 109                             use_whitebox_jar);
 110 
 111         output = TestCommon.exec(TestCommon.concatPaths(appJar, app2Jar),
 112                                  // command-line arguments ...
 113                                  "--add-opens=java.base/java.lang=ALL-UNNAMED",
 114                                  "--add-opens=java.base/java.security=ALL-UNNAMED",
 115                                  use_whitebox_jar,
 116                                  "-XX:+UnlockDiagnosticVMOptions",
 117                                  "-XX:+WhiteBoxAPI",
 118                                  "LoaderSegregation", customJarPath);
 119         TestCommon.checkExec(output);
 120     }
 121 }


  46 import sun.hotspot.WhiteBox;
  47 
  48 /**
  49  * See "Handling of the classes in the AppCDS archive" at the top of
  50  * systemDicrionatyShared.hpp.
  51  *
  52  * This test ensure that the 2 types of archived classes (BUILTIN and UNREGISTERED)
  53  * are segregated at both dump-time and run time:
  54  *
  55  * [A] An archived BUILTIN class cannot be a subclass of a non-BUILTIN class.
  56  * [B] An archived BUILTIN class cannot implement a non-BUILTIN interface.
  57  * [C] BUILTIN and UNREGISTERED classes can be loaded only by their corresponding
  58  *     type of loaders.
  59  *
  60  */
  61 public class LoaderSegregationTest {
  62     public static void main(String[] args) throws Exception {
  63         String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
  64         String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
  65 
  66         String appJar = JarBuilder.build("LoaderSegregation_app", "LoaderSegregation", "LoaderSegregation$1",
  67                                          "CustomLoadee", "CustomLoadee2", "CustomLoadee3Child", "CustomInterface2_ia",
  68                                          "OnlyBuiltin", "Util");
  69 
  70         String app2Jar = JarBuilder.build("LoaderSegregation_app2", "CustomLoadee3", "CustomInterface2_ib");
  71 
  72         String customJarPath = JarBuilder.build("LoaderSegregation_custom", "CustomLoadee",
  73                                                 "CustomLoadee2", "CustomInterface2_ia", "CustomInterface2_ib",
  74                                                 "CustomLoadee3", "CustomLoadee3Child",
  75                                                 "OnlyBuiltin", "OnlyUnregistered");
  76 
  77         // Dump the archive
  78         String classlist[] = new String[] {
  79             "LoaderSegregation",
  80             "java/lang/Object id: 1",
  81 
  82             // These are the UNREGISTERED classes: they have "source:"
  83             // but they don't have "loader:".
  84             "CustomLoadee id: 2 super: 1 source: " + customJarPath,
  85 
  86             "CustomInterface2_ia id: 3 super: 1 source: " + customJarPath,


  93             // At dump time, the following BUILTIN classes are loaded after the UNREGISTERED
  94             // classes from above. However, at dump time, they cannot use the UNREGISTERED classes are their
  95             // super or interface.
  96             "CustomLoadee",          // can be loaded at dump time
  97             "CustomLoadee2",         // cannot be loaded at dump time (interface missing)
  98             "CustomLoadee3Child",    // cannot be loaded at dump time (super missing)
  99 
 100             // Check that BUILTIN and UNREGISTERED classes can be loaded only by their
 101             // corresponding type of loaders.
 102             "OnlyBuiltin",
 103             "OnlyUnregistered id: 9 super: 1 source: " + customJarPath,
 104         };
 105 
 106         OutputAnalyzer output;
 107         TestCommon.testDump(appJar, classlist,
 108                             // command-line arguments ...
 109                             use_whitebox_jar);
 110 
 111         output = TestCommon.exec(TestCommon.concatPaths(appJar, app2Jar),
 112                                  // command-line arguments ...


 113                                  use_whitebox_jar,
 114                                  "-XX:+UnlockDiagnosticVMOptions",
 115                                  "-XX:+WhiteBoxAPI",
 116                                  "LoaderSegregation", customJarPath);
 117         TestCommon.checkExec(output);
 118     }
 119 }
< prev index next >