test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/JvmtiAddPath.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: 52316
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
 * @summary JvmtiEnv::AddToBootstrapClassLoaderSearch and JvmtiEnv::AddToSystemClassLoaderSearch should disable AppCDS
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    28
 * @requires vm.cds
57567
b000362a89a0 8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents: 54927
diff changeset
    29
 * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/cds/appcds
57705
7cf02b2c1455 8229267: [TESTBUG] Remove unnecessary @modules dependencies in CDS tests
iklam
parents: 57567
diff changeset
    30
 * @modules jdk.jartool/sun.tools.jar
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    31
 * @build sun.hotspot.WhiteBox
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    32
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    33
 * @compile ../../test-classes/JvmtiApp.java
52316
3152b928769d 8209566: [TESTBUG] runtime/appcds/jigsaw/modulepath/JvmtiAddPath.java timeout on tier6 on sparc
ccheung
parents: 51990
diff changeset
    34
 * @run driver/timeout=240 JvmtiAddPath
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    35
 */
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    36
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    37
import java.io.File;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    38
import java.nio.file.Files;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    39
import java.nio.file.Path;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    40
import java.nio.file.Paths;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    41
import jdk.test.lib.process.OutputAnalyzer;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    42
import sun.hotspot.WhiteBox;
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 JvmtiAddPath {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    45
    static String use_whitebox_jar;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    46
    static String[] no_extra_matches = {};
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    47
    static String[] check_appcds_enabled = {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    48
        "[class,load] ExtraClass source: shared object"
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
    static String[] check_appcds_disabled = {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    51
        "[class,load] ExtraClass source: file:"
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
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    54
    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
    55
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    56
    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
    57
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    58
    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
    59
    private static final Path MODS_DIR = Paths.get("mods");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    60
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    61
    // the module name of the test module
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    62
    private static final String TEST_MODULE1 = "com.simple";
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    63
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    64
    // the module main class
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    65
    private static final String MAIN_CLASS = "com.simple.Main";
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
    private static Path moduleDir = null;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    68
    private static Path mainJar = null;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    69
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    70
    public static void buildTestModule() throws Exception {
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
        // 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
    73
        JarBuilder.compileModule(SRC_DIR.resolve(TEST_MODULE1),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    74
                                 MODS_DIR.resolve(TEST_MODULE1),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    75
                                 MODS_DIR.toString());
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    76
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    77
        moduleDir = Files.createTempDirectory(USER_DIR, "mlib");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    78
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    79
        mainJar = moduleDir.resolve(TEST_MODULE1 + ".jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    80
        String classes = MODS_DIR.resolve(TEST_MODULE1).toString();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    81
        JarBuilder.createModularJar(mainJar.toString(), classes, MAIN_CLASS);
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
    static void run(String cp, String... args) throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    85
        run(no_extra_matches, cp, args);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    86
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    87
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    88
    static void run(String[] extra_matches, String cp, String... args) throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    89
        String[] opts = {"-cp", cp, "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", use_whitebox_jar};
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    90
        opts = TestCommon.concat(opts, args);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    91
        TestCommon.run(opts).assertNormalExit(extra_matches);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    92
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    93
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    94
    public static void main(String[] args) throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    95
        buildTestModule();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    96
        JarBuilder.build("jvmti_app", "JvmtiApp", "ExtraClass");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    97
        JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    98
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    99
        // In all the test cases below, appJar does not contain Hello.class. Instead, we
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   100
        // append JAR file(s) that contain Hello.class to the boot classpath, the app
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   101
        // classpath, or both, and verify that Hello.class is loaded by the expected ClassLoader.
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   102
        String appJar = TestCommon.getTestJar("jvmti_app.jar");         // contains JvmtiApp.class
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   103
        String addappJar = mainJar.toString();  // contains Main.class
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   104
        String addbootJar = mainJar.toString(); // contains Main.class
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   105
        String twoAppJars = appJar + File.pathSeparator + addappJar;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   106
        String modulePath = "--module-path=" + moduleDir.toString();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   107
        String wbJar = TestCommon.getTestJar("WhiteBox.jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   108
        use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   109
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   110
        OutputAnalyzer output = TestCommon.createArchive(
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   111
                                    appJar,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   112
                                    TestCommon.list("JvmtiApp", "ExtraClass", MAIN_CLASS),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   113
                                    use_whitebox_jar,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   114
                                    modulePath);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   115
        TestCommon.checkDump(output);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   116
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   117
        System.out.println("Test case 1: not adding module path - Hello.class should not be found");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   118
        run(check_appcds_enabled, appJar,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   119
            "-Xlog:class+load", "JvmtiApp", "noadd", MAIN_CLASS); // appcds should be enabled
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   120
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   121
        System.out.println("Test case 2: add to boot classpath only - should find Hello.class in boot loader");
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52316
diff changeset
   122
        String[] toCheck = TestCommon.isDynamicArchive() ? check_appcds_enabled :
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52316
diff changeset
   123
                           check_appcds_disabled;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52316
diff changeset
   124
        run(toCheck, appJar,
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   125
            "-Xlog:class+load=trace",
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   126
            modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   127
            "JvmtiApp", "bootonly", addbootJar, MAIN_CLASS); // appcds should be disabled
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   128
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   129
        System.out.println("Test case 3: add to app classpath only - should find Hello.class in app loader");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   130
        run(appJar, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   131
            "JvmtiApp", "apponly", addappJar, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   132
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   133
        System.out.println("Test case 4: add to boot and app paths - should find Hello.class in boot loader");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   134
        run(appJar, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   135
            "JvmtiApp", "appandboot", addbootJar, addappJar, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   136
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   137
        System.out.println("Test case 5: add to app using -cp, but add to boot using JVMTI - should find Hello.class in boot loader");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   138
        run(appJar, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   139
            "JvmtiApp", "bootonly", addappJar, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   140
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   141
        System.out.println("Test case 6: add to app using AppCDS, but add to boot using JVMTI - should find Hello.class in boot loader");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   142
        output = TestCommon.createArchive(
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   143
                     appJar, TestCommon.list("JvmtiApp", "ExtraClass"),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   144
                     use_whitebox_jar,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   145
                     modulePath);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   146
        TestCommon.checkDump(output);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   147
        run(twoAppJars, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   148
            "JvmtiApp", "bootonly", addappJar, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   149
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   150
        System.out.println("Test case 7: add to app using AppCDS, no JVMTI calls - should find Hello.class in app loader");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   151
        run(twoAppJars, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   152
            "JvmtiApp", "noadd-appcds", MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   153
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   154
}