Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.
/ jdk22 Public archive

Commit ee4d54c

Browse files
committed
8323950: Null CLD while loading shared lambda proxy class with javaagent active
Reviewed-by: dholmes Backport-of: d51aaf6304e0dd1cde4a85bf6a822332f56c0ff2
1 parent 306e364 commit ee4d54c

File tree

3 files changed

+119
-6
lines changed

3 files changed

+119
-6
lines changed

src/hotspot/share/classfile/systemDictionary.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1111,14 +1111,13 @@ InstanceKlass* SystemDictionary::load_shared_lambda_proxy_class(InstanceKlass* i
11111111
if (loaded_ik != nullptr) {
11121112
assert(shared_nest_host->is_same_class_package(ik),
11131113
"lambda proxy class and its nest host must be in the same package");
1114+
// The lambda proxy class and its nest host have the same class loader and class loader data,
1115+
// as verified in SystemDictionaryShared::add_lambda_proxy_class()
1116+
assert(shared_nest_host->class_loader() == class_loader(), "mismatched class loader");
1117+
assert(shared_nest_host->class_loader_data() == class_loader_data(class_loader), "mismatched class loader data");
1118+
ik->set_nest_host(shared_nest_host);
11141119
}
11151120

1116-
// The lambda proxy class and its nest host have the same class loader and class loader data,
1117-
// as verified in SystemDictionaryShared::add_lambda_proxy_class()
1118-
assert(shared_nest_host->class_loader() == class_loader(), "mismatched class loader");
1119-
assert(shared_nest_host->class_loader_data() == class_loader_data(class_loader), "mismatched class loader data");
1120-
ik->set_nest_host(shared_nest_host);
1121-
11221121
return loaded_ik;
11231122
}
11241123

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2024, 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 8323950
28+
* @summary Transforming an interface of an archived lambda proxy class should not
29+
* crash the VM. The lambda proxy class should be regenerated during runtime.
30+
* @requires vm.cds
31+
* @requires vm.jvmti
32+
* @requires vm.flagless
33+
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
34+
* @compile test-classes/SimpleTest.java
35+
* @compile test-classes/TransformBootClass.java
36+
* @run driver TransformInterfaceOfLambda
37+
*/
38+
39+
import jdk.test.lib.process.OutputAnalyzer;
40+
import jdk.test.lib.process.ProcessTools;
41+
import jdk.test.lib.helpers.ClassFileInstaller;
42+
43+
public class TransformInterfaceOfLambda {
44+
45+
public static String agentClasses[] = {
46+
TransformBootClass.class.getName(),
47+
};
48+
49+
public static void main(String[] args) throws Exception {
50+
String mainClass = SimpleTest.class.getName();
51+
String namePrefix = "transform-interface-of-lambda";
52+
JarBuilder.build(namePrefix, mainClass);
53+
54+
String appJar = TestCommon.getTestJar(namePrefix + ".jar");
55+
56+
String agentJar =
57+
ClassFileInstaller.writeJar("TransformBootClass.jar",
58+
ClassFileInstaller.Manifest.fromSourceFile("test-classes/TransformBootClass.mf"),
59+
agentClasses);
60+
String useJavaAgent = "-javaagent:" + agentJar + "=java/util/function/IntFunction";
61+
62+
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
63+
"-cp", appJar, "-Xlog:class+load,cds=debug",
64+
"-XX:+UnlockDiagnosticVMOptions",
65+
"-XX:+AllowArchivingWithJavaAgent",
66+
useJavaAgent,
67+
mainClass);
68+
OutputAnalyzer out = new OutputAnalyzer(pb.start());
69+
System.out.println(out.getStdout());
70+
out.shouldHaveExitValue(0)
71+
// the class loaded by the SimpleTest should be from the archive
72+
.shouldContain("[class,load] java.text.SimpleDateFormat source: shared objects file")
73+
// the IntFunction is the interface which is being transformed. The
74+
// interface is a super type of the following lambda proxy class.
75+
.shouldContain("Transforming class java/util/function/IntFunction")
76+
// the lambda proxy class should be regenerated
77+
.shouldMatch(".class.load.*sun.util.locale.provider.LocaleProviderAdapter[$][$]Lambda/0x.*source:.*sun.util.locale.provider.LocaleProviderAdapter");
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2024, 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+
* Loading the java.text.SimpleDateFormat class will in turn load the
27+
* sun.util.locale.provider.LocaleProviderAdapter$$Lambda/0x... lambda proxy class
28+
* which will also load its interface java.util.function.IntFunction.
29+
* By default, all of the above classes should be in the default CDS archive.
30+
*/
31+
public class SimpleTest {
32+
public static void main(String[] args) throws Exception {
33+
new java.text.SimpleDateFormat();
34+
}
35+
}

0 commit comments

Comments
 (0)