test/hotspot/jtreg/runtime/cds/appcds/HelloExtTest.java
changeset 57567 b000362a89a0
parent 51990 6003e034cdd8
child 57705 7cf02b2c1455
equal deleted inserted replaced
57566:ad84ae073248 57567:b000362a89a0
       
     1 /*
       
     2  * Copyright (c) 2015, 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 a simple test for loading a class using the platform class loader
       
    28  *          (which used to be called the "extension loader) in AppCDS
       
    29  * @requires vm.cds
       
    30  * @library /test/lib
       
    31  * @modules java.base/jdk.internal.misc
       
    32  *          java.management
       
    33  *          jdk.jartool/sun.tools.jar
       
    34  *          jdk.internal.jvmstat/sun.jvmstat.monitor
       
    35  * @compile test-classes/HelloExt.java
       
    36  * @build sun.hotspot.WhiteBox
       
    37  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
       
    38  * @run driver HelloExtTest
       
    39  */
       
    40 
       
    41 import jdk.test.lib.process.OutputAnalyzer;
       
    42 
       
    43 public class HelloExtTest {
       
    44 
       
    45   public static void main(String[] args) throws Exception {
       
    46     JarBuilder.build("helloExt", "HelloExt");
       
    47 
       
    48     String appJar = TestCommon.getTestJar("helloExt.jar");
       
    49     JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
       
    50     String whiteBoxJar = TestCommon.getTestJar("WhiteBox.jar");
       
    51     String bootClassPath = "-Xbootclasspath/a:" + whiteBoxJar;
       
    52 
       
    53     TestCommon.dump(appJar,
       
    54         TestCommon.list("javax/annotation/processing/FilerException", "[Ljava/lang/Comparable;"),
       
    55         bootClassPath);
       
    56 
       
    57     String prefix = ".class.load. ";
       
    58     String class_pattern = ".*LambdaForm[$]MH[/][0123456789].*";
       
    59     String suffix = ".*source: shared objects file.*";
       
    60     String pattern = prefix + class_pattern + suffix;
       
    61 
       
    62     TestCommon.run("-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
       
    63             "-cp", appJar, bootClassPath, "-Xlog:class+load", "HelloExt")
       
    64         .assertNormalExit(output -> output.shouldNotMatch(pattern));
       
    65 
       
    66 
       
    67     TestCommon.run("-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
       
    68             "-cp", appJar, bootClassPath, "-Xlog:class+load",
       
    69             "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary",
       
    70             "HelloExt")
       
    71         .assertNormalExit(output ->  output.shouldNotMatch(class_pattern));
       
    72   }
       
    73 }