test/hotspot/jtreg/runtime/appcds/javaldr/AnonVmClassesDuringDump.java
author jiangli
Mon, 21 May 2018 15:15:58 -0400
changeset 50199 83d8b3a25f25
parent 49894 c830e94b5606
child 52596 dfa02b3f728c
permissions -rw-r--r--
8199807: AppCDS performs overly restrictive path matching check. 8203377: Cleanup the usage of os::file_name_strcmp() in SharedPathsMiscInfo::check(). Summary: Relax CDS/AppCDS path check for modules image. Reviewed-by: iklam, 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
/*
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
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.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    32
 * @library /test/lib /test/hotspot/jtreg/runtime/appcds /test/hotspot/jtreg/runtime/appcds/test-classes
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
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    50
    public static void main(String[] args) throws Throwable {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    51
        String agentJar =
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    52
            ClassFileInstaller.writeJar("AnonVmClassesDuringDumpTransformer.jar",
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    53
                                        ClassFileInstaller.Manifest.fromSourceFile("AnonVmClassesDuringDumpTransformer.mf"),
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    54
                                        agentClasses);
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    55
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    56
        String appJar =
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    57
            ClassFileInstaller.writeJar("AnonVmClassesDuringDumpApp.jar", appClasses);
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    58
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    59
        TestCommon.testDump(appJar, TestCommon.list("Hello"),
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    60
                            "-javaagent:" + agentJar,
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    61
                            // 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
    62
                            // in STDOUT
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    63
                            "-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
    64
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
    65
        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
    66
        // 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
    67
        // 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
    68
        // 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
    69
        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
    70
        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
    71
        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
    72
        // during run time, anonymous classes shouldn't be loaded from the archive
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    73
        TestCommon.run("-cp", appJar, "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
    74
            .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
    75
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
    76
        // 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
    77
        TestCommon.run("-cp", appJar,
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
            "-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
    79
            .assertNormalExit(output -> output.shouldNotMatch(class_pattern));
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    80
    }
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    81
}
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    82