Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit b5c5079

Browse files
committed
8261860: Crash caused by lambda proxy class loaded in Shutdown hook
Reviewed-by: minqi, iklam
1 parent b5ea908 commit b5c5079

File tree

3 files changed

+138
-1
lines changed

3 files changed

+138
-1
lines changed

src/hotspot/share/classfile/systemDictionaryShared.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,9 @@ void SystemDictionaryShared::add_lambda_proxy_class(InstanceKlass* caller_ik,
16251625
InstanceKlass* nest_host = caller_ik->nest_host(THREAD);
16261626

16271627
DumpTimeSharedClassInfo* info = _dumptime_table->get(lambda_ik);
1628-
if (info != NULL && !lambda_ik->is_non_strong_hidden() && is_builtin(lambda_ik) && is_builtin(caller_ik)) {
1628+
if (info != NULL && !lambda_ik->is_non_strong_hidden() && is_builtin(lambda_ik) && is_builtin(caller_ik)
1629+
// Don't include the lambda proxy if its nest host is not in the "linked" state.
1630+
&& nest_host->is_linked()) {
16291631
// Set _is_archived_lambda_proxy in DumpTimeSharedClassInfo so that the lambda_ik
16301632
// won't be excluded during dumping of shared archive. See ExcludeDumpTimeSharedClasses.
16311633
info->_is_archived_lambda_proxy = true;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2021, 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+
* @bug 8261860
28+
* @summary VM should not crash if a lambda proxy class is created during
29+
* shutdown and its nest host is not linked.
30+
* @requires vm.cds
31+
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
32+
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
33+
* @build LambdaProxyDuringShutdownApp sun.hotspot.WhiteBox LambdaVerification
34+
* @run driver ClassFileInstaller -jar lambda_proxy_shutdown.jar LambdaVerification
35+
* LambdaProxyDuringShutdownApp MyShutdown Outer Outer$Inner
36+
* @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
37+
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
38+
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. LambdaProxyDuringShutdown
39+
*/
40+
41+
public class LambdaProxyDuringShutdown extends DynamicArchiveTestBase {
42+
public static void main(String[] args) throws Exception {
43+
runTest(LambdaProxyDuringShutdown::test);
44+
}
45+
46+
static void test() throws Exception {
47+
String topArchiveName = getNewArchiveName();
48+
String appJar = ClassFileInstaller.getJarPath("lambda_proxy_shutdown.jar");
49+
String mainClass = "LambdaProxyDuringShutdownApp";
50+
String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar");
51+
String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
52+
String appOutput = "Hello from Inner";
53+
54+
dump(topArchiveName,
55+
"-XX:+UnlockDiagnosticVMOptions",
56+
"-XX:+WhiteBoxAPI",
57+
"-Xlog:class+load=debug,cds=debug,cds+dynamic=info",
58+
use_whitebox_jar,
59+
"-cp", appJar, mainClass)
60+
.assertNormalExit(output -> {
61+
// Nest host should be skipped since it is not in the linked state.
62+
output.shouldContain("Skipping Outer: Not linked")
63+
// Lambda proxy is loaded normally.
64+
.shouldMatch("class.load.*Outer[$]Inner[$][$]Lambda[$].*0x.*source:.Outer")
65+
.shouldContain(appOutput)
66+
.shouldHaveExitValue(0);
67+
});
68+
69+
run(topArchiveName,
70+
"-XX:+UnlockDiagnosticVMOptions",
71+
"-XX:+WhiteBoxAPI",
72+
use_whitebox_jar,
73+
"-Xlog:class+load=debug",
74+
"-cp", appJar, mainClass, "run")
75+
.assertNormalExit(output -> {
76+
// Only the Inner class is loaded from the dynamic archive.
77+
// The nest host (Outer) and its lambda proxy are not loaded
78+
// from the dynamic archive.
79+
output.shouldMatch("class.load.*Outer.source:.*lambda_proxy_shutdown.jar")
80+
.shouldMatch("class.load.*Outer[$]Inner[$][$]Lambda[$].*0x.*source:.Outer")
81+
.shouldMatch("class.load. Outer[$]Inner.source:.*shared.*objects.*file.*(top)")
82+
.shouldContain(appOutput)
83+
.shouldHaveExitValue(0);
84+
});
85+
}
86+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2021, 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+
class Outer{
25+
static final class Inner{
26+
static {
27+
doit(() -> {
28+
System.out.println("Hello from Inner");
29+
});
30+
}
31+
static void doit(Runnable t) {
32+
t.run();
33+
}
34+
}
35+
}
36+
37+
class MyShutdown extends Thread {
38+
public void run() {
39+
Outer.Inner inner = new Outer.Inner();
40+
}
41+
}
42+
43+
public class LambdaProxyDuringShutdownApp {
44+
public static void main(String[] args) throws Exception {
45+
Runtime r = Runtime.getRuntime();
46+
r.addShutdownHook(new MyShutdown());
47+
System.exit(0);
48+
}
49+
}

0 commit comments

Comments
 (0)