640 // Currently AppCDS only archives classes from the run-time image, the
641 // -Xbootclasspath/a path, the class path, and the module path.
642 //
643 // Check if a shared class can be loaded by the specific classloader. Following
644 // are the "visible" archived classes for different classloaders.
645 //
646 // NULL classloader:
647 // - see SystemDictionary::is_shared_class_visible()
648 // Platform classloader:
649 // - Module class from runtime image. ModuleEntry must be defined in the
650 // classloader.
651 // App classloader:
652 // - Module Class from runtime image and module path. ModuleEntry must be defined in the
653 // classloader.
654 // - Class from -cp. The class must have no PackageEntry defined in any of the
655 // boot/platform/app classloader, or must be in the unnamed module defined in the
656 // AppClassLoader.
657 bool SystemDictionaryShared::is_shared_class_visible_for_classloader(
658 InstanceKlass* ik,
659 Handle class_loader,
660 const char* pkg_string,
661 Symbol* pkg_name,
662 PackageEntry* pkg_entry,
663 ModuleEntry* mod_entry,
664 TRAPS) {
665 assert(class_loader.not_null(), "Class loader should not be NULL");
666 assert(Universe::is_module_initialized(), "Module system is not initialized");
667 ResourceMark rm(THREAD);
668
669 int path_index = ik->shared_classpath_index();
670 SharedClassPathEntry* ent =
671 (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
672
673 if (SystemDictionary::is_platform_class_loader(class_loader())) {
674 assert(ent != NULL, "shared class for PlatformClassLoader should have valid SharedClassPathEntry");
675 // The PlatformClassLoader can only load archived class originated from the
676 // run-time image. The class' PackageEntry/ModuleEntry must be
677 // defined by the PlatformClassLoader.
678 if (mod_entry != NULL) {
679 // PackageEntry/ModuleEntry is found in the classloader. Check if the
680 // ModuleEntry's location agrees with the archived class' origination.
681 if (ent->is_modules_image() && mod_entry->location()->starts_with("jrt:")) {
682 return true; // Module class from the runtime image
683 }
684 }
685 } else if (SystemDictionary::is_system_class_loader(class_loader())) {
686 assert(ent != NULL, "shared class for system loader should have valid SharedClassPathEntry");
687 if (pkg_string == NULL) {
688 // The archived class is in the unnamed package. Currently, the boot image
689 // does not contain any class in the unnamed package.
690 assert(!ent->is_modules_image(), "Class in the unnamed package must be from the classpath");
691 if (path_index >= ClassLoaderExt::app_class_paths_start_index()) {
692 assert(path_index < ClassLoaderExt::app_module_paths_start_index(), "invalid path_index");
693 return true;
694 }
695 } else {
696 // Check if this is from a PackageEntry/ModuleEntry defined in the AppClassloader.
697 if (pkg_entry == NULL) {
698 // It's not guaranteed that the class is from the classpath if the
699 // PackageEntry cannot be found from the AppClassloader. Need to check
700 // the boot and platform classloader as well.
701 if (get_package_entry(pkg_name, ClassLoaderData::class_loader_data_or_null(SystemDictionary::java_platform_loader())) == NULL &&
702 get_package_entry(pkg_name, ClassLoaderData::the_null_class_loader_data()) == NULL) {
703 // The PackageEntry is not defined in any of the boot/platform/app classloaders.
704 // The archived class must from -cp path and not from the runtime image.
705 if (!ent->is_modules_image() && path_index >= ClassLoaderExt::app_class_paths_start_index() &&
706 path_index < ClassLoaderExt::app_module_paths_start_index()) {
707 return true;
|
640 // Currently AppCDS only archives classes from the run-time image, the
641 // -Xbootclasspath/a path, the class path, and the module path.
642 //
643 // Check if a shared class can be loaded by the specific classloader. Following
644 // are the "visible" archived classes for different classloaders.
645 //
646 // NULL classloader:
647 // - see SystemDictionary::is_shared_class_visible()
648 // Platform classloader:
649 // - Module class from runtime image. ModuleEntry must be defined in the
650 // classloader.
651 // App classloader:
652 // - Module Class from runtime image and module path. ModuleEntry must be defined in the
653 // classloader.
654 // - Class from -cp. The class must have no PackageEntry defined in any of the
655 // boot/platform/app classloader, or must be in the unnamed module defined in the
656 // AppClassLoader.
657 bool SystemDictionaryShared::is_shared_class_visible_for_classloader(
658 InstanceKlass* ik,
659 Handle class_loader,
660 Symbol* pkg_name,
661 PackageEntry* pkg_entry,
662 ModuleEntry* mod_entry,
663 TRAPS) {
664 assert(class_loader.not_null(), "Class loader should not be NULL");
665 assert(Universe::is_module_initialized(), "Module system is not initialized");
666 ResourceMark rm(THREAD);
667
668 int path_index = ik->shared_classpath_index();
669 SharedClassPathEntry* ent =
670 (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
671
672 if (SystemDictionary::is_platform_class_loader(class_loader())) {
673 assert(ent != NULL, "shared class for PlatformClassLoader should have valid SharedClassPathEntry");
674 // The PlatformClassLoader can only load archived class originated from the
675 // run-time image. The class' PackageEntry/ModuleEntry must be
676 // defined by the PlatformClassLoader.
677 if (mod_entry != NULL) {
678 // PackageEntry/ModuleEntry is found in the classloader. Check if the
679 // ModuleEntry's location agrees with the archived class' origination.
680 if (ent->is_modules_image() && mod_entry->location()->starts_with("jrt:")) {
681 return true; // Module class from the runtime image
682 }
683 }
684 } else if (SystemDictionary::is_system_class_loader(class_loader())) {
685 assert(ent != NULL, "shared class for system loader should have valid SharedClassPathEntry");
686 if (pkg_name == NULL) {
687 // The archived class is in the unnamed package. Currently, the boot image
688 // does not contain any class in the unnamed package.
689 assert(!ent->is_modules_image(), "Class in the unnamed package must be from the classpath");
690 if (path_index >= ClassLoaderExt::app_class_paths_start_index()) {
691 assert(path_index < ClassLoaderExt::app_module_paths_start_index(), "invalid path_index");
692 return true;
693 }
694 } else {
695 // Check if this is from a PackageEntry/ModuleEntry defined in the AppClassloader.
696 if (pkg_entry == NULL) {
697 // It's not guaranteed that the class is from the classpath if the
698 // PackageEntry cannot be found from the AppClassloader. Need to check
699 // the boot and platform classloader as well.
700 if (get_package_entry(pkg_name, ClassLoaderData::class_loader_data_or_null(SystemDictionary::java_platform_loader())) == NULL &&
701 get_package_entry(pkg_name, ClassLoaderData::the_null_class_loader_data()) == NULL) {
702 // The PackageEntry is not defined in any of the boot/platform/app classloaders.
703 // The archived class must from -cp path and not from the runtime image.
704 if (!ent->is_modules_image() && path_index >= ClassLoaderExt::app_class_paths_start_index() &&
705 path_index < ClassLoaderExt::app_module_paths_start_index()) {
706 return true;
|