67 #include "runtime/vm_version.hpp"
68 #include "services/management.hpp"
69 #include "services/threadService.hpp"
70 #include "utilities/events.hpp"
71 #include "utilities/hashtable.inline.hpp"
72 #include "utilities/macros.hpp"
73 #if INCLUDE_CDS
74 #include "classfile/sharedClassUtil.hpp"
75 #include "classfile/sharedPathsMiscInfo.hpp"
76 #endif
77
78 // Entry points in zip.dll for loading zip/jar file entries
79
80 typedef void * * (JNICALL *ZipOpen_t)(const char *name, char **pmsg);
81 typedef void (JNICALL *ZipClose_t)(jzfile *zip);
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);
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);
86 typedef jint (JNICALL *Crc32_t)(jint crc, const jbyte *buf, jint len);
87 typedef void (JNICALL *FreeEntry_t)(jzfile *zip, jzentry *entry);
88
89 static ZipOpen_t ZipOpen = NULL;
90 static ZipClose_t ZipClose = NULL;
91 static FindEntry_t FindEntry = NULL;
92 static ReadEntry_t ReadEntry = NULL;
93 static GetNextEntry_t GetNextEntry = NULL;
94 static canonicalize_fn_t CanonicalizeEntry = NULL;
95 static ZipInflateFully_t ZipInflateFully = NULL;
96 static Crc32_t Crc32 = NULL;
97 static FreeEntry_t FreeEntry = NULL;
98
99 // Entry points for jimage.dll for loading jimage file entries
100
101 static JImageOpen_t JImageOpen = NULL;
102 static JImageClose_t JImageClose = NULL;
103 static JImagePackageToModule_t JImagePackageToModule = NULL;
104 static JImageFindResource_t JImageFindResource = NULL;
105 static JImageGetResource_t JImageGetResource = NULL;
106 static JImageResourceIterator_t JImageResourceIterator = NULL;
107 static JImage_ResourcePath_t JImageResourcePath = NULL;
108
109 // Globals
110
111 PerfCounter* ClassLoader::_perf_accumulated_time = NULL;
112 PerfCounter* ClassLoader::_perf_classes_inited = NULL;
113 PerfCounter* ClassLoader::_perf_class_init_time = NULL;
114 PerfCounter* ClassLoader::_perf_class_init_selftime = NULL;
115 PerfCounter* ClassLoader::_perf_classes_verified = NULL;
116 PerfCounter* ClassLoader::_perf_class_verify_time = NULL;
117 PerfCounter* ClassLoader::_perf_class_verify_selftime = NULL;
133 PerfCounter* ClassLoader::_perf_sys_classfile_bytes_read = NULL;
134 PerfCounter* ClassLoader::_sync_systemLoaderLockContentionRate = NULL;
135 PerfCounter* ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL;
136 PerfCounter* ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL;
137 PerfCounter* ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL;
138 PerfCounter* ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
139 PerfCounter* ClassLoader::_unsafe_defineClassCallCounter = NULL;
140 PerfCounter* ClassLoader::_isUnsyncloadClass = NULL;
141 PerfCounter* ClassLoader::_load_instance_class_failCounter = NULL;
142
143 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = NULL;
144 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
145 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
146 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
147 ClassPathEntry* ClassLoader::_last_append_entry = NULL;
148 int ClassLoader::_num_entries = 0;
149 #if INCLUDE_CDS
150 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL;
151 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL;
152 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
153 int ClassLoader::_num_patch_mod_prefixes = 0;
154 #endif
155
156 // helper routines
157 bool string_starts_with(const char* str, const char* str_to_find) {
158 size_t str_len = strlen(str);
159 size_t str_to_find_len = strlen(str_to_find);
160 if (str_to_find_len > str_len) {
161 return false;
162 }
163 return (strncmp(str, str_to_find, str_to_find_len) == 0);
164 }
165
166 static const char* get_jimage_version_string() {
167 static char version_string[10] = "";
168 if (version_string[0] == '\0') {
169 jio_snprintf(version_string, sizeof(version_string), "%d.%d",
170 Abstract_VM_Version::vm_major_version(), Abstract_VM_Version::vm_minor_version());
171 }
172 return (const char*)version_string;
173 }
303 FREE_RESOURCE_ARRAY(char, path, JVM_MAXPATHLEN);
304 return NULL;
305 }
306
307 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append) : ClassPathEntry() {
308 _zip = zip;
309 char *copy = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass);
310 strcpy(copy, zip_name);
311 _zip_name = copy;
312 _is_boot_append = is_boot_append;
313 _multi_versioned = _unknown;
314 }
315
316 ClassPathZipEntry::~ClassPathZipEntry() {
317 if (ZipClose != NULL) {
318 (*ZipClose)(_zip);
319 }
320 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 }
336
337 u1* ClassPathZipEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) {
338 // enable call to C land
339 JavaThread* thread = JavaThread::current();
340 ThreadToNativeFromVM ttn(thread);
341 // check whether zip archive contains name
342 jint name_len;
343 jzentry* entry = (*FindEntry)(_zip, name, filesize, &name_len);
344 if (entry == NULL) return NULL;
345 u1* buffer;
346 char name_buf[128];
347 char* filename;
348 if (name_len < 128) {
349 filename = name_buf;
350 } else {
351 filename = NEW_RESOURCE_ARRAY(char, name_len + 1);
352 }
353
354 // read contents into resource array
355 int size = (*filesize) + ((nul_terminate) ? 1 : 0);
356 buffer = NEW_RESOURCE_ARRAY(u1, size);
1073 // First make sure native library is loaded
1074 os::native_java_library();
1075 // Load zip library
1076 char path[JVM_MAXPATHLEN];
1077 char ebuf[1024];
1078 void* handle = NULL;
1079 if (os::dll_build_name(path, sizeof(path), Arguments::get_dll_dir(), "zip")) {
1080 handle = os::dll_load(path, ebuf, sizeof ebuf);
1081 }
1082 if (handle == NULL) {
1083 vm_exit_during_initialization("Unable to load ZIP library", path);
1084 }
1085 // Lookup zip entry points
1086 ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, os::dll_lookup(handle, "ZIP_Open"));
1087 ZipClose = CAST_TO_FN_PTR(ZipClose_t, os::dll_lookup(handle, "ZIP_Close"));
1088 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"));
1090 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"));
1092 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
1095 // 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 ||
1097 GetNextEntry == NULL || Crc32 == NULL) {
1098 vm_exit_during_initialization("Corrupted ZIP library", path);
1099 }
1100
1101 if (ZipInflateFully == NULL) {
1102 vm_exit_during_initialization("Corrupted ZIP library ZIP_InflateFully missing", path);
1103 }
1104
1105 // Lookup canonicalize entry in libjava.dll
1106 void *javalib_handle = os::native_java_library();
1107 CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, os::dll_lookup(javalib_handle, "Canonicalize"));
1108 // This lookup only works on 1.3. Do not check for non-null here
1109 }
1110
1111 void ClassLoader::load_jimage_library() {
1112 // First make sure native library is loaded
1113 os::native_java_library();
1401 while (e != NULL) {
1402 stream = e->open_stream(file_name, CHECK_NULL);
1403 // No context.check is required since CDS is not supported
1404 // for an exploded modules build or if --patch-module is specified.
1405 if (NULL != stream) {
1406 return stream;
1407 }
1408 e = e->next();
1409 }
1410 // If the module was located, break out even if the class was not
1411 // located successfully from that module's ClassPathEntry list.
1412 // There will not be another valid entry for that module.
1413 return NULL;
1414 }
1415 }
1416 }
1417
1418 return NULL;
1419 }
1420
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) {
1473 assert(name != NULL, "invariant");
1474 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1475
1476 ResourceMark rm(THREAD);
1477 HandleMark hm(THREAD);
1478
1479 const char* const class_name = name->as_C_string();
1480
1481 EventMark m("loading class %s", class_name);
1482 ThreadProfilerMark tpm(ThreadProfilerMark::classLoaderRegion);
1483
1484 const char* const file_name = file_name_for_class_name(class_name,
1485 name->utf8_length());
1486 assert(file_name != NULL, "invariant");
1487
1488 ClassLoaderExt::Context context(class_name, file_name, THREAD);
1489
1490 // Lookup stream for parsing .class file
1491 ClassFileStream* stream = NULL;
1492 s2 classpath_index = 0;
1493 ClassPathEntry* e = NULL;
1494
1495 // If DumpSharedSpaces is true boot loader visibility boundaries are set to:
1496 // - [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 //
1500 // If search_append_only is true, boot loader visibility boundaries are
1501 // set to be _first_append_entry to the end. This includes:
1502 // [-Xbootclasspath/a]; [jvmti appended entries]
1503 //
1504 // If both DumpSharedSpaces and search_append_only are false, boot loader
1505 // visibility boundaries are set to be the --patch-module entries plus the base piece.
1506 // This would include:
1507 // [--patch-module=<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
1508 //
1509 // DumpSharedSpaces and search_append_only are mutually exclusive and cannot
1510 // be true at the same time.
1511 assert(!(DumpSharedSpaces && search_append_only), "DumpSharedSpaces and search_append_only are both true");
1512
1513 // Load Attempt #1: --patch-module
1514 // Determine the class' defining module. If it appears in the _patch_mod_entries,
1515 // attempt to load the class from those locations specific to the module.
1516 // Specifications to --patch-module can contain a partial number of classes
1517 // 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.
1519 // Note: The --patch-module entries are never searched if the boot loader's
1520 // visibility boundary is limited to only searching the append entries.
1521 if (_patch_mod_entries != NULL && !search_append_only) {
1522 if (!DumpSharedSpaces) {
1523 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 }
1532 }
1533
1534 // Load Attempt #2: [jimage | exploded build]
1535 if (!search_append_only && (NULL == stream)) {
1536 if (has_jrt_entry()) {
1537 e = _jrt_entry;
1538 stream = _jrt_entry->open_stream(file_name, CHECK_NULL);
1539 if (!context.check(stream, classpath_index)) {
1540 return NULL;
1541 }
1542 } else {
1543 // Exploded build - attempt to locate class in its defining module's location.
1544 assert(_exploded_entries != NULL, "No exploded build entries present");
1545 stream = search_module_entries(_exploded_entries, class_name, file_name, CHECK_NULL);
1546 }
1547 }
1548
1549 // Load Attempt #3: [-Xbootclasspath/a]; [jvmti appended entries]
1550 if ((search_append_only || DumpSharedSpaces) && (NULL == stream)) {
1662 // increment the isUnsyncloadClass counter if UnsyncloadClass is set.
1663 if (UnsyncloadClass) {
1664 _isUnsyncloadClass->inc();
1665 }
1666 }
1667
1668 // lookup zip library entry points
1669 load_zip_library();
1670 // lookup jimage library entry points
1671 load_jimage_library();
1672 #if INCLUDE_CDS
1673 // initialize search path
1674 if (DumpSharedSpaces) {
1675 _shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info();
1676 }
1677 #endif
1678 setup_bootstrap_search_path();
1679 }
1680
1681 #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() {
1731 if (DumpSharedSpaces) {
1732 setup_patch_mod_path();
1733 ClassLoaderExt::setup_search_paths();
1734 _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1735 }
1736 }
1737 #endif
1738
1739 jlong ClassLoader::classloader_time_ms() {
1740 return UsePerfData ?
1741 Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1742 }
1743
1744 jlong ClassLoader::class_init_count() {
1745 return UsePerfData ? _perf_classes_inited->get_value() : -1;
1746 }
1747
1748 jlong ClassLoader::class_init_time_ms() {
1749 return UsePerfData ?
1750 Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1751 }
1752
|
67 #include "runtime/vm_version.hpp"
68 #include "services/management.hpp"
69 #include "services/threadService.hpp"
70 #include "utilities/events.hpp"
71 #include "utilities/hashtable.inline.hpp"
72 #include "utilities/macros.hpp"
73 #if INCLUDE_CDS
74 #include "classfile/sharedClassUtil.hpp"
75 #include "classfile/sharedPathsMiscInfo.hpp"
76 #endif
77
78 // Entry points in zip.dll for loading zip/jar file entries
79
80 typedef void * * (JNICALL *ZipOpen_t)(const char *name, char **pmsg);
81 typedef void (JNICALL *ZipClose_t)(jzfile *zip);
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);
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);
86 typedef jint (JNICALL *Crc32_t)(jint crc, const jbyte *buf, jint len);
87
88 static ZipOpen_t ZipOpen = NULL;
89 static ZipClose_t ZipClose = NULL;
90 static FindEntry_t FindEntry = NULL;
91 static ReadEntry_t ReadEntry = NULL;
92 static GetNextEntry_t GetNextEntry = NULL;
93 static canonicalize_fn_t CanonicalizeEntry = NULL;
94 static ZipInflateFully_t ZipInflateFully = NULL;
95 static Crc32_t Crc32 = NULL;
96
97 // Entry points for jimage.dll for loading jimage file entries
98
99 static JImageOpen_t JImageOpen = NULL;
100 static JImageClose_t JImageClose = NULL;
101 static JImagePackageToModule_t JImagePackageToModule = NULL;
102 static JImageFindResource_t JImageFindResource = NULL;
103 static JImageGetResource_t JImageGetResource = NULL;
104 static JImageResourceIterator_t JImageResourceIterator = NULL;
105 static JImage_ResourcePath_t JImageResourcePath = NULL;
106
107 // Globals
108
109 PerfCounter* ClassLoader::_perf_accumulated_time = NULL;
110 PerfCounter* ClassLoader::_perf_classes_inited = NULL;
111 PerfCounter* ClassLoader::_perf_class_init_time = NULL;
112 PerfCounter* ClassLoader::_perf_class_init_selftime = NULL;
113 PerfCounter* ClassLoader::_perf_classes_verified = NULL;
114 PerfCounter* ClassLoader::_perf_class_verify_time = NULL;
115 PerfCounter* ClassLoader::_perf_class_verify_selftime = NULL;
131 PerfCounter* ClassLoader::_perf_sys_classfile_bytes_read = NULL;
132 PerfCounter* ClassLoader::_sync_systemLoaderLockContentionRate = NULL;
133 PerfCounter* ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL;
134 PerfCounter* ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL;
135 PerfCounter* ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL;
136 PerfCounter* ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
137 PerfCounter* ClassLoader::_unsafe_defineClassCallCounter = NULL;
138 PerfCounter* ClassLoader::_isUnsyncloadClass = NULL;
139 PerfCounter* ClassLoader::_load_instance_class_failCounter = NULL;
140
141 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = NULL;
142 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
143 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
144 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
145 ClassPathEntry* ClassLoader::_last_append_entry = NULL;
146 int ClassLoader::_num_entries = 0;
147 #if INCLUDE_CDS
148 GrowableArray<char*>* ClassLoader::_boot_modules_array = NULL;
149 GrowableArray<char*>* ClassLoader::_platform_modules_array = NULL;
150 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
151 #endif
152
153 // helper routines
154 bool string_starts_with(const char* str, const char* str_to_find) {
155 size_t str_len = strlen(str);
156 size_t str_to_find_len = strlen(str_to_find);
157 if (str_to_find_len > str_len) {
158 return false;
159 }
160 return (strncmp(str, str_to_find, str_to_find_len) == 0);
161 }
162
163 static const char* get_jimage_version_string() {
164 static char version_string[10] = "";
165 if (version_string[0] == '\0') {
166 jio_snprintf(version_string, sizeof(version_string), "%d.%d",
167 Abstract_VM_Version::vm_major_version(), Abstract_VM_Version::vm_minor_version());
168 }
169 return (const char*)version_string;
170 }
300 FREE_RESOURCE_ARRAY(char, path, JVM_MAXPATHLEN);
301 return NULL;
302 }
303
304 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append) : ClassPathEntry() {
305 _zip = zip;
306 char *copy = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass);
307 strcpy(copy, zip_name);
308 _zip_name = copy;
309 _is_boot_append = is_boot_append;
310 _multi_versioned = _unknown;
311 }
312
313 ClassPathZipEntry::~ClassPathZipEntry() {
314 if (ZipClose != NULL) {
315 (*ZipClose)(_zip);
316 }
317 FREE_C_HEAP_ARRAY(char, _zip_name);
318 }
319
320 u1* ClassPathZipEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) {
321 // enable call to C land
322 JavaThread* thread = JavaThread::current();
323 ThreadToNativeFromVM ttn(thread);
324 // check whether zip archive contains name
325 jint name_len;
326 jzentry* entry = (*FindEntry)(_zip, name, filesize, &name_len);
327 if (entry == NULL) return NULL;
328 u1* buffer;
329 char name_buf[128];
330 char* filename;
331 if (name_len < 128) {
332 filename = name_buf;
333 } else {
334 filename = NEW_RESOURCE_ARRAY(char, name_len + 1);
335 }
336
337 // read contents into resource array
338 int size = (*filesize) + ((nul_terminate) ? 1 : 0);
339 buffer = NEW_RESOURCE_ARRAY(u1, size);
1056 // First make sure native library is loaded
1057 os::native_java_library();
1058 // Load zip library
1059 char path[JVM_MAXPATHLEN];
1060 char ebuf[1024];
1061 void* handle = NULL;
1062 if (os::dll_build_name(path, sizeof(path), Arguments::get_dll_dir(), "zip")) {
1063 handle = os::dll_load(path, ebuf, sizeof ebuf);
1064 }
1065 if (handle == NULL) {
1066 vm_exit_during_initialization("Unable to load ZIP library", path);
1067 }
1068 // Lookup zip entry points
1069 ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, os::dll_lookup(handle, "ZIP_Open"));
1070 ZipClose = CAST_TO_FN_PTR(ZipClose_t, os::dll_lookup(handle, "ZIP_Close"));
1071 FindEntry = CAST_TO_FN_PTR(FindEntry_t, os::dll_lookup(handle, "ZIP_FindEntry"));
1072 ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, os::dll_lookup(handle, "ZIP_ReadEntry"));
1073 GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, os::dll_lookup(handle, "ZIP_GetNextEntry"));
1074 ZipInflateFully = CAST_TO_FN_PTR(ZipInflateFully_t, os::dll_lookup(handle, "ZIP_InflateFully"));
1075 Crc32 = CAST_TO_FN_PTR(Crc32_t, os::dll_lookup(handle, "ZIP_CRC32"));
1076
1077 // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL
1078 if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL ||
1079 GetNextEntry == NULL || Crc32 == NULL) {
1080 vm_exit_during_initialization("Corrupted ZIP library", path);
1081 }
1082
1083 if (ZipInflateFully == NULL) {
1084 vm_exit_during_initialization("Corrupted ZIP library ZIP_InflateFully missing", path);
1085 }
1086
1087 // Lookup canonicalize entry in libjava.dll
1088 void *javalib_handle = os::native_java_library();
1089 CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, os::dll_lookup(javalib_handle, "Canonicalize"));
1090 // This lookup only works on 1.3. Do not check for non-null here
1091 }
1092
1093 void ClassLoader::load_jimage_library() {
1094 // First make sure native library is loaded
1095 os::native_java_library();
1383 while (e != NULL) {
1384 stream = e->open_stream(file_name, CHECK_NULL);
1385 // No context.check is required since CDS is not supported
1386 // for an exploded modules build or if --patch-module is specified.
1387 if (NULL != stream) {
1388 return stream;
1389 }
1390 e = e->next();
1391 }
1392 // If the module was located, break out even if the class was not
1393 // located successfully from that module's ClassPathEntry list.
1394 // There will not be another valid entry for that module.
1395 return NULL;
1396 }
1397 }
1398 }
1399
1400 return NULL;
1401 }
1402
1403 instanceKlassHandle ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
1404 assert(name != NULL, "invariant");
1405 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1406
1407 ResourceMark rm(THREAD);
1408 HandleMark hm(THREAD);
1409
1410 const char* const class_name = name->as_C_string();
1411
1412 EventMark m("loading class %s", class_name);
1413 ThreadProfilerMark tpm(ThreadProfilerMark::classLoaderRegion);
1414
1415 const char* const file_name = file_name_for_class_name(class_name,
1416 name->utf8_length());
1417 assert(file_name != NULL, "invariant");
1418
1419 ClassLoaderExt::Context context(class_name, file_name, THREAD);
1420
1421 // Lookup stream for parsing .class file
1422 ClassFileStream* stream = NULL;
1423 s2 classpath_index = 0;
1424 ClassPathEntry* e = NULL;
1425
1426 // If DumpSharedSpaces is true boot loader visibility boundaries are set to:
1427 // - [jimage] + [_first_append_entry to _last_append_entry] (all path entries).
1428 //
1429 // If search_append_only is true, boot loader visibility boundaries are
1430 // set to be _first_append_entry to the end. This includes:
1431 // [-Xbootclasspath/a]; [jvmti appended entries]
1432 //
1433 // If both DumpSharedSpaces and search_append_only are false, boot loader
1434 // visibility boundaries are set to be the --patch-module entries plus the base piece.
1435 // This would include:
1436 // [--patch-module=<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
1437 //
1438 // DumpSharedSpaces and search_append_only are mutually exclusive and cannot
1439 // be true at the same time.
1440 assert(!(DumpSharedSpaces && search_append_only), "DumpSharedSpaces and search_append_only are both true");
1441
1442 // Load Attempt #1: --patch-module
1443 // Determine the class' defining module. If it appears in the _patch_mod_entries,
1444 // attempt to load the class from those locations specific to the module.
1445 // Specifications to --patch-module can contain a partial number of classes
1446 // that are part of the overall module definition. So if a particular class is not
1447 // found within its module specification, the search should continue to Load Attempt #2.
1448 // Note: The --patch-module entries are never searched if the boot loader's
1449 // visibility boundary is limited to only searching the append entries.
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 [jimage|exploded build] 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.
1456 if (!DumpSharedSpaces) {
1457 stream = search_module_entries(_patch_mod_entries, class_name, file_name, CHECK_NULL);
1458 }
1459 }
1460
1461 // Load Attempt #2: [jimage | exploded build]
1462 if (!search_append_only && (NULL == stream)) {
1463 if (has_jrt_entry()) {
1464 e = _jrt_entry;
1465 stream = _jrt_entry->open_stream(file_name, CHECK_NULL);
1466 if (!context.check(stream, classpath_index)) {
1467 return NULL;
1468 }
1469 } else {
1470 // Exploded build - attempt to locate class in its defining module's location.
1471 assert(_exploded_entries != NULL, "No exploded build entries present");
1472 stream = search_module_entries(_exploded_entries, class_name, file_name, CHECK_NULL);
1473 }
1474 }
1475
1476 // Load Attempt #3: [-Xbootclasspath/a]; [jvmti appended entries]
1477 if ((search_append_only || DumpSharedSpaces) && (NULL == stream)) {
1589 // increment the isUnsyncloadClass counter if UnsyncloadClass is set.
1590 if (UnsyncloadClass) {
1591 _isUnsyncloadClass->inc();
1592 }
1593 }
1594
1595 // lookup zip library entry points
1596 load_zip_library();
1597 // lookup jimage library entry points
1598 load_jimage_library();
1599 #if INCLUDE_CDS
1600 // initialize search path
1601 if (DumpSharedSpaces) {
1602 _shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info();
1603 }
1604 #endif
1605 setup_bootstrap_search_path();
1606 }
1607
1608 #if INCLUDE_CDS
1609 void ClassLoader::initialize_shared_path() {
1610 if (DumpSharedSpaces) {
1611 ClassLoaderExt::setup_search_paths();
1612 _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1613 }
1614 }
1615 #endif
1616
1617 jlong ClassLoader::classloader_time_ms() {
1618 return UsePerfData ?
1619 Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1620 }
1621
1622 jlong ClassLoader::class_init_count() {
1623 return UsePerfData ? _perf_classes_inited->get_value() : -1;
1624 }
1625
1626 jlong ClassLoader::class_init_time_ms() {
1627 return UsePerfData ?
1628 Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1629 }
1630
|