hotspot/src/share/vm/classfile/classLoader.cpp
changeset 40013 943cf01a6b82
parent 39223 af5506aae343
child 40016 bf6fcd467a7b
equal deleted inserted replaced
40012:f69cfe79fe98 40013:943cf01a6b82
   139 PerfCounter*    ClassLoader::_unsafe_defineClassCallCounter = NULL;
   139 PerfCounter*    ClassLoader::_unsafe_defineClassCallCounter = NULL;
   140 PerfCounter*    ClassLoader::_isUnsyncloadClass = NULL;
   140 PerfCounter*    ClassLoader::_isUnsyncloadClass = NULL;
   141 PerfCounter*    ClassLoader::_load_instance_class_failCounter = NULL;
   141 PerfCounter*    ClassLoader::_load_instance_class_failCounter = NULL;
   142 
   142 
   143 GrowableArray<ModuleClassPathList*>* ClassLoader::_xpatch_entries = NULL;
   143 GrowableArray<ModuleClassPathList*>* ClassLoader::_xpatch_entries = NULL;
   144 ClassPathEntry* ClassLoader::_first_entry        = NULL;
   144 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
   145 ClassPathEntry* ClassLoader::_last_entry         = NULL;
   145 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
       
   146 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
       
   147 ClassPathEntry* ClassLoader::_last_append_entry  = NULL;
   146 int             ClassLoader::_num_entries        = 0;
   148 int             ClassLoader::_num_entries        = 0;
   147 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
       
   148 bool            ClassLoader::_has_jimage = false;
       
   149 #if INCLUDE_CDS
   149 #if INCLUDE_CDS
   150 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL;
   150 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL;
   151 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL;
   151 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL;
   152 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
   152 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
   153 #endif
   153 #endif
   506           }
   506           }
   507         }
   507         }
   508 #endif
   508 #endif
   509 
   509 
   510       } else {
   510       } else {
   511         PackageEntry* package_entry = get_package_entry(name, ClassLoaderData::the_null_class_loader_data(), THREAD);
   511         PackageEntry* package_entry = get_package_entry(name, ClassLoaderData::the_null_class_loader_data(), CHECK_NULL);
   512         if (package_entry != NULL) {
   512         if (package_entry != NULL) {
   513           ResourceMark rm;
   513           ResourceMark rm;
   514           // Get the module name
   514           // Get the module name
   515           ModuleEntry* module = package_entry->module();
   515           ModuleEntry* module = package_entry->module();
   516           assert(module != NULL, "Boot classLoader package missing module");
   516           assert(module != NULL, "Boot classLoader package missing module");
   649   }
   649   }
   650 }
   650 }
   651 #endif
   651 #endif
   652 
   652 
   653 void ClassLoader::setup_bootstrap_search_path() {
   653 void ClassLoader::setup_bootstrap_search_path() {
   654   assert(_first_entry == NULL, "should not setup bootstrap class search path twice");
       
   655   const char* sys_class_path = Arguments::get_sysclasspath();
   654   const char* sys_class_path = Arguments::get_sysclasspath();
   656   const char* java_class_path = Arguments::get_appclasspath();
   655   const char* java_class_path = Arguments::get_appclasspath();
   657   if (PrintSharedArchiveAndExit) {
   656   if (PrintSharedArchiveAndExit) {
   658     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
   657     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
   659     // the same as the bootcp of the shared archive.
   658     // the same as the bootcp of the shared archive.
   692 void ClassLoader::setup_xpatch_entries() {
   691 void ClassLoader::setup_xpatch_entries() {
   693   Thread* THREAD = Thread::current();
   692   Thread* THREAD = Thread::current();
   694   GrowableArray<ModuleXPatchPath*>* xpatch_args = Arguments::get_xpatchprefix();
   693   GrowableArray<ModuleXPatchPath*>* xpatch_args = Arguments::get_xpatchprefix();
   695   int num_of_entries = xpatch_args->length();
   694   int num_of_entries = xpatch_args->length();
   696 
   695 
   697   // Set up the boot loader's xpatch_entries list
   696   assert(!DumpSharedSpaces, "DumpSharedSpaces not supported with -Xpatch");
       
   697   assert(!UseSharedSpaces, "UseSharedSpaces not supported with -Xpatch");
       
   698 
       
   699   // Set up the boot loader's _xpatch_entries list
   698   _xpatch_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
   700   _xpatch_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
   699 
   701 
   700   for (int i = 0; i < num_of_entries; i++) {
   702   for (int i = 0; i < num_of_entries; i++) {
   701     const char* module_name = (xpatch_args->at(i))->module_name();
   703     const char* module_name = (xpatch_args->at(i))->module_name();
   702     Symbol* const module_sym = SymbolTable::lookup(module_name, (int)strlen(module_name), CHECK);
   704     Symbol* const module_sym = SymbolTable::lookup(module_name, (int)strlen(module_name), CHECK);
   740     }
   742     }
   741   }
   743   }
   742 }
   744 }
   743 
   745 
   744 void ClassLoader::setup_search_path(const char *class_path, bool bootstrap_search) {
   746 void ClassLoader::setup_search_path(const char *class_path, bool bootstrap_search) {
   745   int offset = 0;
       
   746   int len = (int)strlen(class_path);
   747   int len = (int)strlen(class_path);
   747   int end = 0;
   748   int end = 0;
   748   bool mark_append_entry = false;
   749   bool set_base_piece = bootstrap_search;
   749 
   750 
   750   // Iterate over class path entries
   751   // Iterate over class path entries
   751   for (int start = 0; start < len; start = end) {
   752   for (int start = 0; start < len; start = end) {
   752     while (class_path[end] && class_path[end] != os::path_separator()[0]) {
   753     while (class_path[end] && class_path[end] != os::path_separator()[0]) {
   753       end++;
   754       end++;
   754     }
   755     }
   755     EXCEPTION_MARK;
   756     EXCEPTION_MARK;
   756     ResourceMark rm(THREAD);
   757     ResourceMark rm(THREAD);
   757     mark_append_entry = (mark_append_entry ||
       
   758       (bootstrap_search && (start == Arguments::bootclassloader_append_index())));
       
   759     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
   758     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
   760     strncpy(path, &class_path[start], end - start);
   759     strncpy(path, &class_path[start], end - start);
   761     path[end - start] = '\0';
   760     path[end - start] = '\0';
   762     update_class_path_entry_list(path, false, mark_append_entry, false, bootstrap_search);
   761 
   763 
   762     // The first time through the bootstrap_search setup, it must be determined
   764     // Check on the state of the boot loader's append path
   763     // what the base or core piece of the boot loader search is.  Either a java runtime
   765     if (mark_append_entry && (_first_append_entry == NULL)) {
   764     // image is present or this is an exploded module build situation.
   766       // Failure to mark the first append entry, most likely
   765     if (set_base_piece) {
   767       // due to a non-existent path. Record the next entry
   766       assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, "java.base"),
   768       // as the first boot loader append entry.
   767              "Incorrect boot loader search path, no java runtime image or java.base exploded build");
   769       mark_append_entry = true;
   768       struct stat st;
       
   769       if (os::stat(path, &st) == 0) {
       
   770         // Directory found
       
   771         Thread* THREAD = Thread::current();
       
   772         ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, CHECK);
       
   773 
       
   774         // Check for a jimage
       
   775         if (Arguments::has_jimage()) {
       
   776           assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice");
       
   777           assert(new_entry != NULL && new_entry->is_jrt(), "No java runtime image present");
       
   778           _jrt_entry = new_entry;
       
   779           ++_num_entries;
       
   780 #if INCLUDE_CDS
       
   781           if (DumpSharedSpaces) {
       
   782             JImageFile *jimage = _jrt_entry->jimage();
       
   783             assert(jimage != NULL, "No java runtime image file present");
       
   784             ClassLoader::initialize_module_loader_map(jimage);
       
   785           }
       
   786 #endif
       
   787         }
       
   788       } else {
       
   789         // If path does not exist, exit
       
   790         vm_exit_during_initialization("Unable to establish the boot loader search path", path);
       
   791       }
       
   792       set_base_piece = false;
   770     } else {
   793     } else {
   771       mark_append_entry = false;
   794       // Every entry on the system boot class path after the initial base piece,
       
   795       // which is set by os::set_boot_path(), is considered an appended entry.
       
   796       update_class_path_entry_list(path, false, bootstrap_search);
   772     }
   797     }
   773 
   798 
   774 #if INCLUDE_CDS
   799 #if INCLUDE_CDS
   775     if (DumpSharedSpaces) {
   800     if (DumpSharedSpaces) {
   776       check_shared_classpath(path);
   801       check_shared_classpath(path);
   778 #endif
   803 #endif
   779     while (class_path[end] == os::path_separator()[0]) {
   804     while (class_path[end] == os::path_separator()[0]) {
   780       end++;
   805       end++;
   781     }
   806     }
   782   }
   807   }
       
   808 }
       
   809 
       
   810 // During an exploded modules build, each module defined to the boot loader
       
   811 // will be added to the ClassLoader::_exploded_entries array.
       
   812 void ClassLoader::add_to_exploded_build_list(Symbol* module_sym, TRAPS) {
       
   813   assert(!ClassLoader::has_jrt_entry(), "Exploded build not applicable");
       
   814 
       
   815   // Set up the boot loader's _exploded_entries list
       
   816   if (_exploded_entries == NULL) {
       
   817     _exploded_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(EXPLODED_ENTRY_SIZE, true);
       
   818   }
       
   819 
       
   820   // Find the module's symbol
       
   821   ResourceMark rm(THREAD);
       
   822   const char *module_name = module_sym->as_C_string();
       
   823   const char *home = Arguments::get_java_home();
       
   824   const char file_sep = os::file_separator()[0];
       
   825   // 10 represents the length of "modules" + 2 file separators + \0
       
   826   size_t len = strlen(home) + strlen(module_name) + 10;
       
   827   char *path = NEW_C_HEAP_ARRAY(char, len, mtModule);
       
   828   jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
       
   829 
       
   830   struct stat st;
       
   831   if (os::stat(path, &st) == 0) {
       
   832     // Directory found
       
   833     ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, CHECK);
       
   834 
       
   835     // If the path specification is valid, enter it into this module's list.
       
   836     // There is no need to check for duplicate modules in the exploded entry list,
       
   837     // since no two modules with the same name can be defined to the boot loader.
       
   838     // This is checked at module definition time in Modules::define_module.
       
   839     if (new_entry != NULL) {
       
   840       ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);
       
   841       module_cpl->add_to_list(new_entry);
       
   842       _exploded_entries->push(module_cpl);
       
   843       log_info(class, load)("path: %s", path);
       
   844     }
       
   845   }
       
   846   FREE_C_HEAP_ARRAY(char, path);
   783 }
   847 }
   784 
   848 
   785 ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st,
   849 ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st,
   786                                                      bool throw_exception,
   850                                                      bool throw_exception,
   787                                                      bool is_boot_append, TRAPS) {
   851                                                      bool is_boot_append, TRAPS) {
   870     }
   934     }
   871   }
   935   }
   872   return NULL;
   936   return NULL;
   873 }
   937 }
   874 
   938 
   875 // The boot class loader must adhere to specfic visibility rules.
       
   876 // Prior to loading a class in a named package, the package is checked
       
   877 // to see if it is in a module defined to the boot loader. If the
       
   878 // package is not in a module defined to the boot loader, the class
       
   879 // must be loaded only in the boot loader's append path, which
       
   880 // consists of [-Xbootclasspath/a]; [jvmti appended entries]
       
   881 void ClassLoader::set_first_append_entry(ClassPathEntry *new_entry) {
       
   882   if (_first_append_entry == NULL) {
       
   883     _first_append_entry = new_entry;
       
   884   }
       
   885 }
       
   886 
       
   887 // returns true if entry already on class path
   939 // returns true if entry already on class path
   888 bool ClassLoader::contains_entry(ClassPathEntry *entry) {
   940 bool ClassLoader::contains_entry(ClassPathEntry *entry) {
   889   ClassPathEntry* e = _first_entry;
   941   ClassPathEntry* e = _first_append_entry;
   890   while (e != NULL) {
   942   while (e != NULL) {
   891     // assume zip entries have been canonicalized
   943     // assume zip entries have been canonicalized
   892     if (strcmp(entry->name(), e->name()) == 0) {
   944     if (strcmp(entry->name(), e->name()) == 0) {
   893       return true;
   945       return true;
   894     }
   946     }
   897   return false;
   949   return false;
   898 }
   950 }
   899 
   951 
   900 void ClassLoader::add_to_list(ClassPathEntry *new_entry) {
   952 void ClassLoader::add_to_list(ClassPathEntry *new_entry) {
   901   if (new_entry != NULL) {
   953   if (new_entry != NULL) {
   902     if (_last_entry == NULL) {
   954     if (_last_append_entry == NULL) {
   903       _first_entry = _last_entry = new_entry;
   955       assert(_first_append_entry == NULL, "boot loader's append class path entry list not empty");
       
   956       _first_append_entry = _last_append_entry = new_entry;
   904     } else {
   957     } else {
   905       _last_entry->set_next(new_entry);
   958       _last_append_entry->set_next(new_entry);
   906       _last_entry = new_entry;
   959       _last_append_entry = new_entry;
   907     }
   960     }
   908   }
   961   }
   909   _num_entries ++;
   962   _num_entries++;
   910 }
       
   911 
       
   912 void ClassLoader::prepend_to_list(ClassPathEntry *new_entry) {
       
   913   if (new_entry != NULL) {
       
   914     if (_last_entry == NULL) {
       
   915       _first_entry = _last_entry = new_entry;
       
   916     } else {
       
   917       new_entry->set_next(_first_entry);
       
   918       _first_entry = new_entry;
       
   919     }
       
   920   }
       
   921   _num_entries ++;
       
   922 }
   963 }
   923 
   964 
   924 void ClassLoader::add_to_list(const char *apath) {
   965 void ClassLoader::add_to_list(const char *apath) {
   925   update_class_path_entry_list((char*)apath, false, false, false, false);
   966   update_class_path_entry_list((char*)apath, false, false);
   926 }
       
   927 
       
   928 void ClassLoader::prepend_to_list(const char *apath) {
       
   929   update_class_path_entry_list((char*)apath, false, false, true, false);
       
   930 }
   967 }
   931 
   968 
   932 // Returns true IFF the file/dir exists and the entry was successfully created.
   969 // Returns true IFF the file/dir exists and the entry was successfully created.
   933 bool ClassLoader::update_class_path_entry_list(const char *path,
   970 bool ClassLoader::update_class_path_entry_list(const char *path,
   934                                                bool check_for_duplicates,
   971                                                bool check_for_duplicates,
   935                                                bool mark_append_entry,
       
   936                                                bool prepend_entry,
       
   937                                                bool is_boot_append,
   972                                                bool is_boot_append,
   938                                                bool throw_exception) {
   973                                                bool throw_exception) {
   939   struct stat st;
   974   struct stat st;
   940   if (os::stat(path, &st) == 0) {
   975   if (os::stat(path, &st) == 0) {
   941     // File or directory found
   976     // File or directory found
   944     new_entry = create_class_path_entry(path, &st, throw_exception, is_boot_append, CHECK_(false));
   979     new_entry = create_class_path_entry(path, &st, throw_exception, is_boot_append, CHECK_(false));
   945     if (new_entry == NULL) {
   980     if (new_entry == NULL) {
   946       return false;
   981       return false;
   947     }
   982     }
   948 
   983 
   949     // Ensure that the first boot loader append entry will always be set correctly.
       
   950     assert((!mark_append_entry ||
       
   951             (mark_append_entry && (!check_for_duplicates || !contains_entry(new_entry)))),
       
   952            "failed to mark boot loader's first append boundary");
       
   953 
       
   954     // Do not reorder the bootclasspath which would break get_system_package().
   984     // Do not reorder the bootclasspath which would break get_system_package().
   955     // Add new entry to linked list
   985     // Add new entry to linked list
   956 
       
   957     if (!check_for_duplicates || !contains_entry(new_entry)) {
   986     if (!check_for_duplicates || !contains_entry(new_entry)) {
   958       ClassLoaderExt::add_class_path_entry(path, check_for_duplicates, new_entry, prepend_entry);
   987       ClassLoaderExt::add_class_path_entry(path, check_for_duplicates, new_entry);
   959       if (mark_append_entry) {
       
   960         set_first_append_entry(new_entry);
       
   961       }
       
   962     }
   988     }
   963     return true;
   989     return true;
   964   } else {
   990   } else {
   965 #if INCLUDE_CDS
   991 #if INCLUDE_CDS
   966     if (DumpSharedSpaces) {
   992     if (DumpSharedSpaces) {
   969 #endif
   995 #endif
   970     return false;
   996     return false;
   971   }
   997   }
   972 }
   998 }
   973 
   999 
       
  1000 static void print_module_entry_table(const GrowableArray<ModuleClassPathList*>* const module_list) {
       
  1001   ResourceMark rm;
       
  1002   int num_of_entries = module_list->length();
       
  1003   for (int i = 0; i < num_of_entries; i++) {
       
  1004     ClassPathEntry* e;
       
  1005     ModuleClassPathList* mpl = module_list->at(i);
       
  1006     tty->print("%s=", mpl->module_name()->as_C_string());
       
  1007     e = mpl->module_first_entry();
       
  1008     while (e != NULL) {
       
  1009       tty->print("%s", e->name());
       
  1010       e = e->next();
       
  1011       if (e != NULL) {
       
  1012         tty->print("%s", os::path_separator());
       
  1013       }
       
  1014     }
       
  1015     tty->print(" ;");
       
  1016   }
       
  1017 }
       
  1018 
   974 void ClassLoader::print_bootclasspath() {
  1019 void ClassLoader::print_bootclasspath() {
   975   ClassPathEntry* e;
  1020   ClassPathEntry* e;
   976   tty->print("[bootclasspath= ");
  1021   tty->print("[bootclasspath= ");
   977 
  1022 
   978   // Print -Xpatch module/path specifications first
  1023   // Print -Xpatch module/path specifications first
   979   if (_xpatch_entries != NULL) {
  1024   if (_xpatch_entries != NULL) {
   980     ResourceMark rm;
  1025     print_module_entry_table(_xpatch_entries);
   981     int num_of_entries = _xpatch_entries->length();
  1026   }
   982     for (int i = 0; i < num_of_entries; i++) {
  1027 
   983       ModuleClassPathList* mpl = _xpatch_entries->at(i);
  1028   // [jimage | exploded modules build]
   984       tty->print("%s=", mpl->module_name()->as_C_string());
  1029   if (has_jrt_entry()) {
   985       e = mpl->module_first_entry();
  1030     // Print the location of the java runtime image
   986       while (e != NULL) {
  1031     tty->print("%s ;", _jrt_entry->name());
   987         tty->print("%s", e->name());
  1032   } else {
   988         e = e->next();
  1033     // Print exploded module build path specifications
   989         if (e != NULL) {
  1034     if (_exploded_entries != NULL) {
   990           tty->print("%s", os::path_separator());
  1035       print_module_entry_table(_exploded_entries);
   991         }
  1036     }
   992       }
  1037   }
   993       tty->print(" ;");
  1038 
   994     }
  1039   // appended entries
   995   }
  1040   e = _first_append_entry;
   996 
       
   997   e = _first_entry;
       
   998   while (e != NULL) {
  1041   while (e != NULL) {
   999     tty->print("%s ;", e->name());
  1042     tty->print("%s ;", e->name());
  1000     e = e->next();
  1043     e = e->next();
  1001   }
  1044   }
  1002   tty->print_cr("]");
  1045   tty->print_cr("]");
  1296   strncpy(&file_name[class_name_len], class_suffix, sizeof(class_suffix));
  1339   strncpy(&file_name[class_name_len], class_suffix, sizeof(class_suffix));
  1297 
  1340 
  1298   return file_name;
  1341   return file_name;
  1299 }
  1342 }
  1300 
  1343 
       
  1344 // Search either the xpatch or exploded build entries for class
       
  1345 ClassFileStream* ClassLoader::search_module_entries(const GrowableArray<ModuleClassPathList*>* const module_list,
       
  1346                                                     const char* const class_name, const char* const file_name, TRAPS) {
       
  1347   ClassFileStream* stream = NULL;
       
  1348 
       
  1349   // Find the class' defining module in the boot loader's module entry table
       
  1350   PackageEntry* pkg_entry = get_package_entry(class_name, ClassLoaderData::the_null_class_loader_data(), CHECK_NULL);
       
  1351   ModuleEntry* mod_entry = (pkg_entry != NULL) ? pkg_entry->module() : NULL;
       
  1352 
       
  1353   // If the module system has not defined java.base yet, then
       
  1354   // classes loaded are assumed to be defined to java.base.
       
  1355   // When java.base is eventually defined by the module system,
       
  1356   // all packages of classes that have been previously loaded
       
  1357   // are verified in ModuleEntryTable::verify_javabase_packages().
       
  1358   if (!Universe::is_module_initialized() &&
       
  1359       !ModuleEntryTable::javabase_defined() &&
       
  1360       mod_entry == NULL) {
       
  1361     mod_entry = ModuleEntryTable::javabase_module();
       
  1362   }
       
  1363 
       
  1364   // The module must be a named module
       
  1365   if (mod_entry != NULL && mod_entry->is_named()) {
       
  1366     int num_of_entries = module_list->length();
       
  1367     const Symbol* class_module_name = mod_entry->name();
       
  1368 
       
  1369     // Loop through all the modules in either the xpatch or exploded entries looking for module
       
  1370     for (int i = 0; i < num_of_entries; i++) {
       
  1371       ModuleClassPathList* module_cpl = module_list->at(i);
       
  1372       Symbol* module_cpl_name = module_cpl->module_name();
       
  1373 
       
  1374       if (module_cpl_name->fast_compare(class_module_name) == 0) {
       
  1375         // Class' module has been located, attempt to load
       
  1376         // the class from the module's ClassPathEntry list.
       
  1377         ClassPathEntry* e = module_cpl->module_first_entry();
       
  1378         while (e != NULL) {
       
  1379           stream = e->open_stream(file_name, CHECK_NULL);
       
  1380           // No context.check is required since CDS is not supported
       
  1381           // for an exploded modules build or if -Xpatch is specified.
       
  1382           if (NULL != stream) {
       
  1383             return stream;
       
  1384           }
       
  1385           e = e->next();
       
  1386         }
       
  1387         // If the module was located, break out even if the class was not
       
  1388         // located successfully from that module's ClassPathEntry list.
       
  1389         // There will not be another valid entry for that module.
       
  1390         return NULL;
       
  1391       }
       
  1392     }
       
  1393   }
       
  1394 
       
  1395   return NULL;
       
  1396 }
       
  1397 
  1301 instanceKlassHandle ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
  1398 instanceKlassHandle ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
  1302   assert(name != NULL, "invariant");
  1399   assert(name != NULL, "invariant");
  1303   assert(THREAD->is_Java_thread(), "must be a JavaThread");
  1400   assert(THREAD->is_Java_thread(), "must be a JavaThread");
  1304 
  1401 
  1305   ResourceMark rm(THREAD);
  1402   ResourceMark rm(THREAD);
  1319   // Lookup stream for parsing .class file
  1416   // Lookup stream for parsing .class file
  1320   ClassFileStream* stream = NULL;
  1417   ClassFileStream* stream = NULL;
  1321   s2 classpath_index = 0;
  1418   s2 classpath_index = 0;
  1322   ClassPathEntry* e = NULL;
  1419   ClassPathEntry* e = NULL;
  1323 
  1420 
  1324   // If DumpSharedSpaces is true, boot loader visibility boundaries are set
  1421   // If DumpSharedSpaces is true boot loader visibility boundaries are set to:
  1325   // to be _first_entry to the end (all path entries). No -Xpatch entries are
  1422   //   - [jimage] + [_first_append_entry to _last_append_entry] (all path entries).
  1326   // included since CDS and AppCDS are not supported if -Xpatch is specified.
  1423   // No -Xpatch entries or exploded module builds are included since CDS
       
  1424   // is not supported if -Xpatch or exploded module builds are used.
  1327   //
  1425   //
  1328   // If search_append_only is true, boot loader visibility boundaries are
  1426   // If search_append_only is true, boot loader visibility boundaries are
  1329   // set to be _first_append_entry to the end. This includes:
  1427   // set to be _first_append_entry to the end. This includes:
  1330   //   [-Xbootclasspath/a]; [jvmti appended entries]
  1428   //   [-Xbootclasspath/a]; [jvmti appended entries]
  1331   //
  1429   //
  1332   // If both DumpSharedSpaces and search_append_only are false, boot loader
  1430   // If both DumpSharedSpaces and search_append_only are false, boot loader
  1333   // visibility boundaries are set to be _first_entry to the entry before
  1431   // visibility boundaries are set to be the -Xpatch entries plus the base piece.
  1334   // the _first_append_entry.  This would include:
  1432   // This would include:
  1335   //   [-Xpatch:<module>=<file>(<pathsep><file>)*];  [exploded build | jimage]
  1433   //   [-Xpatch:<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
  1336   //
  1434   //
  1337   // DumpSharedSpaces and search_append_only are mutually exclusive and cannot
  1435   // DumpSharedSpaces and search_append_only are mutually exclusive and cannot
  1338   // be true at the same time.
  1436   // be true at the same time.
  1339   assert(!(DumpSharedSpaces && search_append_only), "DumpSharedSpaces and search_append_only are both true");
  1437   assert(!(DumpSharedSpaces && search_append_only), "DumpSharedSpaces and search_append_only are both true");
  1340 
  1438 
  1341   // Load Attempt #1: -Xpatch
  1439   // Load Attempt #1: -Xpatch
  1342   // Determine the class' defining module.  If it appears in the _xpatch_entries,
  1440   // Determine the class' defining module.  If it appears in the _xpatch_entries,
  1343   // attempt to load the class from those locations specific to the module.
  1441   // attempt to load the class from those locations specific to the module.
       
  1442   // Specifications to -Xpatch can contain a partial number of classes
       
  1443   // that are part of the overall module definition.  So if a particular class is not
       
  1444   // found within its module specification, the search should continue to Load Attempt #2.
  1344   // Note: The -Xpatch entries are never searched if the boot loader's
  1445   // Note: The -Xpatch entries are never searched if the boot loader's
  1345   //       visibility boundary is limited to only searching the append entries.
  1446   //       visibility boundary is limited to only searching the append entries.
  1346   if (_xpatch_entries != NULL && !search_append_only && !DumpSharedSpaces) {
  1447   if (_xpatch_entries != NULL && !search_append_only && !DumpSharedSpaces) {
  1347     // Find the module in the boot loader's module entry table
  1448     stream = search_module_entries(_xpatch_entries, class_name, file_name, CHECK_NULL);
  1348     PackageEntry* pkg_entry = get_package_entry(class_name, ClassLoaderData::the_null_class_loader_data(), THREAD);
  1449   }
  1349     ModuleEntry* mod_entry = (pkg_entry != NULL) ? pkg_entry->module() : NULL;
  1450 
  1350 
  1451   // Load Attempt #2: [jimage | exploded build]
  1351     // If the module system has not defined java.base yet, then
       
  1352     // classes loaded are assumed to be defined to java.base.
       
  1353     // When java.base is eventually defined by the module system,
       
  1354     // all packages of classes that have been previously loaded
       
  1355     // are verified in ModuleEntryTable::verify_javabase_packages().
       
  1356     if (!Universe::is_module_initialized() &&
       
  1357         !ModuleEntryTable::javabase_defined() &&
       
  1358         mod_entry == NULL) {
       
  1359       mod_entry = ModuleEntryTable::javabase_module();
       
  1360     }
       
  1361 
       
  1362     // The module must be a named module
       
  1363     if (mod_entry != NULL && mod_entry->is_named()) {
       
  1364       int num_of_entries = _xpatch_entries->length();
       
  1365       const Symbol* class_module_name = mod_entry->name();
       
  1366 
       
  1367       // Loop through all the xpatch entries looking for module
       
  1368       for (int i = 0; i < num_of_entries; i++) {
       
  1369         ModuleClassPathList* module_cpl = _xpatch_entries->at(i);
       
  1370         Symbol* module_cpl_name = module_cpl->module_name();
       
  1371 
       
  1372         if (module_cpl_name->fast_compare(class_module_name) == 0) {
       
  1373           // Class' module has been located, attempt to load
       
  1374           // the class from the module's ClassPathEntry list.
       
  1375           e = module_cpl->module_first_entry();
       
  1376           while (e != NULL) {
       
  1377             stream = e->open_stream(file_name, CHECK_NULL);
       
  1378             // No context.check is required since both CDS
       
  1379             // and AppCDS are turned off if -Xpatch is specified.
       
  1380             if (NULL != stream) {
       
  1381               break;
       
  1382             }
       
  1383             e = e->next();
       
  1384           }
       
  1385           // If the module was located in the xpatch entries, break out
       
  1386           // even if the class was not located successfully from that module's
       
  1387           // ClassPathEntry list. There will not be another valid entry for
       
  1388           // that module in the _xpatch_entries array.
       
  1389           break;
       
  1390         }
       
  1391       }
       
  1392     }
       
  1393   }
       
  1394 
       
  1395   // Load Attempt #2: [exploded build | jimage]
       
  1396   if (!search_append_only && (NULL == stream)) {
  1452   if (!search_append_only && (NULL == stream)) {
  1397     e = _first_entry;
  1453     if (has_jrt_entry()) {
  1398     while ((e != NULL) && (e != _first_append_entry)) {
  1454       e = _jrt_entry;
  1399       stream = e->open_stream(file_name, CHECK_NULL);
  1455       stream = _jrt_entry->open_stream(file_name, CHECK_NULL);
  1400       if (!context.check(stream, classpath_index)) {
  1456       if (!context.check(stream, classpath_index)) {
  1401         return NULL;
  1457         return NULL;
  1402       }
  1458       }
  1403       if (NULL != stream) {
  1459     } else {
  1404         break;
  1460       // Exploded build - attempt to locate class in its defining module's location.
  1405       }
  1461       assert(_exploded_entries != NULL, "No exploded build entries present");
  1406       e = e->next();
  1462       stream = search_module_entries(_exploded_entries, class_name, file_name, CHECK_NULL);
  1407       ++classpath_index;
       
  1408     }
  1463     }
  1409   }
  1464   }
  1410 
  1465 
  1411   // Load Attempt #3: [-Xbootclasspath/a]; [jvmti appended entries]
  1466   // Load Attempt #3: [-Xbootclasspath/a]; [jvmti appended entries]
  1412   if ((search_append_only || DumpSharedSpaces) && (NULL == stream)) {
  1467   if ((search_append_only || DumpSharedSpaces) && (NULL == stream)) {
  1413     // For the boot loader append path search, must calculate
  1468     // For the boot loader append path search, the starting classpath_index
  1414     // the starting classpath_index prior to attempting to
  1469     // for the appended piece is always 1 to account for either the
  1415     // load the classfile.
  1470     // _jrt_entry or the _exploded_entries.
  1416     if (search_append_only) {
  1471     assert(classpath_index == 0, "The classpath_index has been incremented incorrectly");
  1417       ClassPathEntry *tmp_e = _first_entry;
  1472     classpath_index = 1;
  1418       while ((tmp_e != NULL) && (tmp_e != _first_append_entry)) {
       
  1419         tmp_e = tmp_e->next();
       
  1420         ++classpath_index;
       
  1421       }
       
  1422     }
       
  1423 
  1473 
  1424     e = _first_append_entry;
  1474     e = _first_append_entry;
  1425     while (e != NULL) {
  1475     while (e != NULL) {
  1426       stream = e->open_stream(file_name, CHECK_NULL);
  1476       stream = e->open_stream(file_name, CHECK_NULL);
  1427       if (!context.check(stream, classpath_index)) {
  1477       if (!context.check(stream, classpath_index)) {
  1595 void classLoader_init1() {
  1645 void classLoader_init1() {
  1596   ClassLoader::initialize();
  1646   ClassLoader::initialize();
  1597 }
  1647 }
  1598 
  1648 
  1599 // Complete the ClassPathEntry setup for the boot loader
  1649 // Complete the ClassPathEntry setup for the boot loader
  1600 void classLoader_init2() {
  1650 void ClassLoader::classLoader_init2(TRAPS) {
       
  1651   // Create the moduleEntry for java.base
       
  1652   create_javabase();
       
  1653 
  1601   // Setup the list of module/path pairs for -Xpatch processing
  1654   // Setup the list of module/path pairs for -Xpatch processing
  1602   // This must be done after the SymbolTable is created in order
  1655   // This must be done after the SymbolTable is created in order
  1603   // to use fast_compare on module names instead of a string compare.
  1656   // to use fast_compare on module names instead of a string compare.
  1604   if (Arguments::get_xpatchprefix() != NULL) {
  1657   if (Arguments::get_xpatchprefix() != NULL) {
  1605     ClassLoader::setup_xpatch_entries();
  1658     setup_xpatch_entries();
  1606   }
  1659   }
  1607 
  1660 
  1608   // Determine if this is an exploded build
  1661   // Setup the initial java.base/path pair for the exploded build entries.
  1609   ClassLoader::set_has_jimage();
  1662   // As more modules are defined during module system initialization, more
       
  1663   // entries will be added to the exploded build array.
       
  1664   if (!has_jrt_entry()) {
       
  1665     assert(!DumpSharedSpaces, "DumpSharedSpaces not supported with exploded module builds");
       
  1666     assert(!UseSharedSpaces, "UsedSharedSpaces not supported with exploded module builds");
       
  1667     add_to_exploded_build_list(vmSymbols::java_base(), CHECK);
       
  1668   }
  1610 }
  1669 }
  1611 
  1670 
  1612 
  1671 
  1613 bool ClassLoader::get_canonical_path(const char* orig, char* out, int len) {
  1672 bool ClassLoader::get_canonical_path(const char* orig, char* out, int len) {
  1614   assert(orig != NULL && out != NULL && len > 0, "bad arguments");
  1673   assert(orig != NULL && out != NULL && len > 0, "bad arguments");
  1649     ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(NULL), vmSymbols::java_base(), NULL, NULL, null_cld);
  1708     ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(NULL), vmSymbols::java_base(), NULL, NULL, null_cld);
  1650     if (jb_module == NULL) {
  1709     if (jb_module == NULL) {
  1651       vm_exit_during_initialization("Unable to create ModuleEntry for java.base");
  1710       vm_exit_during_initialization("Unable to create ModuleEntry for java.base");
  1652     }
  1711     }
  1653     ModuleEntryTable::set_javabase_module(jb_module);
  1712     ModuleEntryTable::set_javabase_module(jb_module);
  1654   }
       
  1655 }
       
  1656 
       
  1657 void ClassLoader::set_has_jimage() {
       
  1658   // Determine if this is an exploded build. When looking for
       
  1659   // the jimage file, only search the piece of the boot
       
  1660   // loader's boot class path which contains [exploded build | jimage].
       
  1661   // Do not search the boot loader's xpatch entries or append path.
       
  1662   ClassPathEntry* e = _first_entry;
       
  1663   ClassPathEntry* last_e = _first_append_entry;
       
  1664   while ((e != NULL) && (e != last_e)) {
       
  1665     JImageFile *jimage = e->jimage();
       
  1666     if (jimage != NULL && e->is_jrt()) {
       
  1667       _has_jimage = true;
       
  1668 #if INCLUDE_CDS
       
  1669       ClassLoader::initialize_module_loader_map(jimage);
       
  1670 #endif
       
  1671       return;
       
  1672     }
       
  1673     e = e->next();
       
  1674   }
  1713   }
  1675 }
  1714 }
  1676 
  1715 
  1677 #ifndef PRODUCT
  1716 #ifndef PRODUCT
  1678 
  1717 
  1760 void ClassLoader::compile_the_world() {
  1799 void ClassLoader::compile_the_world() {
  1761   EXCEPTION_MARK;
  1800   EXCEPTION_MARK;
  1762   HandleMark hm(THREAD);
  1801   HandleMark hm(THREAD);
  1763   ResourceMark rm(THREAD);
  1802   ResourceMark rm(THREAD);
  1764 
  1803 
       
  1804   assert(has_jrt_entry(), "Compile The World not supported with exploded module build");
       
  1805 
  1765   // Find bootstrap loader
  1806   // Find bootstrap loader
  1766   Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
  1807   Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
  1767   // Iterate over all bootstrap class path entries
       
  1768   ClassPathEntry* e = _first_entry;
       
  1769   jlong start = os::javaTimeMillis();
  1808   jlong start = os::javaTimeMillis();
       
  1809 
       
  1810   // Compile the world for the modular java runtime image
       
  1811   _jrt_entry->compile_the_world(system_class_loader, CATCH);
       
  1812 
       
  1813   // Iterate over all bootstrap class path appended entries
       
  1814   ClassPathEntry* e = _first_append_entry;
  1770   while (e != NULL) {
  1815   while (e != NULL) {
  1771     // We stop at "modules" jimage, unless it is the first bootstrap path entry
  1816     assert(!e->is_jrt(), "A modular java runtime image is present on the list of appended entries");
  1772     if (e->is_jrt() && e != _first_entry) break;
       
  1773     e->compile_the_world(system_class_loader, CATCH);
  1817     e->compile_the_world(system_class_loader, CATCH);
  1774     e = e->next();
  1818     e = e->next();
  1775   }
  1819   }
  1776   jlong end = os::javaTimeMillis();
  1820   jlong end = os::javaTimeMillis();
  1777   tty->print_cr("CompileTheWorld : Done (%d classes, %d methods, " JLONG_FORMAT " ms)",
  1821   tty->print_cr("CompileTheWorld : Done (%d classes, %d methods, " JLONG_FORMAT " ms)",