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




1535   }
1536 
1537   oop loader = ik->class_loader();
1538   char* src = (char*)stream->source();
1539   if (src == NULL) {
1540     if (loader == NULL) {
1541       // JFR classes
1542       ik->set_shared_classpath_index(0);
1543       ik->set_class_loader_type(ClassLoader::BOOT_LOADER);
1544     }
1545     return;
1546   }
1547 
1548   assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build");
1549 
1550   ResourceMark rm(THREAD);
1551   int classpath_index = -1;
1552   PackageEntry* pkg_entry = ik->package();
1553 
1554   if (FileMapInfo::get_number_of_shared_paths() > 0) {
1555     char* canonical_path = NEW_RESOURCE_ARRAY(char, JVM_MAXPATHLEN);
1556 
1557     // save the path from the file: protocol or the module name from the jrt: protocol
1558     // if no protocol prefix is found, path is the same as stream->source()
1559     char* path = skip_uri_protocol(src);






1560     for (int i = 0; i < FileMapInfo::get_number_of_shared_paths(); i++) {
1561       SharedClassPathEntry* ent = FileMapInfo::shared_path(i);
1562       if (get_canonical_path(ent->name(), canonical_path, JVM_MAXPATHLEN)) {




1563         // If the path (from the class stream source) is the same as the shared
1564         // class or module path, then we have a match.
1565         if (strcmp(canonical_path, os::native_path((char*)path)) == 0) {
1566           // NULL pkg_entry and pkg_entry in an unnamed module implies the class
1567           // is from the -cp or boot loader append path which consists of -Xbootclasspath/a
1568           // and jvmti appended entries.
1569           if ((pkg_entry == NULL) || (pkg_entry->in_unnamed_module())) {
1570             // Ensure the index is within the -cp range before assigning
1571             // to the classpath_index.
1572             if (SystemDictionary::is_system_class_loader(loader) &&
1573                 (i >= ClassLoaderExt::app_class_paths_start_index()) &&
1574                 (i < ClassLoaderExt::app_module_paths_start_index())) {
1575               classpath_index = i;
1576               break;
1577             } else {
1578               if ((i >= 1) &&
1579                   (i < ClassLoaderExt::app_class_paths_start_index())) {
1580                 // The class must be from boot loader append path which consists of
1581                 // -Xbootclasspath/a and jvmti appended entries.
1582                 assert(loader == NULL, "sanity");
1583                 classpath_index = i;
1584                 break;
1585               }
1586             }
1587           } else {
1588             // A class from a named module from the --module-path. Ensure the index is
1589             // within the --module-path range before assigning to the classpath_index.
1590             if ((pkg_entry != NULL) && !(pkg_entry->in_unnamed_module()) && (i > 0)) {
1591               if (i >= ClassLoaderExt::app_module_paths_start_index() &&
1592                   i < FileMapInfo::get_number_of_shared_paths()) {
1593                 classpath_index = i;
1594                 break;
1595               }
1596             }
1597           }
1598         }
1599         // for index 0 and the stream->source() is the modules image or has the jrt: protocol.
1600         // The class must be from the runtime modules image.
1601         if (i == 0 && (is_modules_image(src) || string_starts_with(src, "jrt:"))) {
1602           classpath_index = i;
1603           break;
1604         }
1605       }
1606     }
1607 
1608     // No path entry found for this class. Must be a shared class loaded by the
1609     // user defined classloader.
1610     if (classpath_index < 0) {
1611       assert(ik->shared_classpath_index() < 0, "Sanity");
1612       return;
1613     }
1614   } else {
1615     // The shared path table is set up after module system initialization.
1616     // The path table contains no entry before that. Any classes loaded prior
1617     // to the setup of the shared path table must be from the modules image.
1618     assert(is_modules_image(src), "stream must be from modules image");
1619     assert(FileMapInfo::get_number_of_shared_paths() == 0, "shared path table must not have been setup");
1620     classpath_index = 0;
1621   }
1622 
1623   const char* const class_name = ik->name()->as_C_string();
1624   const char* const file_name = file_name_for_class_name(class_name,




1535   }
1536 
1537   oop loader = ik->class_loader();
1538   char* src = (char*)stream->source();
1539   if (src == NULL) {
1540     if (loader == NULL) {
1541       // JFR classes
1542       ik->set_shared_classpath_index(0);
1543       ik->set_class_loader_type(ClassLoader::BOOT_LOADER);
1544     }
1545     return;
1546   }
1547 
1548   assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build");
1549 
1550   ResourceMark rm(THREAD);
1551   int classpath_index = -1;
1552   PackageEntry* pkg_entry = ik->package();
1553 
1554   if (FileMapInfo::get_number_of_shared_paths() > 0) {
1555     char* canonical_path_table_entry = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, JVM_MAXPATHLEN);
1556 
1557     // save the path from the file: protocol or the module name from the jrt: protocol
1558     // if no protocol prefix is found, path is the same as stream->source()
1559     char* path = skip_uri_protocol(src);
1560     char* canonical_class_src_path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, JVM_MAXPATHLEN);
1561     if (!get_canonical_path(path, canonical_class_src_path, JVM_MAXPATHLEN)) {
1562       tty->print_cr("Bad pathname %s. CDS dump aborted.",
1563         path);
1564       vm_exit(1);
1565     }
1566     for (int i = 0; i < FileMapInfo::get_number_of_shared_paths(); i++) {
1567       SharedClassPathEntry* ent = FileMapInfo::shared_path(i);
1568       if (!get_canonical_path(ent->name(), canonical_path_table_entry, JVM_MAXPATHLEN)) {
1569         tty->print_cr("Bad pathname %s. CDS dump aborted.",
1570           ent->name());
1571         vm_exit(1);
1572       }
1573       // If the path (from the class stream source) is the same as the shared
1574       // class or module path, then we have a match.
1575       if (strcmp(canonical_path_table_entry, canonical_class_src_path) == 0) {
1576         // NULL pkg_entry and pkg_entry in an unnamed module implies the class
1577         // is from the -cp or boot loader append path which consists of -Xbootclasspath/a
1578         // and jvmti appended entries.
1579         if ((pkg_entry == NULL) || (pkg_entry->in_unnamed_module())) {
1580           // Ensure the index is within the -cp range before assigning
1581           // to the classpath_index.
1582           if (SystemDictionary::is_system_class_loader(loader) &&
1583               (i >= ClassLoaderExt::app_class_paths_start_index()) &&
1584               (i < ClassLoaderExt::app_module_paths_start_index())) {
1585             classpath_index = i;
1586             break;
1587           } else {
1588             if ((i >= 1) &&
1589                 (i < ClassLoaderExt::app_class_paths_start_index())) {
1590               // The class must be from boot loader append path which consists of
1591               // -Xbootclasspath/a and jvmti appended entries.
1592               assert(loader == NULL, "sanity");
1593               classpath_index = i;
1594               break;
1595             }
1596           }
1597         } else {
1598           // A class from a named module from the --module-path. Ensure the index is
1599           // within the --module-path range before assigning to the classpath_index.
1600           if ((pkg_entry != NULL) && !(pkg_entry->in_unnamed_module()) && (i > 0)) {
1601             if (i >= ClassLoaderExt::app_module_paths_start_index() &&
1602                 i < FileMapInfo::get_number_of_shared_paths()) {
1603               classpath_index = i;
1604               break;
1605             }
1606           }
1607         }
1608       }
1609       // for index 0 and the stream->source() is the modules image or has the jrt: protocol.
1610       // The class must be from the runtime modules image.
1611       if (i == 0 && (is_modules_image(src) || string_starts_with(src, "jrt:"))) {
1612         classpath_index = i;
1613         break;

1614       }
1615     }
1616 
1617     // No path entry found for this class. Must be a shared class loaded by the
1618     // user defined classloader.
1619     if (classpath_index < 0) {
1620       assert(ik->shared_classpath_index() < 0, "Sanity");
1621       return;
1622     }
1623   } else {
1624     // The shared path table is set up after module system initialization.
1625     // The path table contains no entry before that. Any classes loaded prior
1626     // to the setup of the shared path table must be from the modules image.
1627     assert(is_modules_image(src), "stream must be from modules image");
1628     assert(FileMapInfo::get_number_of_shared_paths() == 0, "shared path table must not have been setup");
1629     classpath_index = 0;
1630   }
1631 
1632   const char* const class_name = ik->name()->as_C_string();
1633   const char* const file_name = file_name_for_class_name(class_name,


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