test/hotspot/jtreg/runtime/cds/appcds/JvmtiAddPath.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54927 1512d88b24c6
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
       
     1 /*
       
     2  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 /*
       
    26  * @test
       
    27  * @summary JvmtiEnv::AddToBootstrapClassLoaderSearch and JvmtiEnv::AddToSystemClassLoaderSearch should disable AppCDS
       
    28  * @requires vm.cds
       
    29  * @bug 8060592
       
    30  * @library /test/lib
       
    31  * @modules jdk.jartool/sun.tools.jar
       
    32  * @build sun.hotspot.WhiteBox
       
    33  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
       
    34  * @compile test-classes/Hello.java
       
    35  * @compile test-classes/JvmtiApp.java
       
    36  * @run driver JvmtiAddPath
       
    37  */
       
    38 
       
    39 import java.io.File;
       
    40 import jdk.test.lib.process.OutputAnalyzer;
       
    41 import sun.hotspot.WhiteBox;
       
    42 
       
    43 public class JvmtiAddPath {
       
    44     static String use_whitebox_jar;
       
    45     static String[] no_extra_matches = {};
       
    46     static String[] check_appcds_enabled = {
       
    47         "[class,load] ExtraClass source: shared object"
       
    48     };
       
    49     static String[] check_appcds_disabled = {
       
    50         "[class,load] ExtraClass source: file:"
       
    51     };
       
    52 
       
    53     static void run(String cp, String... args) throws Exception {
       
    54         run(no_extra_matches, cp, args);
       
    55     }
       
    56 
       
    57     static void run(String[] extra_matches, String cp, String... args) throws Exception {
       
    58         String[] opts = {"-cp", cp, "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", use_whitebox_jar};
       
    59         opts = TestCommon.concat(opts, args);
       
    60         TestCommon.run(opts).assertNormalExit(extra_matches);
       
    61     }
       
    62 
       
    63     public static void main(String[] args) throws Exception {
       
    64         JarBuilder.build("jvmti_addboot", "Hello");
       
    65         JarBuilder.build("jvmti_addapp", "Hello");
       
    66         JarBuilder.build("jvmti_app", "JvmtiApp", "ExtraClass");
       
    67         JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
       
    68 
       
    69         // In all the test cases below, appJar does not contain Hello.class. Instead, we
       
    70         // append JAR file(s) that contain Hello.class to the boot classpath, the app
       
    71         // classpath, or both, and verify that Hello.class is loaded by the expected ClassLoader.
       
    72         String appJar = TestCommon.getTestJar("jvmti_app.jar");         // contains JvmtiApp.class
       
    73         String addappJar = TestCommon.getTestJar("jvmti_addapp.jar");   // contains Hello.class
       
    74         String addbootJar = TestCommon.getTestJar("jvmti_addboot.jar"); // contains Hello.class
       
    75         String twoAppJars = appJar + File.pathSeparator + addappJar;
       
    76         String wbJar = TestCommon.getTestJar("WhiteBox.jar");
       
    77         use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
       
    78 
       
    79         TestCommon.testDump(appJar, TestCommon.list("JvmtiApp", "ExtraClass"), use_whitebox_jar);
       
    80 
       
    81         System.out.println("Test case 1: not adding any paths - Hello.class should not be found");
       
    82         run(check_appcds_enabled, appJar, "-Xlog:class+load", "JvmtiApp", "noadd"); // appcds should be enabled
       
    83 
       
    84         System.out.println("Test case 2: add to boot classpath only - should find Hello.class in boot loader");
       
    85         String[] toCheck = (TestCommon.isDynamicArchive()) ? check_appcds_enabled
       
    86                                                            : check_appcds_disabled;
       
    87         run(toCheck, appJar, "-Xlog:class+load", "JvmtiApp", "bootonly", addbootJar); // appcds should be disabled
       
    88 
       
    89         System.out.println("Test case 3: add to app classpath only - should find Hello.class in app loader");
       
    90         run(appJar, "JvmtiApp", "apponly", addappJar);
       
    91 
       
    92         System.out.println("Test case 4: add to boot and app paths - should find Hello.class in boot loader");
       
    93         run(appJar, "JvmtiApp", "appandboot", addbootJar, addappJar);
       
    94 
       
    95         System.out.println("Test case 5: add to app using -cp, but add to boot using JVMTI - should find Hello.class in boot loader");
       
    96         run(twoAppJars, "JvmtiApp", "bootonly", addappJar);
       
    97 
       
    98         System.out.println("Test case 6: add to app using AppCDS, but add to boot using JVMTI - should find Hello.class in boot loader");
       
    99         TestCommon.testDump(twoAppJars, TestCommon.list("JvmtiApp", "ExtraClass", "Hello"), use_whitebox_jar);
       
   100         if (!TestCommon.isDynamicArchive()) {
       
   101             // skip for dynamic archive, the Hello class will be loaded from
       
   102             // the dynamic archive
       
   103             run(twoAppJars, "JvmtiApp", "bootonly", addappJar);
       
   104         }
       
   105 
       
   106         System.out.println("Test case 7: add to app using AppCDS, no JVMTI calls - should find Hello.class in app loader");
       
   107         run(twoAppJars, "JvmtiApp", "noadd-appcds");
       
   108     }
       
   109 }