test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/JvmtiAddPath.java
author ccheung
Fri, 17 May 2019 08:29:55 -0700
changeset 54927 1512d88b24c6
parent 52316 3152b928769d
permissions -rw-r--r--
8207812: Implement Dynamic CDS Archive Summary: Improve the usability of AppCDS Reviewed-by: acorn, jiangli, mseledtsov Contributed-by: ioi.lam@oracle.com, jianglizhou@google.com, calvin.cheung@oracle.com
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
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    29
 * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/appcds
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    31
 *          java.management
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    32
 *          jdk.jartool/sun.tools.jar
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    33
 * @build sun.hotspot.WhiteBox
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    34
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    35
 * @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
    36
 * @run driver/timeout=240 JvmtiAddPath
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    37
 */
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    38
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    39
import java.io.File;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    40
import java.nio.file.Files;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    41
import java.nio.file.Path;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    42
import java.nio.file.Paths;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    43
import jdk.test.lib.process.OutputAnalyzer;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    44
import sun.hotspot.WhiteBox;
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
public class JvmtiAddPath {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    47
    static String use_whitebox_jar;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    48
    static String[] no_extra_matches = {};
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    49
    static String[] check_appcds_enabled = {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    50
        "[class,load] ExtraClass source: shared object"
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    51
    };
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    52
    static String[] check_appcds_disabled = {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    53
        "[class,load] ExtraClass source: file:"
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    54
    };
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 Path USER_DIR = Paths.get(System.getProperty("user.dir"));
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 String TEST_SRC = System.getProperty("test.src");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    59
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    60
    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
    61
    private static final Path MODS_DIR = Paths.get("mods");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    62
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    63
    // the module name of the test module
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    64
    private static final String TEST_MODULE1 = "com.simple";
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    65
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    66
    // the module main class
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    67
    private static final String MAIN_CLASS = "com.simple.Main";
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    68
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    69
    private static Path moduleDir = null;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    70
    private static Path mainJar = null;
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
    public static void buildTestModule() throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    73
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    74
        // 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
    75
        JarBuilder.compileModule(SRC_DIR.resolve(TEST_MODULE1),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    76
                                 MODS_DIR.resolve(TEST_MODULE1),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    77
                                 MODS_DIR.toString());
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
        moduleDir = Files.createTempDirectory(USER_DIR, "mlib");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    80
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    81
        mainJar = moduleDir.resolve(TEST_MODULE1 + ".jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    82
        String classes = MODS_DIR.resolve(TEST_MODULE1).toString();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    83
        JarBuilder.createModularJar(mainJar.toString(), classes, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    84
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    85
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    86
    static void run(String cp, String... args) throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    87
        run(no_extra_matches, cp, args);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    88
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    89
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    90
    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
    91
        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
    92
        opts = TestCommon.concat(opts, args);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    93
        TestCommon.run(opts).assertNormalExit(extra_matches);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    94
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    95
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    96
    public static void main(String[] args) throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    97
        buildTestModule();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    98
        JarBuilder.build("jvmti_app", "JvmtiApp", "ExtraClass");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
    99
        JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   100
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   101
        // 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
   102
        // 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
   103
        // 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
   104
        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
   105
        String addappJar = mainJar.toString();  // contains Main.class
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   106
        String addbootJar = mainJar.toString(); // contains Main.class
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   107
        String twoAppJars = appJar + File.pathSeparator + addappJar;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   108
        String modulePath = "--module-path=" + moduleDir.toString();
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   109
        String wbJar = TestCommon.getTestJar("WhiteBox.jar");
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   110
        use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   111
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   112
        OutputAnalyzer output = TestCommon.createArchive(
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   113
                                    appJar,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   114
                                    TestCommon.list("JvmtiApp", "ExtraClass", MAIN_CLASS),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   115
                                    use_whitebox_jar,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   116
                                    modulePath);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   117
        TestCommon.checkDump(output);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   118
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   119
        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
   120
        run(check_appcds_enabled, appJar,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   121
            "-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
   122
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   123
        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
   124
        String[] toCheck = TestCommon.isDynamicArchive() ? check_appcds_enabled :
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52316
diff changeset
   125
                           check_appcds_disabled;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52316
diff changeset
   126
        run(toCheck, appJar,
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   127
            "-Xlog:class+load=trace",
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   128
            modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   129
            "JvmtiApp", "bootonly", addbootJar, MAIN_CLASS); // appcds should be disabled
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   130
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   131
        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
   132
        run(appJar, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   133
            "JvmtiApp", "apponly", addappJar, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   134
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   135
        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
   136
        run(appJar, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   137
            "JvmtiApp", "appandboot", addbootJar, addappJar, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   138
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   139
        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
   140
        run(appJar, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   141
            "JvmtiApp", "bootonly", addappJar, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   142
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   143
        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
   144
        output = TestCommon.createArchive(
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   145
                     appJar, TestCommon.list("JvmtiApp", "ExtraClass"),
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   146
                     use_whitebox_jar,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   147
                     modulePath);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   148
        TestCommon.checkDump(output);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   149
        run(twoAppJars, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   150
            "JvmtiApp", "bootonly", addappJar, MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   151
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   152
        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
   153
        run(twoAppJars, modulePath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   154
            "JvmtiApp", "noadd-appcds", MAIN_CLASS);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   155
    }
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents:
diff changeset
   156
}