test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/MainModuleOnly.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57705 7cf02b2c1455
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
     1
/*
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
     4
 *
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
     8
 *
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    13
 * accompanied this code).
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    14
 *
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    18
 *
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    21
 * questions.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    22
 *
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    23
 */
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    24
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    25
/**
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    26
 * @test
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    27
 * @requires vm.cds
57567
b000362a89a0 8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents: 54927
diff changeset
    28
 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
57705
7cf02b2c1455 8229267: [TESTBUG] Remove unnecessary @modules dependencies in CDS tests
iklam
parents: 57567
diff changeset
    29
 * @modules jdk.jartool/sun.tools.jar
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    30
 * @run main/othervm MainModuleOnly
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    31
 * @summary Test some scenarios with a main modular jar specified in the --module-path and -cp options in the command line.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    32
 */
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    33
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    34
import java.io.File;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    35
import java.nio.file.Files;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    36
import java.nio.file.Path;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    37
import java.nio.file.Paths;
50254
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
    38
import java.util.Arrays;
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    39
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    40
import jdk.test.lib.cds.CDSTestUtils.Result;
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    41
import jdk.test.lib.process.OutputAnalyzer;
50254
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
    42
import jdk.test.lib.Platform;
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    43
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    44
public class MainModuleOnly {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    45
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    46
    private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    47
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    48
    private static final String TEST_SRC = System.getProperty("test.src");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    49
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    50
    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    51
    private static final Path MODS_DIR = Paths.get("mods");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    52
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    53
    // the module name of the test module
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    54
    private static final String TEST_MODULE1 = "com.simple";
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    55
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    56
    // the module main class
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    57
    private static final String MAIN_CLASS = "com.simple.Main";
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    58
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    59
    private static Path moduleDir = null;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    60
    private static Path moduleDir2 = null;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    61
    private static Path destJar = null;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    62
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    63
    private static final String jarFileError = "A jar file is not the one used while building the shared archive file:";
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    64
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    65
    public static void buildTestModule() throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    66
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    67
        // javac -d mods/$TESTMODULE --module-path MOD_DIR src/$TESTMODULE/**
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    68
        JarBuilder.compileModule(SRC_DIR.resolve(TEST_MODULE1),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    69
                                 MODS_DIR.resolve(TEST_MODULE1),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    70
                                 MODS_DIR.toString());
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    71
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    72
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    73
        moduleDir = Files.createTempDirectory(USER_DIR, "mlib");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    74
        moduleDir2 = Files.createTempDirectory(USER_DIR, "mlib2");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    75
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    76
        Path srcJar = moduleDir.resolve(TEST_MODULE1 + ".jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    77
        destJar = moduleDir2.resolve(TEST_MODULE1 + ".jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    78
        String classes = MODS_DIR.resolve(TEST_MODULE1).toString();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    79
        JarBuilder.createModularJar(srcJar.toString(), classes, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    80
        Files.copy(srcJar, destJar);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    81
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    82
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    83
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    84
    public static void main(String... args) throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    85
        // compile the modules and create the modular jar files
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    86
        buildTestModule();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    87
        String appClasses[] = {MAIN_CLASS};
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    88
        // create an archive with both -cp and --module-path in the command line.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    89
        // Only the class in the modular jar in the --module-path will be archived;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    90
        // the class in the modular jar in the -cp won't be archived.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    91
        OutputAnalyzer output = TestCommon.createArchive(
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    92
                                        destJar.toString(), appClasses,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    93
                                        "--module-path", moduleDir.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    94
                                        "-m", TEST_MODULE1);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    95
        TestCommon.checkDump(output);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    96
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    97
        // run with the archive using the same command line as in dump time.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    98
        // The main class should be loaded from the archive.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    99
        TestCommon.run("-Xlog:class+load=trace",
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   100
                       "-cp", destJar.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   101
                       "--module-path", moduleDir.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   102
                       "-m", TEST_MODULE1)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   103
            .assertNormalExit("[class,load] com.simple.Main source: shared objects file");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   104
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   105
        // run with the archive with the main class name inserted before the -m.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   106
        // The main class name will be picked up before the module name. So the
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   107
        // main class should be loaded from the jar in the -cp.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   108
        TestCommon.run("-Xlog:class+load=trace",
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   109
                       "-cp", destJar.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   110
                       "--module-path", moduleDir.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   111
                       MAIN_CLASS, "-m", TEST_MODULE1)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   112
            .assertNormalExit(out ->
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   113
                out.shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"));
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   114
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   115
        // run with the archive with exploded module. Since during dump time, we
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   116
        // only archive classes from the modular jar in the --module-path, the
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   117
        // main class should be loaded from the exploded module directory.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   118
        TestCommon.run("-Xlog:class+load=trace",
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   119
                       "-cp", destJar.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   120
                       "--module-path", MODS_DIR.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   121
                       "-m", TEST_MODULE1 + "/" + MAIN_CLASS)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   122
            .assertNormalExit(out -> {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   123
                out.shouldMatch(".class.load. com.simple.Main source:.*com.simple")
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   124
                   .shouldContain(MODS_DIR.toString());
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   125
            });
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   126
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   127
        // run with the archive with the --upgrade-module-path option.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   128
        // CDS will be disabled with this options and the main class will be
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   129
        // loaded from the modular jar.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   130
        TestCommon.run("-Xlog:class+load=trace",
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   131
                       "-cp", destJar.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   132
                       "--upgrade-module-path", moduleDir.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   133
                       "--module-path", moduleDir.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   134
                       "-m", TEST_MODULE1)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   135
            .assertSilentlyDisabledCDS(out -> {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   136
                out.shouldHaveExitValue(0)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   137
                   .shouldMatch("CDS is disabled when the.*option is specified")
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   138
                   .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   139
            });
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   140
        // run with the archive with the --limit-modules option.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   141
        // CDS will be disabled with this options and the main class will be
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   142
        // loaded from the modular jar.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   143
        TestCommon.run("-Xlog:class+load=trace",
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   144
                       "-cp", destJar.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   145
                       "--limit-modules", "java.base," + TEST_MODULE1,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   146
                       "--module-path", moduleDir.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   147
                       "-m", TEST_MODULE1)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   148
            .assertSilentlyDisabledCDS(out -> {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   149
                out.shouldHaveExitValue(0)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   150
                   .shouldMatch("CDS is disabled when the.*option is specified")
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   151
                   .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   152
            });
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   153
        // run with the archive with the --patch-module option.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   154
        // CDS will be disabled with this options and the main class will be
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   155
        // loaded from the modular jar.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   156
        TestCommon.run("-Xlog:class+load=trace",
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   157
                       "-cp", destJar.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   158
                       "--patch-module", TEST_MODULE1 + "=" + MODS_DIR.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   159
                       "--module-path", moduleDir.toString(),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   160
                       "-m", TEST_MODULE1)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   161
            .assertSilentlyDisabledCDS(out -> {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   162
                out.shouldHaveExitValue(0)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   163
                   .shouldMatch("CDS is disabled when the.*option is specified")
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   164
                   .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   165
            });
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   166
        // modify the timestamp of the jar file
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   167
        (new File(destJar.toString())).setLastModified(System.currentTimeMillis() + 2000);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   168
        // run with the archive and the jar with modified timestamp.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   169
        // It should fail due to timestamp of the jar doesn't match the one
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   170
        // used during dump time.
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   171
        Result res = TestCommon.run("-cp", destJar.toString(),
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   172
                       "-Xlog:cds",
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   173
                       "--module-path", moduleDir.toString(),
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   174
                       "-m", TEST_MODULE1);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   175
        res.assertAbnormalExit(jarFileError);
50079
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 49942
diff changeset
   176
        // create an archive with a non-empty directory in the --module-path.
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 49942
diff changeset
   177
        // The dumping process will exit with an error due to non-empty directory
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 49942
diff changeset
   178
        // in the --module-path.
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   179
        String mainModule = TEST_MODULE1;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   180
        if (TestCommon.isDynamicArchive()) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   181
            mainModule += "/" + MAIN_CLASS;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   182
        }
50079
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 49942
diff changeset
   183
        output = TestCommon.createArchive(destJar.toString(), appClasses,
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 49942
diff changeset
   184
                                          "--module-path", MODS_DIR.toString(),
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   185
                                          "-m", mainModule);
50079
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 49942
diff changeset
   186
        output.shouldHaveExitValue(1)
5830a17d9fc8 8202289: Non-empty directory in module path is not handled properly at CDS/AppCDS dump time
ccheung
parents: 49942
diff changeset
   187
              .shouldMatch("Error: non-empty directory.*com.simple");
50254
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   188
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   189
        // test module path with very long length
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   190
        //
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   191
        // This test can't be run on the windows platform due to an existing
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   192
        // issue in ClassLoader::get_canonical_path() (JDK-8190737).
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   193
        if (Platform.isWindows()) {
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   194
            System.out.println("Long module path test cannot be tested on the Windows platform.");
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   195
            return;
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   196
        }
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   197
        Path longDir = USER_DIR;
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   198
        int pathLen = longDir.toString().length();
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   199
        int PATH_LEN = 2034;
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   200
        int MAX_DIR_LEN = 250;
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   201
        while (pathLen < PATH_LEN) {
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   202
            int remaining = PATH_LEN - pathLen;
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   203
            int subPathLen = remaining > MAX_DIR_LEN ? MAX_DIR_LEN : remaining;
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   204
            char[] chars = new char[subPathLen];
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   205
            Arrays.fill(chars, 'x');
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   206
            String subPath = new String(chars);
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   207
            longDir = Paths.get(longDir.toString(), subPath);
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   208
            pathLen = longDir.toString().length();
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   209
        }
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   210
        File longDirFile = new File(longDir.toString());
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   211
        try {
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   212
            longDirFile.mkdirs();
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   213
        } catch (Exception e) {
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   214
            throw e;
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   215
        }
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   216
        Path longDirJar = longDir.resolve(TEST_MODULE1 + ".jar");
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   217
        // IOException results from the Files.copy() call on platform
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   218
        // such as MacOS X. Test can't be proceeded further with the
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   219
        // exception.
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   220
        try {
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   221
            Files.copy(destJar, longDirJar);
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   222
        } catch (java.io.IOException ioe) {
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   223
            System.out.println("Caught IOException from Files.copy(). Cannot continue.");
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   224
            return;
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   225
        }
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   226
        output = TestCommon.createArchive(destJar.toString(), appClasses,
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   227
                                          "-Xlog:exceptions=trace",
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   228
                                          "--module-path", longDirJar.toString(),
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   229
                                          "-m", TEST_MODULE1);
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   230
        if (output.getExitValue() != 0) {
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   231
            output.shouldMatch("os::stat error.*CDS dump aborted");
61657d4a99e5 8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
ccheung
parents: 50199
diff changeset
   232
        }
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   233
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   234
}