Skip to content

Commit f647d4d

Browse files
committed
8345936: Call ClassLoader.getResourceAsByteArray only for multi-release jar
Reviewed-by: iklam, dholmes
1 parent cfa04d3 commit f647d4d

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

src/hotspot/share/cds/filemap.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ void SharedClassPathEntry::init(bool is_modules_image,
347347
_type = jar_entry;
348348
_timestamp = st.st_mtime;
349349
_from_class_path_attr = cpe->from_class_path_attr();
350+
_is_multi_release = cpe->is_multi_release_jar();
350351
}
351352
_filesize = st.st_size;
352353
_is_module_path = is_module_path;
@@ -2680,7 +2681,7 @@ ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
26802681
jio_snprintf(msg, strlen(path) + 127, "error in finding JAR file %s", path);
26812682
THROW_MSG_(vmSymbols::java_io_IOException(), msg, nullptr);
26822683
} else {
2683-
ent = ClassLoader::create_class_path_entry(THREAD, path, &st, false, false);
2684+
ent = ClassLoader::create_class_path_entry(THREAD, path, &st, false, false, scpe->is_multi_release());
26842685
if (ent == nullptr) {
26852686
char *msg = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(path) + 128);
26862687
jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path);
@@ -2715,7 +2716,7 @@ ClassFileStream* FileMapInfo::open_stream_for_jvmti(InstanceKlass* ik, Handle cl
27152716
name->utf8_length());
27162717
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
27172718
ClassFileStream* cfs;
2718-
if (class_loader() != nullptr && !cpe->is_modules_image()) {
2719+
if (class_loader() != nullptr && !cpe->is_modules_image() && cpe->is_multi_release_jar()) {
27192720
cfs = get_stream_from_class_loader(class_loader, cpe, file_name, CHECK_NULL);
27202721
} else {
27212722
cfs = cpe->open_stream_for_loader(THREAD, file_name, loader_data);

src/hotspot/share/cds/filemap.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ class SharedClassPathEntry : public MetaspaceObj {
6464
u1 _type;
6565
bool _is_module_path;
6666
bool _from_class_path_attr;
67+
bool _is_multi_release;
6768
time_t _timestamp; // jar timestamp, 0 if is directory, modules image or other
6869
int64_t _filesize; // jar/jimage file size, -1 if is directory, -2 if other
6970
Array<char>* _name;
7071
Array<u1>* _manifest;
7172

7273
public:
7374
SharedClassPathEntry() : _type(0), _is_module_path(false),
74-
_from_class_path_attr(false), _timestamp(0),
75+
_from_class_path_attr(false), _is_multi_release(false), _timestamp(0),
7576
_filesize(0), _name(nullptr), _manifest(nullptr) {}
7677
static int size() {
7778
static_assert(is_aligned(sizeof(SharedClassPathEntry), wordSize), "must be");
@@ -92,6 +93,7 @@ class SharedClassPathEntry : public MetaspaceObj {
9293
bool is_jar() const { return _type == jar_entry; }
9394
bool is_non_existent() const { return _type == non_existent_entry; }
9495
bool from_class_path_attr() { return _from_class_path_attr; }
96+
bool is_multi_release() { return _is_multi_release; }
9597
time_t timestamp() const { return _timestamp; }
9698
const char* name() const;
9799
const char* manifest() const {

src/hotspot/share/classfile/classLoader.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,11 @@ ClassFileStream* ClassPathDirEntry::open_stream(JavaThread* current, const char*
303303
}
304304

305305
ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name,
306-
bool is_boot_append, bool from_class_path_attr) : ClassPathEntry() {
306+
bool is_boot_append, bool from_class_path_attr, bool multi_release) : ClassPathEntry() {
307307
_zip = zip;
308308
_zip_name = copy_path(zip_name);
309309
_from_class_path_attr = from_class_path_attr;
310+
_multi_release = multi_release;
310311
}
311312

312313
ClassPathZipEntry::~ClassPathZipEntry() {
@@ -750,7 +751,8 @@ jzfile* ClassLoader::open_zip_file(const char* canonical_path, char** error_msg,
750751
ClassPathEntry* ClassLoader::create_class_path_entry(JavaThread* current,
751752
const char *path, const struct stat* st,
752753
bool is_boot_append,
753-
bool from_class_path_attr) {
754+
bool from_class_path_attr,
755+
bool is_multi_release) {
754756
ClassPathEntry* new_entry = nullptr;
755757
if ((st->st_mode & S_IFMT) == S_IFREG) {
756758
ResourceMark rm(current);
@@ -763,7 +765,7 @@ ClassPathEntry* ClassLoader::create_class_path_entry(JavaThread* current,
763765
char* error_msg = nullptr;
764766
jzfile* zip = open_zip_file(canonical_path, &error_msg, current);
765767
if (zip != nullptr && error_msg == nullptr) {
766-
new_entry = new ClassPathZipEntry(zip, path, is_boot_append, from_class_path_attr);
768+
new_entry = new ClassPathZipEntry(zip, path, is_boot_append, from_class_path_attr, is_multi_release);
767769
} else {
768770
#if INCLUDE_CDS
769771
ClassLoaderExt::set_has_non_jar_in_classpath();
@@ -796,7 +798,7 @@ ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path, bo
796798
jzfile* zip = open_zip_file(canonical_path, &error_msg, thread);
797799
if (zip != nullptr && error_msg == nullptr) {
798800
// create using canonical path
799-
return new ClassPathZipEntry(zip, canonical_path, is_boot_append, false);
801+
return new ClassPathZipEntry(zip, canonical_path, is_boot_append, false, false);
800802
}
801803
}
802804
}

src/hotspot/share/classfile/classLoader.hpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class ClassPathEntry : public CHeapObj<mtClass> {
5858

5959
virtual bool is_modules_image() const { return false; }
6060
virtual bool is_jar_file() const { return false; }
61+
virtual bool is_multi_release_jar() const { return false; }
62+
virtual void set_multi_release_jar() {}
6163
// Is this entry created from the "Class-path" attribute from a JAR Manifest?
6264
virtual bool from_class_path_attr() const { return false; }
6365
virtual const char* name() const = 0;
@@ -91,11 +93,14 @@ class ClassPathZipEntry: public ClassPathEntry {
9193
jzfile* _zip; // The zip archive
9294
const char* _zip_name; // Name of zip archive
9395
bool _from_class_path_attr; // From the "Class-path" attribute of a jar file
96+
bool _multi_release; // multi-release jar
9497
public:
9598
bool is_jar_file() const { return true; }
99+
bool is_multi_release_jar() const { return _multi_release; }
100+
void set_multi_release_jar() { _multi_release = true; }
96101
bool from_class_path_attr() const { return _from_class_path_attr; }
97102
const char* name() const { return _zip_name; }
98-
ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append, bool from_class_path_attr);
103+
ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append, bool from_class_path_attr, bool multi_release);
99104
virtual ~ClassPathZipEntry();
100105
u1* open_entry(JavaThread* current, const char* name, jint* filesize, bool nul_terminate);
101106
ClassFileStream* open_stream(JavaThread* current, const char* name);
@@ -260,7 +265,8 @@ class ClassLoader: AllStatic {
260265
static ClassPathEntry* create_class_path_entry(JavaThread* current,
261266
const char *path, const struct stat* st,
262267
bool is_boot_append,
263-
bool from_class_path_attr);
268+
bool from_class_path_attr,
269+
bool is_multi_release = false);
264270

265271
// Canonicalizes path names, so strcmp will work properly. This is mainly
266272
// to avoid confusing the zip library

src/hotspot/share/classfile/classLoaderExt.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ void ClassLoaderExt::process_jar_manifest(JavaThread* current, ClassPathEntry* e
244244
vm_exit_during_cds_dumping(err_msg("-Xshare:dump does not support Extension-List in JAR manifest: %s", entry->name()));
245245
}
246246

247+
if (strstr(manifest, "Multi-Release: true") != nullptr) {
248+
entry->set_multi_release_jar();
249+
}
250+
247251
char* cp_attr = get_class_path_attr(entry->name(), manifest, manifest_size);
248252

249253
if (cp_attr != nullptr && strlen(cp_attr) > 0) {
@@ -299,6 +303,7 @@ void ClassLoaderExt::process_jar_manifest(JavaThread* current, ClassPathEntry* e
299303
file_start = file_end;
300304
}
301305
}
306+
return;
302307
}
303308

304309
void ClassLoaderExt::setup_search_paths(JavaThread* current) {

0 commit comments

Comments
 (0)