test/hotspot/jtreg/runtime/cds/appcds/cacheObject/ArchivedModuleComboTest.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 51990 6003e034cdd8
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
       
     1 /*
       
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 /*
       
    26  * @test
       
    27  * @summary Test archived system module sub-graph and verify objects are archived.
       
    28  * @requires vm.cds.archived.java.heap
       
    29  * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/cds/appcds
       
    30  * @build sun.hotspot.WhiteBox
       
    31  * @compile CheckArchivedModuleApp.java
       
    32  * @run driver ClassFileInstaller -jar app.jar CheckArchivedModuleApp
       
    33  * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
       
    34  * @run driver ArchivedModuleComboTest
       
    35  */
       
    36 
       
    37 import java.io.File;
       
    38 import java.nio.file.Files;
       
    39 import java.nio.file.Path;
       
    40 import java.nio.file.Paths;
       
    41 import jdk.test.lib.process.OutputAnalyzer;
       
    42 import jdk.test.lib.process.ProcessTools;
       
    43 import sun.hotspot.WhiteBox;
       
    44 
       
    45 public class ArchivedModuleComboTest {
       
    46     public static void main(String[] args) throws Exception {
       
    47         String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar");
       
    48         String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
       
    49         String appJar = ClassFileInstaller.getJarPath("app.jar");
       
    50 
       
    51         Path userDir = Paths.get(System.getProperty("user.dir"));
       
    52         Path moduleDir = Files.createTempDirectory(userDir, "mods");
       
    53 
       
    54         //
       
    55         // Dump without --module-path, without --show-module-resolution
       
    56         //
       
    57         OutputAnalyzer output = TestCommon.dump(appJar,
       
    58                                     TestCommon.list("CheckArchivedModuleApp"),
       
    59                                     use_whitebox_jar);
       
    60         TestCommon.checkDump(output);
       
    61 
       
    62         // Test case 1)
       
    63         // - Dump without --module-path, without --show-module-resolution
       
    64         // - Run from -cp only and without --show-module-resolution
       
    65         //     + archived boot layer module ModuleDescriptors should be used
       
    66         //     + archived boot layer configuration should be used
       
    67         System.out.println("----------------------- Test case 1 ----------------------");
       
    68         output = TestCommon.exec(appJar, use_whitebox_jar,
       
    69                                  "-XX:+UnlockDiagnosticVMOptions",
       
    70                                  "-XX:+WhiteBoxAPI",
       
    71                                  "CheckArchivedModuleApp",
       
    72                                  "yes",
       
    73                                  "yes");
       
    74         TestCommon.checkExec(output);
       
    75 
       
    76         // Test case 2)
       
    77         // - Dump without --module-path, without --show-module-resolution
       
    78         // - Run from -cp only and with --show-module-resolution
       
    79         //     + archived boot layer module ModuleDescriptors should be used with
       
    80         //       --show-module-resolution (requires resolution)
       
    81         //     + archived boot layer Configuration should not be disabled
       
    82         System.out.println("----------------------- Test case 2 ----------------------");
       
    83         output = TestCommon.exec(appJar, use_whitebox_jar,
       
    84                                  "--show-module-resolution",
       
    85                                  "-XX:+UnlockDiagnosticVMOptions",
       
    86                                  "-XX:+WhiteBoxAPI",
       
    87                                  "CheckArchivedModuleApp",
       
    88                                  "yes",
       
    89                                  "no");
       
    90         TestCommon.checkExec(output, "root java.base jrt:/java.base");
       
    91 
       
    92         // Test case 3)
       
    93         // - Dump without --module-path, without --show-module-resolution
       
    94         // - Run with --module-path
       
    95         //    + archived boot layer module ModuleDescriptors should be disabled
       
    96         //    + archived boot layer Configuration should be disabled
       
    97         System.out.println("----------------------- Test case 3 ----------------------");
       
    98         output = TestCommon.exec(appJar, use_whitebox_jar,
       
    99                                  "--module-path",
       
   100                                  moduleDir.toString(),
       
   101                                  "-XX:+UnlockDiagnosticVMOptions",
       
   102                                  "-XX:+WhiteBoxAPI",
       
   103                                  "CheckArchivedModuleApp",
       
   104                                  "no",
       
   105                                  "no");
       
   106         TestCommon.checkExec(output);
       
   107 
       
   108         //
       
   109         // Dump with --module-path specified (test case 4, 5). Use an
       
   110         // empty directory as it's simple and still triggers the case
       
   111         // where system module objects are not archived.
       
   112         //
       
   113         output = TestCommon.dump(appJar,
       
   114                                  TestCommon.list("CheckArchivedModuleApp"),
       
   115                                  "--module-path",
       
   116                                  moduleDir.toString(),
       
   117                                  use_whitebox_jar);
       
   118         TestCommon.checkDump(output);
       
   119 
       
   120         // Test case 4)
       
   121         // - Dump with --module-path
       
   122         // - Run from -cp only, no archived boot layer module ModuleDescriptors
       
   123         //   and Configuration should be found.
       
   124         System.out.println("----------------------- Test case 4 ----------------------");
       
   125         output = TestCommon.exec(appJar, use_whitebox_jar,
       
   126                                  "-XX:+UnlockDiagnosticVMOptions",
       
   127                                  "-XX:+WhiteBoxAPI",
       
   128                                  "CheckArchivedModuleApp",
       
   129                                  "no",
       
   130                                  "no");
       
   131         TestCommon.checkExec(output);
       
   132 
       
   133         // Test case 5)
       
   134         // - Dump with --module-path
       
   135         // - Run with --module-path, no archived boot layer module ModuleDescriptors
       
   136         //   and Configuration should be found.
       
   137         System.out.println("----------------------- Test case 5 ----------------------");
       
   138         output = TestCommon.exec(appJar, use_whitebox_jar,
       
   139                                  "--module-path",
       
   140                                  moduleDir.toString(),
       
   141                                  "-XX:+UnlockDiagnosticVMOptions",
       
   142                                  "-XX:+WhiteBoxAPI",
       
   143                                  "CheckArchivedModuleApp",
       
   144                                  "no",
       
   145                                  "no");
       
   146         TestCommon.checkExec(output);
       
   147 
       
   148         //
       
   149         // Dump without --module-path, with --show-module-resolution
       
   150         //
       
   151         output = TestCommon.dump(appJar,
       
   152                                  TestCommon.list("CheckArchivedModuleApp"),
       
   153                                  "--show-module-resolution",
       
   154                                  use_whitebox_jar);
       
   155         TestCommon.checkDump(output, "root java.base jrt:/java.base");
       
   156 
       
   157         // Test case 6)
       
   158         // - Dump without --module-path, with --show-module-resolution
       
   159         // - Run from -cp only and without --show-module-resolution
       
   160         //     + archived boot layer module ModuleDescriptors should be used
       
   161         //     + archived boot layer Configuration should be used
       
   162         System.out.println("----------------------- Test case 6 ----------------------");
       
   163         output = TestCommon.exec(appJar, use_whitebox_jar,
       
   164                                  "-XX:+UnlockDiagnosticVMOptions",
       
   165                                  "-XX:+WhiteBoxAPI",
       
   166                                  "CheckArchivedModuleApp",
       
   167                                  "yes",
       
   168                                  "yes");
       
   169         TestCommon.checkExec(output);
       
   170 
       
   171         // Test case 7)
       
   172         // - Dump without --module-path, with --show-module-resolution
       
   173         // - Run from -cp only and with --show-module-resolution
       
   174         //     + archived boot layer module ModuleDescriptors should be used with
       
   175         //       --show-module-resolution (requires resolution)
       
   176         //     + archived boot layer Configuration should be disabled
       
   177         System.out.println("----------------------- Test case 7 ----------------------");
       
   178         output = TestCommon.exec(appJar, use_whitebox_jar,
       
   179                                  "--show-module-resolution",
       
   180                                  "-XX:+UnlockDiagnosticVMOptions",
       
   181                                  "-XX:+WhiteBoxAPI",
       
   182                                  "CheckArchivedModuleApp",
       
   183                                  "yes",
       
   184                                  "no");
       
   185         TestCommon.checkExec(output, "root java.base jrt:/java.base");
       
   186     }
       
   187 }