hotspot/test/runtime/modules/PatchModule/PatchModuleCDS.java
author ccheung
Mon, 28 Aug 2017 15:34:04 -0700
changeset 47103 a993ec29ec75
parent 46790 8c4deba6a0ee
permissions -rw-r--r--
8186842: Use Java class loaders for creating the CDS archive Reviewed-by: coleenp, jiangli, iklam, mseledtsov Contributed-by: calvin.cheung@oracle.com, ioi.lam@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     1
/*
46779
d80ca591ae48 8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents: 45112
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     4
 *
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     8
 *
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    13
 * accompanied this code).
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    14
 *
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    18
 *
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    21
 * questions.
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    22
 */
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    23
46779
d80ca591ae48 8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents: 45112
diff changeset
    24
/**
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    25
 * @test
46779
d80ca591ae48 8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents: 45112
diff changeset
    26
 * @requires vm.cds
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    27
 * @summary test that --patch-module works with CDS
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    28
 * @library /test/lib
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.misc
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    30
 *          jdk.jartool/sun.tools.jar
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    31
 * @build PatchModuleMain
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    32
 * @run main PatchModuleCDS
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    33
 */
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    34
45112
fbec2bfa3839 8180037: move jdk.test.lib.InMemoryJavaCompiler to a separate package
iignatyev
parents: 42876
diff changeset
    35
import jdk.test.lib.compiler.InMemoryJavaCompiler;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    37
import jdk.test.lib.process.ProcessTools;
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    38
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    39
public class PatchModuleCDS {
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    40
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    41
    public static void main(String args[]) throws Throwable {
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    42
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    43
        // Case 1: Test that --patch-module and -Xshare:dump are compatible
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    44
        String filename = "patch_module.jsa";
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    45
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    46
            "-XX:+UnlockDiagnosticVMOptions",
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    47
            "-XX:SharedArchiveFile=" + filename,
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    48
            "-Xshare:dump",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    49
            "--patch-module=java.naming=no/such/directory",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    50
            "-Xlog:class+path=info",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    51
            "-version");
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    52
        new OutputAnalyzer(pb.start())
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    53
            .shouldContain("ro space:"); // Make sure archive got created.
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    54
42876
ff8ff9dcccec 8168797: do not load any archived classes from a patched module
jiangli
parents: 41281
diff changeset
    55
        // Case 2: Test that directory in --patch-module is supported for CDS dumping
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    56
        // Create a class file in the module java.base.
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    57
        String source = "package javax.naming.spi; "                +
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    58
                        "public class NamingManager { "             +
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    59
                        "    static { "                             +
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    60
                        "        System.out.println(\"I pass!\"); " +
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    61
                        "    } "                                    +
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    62
                        "}";
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    63
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    64
        ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
46790
8c4deba6a0ee 8177741: Fix hotspot tests to use --patch-module instead of -Xmodule
hseigel
parents: 46779
diff changeset
    65
             InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"),
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    66
             System.getProperty("test.classes"));
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    67
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    68
        pb = ProcessTools.createJavaProcessBuilder(
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    69
            "-XX:+UnlockDiagnosticVMOptions",
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    70
            "-XX:SharedArchiveFile=" + filename,
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    71
            "-Xshare:dump",
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46790
diff changeset
    72
            "--patch-module=java.naming=" + System.getProperty("test.classes"),
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    73
            "-Xlog:class+path=info",
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    74
            "-version");
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    75
        new OutputAnalyzer(pb.start())
42876
ff8ff9dcccec 8168797: do not load any archived classes from a patched module
jiangli
parents: 41281
diff changeset
    76
            .shouldContain("ro space:"); // Make sure archive got created.
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
    77
41281
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    78
        // Case 3a: Test CDS dumping with jar file in --patch-module
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    79
        BasicJarBuilder.build("javanaming", "javax/naming/spi/NamingManager");
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    80
        String moduleJar = BasicJarBuilder.getTestJar("javanaming.jar");
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    81
        pb = ProcessTools.createJavaProcessBuilder(
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    82
            "-XX:+UnlockDiagnosticVMOptions",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    83
            "-XX:SharedArchiveFile=" + filename,
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    84
            "-Xshare:dump",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    85
            "--patch-module=java.naming=" + moduleJar,
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    86
            "-Xlog:class+load",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    87
            "-Xlog:class+path=info",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    88
            "PatchModuleMain", "javax.naming.spi.NamingManager");
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    89
        new OutputAnalyzer(pb.start())
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    90
            .shouldContain("ro space:"); // Make sure archive got created.
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    91
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    92
        // Case 3b: Test CDS run with jar file in --patch-module
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    93
        pb = ProcessTools.createJavaProcessBuilder(
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    94
            "-XX:+UnlockDiagnosticVMOptions",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    95
            "-XX:SharedArchiveFile=" + filename,
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    96
            "-Xshare:auto",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    97
            "--patch-module=java.naming=" + moduleJar,
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    98
            "-Xlog:class+load",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
    99
            "-Xlog:class+path=info",
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
   100
            "PatchModuleMain", "javax.naming.spi.NamingManager");
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
   101
        new OutputAnalyzer(pb.start())
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
   102
            .shouldContain("I pass!")
e1dc38ba642f 8164011: --patch-module support for CDS
ccheung
parents: 40631
diff changeset
   103
            .shouldHaveExitValue(0);
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
   104
    }
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
diff changeset
   105
}