Skip to content

Commit 88e0b00

Browse files
committed
8353298: AOT cache creation asserts with _array_klasses in an unregistered InstanceKlass
Reviewed-by: ccheung, kvn
1 parent adcaf01 commit 88e0b00

File tree

2 files changed

+116
-2
lines changed

2 files changed

+116
-2
lines changed

src/hotspot/share/oops/klass.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,14 @@ void Klass::remove_java_mirror() {
830830
oop orig_mirror = src_k->java_mirror();
831831
if (orig_mirror == nullptr) {
832832
assert(CDSConfig::is_dumping_final_static_archive(), "sanity");
833-
assert(is_instance_klass(), "sanity");
834-
assert(InstanceKlass::cast(this)->is_shared_unregistered_class(), "sanity");
833+
if (is_instance_klass()) {
834+
assert(InstanceKlass::cast(this)->is_shared_unregistered_class(), "sanity");
835+
} else {
836+
precond(is_objArray_klass());
837+
Klass *k = ObjArrayKlass::cast(this)->bottom_klass();
838+
precond(k->is_instance_klass());
839+
assert(InstanceKlass::cast(k)->is_shared_unregistered_class(), "sanity");
840+
}
835841
} else {
836842
oop scratch_mirror = HeapShared::scratch_java_mirror(orig_mirror);
837843
if (scratch_mirror != nullptr) {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2025, 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+
* @summary Test AOT cache support for array classes in custom class loaders.
28+
* @bug 8353298
29+
* @requires vm.cds.supports.aot.class.linking
30+
* @comment work around JDK-8345635
31+
* @requires !vm.jvmci.enabled
32+
* @library /test/lib
33+
* @build AOTCacheSupportForCustomLoaders
34+
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar AppWithCustomLoaders AppWithCustomLoaders$MyLoader
35+
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar cust.jar AppWithCustomLoaders$MyLoadeeA AppWithCustomLoaders$MyLoadeeB
36+
* @run driver AOTCacheSupportForCustomLoaders AOT
37+
*/
38+
39+
import java.net.URL;
40+
import java.net.URLClassLoader;
41+
import java.io.File;
42+
import jdk.test.lib.cds.SimpleCDSAppTester;
43+
import jdk.test.lib.process.OutputAnalyzer;
44+
45+
public class AOTCacheSupportForCustomLoaders {
46+
public static void main(String... args) throws Exception {
47+
SimpleCDSAppTester.of("AOTCacheSupportForCustomLoaders")
48+
.classpath("app.jar")
49+
.addVmArgs("-Xlog:cds+class=debug", "-Xlog:cds")
50+
.appCommandLine("AppWithCustomLoaders")
51+
.setAssemblyChecker((OutputAnalyzer out) -> {
52+
out.shouldMatch("cds,class.*unreg AppWithCustomLoaders[$]MyLoadeeA")
53+
.shouldMatch("cds,class.*array \\[LAppWithCustomLoaders[$]MyLoadeeA;");
54+
})
55+
.setProductionChecker((OutputAnalyzer out) -> {
56+
out.shouldContain("Using AOT-linked classes: true");
57+
})
58+
.runAOTWorkflow();
59+
}
60+
}
61+
62+
class AppWithCustomLoaders {
63+
public static void main(String args[]) throws Exception {
64+
File custJar = new File("cust.jar");
65+
URL[] urls = new URL[] {custJar.toURI().toURL()};
66+
MyLoader loader = new MyLoader(urls, AppWithCustomLoaders.class.getClassLoader());
67+
68+
// Test 1: array class of MyLoadeeA (JDK-8353298)
69+
Class klass = loader.loadClass("AppWithCustomLoaders$MyLoadeeA");
70+
klass.newInstance();
71+
72+
// TODO: more test cases JDK-8354557
73+
}
74+
75+
public static class MyLoader extends URLClassLoader {
76+
public MyLoader(URL[] urls, ClassLoader parent) {
77+
super(urls, parent);
78+
}
79+
}
80+
81+
public static class MyLoadeeA {
82+
static Object[] array1;
83+
84+
public MyLoadeeA() {
85+
if (array1 == null) {
86+
test();
87+
Object o = array1[0];
88+
System.out.println("array1[0] is of class: " + o.getClass());
89+
if (!(o instanceof MyLoadeeA)) {
90+
throw new RuntimeException("array1[0] should be an instanceof MyLoadeeA");
91+
}
92+
}
93+
}
94+
95+
static void test() {
96+
array1 = new MyLoadeeA[10];
97+
for (int i = 0; i < 10; i++) {
98+
if ((i % 2) == 0) {
99+
array1[i] = new MyLoadeeB();
100+
} else {
101+
array1[i] = new MyLoadeeA();
102+
}
103+
}
104+
}
105+
}
106+
107+
public static class MyLoadeeB extends MyLoadeeA {}
108+
}

0 commit comments

Comments
 (0)