143 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_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; |
|
149 int ClassLoader::_num_boot_entries = -1; |
|
150 #if INCLUDE_CDS |
148 #if INCLUDE_CDS |
|
149 ClassPathEntry* ClassLoader::_app_classpath_entries = NULL; |
|
150 ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL; |
151 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL; |
151 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL; |
152 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL; |
152 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL; |
153 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL; |
153 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL; |
154 #endif |
154 #endif |
155 |
155 |
658 } |
658 } |
659 #endif |
659 #endif |
660 |
660 |
661 void ClassLoader::setup_bootstrap_search_path() { |
661 void ClassLoader::setup_bootstrap_search_path() { |
662 const char* sys_class_path = Arguments::get_sysclasspath(); |
662 const char* sys_class_path = Arguments::get_sysclasspath(); |
663 const char* java_class_path = Arguments::get_appclasspath(); |
|
664 if (PrintSharedArchiveAndExit) { |
663 if (PrintSharedArchiveAndExit) { |
665 // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily |
664 // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily |
666 // the same as the bootcp of the shared archive. |
665 // the same as the bootcp of the shared archive. |
667 } else { |
666 } else { |
668 trace_class_path("bootstrap loader class path=", sys_class_path); |
667 trace_class_path("bootstrap loader class path=", sys_class_path); |
669 trace_class_path("classpath: ", java_class_path); |
|
670 } |
668 } |
671 #if INCLUDE_CDS |
669 #if INCLUDE_CDS |
672 if (DumpSharedSpaces) { |
670 if (DumpSharedSpaces) { |
673 _shared_paths_misc_info->add_boot_classpath(sys_class_path); |
671 _shared_paths_misc_info->add_boot_classpath(sys_class_path); |
674 } |
672 } |
675 #endif |
673 #endif |
676 setup_search_path(sys_class_path, true); |
674 setup_boot_search_path(sys_class_path); |
677 } |
675 } |
678 |
676 |
679 #if INCLUDE_CDS |
677 #if INCLUDE_CDS |
680 int ClassLoader::get_shared_paths_misc_info_size() { |
678 int ClassLoader::get_shared_paths_misc_info_size() { |
681 return _shared_paths_misc_info->get_used_bytes(); |
679 return _shared_paths_misc_info->get_used_bytes(); |
689 SharedPathsMiscInfo* checker = SharedClassUtil::allocate_shared_paths_misc_info((char*)buf, size); |
687 SharedPathsMiscInfo* checker = SharedClassUtil::allocate_shared_paths_misc_info((char*)buf, size); |
690 bool result = checker->check(); |
688 bool result = checker->check(); |
691 delete checker; |
689 delete checker; |
692 return result; |
690 return result; |
693 } |
691 } |
|
692 |
|
693 void ClassLoader::setup_app_search_path(const char *class_path) { |
|
694 |
|
695 assert(DumpSharedSpaces, "Sanity"); |
|
696 |
|
697 Thread* THREAD = Thread::current(); |
|
698 int len = (int)strlen(class_path); |
|
699 int end = 0; |
|
700 |
|
701 // Iterate over class path entries |
|
702 for (int start = 0; start < len; start = end) { |
|
703 while (class_path[end] && class_path[end] != os::path_separator()[0]) { |
|
704 end++; |
|
705 } |
|
706 EXCEPTION_MARK; |
|
707 ResourceMark rm(THREAD); |
|
708 char* path = NEW_RESOURCE_ARRAY(char, end - start + 1); |
|
709 strncpy(path, &class_path[start], end - start); |
|
710 path[end - start] = '\0'; |
|
711 |
|
712 check_shared_classpath(path); |
|
713 |
|
714 update_class_path_entry_list(path, false, false); |
|
715 |
|
716 while (class_path[end] == os::path_separator()[0]) { |
|
717 end++; |
|
718 } |
|
719 } |
|
720 } |
|
721 |
694 #endif |
722 #endif |
695 |
723 |
696 // Construct the array of module/path pairs as specified to --patch-module |
724 // Construct the array of module/path pairs as specified to --patch-module |
697 // for the boot loader to search ahead of the jimage, if the class being |
725 // for the boot loader to search ahead of the jimage, if the class being |
698 // loaded is defined to a module that has been specified to --patch-module. |
726 // loaded is defined to a module that has been specified to --patch-module. |
778 ResourceMark rm(THREAD); |
807 ResourceMark rm(THREAD); |
779 char* path = NEW_RESOURCE_ARRAY(char, end - start + 1); |
808 char* path = NEW_RESOURCE_ARRAY(char, end - start + 1); |
780 strncpy(path, &class_path[start], end - start); |
809 strncpy(path, &class_path[start], end - start); |
781 path[end - start] = '\0'; |
810 path[end - start] = '\0'; |
782 |
811 |
783 // The first time through the bootstrap_search setup, it must be determined |
|
784 // what the base or core piece of the boot loader search is. Either a java runtime |
|
785 // image is present or this is an exploded module build situation. |
|
786 if (set_base_piece) { |
812 if (set_base_piece) { |
|
813 // The first time through the bootstrap_search setup, it must be determined |
|
814 // what the base or core piece of the boot loader search is. Either a java runtime |
|
815 // image is present or this is an exploded module build situation. |
787 assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, JAVA_BASE_NAME), |
816 assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, JAVA_BASE_NAME), |
788 "Incorrect boot loader search path, no java runtime image or " JAVA_BASE_NAME " exploded build"); |
817 "Incorrect boot loader search path, no java runtime image or " JAVA_BASE_NAME " exploded build"); |
789 struct stat st; |
818 struct stat st; |
790 if (os::stat(path, &st) == 0) { |
819 if (os::stat(path, &st) == 0) { |
791 // Directory found |
820 // Directory found |
795 // Check for a jimage |
824 // Check for a jimage |
796 if (Arguments::has_jimage()) { |
825 if (Arguments::has_jimage()) { |
797 assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice"); |
826 assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice"); |
798 assert(new_entry != NULL && new_entry->is_modules_image(), "No java runtime image present"); |
827 assert(new_entry != NULL && new_entry->is_modules_image(), "No java runtime image present"); |
799 _jrt_entry = new_entry; |
828 _jrt_entry = new_entry; |
800 ++_num_entries; |
829 assert(_jrt_entry->jimage() != NULL, "No java runtime image"); |
801 #if INCLUDE_CDS |
|
802 if (DumpSharedSpaces) { |
|
803 JImageFile *jimage = _jrt_entry->jimage(); |
|
804 assert(jimage != NULL, "No java runtime image file present"); |
|
805 } |
|
806 #endif |
|
807 } |
830 } |
808 } else { |
831 } else { |
809 // If path does not exist, exit |
832 // If path does not exist, exit |
810 vm_exit_during_initialization("Unable to establish the boot loader search path", path); |
833 vm_exit_during_initialization("Unable to establish the boot loader search path", path); |
811 } |
834 } |
812 set_base_piece = false; |
835 set_base_piece = false; |
813 } else { |
836 } else { |
814 // Every entry on the system boot class path after the initial base piece, |
837 // Every entry on the system boot class path after the initial base piece, |
815 // which is set by os::set_boot_path(), is considered an appended entry. |
838 // which is set by os::set_boot_path(), is considered an appended entry. |
816 update_class_path_entry_list(path, false, bootstrap_search); |
839 update_class_path_entry_list(path, false, true); |
817 } |
840 } |
818 |
841 |
819 #if INCLUDE_CDS |
842 #if INCLUDE_CDS |
820 if (DumpSharedSpaces) { |
843 if (DumpSharedSpaces) { |
821 check_shared_classpath(path); |
844 check_shared_classpath(path); |
966 e = e->next(); |
989 e = e->next(); |
967 } |
990 } |
968 return false; |
991 return false; |
969 } |
992 } |
970 |
993 |
971 void ClassLoader::add_to_list(ClassPathEntry *new_entry) { |
994 void ClassLoader::add_to_boot_append_entries(ClassPathEntry *new_entry) { |
972 if (new_entry != NULL) { |
995 if (new_entry != NULL) { |
973 if (_last_append_entry == NULL) { |
996 if (_last_append_entry == NULL) { |
974 assert(_first_append_entry == NULL, "boot loader's append class path entry list not empty"); |
997 assert(_first_append_entry == NULL, "boot loader's append class path entry list not empty"); |
975 _first_append_entry = _last_append_entry = new_entry; |
998 _first_append_entry = _last_append_entry = new_entry; |
976 } else { |
999 } else { |
977 _last_append_entry->set_next(new_entry); |
1000 _last_append_entry->set_next(new_entry); |
978 _last_append_entry = new_entry; |
1001 _last_append_entry = new_entry; |
979 } |
1002 } |
980 } |
1003 } |
981 _num_entries++; |
1004 } |
982 } |
1005 |
983 |
1006 // Record the path entries specified in -cp during dump time. The recorded |
984 void ClassLoader::add_to_list(const char *apath) { |
1007 // information will be used at runtime for loading the archived app classes. |
985 update_class_path_entry_list((char*)apath, false, false); |
1008 // |
|
1009 // Note that at dump time, ClassLoader::_app_classpath_entries are NOT used for |
|
1010 // loading app classes. Instead, the app class are loaded by the |
|
1011 // jdk/internal/loader/ClassLoaders$AppClassLoader instance. |
|
1012 void ClassLoader::add_to_app_classpath_entries(const char* path, |
|
1013 ClassPathEntry* entry, |
|
1014 bool check_for_duplicates) { |
|
1015 #if INCLUDE_CDS |
|
1016 assert(entry != NULL, "ClassPathEntry should not be NULL"); |
|
1017 ClassPathEntry* e = _app_classpath_entries; |
|
1018 if (check_for_duplicates) { |
|
1019 while (e != NULL) { |
|
1020 if (strcmp(e->name(), entry->name()) == 0) { |
|
1021 // entry already exists |
|
1022 return; |
|
1023 } |
|
1024 e = e->next(); |
|
1025 } |
|
1026 } |
|
1027 |
|
1028 // The entry does not exist, add to the list |
|
1029 if (_app_classpath_entries == NULL) { |
|
1030 assert(_last_app_classpath_entry == NULL, "Sanity"); |
|
1031 _app_classpath_entries = _last_app_classpath_entry = entry; |
|
1032 } else { |
|
1033 _last_app_classpath_entry->set_next(entry); |
|
1034 _last_app_classpath_entry = entry; |
|
1035 } |
|
1036 |
|
1037 if (entry->is_jar_file()) { |
|
1038 ClassLoaderExt::process_jar_manifest(entry, check_for_duplicates); |
|
1039 } else { |
|
1040 if (!os::dir_is_empty(path)) { |
|
1041 tty->print_cr("Error: non-empty directory '%s'", path); |
|
1042 exit_with_path_failure("Cannot have non-empty directory in app classpaths", NULL); |
|
1043 } |
|
1044 } |
|
1045 #endif |
986 } |
1046 } |
987 |
1047 |
988 // Returns true IFF the file/dir exists and the entry was successfully created. |
1048 // Returns true IFF the file/dir exists and the entry was successfully created. |
989 bool ClassLoader::update_class_path_entry_list(const char *path, |
1049 bool ClassLoader::update_class_path_entry_list(const char *path, |
990 bool check_for_duplicates, |
1050 bool check_for_duplicates, |
1400 assert(classpath_index == 0, "The classpath_index has been incremented incorrectly"); |
1463 assert(classpath_index == 0, "The classpath_index has been incremented incorrectly"); |
1401 classpath_index = 1; |
1464 classpath_index = 1; |
1402 |
1465 |
1403 e = _first_append_entry; |
1466 e = _first_append_entry; |
1404 while (e != NULL) { |
1467 while (e != NULL) { |
1405 if (DumpSharedSpaces && classpath_index >= _num_boot_entries) { |
|
1406 // Do not load any class from the app classpath using the boot loader. Let |
|
1407 // the built-in app class laoder load them. |
|
1408 break; |
|
1409 } |
|
1410 stream = e->open_stream(file_name, CHECK_NULL); |
1468 stream = e->open_stream(file_name, CHECK_NULL); |
1411 if (!context.check(stream, classpath_index)) { |
1469 if (!context.check(stream, classpath_index)) { |
1412 return NULL; |
1470 return NULL; |
1413 } |
1471 } |
1414 if (NULL != stream) { |
1472 if (NULL != stream) { |
1463 source += 5; |
1525 source += 5; |
1464 } |
1526 } |
1465 return source; |
1527 return source; |
1466 } |
1528 } |
1467 |
1529 |
1468 void ClassLoader::record_shared_class_loader_type(InstanceKlass* ik, const ClassFileStream* stream) { |
1530 // Record the shared classpath index and loader type for classes loaded |
|
1531 // by the builtin loaders at dump time. |
|
1532 void ClassLoader::record_result(InstanceKlass* ik, const ClassFileStream* stream) { |
1469 assert(DumpSharedSpaces, "sanity"); |
1533 assert(DumpSharedSpaces, "sanity"); |
1470 assert(stream != NULL, "sanity"); |
1534 assert(stream != NULL, "sanity"); |
1471 |
1535 |
1472 if (ik->is_anonymous()) { |
1536 if (ik->is_anonymous()) { |
1473 // We do not archive anonymous classes. |
1537 // We do not archive anonymous classes. |
1474 return; |
1538 return; |
1475 } |
1539 } |
1476 |
1540 |
1477 if (stream->source() == NULL) { |
1541 char* src = (char*)stream->source(); |
|
1542 if (src == NULL) { |
1478 if (ik->class_loader() == NULL) { |
1543 if (ik->class_loader() == NULL) { |
1479 // JFR classes |
1544 // JFR classes |
1480 ik->set_shared_classpath_index(0); |
1545 ik->set_shared_classpath_index(0); |
1481 ik->set_class_loader_type(ClassLoader::BOOT_LOADER); |
1546 ik->set_class_loader_type(ClassLoader::BOOT_LOADER); |
1482 } |
1547 } |
1484 } |
1549 } |
1485 |
1550 |
1486 assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build"); |
1551 assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build"); |
1487 |
1552 |
1488 ModuleEntry* module = ik->module(); |
1553 ModuleEntry* module = ik->module(); |
1489 ClassPathEntry* e = NULL; |
1554 int classpath_index = -1; |
1490 int classpath_index = 0; |
|
1491 |
|
1492 // Check if the class is from the runtime image |
|
1493 if (module != NULL && (module->location() != NULL) && |
|
1494 (module->location()->starts_with("jrt:"))) { |
|
1495 e = _jrt_entry; |
|
1496 classpath_index = 0; |
|
1497 } else { |
|
1498 classpath_index = 1; |
|
1499 ResourceMark rm; |
|
1500 char* canonical_path = NEW_RESOURCE_ARRAY(char, JVM_MAXPATHLEN); |
|
1501 for (e = _first_append_entry; e != NULL; e = e->next()) { |
|
1502 if (get_canonical_path(e->name(), canonical_path, JVM_MAXPATHLEN)) { |
|
1503 char* src = (char*)stream->source(); |
|
1504 // save the path from the file: protocol or the module name from the jrt: protocol |
|
1505 // if no protocol prefix is found, src is the same as stream->source() after the following call |
|
1506 src = skip_uri_protocol(src); |
|
1507 if (strcmp(canonical_path, os::native_path((char*)src)) == 0) { |
|
1508 break; |
|
1509 } |
|
1510 classpath_index ++; |
|
1511 } |
|
1512 } |
|
1513 if (e == NULL) { |
|
1514 assert(ik->shared_classpath_index() < 0, |
|
1515 "must be a class from a custom jar which isn't in the class path or boot class path"); |
|
1516 return; |
|
1517 } |
|
1518 } |
|
1519 |
|
1520 if (classpath_index < _num_boot_entries) { |
|
1521 // ik is either: |
|
1522 // 1) a boot class loaded from the runtime image during vm initialization (classpath_index = 0); or |
|
1523 // 2) a user's class from -Xbootclasspath/a (classpath_index > 0) |
|
1524 // In the second case, the classpath_index, classloader_type will be recorded via |
|
1525 // context.record_result() in ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS). |
|
1526 if (classpath_index > 0) { |
|
1527 return; |
|
1528 } |
|
1529 } |
|
1530 |
|
1531 ResourceMark rm; |
1555 ResourceMark rm; |
|
1556 char* canonical_path = NEW_RESOURCE_ARRAY(char, JVM_MAXPATHLEN); |
|
1557 |
|
1558 // save the path from the file: protocol or the module name from the jrt: protocol |
|
1559 // if no protocol prefix is found, path is the same as stream->source() |
|
1560 char* path = skip_uri_protocol(src); |
|
1561 for (int i = 0; i < FileMapInfo::get_number_of_share_classpaths(); i++) { |
|
1562 SharedClassPathEntry* ent = FileMapInfo::shared_classpath(i); |
|
1563 if (get_canonical_path(ent->name(), canonical_path, JVM_MAXPATHLEN)) { |
|
1564 // If the path (from the class stream srouce) is the same as the shared |
|
1565 // class path, then we have a match. For classes from module image loaded by the |
|
1566 // PlatformClassLoader, the stream->source() is not the name of the module image. |
|
1567 // Need to look for 'jrt:' explicitly. |
|
1568 if (strcmp(canonical_path, os::native_path((char*)path)) == 0 || |
|
1569 (i == 0 && string_starts_with(src, "jrt:"))) { |
|
1570 classpath_index = i; |
|
1571 break; |
|
1572 } |
|
1573 } |
|
1574 } |
|
1575 if (classpath_index < 0) { |
|
1576 // Shared classpath entry table only contains boot class path and -cp path. |
|
1577 // No path entry found for this class. Must be a shared class loaded by the |
|
1578 // user defined classloader. |
|
1579 assert(ik->shared_classpath_index() < 0, "Sanity"); |
|
1580 return; |
|
1581 } |
|
1582 |
1532 const char* const class_name = ik->name()->as_C_string(); |
1583 const char* const class_name = ik->name()->as_C_string(); |
1533 const char* const file_name = file_name_for_class_name(class_name, |
1584 const char* const file_name = file_name_for_class_name(class_name, |
1534 ik->name()->utf8_length()); |
1585 ik->name()->utf8_length()); |
1535 assert(file_name != NULL, "invariant"); |
1586 assert(file_name != NULL, "invariant"); |
1536 Thread* THREAD = Thread::current(); |
1587 Thread* THREAD = Thread::current(); |
1537 ClassLoaderExt::Context context(class_name, file_name, CATCH); |
1588 ClassLoaderExt::Context context(class_name, file_name, CATCH); |
1538 context.record_result(ik->name(), e, classpath_index, ik, THREAD); |
1589 context.record_result(ik->name(), classpath_index, ik, THREAD); |
1539 } |
1590 } |
1540 #endif // INCLUDE_CDS |
1591 #endif // INCLUDE_CDS |
1541 |
1592 |
1542 // Initialize the class loader's access to methods in libzip. Parse and |
1593 // Initialize the class loader's access to methods in libzip. Parse and |
1543 // process the boot classpath into a list ClassPathEntry objects. Once |
1594 // process the boot classpath into a list ClassPathEntry objects. Once |