Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "classfile/classFileParser.hpp" |
aoqi@0 | 27 | #include "classfile/classFileStream.hpp" |
aoqi@0 | 28 | #include "classfile/classLoader.hpp" |
iklam@7089 | 29 | #include "classfile/classLoaderExt.hpp" |
aoqi@0 | 30 | #include "classfile/classLoaderData.inline.hpp" |
aoqi@0 | 31 | #include "classfile/javaClasses.hpp" |
iklam@7089 | 32 | #if INCLUDE_CDS |
iklam@7089 | 33 | #include "classfile/sharedPathsMiscInfo.hpp" |
iklam@7089 | 34 | #include "classfile/sharedClassUtil.hpp" |
iklam@7089 | 35 | #endif |
aoqi@0 | 36 | #include "classfile/systemDictionary.hpp" |
aoqi@0 | 37 | #include "classfile/vmSymbols.hpp" |
aoqi@0 | 38 | #include "compiler/compileBroker.hpp" |
aoqi@0 | 39 | #include "gc_interface/collectedHeap.inline.hpp" |
aoqi@0 | 40 | #include "interpreter/bytecodeStream.hpp" |
aoqi@0 | 41 | #include "interpreter/oopMapCache.hpp" |
aoqi@0 | 42 | #include "memory/allocation.inline.hpp" |
iklam@7089 | 43 | #include "memory/filemap.hpp" |
aoqi@0 | 44 | #include "memory/generation.hpp" |
aoqi@0 | 45 | #include "memory/oopFactory.hpp" |
aoqi@0 | 46 | #include "memory/universe.inline.hpp" |
aoqi@0 | 47 | #include "oops/instanceKlass.hpp" |
aoqi@0 | 48 | #include "oops/instanceRefKlass.hpp" |
aoqi@0 | 49 | #include "oops/oop.inline.hpp" |
aoqi@0 | 50 | #include "oops/symbol.hpp" |
aoqi@0 | 51 | #include "prims/jvm_misc.hpp" |
aoqi@0 | 52 | #include "runtime/arguments.hpp" |
aoqi@0 | 53 | #include "runtime/compilationPolicy.hpp" |
aoqi@0 | 54 | #include "runtime/fprofiler.hpp" |
aoqi@0 | 55 | #include "runtime/handles.hpp" |
aoqi@0 | 56 | #include "runtime/handles.inline.hpp" |
aoqi@0 | 57 | #include "runtime/init.hpp" |
aoqi@0 | 58 | #include "runtime/interfaceSupport.hpp" |
aoqi@0 | 59 | #include "runtime/java.hpp" |
aoqi@0 | 60 | #include "runtime/javaCalls.hpp" |
aoqi@0 | 61 | #include "runtime/threadCritical.hpp" |
aoqi@0 | 62 | #include "runtime/timer.hpp" |
aoqi@0 | 63 | #include "services/management.hpp" |
aoqi@0 | 64 | #include "services/threadService.hpp" |
aoqi@0 | 65 | #include "utilities/events.hpp" |
aoqi@0 | 66 | #include "utilities/hashtable.hpp" |
aoqi@0 | 67 | #include "utilities/hashtable.inline.hpp" |
aoqi@0 | 68 | #ifdef TARGET_OS_FAMILY_linux |
aoqi@0 | 69 | # include "os_linux.inline.hpp" |
aoqi@0 | 70 | #endif |
aoqi@0 | 71 | #ifdef TARGET_OS_FAMILY_solaris |
aoqi@0 | 72 | # include "os_solaris.inline.hpp" |
aoqi@0 | 73 | #endif |
aoqi@0 | 74 | #ifdef TARGET_OS_FAMILY_windows |
aoqi@0 | 75 | # include "os_windows.inline.hpp" |
aoqi@0 | 76 | #endif |
aoqi@0 | 77 | #ifdef TARGET_OS_FAMILY_aix |
aoqi@0 | 78 | # include "os_aix.inline.hpp" |
aoqi@0 | 79 | #endif |
aoqi@0 | 80 | #ifdef TARGET_OS_FAMILY_bsd |
aoqi@0 | 81 | # include "os_bsd.inline.hpp" |
aoqi@0 | 82 | #endif |
aoqi@0 | 83 | |
aoqi@0 | 84 | |
aoqi@0 | 85 | // Entry points in zip.dll for loading zip/jar file entries |
aoqi@0 | 86 | |
aoqi@0 | 87 | typedef void * * (JNICALL *ZipOpen_t)(const char *name, char **pmsg); |
aoqi@0 | 88 | typedef void (JNICALL *ZipClose_t)(jzfile *zip); |
aoqi@0 | 89 | typedef jzentry* (JNICALL *FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen); |
aoqi@0 | 90 | typedef jboolean (JNICALL *ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf); |
aoqi@0 | 91 | typedef jboolean (JNICALL *ReadMappedEntry_t)(jzfile *zip, jzentry *entry, unsigned char **buf, char *namebuf); |
aoqi@0 | 92 | typedef jzentry* (JNICALL *GetNextEntry_t)(jzfile *zip, jint n); |
aoqi@0 | 93 | typedef jint (JNICALL *Crc32_t)(jint crc, const jbyte *buf, jint len); |
aoqi@0 | 94 | |
aoqi@0 | 95 | static ZipOpen_t ZipOpen = NULL; |
aoqi@0 | 96 | static ZipClose_t ZipClose = NULL; |
aoqi@0 | 97 | static FindEntry_t FindEntry = NULL; |
aoqi@0 | 98 | static ReadEntry_t ReadEntry = NULL; |
aoqi@0 | 99 | static ReadMappedEntry_t ReadMappedEntry = NULL; |
aoqi@0 | 100 | static GetNextEntry_t GetNextEntry = NULL; |
aoqi@0 | 101 | static canonicalize_fn_t CanonicalizeEntry = NULL; |
aoqi@0 | 102 | static Crc32_t Crc32 = NULL; |
aoqi@0 | 103 | |
aoqi@0 | 104 | // Globals |
aoqi@0 | 105 | |
aoqi@0 | 106 | PerfCounter* ClassLoader::_perf_accumulated_time = NULL; |
aoqi@0 | 107 | PerfCounter* ClassLoader::_perf_classes_inited = NULL; |
aoqi@0 | 108 | PerfCounter* ClassLoader::_perf_class_init_time = NULL; |
aoqi@0 | 109 | PerfCounter* ClassLoader::_perf_class_init_selftime = NULL; |
aoqi@0 | 110 | PerfCounter* ClassLoader::_perf_classes_verified = NULL; |
aoqi@0 | 111 | PerfCounter* ClassLoader::_perf_class_verify_time = NULL; |
aoqi@0 | 112 | PerfCounter* ClassLoader::_perf_class_verify_selftime = NULL; |
aoqi@0 | 113 | PerfCounter* ClassLoader::_perf_classes_linked = NULL; |
aoqi@0 | 114 | PerfCounter* ClassLoader::_perf_class_link_time = NULL; |
aoqi@0 | 115 | PerfCounter* ClassLoader::_perf_class_link_selftime = NULL; |
aoqi@0 | 116 | PerfCounter* ClassLoader::_perf_class_parse_time = NULL; |
aoqi@0 | 117 | PerfCounter* ClassLoader::_perf_class_parse_selftime = NULL; |
aoqi@0 | 118 | PerfCounter* ClassLoader::_perf_sys_class_lookup_time = NULL; |
aoqi@0 | 119 | PerfCounter* ClassLoader::_perf_shared_classload_time = NULL; |
aoqi@0 | 120 | PerfCounter* ClassLoader::_perf_sys_classload_time = NULL; |
aoqi@0 | 121 | PerfCounter* ClassLoader::_perf_app_classload_time = NULL; |
aoqi@0 | 122 | PerfCounter* ClassLoader::_perf_app_classload_selftime = NULL; |
aoqi@0 | 123 | PerfCounter* ClassLoader::_perf_app_classload_count = NULL; |
aoqi@0 | 124 | PerfCounter* ClassLoader::_perf_define_appclasses = NULL; |
aoqi@0 | 125 | PerfCounter* ClassLoader::_perf_define_appclass_time = NULL; |
aoqi@0 | 126 | PerfCounter* ClassLoader::_perf_define_appclass_selftime = NULL; |
aoqi@0 | 127 | PerfCounter* ClassLoader::_perf_app_classfile_bytes_read = NULL; |
aoqi@0 | 128 | PerfCounter* ClassLoader::_perf_sys_classfile_bytes_read = NULL; |
aoqi@0 | 129 | PerfCounter* ClassLoader::_sync_systemLoaderLockContentionRate = NULL; |
aoqi@0 | 130 | PerfCounter* ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL; |
aoqi@0 | 131 | PerfCounter* ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL; |
aoqi@0 | 132 | PerfCounter* ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL; |
aoqi@0 | 133 | PerfCounter* ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL; |
aoqi@0 | 134 | PerfCounter* ClassLoader::_unsafe_defineClassCallCounter = NULL; |
aoqi@0 | 135 | PerfCounter* ClassLoader::_isUnsyncloadClass = NULL; |
aoqi@0 | 136 | PerfCounter* ClassLoader::_load_instance_class_failCounter = NULL; |
aoqi@0 | 137 | |
aoqi@0 | 138 | ClassPathEntry* ClassLoader::_first_entry = NULL; |
aoqi@0 | 139 | ClassPathEntry* ClassLoader::_last_entry = NULL; |
iklam@7089 | 140 | int ClassLoader::_num_entries = 0; |
aoqi@0 | 141 | PackageHashtable* ClassLoader::_package_hash_table = NULL; |
aoqi@0 | 142 | |
iklam@7089 | 143 | #if INCLUDE_CDS |
iklam@7089 | 144 | SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL; |
iklam@7089 | 145 | #endif |
aoqi@0 | 146 | // helper routines |
aoqi@0 | 147 | bool string_starts_with(const char* str, const char* str_to_find) { |
aoqi@0 | 148 | size_t str_len = strlen(str); |
aoqi@0 | 149 | size_t str_to_find_len = strlen(str_to_find); |
aoqi@0 | 150 | if (str_to_find_len > str_len) { |
aoqi@0 | 151 | return false; |
aoqi@0 | 152 | } |
aoqi@0 | 153 | return (strncmp(str, str_to_find, str_to_find_len) == 0); |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | bool string_ends_with(const char* str, const char* str_to_find) { |
aoqi@0 | 157 | size_t str_len = strlen(str); |
aoqi@0 | 158 | size_t str_to_find_len = strlen(str_to_find); |
aoqi@0 | 159 | if (str_to_find_len > str_len) { |
aoqi@0 | 160 | return false; |
aoqi@0 | 161 | } |
aoqi@0 | 162 | return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0); |
aoqi@0 | 163 | } |
aoqi@0 | 164 | |
aoqi@0 | 165 | |
aoqi@0 | 166 | MetaIndex::MetaIndex(char** meta_package_names, int num_meta_package_names) { |
aoqi@0 | 167 | if (num_meta_package_names == 0) { |
aoqi@0 | 168 | _meta_package_names = NULL; |
aoqi@0 | 169 | _num_meta_package_names = 0; |
aoqi@0 | 170 | } else { |
aoqi@0 | 171 | _meta_package_names = NEW_C_HEAP_ARRAY(char*, num_meta_package_names, mtClass); |
aoqi@0 | 172 | _num_meta_package_names = num_meta_package_names; |
aoqi@0 | 173 | memcpy(_meta_package_names, meta_package_names, num_meta_package_names * sizeof(char*)); |
aoqi@0 | 174 | } |
aoqi@0 | 175 | } |
aoqi@0 | 176 | |
aoqi@0 | 177 | |
aoqi@0 | 178 | MetaIndex::~MetaIndex() { |
aoqi@0 | 179 | FREE_C_HEAP_ARRAY(char*, _meta_package_names, mtClass); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | |
aoqi@0 | 183 | bool MetaIndex::may_contain(const char* class_name) { |
aoqi@0 | 184 | if ( _num_meta_package_names == 0) { |
aoqi@0 | 185 | return false; |
aoqi@0 | 186 | } |
aoqi@0 | 187 | size_t class_name_len = strlen(class_name); |
aoqi@0 | 188 | for (int i = 0; i < _num_meta_package_names; i++) { |
aoqi@0 | 189 | char* pkg = _meta_package_names[i]; |
aoqi@0 | 190 | size_t pkg_len = strlen(pkg); |
aoqi@0 | 191 | size_t min_len = MIN2(class_name_len, pkg_len); |
aoqi@0 | 192 | if (!strncmp(class_name, pkg, min_len)) { |
aoqi@0 | 193 | return true; |
aoqi@0 | 194 | } |
aoqi@0 | 195 | } |
aoqi@0 | 196 | return false; |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | |
aoqi@0 | 200 | ClassPathEntry::ClassPathEntry() { |
aoqi@0 | 201 | set_next(NULL); |
aoqi@0 | 202 | } |
aoqi@0 | 203 | |
aoqi@0 | 204 | |
aoqi@0 | 205 | bool ClassPathEntry::is_lazy() { |
aoqi@0 | 206 | return false; |
aoqi@0 | 207 | } |
aoqi@0 | 208 | |
iklam@7090 | 209 | ClassPathDirEntry::ClassPathDirEntry(const char* dir) : ClassPathEntry() { |
iklam@7090 | 210 | char* copy = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass); |
iklam@7090 | 211 | strcpy(copy, dir); |
iklam@7090 | 212 | _dir = copy; |
aoqi@0 | 213 | } |
aoqi@0 | 214 | |
aoqi@0 | 215 | |
aoqi@0 | 216 | ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) { |
aoqi@0 | 217 | // construct full path name |
aoqi@0 | 218 | char path[JVM_MAXPATHLEN]; |
aoqi@0 | 219 | if (jio_snprintf(path, sizeof(path), "%s%s%s", _dir, os::file_separator(), name) == -1) { |
aoqi@0 | 220 | return NULL; |
aoqi@0 | 221 | } |
aoqi@0 | 222 | // check if file exists |
aoqi@0 | 223 | struct stat st; |
aoqi@0 | 224 | if (os::stat(path, &st) == 0) { |
iklam@7089 | 225 | #if INCLUDE_CDS |
iklam@7089 | 226 | if (DumpSharedSpaces) { |
iklam@7089 | 227 | // We have already check in ClassLoader::check_shared_classpath() that the directory is empty, so |
iklam@7089 | 228 | // we should never find a file underneath it -- unless user has added a new file while we are running |
iklam@7089 | 229 | // the dump, in which case let's quit! |
iklam@7089 | 230 | ShouldNotReachHere(); |
iklam@7089 | 231 | } |
iklam@7089 | 232 | #endif |
aoqi@0 | 233 | // found file, open it |
aoqi@0 | 234 | int file_handle = os::open(path, 0, 0); |
aoqi@0 | 235 | if (file_handle != -1) { |
aoqi@0 | 236 | // read contents into resource array |
aoqi@0 | 237 | u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size); |
aoqi@0 | 238 | size_t num_read = os::read(file_handle, (char*) buffer, st.st_size); |
aoqi@0 | 239 | // close file |
aoqi@0 | 240 | os::close(file_handle); |
aoqi@0 | 241 | // construct ClassFileStream |
aoqi@0 | 242 | if (num_read == (size_t)st.st_size) { |
aoqi@0 | 243 | if (UsePerfData) { |
aoqi@0 | 244 | ClassLoader::perf_sys_classfile_bytes_read()->inc(num_read); |
aoqi@0 | 245 | } |
aoqi@0 | 246 | return new ClassFileStream(buffer, st.st_size, _dir); // Resource allocated |
aoqi@0 | 247 | } |
aoqi@0 | 248 | } |
aoqi@0 | 249 | } |
aoqi@0 | 250 | return NULL; |
aoqi@0 | 251 | } |
aoqi@0 | 252 | |
aoqi@0 | 253 | |
aoqi@0 | 254 | ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() { |
aoqi@0 | 255 | _zip = zip; |
iklam@7090 | 256 | char *copy = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass); |
iklam@7090 | 257 | strcpy(copy, zip_name); |
iklam@7090 | 258 | _zip_name = copy; |
aoqi@0 | 259 | } |
aoqi@0 | 260 | |
aoqi@0 | 261 | ClassPathZipEntry::~ClassPathZipEntry() { |
aoqi@0 | 262 | if (ZipClose != NULL) { |
aoqi@0 | 263 | (*ZipClose)(_zip); |
aoqi@0 | 264 | } |
aoqi@0 | 265 | FREE_C_HEAP_ARRAY(char, _zip_name, mtClass); |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
iklam@7089 | 268 | u1* ClassPathZipEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) { |
iklam@7089 | 269 | // enable call to C land |
aoqi@0 | 270 | JavaThread* thread = JavaThread::current(); |
aoqi@0 | 271 | ThreadToNativeFromVM ttn(thread); |
aoqi@0 | 272 | // check whether zip archive contains name |
iklam@7089 | 273 | jint name_len; |
iklam@7089 | 274 | jzentry* entry = (*FindEntry)(_zip, name, filesize, &name_len); |
aoqi@0 | 275 | if (entry == NULL) return NULL; |
aoqi@0 | 276 | u1* buffer; |
aoqi@0 | 277 | char name_buf[128]; |
aoqi@0 | 278 | char* filename; |
aoqi@0 | 279 | if (name_len < 128) { |
aoqi@0 | 280 | filename = name_buf; |
aoqi@0 | 281 | } else { |
aoqi@0 | 282 | filename = NEW_RESOURCE_ARRAY(char, name_len + 1); |
aoqi@0 | 283 | } |
aoqi@0 | 284 | |
iklam@7089 | 285 | // file found, get pointer to the entry in mmapped jar file. |
aoqi@0 | 286 | if (ReadMappedEntry == NULL || |
aoqi@0 | 287 | !(*ReadMappedEntry)(_zip, entry, &buffer, filename)) { |
iklam@7089 | 288 | // mmapped access not available, perhaps due to compression, |
aoqi@0 | 289 | // read contents into resource array |
iklam@7089 | 290 | int size = (*filesize) + ((nul_terminate) ? 1 : 0); |
iklam@7089 | 291 | buffer = NEW_RESOURCE_ARRAY(u1, size); |
aoqi@0 | 292 | if (!(*ReadEntry)(_zip, entry, buffer, filename)) return NULL; |
aoqi@0 | 293 | } |
iklam@7089 | 294 | |
iklam@7089 | 295 | // return result |
iklam@7089 | 296 | if (nul_terminate) { |
iklam@7089 | 297 | buffer[*filesize] = 0; |
iklam@7089 | 298 | } |
iklam@7089 | 299 | return buffer; |
iklam@7089 | 300 | } |
iklam@7089 | 301 | |
iklam@7089 | 302 | ClassFileStream* ClassPathZipEntry::open_stream(const char* name, TRAPS) { |
iklam@7089 | 303 | jint filesize; |
iklam@7089 | 304 | u1* buffer = open_entry(name, &filesize, false, CHECK_NULL); |
iklam@7089 | 305 | if (buffer == NULL) { |
iklam@7089 | 306 | return NULL; |
iklam@7089 | 307 | } |
aoqi@0 | 308 | if (UsePerfData) { |
aoqi@0 | 309 | ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize); |
aoqi@0 | 310 | } |
iklam@7089 | 311 | return new ClassFileStream(buffer, filesize, _zip_name); // Resource allocated |
aoqi@0 | 312 | } |
aoqi@0 | 313 | |
aoqi@0 | 314 | // invoke function for each entry in the zip file |
aoqi@0 | 315 | void ClassPathZipEntry::contents_do(void f(const char* name, void* context), void* context) { |
aoqi@0 | 316 | JavaThread* thread = JavaThread::current(); |
aoqi@0 | 317 | HandleMark handle_mark(thread); |
aoqi@0 | 318 | ThreadToNativeFromVM ttn(thread); |
aoqi@0 | 319 | for (int n = 0; ; n++) { |
aoqi@0 | 320 | jzentry * ze = ((*GetNextEntry)(_zip, n)); |
aoqi@0 | 321 | if (ze == NULL) break; |
aoqi@0 | 322 | (*f)(ze->name, context); |
aoqi@0 | 323 | } |
aoqi@0 | 324 | } |
aoqi@0 | 325 | |
iklam@7090 | 326 | LazyClassPathEntry::LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() { |
aoqi@0 | 327 | _path = strdup(path); |
aoqi@0 | 328 | _st = *st; |
aoqi@0 | 329 | _meta_index = NULL; |
aoqi@0 | 330 | _resolved_entry = NULL; |
aoqi@0 | 331 | _has_error = false; |
iklam@7089 | 332 | _throw_exception = throw_exception; |
aoqi@0 | 333 | } |
aoqi@0 | 334 | |
aoqi@0 | 335 | bool LazyClassPathEntry::is_jar_file() { |
aoqi@0 | 336 | return ((_st.st_mode & S_IFREG) == S_IFREG); |
aoqi@0 | 337 | } |
aoqi@0 | 338 | |
aoqi@0 | 339 | ClassPathEntry* LazyClassPathEntry::resolve_entry(TRAPS) { |
aoqi@0 | 340 | if (_resolved_entry != NULL) { |
aoqi@0 | 341 | return (ClassPathEntry*) _resolved_entry; |
aoqi@0 | 342 | } |
aoqi@0 | 343 | ClassPathEntry* new_entry = NULL; |
iklam@7089 | 344 | new_entry = ClassLoader::create_class_path_entry(_path, &_st, false, _throw_exception, CHECK_NULL); |
iklam@7089 | 345 | if (!_throw_exception && new_entry == NULL) { |
iklam@7089 | 346 | assert(!HAS_PENDING_EXCEPTION, "must be"); |
iklam@7089 | 347 | return NULL; |
iklam@7089 | 348 | } |
aoqi@0 | 349 | { |
aoqi@0 | 350 | ThreadCritical tc; |
aoqi@0 | 351 | if (_resolved_entry == NULL) { |
aoqi@0 | 352 | _resolved_entry = new_entry; |
aoqi@0 | 353 | return new_entry; |
aoqi@0 | 354 | } |
aoqi@0 | 355 | } |
aoqi@0 | 356 | assert(_resolved_entry != NULL, "bug in MT-safe resolution logic"); |
aoqi@0 | 357 | delete new_entry; |
aoqi@0 | 358 | return (ClassPathEntry*) _resolved_entry; |
aoqi@0 | 359 | } |
aoqi@0 | 360 | |
aoqi@0 | 361 | ClassFileStream* LazyClassPathEntry::open_stream(const char* name, TRAPS) { |
aoqi@0 | 362 | if (_meta_index != NULL && |
aoqi@0 | 363 | !_meta_index->may_contain(name)) { |
aoqi@0 | 364 | return NULL; |
aoqi@0 | 365 | } |
aoqi@0 | 366 | if (_has_error) { |
aoqi@0 | 367 | return NULL; |
aoqi@0 | 368 | } |
aoqi@0 | 369 | ClassPathEntry* cpe = resolve_entry(THREAD); |
aoqi@0 | 370 | if (cpe == NULL) { |
aoqi@0 | 371 | _has_error = true; |
aoqi@0 | 372 | return NULL; |
aoqi@0 | 373 | } else { |
aoqi@0 | 374 | return cpe->open_stream(name, THREAD); |
aoqi@0 | 375 | } |
aoqi@0 | 376 | } |
aoqi@0 | 377 | |
aoqi@0 | 378 | bool LazyClassPathEntry::is_lazy() { |
aoqi@0 | 379 | return true; |
aoqi@0 | 380 | } |
aoqi@0 | 381 | |
iklam@7089 | 382 | u1* LazyClassPathEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) { |
iklam@7089 | 383 | if (_has_error) { |
iklam@7089 | 384 | return NULL; |
iklam@7089 | 385 | } |
iklam@7089 | 386 | ClassPathEntry* cpe = resolve_entry(THREAD); |
iklam@7089 | 387 | if (cpe == NULL) { |
iklam@7089 | 388 | _has_error = true; |
iklam@7089 | 389 | return NULL; |
iklam@7089 | 390 | } else if (cpe->is_jar_file()) { |
iklam@7089 | 391 | return ((ClassPathZipEntry*)cpe)->open_entry(name, filesize, nul_terminate,THREAD); |
iklam@7089 | 392 | } else { |
iklam@7089 | 393 | ShouldNotReachHere(); |
iklam@7089 | 394 | *filesize = 0; |
iklam@7089 | 395 | return NULL; |
iklam@7089 | 396 | } |
iklam@7089 | 397 | } |
iklam@7089 | 398 | |
aoqi@0 | 399 | static void print_meta_index(LazyClassPathEntry* entry, |
aoqi@0 | 400 | GrowableArray<char*>& meta_packages) { |
aoqi@0 | 401 | tty->print("[Meta index for %s=", entry->name()); |
aoqi@0 | 402 | for (int i = 0; i < meta_packages.length(); i++) { |
aoqi@0 | 403 | if (i > 0) tty->print(" "); |
aoqi@0 | 404 | tty->print("%s", meta_packages.at(i)); |
aoqi@0 | 405 | } |
aoqi@0 | 406 | tty->print_cr("]"); |
aoqi@0 | 407 | } |
aoqi@0 | 408 | |
iklam@7089 | 409 | #if INCLUDE_CDS |
iklam@7089 | 410 | void ClassLoader::exit_with_path_failure(const char* error, const char* message) { |
iklam@7089 | 411 | assert(DumpSharedSpaces, "only called at dump time"); |
iklam@7089 | 412 | tty->print_cr("Hint: enable -XX:+TraceClassPaths to diagnose the failure"); |
iklam@7089 | 413 | vm_exit_during_initialization(error, message); |
iklam@7089 | 414 | } |
iklam@7089 | 415 | #endif |
aoqi@0 | 416 | |
ccheung@8184 | 417 | void ClassLoader::trace_class_path(outputStream* out, const char* msg, const char* name) { |
iklam@7089 | 418 | if (!TraceClassPaths) { |
iklam@7089 | 419 | return; |
iklam@7089 | 420 | } |
iklam@7089 | 421 | |
iklam@7089 | 422 | if (msg) { |
ccheung@8184 | 423 | out->print("%s", msg); |
iklam@7089 | 424 | } |
iklam@7089 | 425 | if (name) { |
iklam@7089 | 426 | if (strlen(name) < 256) { |
ccheung@8184 | 427 | out->print("%s", name); |
iklam@7089 | 428 | } else { |
iklam@7089 | 429 | // For very long paths, we need to print each character separately, |
iklam@7089 | 430 | // as print_cr() has a length limit |
iklam@7089 | 431 | while (name[0] != '\0') { |
ccheung@8184 | 432 | out->print("%c", name[0]); |
iklam@7089 | 433 | name++; |
iklam@7089 | 434 | } |
iklam@7089 | 435 | } |
iklam@7089 | 436 | } |
iklam@7089 | 437 | if (msg && msg[0] == '[') { |
ccheung@8184 | 438 | out->print_cr("]"); |
iklam@7089 | 439 | } else { |
ccheung@8184 | 440 | out->cr(); |
iklam@7089 | 441 | } |
iklam@7089 | 442 | } |
iklam@7089 | 443 | |
iklam@7089 | 444 | void ClassLoader::setup_bootstrap_meta_index() { |
aoqi@0 | 445 | // Set up meta index which allows us to open boot jars lazily if |
aoqi@0 | 446 | // class data sharing is enabled |
iklam@7089 | 447 | const char* meta_index_path = Arguments::get_meta_index_path(); |
iklam@7089 | 448 | const char* meta_index_dir = Arguments::get_meta_index_dir(); |
iklam@7089 | 449 | setup_meta_index(meta_index_path, meta_index_dir, 0); |
iklam@7089 | 450 | } |
iklam@7089 | 451 | |
iklam@7089 | 452 | void ClassLoader::setup_meta_index(const char* meta_index_path, const char* meta_index_dir, int start_index) { |
aoqi@0 | 453 | const char* known_version = "% VERSION 2"; |
aoqi@0 | 454 | FILE* file = fopen(meta_index_path, "r"); |
aoqi@0 | 455 | int line_no = 0; |
iklam@7089 | 456 | #if INCLUDE_CDS |
iklam@7089 | 457 | if (DumpSharedSpaces) { |
iklam@7089 | 458 | if (file != NULL) { |
iklam@7089 | 459 | _shared_paths_misc_info->add_required_file(meta_index_path); |
iklam@7089 | 460 | } else { |
iklam@7089 | 461 | _shared_paths_misc_info->add_nonexist_path(meta_index_path); |
iklam@7089 | 462 | } |
iklam@7089 | 463 | } |
iklam@7089 | 464 | #endif |
aoqi@0 | 465 | if (file != NULL) { |
aoqi@0 | 466 | ResourceMark rm; |
aoqi@0 | 467 | LazyClassPathEntry* cur_entry = NULL; |
aoqi@0 | 468 | GrowableArray<char*> boot_class_path_packages(10); |
aoqi@0 | 469 | char package_name[256]; |
aoqi@0 | 470 | bool skipCurrentJar = false; |
aoqi@0 | 471 | while (fgets(package_name, sizeof(package_name), file) != NULL) { |
aoqi@0 | 472 | ++line_no; |
aoqi@0 | 473 | // Remove trailing newline |
aoqi@0 | 474 | package_name[strlen(package_name) - 1] = '\0'; |
aoqi@0 | 475 | switch(package_name[0]) { |
aoqi@0 | 476 | case '%': |
aoqi@0 | 477 | { |
aoqi@0 | 478 | if ((line_no == 1) && (strcmp(package_name, known_version) != 0)) { |
aoqi@0 | 479 | if (TraceClassLoading && Verbose) { |
aoqi@0 | 480 | tty->print("[Unsupported meta index version]"); |
aoqi@0 | 481 | } |
aoqi@0 | 482 | fclose(file); |
aoqi@0 | 483 | return; |
aoqi@0 | 484 | } |
aoqi@0 | 485 | } |
aoqi@0 | 486 | |
aoqi@0 | 487 | // These directives indicate jar files which contain only |
aoqi@0 | 488 | // classes, only non-classfile resources, or a combination of |
aoqi@0 | 489 | // the two. See src/share/classes/sun/misc/MetaIndex.java and |
aoqi@0 | 490 | // make/tools/MetaIndex/BuildMetaIndex.java in the J2SE |
aoqi@0 | 491 | // workspace. |
aoqi@0 | 492 | case '#': |
aoqi@0 | 493 | case '!': |
aoqi@0 | 494 | case '@': |
aoqi@0 | 495 | { |
aoqi@0 | 496 | // Hand off current packages to current lazy entry (if any) |
aoqi@0 | 497 | if ((cur_entry != NULL) && |
aoqi@0 | 498 | (boot_class_path_packages.length() > 0)) { |
iklam@7089 | 499 | if ((TraceClassLoading || TraceClassPaths) && Verbose) { |
aoqi@0 | 500 | print_meta_index(cur_entry, boot_class_path_packages); |
aoqi@0 | 501 | } |
aoqi@0 | 502 | MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0), |
aoqi@0 | 503 | boot_class_path_packages.length()); |
aoqi@0 | 504 | cur_entry->set_meta_index(index); |
aoqi@0 | 505 | } |
aoqi@0 | 506 | cur_entry = NULL; |
aoqi@0 | 507 | boot_class_path_packages.clear(); |
aoqi@0 | 508 | |
aoqi@0 | 509 | // Find lazy entry corresponding to this jar file |
iklam@7089 | 510 | int count = 0; |
iklam@7089 | 511 | for (ClassPathEntry* entry = _first_entry; entry != NULL; entry = entry->next(), count++) { |
iklam@7089 | 512 | if (count >= start_index && |
iklam@7089 | 513 | entry->is_lazy() && |
aoqi@0 | 514 | string_starts_with(entry->name(), meta_index_dir) && |
aoqi@0 | 515 | string_ends_with(entry->name(), &package_name[2])) { |
aoqi@0 | 516 | cur_entry = (LazyClassPathEntry*) entry; |
aoqi@0 | 517 | break; |
aoqi@0 | 518 | } |
aoqi@0 | 519 | } |
aoqi@0 | 520 | |
aoqi@0 | 521 | // If the first character is '@', it indicates the following jar |
aoqi@0 | 522 | // file is a resource only jar file in which case, we should skip |
aoqi@0 | 523 | // reading the subsequent entries since the resource loading is |
aoqi@0 | 524 | // totally handled by J2SE side. |
aoqi@0 | 525 | if (package_name[0] == '@') { |
aoqi@0 | 526 | if (cur_entry != NULL) { |
aoqi@0 | 527 | cur_entry->set_meta_index(new MetaIndex(NULL, 0)); |
aoqi@0 | 528 | } |
aoqi@0 | 529 | cur_entry = NULL; |
aoqi@0 | 530 | skipCurrentJar = true; |
aoqi@0 | 531 | } else { |
aoqi@0 | 532 | skipCurrentJar = false; |
aoqi@0 | 533 | } |
aoqi@0 | 534 | |
aoqi@0 | 535 | break; |
aoqi@0 | 536 | } |
aoqi@0 | 537 | |
aoqi@0 | 538 | default: |
aoqi@0 | 539 | { |
aoqi@0 | 540 | if (!skipCurrentJar && cur_entry != NULL) { |
aoqi@0 | 541 | char* new_name = strdup(package_name); |
aoqi@0 | 542 | boot_class_path_packages.append(new_name); |
aoqi@0 | 543 | } |
aoqi@0 | 544 | } |
aoqi@0 | 545 | } |
aoqi@0 | 546 | } |
aoqi@0 | 547 | // Hand off current packages to current lazy entry (if any) |
aoqi@0 | 548 | if ((cur_entry != NULL) && |
aoqi@0 | 549 | (boot_class_path_packages.length() > 0)) { |
iklam@7089 | 550 | if ((TraceClassLoading || TraceClassPaths) && Verbose) { |
aoqi@0 | 551 | print_meta_index(cur_entry, boot_class_path_packages); |
aoqi@0 | 552 | } |
aoqi@0 | 553 | MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0), |
aoqi@0 | 554 | boot_class_path_packages.length()); |
aoqi@0 | 555 | cur_entry->set_meta_index(index); |
aoqi@0 | 556 | } |
aoqi@0 | 557 | fclose(file); |
aoqi@0 | 558 | } |
aoqi@0 | 559 | } |
aoqi@0 | 560 | |
iklam@7089 | 561 | #if INCLUDE_CDS |
iklam@7089 | 562 | void ClassLoader::check_shared_classpath(const char *path) { |
iklam@7089 | 563 | if (strcmp(path, "") == 0) { |
iklam@7089 | 564 | exit_with_path_failure("Cannot have empty path in archived classpaths", NULL); |
iklam@7089 | 565 | } |
iklam@7089 | 566 | |
iklam@7089 | 567 | struct stat st; |
iklam@7089 | 568 | if (os::stat(path, &st) == 0) { |
iklam@7089 | 569 | if ((st.st_mode & S_IFREG) != S_IFREG) { // is directory |
iklam@7089 | 570 | if (!os::dir_is_empty(path)) { |
iklam@7089 | 571 | tty->print_cr("Error: non-empty directory '%s'", path); |
iklam@7089 | 572 | exit_with_path_failure("CDS allows only empty directories in archived classpaths", NULL); |
iklam@7089 | 573 | } |
iklam@7089 | 574 | } |
iklam@7089 | 575 | } |
iklam@7089 | 576 | } |
iklam@7089 | 577 | #endif |
iklam@7089 | 578 | |
aoqi@0 | 579 | void ClassLoader::setup_bootstrap_search_path() { |
aoqi@0 | 580 | assert(_first_entry == NULL, "should not setup bootstrap class search path twice"); |
iklam@7090 | 581 | const char* sys_class_path = Arguments::get_sysclasspath(); |
iklam@7090 | 582 | if (PrintSharedArchiveAndExit) { |
iklam@7090 | 583 | // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily |
iklam@7090 | 584 | // the same as the bootcp of the shared archive. |
iklam@7090 | 585 | } else { |
ccheung@8184 | 586 | trace_class_path(tty, "[Bootstrap loader class path=", sys_class_path); |
aoqi@0 | 587 | } |
iklam@7089 | 588 | #if INCLUDE_CDS |
iklam@7089 | 589 | if (DumpSharedSpaces) { |
iklam@7090 | 590 | _shared_paths_misc_info->add_boot_classpath(sys_class_path); |
iklam@7089 | 591 | } |
iklam@7089 | 592 | #endif |
iklam@7089 | 593 | setup_search_path(sys_class_path); |
iklam@7089 | 594 | } |
aoqi@0 | 595 | |
iklam@7089 | 596 | #if INCLUDE_CDS |
iklam@7089 | 597 | int ClassLoader::get_shared_paths_misc_info_size() { |
iklam@7089 | 598 | return _shared_paths_misc_info->get_used_bytes(); |
iklam@7089 | 599 | } |
iklam@7089 | 600 | |
iklam@7089 | 601 | void* ClassLoader::get_shared_paths_misc_info() { |
iklam@7089 | 602 | return _shared_paths_misc_info->buffer(); |
iklam@7089 | 603 | } |
iklam@7089 | 604 | |
iklam@7089 | 605 | bool ClassLoader::check_shared_paths_misc_info(void *buf, int size) { |
iklam@7089 | 606 | SharedPathsMiscInfo* checker = SharedClassUtil::allocate_shared_paths_misc_info((char*)buf, size); |
iklam@7089 | 607 | bool result = checker->check(); |
iklam@7089 | 608 | delete checker; |
iklam@7089 | 609 | return result; |
iklam@7089 | 610 | } |
iklam@7089 | 611 | #endif |
iklam@7089 | 612 | |
iklam@7322 | 613 | void ClassLoader::setup_search_path(const char *class_path, bool canonicalize) { |
iklam@7089 | 614 | int offset = 0; |
iklam@7089 | 615 | int len = (int)strlen(class_path); |
aoqi@0 | 616 | int end = 0; |
aoqi@0 | 617 | |
aoqi@0 | 618 | // Iterate over class path entries |
aoqi@0 | 619 | for (int start = 0; start < len; start = end) { |
iklam@7089 | 620 | while (class_path[end] && class_path[end] != os::path_separator()[0]) { |
aoqi@0 | 621 | end++; |
aoqi@0 | 622 | } |
iklam@7089 | 623 | EXCEPTION_MARK; |
iklam@7089 | 624 | ResourceMark rm(THREAD); |
iklam@7089 | 625 | char* path = NEW_RESOURCE_ARRAY(char, end - start + 1); |
iklam@7089 | 626 | strncpy(path, &class_path[start], end - start); |
iklam@7089 | 627 | path[end - start] = '\0'; |
iklam@7322 | 628 | if (canonicalize) { |
iklam@7322 | 629 | char* canonical_path = NEW_RESOURCE_ARRAY(char, JVM_MAXPATHLEN + 1); |
iklam@7322 | 630 | if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) { |
iklam@7322 | 631 | path = canonical_path; |
iklam@7322 | 632 | } |
iklam@7322 | 633 | } |
iklam@7322 | 634 | update_class_path_entry_list(path, /*check_for_duplicates=*/canonicalize); |
iklam@7089 | 635 | #if INCLUDE_CDS |
iklam@7089 | 636 | if (DumpSharedSpaces) { |
iklam@7089 | 637 | check_shared_classpath(path); |
iklam@7089 | 638 | } |
iklam@7089 | 639 | #endif |
iklam@7089 | 640 | while (class_path[end] == os::path_separator()[0]) { |
aoqi@0 | 641 | end++; |
aoqi@0 | 642 | } |
aoqi@0 | 643 | } |
aoqi@0 | 644 | } |
aoqi@0 | 645 | |
iklam@7090 | 646 | ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st, |
iklam@7089 | 647 | bool lazy, bool throw_exception, TRAPS) { |
aoqi@0 | 648 | JavaThread* thread = JavaThread::current(); |
aoqi@0 | 649 | if (lazy) { |
iklam@7089 | 650 | return new LazyClassPathEntry(path, st, throw_exception); |
aoqi@0 | 651 | } |
aoqi@0 | 652 | ClassPathEntry* new_entry = NULL; |
aoqi@0 | 653 | if ((st->st_mode & S_IFREG) == S_IFREG) { |
aoqi@0 | 654 | // Regular file, should be a zip file |
aoqi@0 | 655 | // Canonicalized filename |
aoqi@0 | 656 | char canonical_path[JVM_MAXPATHLEN]; |
aoqi@0 | 657 | if (!get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) { |
aoqi@0 | 658 | // This matches the classic VM |
iklam@7089 | 659 | if (throw_exception) { |
iklam@7089 | 660 | THROW_MSG_(vmSymbols::java_io_IOException(), "Bad pathname", NULL); |
iklam@7089 | 661 | } else { |
iklam@7089 | 662 | return NULL; |
iklam@7089 | 663 | } |
aoqi@0 | 664 | } |
aoqi@0 | 665 | char* error_msg = NULL; |
aoqi@0 | 666 | jzfile* zip; |
aoqi@0 | 667 | { |
aoqi@0 | 668 | // enable call to C land |
aoqi@0 | 669 | ThreadToNativeFromVM ttn(thread); |
aoqi@0 | 670 | HandleMark hm(thread); |
aoqi@0 | 671 | zip = (*ZipOpen)(canonical_path, &error_msg); |
aoqi@0 | 672 | } |
aoqi@0 | 673 | if (zip != NULL && error_msg == NULL) { |
aoqi@0 | 674 | new_entry = new ClassPathZipEntry(zip, path); |
iklam@7089 | 675 | if (TraceClassLoading || TraceClassPaths) { |
aoqi@0 | 676 | tty->print_cr("[Opened %s]", path); |
aoqi@0 | 677 | } |
aoqi@0 | 678 | } else { |
aoqi@0 | 679 | ResourceMark rm(thread); |
aoqi@0 | 680 | char *msg; |
aoqi@0 | 681 | if (error_msg == NULL) { |
aoqi@0 | 682 | msg = NEW_RESOURCE_ARRAY(char, strlen(path) + 128); ; |
aoqi@0 | 683 | jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path); |
aoqi@0 | 684 | } else { |
aoqi@0 | 685 | int len = (int)(strlen(path) + strlen(error_msg) + 128); |
aoqi@0 | 686 | msg = NEW_RESOURCE_ARRAY(char, len); ; |
aoqi@0 | 687 | jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path); |
aoqi@0 | 688 | } |
iklam@7089 | 689 | if (throw_exception) { |
iklam@7089 | 690 | THROW_MSG_(vmSymbols::java_lang_ClassNotFoundException(), msg, NULL); |
iklam@7089 | 691 | } else { |
iklam@7089 | 692 | return NULL; |
iklam@7089 | 693 | } |
aoqi@0 | 694 | } |
aoqi@0 | 695 | } else { |
aoqi@0 | 696 | // Directory |
aoqi@0 | 697 | new_entry = new ClassPathDirEntry(path); |
iklam@7089 | 698 | if (TraceClassLoading || TraceClassPaths) { |
aoqi@0 | 699 | tty->print_cr("[Path %s]", path); |
aoqi@0 | 700 | } |
aoqi@0 | 701 | } |
aoqi@0 | 702 | return new_entry; |
aoqi@0 | 703 | } |
aoqi@0 | 704 | |
aoqi@0 | 705 | |
aoqi@0 | 706 | // Create a class path zip entry for a given path (return NULL if not found |
aoqi@0 | 707 | // or zip/JAR file cannot be opened) |
aoqi@0 | 708 | ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) { |
aoqi@0 | 709 | // check for a regular file |
aoqi@0 | 710 | struct stat st; |
aoqi@0 | 711 | if (os::stat(path, &st) == 0) { |
aoqi@0 | 712 | if ((st.st_mode & S_IFREG) == S_IFREG) { |
aoqi@0 | 713 | char canonical_path[JVM_MAXPATHLEN]; |
iklam@7090 | 714 | if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) { |
aoqi@0 | 715 | char* error_msg = NULL; |
aoqi@0 | 716 | jzfile* zip; |
aoqi@0 | 717 | { |
aoqi@0 | 718 | // enable call to C land |
aoqi@0 | 719 | JavaThread* thread = JavaThread::current(); |
aoqi@0 | 720 | ThreadToNativeFromVM ttn(thread); |
aoqi@0 | 721 | HandleMark hm(thread); |
aoqi@0 | 722 | zip = (*ZipOpen)(canonical_path, &error_msg); |
aoqi@0 | 723 | } |
aoqi@0 | 724 | if (zip != NULL && error_msg == NULL) { |
aoqi@0 | 725 | // create using canonical path |
aoqi@0 | 726 | return new ClassPathZipEntry(zip, canonical_path); |
aoqi@0 | 727 | } |
aoqi@0 | 728 | } |
aoqi@0 | 729 | } |
aoqi@0 | 730 | } |
aoqi@0 | 731 | return NULL; |
aoqi@0 | 732 | } |
aoqi@0 | 733 | |
aoqi@0 | 734 | // returns true if entry already on class path |
aoqi@0 | 735 | bool ClassLoader::contains_entry(ClassPathEntry *entry) { |
aoqi@0 | 736 | ClassPathEntry* e = _first_entry; |
aoqi@0 | 737 | while (e != NULL) { |
aoqi@0 | 738 | // assume zip entries have been canonicalized |
aoqi@0 | 739 | if (strcmp(entry->name(), e->name()) == 0) { |
aoqi@0 | 740 | return true; |
aoqi@0 | 741 | } |
aoqi@0 | 742 | e = e->next(); |
aoqi@0 | 743 | } |
aoqi@0 | 744 | return false; |
aoqi@0 | 745 | } |
aoqi@0 | 746 | |
aoqi@0 | 747 | void ClassLoader::add_to_list(ClassPathEntry *new_entry) { |
aoqi@0 | 748 | if (new_entry != NULL) { |
aoqi@0 | 749 | if (_last_entry == NULL) { |
aoqi@0 | 750 | _first_entry = _last_entry = new_entry; |
aoqi@0 | 751 | } else { |
aoqi@0 | 752 | _last_entry->set_next(new_entry); |
aoqi@0 | 753 | _last_entry = new_entry; |
aoqi@0 | 754 | } |
aoqi@0 | 755 | } |
iklam@7089 | 756 | _num_entries ++; |
aoqi@0 | 757 | } |
aoqi@0 | 758 | |
iklam@7089 | 759 | // Returns true IFF the file/dir exists and the entry was successfully created. |
iklam@7090 | 760 | bool ClassLoader::update_class_path_entry_list(const char *path, |
iklam@7089 | 761 | bool check_for_duplicates, |
iklam@7089 | 762 | bool throw_exception) { |
aoqi@0 | 763 | struct stat st; |
aoqi@0 | 764 | if (os::stat(path, &st) == 0) { |
aoqi@0 | 765 | // File or directory found |
aoqi@0 | 766 | ClassPathEntry* new_entry = NULL; |
aoqi@0 | 767 | Thread* THREAD = Thread::current(); |
iklam@7089 | 768 | new_entry = create_class_path_entry(path, &st, LazyBootClassLoader, throw_exception, CHECK_(false)); |
iklam@7089 | 769 | if (new_entry == NULL) { |
iklam@7089 | 770 | return false; |
iklam@7089 | 771 | } |
aoqi@0 | 772 | // The kernel VM adds dynamically to the end of the classloader path and |
aoqi@0 | 773 | // doesn't reorder the bootclasspath which would break java.lang.Package |
aoqi@0 | 774 | // (see PackageInfo). |
aoqi@0 | 775 | // Add new entry to linked list |
aoqi@0 | 776 | if (!check_for_duplicates || !contains_entry(new_entry)) { |
iklam@7089 | 777 | ClassLoaderExt::add_class_path_entry(path, check_for_duplicates, new_entry); |
aoqi@0 | 778 | } |
iklam@7089 | 779 | return true; |
iklam@7089 | 780 | } else { |
iklam@7089 | 781 | #if INCLUDE_CDS |
iklam@7089 | 782 | if (DumpSharedSpaces) { |
iklam@7089 | 783 | _shared_paths_misc_info->add_nonexist_path(path); |
iklam@7089 | 784 | } |
iklam@7090 | 785 | #endif |
iklam@7089 | 786 | return false; |
aoqi@0 | 787 | } |
aoqi@0 | 788 | } |
aoqi@0 | 789 | |
aoqi@0 | 790 | void ClassLoader::print_bootclasspath() { |
aoqi@0 | 791 | ClassPathEntry* e = _first_entry; |
aoqi@0 | 792 | tty->print("[bootclasspath= "); |
aoqi@0 | 793 | while (e != NULL) { |
aoqi@0 | 794 | tty->print("%s ;", e->name()); |
aoqi@0 | 795 | e = e->next(); |
aoqi@0 | 796 | } |
aoqi@0 | 797 | tty->print_cr("]"); |
aoqi@0 | 798 | } |
aoqi@0 | 799 | |
aoqi@0 | 800 | void ClassLoader::load_zip_library() { |
aoqi@0 | 801 | assert(ZipOpen == NULL, "should not load zip library twice"); |
aoqi@0 | 802 | // First make sure native library is loaded |
aoqi@0 | 803 | os::native_java_library(); |
aoqi@0 | 804 | // Load zip library |
aoqi@0 | 805 | char path[JVM_MAXPATHLEN]; |
aoqi@0 | 806 | char ebuf[1024]; |
aoqi@0 | 807 | void* handle = NULL; |
aoqi@0 | 808 | if (os::dll_build_name(path, sizeof(path), Arguments::get_dll_dir(), "zip")) { |
aoqi@0 | 809 | handle = os::dll_load(path, ebuf, sizeof ebuf); |
aoqi@0 | 810 | } |
aoqi@0 | 811 | if (handle == NULL) { |
aoqi@0 | 812 | vm_exit_during_initialization("Unable to load ZIP library", path); |
aoqi@0 | 813 | } |
aoqi@0 | 814 | // Lookup zip entry points |
aoqi@0 | 815 | ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, os::dll_lookup(handle, "ZIP_Open")); |
aoqi@0 | 816 | ZipClose = CAST_TO_FN_PTR(ZipClose_t, os::dll_lookup(handle, "ZIP_Close")); |
aoqi@0 | 817 | FindEntry = CAST_TO_FN_PTR(FindEntry_t, os::dll_lookup(handle, "ZIP_FindEntry")); |
aoqi@0 | 818 | ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, os::dll_lookup(handle, "ZIP_ReadEntry")); |
aoqi@0 | 819 | ReadMappedEntry = CAST_TO_FN_PTR(ReadMappedEntry_t, os::dll_lookup(handle, "ZIP_ReadMappedEntry")); |
aoqi@0 | 820 | GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, os::dll_lookup(handle, "ZIP_GetNextEntry")); |
aoqi@0 | 821 | Crc32 = CAST_TO_FN_PTR(Crc32_t, os::dll_lookup(handle, "ZIP_CRC32")); |
aoqi@0 | 822 | |
aoqi@0 | 823 | // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL |
aoqi@0 | 824 | if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL || |
aoqi@0 | 825 | GetNextEntry == NULL || Crc32 == NULL) { |
aoqi@0 | 826 | vm_exit_during_initialization("Corrupted ZIP library", path); |
aoqi@0 | 827 | } |
aoqi@0 | 828 | |
aoqi@0 | 829 | // Lookup canonicalize entry in libjava.dll |
aoqi@0 | 830 | void *javalib_handle = os::native_java_library(); |
aoqi@0 | 831 | CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, os::dll_lookup(javalib_handle, "Canonicalize")); |
aoqi@0 | 832 | // This lookup only works on 1.3. Do not check for non-null here |
aoqi@0 | 833 | } |
aoqi@0 | 834 | |
aoqi@0 | 835 | int ClassLoader::crc32(int crc, const char* buf, int len) { |
aoqi@0 | 836 | assert(Crc32 != NULL, "ZIP_CRC32 is not found"); |
aoqi@0 | 837 | return (*Crc32)(crc, (const jbyte*)buf, len); |
aoqi@0 | 838 | } |
aoqi@0 | 839 | |
aoqi@0 | 840 | // PackageInfo data exists in order to support the java.lang.Package |
aoqi@0 | 841 | // class. A Package object provides information about a java package |
aoqi@0 | 842 | // (version, vendor, etc.) which originates in the manifest of the jar |
aoqi@0 | 843 | // file supplying the package. For application classes, the ClassLoader |
aoqi@0 | 844 | // object takes care of this. |
aoqi@0 | 845 | |
aoqi@0 | 846 | // For system (boot) classes, the Java code in the Package class needs |
aoqi@0 | 847 | // to be able to identify which source jar file contained the boot |
aoqi@0 | 848 | // class, so that it can extract the manifest from it. This table |
aoqi@0 | 849 | // identifies java packages with jar files in the boot classpath. |
aoqi@0 | 850 | |
aoqi@0 | 851 | // Because the boot classpath cannot change, the classpath index is |
aoqi@0 | 852 | // sufficient to identify the source jar file or directory. (Since |
aoqi@0 | 853 | // directories have no manifests, the directory name is not required, |
aoqi@0 | 854 | // but is available.) |
aoqi@0 | 855 | |
aoqi@0 | 856 | // When using sharing -- the pathnames of entries in the boot classpath |
aoqi@0 | 857 | // may not be the same at runtime as they were when the archive was |
aoqi@0 | 858 | // created (NFS, Samba, etc.). The actual files and directories named |
aoqi@0 | 859 | // in the classpath must be the same files, in the same order, even |
aoqi@0 | 860 | // though the exact name is not the same. |
aoqi@0 | 861 | |
aoqi@0 | 862 | class PackageInfo: public BasicHashtableEntry<mtClass> { |
aoqi@0 | 863 | public: |
aoqi@0 | 864 | const char* _pkgname; // Package name |
aoqi@0 | 865 | int _classpath_index; // Index of directory or JAR file loaded from |
aoqi@0 | 866 | |
aoqi@0 | 867 | PackageInfo* next() { |
aoqi@0 | 868 | return (PackageInfo*)BasicHashtableEntry<mtClass>::next(); |
aoqi@0 | 869 | } |
aoqi@0 | 870 | |
aoqi@0 | 871 | const char* pkgname() { return _pkgname; } |
aoqi@0 | 872 | void set_pkgname(char* pkgname) { _pkgname = pkgname; } |
aoqi@0 | 873 | |
aoqi@0 | 874 | const char* filename() { |
aoqi@0 | 875 | return ClassLoader::classpath_entry(_classpath_index)->name(); |
aoqi@0 | 876 | } |
aoqi@0 | 877 | |
aoqi@0 | 878 | void set_index(int index) { |
aoqi@0 | 879 | _classpath_index = index; |
aoqi@0 | 880 | } |
aoqi@0 | 881 | }; |
aoqi@0 | 882 | |
aoqi@0 | 883 | |
aoqi@0 | 884 | class PackageHashtable : public BasicHashtable<mtClass> { |
aoqi@0 | 885 | private: |
aoqi@0 | 886 | inline unsigned int compute_hash(const char *s, int n) { |
aoqi@0 | 887 | unsigned int val = 0; |
aoqi@0 | 888 | while (--n >= 0) { |
aoqi@0 | 889 | val = *s++ + 31 * val; |
aoqi@0 | 890 | } |
aoqi@0 | 891 | return val; |
aoqi@0 | 892 | } |
aoqi@0 | 893 | |
aoqi@0 | 894 | PackageInfo* bucket(int index) { |
aoqi@0 | 895 | return (PackageInfo*)BasicHashtable<mtClass>::bucket(index); |
aoqi@0 | 896 | } |
aoqi@0 | 897 | |
aoqi@0 | 898 | PackageInfo* get_entry(int index, unsigned int hash, |
aoqi@0 | 899 | const char* pkgname, size_t n) { |
aoqi@0 | 900 | for (PackageInfo* pp = bucket(index); pp != NULL; pp = pp->next()) { |
aoqi@0 | 901 | if (pp->hash() == hash && |
aoqi@0 | 902 | strncmp(pkgname, pp->pkgname(), n) == 0 && |
aoqi@0 | 903 | pp->pkgname()[n] == '\0') { |
aoqi@0 | 904 | return pp; |
aoqi@0 | 905 | } |
aoqi@0 | 906 | } |
aoqi@0 | 907 | return NULL; |
aoqi@0 | 908 | } |
aoqi@0 | 909 | |
aoqi@0 | 910 | public: |
aoqi@0 | 911 | PackageHashtable(int table_size) |
aoqi@0 | 912 | : BasicHashtable<mtClass>(table_size, sizeof(PackageInfo)) {} |
aoqi@0 | 913 | |
aoqi@0 | 914 | PackageHashtable(int table_size, HashtableBucket<mtClass>* t, int number_of_entries) |
aoqi@0 | 915 | : BasicHashtable<mtClass>(table_size, sizeof(PackageInfo), t, number_of_entries) {} |
aoqi@0 | 916 | |
aoqi@0 | 917 | PackageInfo* get_entry(const char* pkgname, int n) { |
aoqi@0 | 918 | unsigned int hash = compute_hash(pkgname, n); |
aoqi@0 | 919 | return get_entry(hash_to_index(hash), hash, pkgname, n); |
aoqi@0 | 920 | } |
aoqi@0 | 921 | |
aoqi@0 | 922 | PackageInfo* new_entry(char* pkgname, int n) { |
aoqi@0 | 923 | unsigned int hash = compute_hash(pkgname, n); |
aoqi@0 | 924 | PackageInfo* pp; |
aoqi@0 | 925 | pp = (PackageInfo*)BasicHashtable<mtClass>::new_entry(hash); |
aoqi@0 | 926 | pp->set_pkgname(pkgname); |
aoqi@0 | 927 | return pp; |
aoqi@0 | 928 | } |
aoqi@0 | 929 | |
aoqi@0 | 930 | void add_entry(PackageInfo* pp) { |
aoqi@0 | 931 | int index = hash_to_index(pp->hash()); |
aoqi@0 | 932 | BasicHashtable<mtClass>::add_entry(index, pp); |
aoqi@0 | 933 | } |
aoqi@0 | 934 | |
aoqi@0 | 935 | void copy_pkgnames(const char** packages) { |
aoqi@0 | 936 | int n = 0; |
aoqi@0 | 937 | for (int i = 0; i < table_size(); ++i) { |
aoqi@0 | 938 | for (PackageInfo* pp = bucket(i); pp != NULL; pp = pp->next()) { |
aoqi@0 | 939 | packages[n++] = pp->pkgname(); |
aoqi@0 | 940 | } |
aoqi@0 | 941 | } |
aoqi@0 | 942 | assert(n == number_of_entries(), "just checking"); |
aoqi@0 | 943 | } |
aoqi@0 | 944 | |
iklam@7089 | 945 | CDS_ONLY(void copy_table(char** top, char* end, PackageHashtable* table);) |
aoqi@0 | 946 | }; |
aoqi@0 | 947 | |
iklam@7089 | 948 | #if INCLUDE_CDS |
aoqi@0 | 949 | void PackageHashtable::copy_table(char** top, char* end, |
aoqi@0 | 950 | PackageHashtable* table) { |
aoqi@0 | 951 | // Copy (relocate) the table to the shared space. |
aoqi@0 | 952 | BasicHashtable<mtClass>::copy_table(top, end); |
aoqi@0 | 953 | |
aoqi@0 | 954 | // Calculate the space needed for the package name strings. |
aoqi@0 | 955 | int i; |
iklam@7089 | 956 | intptr_t* tableSize = (intptr_t*)(*top); |
iklam@7089 | 957 | *top += sizeof(intptr_t); // For table size |
iklam@7089 | 958 | char* tableStart = *top; |
aoqi@0 | 959 | |
aoqi@0 | 960 | for (i = 0; i < table_size(); ++i) { |
aoqi@0 | 961 | for (PackageInfo* pp = table->bucket(i); |
aoqi@0 | 962 | pp != NULL; |
aoqi@0 | 963 | pp = pp->next()) { |
aoqi@0 | 964 | int n1 = (int)(strlen(pp->pkgname()) + 1); |
iklam@7089 | 965 | if (*top + n1 >= end) { |
iklam@7089 | 966 | report_out_of_shared_space(SharedMiscData); |
iklam@7089 | 967 | } |
aoqi@0 | 968 | pp->set_pkgname((char*)memcpy(*top, pp->pkgname(), n1)); |
aoqi@0 | 969 | *top += n1; |
aoqi@0 | 970 | } |
aoqi@0 | 971 | } |
aoqi@0 | 972 | *top = (char*)align_size_up((intptr_t)*top, sizeof(HeapWord)); |
iklam@7089 | 973 | if (*top >= end) { |
iklam@7089 | 974 | report_out_of_shared_space(SharedMiscData); |
iklam@7089 | 975 | } |
iklam@7089 | 976 | |
iklam@7089 | 977 | // Write table size |
iklam@7089 | 978 | intptr_t len = *top - (char*)tableStart; |
iklam@7089 | 979 | *tableSize = len; |
aoqi@0 | 980 | } |
aoqi@0 | 981 | |
aoqi@0 | 982 | |
aoqi@0 | 983 | void ClassLoader::copy_package_info_buckets(char** top, char* end) { |
aoqi@0 | 984 | _package_hash_table->copy_buckets(top, end); |
aoqi@0 | 985 | } |
aoqi@0 | 986 | |
aoqi@0 | 987 | void ClassLoader::copy_package_info_table(char** top, char* end) { |
aoqi@0 | 988 | _package_hash_table->copy_table(top, end, _package_hash_table); |
aoqi@0 | 989 | } |
iklam@7089 | 990 | #endif |
aoqi@0 | 991 | |
aoqi@0 | 992 | PackageInfo* ClassLoader::lookup_package(const char *pkgname) { |
aoqi@0 | 993 | const char *cp = strrchr(pkgname, '/'); |
aoqi@0 | 994 | if (cp != NULL) { |
aoqi@0 | 995 | // Package prefix found |
aoqi@0 | 996 | int n = cp - pkgname + 1; |
aoqi@0 | 997 | return _package_hash_table->get_entry(pkgname, n); |
aoqi@0 | 998 | } |
aoqi@0 | 999 | return NULL; |
aoqi@0 | 1000 | } |
aoqi@0 | 1001 | |
aoqi@0 | 1002 | |
aoqi@0 | 1003 | bool ClassLoader::add_package(const char *pkgname, int classpath_index, TRAPS) { |
aoqi@0 | 1004 | assert(pkgname != NULL, "just checking"); |
aoqi@0 | 1005 | // Bootstrap loader no longer holds system loader lock obj serializing |
aoqi@0 | 1006 | // load_instance_class and thereby add_package |
aoqi@0 | 1007 | { |
aoqi@0 | 1008 | MutexLocker ml(PackageTable_lock, THREAD); |
aoqi@0 | 1009 | // First check for previously loaded entry |
aoqi@0 | 1010 | PackageInfo* pp = lookup_package(pkgname); |
aoqi@0 | 1011 | if (pp != NULL) { |
aoqi@0 | 1012 | // Existing entry found, check source of package |
aoqi@0 | 1013 | pp->set_index(classpath_index); |
aoqi@0 | 1014 | return true; |
aoqi@0 | 1015 | } |
aoqi@0 | 1016 | |
aoqi@0 | 1017 | const char *cp = strrchr(pkgname, '/'); |
aoqi@0 | 1018 | if (cp != NULL) { |
aoqi@0 | 1019 | // Package prefix found |
aoqi@0 | 1020 | int n = cp - pkgname + 1; |
aoqi@0 | 1021 | |
aoqi@0 | 1022 | char* new_pkgname = NEW_C_HEAP_ARRAY(char, n + 1, mtClass); |
aoqi@0 | 1023 | if (new_pkgname == NULL) { |
aoqi@0 | 1024 | return false; |
aoqi@0 | 1025 | } |
aoqi@0 | 1026 | |
aoqi@0 | 1027 | memcpy(new_pkgname, pkgname, n); |
aoqi@0 | 1028 | new_pkgname[n] = '\0'; |
aoqi@0 | 1029 | pp = _package_hash_table->new_entry(new_pkgname, n); |
aoqi@0 | 1030 | pp->set_index(classpath_index); |
aoqi@0 | 1031 | |
aoqi@0 | 1032 | // Insert into hash table |
aoqi@0 | 1033 | _package_hash_table->add_entry(pp); |
aoqi@0 | 1034 | } |
aoqi@0 | 1035 | return true; |
aoqi@0 | 1036 | } |
aoqi@0 | 1037 | } |
aoqi@0 | 1038 | |
aoqi@0 | 1039 | |
aoqi@0 | 1040 | oop ClassLoader::get_system_package(const char* name, TRAPS) { |
aoqi@0 | 1041 | PackageInfo* pp; |
aoqi@0 | 1042 | { |
aoqi@0 | 1043 | MutexLocker ml(PackageTable_lock, THREAD); |
aoqi@0 | 1044 | pp = lookup_package(name); |
aoqi@0 | 1045 | } |
aoqi@0 | 1046 | if (pp == NULL) { |
aoqi@0 | 1047 | return NULL; |
aoqi@0 | 1048 | } else { |
aoqi@0 | 1049 | Handle p = java_lang_String::create_from_str(pp->filename(), THREAD); |
aoqi@0 | 1050 | return p(); |
aoqi@0 | 1051 | } |
aoqi@0 | 1052 | } |
aoqi@0 | 1053 | |
aoqi@0 | 1054 | |
aoqi@0 | 1055 | objArrayOop ClassLoader::get_system_packages(TRAPS) { |
aoqi@0 | 1056 | ResourceMark rm(THREAD); |
aoqi@0 | 1057 | int nof_entries; |
aoqi@0 | 1058 | const char** packages; |
aoqi@0 | 1059 | { |
aoqi@0 | 1060 | MutexLocker ml(PackageTable_lock, THREAD); |
aoqi@0 | 1061 | // Allocate resource char* array containing package names |
aoqi@0 | 1062 | nof_entries = _package_hash_table->number_of_entries(); |
aoqi@0 | 1063 | if ((packages = NEW_RESOURCE_ARRAY(const char*, nof_entries)) == NULL) { |
aoqi@0 | 1064 | return NULL; |
aoqi@0 | 1065 | } |
aoqi@0 | 1066 | _package_hash_table->copy_pkgnames(packages); |
aoqi@0 | 1067 | } |
aoqi@0 | 1068 | // Allocate objArray and fill with java.lang.String |
aoqi@0 | 1069 | objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), |
aoqi@0 | 1070 | nof_entries, CHECK_0); |
aoqi@0 | 1071 | objArrayHandle result(THREAD, r); |
aoqi@0 | 1072 | for (int i = 0; i < nof_entries; i++) { |
aoqi@0 | 1073 | Handle str = java_lang_String::create_from_str(packages[i], CHECK_0); |
aoqi@0 | 1074 | result->obj_at_put(i, str()); |
aoqi@0 | 1075 | } |
aoqi@0 | 1076 | |
aoqi@0 | 1077 | return result(); |
aoqi@0 | 1078 | } |
aoqi@0 | 1079 | |
aoqi@0 | 1080 | |
aoqi@0 | 1081 | instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) { |
aoqi@0 | 1082 | ResourceMark rm(THREAD); |
iklam@7089 | 1083 | const char* class_name = h_name->as_C_string(); |
iklam@7089 | 1084 | EventMark m("loading class %s", class_name); |
aoqi@0 | 1085 | ThreadProfilerMark tpm(ThreadProfilerMark::classLoaderRegion); |
aoqi@0 | 1086 | |
aoqi@0 | 1087 | stringStream st; |
aoqi@0 | 1088 | // st.print() uses too much stack space while handling a StackOverflowError |
aoqi@0 | 1089 | // st.print("%s.class", h_name->as_utf8()); |
aoqi@0 | 1090 | st.print_raw(h_name->as_utf8()); |
aoqi@0 | 1091 | st.print_raw(".class"); |
iklam@7089 | 1092 | const char* file_name = st.as_string(); |
iklam@7089 | 1093 | ClassLoaderExt::Context context(class_name, file_name, THREAD); |
aoqi@0 | 1094 | |
aoqi@0 | 1095 | // Lookup stream for parsing .class file |
aoqi@0 | 1096 | ClassFileStream* stream = NULL; |
aoqi@0 | 1097 | int classpath_index = 0; |
iklam@7089 | 1098 | ClassPathEntry* e = NULL; |
iklam@7089 | 1099 | instanceKlassHandle h; |
aoqi@0 | 1100 | { |
aoqi@0 | 1101 | PerfClassTraceTime vmtimer(perf_sys_class_lookup_time(), |
aoqi@0 | 1102 | ((JavaThread*) THREAD)->get_thread_stat()->perf_timers_addr(), |
aoqi@0 | 1103 | PerfClassTraceTime::CLASS_LOAD); |
iklam@7089 | 1104 | e = _first_entry; |
aoqi@0 | 1105 | while (e != NULL) { |
iklam@7089 | 1106 | stream = e->open_stream(file_name, CHECK_NULL); |
iklam@7089 | 1107 | if (!context.check(stream, classpath_index)) { |
iklam@7089 | 1108 | return h; // NULL |
iklam@7089 | 1109 | } |
aoqi@0 | 1110 | if (stream != NULL) { |
aoqi@0 | 1111 | break; |
aoqi@0 | 1112 | } |
aoqi@0 | 1113 | e = e->next(); |
aoqi@0 | 1114 | ++classpath_index; |
aoqi@0 | 1115 | } |
aoqi@0 | 1116 | } |
aoqi@0 | 1117 | |
aoqi@0 | 1118 | if (stream != NULL) { |
aoqi@0 | 1119 | // class file found, parse it |
aoqi@0 | 1120 | ClassFileParser parser(stream); |
aoqi@0 | 1121 | ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); |
aoqi@0 | 1122 | Handle protection_domain; |
aoqi@0 | 1123 | TempNewSymbol parsed_name = NULL; |
aoqi@0 | 1124 | instanceKlassHandle result = parser.parseClassFile(h_name, |
aoqi@0 | 1125 | loader_data, |
aoqi@0 | 1126 | protection_domain, |
aoqi@0 | 1127 | parsed_name, |
iklam@7089 | 1128 | context.should_verify(classpath_index), |
iklam@7089 | 1129 | THREAD); |
iklam@7089 | 1130 | if (HAS_PENDING_EXCEPTION) { |
iklam@7089 | 1131 | ResourceMark rm; |
iklam@7089 | 1132 | if (DumpSharedSpaces) { |
iklam@7089 | 1133 | tty->print_cr("Preload Error: Failed to load %s", class_name); |
iklam@7089 | 1134 | } |
iklam@7089 | 1135 | return h; |
iklam@7089 | 1136 | } |
iklam@7089 | 1137 | h = context.record_result(classpath_index, e, result, THREAD); |
iklam@7089 | 1138 | } else { |
iklam@7089 | 1139 | if (DumpSharedSpaces) { |
jiangli@7363 | 1140 | tty->print_cr("Preload Warning: Cannot find %s", class_name); |
aoqi@0 | 1141 | } |
aoqi@0 | 1142 | } |
aoqi@0 | 1143 | |
aoqi@0 | 1144 | return h; |
aoqi@0 | 1145 | } |
aoqi@0 | 1146 | |
aoqi@0 | 1147 | |
aoqi@0 | 1148 | void ClassLoader::create_package_info_table(HashtableBucket<mtClass> *t, int length, |
aoqi@0 | 1149 | int number_of_entries) { |
aoqi@0 | 1150 | assert(_package_hash_table == NULL, "One package info table allowed."); |
aoqi@0 | 1151 | assert(length == package_hash_table_size * sizeof(HashtableBucket<mtClass>), |
aoqi@0 | 1152 | "bad shared package info size."); |
aoqi@0 | 1153 | _package_hash_table = new PackageHashtable(package_hash_table_size, t, |
aoqi@0 | 1154 | number_of_entries); |
aoqi@0 | 1155 | } |
aoqi@0 | 1156 | |
aoqi@0 | 1157 | |
aoqi@0 | 1158 | void ClassLoader::create_package_info_table() { |
aoqi@0 | 1159 | assert(_package_hash_table == NULL, "shouldn't have one yet"); |
aoqi@0 | 1160 | _package_hash_table = new PackageHashtable(package_hash_table_size); |
aoqi@0 | 1161 | } |
aoqi@0 | 1162 | |
aoqi@0 | 1163 | |
aoqi@0 | 1164 | // Initialize the class loader's access to methods in libzip. Parse and |
aoqi@0 | 1165 | // process the boot classpath into a list ClassPathEntry objects. Once |
aoqi@0 | 1166 | // this list has been created, it must not change order (see class PackageInfo) |
aoqi@0 | 1167 | // it can be appended to and is by jvmti and the kernel vm. |
aoqi@0 | 1168 | |
aoqi@0 | 1169 | void ClassLoader::initialize() { |
aoqi@0 | 1170 | assert(_package_hash_table == NULL, "should have been initialized by now."); |
aoqi@0 | 1171 | EXCEPTION_MARK; |
aoqi@0 | 1172 | |
aoqi@0 | 1173 | if (UsePerfData) { |
aoqi@0 | 1174 | // jvmstat performance counters |
aoqi@0 | 1175 | NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time"); |
aoqi@0 | 1176 | NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime"); |
aoqi@0 | 1177 | NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self"); |
aoqi@0 | 1178 | NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime"); |
aoqi@0 | 1179 | NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self"); |
aoqi@0 | 1180 | NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime"); |
aoqi@0 | 1181 | NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self"); |
aoqi@0 | 1182 | NEWPERFEVENTCOUNTER(_perf_classes_inited, SUN_CLS, "initializedClasses"); |
aoqi@0 | 1183 | NEWPERFEVENTCOUNTER(_perf_classes_linked, SUN_CLS, "linkedClasses"); |
aoqi@0 | 1184 | NEWPERFEVENTCOUNTER(_perf_classes_verified, SUN_CLS, "verifiedClasses"); |
aoqi@0 | 1185 | |
aoqi@0 | 1186 | NEWPERFTICKCOUNTER(_perf_class_parse_time, SUN_CLS, "parseClassTime"); |
aoqi@0 | 1187 | NEWPERFTICKCOUNTER(_perf_class_parse_selftime, SUN_CLS, "parseClassTime.self"); |
aoqi@0 | 1188 | NEWPERFTICKCOUNTER(_perf_sys_class_lookup_time, SUN_CLS, "lookupSysClassTime"); |
aoqi@0 | 1189 | NEWPERFTICKCOUNTER(_perf_shared_classload_time, SUN_CLS, "sharedClassLoadTime"); |
aoqi@0 | 1190 | NEWPERFTICKCOUNTER(_perf_sys_classload_time, SUN_CLS, "sysClassLoadTime"); |
aoqi@0 | 1191 | NEWPERFTICKCOUNTER(_perf_app_classload_time, SUN_CLS, "appClassLoadTime"); |
aoqi@0 | 1192 | NEWPERFTICKCOUNTER(_perf_app_classload_selftime, SUN_CLS, "appClassLoadTime.self"); |
aoqi@0 | 1193 | NEWPERFEVENTCOUNTER(_perf_app_classload_count, SUN_CLS, "appClassLoadCount"); |
aoqi@0 | 1194 | NEWPERFTICKCOUNTER(_perf_define_appclasses, SUN_CLS, "defineAppClasses"); |
aoqi@0 | 1195 | NEWPERFTICKCOUNTER(_perf_define_appclass_time, SUN_CLS, "defineAppClassTime"); |
aoqi@0 | 1196 | NEWPERFTICKCOUNTER(_perf_define_appclass_selftime, SUN_CLS, "defineAppClassTime.self"); |
aoqi@0 | 1197 | NEWPERFBYTECOUNTER(_perf_app_classfile_bytes_read, SUN_CLS, "appClassBytes"); |
aoqi@0 | 1198 | NEWPERFBYTECOUNTER(_perf_sys_classfile_bytes_read, SUN_CLS, "sysClassBytes"); |
aoqi@0 | 1199 | |
aoqi@0 | 1200 | |
aoqi@0 | 1201 | // The following performance counters are added for measuring the impact |
aoqi@0 | 1202 | // of the bug fix of 6365597. They are mainly focused on finding out |
aoqi@0 | 1203 | // the behavior of system & user-defined classloader lock, whether |
aoqi@0 | 1204 | // ClassLoader.loadClass/findClass is being called synchronized or not. |
aoqi@0 | 1205 | // Also two additional counters are created to see whether 'UnsyncloadClass' |
aoqi@0 | 1206 | // flag is being set or not and how many times load_instance_class call |
aoqi@0 | 1207 | // fails with linkageError etc. |
aoqi@0 | 1208 | NEWPERFEVENTCOUNTER(_sync_systemLoaderLockContentionRate, SUN_CLS, |
aoqi@0 | 1209 | "systemLoaderLockContentionRate"); |
aoqi@0 | 1210 | NEWPERFEVENTCOUNTER(_sync_nonSystemLoaderLockContentionRate, SUN_CLS, |
aoqi@0 | 1211 | "nonSystemLoaderLockContentionRate"); |
aoqi@0 | 1212 | NEWPERFEVENTCOUNTER(_sync_JVMFindLoadedClassLockFreeCounter, SUN_CLS, |
aoqi@0 | 1213 | "jvmFindLoadedClassNoLockCalls"); |
aoqi@0 | 1214 | NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS, |
aoqi@0 | 1215 | "jvmDefineClassNoLockCalls"); |
aoqi@0 | 1216 | |
aoqi@0 | 1217 | NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS, |
aoqi@0 | 1218 | "jniDefineClassNoLockCalls"); |
aoqi@0 | 1219 | |
aoqi@0 | 1220 | NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS, |
aoqi@0 | 1221 | "unsafeDefineClassCalls"); |
aoqi@0 | 1222 | |
aoqi@0 | 1223 | NEWPERFEVENTCOUNTER(_isUnsyncloadClass, SUN_CLS, "isUnsyncloadClassSet"); |
aoqi@0 | 1224 | NEWPERFEVENTCOUNTER(_load_instance_class_failCounter, SUN_CLS, |
aoqi@0 | 1225 | "loadInstanceClassFailRate"); |
aoqi@0 | 1226 | |
aoqi@0 | 1227 | // increment the isUnsyncloadClass counter if UnsyncloadClass is set. |
aoqi@0 | 1228 | if (UnsyncloadClass) { |
aoqi@0 | 1229 | _isUnsyncloadClass->inc(); |
aoqi@0 | 1230 | } |
aoqi@0 | 1231 | } |
aoqi@0 | 1232 | |
aoqi@0 | 1233 | // lookup zip library entry points |
aoqi@0 | 1234 | load_zip_library(); |
iklam@7089 | 1235 | #if INCLUDE_CDS |
aoqi@0 | 1236 | // initialize search path |
iklam@7089 | 1237 | if (DumpSharedSpaces) { |
iklam@7089 | 1238 | _shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info(); |
iklam@7089 | 1239 | } |
iklam@7089 | 1240 | #endif |
aoqi@0 | 1241 | setup_bootstrap_search_path(); |
aoqi@0 | 1242 | if (LazyBootClassLoader) { |
aoqi@0 | 1243 | // set up meta index which makes boot classpath initialization lazier |
iklam@7089 | 1244 | setup_bootstrap_meta_index(); |
aoqi@0 | 1245 | } |
aoqi@0 | 1246 | } |
aoqi@0 | 1247 | |
iklam@7089 | 1248 | #if INCLUDE_CDS |
iklam@7089 | 1249 | void ClassLoader::initialize_shared_path() { |
iklam@7089 | 1250 | if (DumpSharedSpaces) { |
iklam@7089 | 1251 | ClassLoaderExt::setup_search_paths(); |
iklam@7089 | 1252 | _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check() |
iklam@7089 | 1253 | } |
iklam@7089 | 1254 | } |
iklam@7089 | 1255 | #endif |
aoqi@0 | 1256 | |
aoqi@0 | 1257 | jlong ClassLoader::classloader_time_ms() { |
aoqi@0 | 1258 | return UsePerfData ? |
aoqi@0 | 1259 | Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1; |
aoqi@0 | 1260 | } |
aoqi@0 | 1261 | |
aoqi@0 | 1262 | jlong ClassLoader::class_init_count() { |
aoqi@0 | 1263 | return UsePerfData ? _perf_classes_inited->get_value() : -1; |
aoqi@0 | 1264 | } |
aoqi@0 | 1265 | |
aoqi@0 | 1266 | jlong ClassLoader::class_init_time_ms() { |
aoqi@0 | 1267 | return UsePerfData ? |
aoqi@0 | 1268 | Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1; |
aoqi@0 | 1269 | } |
aoqi@0 | 1270 | |
aoqi@0 | 1271 | jlong ClassLoader::class_verify_time_ms() { |
aoqi@0 | 1272 | return UsePerfData ? |
aoqi@0 | 1273 | Management::ticks_to_ms(_perf_class_verify_time->get_value()) : -1; |
aoqi@0 | 1274 | } |
aoqi@0 | 1275 | |
aoqi@0 | 1276 | jlong ClassLoader::class_link_count() { |
aoqi@0 | 1277 | return UsePerfData ? _perf_classes_linked->get_value() : -1; |
aoqi@0 | 1278 | } |
aoqi@0 | 1279 | |
aoqi@0 | 1280 | jlong ClassLoader::class_link_time_ms() { |
aoqi@0 | 1281 | return UsePerfData ? |
aoqi@0 | 1282 | Management::ticks_to_ms(_perf_class_link_time->get_value()) : -1; |
aoqi@0 | 1283 | } |
aoqi@0 | 1284 | |
aoqi@0 | 1285 | int ClassLoader::compute_Object_vtable() { |
aoqi@0 | 1286 | // hardwired for JDK1.2 -- would need to duplicate class file parsing |
aoqi@0 | 1287 | // code to determine actual value from file |
aoqi@0 | 1288 | // Would be value '11' if finals were in vtable |
aoqi@0 | 1289 | int JDK_1_2_Object_vtable_size = 5; |
aoqi@0 | 1290 | return JDK_1_2_Object_vtable_size * vtableEntry::size(); |
aoqi@0 | 1291 | } |
aoqi@0 | 1292 | |
aoqi@0 | 1293 | |
aoqi@0 | 1294 | void classLoader_init() { |
aoqi@0 | 1295 | ClassLoader::initialize(); |
aoqi@0 | 1296 | } |
aoqi@0 | 1297 | |
aoqi@0 | 1298 | |
iklam@7090 | 1299 | bool ClassLoader::get_canonical_path(const char* orig, char* out, int len) { |
aoqi@0 | 1300 | assert(orig != NULL && out != NULL && len > 0, "bad arguments"); |
aoqi@0 | 1301 | if (CanonicalizeEntry != NULL) { |
iklam@7090 | 1302 | JavaThread* THREAD = JavaThread::current(); |
iklam@7090 | 1303 | JNIEnv* env = THREAD->jni_environment(); |
iklam@7090 | 1304 | ResourceMark rm(THREAD); |
iklam@7090 | 1305 | |
iklam@7090 | 1306 | // os::native_path writes into orig_copy |
iklam@7090 | 1307 | char* orig_copy = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(orig)+1); |
iklam@7090 | 1308 | strcpy(orig_copy, orig); |
iklam@7090 | 1309 | if ((CanonicalizeEntry)(env, os::native_path(orig_copy), out, len) < 0) { |
aoqi@0 | 1310 | return false; |
aoqi@0 | 1311 | } |
aoqi@0 | 1312 | } else { |
aoqi@0 | 1313 | // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing |
aoqi@0 | 1314 | strncpy(out, orig, len); |
aoqi@0 | 1315 | out[len - 1] = '\0'; |
aoqi@0 | 1316 | } |
aoqi@0 | 1317 | return true; |
aoqi@0 | 1318 | } |
aoqi@0 | 1319 | |
aoqi@0 | 1320 | #ifndef PRODUCT |
aoqi@0 | 1321 | |
aoqi@0 | 1322 | void ClassLoader::verify() { |
aoqi@0 | 1323 | _package_hash_table->verify(); |
aoqi@0 | 1324 | } |
aoqi@0 | 1325 | |
aoqi@0 | 1326 | |
aoqi@0 | 1327 | // CompileTheWorld |
aoqi@0 | 1328 | // |
aoqi@0 | 1329 | // Iterates over all class path entries and forces compilation of all methods |
aoqi@0 | 1330 | // in all classes found. Currently, only zip/jar archives are searched. |
aoqi@0 | 1331 | // |
aoqi@0 | 1332 | // The classes are loaded by the Java level bootstrap class loader, and the |
aoqi@0 | 1333 | // initializer is called. If DelayCompilationDuringStartup is true (default), |
aoqi@0 | 1334 | // the interpreter will run the initialization code. Note that forcing |
aoqi@0 | 1335 | // initialization in this way could potentially lead to initialization order |
aoqi@0 | 1336 | // problems, in which case we could just force the initialization bit to be set. |
aoqi@0 | 1337 | |
aoqi@0 | 1338 | |
aoqi@0 | 1339 | // We need to iterate over the contents of a zip/jar file, so we replicate the |
aoqi@0 | 1340 | // jzcell and jzfile definitions from zip_util.h but rename jzfile to real_jzfile, |
aoqi@0 | 1341 | // since jzfile already has a void* definition. |
aoqi@0 | 1342 | // |
aoqi@0 | 1343 | // Note that this is only used in debug mode. |
aoqi@0 | 1344 | // |
aoqi@0 | 1345 | // HotSpot integration note: |
aoqi@0 | 1346 | // Matches zip_util.h 1.14 99/06/01 from jdk1.3 beta H build |
aoqi@0 | 1347 | |
aoqi@0 | 1348 | |
aoqi@0 | 1349 | // JDK 1.3 version |
aoqi@0 | 1350 | typedef struct real_jzentry13 { /* Zip file entry */ |
aoqi@0 | 1351 | char *name; /* entry name */ |
aoqi@0 | 1352 | jint time; /* modification time */ |
aoqi@0 | 1353 | jint size; /* size of uncompressed data */ |
aoqi@0 | 1354 | jint csize; /* size of compressed data (zero if uncompressed) */ |
aoqi@0 | 1355 | jint crc; /* crc of uncompressed data */ |
aoqi@0 | 1356 | char *comment; /* optional zip file comment */ |
aoqi@0 | 1357 | jbyte *extra; /* optional extra data */ |
aoqi@0 | 1358 | jint pos; /* position of LOC header (if negative) or data */ |
aoqi@0 | 1359 | } real_jzentry13; |
aoqi@0 | 1360 | |
aoqi@0 | 1361 | typedef struct real_jzfile13 { /* Zip file */ |
aoqi@0 | 1362 | char *name; /* zip file name */ |
aoqi@0 | 1363 | jint refs; /* number of active references */ |
aoqi@0 | 1364 | jint fd; /* open file descriptor */ |
aoqi@0 | 1365 | void *lock; /* read lock */ |
aoqi@0 | 1366 | char *comment; /* zip file comment */ |
aoqi@0 | 1367 | char *msg; /* zip error message */ |
aoqi@0 | 1368 | void *entries; /* array of hash cells */ |
aoqi@0 | 1369 | jint total; /* total number of entries */ |
aoqi@0 | 1370 | unsigned short *table; /* Hash chain heads: indexes into entries */ |
aoqi@0 | 1371 | jint tablelen; /* number of hash eads */ |
aoqi@0 | 1372 | real_jzfile13 *next; /* next zip file in search list */ |
aoqi@0 | 1373 | jzentry *cache; /* we cache the most recently freed jzentry */ |
aoqi@0 | 1374 | /* Information on metadata names in META-INF directory */ |
aoqi@0 | 1375 | char **metanames; /* array of meta names (may have null names) */ |
aoqi@0 | 1376 | jint metacount; /* number of slots in metanames array */ |
aoqi@0 | 1377 | /* If there are any per-entry comments, they are in the comments array */ |
aoqi@0 | 1378 | char **comments; |
aoqi@0 | 1379 | } real_jzfile13; |
aoqi@0 | 1380 | |
aoqi@0 | 1381 | // JDK 1.2 version |
aoqi@0 | 1382 | typedef struct real_jzentry12 { /* Zip file entry */ |
aoqi@0 | 1383 | char *name; /* entry name */ |
aoqi@0 | 1384 | jint time; /* modification time */ |
aoqi@0 | 1385 | jint size; /* size of uncompressed data */ |
aoqi@0 | 1386 | jint csize; /* size of compressed data (zero if uncompressed) */ |
aoqi@0 | 1387 | jint crc; /* crc of uncompressed data */ |
aoqi@0 | 1388 | char *comment; /* optional zip file comment */ |
aoqi@0 | 1389 | jbyte *extra; /* optional extra data */ |
aoqi@0 | 1390 | jint pos; /* position of LOC header (if negative) or data */ |
aoqi@0 | 1391 | struct real_jzentry12 *next; /* next entry in hash table */ |
aoqi@0 | 1392 | } real_jzentry12; |
aoqi@0 | 1393 | |
aoqi@0 | 1394 | typedef struct real_jzfile12 { /* Zip file */ |
aoqi@0 | 1395 | char *name; /* zip file name */ |
aoqi@0 | 1396 | jint refs; /* number of active references */ |
aoqi@0 | 1397 | jint fd; /* open file descriptor */ |
aoqi@0 | 1398 | void *lock; /* read lock */ |
aoqi@0 | 1399 | char *comment; /* zip file comment */ |
aoqi@0 | 1400 | char *msg; /* zip error message */ |
aoqi@0 | 1401 | real_jzentry12 *entries; /* array of zip entries */ |
aoqi@0 | 1402 | jint total; /* total number of entries */ |
aoqi@0 | 1403 | real_jzentry12 **table; /* hash table of entries */ |
aoqi@0 | 1404 | jint tablelen; /* number of buckets */ |
aoqi@0 | 1405 | jzfile *next; /* next zip file in search list */ |
aoqi@0 | 1406 | } real_jzfile12; |
aoqi@0 | 1407 | |
aoqi@0 | 1408 | |
aoqi@0 | 1409 | void ClassPathDirEntry::compile_the_world(Handle loader, TRAPS) { |
aoqi@0 | 1410 | // For now we only compile all methods in all classes in zip/jar files |
aoqi@0 | 1411 | tty->print_cr("CompileTheWorld : Skipped classes in %s", _dir); |
aoqi@0 | 1412 | tty->cr(); |
aoqi@0 | 1413 | } |
aoqi@0 | 1414 | |
aoqi@0 | 1415 | |
aoqi@0 | 1416 | bool ClassPathDirEntry::is_rt_jar() { |
aoqi@0 | 1417 | return false; |
aoqi@0 | 1418 | } |
aoqi@0 | 1419 | |
aoqi@0 | 1420 | void ClassPathZipEntry::compile_the_world(Handle loader, TRAPS) { |
aoqi@0 | 1421 | if (JDK_Version::is_jdk12x_version()) { |
aoqi@0 | 1422 | compile_the_world12(loader, THREAD); |
aoqi@0 | 1423 | } else { |
aoqi@0 | 1424 | compile_the_world13(loader, THREAD); |
aoqi@0 | 1425 | } |
aoqi@0 | 1426 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 1427 | if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) { |
aoqi@0 | 1428 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 1429 | tty->print_cr("\nCompileTheWorld : Ran out of memory\n"); |
aoqi@0 | 1430 | tty->print_cr("Increase class metadata storage if a limit was set"); |
aoqi@0 | 1431 | } else { |
aoqi@0 | 1432 | tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n"); |
aoqi@0 | 1433 | } |
aoqi@0 | 1434 | } |
aoqi@0 | 1435 | } |
aoqi@0 | 1436 | |
aoqi@0 | 1437 | // Version that works for JDK 1.3.x |
aoqi@0 | 1438 | void ClassPathZipEntry::compile_the_world13(Handle loader, TRAPS) { |
aoqi@0 | 1439 | real_jzfile13* zip = (real_jzfile13*) _zip; |
aoqi@0 | 1440 | tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name); |
aoqi@0 | 1441 | tty->cr(); |
aoqi@0 | 1442 | // Iterate over all entries in zip file |
aoqi@0 | 1443 | for (int n = 0; ; n++) { |
aoqi@0 | 1444 | real_jzentry13 * ze = (real_jzentry13 *)((*GetNextEntry)(_zip, n)); |
aoqi@0 | 1445 | if (ze == NULL) break; |
aoqi@0 | 1446 | ClassLoader::compile_the_world_in(ze->name, loader, CHECK); |
aoqi@0 | 1447 | } |
aoqi@0 | 1448 | } |
aoqi@0 | 1449 | |
aoqi@0 | 1450 | |
aoqi@0 | 1451 | // Version that works for JDK 1.2.x |
aoqi@0 | 1452 | void ClassPathZipEntry::compile_the_world12(Handle loader, TRAPS) { |
aoqi@0 | 1453 | real_jzfile12* zip = (real_jzfile12*) _zip; |
aoqi@0 | 1454 | tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name); |
aoqi@0 | 1455 | tty->cr(); |
aoqi@0 | 1456 | // Iterate over all entries in zip file |
aoqi@0 | 1457 | for (int n = 0; ; n++) { |
aoqi@0 | 1458 | real_jzentry12 * ze = (real_jzentry12 *)((*GetNextEntry)(_zip, n)); |
aoqi@0 | 1459 | if (ze == NULL) break; |
aoqi@0 | 1460 | ClassLoader::compile_the_world_in(ze->name, loader, CHECK); |
aoqi@0 | 1461 | } |
aoqi@0 | 1462 | } |
aoqi@0 | 1463 | |
aoqi@0 | 1464 | bool ClassPathZipEntry::is_rt_jar() { |
aoqi@0 | 1465 | if (JDK_Version::is_jdk12x_version()) { |
aoqi@0 | 1466 | return is_rt_jar12(); |
aoqi@0 | 1467 | } else { |
aoqi@0 | 1468 | return is_rt_jar13(); |
aoqi@0 | 1469 | } |
aoqi@0 | 1470 | } |
aoqi@0 | 1471 | |
aoqi@0 | 1472 | // JDK 1.3 version |
aoqi@0 | 1473 | bool ClassPathZipEntry::is_rt_jar13() { |
aoqi@0 | 1474 | real_jzfile13* zip = (real_jzfile13*) _zip; |
aoqi@0 | 1475 | int len = (int)strlen(zip->name); |
aoqi@0 | 1476 | // Check whether zip name ends in "rt.jar" |
aoqi@0 | 1477 | // This will match other archives named rt.jar as well, but this is |
aoqi@0 | 1478 | // only used for debugging. |
aoqi@0 | 1479 | return (len >= 6) && (strcasecmp(zip->name + len - 6, "rt.jar") == 0); |
aoqi@0 | 1480 | } |
aoqi@0 | 1481 | |
aoqi@0 | 1482 | // JDK 1.2 version |
aoqi@0 | 1483 | bool ClassPathZipEntry::is_rt_jar12() { |
aoqi@0 | 1484 | real_jzfile12* zip = (real_jzfile12*) _zip; |
aoqi@0 | 1485 | int len = (int)strlen(zip->name); |
aoqi@0 | 1486 | // Check whether zip name ends in "rt.jar" |
aoqi@0 | 1487 | // This will match other archives named rt.jar as well, but this is |
aoqi@0 | 1488 | // only used for debugging. |
aoqi@0 | 1489 | return (len >= 6) && (strcasecmp(zip->name + len - 6, "rt.jar") == 0); |
aoqi@0 | 1490 | } |
aoqi@0 | 1491 | |
aoqi@0 | 1492 | void LazyClassPathEntry::compile_the_world(Handle loader, TRAPS) { |
aoqi@0 | 1493 | ClassPathEntry* cpe = resolve_entry(THREAD); |
aoqi@0 | 1494 | if (cpe != NULL) { |
aoqi@0 | 1495 | cpe->compile_the_world(loader, CHECK); |
aoqi@0 | 1496 | } |
aoqi@0 | 1497 | } |
aoqi@0 | 1498 | |
aoqi@0 | 1499 | bool LazyClassPathEntry::is_rt_jar() { |
aoqi@0 | 1500 | Thread* THREAD = Thread::current(); |
aoqi@0 | 1501 | ClassPathEntry* cpe = resolve_entry(THREAD); |
aoqi@0 | 1502 | return (cpe != NULL) ? cpe->is_jar_file() : false; |
aoqi@0 | 1503 | } |
aoqi@0 | 1504 | |
aoqi@0 | 1505 | void ClassLoader::compile_the_world() { |
aoqi@0 | 1506 | EXCEPTION_MARK; |
aoqi@0 | 1507 | HandleMark hm(THREAD); |
aoqi@0 | 1508 | ResourceMark rm(THREAD); |
aoqi@0 | 1509 | // Make sure we don't run with background compilation |
aoqi@0 | 1510 | BackgroundCompilation = false; |
aoqi@0 | 1511 | // Find bootstrap loader |
aoqi@0 | 1512 | Handle system_class_loader (THREAD, SystemDictionary::java_system_loader()); |
aoqi@0 | 1513 | // Iterate over all bootstrap class path entries |
aoqi@0 | 1514 | ClassPathEntry* e = _first_entry; |
aoqi@0 | 1515 | jlong start = os::javaTimeMillis(); |
aoqi@0 | 1516 | while (e != NULL) { |
aoqi@0 | 1517 | // We stop at rt.jar, unless it is the first bootstrap path entry |
aoqi@0 | 1518 | if (e->is_rt_jar() && e != _first_entry) break; |
aoqi@0 | 1519 | e->compile_the_world(system_class_loader, CATCH); |
aoqi@0 | 1520 | e = e->next(); |
aoqi@0 | 1521 | } |
aoqi@0 | 1522 | jlong end = os::javaTimeMillis(); |
aoqi@0 | 1523 | tty->print_cr("CompileTheWorld : Done (%d classes, %d methods, " JLONG_FORMAT " ms)", |
aoqi@0 | 1524 | _compile_the_world_class_counter, _compile_the_world_method_counter, (end - start)); |
aoqi@0 | 1525 | { |
aoqi@0 | 1526 | // Print statistics as if before normal exit: |
aoqi@0 | 1527 | extern void print_statistics(); |
aoqi@0 | 1528 | print_statistics(); |
aoqi@0 | 1529 | } |
aoqi@0 | 1530 | vm_exit(0); |
aoqi@0 | 1531 | } |
aoqi@0 | 1532 | |
aoqi@0 | 1533 | int ClassLoader::_compile_the_world_class_counter = 0; |
aoqi@0 | 1534 | int ClassLoader::_compile_the_world_method_counter = 0; |
aoqi@0 | 1535 | static int _codecache_sweep_counter = 0; |
aoqi@0 | 1536 | |
aoqi@0 | 1537 | // Filter out all exceptions except OOMs |
aoqi@0 | 1538 | static void clear_pending_exception_if_not_oom(TRAPS) { |
aoqi@0 | 1539 | if (HAS_PENDING_EXCEPTION && |
aoqi@0 | 1540 | !PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) { |
aoqi@0 | 1541 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 1542 | } |
aoqi@0 | 1543 | // The CHECK at the caller will propagate the exception out |
aoqi@0 | 1544 | } |
aoqi@0 | 1545 | |
aoqi@0 | 1546 | /** |
aoqi@0 | 1547 | * Returns if the given method should be compiled when doing compile-the-world. |
aoqi@0 | 1548 | * |
aoqi@0 | 1549 | * TODO: This should be a private method in a CompileTheWorld class. |
aoqi@0 | 1550 | */ |
aoqi@0 | 1551 | static bool can_be_compiled(methodHandle m, int comp_level) { |
aoqi@0 | 1552 | assert(CompileTheWorld, "must be"); |
aoqi@0 | 1553 | |
aoqi@0 | 1554 | // It's not valid to compile a native wrapper for MethodHandle methods |
aoqi@0 | 1555 | // that take a MemberName appendix since the bytecode signature is not |
aoqi@0 | 1556 | // correct. |
aoqi@0 | 1557 | vmIntrinsics::ID iid = m->intrinsic_id(); |
aoqi@0 | 1558 | if (MethodHandles::is_signature_polymorphic(iid) && MethodHandles::has_member_arg(iid)) { |
aoqi@0 | 1559 | return false; |
aoqi@0 | 1560 | } |
aoqi@0 | 1561 | |
aoqi@0 | 1562 | return CompilationPolicy::can_be_compiled(m, comp_level); |
aoqi@0 | 1563 | } |
aoqi@0 | 1564 | |
aoqi@0 | 1565 | void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { |
aoqi@0 | 1566 | int len = (int)strlen(name); |
aoqi@0 | 1567 | if (len > 6 && strcmp(".class", name + len - 6) == 0) { |
aoqi@0 | 1568 | // We have a .class file |
aoqi@0 | 1569 | char buffer[2048]; |
aoqi@0 | 1570 | strncpy(buffer, name, len - 6); |
aoqi@0 | 1571 | buffer[len-6] = 0; |
aoqi@0 | 1572 | // If the file has a period after removing .class, it's not really a |
aoqi@0 | 1573 | // valid class file. The class loader will check everything else. |
aoqi@0 | 1574 | if (strchr(buffer, '.') == NULL) { |
aoqi@0 | 1575 | _compile_the_world_class_counter++; |
aoqi@0 | 1576 | if (_compile_the_world_class_counter > CompileTheWorldStopAt) return; |
aoqi@0 | 1577 | |
aoqi@0 | 1578 | // Construct name without extension |
aoqi@0 | 1579 | TempNewSymbol sym = SymbolTable::new_symbol(buffer, CHECK); |
aoqi@0 | 1580 | // Use loader to load and initialize class |
aoqi@0 | 1581 | Klass* ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD); |
aoqi@0 | 1582 | instanceKlassHandle k (THREAD, ik); |
aoqi@0 | 1583 | if (k.not_null() && !HAS_PENDING_EXCEPTION) { |
aoqi@0 | 1584 | k->initialize(THREAD); |
aoqi@0 | 1585 | } |
aoqi@0 | 1586 | bool exception_occurred = HAS_PENDING_EXCEPTION; |
aoqi@0 | 1587 | clear_pending_exception_if_not_oom(CHECK); |
aoqi@0 | 1588 | if (CompileTheWorldPreloadClasses && k.not_null()) { |
aoqi@0 | 1589 | ConstantPool::preload_and_initialize_all_classes(k->constants(), THREAD); |
aoqi@0 | 1590 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 1591 | // If something went wrong in preloading we just ignore it |
aoqi@0 | 1592 | clear_pending_exception_if_not_oom(CHECK); |
aoqi@0 | 1593 | tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_class_counter, buffer); |
aoqi@0 | 1594 | } |
aoqi@0 | 1595 | } |
aoqi@0 | 1596 | |
aoqi@0 | 1597 | if (_compile_the_world_class_counter >= CompileTheWorldStartAt) { |
aoqi@0 | 1598 | if (k.is_null() || exception_occurred) { |
aoqi@0 | 1599 | // If something went wrong (e.g. ExceptionInInitializerError) we skip this class |
aoqi@0 | 1600 | tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_class_counter, buffer); |
aoqi@0 | 1601 | } else { |
aoqi@0 | 1602 | tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_class_counter, buffer); |
aoqi@0 | 1603 | // Preload all classes to get around uncommon traps |
aoqi@0 | 1604 | // Iterate over all methods in class |
aoqi@0 | 1605 | int comp_level = CompilationPolicy::policy()->initial_compile_level(); |
aoqi@0 | 1606 | for (int n = 0; n < k->methods()->length(); n++) { |
aoqi@0 | 1607 | methodHandle m (THREAD, k->methods()->at(n)); |
aoqi@0 | 1608 | if (can_be_compiled(m, comp_level)) { |
aoqi@0 | 1609 | if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) { |
aoqi@0 | 1610 | // Give sweeper a chance to keep up with CTW |
aoqi@0 | 1611 | VM_ForceSafepoint op; |
aoqi@0 | 1612 | VMThread::execute(&op); |
aoqi@0 | 1613 | _codecache_sweep_counter = 0; |
aoqi@0 | 1614 | } |
aoqi@0 | 1615 | // Force compilation |
aoqi@0 | 1616 | CompileBroker::compile_method(m, InvocationEntryBci, comp_level, |
aoqi@0 | 1617 | methodHandle(), 0, "CTW", THREAD); |
aoqi@0 | 1618 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 1619 | clear_pending_exception_if_not_oom(CHECK); |
aoqi@0 | 1620 | tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string()); |
aoqi@0 | 1621 | } else { |
aoqi@0 | 1622 | _compile_the_world_method_counter++; |
aoqi@0 | 1623 | } |
aoqi@0 | 1624 | if (TieredCompilation && TieredStopAtLevel >= CompLevel_full_optimization) { |
aoqi@0 | 1625 | // Clobber the first compile and force second tier compilation |
aoqi@0 | 1626 | nmethod* nm = m->code(); |
iveresov@7147 | 1627 | if (nm != NULL && !m->is_method_handle_intrinsic()) { |
aoqi@0 | 1628 | // Throw out the code so that the code cache doesn't fill up |
aoqi@0 | 1629 | nm->make_not_entrant(); |
aoqi@0 | 1630 | } |
aoqi@0 | 1631 | CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_full_optimization, |
aoqi@0 | 1632 | methodHandle(), 0, "CTW", THREAD); |
aoqi@0 | 1633 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 1634 | clear_pending_exception_if_not_oom(CHECK); |
aoqi@0 | 1635 | tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string()); |
aoqi@0 | 1636 | } else { |
aoqi@0 | 1637 | _compile_the_world_method_counter++; |
aoqi@0 | 1638 | } |
aoqi@0 | 1639 | } |
aoqi@0 | 1640 | } else { |
aoqi@0 | 1641 | tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_class_counter, m->name_and_sig_as_C_string()); |
aoqi@0 | 1642 | } |
aoqi@0 | 1643 | |
aoqi@0 | 1644 | nmethod* nm = m->code(); |
iveresov@7147 | 1645 | if (nm != NULL && !m->is_method_handle_intrinsic()) { |
aoqi@0 | 1646 | // Throw out the code so that the code cache doesn't fill up |
aoqi@0 | 1647 | nm->make_not_entrant(); |
aoqi@0 | 1648 | } |
aoqi@0 | 1649 | } |
aoqi@0 | 1650 | } |
aoqi@0 | 1651 | } |
aoqi@0 | 1652 | } |
aoqi@0 | 1653 | } |
aoqi@0 | 1654 | } |
aoqi@0 | 1655 | |
aoqi@0 | 1656 | #endif //PRODUCT |
aoqi@0 | 1657 | |
aoqi@0 | 1658 | // Please keep following two functions at end of this file. With them placed at top or in middle of the file, |
aoqi@0 | 1659 | // they could get inlined by agressive compiler, an unknown trick, see bug 6966589. |
aoqi@0 | 1660 | void PerfClassTraceTime::initialize() { |
aoqi@0 | 1661 | if (!UsePerfData) return; |
aoqi@0 | 1662 | |
aoqi@0 | 1663 | if (_eventp != NULL) { |
aoqi@0 | 1664 | // increment the event counter |
aoqi@0 | 1665 | _eventp->inc(); |
aoqi@0 | 1666 | } |
aoqi@0 | 1667 | |
aoqi@0 | 1668 | // stop the current active thread-local timer to measure inclusive time |
aoqi@0 | 1669 | _prev_active_event = -1; |
aoqi@0 | 1670 | for (int i=0; i < EVENT_TYPE_COUNT; i++) { |
aoqi@0 | 1671 | if (_timers[i].is_active()) { |
aoqi@0 | 1672 | assert(_prev_active_event == -1, "should have only one active timer"); |
aoqi@0 | 1673 | _prev_active_event = i; |
aoqi@0 | 1674 | _timers[i].stop(); |
aoqi@0 | 1675 | } |
aoqi@0 | 1676 | } |
aoqi@0 | 1677 | |
aoqi@0 | 1678 | if (_recursion_counters == NULL || (_recursion_counters[_event_type])++ == 0) { |
aoqi@0 | 1679 | // start the inclusive timer if not recursively called |
aoqi@0 | 1680 | _t.start(); |
aoqi@0 | 1681 | } |
aoqi@0 | 1682 | |
aoqi@0 | 1683 | // start thread-local timer of the given event type |
aoqi@0 | 1684 | if (!_timers[_event_type].is_active()) { |
aoqi@0 | 1685 | _timers[_event_type].start(); |
aoqi@0 | 1686 | } |
aoqi@0 | 1687 | } |
aoqi@0 | 1688 | |
aoqi@0 | 1689 | PerfClassTraceTime::~PerfClassTraceTime() { |
aoqi@0 | 1690 | if (!UsePerfData) return; |
aoqi@0 | 1691 | |
aoqi@0 | 1692 | // stop the thread-local timer as the event completes |
aoqi@0 | 1693 | // and resume the thread-local timer of the event next on the stack |
aoqi@0 | 1694 | _timers[_event_type].stop(); |
aoqi@0 | 1695 | jlong selftime = _timers[_event_type].ticks(); |
aoqi@0 | 1696 | |
aoqi@0 | 1697 | if (_prev_active_event >= 0) { |
aoqi@0 | 1698 | _timers[_prev_active_event].start(); |
aoqi@0 | 1699 | } |
aoqi@0 | 1700 | |
aoqi@0 | 1701 | if (_recursion_counters != NULL && --(_recursion_counters[_event_type]) > 0) return; |
aoqi@0 | 1702 | |
aoqi@0 | 1703 | // increment the counters only on the leaf call |
aoqi@0 | 1704 | _t.stop(); |
aoqi@0 | 1705 | _timep->inc(_t.ticks()); |
aoqi@0 | 1706 | if (_selftimep != NULL) { |
aoqi@0 | 1707 | _selftimep->inc(selftime); |
aoqi@0 | 1708 | } |
aoqi@0 | 1709 | // add all class loading related event selftime to the accumulated time counter |
aoqi@0 | 1710 | ClassLoader::perf_accumulated_time()->inc(selftime); |
aoqi@0 | 1711 | |
aoqi@0 | 1712 | // reset the timer |
aoqi@0 | 1713 | _timers[_event_type].reset(); |
aoqi@0 | 1714 | } |