From c2d1cde7852298044efe6210f287b33d47be58af Mon Sep 17 00:00:00 2001 From: Calvin Cheung Date: Fri, 26 Mar 2021 15:50:53 +0000 Subject: [PATCH] get rid of throw_exception in ClassLoader::create_class_path_entry --- src/hotspot/share/classfile/classLoader.cpp | 103 ++++++------------ src/hotspot/share/classfile/classLoader.hpp | 37 +++---- .../share/classfile/classLoaderExt.cpp | 35 +++--- .../share/classfile/classLoaderExt.hpp | 10 +- src/hotspot/share/memory/filemap.cpp | 11 +- src/hotspot/share/memory/metaspaceShared.cpp | 7 +- 6 files changed, 80 insertions(+), 123 deletions(-) diff --git a/src/hotspot/share/classfile/classLoader.cpp b/src/hotspot/share/classfile/classLoader.cpp index 3dd8550f2c21c..b78ff0d6eaca4 100644 --- a/src/hotspot/share/classfile/classLoader.cpp +++ b/src/hotspot/share/classfile/classLoader.cpp @@ -500,7 +500,7 @@ void ClassLoader::trace_class_path(const char* msg, const char* name) { } } -void ClassLoader::setup_bootstrap_search_path(TRAPS) { +void ClassLoader::setup_bootstrap_search_path(Thread* current) { const char* sys_class_path = Arguments::get_sysclasspath(); assert(sys_class_path != NULL, "System boot class path must not be NULL"); if (PrintSharedArchiveAndExit) { @@ -509,11 +509,11 @@ void ClassLoader::setup_bootstrap_search_path(TRAPS) { } else { trace_class_path("bootstrap loader class path=", sys_class_path); } - setup_bootstrap_search_path_impl(sys_class_path, CHECK); + setup_bootstrap_search_path_impl(current, sys_class_path); } #if INCLUDE_CDS -void ClassLoader::setup_app_search_path(const char *class_path, TRAPS) { +void ClassLoader::setup_app_search_path(Thread* current, const char *class_path) { Arguments::assert_is_dumping_archive(); ResourceMark rm; @@ -521,7 +521,7 @@ void ClassLoader::setup_app_search_path(const char *class_path, TRAPS) { while (cp_stream.has_next()) { const char* path = cp_stream.get_next(); - update_class_path_entry_list(path, false, false, false, CHECK); + update_class_path_entry_list(current, path, false, false, false); } } @@ -541,7 +541,7 @@ void ClassLoader::add_to_module_path_entries(const char* path, } // Add a module path to the _module_path_entries list. -void ClassLoader::setup_module_search_path(const char* path, TRAPS) { +void ClassLoader::setup_module_search_path(Thread* current, const char* path) { Arguments::assert_is_dumping_archive(); struct stat st; if (os::stat(path, &st) != 0) { @@ -551,13 +551,11 @@ void ClassLoader::setup_module_search_path(const char* path, TRAPS) { } // File or directory found ClassPathEntry* new_entry = NULL; - new_entry = create_class_path_entry_or_fail(path, &st, - false /*is_boot_append */, false /* from_class_path_attr */, CHECK); - if (new_entry == NULL) { - return; + new_entry = create_class_path_entry(current, path, &st, + false /*is_boot_append */, false /* from_class_path_attr */); + if (new_entry != NULL) { + add_to_module_path_entries(path, new_entry); } - - add_to_module_path_entries(path, new_entry); return; } @@ -595,7 +593,7 @@ void ClassLoader::setup_patch_mod_entries() { struct stat st; if (os::stat(path, &st) == 0) { // File or directory found - ClassPathEntry* new_entry = create_class_path_entry_or_null(THREAD, path, &st, false, false); + ClassPathEntry* new_entry = create_class_path_entry(THREAD, path, &st, false, false); // If the path specification is valid, enter it into this module's list if (new_entry != NULL) { module_cpl->add_to_list(new_entry); @@ -627,8 +625,8 @@ bool ClassLoader::is_in_patch_mod_entries(Symbol* module_name) { } // Set up the _jrt_entry if present and boot append path -void ClassLoader::setup_bootstrap_search_path_impl(const char *class_path, TRAPS) { - ResourceMark rm(THREAD); +void ClassLoader::setup_bootstrap_search_path_impl(Thread* current, const char *class_path) { + ResourceMark rm(current); ClasspathStream cp_stream(class_path); bool set_base_piece = true; @@ -652,7 +650,7 @@ void ClassLoader::setup_bootstrap_search_path_impl(const char *class_path, TRAPS struct stat st; if (os::stat(path, &st) == 0) { // Directory found - ClassPathEntry* new_entry = create_class_path_entry_or_null(THREAD, path, &st, false, false); + ClassPathEntry* new_entry = create_class_path_entry(current, path, &st, false, false); // Check for a jimage if (Arguments::has_jimage()) { @@ -669,7 +667,7 @@ void ClassLoader::setup_bootstrap_search_path_impl(const char *class_path, TRAPS } else { // Every entry on the system boot class path after the initial base piece, // which is set by os::set_boot_path(), is considered an appended entry. - update_class_path_entry_list(path, false, true, false, CHECK); + update_class_path_entry_list(current, path, false, true, false); } } } @@ -693,7 +691,7 @@ void ClassLoader::add_to_exploded_build_list(Thread* current, Symbol* module_sym struct stat st; if (os::stat(path, &st) == 0) { // Directory found - ClassPathEntry* new_entry = create_class_path_entry_or_null(current, path, &st, false, false); + ClassPathEntry* new_entry = create_class_path_entry(current, path, &st, false, false); // If the path specification is valid, enter it into this module's list. // There is no need to check for duplicate modules in the exploded entry list, @@ -719,25 +717,11 @@ jzfile* ClassLoader::open_zip_file(const char* canonical_path, char** error_msg, return (*ZipOpen)(canonical_path, error_msg); } -ClassPathEntry* ClassLoader::create_class_path_entry_or_fail(const char *path, const struct stat* st, - bool is_boot_append, - bool from_class_path_attr, TRAPS) { - return create_class_path_entry(path, st, true /*throw_exception*/, is_boot_append, from_class_path_attr, CHECK_NULL); -} - -ClassPathEntry* ClassLoader::create_class_path_entry_or_null(Thread* current, - const char *path, const struct stat* st, - bool is_boot_append, - bool from_class_path_attr) { - return create_class_path_entry(path, st, false /*throw_exception*/, is_boot_append, from_class_path_attr, current); -} - -ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st, - bool throw_exception, +ClassPathEntry* ClassLoader::create_class_path_entry(Thread* current, + const char *path, const struct stat* st, bool is_boot_append, - bool from_class_path_attr, - TRAPS) { - JavaThread* thread = THREAD->as_Java_thread(); + bool from_class_path_attr) { + JavaThread* thread = current->as_Java_thread(); ClassPathEntry* new_entry = NULL; if ((st->st_mode & S_IFMT) == S_IFREG) { ResourceMark rm(thread); @@ -745,12 +729,7 @@ ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const str // Canonicalized filename const char* canonical_path = get_canonical_path(path, thread); if (canonical_path == NULL) { - // This matches the classic VM - if (throw_exception) { - THROW_MSG_(vmSymbols::java_io_IOException(), "Bad pathname", NULL); - } else { - return NULL; - } + return NULL; } jint error; JImageFile* jimage =(*JImageOpen)(canonical_path, &error); @@ -762,21 +741,7 @@ ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const str if (zip != NULL && error_msg == NULL) { new_entry = new ClassPathZipEntry(zip, path, is_boot_append, from_class_path_attr); } else { - char *msg; - if (error_msg == NULL) { - msg = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, strlen(path) + 128); ; - jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path); - } else { - int len = (int)(strlen(path) + strlen(error_msg) + 128); - msg = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, len); ; - jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path); - } - // Don't complain about bad jar files added via -Xbootclasspath/a:. - if (throw_exception && is_init_completed()) { - THROW_MSG_(vmSymbols::java_lang_ClassNotFoundException(), msg, NULL); - } else { - return NULL; - } + return NULL; } } log_info(class, path)("opened: %s", path); @@ -847,10 +812,10 @@ void ClassLoader::add_to_boot_append_entries(ClassPathEntry *new_entry) { // Note that at dump time, ClassLoader::_app_classpath_entries are NOT used for // loading app classes. Instead, the app class are loaded by the // jdk/internal/loader/ClassLoaders$AppClassLoader instance. -void ClassLoader::add_to_app_classpath_entries(const char* path, +void ClassLoader::add_to_app_classpath_entries(Thread* current, + const char* path, ClassPathEntry* entry, - bool check_for_duplicates, - TRAPS) { + bool check_for_duplicates) { #if INCLUDE_CDS assert(entry != NULL, "ClassPathEntry should not be NULL"); ClassPathEntry* e = _app_classpath_entries; @@ -874,22 +839,22 @@ void ClassLoader::add_to_app_classpath_entries(const char* path, } if (entry->is_jar_file()) { - ClassLoaderExt::process_jar_manifest(entry, check_for_duplicates, CHECK); + ClassLoaderExt::process_jar_manifest(current, entry, check_for_duplicates); } #endif } // Returns true IFF the file/dir exists and the entry was successfully created. -bool ClassLoader::update_class_path_entry_list(const char *path, +bool ClassLoader::update_class_path_entry_list(Thread* current, + const char *path, bool check_for_duplicates, bool is_boot_append, - bool from_class_path_attr, - TRAPS) { + bool from_class_path_attr) { struct stat st; if (os::stat(path, &st) == 0) { // File or directory found ClassPathEntry* new_entry = NULL; - new_entry = create_class_path_entry_or_fail(path, &st, is_boot_append, from_class_path_attr, CHECK_false); + new_entry = create_class_path_entry(current, path, &st, is_boot_append, from_class_path_attr); if (new_entry == NULL) { return false; } @@ -899,7 +864,7 @@ bool ClassLoader::update_class_path_entry_list(const char *path, if (is_boot_append) { add_to_boot_append_entries(new_entry); } else { - add_to_app_classpath_entries(path, new_entry, check_for_duplicates, CHECK_false); + add_to_app_classpath_entries(current, path, new_entry, check_for_duplicates); } return true; } else { @@ -1454,7 +1419,7 @@ void ClassLoader::initialize(TRAPS) { // lookup java library entry points load_java_library(); // jimage library entry points are loaded below, in lookup_vm_options - setup_bootstrap_search_path(CHECK); + setup_bootstrap_search_path(THREAD); } char* lookup_vm_resource(JImageFile *jimage, const char *jimage_version, const char *path) { @@ -1491,15 +1456,15 @@ char* ClassLoader::lookup_vm_options() { } #if INCLUDE_CDS -void ClassLoader::initialize_shared_path(TRAPS) { +void ClassLoader::initialize_shared_path(Thread* current) { if (Arguments::is_dumping_archive()) { - ClassLoaderExt::setup_search_paths(CHECK); + ClassLoaderExt::setup_search_paths(current); } } void ClassLoader::initialize_module_path(TRAPS) { if (Arguments::is_dumping_archive()) { - ClassLoaderExt::setup_module_paths(CHECK); + ClassLoaderExt::setup_module_paths(THREAD); FileMapInfo::allocate_shared_path_table(CHECK); } } diff --git a/src/hotspot/share/classfile/classLoader.hpp b/src/hotspot/share/classfile/classLoader.hpp index f16cee33bbcd1..79cdfc1e11eeb 100644 --- a/src/hotspot/share/classfile/classLoader.hpp +++ b/src/hotspot/share/classfile/classLoader.hpp @@ -222,12 +222,12 @@ class ClassLoader: AllStatic { CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;) CDS_ONLY(static ClassPathEntry* _module_path_entries;) CDS_ONLY(static ClassPathEntry* _last_module_path_entry;) - CDS_ONLY(static void setup_app_search_path(const char* class_path, TRAPS);) - CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);) - static void add_to_app_classpath_entries(const char* path, + CDS_ONLY(static void setup_app_search_path(Thread* current, const char* class_path);) + CDS_ONLY(static void setup_module_search_path(Thread* current, const char* path);) + static void add_to_app_classpath_entries(Thread* current, + const char* path, ClassPathEntry* entry, - bool check_for_duplicates, - TRAPS); + bool check_for_duplicates); CDS_ONLY(static void add_to_module_path_entries(const char* path, ClassPathEntry* entry);) public: @@ -241,8 +241,8 @@ class ClassLoader: AllStatic { // - setup the boot loader's system class path // - setup the boot loader's patch mod entries, if present // - create the ModuleEntry for java.base - static void setup_bootstrap_search_path(TRAPS); - static void setup_bootstrap_search_path_impl(const char *class_path, TRAPS); + static void setup_bootstrap_search_path(Thread* current); + static void setup_bootstrap_search_path_impl(Thread* current, const char *class_path); static void setup_patch_mod_entries(); static void create_javabase(); @@ -256,19 +256,12 @@ class ClassLoader: AllStatic { static void release_load_zip_library(); static inline void load_zip_library_if_needed(); static jzfile* open_zip_file(const char* canonical_path, char** error_msg, JavaThread* thread); - static ClassPathEntry* create_class_path_entry(const char *path, const struct stat* st, - bool throw_exception, - bool is_boot_append, - bool from_class_path_attr, TRAPS); public: - static ClassPathEntry* create_class_path_entry_or_fail(const char *path, const struct stat* st, - bool is_boot_append, - bool from_class_path_attr, TRAPS); - static ClassPathEntry* create_class_path_entry_or_null(Thread* current, - const char *path, const struct stat* st, - bool is_boot_append, - bool from_class_path_attr); + static ClassPathEntry* create_class_path_entry(Thread* current, + const char *path, const struct stat* st, + bool is_boot_append, + bool from_class_path_attr); // Canonicalizes path names, so strcmp will work properly. This is mainly // to avoid confusing the zip library @@ -277,11 +270,11 @@ class ClassLoader: AllStatic { int class_name_len); static PackageEntry* get_package_entry(Symbol* pkg_name, ClassLoaderData* loader_data); static int crc32(int crc, const char* buf, int len); - static bool update_class_path_entry_list(const char *path, + static bool update_class_path_entry_list(Thread* current, + const char *path, bool check_for_duplicates, bool is_boot_append, - bool from_class_path_attr, - TRAPS); + bool from_class_path_attr); static void print_bootclasspath(); // Timing @@ -346,7 +339,7 @@ class ClassLoader: AllStatic { // Initialization static void initialize(TRAPS); static void classLoader_init2(Thread* current); - CDS_ONLY(static void initialize_shared_path(TRAPS);) + CDS_ONLY(static void initialize_shared_path(Thread* current);) CDS_ONLY(static void initialize_module_path(TRAPS);) static int compute_Object_vtable(); diff --git a/src/hotspot/share/classfile/classLoaderExt.cpp b/src/hotspot/share/classfile/classLoaderExt.cpp index 0ea3e1b7beba1..c281e254de67e 100644 --- a/src/hotspot/share/classfile/classLoaderExt.cpp +++ b/src/hotspot/share/classfile/classLoaderExt.cpp @@ -65,7 +65,7 @@ void ClassLoaderExt::append_boot_classpath(ClassPathEntry* new_entry) { ClassLoader::add_to_boot_append_entries(new_entry); } -void ClassLoaderExt::setup_app_search_path(TRAPS) { +void ClassLoaderExt::setup_app_search_path(Thread* current) { Arguments::assert_is_dumping_archive(); _app_class_paths_start_index = ClassLoader::num_boot_classpath_entries(); char* app_class_path = os::strdup(Arguments::get_appclasspath()); @@ -77,30 +77,30 @@ void ClassLoaderExt::setup_app_search_path(TRAPS) { trace_class_path("app loader class path (skipped)=", app_class_path); } else { trace_class_path("app loader class path=", app_class_path); - ClassLoader::setup_app_search_path(app_class_path, CHECK); + ClassLoader::setup_app_search_path(current, app_class_path); } } -void ClassLoaderExt::process_module_table(ModuleEntryTable* met, TRAPS) { - ResourceMark rm(THREAD); +void ClassLoaderExt::process_module_table(Thread* current, ModuleEntryTable* met) { + ResourceMark rm(current); for (int i = 0; i < met->table_size(); i++) { for (ModuleEntry* m = met->bucket(i); m != NULL;) { char* path = m->location()->as_C_string(); if (strncmp(path, "file:", 5) == 0) { path = ClassLoader::skip_uri_protocol(path); - ClassLoader::setup_module_search_path(path, CHECK); + ClassLoader::setup_module_search_path(current, path); } m = m->next(); } } } -void ClassLoaderExt::setup_module_paths(TRAPS) { +void ClassLoaderExt::setup_module_paths(Thread* current) { Arguments::assert_is_dumping_archive(); _app_module_paths_start_index = ClassLoader::num_boot_classpath_entries() + ClassLoader::num_app_classpath_entries(); - Handle system_class_loader (THREAD, SystemDictionary::java_system_loader()); + Handle system_class_loader (current, SystemDictionary::java_system_loader()); ModuleEntryTable* met = Modules::get_module_entry_table(system_class_loader); - process_module_table(met, CHECK); + process_module_table(current, met); } char* ClassLoaderExt::read_manifest(Thread* current, ClassPathEntry* entry, jint *manifest_size, bool clean_text) { @@ -163,11 +163,11 @@ char* ClassLoaderExt::get_class_path_attr(const char* jar_path, char* manifest, return found; } -void ClassLoaderExt::process_jar_manifest(ClassPathEntry* entry, - bool check_for_duplicates, TRAPS) { - ResourceMark rm(THREAD); +void ClassLoaderExt::process_jar_manifest(Thread* current, ClassPathEntry* entry, + bool check_for_duplicates) { + ResourceMark rm(current); jint manifest_size; - char* manifest = read_manifest(THREAD, entry, &manifest_size); + char* manifest = read_manifest(current, entry, &manifest_size); if (manifest == NULL) { return; @@ -207,13 +207,12 @@ void ClassLoaderExt::process_jar_manifest(ClassPathEntry* entry, size_t name_len = strlen(file_start); if (name_len > 0) { - ResourceMark rm(THREAD); + ResourceMark rm(current); size_t libname_len = dir_len + name_len; char* libname = NEW_RESOURCE_ARRAY(char, libname_len + 1); int n = os::snprintf(libname, libname_len + 1, "%.*s%s", dir_len, dir_name, file_start); assert((size_t)n == libname_len, "Unexpected number of characters in string"); - bool status = ClassLoader::update_class_path_entry_list(libname, true, false, true /* from_class_path_attr */, CHECK); - if (status) { + if (ClassLoader::update_class_path_entry_list(current, libname, true, false, true /* from_class_path_attr */)) { trace_class_path("library = ", libname); } else { trace_class_path("library (non-existent) = ", libname); @@ -226,8 +225,8 @@ void ClassLoaderExt::process_jar_manifest(ClassPathEntry* entry, } } -void ClassLoaderExt::setup_search_paths(TRAPS) { - ClassLoaderExt::setup_app_search_path(CHECK); +void ClassLoaderExt::setup_search_paths(Thread* current) { + ClassLoaderExt::setup_app_search_path(current); } void ClassLoaderExt::record_result(const s2 classpath_index, InstanceKlass* result) { @@ -327,7 +326,7 @@ ClassPathEntry* ClassLoaderExt::find_classpath_entry_from_cache(Thread* current, } ClassPathEntry* new_entry = NULL; - new_entry = create_class_path_entry_or_null(current, path, &st, false, false); + new_entry = create_class_path_entry(current, path, &st, false, false); if (new_entry == NULL) { return NULL; } diff --git a/src/hotspot/share/classfile/classLoaderExt.hpp b/src/hotspot/share/classfile/classLoaderExt.hpp index fc92802b25e08..4e827ea2a9a98 100644 --- a/src/hotspot/share/classfile/classLoaderExt.hpp +++ b/src/hotspot/share/classfile/classLoaderExt.hpp @@ -45,8 +45,8 @@ class ClassLoaderExt: public ClassLoader { // AllStatic }; static char* get_class_path_attr(const char* jar_path, char* manifest, jint manifest_size); - static void setup_app_search_path(TRAPS); // Only when -Xshare:dump - static void process_module_table(ModuleEntryTable* met, TRAPS); + static void setup_app_search_path(Thread* current); // Only when -Xshare:dump + static void process_module_table(Thread* current, ModuleEntryTable* met); // index of first app JAR in shared classpath entry table static jshort _app_class_paths_start_index; // index of first modular JAR in shared modulepath entry table @@ -61,13 +61,13 @@ class ClassLoaderExt: public ClassLoader { // AllStatic static ClassPathEntry* find_classpath_entry_from_cache(Thread* current, const char* path); public: - static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates, TRAPS); + static void process_jar_manifest(Thread* current, ClassPathEntry* entry, bool check_for_duplicates); // Called by JVMTI code to add boot classpath static void append_boot_classpath(ClassPathEntry* new_entry); - static void setup_search_paths(TRAPS); - static void setup_module_paths(TRAPS); + static void setup_search_paths(Thread* current); + static void setup_module_paths(Thread* current); static char* read_manifest(Thread* current, ClassPathEntry* entry, jint *manifest_size) { // Remove all the new-line continuations (which wrap long lines at 72 characters, see diff --git a/src/hotspot/share/memory/filemap.cpp b/src/hotspot/share/memory/filemap.cpp index 5932445502fe6..9b08f93d5b239 100644 --- a/src/hotspot/share/memory/filemap.cpp +++ b/src/hotspot/share/memory/filemap.cpp @@ -2336,11 +2336,16 @@ ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) { const char* path = scpe->name(); struct stat st; if (os::stat(path, &st) != 0) { - char *msg = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(path) + 128); ; - jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path); + char *msg = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(path) + 128); + jio_snprintf(msg, strlen(path) + 127, "error in finding JAR file %s", path); THROW_MSG_(vmSymbols::java_io_IOException(), msg, NULL); } else { - ent = ClassLoader::create_class_path_entry_or_fail(path, &st, false, false, CHECK_NULL); + ent = ClassLoader::create_class_path_entry(THREAD, path, &st, false, false); + if (ent == NULL) { + char *msg = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(path) + 128); + jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path); + THROW_MSG_(vmSymbols::java_io_IOException(), msg, NULL); + } } } diff --git a/src/hotspot/share/memory/metaspaceShared.cpp b/src/hotspot/share/memory/metaspaceShared.cpp index 5cf3bd45862b7..2abf3409a7f8f 100644 --- a/src/hotspot/share/memory/metaspaceShared.cpp +++ b/src/hotspot/share/memory/metaspaceShared.cpp @@ -602,12 +602,7 @@ void MetaspaceShared::prepare_for_dumping() { Arguments::assert_is_dumping_archive(); Arguments::check_unsupported_dumping_properties(); - EXCEPTION_MARK; - ClassLoader::initialize_shared_path(THREAD); - if (HAS_PENDING_EXCEPTION) { - java_lang_Throwable::print(PENDING_EXCEPTION, tty); - vm_exit_during_initialization("ClassLoader::initialize_shared_path() failed unexpectedly"); - } + ClassLoader::initialize_shared_path(Thread::current()); } // Preload classes from a list, populate the shared spaces and dump to a