test/hotspot/jtreg/runtime/cds/appcds/javaldr/AnonVmClassesDuringDump.java
author coleenp
Mon, 29 Jul 2019 10:34:20 -0400
changeset 57567 b000362a89a0
parent 52596 test/hotspot/jtreg/runtime/appcds/javaldr/AnonVmClassesDuringDump.java@dfa02b3f728c
child 57705 7cf02b2c1455
permissions -rw-r--r--
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds Summary: add top level cds directory and adjust test groups Reviewed-by: mseledtsov, ccheung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     1
/*
57567
b000362a89a0 8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents: 52596
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     4
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     8
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    13
 * accompanied this code).
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    14
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    18
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    21
 * questions.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    22
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    23
 */
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    24
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    25
/*
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    26
 * @test
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    27
 * @summary When dumping the CDS archive, try to load VM anonymous classes to make sure they
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    28
 *          are handled properly. Note: these are not "anonymous inner classes" in the Java source code,
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    29
 *          but rather classes that are not recorded in any ClassLoaderData::dictionary(),
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    30
 *          such as classes that are generated for Lambda expressions.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    31
 *          See https://blogs.oracle.com/jrose/anonymous-classes-in-the-vm.
57567
b000362a89a0 8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents: 52596
diff changeset
    32
 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    33
 * @requires vm.cds
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    34
 * @requires vm.flavor != "minimal"
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    35
 * @modules java.base/jdk.internal.misc
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    36
 *          jdk.jartool/sun.tools.jar
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    37
 *          java.management
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    38
 * @build AnonVmClassesDuringDumpTransformer Hello
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    39
 * @run main/othervm AnonVmClassesDuringDump
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    40
 */
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    41
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    42
public class AnonVmClassesDuringDump {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    43
    public static String appClasses[] = {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    44
        "Hello",
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    45
    };
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    46
    public static String agentClasses[] = {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    47
        "AnonVmClassesDuringDumpTransformer",
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    48
    };
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    49
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 49894
diff changeset
    50
    public static String cdsDiagnosticOption = "-XX:+AllowArchivingWithJavaAgent";
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 49894
diff changeset
    51
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    52
    public static void main(String[] args) throws Throwable {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    53
        String agentJar =
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    54
            ClassFileInstaller.writeJar("AnonVmClassesDuringDumpTransformer.jar",
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    55
                                        ClassFileInstaller.Manifest.fromSourceFile("AnonVmClassesDuringDumpTransformer.mf"),
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    56
                                        agentClasses);
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    57
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    58
        String appJar =
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    59
            ClassFileInstaller.writeJar("AnonVmClassesDuringDumpApp.jar", appClasses);
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    60
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    61
        TestCommon.testDump(appJar, TestCommon.list("Hello"),
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    62
                            "-javaagent:" + agentJar,
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 49894
diff changeset
    63
                            "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    64
                            // Set the following property to see logs for dynamically generated classes
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    65
                            // in STDOUT
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    66
                            "-Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true");
49894
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    67
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    68
        String prefix = ".class.load. ";
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    69
        // class name pattern like the following:
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    70
        // jdk.internal.loader.BuiltinClassLoader$$Lambda$1/1816757085
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    71
        // java.lang.invoke.LambdaForm$MH/1585787493
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    72
        String class_pattern = ".*Lambda([a-z0-9$]+)/([0-9]+).*";
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    73
        String suffix = ".*source: shared objects file.*";
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    74
        String pattern = prefix + class_pattern + suffix;
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    75
        // during run time, anonymous classes shouldn't be loaded from the archive
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 49894
diff changeset
    76
        TestCommon.run("-cp", appJar,
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 49894
diff changeset
    77
            "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption, "Hello")
49894
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    78
            .assertNormalExit(output -> output.shouldNotMatch(pattern));
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    79
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    80
        // inspect the archive and make sure no anonymous class is in there
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    81
        TestCommon.run("-cp", appJar,
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents: 49894
diff changeset
    82
            "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
49894
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    83
            "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary", "Hello")
c830e94b5606 8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents: 49352
diff changeset
    84
            .assertNormalExit(output -> output.shouldNotMatch(class_pattern));
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    85
    }
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    86
}
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    87