test/hotspot/jtreg/runtime/appcds/cacheObject/CheckArchivedModuleApp.java
changeset 51371 3ab8b84e93cd
parent 50951 b96466cdfc45
child 51688 fd3b632801aa
equal deleted inserted replaced
51370:fbb62267e5e9 51371:3ab8b84e93cd
    21  * questions.
    21  * questions.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 import java.io.File;
    25 import java.io.File;
       
    26 import java.lang.module.Configuration;
    26 import java.lang.module.ModuleDescriptor;
    27 import java.lang.module.ModuleDescriptor;
       
    28 import java.util.List;
    27 import java.util.Set;
    29 import java.util.Set;
    28 import sun.hotspot.WhiteBox;
    30 import sun.hotspot.WhiteBox;
    29 
    31 
    30 //
    32 //
    31 // Test archived system module graph when open archive heap objects are mapped:
    33 // Test archived system module graph when open archive heap objects are mapped:
    39             System.out.println("Archived open_archive_heap objects are not mapped.");
    41             System.out.println("Archived open_archive_heap objects are not mapped.");
    40             System.out.println("This may happen during normal operation. Test Skipped.");
    42             System.out.println("This may happen during normal operation. Test Skipped.");
    41             return;
    43             return;
    42         }
    44         }
    43 
    45 
    44         boolean expectArchived = "yes".equals(args[0]);
    46         if (args.length != 2) {
    45         checkModuleDescriptors(expectArchived);
    47            throw new RuntimeException(
       
    48                "FAILED. Incorrect argument length: " + args.length);
       
    49         }
       
    50         boolean expectArchivedDescriptors = "yes".equals(args[0]);
       
    51         boolean expectArchivedConfiguration = "yes".equals(args[1]);
       
    52         checkModuleDescriptors(expectArchivedDescriptors);
       
    53         checkConfiguration(expectArchivedConfiguration);
       
    54         checkEmptyConfiguration(expectArchivedConfiguration);
    46     }
    55     }
    47 
    56 
    48     private static void checkModuleDescriptors(boolean expectArchived) {
    57     private static void checkModuleDescriptors(boolean expectArchivedDescriptors) {
    49         Set<Module> modules = ModuleLayer.boot().modules();
    58         Set<Module> modules = ModuleLayer.boot().modules();
    50         for (Module m : modules) {
    59         for (Module m : modules) {
    51             ModuleDescriptor md = m.getDescriptor();
    60             ModuleDescriptor md = m.getDescriptor();
    52             String name = md.name();
    61             String name = md.name();
    53             if (expectArchived) {
    62             if (expectArchivedDescriptors) {
    54                 if (wb.isShared(md)) {
    63                 if (wb.isShared(md)) {
    55                     System.out.println(name + " is archived. Expected.");
    64                     System.out.println(name + " is archived. Expected.");
    56                 } else {
    65                 } else {
    57                     throw new RuntimeException(
    66                     throw new RuntimeException(
    58                         "FAILED. " + name + " is not archived. Expect archived.");
    67                         "FAILED. " + name + " is not archived. Expect archived.");
    65                         "FAILED. " + name + " is archived. Expect not archived.");
    74                         "FAILED. " + name + " is archived. Expect not archived.");
    66                 }
    75                 }
    67             }
    76             }
    68         }
    77         }
    69     }
    78     }
       
    79 
       
    80     private static void checkEmptyConfiguration(boolean expectArchivedConfiguration) {
       
    81         // Configuration.EMPTY_CONFIGURATION uses the singletons,
       
    82         // ListN.EMPTY_LIST, SetN.EMPTY_SET and MapN.EMPTY_MAP in
       
    83         // ImmutableCollections for the 'parents', 'modules' and
       
    84         // 'graph' fields. The ImmutableCollections singletons
       
    85         // can be accessed via List.of(), Set.of() and Map.of() APIs.
       
    86         // Configuration public APIs also allow access to the
       
    87         // EMPTY_CONFIGURATION's 'parents' and 'modules'. When the
       
    88         // archived java heap data is enabled at runtime, make sure
       
    89         // the EMPTY_CONFIGURATION.parents and EMPTY_CONFIGURATION.modules
       
    90         // are the archived ImmutableCollections singletons.
       
    91         Configuration emptyCf = Configuration.empty();
       
    92         List emptyCfParents = emptyCf.parents();
       
    93         Set emptyCfModules = emptyCf.modules();
       
    94         if (expectArchivedConfiguration) {
       
    95             if (emptyCfParents == List.of() &&
       
    96                 wb.isShared(emptyCfParents)) {
       
    97                 System.out.println("Empty Configuration has expected parents.");
       
    98             } else {
       
    99                 throw new RuntimeException(
       
   100                     "FAILED. Unexpected parents for empty Configuration.");
       
   101             }
       
   102             if (emptyCfModules == Set.of() &&
       
   103                 wb.isShared(emptyCfModules)) {
       
   104                 System.out.println("Empty Configuration has expected module set.");
       
   105             } else {
       
   106                 throw new RuntimeException(
       
   107                     "FAILED. Unexpected module set for empty Configuration.");
       
   108             }
       
   109         }
       
   110     }
       
   111 
       
   112 
       
   113 
       
   114     private static void checkConfiguration(boolean expectArchivedConfiguration) {
       
   115         Configuration cf = ModuleLayer.boot().configuration();
       
   116 
       
   117         if (expectArchivedConfiguration) {
       
   118             if (wb.isShared(cf)) {
       
   119                 System.out.println("Boot layer configuration is archived. Expected.");
       
   120             } else {
       
   121                 throw new RuntimeException(
       
   122                     "FAILED. Boot layer configuration is not archived.");
       
   123             }
       
   124         } else {
       
   125             if (!wb.isShared(cf)) {
       
   126                 System.out.println("Boot layer configuration is not archived. Expected.");
       
   127             } else {
       
   128                 throw new RuntimeException(
       
   129                     "FAILED. Boot layer configuration is archived.");
       
   130             }
       
   131         }
       
   132     }
    70 }
   133 }