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

src/hotspot/share/classfile/classLoader.cpp

Print this page




 722     }
 723   }
 724 }
 725 
 726 void ClassLoader::add_to_module_path_entries(const char* path,
 727                                              ClassPathEntry* entry) {
 728   assert(entry != NULL, "ClassPathEntry should not be NULL");
 729   assert(DumpSharedSpaces, "dump time only");
 730 
 731   // The entry does not exist, add to the list
 732   if (_module_path_entries == NULL) {
 733     assert(_last_module_path_entry == NULL, "Sanity");
 734     _module_path_entries = _last_module_path_entry = entry;
 735   } else {
 736     _last_module_path_entry->set_next(entry);
 737     _last_module_path_entry = entry;
 738   }
 739 }
 740 
 741 // Add a module path to the _module_path_entries list.
 742 void ClassLoader::update_module_path_entry_list(const char *path,
 743                                                bool throw_exception) {
 744   assert(DumpSharedSpaces, "dump time only");
 745   struct stat st;
 746   int ret = os::stat(path, &st);
 747   assert(ret == 0, "module path must exist");
 748   // File or directory found
 749   ClassPathEntry* new_entry = NULL;
 750   Thread* THREAD = Thread::current();
 751   new_entry = create_class_path_entry(path, &st, throw_exception,
 752                                       false /*is_boot_append */, CHECK);
 753   if (new_entry == NULL) {
 754     return;
 755   }
 756 
 757   add_to_module_path_entries(path, new_entry);
 758   return;
 759 }
 760 
 761 void ClassLoader::setup_module_search_path(const char* path) {
 762   check_shared_classpath(path);
 763   update_module_path_entry_list(path);
 764 }
 765 #endif // INCLUDE_CDS
 766 
 767 // Construct the array of module/path pairs as specified to --patch-module
 768 // for the boot loader to search ahead of the jimage, if the class being
 769 // loaded is defined to a module that has been specified to --patch-module.
 770 void ClassLoader::setup_patch_mod_entries() {
 771   Thread* THREAD = Thread::current();
 772   GrowableArray<ModulePatchPath*>* patch_mod_args = Arguments::get_patch_mod_prefix();
 773   int num_of_entries = patch_mod_args->length();
 774 
 775 
 776   // Set up the boot loader's _patch_mod_entries list
 777   _patch_mod_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
 778 
 779   for (int i = 0; i < num_of_entries; i++) {
 780     const char* module_name = (patch_mod_args->at(i))->module_name();
 781     Symbol* const module_sym = SymbolTable::lookup(module_name, (int)strlen(module_name), CHECK);
 782     assert(module_sym != NULL, "Failed to obtain Symbol for module name");
 783     ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);


1557   if (strncmp(source, "file:", 5) == 0) {
1558     // file: protocol path could start with file:/ or file:///
1559     // locate the char after all the forward slashes
1560     int offset = 5;
1561     while (*(source + offset) == '/') {
1562         offset++;
1563     }
1564     source += offset;
1565   // for non-windows platforms, move back one char as the path begins with a '/'
1566 #ifndef _WINDOWS
1567     source -= 1;
1568 #endif
1569   } else if (strncmp(source, "jrt:/", 5) == 0) {
1570     source += 5;
1571   }
1572   return source;
1573 }
1574 
1575 // Record the shared classpath index and loader type for classes loaded
1576 // by the builtin loaders at dump time.
1577 void ClassLoader::record_result(InstanceKlass* ik, const ClassFileStream* stream) {
1578   assert(DumpSharedSpaces, "sanity");
1579   assert(stream != NULL, "sanity");
1580 
1581   if (ik->is_anonymous()) {
1582     // We do not archive anonymous classes.
1583     return;
1584   }
1585 
1586   oop loader = ik->class_loader();
1587   char* src = (char*)stream->source();
1588   if (src == NULL) {
1589     if (loader == NULL) {
1590       // JFR classes
1591       ik->set_shared_classpath_index(0);
1592       ik->set_class_loader_type(ClassLoader::BOOT_LOADER);
1593     }
1594     return;
1595   }
1596 
1597   assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build");
1598 
1599   ResourceMark rm;
1600   Thread* THREAD = Thread::current();
1601   int classpath_index = -1;
1602   PackageEntry* pkg_entry = ik->package();
1603 
1604   if (FileMapInfo::get_number_of_shared_paths() > 0) {
1605     char* canonical_path = NEW_RESOURCE_ARRAY(char, JVM_MAXPATHLEN);
1606 
1607     // save the path from the file: protocol or the module name from the jrt: protocol
1608     // if no protocol prefix is found, path is the same as stream->source()
1609     char* path = skip_uri_protocol(src);
1610     for (int i = 0; i < FileMapInfo::get_number_of_shared_paths(); i++) {
1611       SharedClassPathEntry* ent = FileMapInfo::shared_path(i);
1612       if (get_canonical_path(ent->name(), canonical_path, JVM_MAXPATHLEN)) {
1613         // If the path (from the class stream source) is the same as the shared
1614         // class or module path, then we have a match.
1615         if (strcmp(canonical_path, os::native_path((char*)path)) == 0) {
1616           // NULL pkg_entry and pkg_entry in an unnamed module implies the class
1617           // is from the -cp or -Xbootclasspath/a.

1618           if ((pkg_entry == NULL) || (pkg_entry->in_unnamed_module())) {
1619             // Ensure the index is within the -cp range before assigning
1620             // to the classpath_index.
1621             if (SystemDictionary::is_system_class_loader(loader) &&
1622                 (i >= ClassLoaderExt::app_class_paths_start_index()) &&
1623                 (i < ClassLoaderExt::app_module_paths_start_index())) {
1624               classpath_index = i;
1625               break;
1626             } else {
1627               if ((i >= 1) &&
1628                   (i < ClassLoaderExt::app_class_paths_start_index())) {
1629                 // The class must be from -Xbootclasspath/a

1630                 assert(loader == NULL, "sanity");
1631                 classpath_index = i;
1632                 break;
1633               }
1634             }
1635           } else {
1636             // A class from a named module from the --module-path. Ensure the index is
1637             // within the --module-path range before assigning to the classpath_index.
1638             if ((pkg_entry != NULL) && !(pkg_entry->in_unnamed_module()) && (i > 0)) {
1639               if (i >= ClassLoaderExt::app_module_paths_start_index() &&
1640                   i < FileMapInfo::get_number_of_shared_paths()) {
1641                 classpath_index = i;
1642                 break;
1643               }
1644             }
1645           }
1646         }
1647         // for index 0 and the stream->source() is the modules image or has the jrt: protocol.
1648         // The class must be from the runtime modules image.
1649         if (i == 0 && (is_modules_image(src) || string_starts_with(src, "jrt:"))) {


1741   load_zip_library();
1742   // lookup jimage library entry points
1743   load_jimage_library();
1744 #if INCLUDE_CDS
1745   // initialize search path
1746   if (DumpSharedSpaces) {
1747     _shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info();
1748   }
1749 #endif
1750   setup_bootstrap_search_path();
1751 }
1752 
1753 #if INCLUDE_CDS
1754 void ClassLoader::initialize_shared_path() {
1755   if (DumpSharedSpaces) {
1756     ClassLoaderExt::setup_search_paths();
1757     _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1758   }
1759 }
1760 
1761 void ClassLoader::initialize_module_path() {
1762   if (DumpSharedSpaces) {
1763     ClassLoaderExt::setup_module_paths();
1764     FileMapInfo::allocate_shared_path_table();
1765   }
1766 }
1767 #endif
1768 
1769 jlong ClassLoader::classloader_time_ms() {
1770   return UsePerfData ?
1771     Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1772 }
1773 
1774 jlong ClassLoader::class_init_count() {
1775   return UsePerfData ? _perf_classes_inited->get_value() : -1;
1776 }
1777 
1778 jlong ClassLoader::class_init_time_ms() {
1779   return UsePerfData ?
1780     Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1781 }
1782 
1783 jlong ClassLoader::class_verify_time_ms() {




 722     }
 723   }
 724 }
 725 
 726 void ClassLoader::add_to_module_path_entries(const char* path,
 727                                              ClassPathEntry* entry) {
 728   assert(entry != NULL, "ClassPathEntry should not be NULL");
 729   assert(DumpSharedSpaces, "dump time only");
 730 
 731   // The entry does not exist, add to the list
 732   if (_module_path_entries == NULL) {
 733     assert(_last_module_path_entry == NULL, "Sanity");
 734     _module_path_entries = _last_module_path_entry = entry;
 735   } else {
 736     _last_module_path_entry->set_next(entry);
 737     _last_module_path_entry = entry;
 738   }
 739 }
 740 
 741 // Add a module path to the _module_path_entries list.
 742 void ClassLoader::update_module_path_entry_list(const char *path, TRAPS) {

 743   assert(DumpSharedSpaces, "dump time only");
 744   struct stat st;
 745   int ret = os::stat(path, &st);
 746   assert(ret == 0, "module path must exist");
 747   // File or directory found
 748   ClassPathEntry* new_entry = NULL;
 749   new_entry = create_class_path_entry(path, &st, true /* throw_exception */,

 750                                       false /*is_boot_append */, CHECK);
 751   if (new_entry == NULL) {
 752     return;
 753   }
 754 
 755   add_to_module_path_entries(path, new_entry);
 756   return;
 757 }
 758 
 759 void ClassLoader::setup_module_search_path(const char* path, TRAPS) {
 760   check_shared_classpath(path);
 761   update_module_path_entry_list(path, THREAD);
 762 }
 763 #endif // INCLUDE_CDS
 764 
 765 // Construct the array of module/path pairs as specified to --patch-module
 766 // for the boot loader to search ahead of the jimage, if the class being
 767 // loaded is defined to a module that has been specified to --patch-module.
 768 void ClassLoader::setup_patch_mod_entries() {
 769   Thread* THREAD = Thread::current();
 770   GrowableArray<ModulePatchPath*>* patch_mod_args = Arguments::get_patch_mod_prefix();
 771   int num_of_entries = patch_mod_args->length();
 772 
 773 
 774   // Set up the boot loader's _patch_mod_entries list
 775   _patch_mod_entries = new (ResourceObj::C_HEAP, mtModule) GrowableArray<ModuleClassPathList*>(num_of_entries, true);
 776 
 777   for (int i = 0; i < num_of_entries; i++) {
 778     const char* module_name = (patch_mod_args->at(i))->module_name();
 779     Symbol* const module_sym = SymbolTable::lookup(module_name, (int)strlen(module_name), CHECK);
 780     assert(module_sym != NULL, "Failed to obtain Symbol for module name");
 781     ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);


1555   if (strncmp(source, "file:", 5) == 0) {
1556     // file: protocol path could start with file:/ or file:///
1557     // locate the char after all the forward slashes
1558     int offset = 5;
1559     while (*(source + offset) == '/') {
1560         offset++;
1561     }
1562     source += offset;
1563   // for non-windows platforms, move back one char as the path begins with a '/'
1564 #ifndef _WINDOWS
1565     source -= 1;
1566 #endif
1567   } else if (strncmp(source, "jrt:/", 5) == 0) {
1568     source += 5;
1569   }
1570   return source;
1571 }
1572 
1573 // Record the shared classpath index and loader type for classes loaded
1574 // by the builtin loaders at dump time.
1575 void ClassLoader::record_result(InstanceKlass* ik, const ClassFileStream* stream, TRAPS) {
1576   assert(DumpSharedSpaces, "sanity");
1577   assert(stream != NULL, "sanity");
1578 
1579   if (ik->is_anonymous()) {
1580     // We do not archive anonymous classes.
1581     return;
1582   }
1583 
1584   oop loader = ik->class_loader();
1585   char* src = (char*)stream->source();
1586   if (src == NULL) {
1587     if (loader == NULL) {
1588       // JFR classes
1589       ik->set_shared_classpath_index(0);
1590       ik->set_class_loader_type(ClassLoader::BOOT_LOADER);
1591     }
1592     return;
1593   }
1594 
1595   assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build");
1596 
1597   ResourceMark rm(THREAD);

1598   int classpath_index = -1;
1599   PackageEntry* pkg_entry = ik->package();
1600 
1601   if (FileMapInfo::get_number_of_shared_paths() > 0) {
1602     char* canonical_path = NEW_RESOURCE_ARRAY(char, JVM_MAXPATHLEN);
1603 
1604     // save the path from the file: protocol or the module name from the jrt: protocol
1605     // if no protocol prefix is found, path is the same as stream->source()
1606     char* path = skip_uri_protocol(src);
1607     for (int i = 0; i < FileMapInfo::get_number_of_shared_paths(); i++) {
1608       SharedClassPathEntry* ent = FileMapInfo::shared_path(i);
1609       if (get_canonical_path(ent->name(), canonical_path, JVM_MAXPATHLEN)) {
1610         // If the path (from the class stream source) is the same as the shared
1611         // class or module path, then we have a match.
1612         if (strcmp(canonical_path, os::native_path((char*)path)) == 0) {
1613           // NULL pkg_entry and pkg_entry in an unnamed module implies the class
1614           // is from the -cp or boot loader append path which consists of -Xbootclasspath/a
1615           // and jvmti appended entries.
1616           if ((pkg_entry == NULL) || (pkg_entry->in_unnamed_module())) {
1617             // Ensure the index is within the -cp range before assigning
1618             // to the classpath_index.
1619             if (SystemDictionary::is_system_class_loader(loader) &&
1620                 (i >= ClassLoaderExt::app_class_paths_start_index()) &&
1621                 (i < ClassLoaderExt::app_module_paths_start_index())) {
1622               classpath_index = i;
1623               break;
1624             } else {
1625               if ((i >= 1) &&
1626                   (i < ClassLoaderExt::app_class_paths_start_index())) {
1627                 // The class must be from boot loader append path which consists of
1628                 // -Xbootclasspath/a and jvmti appended entries.
1629                 assert(loader == NULL, "sanity");
1630                 classpath_index = i;
1631                 break;
1632               }
1633             }
1634           } else {
1635             // A class from a named module from the --module-path. Ensure the index is
1636             // within the --module-path range before assigning to the classpath_index.
1637             if ((pkg_entry != NULL) && !(pkg_entry->in_unnamed_module()) && (i > 0)) {
1638               if (i >= ClassLoaderExt::app_module_paths_start_index() &&
1639                   i < FileMapInfo::get_number_of_shared_paths()) {
1640                 classpath_index = i;
1641                 break;
1642               }
1643             }
1644           }
1645         }
1646         // for index 0 and the stream->source() is the modules image or has the jrt: protocol.
1647         // The class must be from the runtime modules image.
1648         if (i == 0 && (is_modules_image(src) || string_starts_with(src, "jrt:"))) {


1740   load_zip_library();
1741   // lookup jimage library entry points
1742   load_jimage_library();
1743 #if INCLUDE_CDS
1744   // initialize search path
1745   if (DumpSharedSpaces) {
1746     _shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info();
1747   }
1748 #endif
1749   setup_bootstrap_search_path();
1750 }
1751 
1752 #if INCLUDE_CDS
1753 void ClassLoader::initialize_shared_path() {
1754   if (DumpSharedSpaces) {
1755     ClassLoaderExt::setup_search_paths();
1756     _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1757   }
1758 }
1759 
1760 void ClassLoader::initialize_module_path(TRAPS) {
1761   if (DumpSharedSpaces) {
1762     ClassLoaderExt::setup_module_paths(THREAD);
1763     FileMapInfo::allocate_shared_path_table();
1764   }
1765 }
1766 #endif
1767 
1768 jlong ClassLoader::classloader_time_ms() {
1769   return UsePerfData ?
1770     Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1771 }
1772 
1773 jlong ClassLoader::class_init_count() {
1774   return UsePerfData ? _perf_classes_inited->get_value() : -1;
1775 }
1776 
1777 jlong ClassLoader::class_init_time_ms() {
1778   return UsePerfData ?
1779     Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1780 }
1781 
1782 jlong ClassLoader::class_verify_time_ms() {


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