< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/jigsaw/module/ModuleOption.java

Print this page

  1 /*
  2  * Copyright (c) 2023, 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  * @test
 26  * @bug 8316969
 27  * @summary Test handling of module option (-m).
 28  * @requires vm.cds.write.archived.java.heap
 29  * @requires vm.flagless
 30  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
 31  * @run driver ModuleOption
 32  */
 33 
 34 import jdk.test.lib.process.OutputAnalyzer;
 35 
 36 public class ModuleOption {
 37     public static void main(String[] args) throws Exception {
 38         final String moduleOption = "jdk.httpserver/sun.net.httpserver.simpleserver.Main";
 39         final String incubatorModule = "jdk.incubator.vector";
 40         final String loggingOption = "-Xlog:cds=debug,cds+module=debug,cds+heap=info,module=trace";
 41         final String versionPattern = "java.[0-9][0-9][-].*";
 42         final String subgraphCannotBeUsed = "subgraph jdk.internal.module.ArchivedBootLayer cannot be used because full module graph is disabled";

 43         String archiveName = TestCommon.getNewArchiveName("module-option");
 44         TestCommon.setCurrentArchiveName(archiveName);
 45 
 46         // dump a base archive with -m jdk.httpserver
 47         OutputAnalyzer oa = TestCommon.dumpBaseArchive(
 48             archiveName,
 49             loggingOption,
 50             "-m", moduleOption,
 51             "-version");
 52         oa.shouldHaveExitValue(0);
 53 
 54         // same module specified during runtime
 55         oa = TestCommon.execCommon(
 56             loggingOption,
 57             "-m", moduleOption,
 58             "-version");
 59         oa.shouldHaveExitValue(0)
 60           // version of the jdk.httpserver module, e.g. java 22-ea
 61           .shouldMatch(versionPattern)
 62           .shouldMatch("cds,module.*Restored from archive: entry.0x.*name jdk.httpserver");


 63 
 64         // different module specified during runtime
 65         oa = TestCommon.execCommon(
 66             loggingOption,
 67             "-m", "jdk.compiler/com.sun.tools.javac.Main",
 68             "-version");
 69         oa.shouldHaveExitValue(0)
 70           .shouldContain("Mismatched modules: runtime jdk.compiler dump time jdk.httpserver")
 71           .shouldContain(subgraphCannotBeUsed);


 72 
 73         // no module specified during runtime
 74         oa = TestCommon.execCommon(
 75             loggingOption,
 76             "-version");
 77         oa.shouldHaveExitValue(0)
 78           .shouldContain("Module jdk.httpserver specified during dump time but not during runtime")
 79           .shouldContain(subgraphCannotBeUsed);


 80 
 81         // dump an archive without the module option
 82         archiveName = TestCommon.getNewArchiveName("no-module-option");
 83         TestCommon.setCurrentArchiveName(archiveName);
 84         oa = TestCommon.dumpBaseArchive(
 85             archiveName,
 86             loggingOption,
 87             "-version");
 88         oa.shouldHaveExitValue(0);
 89 
 90         // run with module option
 91         oa = TestCommon.execCommon(
 92             loggingOption,
 93             "-m", moduleOption,
 94             "-version");
 95         oa.shouldHaveExitValue(0)
 96           .shouldContain("Module jdk.httpserver specified during runtime but not during dump time")
 97           // version of the jdk.httpserver module, e.g. java 22-ea
 98           .shouldMatch(versionPattern)
 99           .shouldContain(subgraphCannotBeUsed);


100 
101         // dump an archive with an incubator module, -m jdk.incubator.vector
102         archiveName = TestCommon.getNewArchiveName("incubator-module");
103         TestCommon.setCurrentArchiveName(archiveName);
104         oa = TestCommon.dumpBaseArchive(
105             archiveName,
106             loggingOption,
107             "-m", incubatorModule,
108             "-version");
109         oa.shouldHaveExitValue(0)
110           // module graph won't be archived with an incubator module
111           .shouldContain("archivedBootLayer not available, disabling full module graph");
112 
113         // run with the same incubator module
114         oa = TestCommon.execCommon(
115             loggingOption,
116             "-m", incubatorModule,
117             "-version");
118         oa.shouldContain("full module graph: disabled")
119           // module is not restored from archive

  1 /*
  2  * Copyright (c) 2023, 2024, 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  * @test
 26  * @bug 8316969
 27  * @summary Test handling of module option (-m).
 28  * @requires vm.cds.write.archived.java.heap
 29  * @requires vm.flagless
 30  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
 31  * @run driver ModuleOption
 32  */
 33 
 34 import jdk.test.lib.process.OutputAnalyzer;
 35 
 36 public class ModuleOption {
 37     public static void main(String[] args) throws Exception {
 38         final String moduleOption = "jdk.httpserver/sun.net.httpserver.simpleserver.Main";
 39         final String incubatorModule = "jdk.incubator.vector";
 40         final String loggingOption = "-Xlog:cds=debug,cds+module=debug,cds+heap=info,module=trace";
 41         final String versionPattern = "java.[0-9][0-9][-].*";
 42         final String subgraphCannotBeUsed = "subgraph jdk.internal.module.ArchivedBootLayer cannot be used because full module graph is disabled";
 43         final String noOptimizedModuleHandling = "optimized module handling: disabled because archive was created without optimized module handling";
 44         String archiveName = TestCommon.getNewArchiveName("module-option");
 45         TestCommon.setCurrentArchiveName(archiveName);
 46 
 47         // dump a base archive with -m jdk.httpserver
 48         OutputAnalyzer oa = TestCommon.dumpBaseArchive(
 49             archiveName,
 50             loggingOption,
 51             "-m", moduleOption,
 52             "-version");
 53         oa.shouldHaveExitValue(0);
 54 
 55         // same module specified during runtime
 56         oa = TestCommon.execCommon(
 57             loggingOption,
 58             "-m", moduleOption,
 59             "-version");
 60         oa.shouldHaveExitValue(0)
 61           // version of the jdk.httpserver module, e.g. java 22-ea
 62           .shouldMatch(versionPattern);
 63         if (!oa.contains(noOptimizedModuleHandling)) {
 64             oa.shouldMatch("cds,module.*Restored from archive: entry.0x.*name jdk.httpserver");
 65         }
 66 
 67         // different module specified during runtime
 68         oa = TestCommon.execCommon(
 69             loggingOption,
 70             "-m", "jdk.compiler/com.sun.tools.javac.Main",
 71             "-version");
 72         oa.shouldHaveExitValue(0)
 73           .shouldContain("Mismatched modules: runtime jdk.compiler dump time jdk.httpserver");
 74         if (!oa.contains(noOptimizedModuleHandling)) {
 75             oa.shouldContain(subgraphCannotBeUsed);
 76         }
 77 
 78         // no module specified during runtime
 79         oa = TestCommon.execCommon(
 80             loggingOption,
 81             "-version");
 82         oa.shouldHaveExitValue(0)
 83           .shouldContain("Module jdk.httpserver specified during dump time but not during runtime");
 84         if (!oa.contains(noOptimizedModuleHandling)) {
 85             oa.shouldContain(subgraphCannotBeUsed);
 86         }
 87 
 88         // dump an archive without the module option
 89         archiveName = TestCommon.getNewArchiveName("no-module-option");
 90         TestCommon.setCurrentArchiveName(archiveName);
 91         oa = TestCommon.dumpBaseArchive(
 92             archiveName,
 93             loggingOption,
 94             "-version");
 95         oa.shouldHaveExitValue(0);
 96 
 97         // run with module option
 98         oa = TestCommon.execCommon(
 99             loggingOption,
100             "-m", moduleOption,
101             "-version");
102         oa.shouldHaveExitValue(0)
103           .shouldContain("Module jdk.httpserver specified during runtime but not during dump time")
104           // version of the jdk.httpserver module, e.g. java 22-ea
105           .shouldMatch(versionPattern);
106         if (!oa.contains(noOptimizedModuleHandling)) {
107             oa.shouldContain(subgraphCannotBeUsed);
108         }
109 
110         // dump an archive with an incubator module, -m jdk.incubator.vector
111         archiveName = TestCommon.getNewArchiveName("incubator-module");
112         TestCommon.setCurrentArchiveName(archiveName);
113         oa = TestCommon.dumpBaseArchive(
114             archiveName,
115             loggingOption,
116             "-m", incubatorModule,
117             "-version");
118         oa.shouldHaveExitValue(0)
119           // module graph won't be archived with an incubator module
120           .shouldContain("archivedBootLayer not available, disabling full module graph");
121 
122         // run with the same incubator module
123         oa = TestCommon.execCommon(
124             loggingOption,
125             "-m", incubatorModule,
126             "-version");
127         oa.shouldContain("full module graph: disabled")
128           // module is not restored from archive
< prev index next >