diff --git a/src/hotspot/share/cds/filemap.cpp b/src/hotspot/share/cds/filemap.cpp index f78e910585ac7..cf11877981dd9 100644 --- a/src/hotspot/share/cds/filemap.cpp +++ b/src/hotspot/share/cds/filemap.cpp @@ -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(0), buffer, len); diff --git a/src/hotspot/share/classfile/vmClassMacros.hpp b/src/hotspot/share/classfile/vmClassMacros.hpp index 07fe6b0e2356f..395034d4a21a6 100644 --- a/src/hotspot/share/classfile/vmClassMacros.hpp +++ b/src/hotspot/share/classfile/vmClassMacros.hpp @@ -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 ) \ \ diff --git a/src/hotspot/share/classfile/vmSymbols.hpp b/src/hotspot/share/classfile/vmSymbols.hpp index ec44e8e9c95cd..386d7f24105d9 100644 --- a/src/hotspot/share/classfile/vmSymbols.hpp +++ b/src/hotspot/share/classfile/vmSymbols.hpp @@ -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") \ @@ -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") \ @@ -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;") \ diff --git a/src/java.base/share/classes/java/lang/ClassLoader.java b/src/java.base/share/classes/java/lang/ClassLoader.java index 55341635d8af9..a4aa01b067060 100644 --- a/src/java.base/share/classes/java/lang/ClassLoader.java +++ b/src/java.base/share/classes/java/lang/ClassLoader.java @@ -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 diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jvmti/CFLH/MultiReleaseJars.java b/test/hotspot/jtreg/runtime/cds/appcds/jvmti/CFLH/MultiReleaseJars.java index d5c2ebd3f089c..92c5e3d5f022c 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jvmti/CFLH/MultiReleaseJars.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jvmti/CFLH/MultiReleaseJars.java @@ -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; }