test/runtime/SharedArchiveFile/BootAppendTests.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff test/runtime/SharedArchiveFile

test/runtime/SharedArchiveFile/BootAppendTests.java

Print this page




  56     private static final String BOOT_APPEND_MODULE_CLASS_NAME =
  57         BOOT_APPEND_MODULE_CLASS.replace('/', '.');
  58     private static final String BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME =
  59         BOOT_APPEND_DUPLICATE_MODULE_CLASS.replace('/', '.');
  60     private static final String BOOT_APPEND_CLASS_NAME =
  61         BOOT_APPEND_CLASS.replace('/', '.');
  62     private static final String[] ARCHIVE_CLASSES =
  63         {BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS, BOOT_APPEND_CLASS};
  64 
  65     private static final String modes[] = {"on", "off"};
  66 
  67     private static String appJar;
  68     private static String bootAppendJar;
  69 
  70     public static void main(String... args) throws Exception {
  71         dumpArchive();
  72 
  73         logTestCase("1");
  74         testBootAppendModuleClass();
  75 
  76         log("TESTCASE: 2");
  77         testBootAppendDuplicateModuleClass();
  78 
  79         logTestCase("3");
  80         testBootAppendExcludedModuleClass();
  81 
  82         logTestCase("4");
  83         testBootAppendDuplicateExcludedModuleClass();
  84 
  85         logTestCase("5");
  86         testBootAppendClass();
  87     }
  88 
  89     private static void logTestCase(String msg) {
  90         System.out.println();
  91         System.out.printf("TESTCASE: %s", msg);
  92         System.out.println();
  93     }
  94 
  95     static void dumpArchive() throws Exception {
  96         // create the classlist


 127                 .addSuffix(APP_CLASS, BOOT_APPEND_MODULE_CLASS_NAME);
 128 
 129             CDSTestUtils.runWithArchive(opts)
 130                 .shouldContain("java.lang.ClassNotFoundException: javax.sound.sampled.MyClass");
 131         }
 132     }
 133 
 134     // Test #2: If a class on -Xbootclasspath/a has the same fully qualified
 135     //          name as a class defined in boot modules, the class is not loaded
 136     //          from -Xbootclasspath/a. Verify the behavior is the same at runtime
 137     //          when CDS is enabled.
 138     //
 139     //          The org.omg.CORBA.Context is a boot module class. The class on
 140     //          the -Xbootclasspath/a path that has the same fully-qualified name
 141     //          should not be loaded at runtime when CDS is enabled.
 142     //          The one from the boot modules should be loaded instead.
 143     public static void testBootAppendDuplicateModuleClass() throws Exception {
 144         for (String mode : modes) {
 145             CDSOptions opts = (new CDSOptions())
 146                 .setXShareMode(mode).setUseVersion(false)
 147                 .addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar)
 148                 .addSuffix(APP_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);


 149 
 150             CDSTestUtils.runWithArchive(opts)
 151                 .shouldContain("[class,load] org.omg.CORBA.Context source: jrt:/java.corba");
 152         }
 153     }
 154 
 155     // Test #3: If a class on -Xbootclasspath/a is from a package defined in boot modules,
 156     //          the class can be loaded from -Xbootclasspath/a when the module is excluded
 157     //          using --limit-modules. Verify the behavior is the same at runtime when CDS
 158     //          is enabled.
 159     //
 160     //          The java.desktop module is excluded using --limit-modules at runtime,
 161     //          javax.sound.sampled.MyClass is archived from -Xbootclasspath/a. It can be
 162     //          loaded from the archive at runtime.
 163     public static void testBootAppendExcludedModuleClass() throws Exception {
 164         for (String mode : modes) {
 165             CDSOptions opts = (new CDSOptions())
 166                 .setXShareMode(mode).setUseVersion(false)
 167                 .addPrefix("-Xbootclasspath/a:" + bootAppendJar,
 168                            "--limit-modules=java.base", "-cp", appJar)




  56     private static final String BOOT_APPEND_MODULE_CLASS_NAME =
  57         BOOT_APPEND_MODULE_CLASS.replace('/', '.');
  58     private static final String BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME =
  59         BOOT_APPEND_DUPLICATE_MODULE_CLASS.replace('/', '.');
  60     private static final String BOOT_APPEND_CLASS_NAME =
  61         BOOT_APPEND_CLASS.replace('/', '.');
  62     private static final String[] ARCHIVE_CLASSES =
  63         {BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS, BOOT_APPEND_CLASS};
  64 
  65     private static final String modes[] = {"on", "off"};
  66 
  67     private static String appJar;
  68     private static String bootAppendJar;
  69 
  70     public static void main(String... args) throws Exception {
  71         dumpArchive();
  72 
  73         logTestCase("1");
  74         testBootAppendModuleClass();
  75 
  76         logTestCase("2");
  77         testBootAppendDuplicateModuleClass();
  78 
  79         logTestCase("3");
  80         testBootAppendExcludedModuleClass();
  81 
  82         logTestCase("4");
  83         testBootAppendDuplicateExcludedModuleClass();
  84 
  85         logTestCase("5");
  86         testBootAppendClass();
  87     }
  88 
  89     private static void logTestCase(String msg) {
  90         System.out.println();
  91         System.out.printf("TESTCASE: %s", msg);
  92         System.out.println();
  93     }
  94 
  95     static void dumpArchive() throws Exception {
  96         // create the classlist


 127                 .addSuffix(APP_CLASS, BOOT_APPEND_MODULE_CLASS_NAME);
 128 
 129             CDSTestUtils.runWithArchive(opts)
 130                 .shouldContain("java.lang.ClassNotFoundException: javax.sound.sampled.MyClass");
 131         }
 132     }
 133 
 134     // Test #2: If a class on -Xbootclasspath/a has the same fully qualified
 135     //          name as a class defined in boot modules, the class is not loaded
 136     //          from -Xbootclasspath/a. Verify the behavior is the same at runtime
 137     //          when CDS is enabled.
 138     //
 139     //          The org.omg.CORBA.Context is a boot module class. The class on
 140     //          the -Xbootclasspath/a path that has the same fully-qualified name
 141     //          should not be loaded at runtime when CDS is enabled.
 142     //          The one from the boot modules should be loaded instead.
 143     public static void testBootAppendDuplicateModuleClass() throws Exception {
 144         for (String mode : modes) {
 145             CDSOptions opts = (new CDSOptions())
 146                 .setXShareMode(mode).setUseVersion(false)
 147                 .addPrefix("--add-modules", "java.corba",
 148                            "-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar)
 149                 .addSuffix("-Xlog:class+load=info",
 150                            APP_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
 151 
 152             CDSTestUtils.runWithArchive(opts)
 153                 .shouldContain("[class,load] org.omg.CORBA.Context source: jrt:/java.corba");
 154         }
 155     }
 156 
 157     // Test #3: If a class on -Xbootclasspath/a is from a package defined in boot modules,
 158     //          the class can be loaded from -Xbootclasspath/a when the module is excluded
 159     //          using --limit-modules. Verify the behavior is the same at runtime when CDS
 160     //          is enabled.
 161     //
 162     //          The java.desktop module is excluded using --limit-modules at runtime,
 163     //          javax.sound.sampled.MyClass is archived from -Xbootclasspath/a. It can be
 164     //          loaded from the archive at runtime.
 165     public static void testBootAppendExcludedModuleClass() throws Exception {
 166         for (String mode : modes) {
 167             CDSOptions opts = (new CDSOptions())
 168                 .setXShareMode(mode).setUseVersion(false)
 169                 .addPrefix("-Xbootclasspath/a:" + bootAppendJar,
 170                            "--limit-modules=java.base", "-cp", appJar)


test/runtime/SharedArchiveFile/BootAppendTests.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File