82 typedef jzentry* (JNICALL *FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen); |
82 typedef jzentry* (JNICALL *FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen); |
83 typedef jboolean (JNICALL *ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf); |
83 typedef jboolean (JNICALL *ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf); |
84 typedef jzentry* (JNICALL *GetNextEntry_t)(jzfile *zip, jint n); |
84 typedef jzentry* (JNICALL *GetNextEntry_t)(jzfile *zip, jint n); |
85 typedef jboolean (JNICALL *ZipInflateFully_t)(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg); |
85 typedef jboolean (JNICALL *ZipInflateFully_t)(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg); |
86 typedef jint (JNICALL *Crc32_t)(jint crc, const jbyte *buf, jint len); |
86 typedef jint (JNICALL *Crc32_t)(jint crc, const jbyte *buf, jint len); |
87 typedef void (JNICALL *FreeEntry_t)(jzfile *zip, jzentry *entry); |
|
88 |
87 |
89 static ZipOpen_t ZipOpen = NULL; |
88 static ZipOpen_t ZipOpen = NULL; |
90 static ZipClose_t ZipClose = NULL; |
89 static ZipClose_t ZipClose = NULL; |
91 static FindEntry_t FindEntry = NULL; |
90 static FindEntry_t FindEntry = NULL; |
92 static ReadEntry_t ReadEntry = NULL; |
91 static ReadEntry_t ReadEntry = NULL; |
93 static GetNextEntry_t GetNextEntry = NULL; |
92 static GetNextEntry_t GetNextEntry = NULL; |
94 static canonicalize_fn_t CanonicalizeEntry = NULL; |
93 static canonicalize_fn_t CanonicalizeEntry = NULL; |
95 static ZipInflateFully_t ZipInflateFully = NULL; |
94 static ZipInflateFully_t ZipInflateFully = NULL; |
96 static Crc32_t Crc32 = NULL; |
95 static Crc32_t Crc32 = NULL; |
97 static FreeEntry_t FreeEntry = NULL; |
|
98 |
96 |
99 // Entry points for jimage.dll for loading jimage file entries |
97 // Entry points for jimage.dll for loading jimage file entries |
100 |
98 |
101 static JImageOpen_t JImageOpen = NULL; |
99 static JImageOpen_t JImageOpen = NULL; |
102 static JImageClose_t JImageClose = NULL; |
100 static JImageClose_t JImageClose = NULL; |
148 int ClassLoader::_num_entries = 0; |
146 int ClassLoader::_num_entries = 0; |
149 #if INCLUDE_CDS |
147 #if INCLUDE_CDS |
150 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL; |
148 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL; |
151 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL; |
149 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL; |
152 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL; |
150 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL; |
153 int ClassLoader::_num_patch_mod_prefixes = 0; |
|
154 #endif |
151 #endif |
155 |
152 |
156 // helper routines |
153 // helper routines |
157 bool string_starts_with(const char* str, const char* str_to_find) { |
154 bool string_starts_with(const char* str, const char* str_to_find) { |
158 size_t str_len = strlen(str); |
155 size_t str_len = strlen(str); |
316 ClassPathZipEntry::~ClassPathZipEntry() { |
313 ClassPathZipEntry::~ClassPathZipEntry() { |
317 if (ZipClose != NULL) { |
314 if (ZipClose != NULL) { |
318 (*ZipClose)(_zip); |
315 (*ZipClose)(_zip); |
319 } |
316 } |
320 FREE_C_HEAP_ARRAY(char, _zip_name); |
317 FREE_C_HEAP_ARRAY(char, _zip_name); |
321 } |
|
322 |
|
323 bool ClassPathZipEntry::stream_exists(const char* name) { |
|
324 // enable call to C land |
|
325 JavaThread* thread = JavaThread::current(); |
|
326 ThreadToNativeFromVM ttn(thread); |
|
327 // check whether zip archive contains name |
|
328 jint name_len, filesize; |
|
329 jzentry* entry = (*FindEntry)(_zip, name, &filesize, &name_len); |
|
330 if (entry != NULL) { |
|
331 (*FreeEntry)(_zip, entry); |
|
332 return true; |
|
333 } |
|
334 return false; |
|
335 } |
318 } |
336 |
319 |
337 u1* ClassPathZipEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) { |
320 u1* ClassPathZipEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) { |
338 // enable call to C land |
321 // enable call to C land |
339 JavaThread* thread = JavaThread::current(); |
322 JavaThread* thread = JavaThread::current(); |
1088 FindEntry = CAST_TO_FN_PTR(FindEntry_t, os::dll_lookup(handle, "ZIP_FindEntry")); |
1071 FindEntry = CAST_TO_FN_PTR(FindEntry_t, os::dll_lookup(handle, "ZIP_FindEntry")); |
1089 ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, os::dll_lookup(handle, "ZIP_ReadEntry")); |
1072 ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, os::dll_lookup(handle, "ZIP_ReadEntry")); |
1090 GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, os::dll_lookup(handle, "ZIP_GetNextEntry")); |
1073 GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, os::dll_lookup(handle, "ZIP_GetNextEntry")); |
1091 ZipInflateFully = CAST_TO_FN_PTR(ZipInflateFully_t, os::dll_lookup(handle, "ZIP_InflateFully")); |
1074 ZipInflateFully = CAST_TO_FN_PTR(ZipInflateFully_t, os::dll_lookup(handle, "ZIP_InflateFully")); |
1092 Crc32 = CAST_TO_FN_PTR(Crc32_t, os::dll_lookup(handle, "ZIP_CRC32")); |
1075 Crc32 = CAST_TO_FN_PTR(Crc32_t, os::dll_lookup(handle, "ZIP_CRC32")); |
1093 FreeEntry = CAST_TO_FN_PTR(FreeEntry_t, os::dll_lookup(handle, "ZIP_FreeEntry")); |
|
1094 |
1076 |
1095 // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL |
1077 // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL |
1096 if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL || |
1078 if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL || |
1097 GetNextEntry == NULL || Crc32 == NULL) { |
1079 GetNextEntry == NULL || Crc32 == NULL) { |
1098 vm_exit_during_initialization("Corrupted ZIP library", path); |
1080 vm_exit_during_initialization("Corrupted ZIP library", path); |
1416 } |
1398 } |
1417 |
1399 |
1418 return NULL; |
1400 return NULL; |
1419 } |
1401 } |
1420 |
1402 |
1421 #if INCLUDE_CDS |
|
1422 // The following function is only used during CDS dump time. |
|
1423 // It checks if a class can be found in the jar entries of the _patch_mod_entries. |
|
1424 // It does not support non-jar entries. |
|
1425 bool ClassLoader::is_in_patch_module(const char* const file_name) { |
|
1426 assert(DumpSharedSpaces, "dump time only"); |
|
1427 if (_patch_mod_entries == NULL) { |
|
1428 return false; |
|
1429 } |
|
1430 |
|
1431 int num_of_entries = _patch_mod_entries->length(); |
|
1432 char* class_module_name = NULL; |
|
1433 ResourceMark rm; |
|
1434 const char *pkg_name = package_from_name(file_name); |
|
1435 // Using the jimage to obtain the class' module name. |
|
1436 // The ModuleEntryTable cannot be used at this point during dump time |
|
1437 // because the module system hasn't been initialized yet. |
|
1438 if (pkg_name != NULL) { |
|
1439 JImageFile *jimage = _jrt_entry->jimage(); |
|
1440 class_module_name = (char*)(*JImagePackageToModule)(jimage, pkg_name); |
|
1441 } |
|
1442 |
|
1443 if (class_module_name == NULL) { |
|
1444 return false; |
|
1445 } |
|
1446 |
|
1447 // Loop through all the patch module entries looking for module |
|
1448 for (int i = 0; i < num_of_entries; i++) { |
|
1449 ModuleClassPathList* module_cpl = _patch_mod_entries->at(i); |
|
1450 Symbol* module_cpl_name = module_cpl->module_name(); |
|
1451 |
|
1452 if (strcmp(module_cpl_name->as_C_string(), class_module_name) == 0) { |
|
1453 // Class' module has been located, attempt to locate |
|
1454 // the class from the module's ClassPathEntry list. |
|
1455 ClassPathEntry* e = module_cpl->module_first_entry(); |
|
1456 while (e != NULL) { |
|
1457 if (e->is_jar_file()) { |
|
1458 if (e->stream_exists(file_name)) { |
|
1459 return true; |
|
1460 } else { |
|
1461 e = e->next(); |
|
1462 } |
|
1463 } |
|
1464 } |
|
1465 } |
|
1466 } |
|
1467 |
|
1468 return false; |
|
1469 } |
|
1470 #endif // INCLUDE_CDS |
|
1471 |
|
1472 instanceKlassHandle ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) { |
1403 instanceKlassHandle ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) { |
1473 assert(name != NULL, "invariant"); |
1404 assert(name != NULL, "invariant"); |
1474 assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
1405 assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
1475 |
1406 |
1476 ResourceMark rm(THREAD); |
1407 ResourceMark rm(THREAD); |
1492 s2 classpath_index = 0; |
1423 s2 classpath_index = 0; |
1493 ClassPathEntry* e = NULL; |
1424 ClassPathEntry* e = NULL; |
1494 |
1425 |
1495 // If DumpSharedSpaces is true boot loader visibility boundaries are set to: |
1426 // If DumpSharedSpaces is true boot loader visibility boundaries are set to: |
1496 // - [jimage] + [_first_append_entry to _last_append_entry] (all path entries). |
1427 // - [jimage] + [_first_append_entry to _last_append_entry] (all path entries). |
1497 // If a class is found in the --patch-module entries, the class will not be included in the |
|
1498 // CDS archive. Also, CDS is not supported if exploded module builds are used. |
|
1499 // |
1428 // |
1500 // If search_append_only is true, boot loader visibility boundaries are |
1429 // If search_append_only is true, boot loader visibility boundaries are |
1501 // set to be _first_append_entry to the end. This includes: |
1430 // set to be _first_append_entry to the end. This includes: |
1502 // [-Xbootclasspath/a]; [jvmti appended entries] |
1431 // [-Xbootclasspath/a]; [jvmti appended entries] |
1503 // |
1432 // |
1517 // that are part of the overall module definition. So if a particular class is not |
1446 // that are part of the overall module definition. So if a particular class is not |
1518 // found within its module specification, the search should continue to Load Attempt #2. |
1447 // found within its module specification, the search should continue to Load Attempt #2. |
1519 // Note: The --patch-module entries are never searched if the boot loader's |
1448 // Note: The --patch-module entries are never searched if the boot loader's |
1520 // visibility boundary is limited to only searching the append entries. |
1449 // visibility boundary is limited to only searching the append entries. |
1521 if (_patch_mod_entries != NULL && !search_append_only) { |
1450 if (_patch_mod_entries != NULL && !search_append_only) { |
|
1451 // At CDS dump time, the --patch-module entries are ignored. That means a |
|
1452 // class is still loaded from the runtime image even if it might |
|
1453 // appear in the _patch_mod_entries. The runtime shared class visibility |
|
1454 // check will determine if a shared class is visible based on the runtime |
|
1455 // environemnt, including the runtime --patch-module setting. |
1522 if (!DumpSharedSpaces) { |
1456 if (!DumpSharedSpaces) { |
1523 stream = search_module_entries(_patch_mod_entries, class_name, file_name, CHECK_NULL); |
1457 stream = search_module_entries(_patch_mod_entries, class_name, file_name, CHECK_NULL); |
1524 } else { |
|
1525 #if INCLUDE_CDS |
|
1526 if (is_in_patch_module(file_name)) { |
|
1527 tty->print_cr("Preload Warning: Skip archiving class %s found in --patch-module entry", class_name); |
|
1528 return NULL; |
|
1529 } |
|
1530 #endif |
|
1531 } |
1458 } |
1532 } |
1459 } |
1533 |
1460 |
1534 // Load Attempt #2: [jimage | exploded build] |
1461 // Load Attempt #2: [jimage | exploded build] |
1535 if (!search_append_only && (NULL == stream)) { |
1462 if (!search_append_only && (NULL == stream)) { |
1677 #endif |
1604 #endif |
1678 setup_bootstrap_search_path(); |
1605 setup_bootstrap_search_path(); |
1679 } |
1606 } |
1680 |
1607 |
1681 #if INCLUDE_CDS |
1608 #if INCLUDE_CDS |
1682 // Capture all the --patch-module entries specified during CDS dump time. |
|
1683 // It also captures the non-existing path(s) and the required file(s) during inspecting |
|
1684 // the entries. |
|
1685 void ClassLoader::setup_patch_mod_path() { |
|
1686 assert(DumpSharedSpaces, "only used with -Xshare:dump"); |
|
1687 ResourceMark rm; |
|
1688 GrowableArray<ModulePatchPath*>* patch_mod_args = Arguments::get_patch_mod_prefix(); |
|
1689 if (patch_mod_args != NULL) { |
|
1690 int num_of_entries = patch_mod_args->length(); |
|
1691 for (int i = 0; i < num_of_entries; i++) { |
|
1692 const char* module_name = (patch_mod_args->at(i))->module_name(); |
|
1693 const char* module_path = (patch_mod_args->at(i))->path_string(); |
|
1694 int path_len = (int)strlen(module_path); |
|
1695 int name_len = (int)strlen(module_name); |
|
1696 int buf_len = name_len + path_len + 2; // add 2 for the '=' and NULL terminator |
|
1697 int end = 0; |
|
1698 char* buf = NEW_C_HEAP_ARRAY(char, buf_len, mtInternal); |
|
1699 // Iterate over the module's class path entries |
|
1700 for (int start = 0; start < path_len; start = end) { |
|
1701 while (module_path[end] && module_path[end] != os::path_separator()[0]) { |
|
1702 end++; |
|
1703 } |
|
1704 strncpy(buf, &module_path[start], end - start); |
|
1705 buf[end - start] = '\0'; |
|
1706 struct stat st; |
|
1707 if (os::stat(buf, &st) != 0) { |
|
1708 // File not found |
|
1709 _shared_paths_misc_info->add_nonexist_path(buf); |
|
1710 } else { |
|
1711 if ((st.st_mode & S_IFMT) != S_IFREG) { // is not a regular file |
|
1712 vm_exit_during_initialization( |
|
1713 "--patch-module requires a regular file during dumping", buf); |
|
1714 } else { |
|
1715 _shared_paths_misc_info->add_required_file(buf); |
|
1716 } |
|
1717 } |
|
1718 while (module_path[end] == os::path_separator()[0]) { |
|
1719 end++; |
|
1720 } |
|
1721 }; |
|
1722 jio_snprintf(buf, buf_len, "%s=%s", module_name, module_path); |
|
1723 _shared_paths_misc_info->add_patch_mod_classpath((const char*)buf); |
|
1724 _num_patch_mod_prefixes++; |
|
1725 FREE_C_HEAP_ARRAY(char, buf); |
|
1726 } |
|
1727 } |
|
1728 } |
|
1729 |
|
1730 void ClassLoader::initialize_shared_path() { |
1609 void ClassLoader::initialize_shared_path() { |
1731 if (DumpSharedSpaces) { |
1610 if (DumpSharedSpaces) { |
1732 setup_patch_mod_path(); |
|
1733 ClassLoaderExt::setup_search_paths(); |
1611 ClassLoaderExt::setup_search_paths(); |
1734 _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check() |
1612 _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check() |
1735 } |
1613 } |
1736 } |
1614 } |
1737 #endif |
1615 #endif |