Skip to content

Commit 1ece4f9

Browse files
committed
8345514: Should use internal class name when calling ClassLoader.getResourceAsByteArray
Reviewed-by: iklam, matsaave
1 parent ef8da28 commit 1ece4f9

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/hotspot/share/cds/filemap.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,16 +2731,16 @@ ClassFileStream* FileMapInfo::get_stream_from_class_loader(Handle class_loader,
27312731
const char* file_name,
27322732
TRAPS) {
27332733
JavaValue result(T_OBJECT);
2734-
TempNewSymbol class_name_sym = SymbolTable::new_symbol(file_name);
2735-
Handle ext_class_name = java_lang_String::externalize_classname(class_name_sym, CHECK_NULL);
2734+
oop class_name = java_lang_String::create_oop_from_str(file_name, THREAD);
2735+
Handle h_class_name = Handle(THREAD, class_name);
27362736

27372737
// byte[] ClassLoader.getResourceAsByteArray(String name)
27382738
JavaCalls::call_virtual(&result,
27392739
class_loader,
27402740
vmClasses::ClassLoader_klass(),
27412741
vmSymbols::getResourceAsByteArray_name(),
27422742
vmSymbols::getResourceAsByteArray_signature(),
2743-
ext_class_name,
2743+
h_class_name,
27442744
CHECK_NULL);
27452745
assert(result.get_type() == T_OBJECT, "just checking");
27462746
oop obj = result.get_oop();

test/hotspot/jtreg/runtime/cds/appcds/jvmti/CFLH/MultiReleaseJars.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ static String getMain() {
4949
String sts = """
5050
public class Main {
5151
public static void main(String[] args) throws Exception {
52-
System.out.println(Class.forName(\"Foo\"));
53-
System.out.println(Class.forName(\"Bar\"));
52+
System.out.println(Class.forName("pkg1.Foo"));
53+
System.out.println(Class.forName("pkg2.Bar"));
5454
}
5555
}
5656
""";
@@ -59,6 +59,7 @@ public static void main(String[] args) throws Exception {
5959

6060
static String getFoo() {
6161
String sts = """
62+
package pkg1;
6263
class Foo {
6364
static {
6465
System.out.println("Hello from Foo old version");
@@ -70,6 +71,7 @@ class Foo {
7071

7172
static String getFooNewVersion() {
7273
String sts = """
74+
package pkg1;
7375
class Foo {
7476
static {
7577
System.out.println("Hello from Foo new version");
@@ -81,6 +83,7 @@ class Foo {
8183

8284
static String getBar() {
8385
String sts = """
86+
package pkg2;
8487
class Bar {
8588
static {
8689
System.out.println("Hello from Bar");
@@ -107,13 +110,17 @@ static void writeFile(File file, String... contents) throws Exception {
107110
/* version.jar entries and files:
108111
* META-INF/
109112
* META-INF/MANIFEST.MF
110-
* Bar.class
111113
* Main.class
114+
* pkg2/
115+
* pkg2/Bar.class
112116
* META-INF/versions/9/
113-
* META-INF/versions/9/Bar.class
114-
* META-INF/versions/9/Foo.class
117+
* META-INF/versions/9/pkg1
118+
* META-INF/versions/9/pkg1/Foo.class
119+
* META-INF/versions/9/pkg2
120+
* META-INF/versions/9/pkg2/Bar.class
115121
* META-INF/versions/24/
116-
* META-INF/versions/24/Foo.class
122+
* META-INF/versions/24/pkg1
123+
* META-INF/versions/24/pkg1Foo.class
117124
*/
118125
static void createClassFilesAndJar() throws Exception {
119126
String tempDir = CDSTestUtils.getOutputDir();
@@ -163,25 +170,25 @@ public static void main(String... args) throws Exception {
163170

164171
String mainClass = "Main";
165172
String appJar = TestCommon.getTestJar("multi-version.jar");
166-
String appClasses[] = {"Foo", "Bar"};
173+
String appClasses[] = {"pkg1/Foo", "pkg2/Bar"};
167174

168175
OutputAnalyzer output = TestCommon.dump(appJar, appClasses);
169176
output.shouldContain("Loading classes to share: done.")
170177
.shouldHaveExitValue(0);
171178

172-
String agentCmdArg = "-agentlib:SimpleClassFileLoadHook=Foo,Hello,HELLO";
179+
String agentCmdArg = "-agentlib:SimpleClassFileLoadHook=pkg1/Foo,Hello,HELLO";
173180
output = TestCommon.execAuto("-cp", appJar,
174181
"-Xlog:cds=info,class+load",
175182
agentCmdArg,
176183
mainClass);
177184

178-
output.shouldMatch(".*Foo.source:.*multi-version.jar")
185+
output.shouldMatch(".*pkg1.Foo.source:.*multi-version.jar")
179186
// New version of Foo is loaded from jar since it was modified by CFLH
180187
.shouldContain("HELLO from Foo new version") // CFLH changed "Hello" to "HELLO"
181-
.shouldContain("class Foo") // output from Main
188+
.shouldContain("class pkg1.Foo") // output from Main
182189
// Bar is loaded from archive
183190
.shouldContain("Bar source: shared objects file")
184191
.shouldContain("Hello from Bar")
185-
.shouldContain("class Bar"); // output from Main
192+
.shouldContain("class pkg2.Bar"); // output from Main
186193
}
187194
}

0 commit comments

Comments
 (0)