hotspot/src/share/vm/classfile/classLoader.cpp
changeset 40244 b3055c216762
parent 40016 bf6fcd467a7b
child 41183 207b92e69457
equal deleted inserted replaced
40238:4d2a15091124 40244:b3055c216762
   138 PerfCounter*    ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
   138 PerfCounter*    ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
   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::_patch_mod_entries = NULL;
   144 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
   144 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
   145 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
   145 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
   146 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
   146 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
   147 ClassPathEntry* ClassLoader::_last_append_entry  = NULL;
   147 ClassPathEntry* ClassLoader::_last_append_entry  = NULL;
   148 int             ClassLoader::_num_entries        = 0;
   148 int             ClassLoader::_num_entries        = 0;
   683   delete checker;
   683   delete checker;
   684   return result;
   684   return result;
   685 }
   685 }
   686 #endif
   686 #endif
   687 
   687 
   688 // Construct the array of module/path pairs as specified to -Xpatch
   688 // Construct the array of module/path pairs as specified to --patch-module
   689 // for the boot loader to search ahead of the jimage, if the class being
   689 // for the boot loader to search ahead of the jimage, if the class being
   690 // loaded is defined to a module that has been specified to -Xpatch.
   690 // loaded is defined to a module that has been specified to --patch-module.
   691 void ClassLoader::setup_xpatch_entries() {
   691 void ClassLoader::setup_patch_mod_entries() {
   692   Thread* THREAD = Thread::current();
   692   Thread* THREAD = Thread::current();
   693   GrowableArray<ModuleXPatchPath*>* xpatch_args = Arguments::get_xpatchprefix();
   693   GrowableArray<ModulePatchPath*>* patch_mod_args = Arguments::get_patch_mod_prefix();
   694   int num_of_entries = xpatch_args->length();
   694   int num_of_entries = patch_mod_args->length();
   695 
   695 
   696   assert(!DumpSharedSpaces, "DumpSharedSpaces not supported with -Xpatch");
   696   assert(!DumpSharedSpaces, "DumpSharedSpaces not supported with --patch-module");
   697   assert(!UseSharedSpaces, "UseSharedSpaces not supported with -Xpatch");
   697   assert(!UseSharedSpaces, "UseSharedSpaces not supported with --patch-module");
   698 
   698 
   699   // Set up the boot loader's _xpatch_entries list
   699   // Set up the boot loader's _patch_mod_entries list
   700   _xpatch_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
   700   _patch_mod_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
   701 
   701 
   702   for (int i = 0; i < num_of_entries; i++) {
   702   for (int i = 0; i < num_of_entries; i++) {
   703     const char* module_name = (xpatch_args->at(i))->module_name();
   703     const char* module_name = (patch_mod_args->at(i))->module_name();
   704     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);
   705     assert(module_sym != NULL, "Failed to obtain Symbol for module name");
   705     assert(module_sym != NULL, "Failed to obtain Symbol for module name");
   706     ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);
   706     ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);
   707 
   707 
   708     char* class_path = (xpatch_args->at(i))->path_string();
   708     char* class_path = (patch_mod_args->at(i))->path_string();
   709     int len = (int)strlen(class_path);
   709     int len = (int)strlen(class_path);
   710     int end = 0;
   710     int end = 0;
   711     // Iterate over the module's class path entries
   711     // Iterate over the module's class path entries
   712     for (int start = 0; start < len; start = end) {
   712     for (int start = 0; start < len; start = end) {
   713       while (class_path[end] && class_path[end] != os::path_separator()[0]) {
   713       while (class_path[end] && class_path[end] != os::path_separator()[0]) {
   733       while (class_path[end] == os::path_separator()[0]) {
   733       while (class_path[end] == os::path_separator()[0]) {
   734         end++;
   734         end++;
   735       }
   735       }
   736     }
   736     }
   737 
   737 
   738     // Record the module into the list of -Xpatch entries only if
   738     // Record the module into the list of --patch-module entries only if
   739     // valid ClassPathEntrys have been created
   739     // valid ClassPathEntrys have been created
   740     if (module_cpl->module_first_entry() != NULL) {
   740     if (module_cpl->module_first_entry() != NULL) {
   741       _xpatch_entries->push(module_cpl);
   741       _patch_mod_entries->push(module_cpl);
   742     }
   742     }
   743   }
   743   }
   744 }
   744 }
   745 
   745 
   746 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) {
  1018 
  1018 
  1019 void ClassLoader::print_bootclasspath() {
  1019 void ClassLoader::print_bootclasspath() {
  1020   ClassPathEntry* e;
  1020   ClassPathEntry* e;
  1021   tty->print("[bootclasspath= ");
  1021   tty->print("[bootclasspath= ");
  1022 
  1022 
  1023   // Print -Xpatch module/path specifications first
  1023   // Print --patch-module module/path specifications first
  1024   if (_xpatch_entries != NULL) {
  1024   if (_patch_mod_entries != NULL) {
  1025     print_module_entry_table(_xpatch_entries);
  1025     print_module_entry_table(_patch_mod_entries);
  1026   }
  1026   }
  1027 
  1027 
  1028   // [jimage | exploded modules build]
  1028   // [jimage | exploded modules build]
  1029   if (has_jrt_entry()) {
  1029   if (has_jrt_entry()) {
  1030     // Print the location of the java runtime image
  1030     // Print the location of the java runtime image
  1339   strncpy(&file_name[class_name_len], class_suffix, sizeof(class_suffix));
  1339   strncpy(&file_name[class_name_len], class_suffix, sizeof(class_suffix));
  1340 
  1340 
  1341   return file_name;
  1341   return file_name;
  1342 }
  1342 }
  1343 
  1343 
  1344 // Search either the xpatch or exploded build entries for class
  1344 // Search either the patch-module or exploded build entries for class
  1345 ClassFileStream* ClassLoader::search_module_entries(const GrowableArray<ModuleClassPathList*>* const module_list,
  1345 ClassFileStream* ClassLoader::search_module_entries(const GrowableArray<ModuleClassPathList*>* const module_list,
  1346                                                     const char* const class_name, const char* const file_name, TRAPS) {
  1346                                                     const char* const class_name, const char* const file_name, TRAPS) {
  1347   ClassFileStream* stream = NULL;
  1347   ClassFileStream* stream = NULL;
  1348 
  1348 
  1349   // Find the class' defining module in the boot loader's module entry table
  1349   // Find the class' defining module in the boot loader's module entry table
  1364   // The module must be a named module
  1364   // The module must be a named module
  1365   if (mod_entry != NULL && mod_entry->is_named()) {
  1365   if (mod_entry != NULL && mod_entry->is_named()) {
  1366     int num_of_entries = module_list->length();
  1366     int num_of_entries = module_list->length();
  1367     const Symbol* class_module_name = mod_entry->name();
  1367     const Symbol* class_module_name = mod_entry->name();
  1368 
  1368 
  1369     // Loop through all the modules in either the xpatch or exploded entries looking for module
  1369     // Loop through all the modules in either the patch-module or exploded entries looking for module
  1370     for (int i = 0; i < num_of_entries; i++) {
  1370     for (int i = 0; i < num_of_entries; i++) {
  1371       ModuleClassPathList* module_cpl = module_list->at(i);
  1371       ModuleClassPathList* module_cpl = module_list->at(i);
  1372       Symbol* module_cpl_name = module_cpl->module_name();
  1372       Symbol* module_cpl_name = module_cpl->module_name();
  1373 
  1373 
  1374       if (module_cpl_name->fast_compare(class_module_name) == 0) {
  1374       if (module_cpl_name->fast_compare(class_module_name) == 0) {
  1376         // the class from the module's ClassPathEntry list.
  1376         // the class from the module's ClassPathEntry list.
  1377         ClassPathEntry* e = module_cpl->module_first_entry();
  1377         ClassPathEntry* e = module_cpl->module_first_entry();
  1378         while (e != NULL) {
  1378         while (e != NULL) {
  1379           stream = e->open_stream(file_name, CHECK_NULL);
  1379           stream = e->open_stream(file_name, CHECK_NULL);
  1380           // No context.check is required since CDS is not supported
  1380           // No context.check is required since CDS is not supported
  1381           // for an exploded modules build or if -Xpatch is specified.
  1381           // for an exploded modules build or if --patch-module is specified.
  1382           if (NULL != stream) {
  1382           if (NULL != stream) {
  1383             return stream;
  1383             return stream;
  1384           }
  1384           }
  1385           e = e->next();
  1385           e = e->next();
  1386         }
  1386         }
  1418   s2 classpath_index = 0;
  1418   s2 classpath_index = 0;
  1419   ClassPathEntry* e = NULL;
  1419   ClassPathEntry* e = NULL;
  1420 
  1420 
  1421   // If DumpSharedSpaces is true boot loader visibility boundaries are set to:
  1421   // If DumpSharedSpaces is true boot loader visibility boundaries are set to:
  1422   //   - [jimage] + [_first_append_entry to _last_append_entry] (all path entries).
  1422   //   - [jimage] + [_first_append_entry to _last_append_entry] (all path entries).
  1423   // No -Xpatch entries or exploded module builds are included since CDS
  1423   // No --patch-module entries or exploded module builds are included since CDS
  1424   // is not supported if -Xpatch or exploded module builds are used.
  1424   // is not supported if --patch-module or exploded module builds are used.
  1425   //
  1425   //
  1426   // If search_append_only is true, boot loader visibility boundaries are
  1426   // If search_append_only is true, boot loader visibility boundaries are
  1427   // set to be _first_append_entry to the end. This includes:
  1427   // set to be _first_append_entry to the end. This includes:
  1428   //   [-Xbootclasspath/a]; [jvmti appended entries]
  1428   //   [-Xbootclasspath/a]; [jvmti appended entries]
  1429   //
  1429   //
  1430   // If both DumpSharedSpaces and search_append_only are false, boot loader
  1430   // If both DumpSharedSpaces and search_append_only are false, boot loader
  1431   // visibility boundaries are set to be the -Xpatch entries plus the base piece.
  1431   // visibility boundaries are set to be the --patch-module entries plus the base piece.
  1432   // This would include:
  1432   // This would include:
  1433   //   [-Xpatch:<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
  1433   //   [--patch-module=<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
  1434   //
  1434   //
  1435   // DumpSharedSpaces and search_append_only are mutually exclusive and cannot
  1435   // DumpSharedSpaces and search_append_only are mutually exclusive and cannot
  1436   // be true at the same time.
  1436   // be true at the same time.
  1437   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");
  1438 
  1438 
  1439   // Load Attempt #1: -Xpatch
  1439   // Load Attempt #1: --patch-module
  1440   // Determine the class' defining module.  If it appears in the _xpatch_entries,
  1440   // Determine the class' defining module.  If it appears in the _patch_mod_entries,
  1441   // 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
  1442   // Specifications to --patch-module can contain a partial number of classes
  1443   // that are part of the overall module definition.  So if a particular class is not
  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.
  1444   // found within its module specification, the search should continue to Load Attempt #2.
  1445   // Note: The -Xpatch entries are never searched if the boot loader's
  1445   // Note: The --patch-module entries are never searched if the boot loader's
  1446   //       visibility boundary is limited to only searching the append entries.
  1446   //       visibility boundary is limited to only searching the append entries.
  1447   if (_xpatch_entries != NULL && !search_append_only && !DumpSharedSpaces) {
  1447   if (_patch_mod_entries != NULL && !search_append_only && !DumpSharedSpaces) {
  1448     stream = search_module_entries(_xpatch_entries, class_name, file_name, CHECK_NULL);
  1448     stream = search_module_entries(_patch_mod_entries, class_name, file_name, CHECK_NULL);
  1449   }
  1449   }
  1450 
  1450 
  1451   // Load Attempt #2: [jimage | exploded build]
  1451   // Load Attempt #2: [jimage | exploded build]
  1452   if (!search_append_only && (NULL == stream)) {
  1452   if (!search_append_only && (NULL == stream)) {
  1453     if (has_jrt_entry()) {
  1453     if (has_jrt_entry()) {
  1648 // Complete the ClassPathEntry setup for the boot loader
  1648 // Complete the ClassPathEntry setup for the boot loader
  1649 void ClassLoader::classLoader_init2(TRAPS) {
  1649 void ClassLoader::classLoader_init2(TRAPS) {
  1650   // Create the moduleEntry for java.base
  1650   // Create the moduleEntry for java.base
  1651   create_javabase();
  1651   create_javabase();
  1652 
  1652 
  1653   // Setup the list of module/path pairs for -Xpatch processing
  1653   // Setup the list of module/path pairs for --patch-module processing
  1654   // This must be done after the SymbolTable is created in order
  1654   // This must be done after the SymbolTable is created in order
  1655   // to use fast_compare on module names instead of a string compare.
  1655   // to use fast_compare on module names instead of a string compare.
  1656   if (Arguments::get_xpatchprefix() != NULL) {
  1656   if (Arguments::get_patch_mod_prefix() != NULL) {
  1657     setup_xpatch_entries();
  1657     setup_patch_mod_entries();
  1658   }
  1658   }
  1659 
  1659 
  1660   // Setup the initial java.base/path pair for the exploded build entries.
  1660   // Setup the initial java.base/path pair for the exploded build entries.
  1661   // As more modules are defined during module system initialization, more
  1661   // As more modules are defined during module system initialization, more
  1662   // entries will be added to the exploded build array.
  1662   // entries will be added to the exploded build array.