Skip to content

Commit

Permalink
@dholmes-ora comment
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinccheung committed Nov 21, 2024
1 parent 96b7945 commit 9b2b655
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
24 changes: 7 additions & 17 deletions src/hotspot/share/cds/filemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,30 +2705,20 @@ ClassFileStream* FileMapInfo::get_stream_from_class_loader(Handle class_loader,
JavaCalls::call_virtual(&result,
class_loader,
vmClasses::ClassLoader_klass(),
vmSymbols::getResourceAsStream_name(),
vmSymbols::getResourceAsStream_signature(),
vmSymbols::getResourceAsByteArray_name(),
vmSymbols::getResourceAsByteArray_signature(),
ext_class_name,
CHECK_NULL);
assert(result.get_type() == T_OBJECT, "just checking");
oop obj = result.get_oop();
assert(obj != nullptr, "ClassLoader::getResourceAsStream should not return null");

Handle input_stream = Handle(THREAD, obj);
JavaValue res(T_OBJECT);
// byte[] InputStream.readAllBytes()
JavaCalls::call_virtual(&res,
input_stream,
vmClasses::InputStream_klass(),
vmSymbols::readAllBytes(),
vmSymbols::void_byte_array_signature(),
CHECK_NULL);
assert(obj != nullptr, "ClassLoader.getResourceAsStream should not return null");

// The result should be a [B
oop res_oop = res.get_oop();
assert(res_oop->is_typeArray(), "just checking");
assert(TypeArrayKlass::cast(res_oop->klass())->element_type() == T_BYTE, "just checking");
assert(obj->is_typeArray(), "just checking");
assert(TypeArrayKlass::cast(obj->klass())->element_type() == T_BYTE, "just checking");

// copy from byte[] to a buffer
typeArrayOop ba = typeArrayOop(res_oop);
typeArrayOop ba = typeArrayOop(obj);
jint len = ba->length();
u1* buffer = NEW_RESOURCE_ARRAY(u1, len);
ArrayAccess<>::arraycopy_to_native<>(ba, typeArrayOopDesc::element_offset<jbyte>(0), buffer, len);
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/classfile/vmClassMacros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
do_klass(CodeSource_klass, java_security_CodeSource ) \
do_klass(ConcurrentHashMap_klass, java_util_concurrent_ConcurrentHashMap ) \
do_klass(ArrayList_klass, java_util_ArrayList ) \
do_klass(InputStream_klass, java_io_InputStream ) \
\
do_klass(StackTraceElement_klass, java_lang_StackTraceElement ) \
\
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/share/classfile/vmSymbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class SerializeClosure;
template(java_net_URLClassLoader, "java/net/URLClassLoader") \
template(java_util_jar_Manifest, "java/util/jar/Manifest") \
template(java_io_ByteArrayInputStream, "java/io/ByteArrayInputStream") \
template(java_io_InputStream, "java/io/InputStream") \
template(java_io_Serializable, "java/io/Serializable") \
template(java_nio_Buffer, "java/nio/Buffer") \
template(java_util_Arrays, "java/util/Arrays") \
Expand Down Expand Up @@ -724,8 +723,8 @@ class SerializeClosure;
template(dumpSharedArchive_signature, "(ZLjava/lang/String;)Ljava/lang/String;") \
template(generateLambdaFormHolderClasses, "generateLambdaFormHolderClasses") \
template(generateLambdaFormHolderClasses_signature, "([Ljava/lang/String;)[Ljava/lang/Object;") \
template(getResourceAsStream_name, "getResourceAsStream") \
template(getResourceAsStream_signature, "(Ljava/lang/String;)Ljava/io/InputStream;") \
template(getResourceAsByteArray_name, "getResourceAsByteArray") \
template(getResourceAsByteArray_signature, "(Ljava/lang/String;)[B") \
template(java_lang_Enum, "java/lang/Enum") \
template(java_lang_invoke_Invokers_Holder, "java/lang/invoke/Invokers$Holder") \
template(java_lang_invoke_DirectMethodHandle_Holder, "java/lang/invoke/DirectMethodHandle$Holder") \
Expand All @@ -735,7 +734,6 @@ class SerializeClosure;
template(jdk_internal_misc_CDS, "jdk/internal/misc/CDS") \
template(java_util_concurrent_ConcurrentHashMap, "java/util/concurrent/ConcurrentHashMap") \
template(java_util_ArrayList, "java/util/ArrayList") \
template(readAllBytes, "readAllBytes") \
template(runtimeSetup, "runtimeSetup") \
template(toFileURL_name, "toFileURL") \
template(toFileURL_signature, "(Ljava/lang/String;)Ljava/net/URL;") \
Expand Down
13 changes: 13 additions & 0 deletions src/java.base/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,19 @@ public InputStream getResourceAsStream(String name) {
}
}

/**
* Called by VM for constructing a ClassFileStream.
*/
private byte[] getResourceAsByteArray(String name) {
Objects.requireNonNull(name);
InputStream is = getResourceAsStream(name);
try {
return is != null ? is.readAllBytes() : null;
} catch (IOException e) {
return null;
}
}

/**
* Open for reading, a resource of the specified name from the search path
* used to load classes. This method locates the resource through the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,48 @@ public class MultiReleaseJars {
static final int MAJOR_VERSION = Runtime.version().major();
static final String MAJOR_VERSION_STRING = String.valueOf(MAJOR_VERSION);

static String[] getMain() {
String[] sts = {
"public class Main {",
" public static void main(String[] args) throws Exception {",
" System.out.println(Class.forName(\"Foo\"));",
" System.out.println(Class.forName(\"Bar\"));",
" }",
"}"
};
static String getMain() {
String sts = """
public class Main {
public static void main(String[] args) throws Exception {
System.out.println(Class.forName(\"Foo\"));
System.out.println(Class.forName(\"Bar\"));
}
}
""";
return sts;
}

static String[] getFoo() {
String[] sts = {
"class Foo {",
" static {",
" System.out.println(\"Hello from Foo old version \");",
" }",
"}",
};
static String getFoo() {
String sts = """
class Foo {
static {
System.out.println("Hello from Foo old version");
}
}
""";
return sts;
}

static String[] getFooNewVersion() {
String[] sts = {
"class Foo {",
" static {",
" System.out.println(\"Hello from Foo new version \");",
" }",
"}",
};
static String getFooNewVersion() {
String sts = """
class Foo {
static {
System.out.println("Hello from Foo new version");
}
}
""";
return sts;
}

static String[] getBar() {
String[] sts = {
"class Bar {",
" static {",
" System.out.println(\"Hello from Bar\");",
" }",
"}",
};
static String getBar() {
String sts = """
class Bar {
static {
System.out.println("Hello from Bar");
}
}
""";
return sts;
}

Expand Down

0 comments on commit 9b2b655

Please sign in to comment.