src/hotspot/share/classfile/classLoader.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Cdiff src/hotspot/share/classfile/classLoader.cpp

src/hotspot/share/classfile/classLoader.cpp

Print this page

        

*** 146,155 **** --- 146,157 ---- ClassPathEntry* ClassLoader::_first_append_entry = NULL; ClassPathEntry* ClassLoader::_last_append_entry = NULL; #if INCLUDE_CDS ClassPathEntry* ClassLoader::_app_classpath_entries = NULL; ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL; + ClassPathEntry* ClassLoader::_module_path_entries = NULL; + ClassPathEntry* ClassLoader::_last_module_path_entry = NULL; SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL; #endif // helper routines bool string_starts_with(const char* str, const char* str_to_find) {
*** 719,728 **** --- 721,735 ---- end++; } } } + void ClassLoader::setup_module_search_path(const char* path) { + check_shared_classpath(path); + update_module_path_entry_list(path); + } + #endif // Construct the array of module/path pairs as specified to --patch-module // for the boot loader to search ahead of the jimage, if the class being // loaded is defined to a module that has been specified to --patch-module.
*** 1086,1095 **** --- 1093,1137 ---- #endif return false; } } + #if INCLUDE_CDS + void ClassLoader::add_to_module_path_entries(const char* path, + ClassPathEntry* entry) { + assert(entry != NULL, "ClassPathEntry should not be NULL"); + ClassPathEntry* e = _module_path_entries; + + // The entry does not exist, add to the list + if (_module_path_entries == NULL) { + assert(_last_module_path_entry == NULL, "Sanity"); + _module_path_entries = _last_module_path_entry = entry; + } else { + _last_module_path_entry->set_next(entry); + _last_module_path_entry = entry; + } + } + + // Add a module path to the _module_path_entries list. + void ClassLoader::update_module_path_entry_list(const char *path, + bool throw_exception) { + struct stat st; + assert(os::stat(path, &st) == 0, "module path must exist"); + // File or directory found + ClassPathEntry* new_entry = NULL; + Thread* THREAD = Thread::current(); + new_entry = create_class_path_entry(path, &st, throw_exception, + false /*is_boot_append */, CHECK); + if (new_entry == NULL) { + return; + } + + add_to_module_path_entries(path, new_entry); + return; + } + #endif // INCLUDE_CDS + static void print_module_entry_table(const GrowableArray<ModuleClassPathList*>* const module_list) { ResourceMark rm; int num_of_entries = module_list->length(); for (int i = 0; i < num_of_entries; i++) { ClassPathEntry* e;
*** 1510,1520 **** return result; } #if INCLUDE_CDS ! static char* skip_uri_protocol(char* source) { if (strncmp(source, "file:", 5) == 0) { // file: protocol path could start with file:/ or file:/// // locate the char after all the forward slashes int offset = 5; while (*(source + offset) == '/') { --- 1552,1562 ---- return result; } #if INCLUDE_CDS ! char* ClassLoader::skip_uri_protocol(char* source) { if (strncmp(source, "file:", 5) == 0) { // file: protocol path could start with file:/ or file:/// // locate the char after all the forward slashes int offset = 5; while (*(source + offset) == '/') {
*** 1540,1596 **** if (ik->is_anonymous()) { // We do not archive anonymous classes. return; } char* src = (char*)stream->source(); if (src == NULL) { ! if (ik->class_loader() == NULL) { // JFR classes ik->set_shared_classpath_index(0); ik->set_class_loader_type(ClassLoader::BOOT_LOADER); } return; } assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build"); - ModuleEntry* module = ik->module(); - int classpath_index = -1; ResourceMark rm; char* canonical_path = NEW_RESOURCE_ARRAY(char, JVM_MAXPATHLEN); // save the path from the file: protocol or the module name from the jrt: protocol // if no protocol prefix is found, path is the same as stream->source() char* path = skip_uri_protocol(src); ! for (int i = 0; i < FileMapInfo::get_number_of_share_classpaths(); i++) { ! SharedClassPathEntry* ent = FileMapInfo::shared_classpath(i); if (get_canonical_path(ent->name(), canonical_path, JVM_MAXPATHLEN)) { ! // If the path (from the class stream srouce) is the same as the shared ! // class path, then we have a match. For classes from module image loaded by the ! // PlatformClassLoader, the stream->source() is not the name of the module image. ! // Need to look for 'jrt:' explicitly. ! if (strcmp(canonical_path, os::native_path((char*)path)) == 0 || ! (i == 0 && string_starts_with(src, "jrt:"))) { classpath_index = i; break; } } } ! if (classpath_index < 0) { ! // Shared classpath entry table only contains boot class path and -cp path. // No path entry found for this class. Must be a shared class loaded by the // user defined classloader. assert(ik->shared_classpath_index() < 0, "Sanity"); return; } const char* const class_name = ik->name()->as_C_string(); const char* const file_name = file_name_for_class_name(class_name, ik->name()->utf8_length()); assert(file_name != NULL, "invariant"); ! Thread* THREAD = Thread::current(); ClassLoaderExt::Context context(class_name, file_name, CATCH); context.record_result(ik->name(), classpath_index, ik, THREAD); } #endif // INCLUDE_CDS --- 1582,1676 ---- if (ik->is_anonymous()) { // We do not archive anonymous classes. return; } + oop loader = ik->class_loader(); char* src = (char*)stream->source(); if (src == NULL) { ! if (loader == NULL) { // JFR classes ik->set_shared_classpath_index(0); ik->set_class_loader_type(ClassLoader::BOOT_LOADER); } return; } assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build"); ResourceMark rm; + Thread* THREAD = Thread::current(); + int classpath_index = -1; + PackageEntry* pkg_entry = ik->package(); + + if (FileMapInfo::get_number_of_shared_paths() > 0) { char* canonical_path = NEW_RESOURCE_ARRAY(char, JVM_MAXPATHLEN); // save the path from the file: protocol or the module name from the jrt: protocol // if no protocol prefix is found, path is the same as stream->source() char* path = skip_uri_protocol(src); ! for (int i = 0; i < FileMapInfo::get_number_of_shared_paths(); i++) { ! SharedClassPathEntry* ent = FileMapInfo::shared_path(i); if (get_canonical_path(ent->name(), canonical_path, JVM_MAXPATHLEN)) { ! // If the path (from the class stream source) is the same as the shared ! // class or module path, then we have a match. ! if (strcmp(canonical_path, os::native_path((char*)path)) == 0) { ! // NULL pkg_entry and pkg_entry in an unnamed module implies the class ! // is from the -cp. Ensure the index is within the -cp range before assigning ! // to the classpath_index. ! if ((pkg_entry == NULL) || (pkg_entry->in_unnamed_module())) { ! if (SystemDictionary::is_system_class_loader(loader) && ! (i >= ClassLoaderExt::app_class_paths_start_index()) && ! (i < ClassLoaderExt::app_module_paths_start_index())) { ! classpath_index = i; ! break; ! } else { ! if ((i >= 1) && ! (i < ClassLoaderExt::app_module_paths_start_index())) { classpath_index = i; break; } } + } else { + // non-NULL pkg_entry and is a named module implies the class is from the + // --module-path. Ensure the index is within the --module-path range before + // assigning to the classpath_index. + if ((pkg_entry != NULL) && !(pkg_entry->in_unnamed_module()) && (i > 0)) { + if (i >= ClassLoaderExt::app_module_paths_start_index() && + i < FileMapInfo::get_number_of_shared_paths()) { + classpath_index = i; + break; } ! } ! } ! } ! // for index 0 and the stream->source() is the modules image or has the jrt: protocol. ! // The class must be from the runtime modules image. ! if (i == 0 && (is_modules_image(src) || string_starts_with(src, "jrt:"))) { ! classpath_index = i; ! break; ! } ! } ! } ! // No path entry found for this class. Must be a shared class loaded by the // user defined classloader. + if (classpath_index < 0) { assert(ik->shared_classpath_index() < 0, "Sanity"); return; } + } else { + assert(is_modules_image(src), "stream must be from modules image"); + assert(FileMapInfo::get_number_of_shared_paths() == 0, "shared path table must not have been setup"); + classpath_index = 0; + } const char* const class_name = ik->name()->as_C_string(); const char* const file_name = file_name_for_class_name(class_name, ik->name()->utf8_length()); assert(file_name != NULL, "invariant"); ! ClassLoaderExt::Context context(class_name, file_name, CATCH); context.record_result(ik->name(), classpath_index, ik, THREAD); } #endif // INCLUDE_CDS
*** 1671,1680 **** --- 1751,1767 ---- if (DumpSharedSpaces) { ClassLoaderExt::setup_search_paths(); _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check() } } + + void ClassLoader::initialize_module_path() { + if (DumpSharedSpaces) { + ClassLoaderExt::setup_module_paths(); + FileMapInfo::allocate_shared_path_table(); + } + } #endif jlong ClassLoader::classloader_time_ms() { return UsePerfData ? Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
src/hotspot/share/classfile/classLoader.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File