71 #include "utilities/classpathStream.hpp" |
71 #include "utilities/classpathStream.hpp" |
72 #include "utilities/events.hpp" |
72 #include "utilities/events.hpp" |
73 #include "utilities/hashtable.inline.hpp" |
73 #include "utilities/hashtable.inline.hpp" |
74 #include "utilities/macros.hpp" |
74 #include "utilities/macros.hpp" |
75 |
75 |
|
76 // Entry point in java.dll for path canonicalization |
|
77 |
|
78 static canonicalize_fn_t CanonicalizeEntry = NULL; |
|
79 |
76 // Entry points in zip.dll for loading zip/jar file entries |
80 // Entry points in zip.dll for loading zip/jar file entries |
77 |
81 |
78 typedef void * * (*ZipOpen_t)(const char *name, char **pmsg); |
82 typedef void * * (*ZipOpen_t)(const char *name, char **pmsg); |
79 typedef void (*ZipClose_t)(jzfile *zip); |
83 typedef void (*ZipClose_t)(jzfile *zip); |
80 typedef jzentry* (*FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen); |
84 typedef jzentry* (*FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen); |
81 typedef jboolean (*ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf); |
85 typedef jboolean (*ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf); |
82 typedef jzentry* (*GetNextEntry_t)(jzfile *zip, jint n); |
86 typedef jzentry* (*GetNextEntry_t)(jzfile *zip, jint n); |
83 typedef jboolean (*ZipInflateFully_t)(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg); |
|
84 typedef jint (*Crc32_t)(jint crc, const jbyte *buf, jint len); |
87 typedef jint (*Crc32_t)(jint crc, const jbyte *buf, jint len); |
85 |
88 |
86 static ZipOpen_t ZipOpen = NULL; |
89 static ZipOpen_t ZipOpen = NULL; |
87 static ZipClose_t ZipClose = NULL; |
90 static ZipClose_t ZipClose = NULL; |
88 static FindEntry_t FindEntry = NULL; |
91 static FindEntry_t FindEntry = NULL; |
89 static ReadEntry_t ReadEntry = NULL; |
92 static ReadEntry_t ReadEntry = NULL; |
90 static GetNextEntry_t GetNextEntry = NULL; |
93 static GetNextEntry_t GetNextEntry = NULL; |
91 static canonicalize_fn_t CanonicalizeEntry = NULL; |
|
92 static ZipInflateFully_t ZipInflateFully = NULL; |
|
93 static Crc32_t Crc32 = NULL; |
94 static Crc32_t Crc32 = NULL; |
94 |
95 |
95 // Entry points for jimage.dll for loading jimage file entries |
96 // Entry points for jimage.dll for loading jimage file entries |
96 |
97 |
97 static JImageOpen_t JImageOpen = NULL; |
98 static JImageOpen_t JImageOpen = NULL; |
962 e = e->next(); |
961 e = e->next(); |
963 } |
962 } |
964 tty->print_cr("]"); |
963 tty->print_cr("]"); |
965 } |
964 } |
966 |
965 |
|
966 void* ClassLoader::dll_lookup(void* lib, const char* name, const char* path) { |
|
967 void* func = os::dll_lookup(lib, name); |
|
968 if (func == NULL) { |
|
969 char msg[256] = ""; |
|
970 jio_snprintf(msg, sizeof(msg), "Could not resolve \"%s\"", name); |
|
971 vm_exit_during_initialization(msg, path); |
|
972 } |
|
973 return func; |
|
974 } |
|
975 |
|
976 void ClassLoader::load_java_library() { |
|
977 assert(CanonicalizeEntry == NULL, "should not load java library twice"); |
|
978 void *javalib_handle = os::native_java_library(); |
|
979 if (javalib_handle == NULL) { |
|
980 vm_exit_during_initialization("Unable to load java library", NULL); |
|
981 } |
|
982 |
|
983 CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, dll_lookup(javalib_handle, "Canonicalize", NULL)); |
|
984 } |
|
985 |
967 void ClassLoader::load_zip_library() { |
986 void ClassLoader::load_zip_library() { |
968 assert(ZipOpen == NULL, "should not load zip library twice"); |
987 assert(ZipOpen == NULL, "should not load zip library twice"); |
969 // First make sure native library is loaded |
|
970 os::native_java_library(); |
|
971 // Load zip library |
|
972 char path[JVM_MAXPATHLEN]; |
988 char path[JVM_MAXPATHLEN]; |
973 char ebuf[1024]; |
989 char ebuf[1024]; |
974 void* handle = NULL; |
990 void* handle = NULL; |
975 if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), "zip")) { |
991 if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), "zip")) { |
976 handle = os::dll_load(path, ebuf, sizeof ebuf); |
992 handle = os::dll_load(path, ebuf, sizeof ebuf); |
977 } |
993 } |
978 if (handle == NULL) { |
994 if (handle == NULL) { |
979 vm_exit_during_initialization("Unable to load ZIP library", path); |
995 vm_exit_during_initialization("Unable to load zip library", path); |
980 } |
996 } |
981 // Lookup zip entry points |
997 |
982 ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, os::dll_lookup(handle, "ZIP_Open")); |
998 ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, dll_lookup(handle, "ZIP_Open", path)); |
983 ZipClose = CAST_TO_FN_PTR(ZipClose_t, os::dll_lookup(handle, "ZIP_Close")); |
999 ZipClose = CAST_TO_FN_PTR(ZipClose_t, dll_lookup(handle, "ZIP_Close", path)); |
984 FindEntry = CAST_TO_FN_PTR(FindEntry_t, os::dll_lookup(handle, "ZIP_FindEntry")); |
1000 FindEntry = CAST_TO_FN_PTR(FindEntry_t, dll_lookup(handle, "ZIP_FindEntry", path)); |
985 ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, os::dll_lookup(handle, "ZIP_ReadEntry")); |
1001 ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, dll_lookup(handle, "ZIP_ReadEntry", path)); |
986 GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, os::dll_lookup(handle, "ZIP_GetNextEntry")); |
1002 GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, dll_lookup(handle, "ZIP_GetNextEntry", path)); |
987 ZipInflateFully = CAST_TO_FN_PTR(ZipInflateFully_t, os::dll_lookup(handle, "ZIP_InflateFully")); |
1003 Crc32 = CAST_TO_FN_PTR(Crc32_t, dll_lookup(handle, "ZIP_CRC32", path)); |
988 Crc32 = CAST_TO_FN_PTR(Crc32_t, os::dll_lookup(handle, "ZIP_CRC32")); |
|
989 |
|
990 // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL |
|
991 if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL || |
|
992 GetNextEntry == NULL || Crc32 == NULL) { |
|
993 vm_exit_during_initialization("Corrupted ZIP library", path); |
|
994 } |
|
995 |
|
996 if (ZipInflateFully == NULL) { |
|
997 vm_exit_during_initialization("Corrupted ZIP library ZIP_InflateFully missing", path); |
|
998 } |
|
999 |
|
1000 // Lookup canonicalize entry in libjava.dll |
|
1001 void *javalib_handle = os::native_java_library(); |
|
1002 CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, os::dll_lookup(javalib_handle, "Canonicalize")); |
|
1003 // This lookup only works on 1.3. Do not check for non-null here |
|
1004 } |
1004 } |
1005 |
1005 |
1006 void ClassLoader::load_jimage_library() { |
1006 void ClassLoader::load_jimage_library() { |
1007 // First make sure native library is loaded |
1007 assert(JImageOpen == NULL, "should not load jimage library twice"); |
1008 os::native_java_library(); |
|
1009 // Load jimage library |
|
1010 char path[JVM_MAXPATHLEN]; |
1008 char path[JVM_MAXPATHLEN]; |
1011 char ebuf[1024]; |
1009 char ebuf[1024]; |
1012 void* handle = NULL; |
1010 void* handle = NULL; |
1013 if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), "jimage")) { |
1011 if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), "jimage")) { |
1014 handle = os::dll_load(path, ebuf, sizeof ebuf); |
1012 handle = os::dll_load(path, ebuf, sizeof ebuf); |
1015 } |
1013 } |
1016 if (handle == NULL) { |
1014 if (handle == NULL) { |
1017 vm_exit_during_initialization("Unable to load jimage library", path); |
1015 vm_exit_during_initialization("Unable to load jimage library", path); |
1018 } |
1016 } |
1019 |
1017 |
1020 // Lookup jimage entry points |
1018 JImageOpen = CAST_TO_FN_PTR(JImageOpen_t, dll_lookup(handle, "JIMAGE_Open", path)); |
1021 JImageOpen = CAST_TO_FN_PTR(JImageOpen_t, os::dll_lookup(handle, "JIMAGE_Open")); |
1019 JImageClose = CAST_TO_FN_PTR(JImageClose_t, dll_lookup(handle, "JIMAGE_Close", path)); |
1022 guarantee(JImageOpen != NULL, "function JIMAGE_Open not found"); |
1020 JImagePackageToModule = CAST_TO_FN_PTR(JImagePackageToModule_t, dll_lookup(handle, "JIMAGE_PackageToModule", path)); |
1023 JImageClose = CAST_TO_FN_PTR(JImageClose_t, os::dll_lookup(handle, "JIMAGE_Close")); |
1021 JImageFindResource = CAST_TO_FN_PTR(JImageFindResource_t, dll_lookup(handle, "JIMAGE_FindResource", path)); |
1024 guarantee(JImageClose != NULL, "function JIMAGE_Close not found"); |
1022 JImageGetResource = CAST_TO_FN_PTR(JImageGetResource_t, dll_lookup(handle, "JIMAGE_GetResource", path)); |
1025 JImagePackageToModule = CAST_TO_FN_PTR(JImagePackageToModule_t, os::dll_lookup(handle, "JIMAGE_PackageToModule")); |
1023 JImageResourceIterator = CAST_TO_FN_PTR(JImageResourceIterator_t, dll_lookup(handle, "JIMAGE_ResourceIterator", path)); |
1026 guarantee(JImagePackageToModule != NULL, "function JIMAGE_PackageToModule not found"); |
|
1027 JImageFindResource = CAST_TO_FN_PTR(JImageFindResource_t, os::dll_lookup(handle, "JIMAGE_FindResource")); |
|
1028 guarantee(JImageFindResource != NULL, "function JIMAGE_FindResource not found"); |
|
1029 JImageGetResource = CAST_TO_FN_PTR(JImageGetResource_t, os::dll_lookup(handle, "JIMAGE_GetResource")); |
|
1030 guarantee(JImageGetResource != NULL, "function JIMAGE_GetResource not found"); |
|
1031 JImageResourceIterator = CAST_TO_FN_PTR(JImageResourceIterator_t, os::dll_lookup(handle, "JIMAGE_ResourceIterator")); |
|
1032 guarantee(JImageResourceIterator != NULL, "function JIMAGE_ResourceIterator not found"); |
|
1033 } |
|
1034 |
|
1035 jboolean ClassLoader::decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg) { |
|
1036 return (*ZipInflateFully)(in, inSize, out, outSize, pmsg); |
|
1037 } |
1024 } |
1038 |
1025 |
1039 int ClassLoader::crc32(int crc, const char* buf, int len) { |
1026 int ClassLoader::crc32(int crc, const char* buf, int len) { |
1040 assert(Crc32 != NULL, "ZIP_CRC32 is not found"); |
|
1041 return (*Crc32)(crc, (const jbyte*)buf, len); |
1027 return (*Crc32)(crc, (const jbyte*)buf, len); |
1042 } |
1028 } |
1043 |
1029 |
1044 // Function add_package extracts the package from the fully qualified class name |
1030 // Function add_package extracts the package from the fully qualified class name |
1045 // and checks if the package is in the boot loader's package entry table. If so, |
1031 // and checks if the package is in the boot loader's package entry table. If so, |
1650 GrowableArray<ModuleClassPathList*>(EXPLODED_ENTRY_SIZE, true); |
1638 GrowableArray<ModuleClassPathList*>(EXPLODED_ENTRY_SIZE, true); |
1651 add_to_exploded_build_list(vmSymbols::java_base(), CHECK); |
1639 add_to_exploded_build_list(vmSymbols::java_base(), CHECK); |
1652 } |
1640 } |
1653 } |
1641 } |
1654 |
1642 |
1655 |
|
1656 bool ClassLoader::get_canonical_path(const char* orig, char* out, int len) { |
1643 bool ClassLoader::get_canonical_path(const char* orig, char* out, int len) { |
1657 assert(orig != NULL && out != NULL && len > 0, "bad arguments"); |
1644 assert(orig != NULL && out != NULL && len > 0, "bad arguments"); |
1658 if (CanonicalizeEntry != NULL) { |
1645 JavaThread* THREAD = JavaThread::current(); |
1659 JavaThread* THREAD = JavaThread::current(); |
1646 JNIEnv* env = THREAD->jni_environment(); |
1660 JNIEnv* env = THREAD->jni_environment(); |
1647 ResourceMark rm(THREAD); |
1661 ResourceMark rm(THREAD); |
1648 |
1662 |
1649 // os::native_path writes into orig_copy |
1663 // os::native_path writes into orig_copy |
1650 char* orig_copy = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(orig)+1); |
1664 char* orig_copy = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(orig)+1); |
1651 strcpy(orig_copy, orig); |
1665 strcpy(orig_copy, orig); |
1652 if ((CanonicalizeEntry)(env, os::native_path(orig_copy), out, len) < 0) { |
1666 if ((CanonicalizeEntry)(env, os::native_path(orig_copy), out, len) < 0) { |
1653 return false; |
1667 return false; |
|
1668 } |
|
1669 } else { |
|
1670 // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing |
|
1671 strncpy(out, orig, len); |
|
1672 out[len - 1] = '\0'; |
|
1673 } |
1654 } |
1674 return true; |
1655 return true; |
1675 } |
1656 } |
1676 |
1657 |
1677 void ClassLoader::create_javabase() { |
1658 void ClassLoader::create_javabase() { |