Skip to content

Commit 02fbcb5

Browse files
committed
8261532: Archived superinterface class cannot be accessed
Reviewed-by: minqi, iklam
1 parent 109af7b commit 02fbcb5

File tree

6 files changed

+183
-3
lines changed

6 files changed

+183
-3
lines changed

src/hotspot/share/classfile/systemDictionaryShared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ InstanceKlass* SystemDictionaryShared::prepare_shared_lambda_proxy_class(Instanc
16771677
InstanceKlass* caller_ik, TRAPS) {
16781678
Handle class_loader(THREAD, caller_ik->class_loader());
16791679
Handle protection_domain;
1680-
PackageEntry* pkg_entry = get_package_entry_from_class(caller_ik, class_loader);
1680+
PackageEntry* pkg_entry = caller_ik->package();
16811681
if (caller_ik->class_loader() != NULL) {
16821682
protection_domain = SystemDictionaryShared::init_security_info(class_loader, caller_ik, pkg_entry, CHECK_NULL);
16831683
}

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,9 +2857,10 @@ void InstanceKlass::set_package(ClassLoaderData* loader_data, PackageEntry* pkg_
28572857
check_prohibited_package(name(), loader_data, CHECK);
28582858
}
28592859

2860-
if (is_shared() && _package_entry == pkg_entry) {
2861-
if (MetaspaceShared::use_full_module_graph()) {
2860+
if (is_shared() && _package_entry != NULL) {
2861+
if (MetaspaceShared::use_full_module_graph() && _package_entry == pkg_entry) {
28622862
// we can use the saved package
2863+
assert(MetaspaceShared::is_in_shared_metaspace(_package_entry), "must be");
28632864
return;
28642865
} else {
28652866
_package_entry = NULL;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 8261532
28+
* @summary An archived super interface should be accessible by the class which
29+
* implements the interface during runtime although the class itself
30+
* is not in the CDS archive.
31+
* @requires vm.cds
32+
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
33+
* /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
34+
* @build sun.hotspot.WhiteBox ArchivedSuperIfApp Bar Baz
35+
* @run driver ClassFileInstaller -jar archived_super_if.jar pkg.ArchivedSuperIfApp pkg.Bar pkg.Baz
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:. ArchivedSuperIf
39+
*/
40+
41+
public class ArchivedSuperIf extends DynamicArchiveTestBase {
42+
public static void main(String[] args) throws Exception {
43+
runTest(ArchivedSuperIf::test);
44+
}
45+
46+
static void test() throws Exception {
47+
String topArchiveName = getNewArchiveName();
48+
String appJar = ClassFileInstaller.getJarPath("archived_super_if.jar");
49+
String mainClass = "pkg.ArchivedSuperIfApp";
50+
String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar");
51+
String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
52+
53+
dump(topArchiveName,
54+
"-XX:+UnlockDiagnosticVMOptions",
55+
"-XX:+WhiteBoxAPI",
56+
"-Xlog:class+load=debug,cds+dynamic=info",
57+
use_whitebox_jar,
58+
"-cp", appJar, mainClass)
59+
.assertNormalExit(output -> {
60+
// Only the inteface Bar is loaded during dump time.
61+
output.shouldMatch(".class.load. pkg.Bar source:.*archived_super_if.jar")
62+
.shouldNotMatch(".class.load. pkg.Baz source:.*archived_super_if.jar")
63+
.shouldHaveExitValue(0);
64+
});
65+
66+
run(topArchiveName,
67+
"-XX:+UnlockDiagnosticVMOptions",
68+
"-XX:+WhiteBoxAPI",
69+
use_whitebox_jar,
70+
"-Xlog:class+load=debug",
71+
"-cp", appJar, mainClass, "Baz")
72+
.assertNormalExit(output -> {
73+
// The interface Bar will be loaded from the archive.
74+
// The class (Baz) which implements Bar will be loaded from jar.
75+
output.shouldContain("[class,load] pkg.Bar source: shared objects file (top)")
76+
.shouldMatch(".class.load. pkg.Baz source:.*archived_super_if.jar")
77+
.shouldHaveExitValue(0);
78+
});
79+
}
80+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
package pkg;
25+
26+
public class ArchivedSuperIfApp {
27+
28+
public static void main(String ... args) throws Exception {
29+
Class.forName("pkg.Bar");
30+
System.out.println(Bar.class.getName());
31+
if (args.length > 0 && args[0].equals("Baz")) {
32+
Class.forName("pkg.Baz");
33+
34+
Baz baz = new Baz();
35+
baz.foo();
36+
System.out.println(Baz.class.getName());
37+
}
38+
}
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
package pkg;
25+
26+
interface Bar {
27+
28+
void foo();
29+
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
package pkg;
25+
26+
class Baz implements Bar {
27+
28+
public void foo() { System.out.println("OK"); }
29+
30+
}

0 commit comments

Comments
 (0)