author | jiefu |
Wed, 06 Nov 2019 13:43:25 +0800 | |
changeset 58944 | bb2a436e616c |
parent 57705 | 7cf02b2c1455 |
child 58679 | 9c3209ff7550 |
child 59129 | d8eddc0ba770 |
permissions | -rw-r--r-- |
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 |
* @build AnonVmClassesDuringDumpTransformer Hello |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
36 |
* @run main/othervm AnonVmClassesDuringDump |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
37 |
*/ |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
38 |
|
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
39 |
public class AnonVmClassesDuringDump { |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
40 |
public static String appClasses[] = { |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
41 |
"Hello", |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
42 |
}; |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
43 |
public static String agentClasses[] = { |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
44 |
"AnonVmClassesDuringDumpTransformer", |
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 |
|
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
|
47 |
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
|
48 |
|
49352
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
49 |
public static void main(String[] args) throws Throwable { |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
50 |
String agentJar = |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
51 |
ClassFileInstaller.writeJar("AnonVmClassesDuringDumpTransformer.jar", |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
52 |
ClassFileInstaller.Manifest.fromSourceFile("AnonVmClassesDuringDumpTransformer.mf"), |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
53 |
agentClasses); |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
54 |
|
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
55 |
String appJar = |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
56 |
ClassFileInstaller.writeJar("AnonVmClassesDuringDumpApp.jar", appClasses); |
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 |
TestCommon.testDump(appJar, TestCommon.list("Hello"), |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
59 |
"-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
|
60 |
"-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption, |
49352
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 |
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
|
73 |
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
|
74 |
"-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
|
75 |
.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
|
76 |
|
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 |
// 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
|
78 |
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
|
79 |
"-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
|
80 |
"-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
|
81 |
.assertNormalExit(output -> output.shouldNotMatch(class_pattern)); |
49352
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
82 |
} |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
83 |
} |
0b48f0aa79ec
8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff
changeset
|
84 |