src/hotspot/share/classfile/classLoader.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File
*** old/src/hotspot/share/classfile/classLoader.cpp	Sun Apr  8 23:15:11 2018
--- new/src/hotspot/share/classfile/classLoader.cpp	Sun Apr  8 23:15:11 2018

*** 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,729 **** --- 721,770 ---- end++; } } } #endif + void ClassLoader::add_to_module_path_entries(const char* path, + ClassPathEntry* entry) { + assert(entry != NULL, "ClassPathEntry should not be NULL"); + assert(DumpSharedSpaces, "dump time only"); + + // 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) { + assert(DumpSharedSpaces, "dump time only"); + struct stat st; + int ret = os::stat(path, &st); + assert(ret == 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; + } + + void ClassLoader::setup_module_search_path(const char* path) { + check_shared_classpath(path); + update_module_path_entry_list(path); + } + #endif // INCLUDE_CDS // 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. void ClassLoader::setup_patch_mod_entries() {
*** 1510,1520 **** --- 1551,1561 ---- return result; } #if INCLUDE_CDS ! static char* skip_uri_protocol(char* source) { ! 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 **** --- 1581,1680 ---- 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 (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; + 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_share_classpaths(); i++) { ! SharedClassPathEntry* ent = FileMapInfo::shared_classpath(i); ! 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 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:"))) { ! // 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 or -Xbootclasspath/a. ! if ((pkg_entry == NULL) || (pkg_entry->in_unnamed_module())) { + // Ensure the index is within the -cp range before assigning + // to the classpath_index. + 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_class_paths_start_index())) { + // The class must be from -Xbootclasspath/a + assert(loader == NULL, "sanity"); classpath_index = i; break; } } + } else { + // A class from a named module 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; } if (classpath_index < 0) { // Shared classpath entry table only contains boot class path and -cp path. + } + } + } + // 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 { + // The shared path table is set up after module system initialization. + // The path table contains no entry before that. Any classes loaded prior + // to the setup of the shared path table must be from the modules image. + 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"); Thread* THREAD = Thread::current(); + ClassLoaderExt::Context context(class_name, file_name, CATCH); context.record_result(ik->name(), classpath_index, ik, THREAD); } #endif // INCLUDE_CDS
*** 1671,1680 **** --- 1755,1771 ---- 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