Tue, 20 Jul 2010 08:41:42 -0700
6964170: Verifier crashes
Summary: Check if klassOop != NULL rather than klass_part != NULL
Reviewed-by: kamg, never
duke@435 | 1 | /* |
never@1999 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_classLoader.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | // Entry points in zip.dll for loading zip/jar file entries |
duke@435 | 30 | |
duke@435 | 31 | typedef void * * (JNICALL *ZipOpen_t)(const char *name, char **pmsg); |
duke@435 | 32 | typedef void (JNICALL *ZipClose_t)(jzfile *zip); |
duke@435 | 33 | typedef jzentry* (JNICALL *FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen); |
duke@435 | 34 | typedef jboolean (JNICALL *ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf); |
duke@435 | 35 | typedef jboolean (JNICALL *ReadMappedEntry_t)(jzfile *zip, jzentry *entry, unsigned char **buf, char *namebuf); |
duke@435 | 36 | typedef jzentry* (JNICALL *GetNextEntry_t)(jzfile *zip, jint n); |
duke@435 | 37 | |
duke@435 | 38 | static ZipOpen_t ZipOpen = NULL; |
duke@435 | 39 | static ZipClose_t ZipClose = NULL; |
duke@435 | 40 | static FindEntry_t FindEntry = NULL; |
duke@435 | 41 | static ReadEntry_t ReadEntry = NULL; |
duke@435 | 42 | static ReadMappedEntry_t ReadMappedEntry = NULL; |
duke@435 | 43 | static GetNextEntry_t GetNextEntry = NULL; |
duke@435 | 44 | static canonicalize_fn_t CanonicalizeEntry = NULL; |
duke@435 | 45 | |
duke@435 | 46 | // Globals |
duke@435 | 47 | |
duke@435 | 48 | PerfCounter* ClassLoader::_perf_accumulated_time = NULL; |
duke@435 | 49 | PerfCounter* ClassLoader::_perf_classes_inited = NULL; |
duke@435 | 50 | PerfCounter* ClassLoader::_perf_class_init_time = NULL; |
mchung@1310 | 51 | PerfCounter* ClassLoader::_perf_class_init_selftime = NULL; |
mchung@1310 | 52 | PerfCounter* ClassLoader::_perf_classes_verified = NULL; |
duke@435 | 53 | PerfCounter* ClassLoader::_perf_class_verify_time = NULL; |
mchung@1310 | 54 | PerfCounter* ClassLoader::_perf_class_verify_selftime = NULL; |
duke@435 | 55 | PerfCounter* ClassLoader::_perf_classes_linked = NULL; |
duke@435 | 56 | PerfCounter* ClassLoader::_perf_class_link_time = NULL; |
mchung@1310 | 57 | PerfCounter* ClassLoader::_perf_class_link_selftime = NULL; |
mchung@1310 | 58 | PerfCounter* ClassLoader::_perf_class_parse_time = NULL; |
mchung@1310 | 59 | PerfCounter* ClassLoader::_perf_class_parse_selftime = NULL; |
mchung@1310 | 60 | PerfCounter* ClassLoader::_perf_sys_class_lookup_time = NULL; |
mchung@1310 | 61 | PerfCounter* ClassLoader::_perf_shared_classload_time = NULL; |
mchung@1310 | 62 | PerfCounter* ClassLoader::_perf_sys_classload_time = NULL; |
mchung@1310 | 63 | PerfCounter* ClassLoader::_perf_app_classload_time = NULL; |
mchung@1310 | 64 | PerfCounter* ClassLoader::_perf_app_classload_selftime = NULL; |
mchung@1310 | 65 | PerfCounter* ClassLoader::_perf_app_classload_count = NULL; |
mchung@1310 | 66 | PerfCounter* ClassLoader::_perf_define_appclasses = NULL; |
mchung@1310 | 67 | PerfCounter* ClassLoader::_perf_define_appclass_time = NULL; |
mchung@1310 | 68 | PerfCounter* ClassLoader::_perf_define_appclass_selftime = NULL; |
mchung@1310 | 69 | PerfCounter* ClassLoader::_perf_app_classfile_bytes_read = NULL; |
mchung@1310 | 70 | PerfCounter* ClassLoader::_perf_sys_classfile_bytes_read = NULL; |
duke@435 | 71 | PerfCounter* ClassLoader::_sync_systemLoaderLockContentionRate = NULL; |
duke@435 | 72 | PerfCounter* ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL; |
duke@435 | 73 | PerfCounter* ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL; |
duke@435 | 74 | PerfCounter* ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL; |
duke@435 | 75 | PerfCounter* ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL; |
duke@435 | 76 | PerfCounter* ClassLoader::_unsafe_defineClassCallCounter = NULL; |
duke@435 | 77 | PerfCounter* ClassLoader::_isUnsyncloadClass = NULL; |
duke@435 | 78 | PerfCounter* ClassLoader::_load_instance_class_failCounter = NULL; |
duke@435 | 79 | |
duke@435 | 80 | ClassPathEntry* ClassLoader::_first_entry = NULL; |
duke@435 | 81 | ClassPathEntry* ClassLoader::_last_entry = NULL; |
duke@435 | 82 | PackageHashtable* ClassLoader::_package_hash_table = NULL; |
duke@435 | 83 | |
duke@435 | 84 | // helper routines |
duke@435 | 85 | bool string_starts_with(const char* str, const char* str_to_find) { |
duke@435 | 86 | size_t str_len = strlen(str); |
duke@435 | 87 | size_t str_to_find_len = strlen(str_to_find); |
duke@435 | 88 | if (str_to_find_len > str_len) { |
duke@435 | 89 | return false; |
duke@435 | 90 | } |
duke@435 | 91 | return (strncmp(str, str_to_find, str_to_find_len) == 0); |
duke@435 | 92 | } |
duke@435 | 93 | |
duke@435 | 94 | bool string_ends_with(const char* str, const char* str_to_find) { |
duke@435 | 95 | size_t str_len = strlen(str); |
duke@435 | 96 | size_t str_to_find_len = strlen(str_to_find); |
duke@435 | 97 | if (str_to_find_len > str_len) { |
duke@435 | 98 | return false; |
duke@435 | 99 | } |
duke@435 | 100 | return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0); |
duke@435 | 101 | } |
duke@435 | 102 | |
duke@435 | 103 | |
duke@435 | 104 | MetaIndex::MetaIndex(char** meta_package_names, int num_meta_package_names) { |
duke@435 | 105 | if (num_meta_package_names == 0) { |
duke@435 | 106 | _meta_package_names = NULL; |
duke@435 | 107 | _num_meta_package_names = 0; |
duke@435 | 108 | } else { |
duke@435 | 109 | _meta_package_names = NEW_C_HEAP_ARRAY(char*, num_meta_package_names); |
duke@435 | 110 | _num_meta_package_names = num_meta_package_names; |
duke@435 | 111 | memcpy(_meta_package_names, meta_package_names, num_meta_package_names * sizeof(char*)); |
duke@435 | 112 | } |
duke@435 | 113 | } |
duke@435 | 114 | |
duke@435 | 115 | |
duke@435 | 116 | MetaIndex::~MetaIndex() { |
duke@435 | 117 | FREE_C_HEAP_ARRAY(char*, _meta_package_names); |
duke@435 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | |
duke@435 | 121 | bool MetaIndex::may_contain(const char* class_name) { |
duke@435 | 122 | if ( _num_meta_package_names == 0) { |
duke@435 | 123 | return false; |
duke@435 | 124 | } |
duke@435 | 125 | size_t class_name_len = strlen(class_name); |
duke@435 | 126 | for (int i = 0; i < _num_meta_package_names; i++) { |
duke@435 | 127 | char* pkg = _meta_package_names[i]; |
duke@435 | 128 | size_t pkg_len = strlen(pkg); |
duke@435 | 129 | size_t min_len = MIN2(class_name_len, pkg_len); |
duke@435 | 130 | if (!strncmp(class_name, pkg, min_len)) { |
duke@435 | 131 | return true; |
duke@435 | 132 | } |
duke@435 | 133 | } |
duke@435 | 134 | return false; |
duke@435 | 135 | } |
duke@435 | 136 | |
duke@435 | 137 | |
duke@435 | 138 | ClassPathEntry::ClassPathEntry() { |
duke@435 | 139 | set_next(NULL); |
duke@435 | 140 | } |
duke@435 | 141 | |
duke@435 | 142 | |
duke@435 | 143 | bool ClassPathEntry::is_lazy() { |
duke@435 | 144 | return false; |
duke@435 | 145 | } |
duke@435 | 146 | |
duke@435 | 147 | ClassPathDirEntry::ClassPathDirEntry(char* dir) : ClassPathEntry() { |
duke@435 | 148 | _dir = NEW_C_HEAP_ARRAY(char, strlen(dir)+1); |
duke@435 | 149 | strcpy(_dir, dir); |
duke@435 | 150 | } |
duke@435 | 151 | |
duke@435 | 152 | |
duke@435 | 153 | ClassFileStream* ClassPathDirEntry::open_stream(const char* name) { |
duke@435 | 154 | // construct full path name |
duke@435 | 155 | char path[JVM_MAXPATHLEN]; |
duke@435 | 156 | if (jio_snprintf(path, sizeof(path), "%s%s%s", _dir, os::file_separator(), name) == -1) { |
duke@435 | 157 | return NULL; |
duke@435 | 158 | } |
duke@435 | 159 | // check if file exists |
duke@435 | 160 | struct stat st; |
duke@435 | 161 | if (os::stat(path, &st) == 0) { |
duke@435 | 162 | // found file, open it |
duke@435 | 163 | int file_handle = hpi::open(path, 0, 0); |
duke@435 | 164 | if (file_handle != -1) { |
duke@435 | 165 | // read contents into resource array |
duke@435 | 166 | u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size); |
duke@435 | 167 | size_t num_read = os::read(file_handle, (char*) buffer, st.st_size); |
duke@435 | 168 | // close file |
duke@435 | 169 | hpi::close(file_handle); |
duke@435 | 170 | // construct ClassFileStream |
duke@435 | 171 | if (num_read == (size_t)st.st_size) { |
mchung@1310 | 172 | if (UsePerfData) { |
mchung@1310 | 173 | ClassLoader::perf_sys_classfile_bytes_read()->inc(num_read); |
mchung@1310 | 174 | } |
duke@435 | 175 | return new ClassFileStream(buffer, st.st_size, _dir); // Resource allocated |
duke@435 | 176 | } |
duke@435 | 177 | } |
duke@435 | 178 | } |
duke@435 | 179 | return NULL; |
duke@435 | 180 | } |
duke@435 | 181 | |
duke@435 | 182 | |
duke@435 | 183 | ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() { |
duke@435 | 184 | _zip = zip; |
duke@435 | 185 | _zip_name = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1); |
duke@435 | 186 | strcpy(_zip_name, zip_name); |
duke@435 | 187 | } |
duke@435 | 188 | |
duke@435 | 189 | ClassPathZipEntry::~ClassPathZipEntry() { |
duke@435 | 190 | if (ZipClose != NULL) { |
duke@435 | 191 | (*ZipClose)(_zip); |
duke@435 | 192 | } |
duke@435 | 193 | FREE_C_HEAP_ARRAY(char, _zip_name); |
duke@435 | 194 | } |
duke@435 | 195 | |
duke@435 | 196 | ClassFileStream* ClassPathZipEntry::open_stream(const char* name) { |
duke@435 | 197 | // enable call to C land |
duke@435 | 198 | JavaThread* thread = JavaThread::current(); |
duke@435 | 199 | ThreadToNativeFromVM ttn(thread); |
duke@435 | 200 | // check whether zip archive contains name |
duke@435 | 201 | jint filesize, name_len; |
duke@435 | 202 | jzentry* entry = (*FindEntry)(_zip, name, &filesize, &name_len); |
duke@435 | 203 | if (entry == NULL) return NULL; |
duke@435 | 204 | u1* buffer; |
duke@435 | 205 | char name_buf[128]; |
duke@435 | 206 | char* filename; |
duke@435 | 207 | if (name_len < 128) { |
duke@435 | 208 | filename = name_buf; |
duke@435 | 209 | } else { |
duke@435 | 210 | filename = NEW_RESOURCE_ARRAY(char, name_len + 1); |
duke@435 | 211 | } |
duke@435 | 212 | |
duke@435 | 213 | // file found, get pointer to class in mmaped jar file. |
duke@435 | 214 | if (ReadMappedEntry == NULL || |
duke@435 | 215 | !(*ReadMappedEntry)(_zip, entry, &buffer, filename)) { |
duke@435 | 216 | // mmaped access not available, perhaps due to compression, |
duke@435 | 217 | // read contents into resource array |
duke@435 | 218 | buffer = NEW_RESOURCE_ARRAY(u1, filesize); |
duke@435 | 219 | if (!(*ReadEntry)(_zip, entry, buffer, filename)) return NULL; |
duke@435 | 220 | } |
mchung@1310 | 221 | if (UsePerfData) { |
mchung@1310 | 222 | ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize); |
mchung@1310 | 223 | } |
duke@435 | 224 | // return result |
duke@435 | 225 | return new ClassFileStream(buffer, filesize, _zip_name); // Resource allocated |
duke@435 | 226 | } |
duke@435 | 227 | |
duke@435 | 228 | // invoke function for each entry in the zip file |
duke@435 | 229 | void ClassPathZipEntry::contents_do(void f(const char* name, void* context), void* context) { |
duke@435 | 230 | JavaThread* thread = JavaThread::current(); |
duke@435 | 231 | HandleMark handle_mark(thread); |
duke@435 | 232 | ThreadToNativeFromVM ttn(thread); |
duke@435 | 233 | for (int n = 0; ; n++) { |
duke@435 | 234 | jzentry * ze = ((*GetNextEntry)(_zip, n)); |
duke@435 | 235 | if (ze == NULL) break; |
duke@435 | 236 | (*f)(ze->name, context); |
duke@435 | 237 | } |
duke@435 | 238 | } |
duke@435 | 239 | |
duke@435 | 240 | LazyClassPathEntry::LazyClassPathEntry(char* path, struct stat st) : ClassPathEntry() { |
duke@435 | 241 | _path = strdup(path); |
duke@435 | 242 | _st = st; |
duke@435 | 243 | _meta_index = NULL; |
duke@435 | 244 | _resolved_entry = NULL; |
duke@435 | 245 | } |
duke@435 | 246 | |
duke@435 | 247 | bool LazyClassPathEntry::is_jar_file() { |
duke@435 | 248 | return ((_st.st_mode & S_IFREG) == S_IFREG); |
duke@435 | 249 | } |
duke@435 | 250 | |
duke@435 | 251 | ClassPathEntry* LazyClassPathEntry::resolve_entry() { |
duke@435 | 252 | if (_resolved_entry != NULL) { |
duke@435 | 253 | return (ClassPathEntry*) _resolved_entry; |
duke@435 | 254 | } |
duke@435 | 255 | ClassPathEntry* new_entry = NULL; |
duke@435 | 256 | ClassLoader::create_class_path_entry(_path, _st, &new_entry, false); |
duke@435 | 257 | assert(new_entry != NULL, "earlier code should have caught this"); |
duke@435 | 258 | { |
duke@435 | 259 | ThreadCritical tc; |
duke@435 | 260 | if (_resolved_entry == NULL) { |
duke@435 | 261 | _resolved_entry = new_entry; |
duke@435 | 262 | return new_entry; |
duke@435 | 263 | } |
duke@435 | 264 | } |
duke@435 | 265 | assert(_resolved_entry != NULL, "bug in MT-safe resolution logic"); |
duke@435 | 266 | delete new_entry; |
duke@435 | 267 | return (ClassPathEntry*) _resolved_entry; |
duke@435 | 268 | } |
duke@435 | 269 | |
duke@435 | 270 | ClassFileStream* LazyClassPathEntry::open_stream(const char* name) { |
duke@435 | 271 | if (_meta_index != NULL && |
duke@435 | 272 | !_meta_index->may_contain(name)) { |
duke@435 | 273 | return NULL; |
duke@435 | 274 | } |
duke@435 | 275 | return resolve_entry()->open_stream(name); |
duke@435 | 276 | } |
duke@435 | 277 | |
duke@435 | 278 | bool LazyClassPathEntry::is_lazy() { |
duke@435 | 279 | return true; |
duke@435 | 280 | } |
duke@435 | 281 | |
duke@435 | 282 | static void print_meta_index(LazyClassPathEntry* entry, |
duke@435 | 283 | GrowableArray<char*>& meta_packages) { |
duke@435 | 284 | tty->print("[Meta index for %s=", entry->name()); |
duke@435 | 285 | for (int i = 0; i < meta_packages.length(); i++) { |
duke@435 | 286 | if (i > 0) tty->print(" "); |
duke@435 | 287 | tty->print(meta_packages.at(i)); |
duke@435 | 288 | } |
duke@435 | 289 | tty->print_cr("]"); |
duke@435 | 290 | } |
duke@435 | 291 | |
duke@435 | 292 | |
duke@435 | 293 | void ClassLoader::setup_meta_index() { |
duke@435 | 294 | // Set up meta index which allows us to open boot jars lazily if |
duke@435 | 295 | // class data sharing is enabled |
duke@435 | 296 | const char* known_version = "% VERSION 2"; |
duke@435 | 297 | char* meta_index_path = Arguments::get_meta_index_path(); |
duke@435 | 298 | char* meta_index_dir = Arguments::get_meta_index_dir(); |
duke@435 | 299 | FILE* file = fopen(meta_index_path, "r"); |
duke@435 | 300 | int line_no = 0; |
duke@435 | 301 | if (file != NULL) { |
duke@435 | 302 | ResourceMark rm; |
duke@435 | 303 | LazyClassPathEntry* cur_entry = NULL; |
duke@435 | 304 | GrowableArray<char*> boot_class_path_packages(10); |
duke@435 | 305 | char package_name[256]; |
duke@435 | 306 | bool skipCurrentJar = false; |
duke@435 | 307 | while (fgets(package_name, sizeof(package_name), file) != NULL) { |
duke@435 | 308 | ++line_no; |
duke@435 | 309 | // Remove trailing newline |
duke@435 | 310 | package_name[strlen(package_name) - 1] = '\0'; |
duke@435 | 311 | switch(package_name[0]) { |
duke@435 | 312 | case '%': |
duke@435 | 313 | { |
duke@435 | 314 | if ((line_no == 1) && (strcmp(package_name, known_version) != 0)) { |
duke@435 | 315 | if (TraceClassLoading && Verbose) { |
duke@435 | 316 | tty->print("[Unsupported meta index version]"); |
duke@435 | 317 | } |
duke@435 | 318 | fclose(file); |
duke@435 | 319 | return; |
duke@435 | 320 | } |
duke@435 | 321 | } |
duke@435 | 322 | |
duke@435 | 323 | // These directives indicate jar files which contain only |
duke@435 | 324 | // classes, only non-classfile resources, or a combination of |
duke@435 | 325 | // the two. See src/share/classes/sun/misc/MetaIndex.java and |
duke@435 | 326 | // make/tools/MetaIndex/BuildMetaIndex.java in the J2SE |
duke@435 | 327 | // workspace. |
duke@435 | 328 | case '#': |
duke@435 | 329 | case '!': |
duke@435 | 330 | case '@': |
duke@435 | 331 | { |
duke@435 | 332 | // Hand off current packages to current lazy entry (if any) |
duke@435 | 333 | if ((cur_entry != NULL) && |
duke@435 | 334 | (boot_class_path_packages.length() > 0)) { |
duke@435 | 335 | if (TraceClassLoading && Verbose) { |
duke@435 | 336 | print_meta_index(cur_entry, boot_class_path_packages); |
duke@435 | 337 | } |
duke@435 | 338 | MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0), |
duke@435 | 339 | boot_class_path_packages.length()); |
duke@435 | 340 | cur_entry->set_meta_index(index); |
duke@435 | 341 | } |
duke@435 | 342 | cur_entry = NULL; |
duke@435 | 343 | boot_class_path_packages.clear(); |
duke@435 | 344 | |
duke@435 | 345 | // Find lazy entry corresponding to this jar file |
duke@435 | 346 | for (ClassPathEntry* entry = _first_entry; entry != NULL; entry = entry->next()) { |
duke@435 | 347 | if (entry->is_lazy() && |
duke@435 | 348 | string_starts_with(entry->name(), meta_index_dir) && |
duke@435 | 349 | string_ends_with(entry->name(), &package_name[2])) { |
duke@435 | 350 | cur_entry = (LazyClassPathEntry*) entry; |
duke@435 | 351 | break; |
duke@435 | 352 | } |
duke@435 | 353 | } |
duke@435 | 354 | |
duke@435 | 355 | // If the first character is '@', it indicates the following jar |
duke@435 | 356 | // file is a resource only jar file in which case, we should skip |
duke@435 | 357 | // reading the subsequent entries since the resource loading is |
duke@435 | 358 | // totally handled by J2SE side. |
duke@435 | 359 | if (package_name[0] == '@') { |
duke@435 | 360 | if (cur_entry != NULL) { |
duke@435 | 361 | cur_entry->set_meta_index(new MetaIndex(NULL, 0)); |
duke@435 | 362 | } |
duke@435 | 363 | cur_entry = NULL; |
duke@435 | 364 | skipCurrentJar = true; |
duke@435 | 365 | } else { |
duke@435 | 366 | skipCurrentJar = false; |
duke@435 | 367 | } |
duke@435 | 368 | |
duke@435 | 369 | break; |
duke@435 | 370 | } |
duke@435 | 371 | |
duke@435 | 372 | default: |
duke@435 | 373 | { |
duke@435 | 374 | if (!skipCurrentJar && cur_entry != NULL) { |
duke@435 | 375 | char* new_name = strdup(package_name); |
duke@435 | 376 | boot_class_path_packages.append(new_name); |
duke@435 | 377 | } |
duke@435 | 378 | } |
duke@435 | 379 | } |
duke@435 | 380 | } |
duke@435 | 381 | // Hand off current packages to current lazy entry (if any) |
duke@435 | 382 | if ((cur_entry != NULL) && |
duke@435 | 383 | (boot_class_path_packages.length() > 0)) { |
duke@435 | 384 | if (TraceClassLoading && Verbose) { |
duke@435 | 385 | print_meta_index(cur_entry, boot_class_path_packages); |
duke@435 | 386 | } |
duke@435 | 387 | MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0), |
duke@435 | 388 | boot_class_path_packages.length()); |
duke@435 | 389 | cur_entry->set_meta_index(index); |
duke@435 | 390 | } |
duke@435 | 391 | fclose(file); |
duke@435 | 392 | } |
duke@435 | 393 | } |
duke@435 | 394 | |
duke@435 | 395 | void ClassLoader::setup_bootstrap_search_path() { |
duke@435 | 396 | assert(_first_entry == NULL, "should not setup bootstrap class search path twice"); |
duke@435 | 397 | char* sys_class_path = os::strdup(Arguments::get_sysclasspath()); |
duke@435 | 398 | if (TraceClassLoading && Verbose) { |
duke@435 | 399 | tty->print_cr("[Bootstrap loader class path=%s]", sys_class_path); |
duke@435 | 400 | } |
duke@435 | 401 | |
duke@435 | 402 | int len = (int)strlen(sys_class_path); |
duke@435 | 403 | int end = 0; |
duke@435 | 404 | |
duke@435 | 405 | // Iterate over class path entries |
duke@435 | 406 | for (int start = 0; start < len; start = end) { |
duke@435 | 407 | while (sys_class_path[end] && sys_class_path[end] != os::path_separator()[0]) { |
duke@435 | 408 | end++; |
duke@435 | 409 | } |
duke@435 | 410 | char* path = NEW_C_HEAP_ARRAY(char, end-start+1); |
duke@435 | 411 | strncpy(path, &sys_class_path[start], end-start); |
duke@435 | 412 | path[end-start] = '\0'; |
duke@435 | 413 | update_class_path_entry_list(path, false); |
duke@435 | 414 | FREE_C_HEAP_ARRAY(char, path); |
duke@435 | 415 | while (sys_class_path[end] == os::path_separator()[0]) { |
duke@435 | 416 | end++; |
duke@435 | 417 | } |
duke@435 | 418 | } |
duke@435 | 419 | } |
duke@435 | 420 | |
duke@435 | 421 | void ClassLoader::create_class_path_entry(char *path, struct stat st, ClassPathEntry **new_entry, bool lazy) { |
duke@435 | 422 | JavaThread* thread = JavaThread::current(); |
duke@435 | 423 | if (lazy) { |
duke@435 | 424 | *new_entry = new LazyClassPathEntry(path, st); |
duke@435 | 425 | return; |
duke@435 | 426 | } |
duke@435 | 427 | if ((st.st_mode & S_IFREG) == S_IFREG) { |
duke@435 | 428 | // Regular file, should be a zip file |
duke@435 | 429 | // Canonicalized filename |
duke@435 | 430 | char canonical_path[JVM_MAXPATHLEN]; |
duke@435 | 431 | if (!get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) { |
duke@435 | 432 | // This matches the classic VM |
duke@435 | 433 | EXCEPTION_MARK; |
duke@435 | 434 | THROW_MSG(vmSymbols::java_io_IOException(), "Bad pathname"); |
duke@435 | 435 | } |
duke@435 | 436 | char* error_msg = NULL; |
duke@435 | 437 | jzfile* zip; |
duke@435 | 438 | { |
duke@435 | 439 | // enable call to C land |
duke@435 | 440 | ThreadToNativeFromVM ttn(thread); |
duke@435 | 441 | HandleMark hm(thread); |
duke@435 | 442 | zip = (*ZipOpen)(canonical_path, &error_msg); |
duke@435 | 443 | } |
duke@435 | 444 | if (zip != NULL && error_msg == NULL) { |
duke@435 | 445 | *new_entry = new ClassPathZipEntry(zip, path); |
duke@435 | 446 | if (TraceClassLoading) { |
duke@435 | 447 | tty->print_cr("[Opened %s]", path); |
duke@435 | 448 | } |
duke@435 | 449 | } else { |
duke@435 | 450 | ResourceMark rm(thread); |
duke@435 | 451 | char *msg; |
duke@435 | 452 | if (error_msg == NULL) { |
duke@435 | 453 | msg = NEW_RESOURCE_ARRAY(char, strlen(path) + 128); ; |
duke@435 | 454 | jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path); |
duke@435 | 455 | } else { |
duke@435 | 456 | int len = (int)(strlen(path) + strlen(error_msg) + 128); |
duke@435 | 457 | msg = NEW_RESOURCE_ARRAY(char, len); ; |
duke@435 | 458 | jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path); |
duke@435 | 459 | } |
duke@435 | 460 | EXCEPTION_MARK; |
duke@435 | 461 | THROW_MSG(vmSymbols::java_lang_ClassNotFoundException(), msg); |
duke@435 | 462 | } |
duke@435 | 463 | } else { |
duke@435 | 464 | // Directory |
duke@435 | 465 | *new_entry = new ClassPathDirEntry(path); |
duke@435 | 466 | if (TraceClassLoading) { |
duke@435 | 467 | tty->print_cr("[Path %s]", path); |
duke@435 | 468 | } |
duke@435 | 469 | } |
duke@435 | 470 | } |
duke@435 | 471 | |
duke@435 | 472 | |
duke@435 | 473 | // Create a class path zip entry for a given path (return NULL if not found |
duke@435 | 474 | // or zip/JAR file cannot be opened) |
duke@435 | 475 | ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) { |
duke@435 | 476 | // check for a regular file |
duke@435 | 477 | struct stat st; |
duke@435 | 478 | if (os::stat(path, &st) == 0) { |
duke@435 | 479 | if ((st.st_mode & S_IFREG) == S_IFREG) { |
duke@435 | 480 | char orig_path[JVM_MAXPATHLEN]; |
duke@435 | 481 | char canonical_path[JVM_MAXPATHLEN]; |
duke@435 | 482 | |
duke@435 | 483 | strcpy(orig_path, path); |
duke@435 | 484 | if (get_canonical_path(orig_path, canonical_path, JVM_MAXPATHLEN)) { |
duke@435 | 485 | char* error_msg = NULL; |
duke@435 | 486 | jzfile* zip; |
duke@435 | 487 | { |
duke@435 | 488 | // enable call to C land |
duke@435 | 489 | JavaThread* thread = JavaThread::current(); |
duke@435 | 490 | ThreadToNativeFromVM ttn(thread); |
duke@435 | 491 | HandleMark hm(thread); |
duke@435 | 492 | zip = (*ZipOpen)(canonical_path, &error_msg); |
duke@435 | 493 | } |
duke@435 | 494 | if (zip != NULL && error_msg == NULL) { |
duke@435 | 495 | // create using canonical path |
duke@435 | 496 | return new ClassPathZipEntry(zip, canonical_path); |
duke@435 | 497 | } |
duke@435 | 498 | } |
duke@435 | 499 | } |
duke@435 | 500 | } |
duke@435 | 501 | return NULL; |
duke@435 | 502 | } |
duke@435 | 503 | |
duke@435 | 504 | // returns true if entry already on class path |
duke@435 | 505 | bool ClassLoader::contains_entry(ClassPathEntry *entry) { |
duke@435 | 506 | ClassPathEntry* e = _first_entry; |
duke@435 | 507 | while (e != NULL) { |
duke@435 | 508 | // assume zip entries have been canonicalized |
duke@435 | 509 | if (strcmp(entry->name(), e->name()) == 0) { |
duke@435 | 510 | return true; |
duke@435 | 511 | } |
duke@435 | 512 | e = e->next(); |
duke@435 | 513 | } |
duke@435 | 514 | return false; |
duke@435 | 515 | } |
duke@435 | 516 | |
duke@435 | 517 | void ClassLoader::add_to_list(ClassPathEntry *new_entry) { |
duke@435 | 518 | if (new_entry != NULL) { |
duke@435 | 519 | if (_last_entry == NULL) { |
duke@435 | 520 | _first_entry = _last_entry = new_entry; |
duke@435 | 521 | } else { |
duke@435 | 522 | _last_entry->set_next(new_entry); |
duke@435 | 523 | _last_entry = new_entry; |
duke@435 | 524 | } |
duke@435 | 525 | } |
duke@435 | 526 | } |
duke@435 | 527 | |
duke@435 | 528 | void ClassLoader::update_class_path_entry_list(const char *path, |
duke@435 | 529 | bool check_for_duplicates) { |
duke@435 | 530 | struct stat st; |
duke@435 | 531 | if (os::stat((char *)path, &st) == 0) { |
duke@435 | 532 | // File or directory found |
duke@435 | 533 | ClassPathEntry* new_entry = NULL; |
duke@435 | 534 | create_class_path_entry((char *)path, st, &new_entry, LazyBootClassLoader); |
duke@435 | 535 | // The kernel VM adds dynamically to the end of the classloader path and |
duke@435 | 536 | // doesn't reorder the bootclasspath which would break java.lang.Package |
duke@435 | 537 | // (see PackageInfo). |
duke@435 | 538 | // Add new entry to linked list |
duke@435 | 539 | if (!check_for_duplicates || !contains_entry(new_entry)) { |
duke@435 | 540 | add_to_list(new_entry); |
duke@435 | 541 | } |
duke@435 | 542 | } |
duke@435 | 543 | } |
duke@435 | 544 | |
duke@435 | 545 | void ClassLoader::print_bootclasspath() { |
duke@435 | 546 | ClassPathEntry* e = _first_entry; |
duke@435 | 547 | tty->print("[bootclasspath= "); |
duke@435 | 548 | while (e != NULL) { |
duke@435 | 549 | tty->print("%s ;", e->name()); |
duke@435 | 550 | e = e->next(); |
duke@435 | 551 | } |
duke@435 | 552 | tty->print_cr("]"); |
duke@435 | 553 | } |
duke@435 | 554 | |
duke@435 | 555 | void ClassLoader::load_zip_library() { |
duke@435 | 556 | assert(ZipOpen == NULL, "should not load zip library twice"); |
duke@435 | 557 | // First make sure native library is loaded |
duke@435 | 558 | os::native_java_library(); |
duke@435 | 559 | // Load zip library |
duke@435 | 560 | char path[JVM_MAXPATHLEN]; |
duke@435 | 561 | char ebuf[1024]; |
duke@435 | 562 | hpi::dll_build_name(path, sizeof(path), Arguments::get_dll_dir(), "zip"); |
duke@435 | 563 | void* handle = hpi::dll_load(path, ebuf, sizeof ebuf); |
duke@435 | 564 | if (handle == NULL) { |
duke@435 | 565 | vm_exit_during_initialization("Unable to load ZIP library", path); |
duke@435 | 566 | } |
duke@435 | 567 | // Lookup zip entry points |
duke@435 | 568 | ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, hpi::dll_lookup(handle, "ZIP_Open")); |
duke@435 | 569 | ZipClose = CAST_TO_FN_PTR(ZipClose_t, hpi::dll_lookup(handle, "ZIP_Close")); |
duke@435 | 570 | FindEntry = CAST_TO_FN_PTR(FindEntry_t, hpi::dll_lookup(handle, "ZIP_FindEntry")); |
duke@435 | 571 | ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, hpi::dll_lookup(handle, "ZIP_ReadEntry")); |
duke@435 | 572 | ReadMappedEntry = CAST_TO_FN_PTR(ReadMappedEntry_t, hpi::dll_lookup(handle, "ZIP_ReadMappedEntry")); |
duke@435 | 573 | GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, hpi::dll_lookup(handle, "ZIP_GetNextEntry")); |
duke@435 | 574 | |
duke@435 | 575 | // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL |
duke@435 | 576 | if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL || GetNextEntry == NULL) { |
duke@435 | 577 | vm_exit_during_initialization("Corrupted ZIP library", path); |
duke@435 | 578 | } |
duke@435 | 579 | |
duke@435 | 580 | // Lookup canonicalize entry in libjava.dll |
duke@435 | 581 | void *javalib_handle = os::native_java_library(); |
duke@435 | 582 | CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, hpi::dll_lookup(javalib_handle, "Canonicalize")); |
duke@435 | 583 | // This lookup only works on 1.3. Do not check for non-null here |
duke@435 | 584 | } |
duke@435 | 585 | |
duke@435 | 586 | // PackageInfo data exists in order to support the java.lang.Package |
duke@435 | 587 | // class. A Package object provides information about a java package |
duke@435 | 588 | // (version, vendor, etc.) which originates in the manifest of the jar |
duke@435 | 589 | // file supplying the package. For application classes, the ClassLoader |
duke@435 | 590 | // object takes care of this. |
duke@435 | 591 | |
duke@435 | 592 | // For system (boot) classes, the Java code in the Package class needs |
duke@435 | 593 | // to be able to identify which source jar file contained the boot |
duke@435 | 594 | // class, so that it can extract the manifest from it. This table |
duke@435 | 595 | // identifies java packages with jar files in the boot classpath. |
duke@435 | 596 | |
duke@435 | 597 | // Because the boot classpath cannot change, the classpath index is |
duke@435 | 598 | // sufficient to identify the source jar file or directory. (Since |
duke@435 | 599 | // directories have no manifests, the directory name is not required, |
duke@435 | 600 | // but is available.) |
duke@435 | 601 | |
duke@435 | 602 | // When using sharing -- the pathnames of entries in the boot classpath |
duke@435 | 603 | // may not be the same at runtime as they were when the archive was |
duke@435 | 604 | // created (NFS, Samba, etc.). The actual files and directories named |
duke@435 | 605 | // in the classpath must be the same files, in the same order, even |
duke@435 | 606 | // though the exact name is not the same. |
duke@435 | 607 | |
duke@435 | 608 | class PackageInfo: public BasicHashtableEntry { |
duke@435 | 609 | public: |
duke@435 | 610 | const char* _pkgname; // Package name |
duke@435 | 611 | int _classpath_index; // Index of directory or JAR file loaded from |
duke@435 | 612 | |
duke@435 | 613 | PackageInfo* next() { |
duke@435 | 614 | return (PackageInfo*)BasicHashtableEntry::next(); |
duke@435 | 615 | } |
duke@435 | 616 | |
duke@435 | 617 | const char* pkgname() { return _pkgname; } |
duke@435 | 618 | void set_pkgname(char* pkgname) { _pkgname = pkgname; } |
duke@435 | 619 | |
duke@435 | 620 | const char* filename() { |
duke@435 | 621 | return ClassLoader::classpath_entry(_classpath_index)->name(); |
duke@435 | 622 | } |
duke@435 | 623 | |
duke@435 | 624 | void set_index(int index) { |
duke@435 | 625 | _classpath_index = index; |
duke@435 | 626 | } |
duke@435 | 627 | }; |
duke@435 | 628 | |
duke@435 | 629 | |
duke@435 | 630 | class PackageHashtable : public BasicHashtable { |
duke@435 | 631 | private: |
duke@435 | 632 | inline unsigned int compute_hash(const char *s, int n) { |
duke@435 | 633 | unsigned int val = 0; |
duke@435 | 634 | while (--n >= 0) { |
duke@435 | 635 | val = *s++ + 31 * val; |
duke@435 | 636 | } |
duke@435 | 637 | return val; |
duke@435 | 638 | } |
duke@435 | 639 | |
duke@435 | 640 | PackageInfo* bucket(int index) { |
duke@435 | 641 | return (PackageInfo*)BasicHashtable::bucket(index); |
duke@435 | 642 | } |
duke@435 | 643 | |
duke@435 | 644 | PackageInfo* get_entry(int index, unsigned int hash, |
duke@435 | 645 | const char* pkgname, size_t n) { |
duke@435 | 646 | for (PackageInfo* pp = bucket(index); pp != NULL; pp = pp->next()) { |
duke@435 | 647 | if (pp->hash() == hash && |
duke@435 | 648 | strncmp(pkgname, pp->pkgname(), n) == 0 && |
duke@435 | 649 | pp->pkgname()[n] == '\0') { |
duke@435 | 650 | return pp; |
duke@435 | 651 | } |
duke@435 | 652 | } |
duke@435 | 653 | return NULL; |
duke@435 | 654 | } |
duke@435 | 655 | |
duke@435 | 656 | public: |
duke@435 | 657 | PackageHashtable(int table_size) |
duke@435 | 658 | : BasicHashtable(table_size, sizeof(PackageInfo)) {} |
duke@435 | 659 | |
duke@435 | 660 | PackageHashtable(int table_size, HashtableBucket* t, int number_of_entries) |
duke@435 | 661 | : BasicHashtable(table_size, sizeof(PackageInfo), t, number_of_entries) {} |
duke@435 | 662 | |
duke@435 | 663 | PackageInfo* get_entry(const char* pkgname, int n) { |
duke@435 | 664 | unsigned int hash = compute_hash(pkgname, n); |
duke@435 | 665 | return get_entry(hash_to_index(hash), hash, pkgname, n); |
duke@435 | 666 | } |
duke@435 | 667 | |
duke@435 | 668 | PackageInfo* new_entry(char* pkgname, int n) { |
duke@435 | 669 | unsigned int hash = compute_hash(pkgname, n); |
duke@435 | 670 | PackageInfo* pp; |
duke@435 | 671 | pp = (PackageInfo*)BasicHashtable::new_entry(hash); |
duke@435 | 672 | pp->set_pkgname(pkgname); |
duke@435 | 673 | return pp; |
duke@435 | 674 | } |
duke@435 | 675 | |
duke@435 | 676 | void add_entry(PackageInfo* pp) { |
duke@435 | 677 | int index = hash_to_index(pp->hash()); |
duke@435 | 678 | BasicHashtable::add_entry(index, pp); |
duke@435 | 679 | } |
duke@435 | 680 | |
duke@435 | 681 | void copy_pkgnames(const char** packages) { |
duke@435 | 682 | int n = 0; |
duke@435 | 683 | for (int i = 0; i < table_size(); ++i) { |
duke@435 | 684 | for (PackageInfo* pp = bucket(i); pp != NULL; pp = pp->next()) { |
duke@435 | 685 | packages[n++] = pp->pkgname(); |
duke@435 | 686 | } |
duke@435 | 687 | } |
duke@435 | 688 | assert(n == number_of_entries(), "just checking"); |
duke@435 | 689 | } |
duke@435 | 690 | |
duke@435 | 691 | void copy_table(char** top, char* end, PackageHashtable* table); |
duke@435 | 692 | }; |
duke@435 | 693 | |
duke@435 | 694 | |
duke@435 | 695 | void PackageHashtable::copy_table(char** top, char* end, |
duke@435 | 696 | PackageHashtable* table) { |
duke@435 | 697 | // Copy (relocate) the table to the shared space. |
duke@435 | 698 | BasicHashtable::copy_table(top, end); |
duke@435 | 699 | |
duke@435 | 700 | // Calculate the space needed for the package name strings. |
duke@435 | 701 | int i; |
duke@435 | 702 | int n = 0; |
duke@435 | 703 | for (i = 0; i < table_size(); ++i) { |
duke@435 | 704 | for (PackageInfo* pp = table->bucket(i); |
duke@435 | 705 | pp != NULL; |
duke@435 | 706 | pp = pp->next()) { |
duke@435 | 707 | n += (int)(strlen(pp->pkgname()) + 1); |
duke@435 | 708 | } |
duke@435 | 709 | } |
duke@435 | 710 | if (*top + n + sizeof(intptr_t) >= end) { |
duke@435 | 711 | warning("\nThe shared miscellaneous data space is not large " |
duke@435 | 712 | "enough to \npreload requested classes. Use " |
duke@435 | 713 | "-XX:SharedMiscDataSize= to increase \nthe initial " |
duke@435 | 714 | "size of the miscellaneous data space.\n"); |
duke@435 | 715 | exit(2); |
duke@435 | 716 | } |
duke@435 | 717 | |
duke@435 | 718 | // Copy the table data (the strings) to the shared space. |
duke@435 | 719 | n = align_size_up(n, sizeof(HeapWord)); |
duke@435 | 720 | *(intptr_t*)(*top) = n; |
duke@435 | 721 | *top += sizeof(intptr_t); |
duke@435 | 722 | |
duke@435 | 723 | for (i = 0; i < table_size(); ++i) { |
duke@435 | 724 | for (PackageInfo* pp = table->bucket(i); |
duke@435 | 725 | pp != NULL; |
duke@435 | 726 | pp = pp->next()) { |
duke@435 | 727 | int n1 = (int)(strlen(pp->pkgname()) + 1); |
duke@435 | 728 | pp->set_pkgname((char*)memcpy(*top, pp->pkgname(), n1)); |
duke@435 | 729 | *top += n1; |
duke@435 | 730 | } |
duke@435 | 731 | } |
duke@435 | 732 | *top = (char*)align_size_up((intptr_t)*top, sizeof(HeapWord)); |
duke@435 | 733 | } |
duke@435 | 734 | |
duke@435 | 735 | |
duke@435 | 736 | void ClassLoader::copy_package_info_buckets(char** top, char* end) { |
duke@435 | 737 | _package_hash_table->copy_buckets(top, end); |
duke@435 | 738 | } |
duke@435 | 739 | |
duke@435 | 740 | void ClassLoader::copy_package_info_table(char** top, char* end) { |
duke@435 | 741 | _package_hash_table->copy_table(top, end, _package_hash_table); |
duke@435 | 742 | } |
duke@435 | 743 | |
duke@435 | 744 | |
duke@435 | 745 | PackageInfo* ClassLoader::lookup_package(const char *pkgname) { |
duke@435 | 746 | const char *cp = strrchr(pkgname, '/'); |
duke@435 | 747 | if (cp != NULL) { |
duke@435 | 748 | // Package prefix found |
duke@435 | 749 | int n = cp - pkgname + 1; |
duke@435 | 750 | return _package_hash_table->get_entry(pkgname, n); |
duke@435 | 751 | } |
duke@435 | 752 | return NULL; |
duke@435 | 753 | } |
duke@435 | 754 | |
duke@435 | 755 | |
duke@435 | 756 | bool ClassLoader::add_package(const char *pkgname, int classpath_index, TRAPS) { |
duke@435 | 757 | assert(pkgname != NULL, "just checking"); |
duke@435 | 758 | // Bootstrap loader no longer holds system loader lock obj serializing |
duke@435 | 759 | // load_instance_class and thereby add_package |
duke@435 | 760 | { |
duke@435 | 761 | MutexLocker ml(PackageTable_lock, THREAD); |
duke@435 | 762 | // First check for previously loaded entry |
duke@435 | 763 | PackageInfo* pp = lookup_package(pkgname); |
duke@435 | 764 | if (pp != NULL) { |
duke@435 | 765 | // Existing entry found, check source of package |
duke@435 | 766 | pp->set_index(classpath_index); |
duke@435 | 767 | return true; |
duke@435 | 768 | } |
duke@435 | 769 | |
duke@435 | 770 | const char *cp = strrchr(pkgname, '/'); |
duke@435 | 771 | if (cp != NULL) { |
duke@435 | 772 | // Package prefix found |
duke@435 | 773 | int n = cp - pkgname + 1; |
duke@435 | 774 | |
duke@435 | 775 | char* new_pkgname = NEW_C_HEAP_ARRAY(char, n + 1); |
duke@435 | 776 | if (new_pkgname == NULL) { |
duke@435 | 777 | return false; |
duke@435 | 778 | } |
duke@435 | 779 | |
duke@435 | 780 | memcpy(new_pkgname, pkgname, n); |
duke@435 | 781 | new_pkgname[n] = '\0'; |
duke@435 | 782 | pp = _package_hash_table->new_entry(new_pkgname, n); |
duke@435 | 783 | pp->set_index(classpath_index); |
duke@435 | 784 | |
duke@435 | 785 | // Insert into hash table |
duke@435 | 786 | _package_hash_table->add_entry(pp); |
duke@435 | 787 | } |
duke@435 | 788 | return true; |
duke@435 | 789 | } |
duke@435 | 790 | } |
duke@435 | 791 | |
duke@435 | 792 | |
duke@435 | 793 | oop ClassLoader::get_system_package(const char* name, TRAPS) { |
duke@435 | 794 | PackageInfo* pp; |
duke@435 | 795 | { |
duke@435 | 796 | MutexLocker ml(PackageTable_lock, THREAD); |
duke@435 | 797 | pp = lookup_package(name); |
duke@435 | 798 | } |
duke@435 | 799 | if (pp == NULL) { |
duke@435 | 800 | return NULL; |
duke@435 | 801 | } else { |
duke@435 | 802 | Handle p = java_lang_String::create_from_str(pp->filename(), THREAD); |
duke@435 | 803 | return p(); |
duke@435 | 804 | } |
duke@435 | 805 | } |
duke@435 | 806 | |
duke@435 | 807 | |
duke@435 | 808 | objArrayOop ClassLoader::get_system_packages(TRAPS) { |
duke@435 | 809 | ResourceMark rm(THREAD); |
duke@435 | 810 | int nof_entries; |
duke@435 | 811 | const char** packages; |
duke@435 | 812 | { |
duke@435 | 813 | MutexLocker ml(PackageTable_lock, THREAD); |
duke@435 | 814 | // Allocate resource char* array containing package names |
duke@435 | 815 | nof_entries = _package_hash_table->number_of_entries(); |
duke@435 | 816 | if ((packages = NEW_RESOURCE_ARRAY(const char*, nof_entries)) == NULL) { |
duke@435 | 817 | return NULL; |
duke@435 | 818 | } |
duke@435 | 819 | _package_hash_table->copy_pkgnames(packages); |
duke@435 | 820 | } |
duke@435 | 821 | // Allocate objArray and fill with java.lang.String |
never@1577 | 822 | objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), |
duke@435 | 823 | nof_entries, CHECK_0); |
duke@435 | 824 | objArrayHandle result(THREAD, r); |
duke@435 | 825 | for (int i = 0; i < nof_entries; i++) { |
duke@435 | 826 | Handle str = java_lang_String::create_from_str(packages[i], CHECK_0); |
duke@435 | 827 | result->obj_at_put(i, str()); |
duke@435 | 828 | } |
duke@435 | 829 | |
duke@435 | 830 | return result(); |
duke@435 | 831 | } |
duke@435 | 832 | |
duke@435 | 833 | |
duke@435 | 834 | instanceKlassHandle ClassLoader::load_classfile(symbolHandle h_name, TRAPS) { |
duke@435 | 835 | ResourceMark rm(THREAD); |
duke@435 | 836 | EventMark m("loading class " INTPTR_FORMAT, (address)h_name()); |
duke@435 | 837 | ThreadProfilerMark tpm(ThreadProfilerMark::classLoaderRegion); |
duke@435 | 838 | |
duke@435 | 839 | stringStream st; |
duke@435 | 840 | // st.print() uses too much stack space while handling a StackOverflowError |
duke@435 | 841 | // st.print("%s.class", h_name->as_utf8()); |
duke@435 | 842 | st.print_raw(h_name->as_utf8()); |
duke@435 | 843 | st.print_raw(".class"); |
duke@435 | 844 | char* name = st.as_string(); |
duke@435 | 845 | |
duke@435 | 846 | // Lookup stream for parsing .class file |
duke@435 | 847 | ClassFileStream* stream = NULL; |
duke@435 | 848 | int classpath_index = 0; |
duke@435 | 849 | { |
mchung@1310 | 850 | PerfClassTraceTime vmtimer(perf_sys_class_lookup_time(), |
mchung@1310 | 851 | ((JavaThread*) THREAD)->get_thread_stat()->perf_timers_addr(), |
mchung@1310 | 852 | PerfClassTraceTime::CLASS_LOAD); |
duke@435 | 853 | ClassPathEntry* e = _first_entry; |
duke@435 | 854 | while (e != NULL) { |
duke@435 | 855 | stream = e->open_stream(name); |
duke@435 | 856 | if (stream != NULL) { |
duke@435 | 857 | break; |
duke@435 | 858 | } |
duke@435 | 859 | e = e->next(); |
duke@435 | 860 | ++classpath_index; |
duke@435 | 861 | } |
duke@435 | 862 | } |
duke@435 | 863 | |
duke@435 | 864 | instanceKlassHandle h(THREAD, klassOop(NULL)); |
duke@435 | 865 | if (stream != NULL) { |
duke@435 | 866 | |
duke@435 | 867 | // class file found, parse it |
duke@435 | 868 | ClassFileParser parser(stream); |
duke@435 | 869 | Handle class_loader; |
duke@435 | 870 | Handle protection_domain; |
duke@435 | 871 | symbolHandle parsed_name; |
duke@435 | 872 | instanceKlassHandle result = parser.parseClassFile(h_name, |
duke@435 | 873 | class_loader, |
duke@435 | 874 | protection_domain, |
duke@435 | 875 | parsed_name, |
acorn@1408 | 876 | false, |
duke@435 | 877 | CHECK_(h)); |
duke@435 | 878 | |
duke@435 | 879 | // add to package table |
duke@435 | 880 | if (add_package(name, classpath_index, THREAD)) { |
duke@435 | 881 | h = result; |
duke@435 | 882 | } |
duke@435 | 883 | } |
duke@435 | 884 | |
duke@435 | 885 | return h; |
duke@435 | 886 | } |
duke@435 | 887 | |
duke@435 | 888 | |
duke@435 | 889 | void ClassLoader::create_package_info_table(HashtableBucket *t, int length, |
duke@435 | 890 | int number_of_entries) { |
duke@435 | 891 | assert(_package_hash_table == NULL, "One package info table allowed."); |
duke@435 | 892 | assert(length == package_hash_table_size * sizeof(HashtableBucket), |
duke@435 | 893 | "bad shared package info size."); |
duke@435 | 894 | _package_hash_table = new PackageHashtable(package_hash_table_size, t, |
duke@435 | 895 | number_of_entries); |
duke@435 | 896 | } |
duke@435 | 897 | |
duke@435 | 898 | |
duke@435 | 899 | void ClassLoader::create_package_info_table() { |
duke@435 | 900 | assert(_package_hash_table == NULL, "shouldn't have one yet"); |
duke@435 | 901 | _package_hash_table = new PackageHashtable(package_hash_table_size); |
duke@435 | 902 | } |
duke@435 | 903 | |
duke@435 | 904 | |
duke@435 | 905 | // Initialize the class loader's access to methods in libzip. Parse and |
duke@435 | 906 | // process the boot classpath into a list ClassPathEntry objects. Once |
duke@435 | 907 | // this list has been created, it must not change order (see class PackageInfo) |
duke@435 | 908 | // it can be appended to and is by jvmti and the kernel vm. |
duke@435 | 909 | |
duke@435 | 910 | void ClassLoader::initialize() { |
duke@435 | 911 | assert(_package_hash_table == NULL, "should have been initialized by now."); |
duke@435 | 912 | EXCEPTION_MARK; |
duke@435 | 913 | |
duke@435 | 914 | if (UsePerfData) { |
duke@435 | 915 | // jvmstat performance counters |
duke@435 | 916 | NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time"); |
duke@435 | 917 | NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime"); |
mchung@1310 | 918 | NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self"); |
duke@435 | 919 | NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime"); |
mchung@1310 | 920 | NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self"); |
duke@435 | 921 | NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime"); |
mchung@1310 | 922 | NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self"); |
duke@435 | 923 | NEWPERFEVENTCOUNTER(_perf_classes_inited, SUN_CLS, "initializedClasses"); |
duke@435 | 924 | NEWPERFEVENTCOUNTER(_perf_classes_linked, SUN_CLS, "linkedClasses"); |
mchung@1310 | 925 | NEWPERFEVENTCOUNTER(_perf_classes_verified, SUN_CLS, "verifiedClasses"); |
mchung@1310 | 926 | |
mchung@1310 | 927 | NEWPERFTICKCOUNTER(_perf_class_parse_time, SUN_CLS, "parseClassTime"); |
mchung@1310 | 928 | NEWPERFTICKCOUNTER(_perf_class_parse_selftime, SUN_CLS, "parseClassTime.self"); |
mchung@1310 | 929 | NEWPERFTICKCOUNTER(_perf_sys_class_lookup_time, SUN_CLS, "lookupSysClassTime"); |
mchung@1310 | 930 | NEWPERFTICKCOUNTER(_perf_shared_classload_time, SUN_CLS, "sharedClassLoadTime"); |
mchung@1310 | 931 | NEWPERFTICKCOUNTER(_perf_sys_classload_time, SUN_CLS, "sysClassLoadTime"); |
mchung@1310 | 932 | NEWPERFTICKCOUNTER(_perf_app_classload_time, SUN_CLS, "appClassLoadTime"); |
mchung@1310 | 933 | NEWPERFTICKCOUNTER(_perf_app_classload_selftime, SUN_CLS, "appClassLoadTime.self"); |
mchung@1310 | 934 | NEWPERFEVENTCOUNTER(_perf_app_classload_count, SUN_CLS, "appClassLoadCount"); |
mchung@1310 | 935 | NEWPERFTICKCOUNTER(_perf_define_appclasses, SUN_CLS, "defineAppClasses"); |
mchung@1310 | 936 | NEWPERFTICKCOUNTER(_perf_define_appclass_time, SUN_CLS, "defineAppClassTime"); |
mchung@1310 | 937 | NEWPERFTICKCOUNTER(_perf_define_appclass_selftime, SUN_CLS, "defineAppClassTime.self"); |
mchung@1310 | 938 | NEWPERFBYTECOUNTER(_perf_app_classfile_bytes_read, SUN_CLS, "appClassBytes"); |
mchung@1310 | 939 | NEWPERFBYTECOUNTER(_perf_sys_classfile_bytes_read, SUN_CLS, "sysClassBytes"); |
mchung@1310 | 940 | |
duke@435 | 941 | |
duke@435 | 942 | // The following performance counters are added for measuring the impact |
duke@435 | 943 | // of the bug fix of 6365597. They are mainly focused on finding out |
duke@435 | 944 | // the behavior of system & user-defined classloader lock, whether |
duke@435 | 945 | // ClassLoader.loadClass/findClass is being called synchronized or not. |
duke@435 | 946 | // Also two additional counters are created to see whether 'UnsyncloadClass' |
duke@435 | 947 | // flag is being set or not and how many times load_instance_class call |
duke@435 | 948 | // fails with linkageError etc. |
duke@435 | 949 | NEWPERFEVENTCOUNTER(_sync_systemLoaderLockContentionRate, SUN_CLS, |
duke@435 | 950 | "systemLoaderLockContentionRate"); |
duke@435 | 951 | NEWPERFEVENTCOUNTER(_sync_nonSystemLoaderLockContentionRate, SUN_CLS, |
duke@435 | 952 | "nonSystemLoaderLockContentionRate"); |
duke@435 | 953 | NEWPERFEVENTCOUNTER(_sync_JVMFindLoadedClassLockFreeCounter, SUN_CLS, |
duke@435 | 954 | "jvmFindLoadedClassNoLockCalls"); |
duke@435 | 955 | NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS, |
duke@435 | 956 | "jvmDefineClassNoLockCalls"); |
duke@435 | 957 | |
duke@435 | 958 | NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS, |
duke@435 | 959 | "jniDefineClassNoLockCalls"); |
duke@435 | 960 | |
duke@435 | 961 | NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS, |
duke@435 | 962 | "unsafeDefineClassCalls"); |
duke@435 | 963 | |
duke@435 | 964 | NEWPERFEVENTCOUNTER(_isUnsyncloadClass, SUN_CLS, "isUnsyncloadClassSet"); |
duke@435 | 965 | NEWPERFEVENTCOUNTER(_load_instance_class_failCounter, SUN_CLS, |
duke@435 | 966 | "loadInstanceClassFailRate"); |
duke@435 | 967 | |
duke@435 | 968 | // increment the isUnsyncloadClass counter if UnsyncloadClass is set. |
duke@435 | 969 | if (UnsyncloadClass) { |
duke@435 | 970 | _isUnsyncloadClass->inc(); |
duke@435 | 971 | } |
duke@435 | 972 | } |
duke@435 | 973 | |
duke@435 | 974 | // lookup zip library entry points |
duke@435 | 975 | load_zip_library(); |
duke@435 | 976 | // initialize search path |
duke@435 | 977 | setup_bootstrap_search_path(); |
duke@435 | 978 | if (LazyBootClassLoader) { |
duke@435 | 979 | // set up meta index which makes boot classpath initialization lazier |
duke@435 | 980 | setup_meta_index(); |
duke@435 | 981 | } |
duke@435 | 982 | } |
duke@435 | 983 | |
duke@435 | 984 | |
duke@435 | 985 | jlong ClassLoader::classloader_time_ms() { |
duke@435 | 986 | return UsePerfData ? |
duke@435 | 987 | Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1; |
duke@435 | 988 | } |
duke@435 | 989 | |
duke@435 | 990 | jlong ClassLoader::class_init_count() { |
duke@435 | 991 | return UsePerfData ? _perf_classes_inited->get_value() : -1; |
duke@435 | 992 | } |
duke@435 | 993 | |
duke@435 | 994 | jlong ClassLoader::class_init_time_ms() { |
duke@435 | 995 | return UsePerfData ? |
duke@435 | 996 | Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1; |
duke@435 | 997 | } |
duke@435 | 998 | |
duke@435 | 999 | jlong ClassLoader::class_verify_time_ms() { |
duke@435 | 1000 | return UsePerfData ? |
duke@435 | 1001 | Management::ticks_to_ms(_perf_class_verify_time->get_value()) : -1; |
duke@435 | 1002 | } |
duke@435 | 1003 | |
duke@435 | 1004 | jlong ClassLoader::class_link_count() { |
duke@435 | 1005 | return UsePerfData ? _perf_classes_linked->get_value() : -1; |
duke@435 | 1006 | } |
duke@435 | 1007 | |
duke@435 | 1008 | jlong ClassLoader::class_link_time_ms() { |
duke@435 | 1009 | return UsePerfData ? |
duke@435 | 1010 | Management::ticks_to_ms(_perf_class_link_time->get_value()) : -1; |
duke@435 | 1011 | } |
duke@435 | 1012 | |
duke@435 | 1013 | int ClassLoader::compute_Object_vtable() { |
duke@435 | 1014 | // hardwired for JDK1.2 -- would need to duplicate class file parsing |
duke@435 | 1015 | // code to determine actual value from file |
duke@435 | 1016 | // Would be value '11' if finals were in vtable |
duke@435 | 1017 | int JDK_1_2_Object_vtable_size = 5; |
duke@435 | 1018 | return JDK_1_2_Object_vtable_size * vtableEntry::size(); |
duke@435 | 1019 | } |
duke@435 | 1020 | |
duke@435 | 1021 | |
duke@435 | 1022 | void classLoader_init() { |
duke@435 | 1023 | ClassLoader::initialize(); |
duke@435 | 1024 | } |
duke@435 | 1025 | |
duke@435 | 1026 | |
duke@435 | 1027 | bool ClassLoader::get_canonical_path(char* orig, char* out, int len) { |
duke@435 | 1028 | assert(orig != NULL && out != NULL && len > 0, "bad arguments"); |
duke@435 | 1029 | if (CanonicalizeEntry != NULL) { |
duke@435 | 1030 | JNIEnv* env = JavaThread::current()->jni_environment(); |
duke@435 | 1031 | if ((CanonicalizeEntry)(env, hpi::native_path(orig), out, len) < 0) { |
duke@435 | 1032 | return false; |
duke@435 | 1033 | } |
duke@435 | 1034 | } else { |
duke@435 | 1035 | // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing |
duke@435 | 1036 | strncpy(out, orig, len); |
duke@435 | 1037 | out[len - 1] = '\0'; |
duke@435 | 1038 | } |
duke@435 | 1039 | return true; |
duke@435 | 1040 | } |
duke@435 | 1041 | |
duke@435 | 1042 | #ifndef PRODUCT |
duke@435 | 1043 | |
duke@435 | 1044 | void ClassLoader::verify() { |
duke@435 | 1045 | _package_hash_table->verify(); |
duke@435 | 1046 | } |
duke@435 | 1047 | |
duke@435 | 1048 | |
duke@435 | 1049 | // CompileTheWorld |
duke@435 | 1050 | // |
duke@435 | 1051 | // Iterates over all class path entries and forces compilation of all methods |
duke@435 | 1052 | // in all classes found. Currently, only zip/jar archives are searched. |
duke@435 | 1053 | // |
duke@435 | 1054 | // The classes are loaded by the Java level bootstrap class loader, and the |
duke@435 | 1055 | // initializer is called. If DelayCompilationDuringStartup is true (default), |
duke@435 | 1056 | // the interpreter will run the initialization code. Note that forcing |
duke@435 | 1057 | // initialization in this way could potentially lead to initialization order |
duke@435 | 1058 | // problems, in which case we could just force the initialization bit to be set. |
duke@435 | 1059 | |
duke@435 | 1060 | |
duke@435 | 1061 | // We need to iterate over the contents of a zip/jar file, so we replicate the |
duke@435 | 1062 | // jzcell and jzfile definitions from zip_util.h but rename jzfile to real_jzfile, |
duke@435 | 1063 | // since jzfile already has a void* definition. |
duke@435 | 1064 | // |
duke@435 | 1065 | // Note that this is only used in debug mode. |
duke@435 | 1066 | // |
duke@435 | 1067 | // HotSpot integration note: |
duke@435 | 1068 | // Matches zip_util.h 1.14 99/06/01 from jdk1.3 beta H build |
duke@435 | 1069 | |
duke@435 | 1070 | |
duke@435 | 1071 | // JDK 1.3 version |
duke@435 | 1072 | typedef struct real_jzentry13 { /* Zip file entry */ |
duke@435 | 1073 | char *name; /* entry name */ |
duke@435 | 1074 | jint time; /* modification time */ |
duke@435 | 1075 | jint size; /* size of uncompressed data */ |
duke@435 | 1076 | jint csize; /* size of compressed data (zero if uncompressed) */ |
duke@435 | 1077 | jint crc; /* crc of uncompressed data */ |
duke@435 | 1078 | char *comment; /* optional zip file comment */ |
duke@435 | 1079 | jbyte *extra; /* optional extra data */ |
duke@435 | 1080 | jint pos; /* position of LOC header (if negative) or data */ |
duke@435 | 1081 | } real_jzentry13; |
duke@435 | 1082 | |
duke@435 | 1083 | typedef struct real_jzfile13 { /* Zip file */ |
duke@435 | 1084 | char *name; /* zip file name */ |
duke@435 | 1085 | jint refs; /* number of active references */ |
duke@435 | 1086 | jint fd; /* open file descriptor */ |
duke@435 | 1087 | void *lock; /* read lock */ |
duke@435 | 1088 | char *comment; /* zip file comment */ |
duke@435 | 1089 | char *msg; /* zip error message */ |
duke@435 | 1090 | void *entries; /* array of hash cells */ |
duke@435 | 1091 | jint total; /* total number of entries */ |
duke@435 | 1092 | unsigned short *table; /* Hash chain heads: indexes into entries */ |
duke@435 | 1093 | jint tablelen; /* number of hash eads */ |
duke@435 | 1094 | real_jzfile13 *next; /* next zip file in search list */ |
duke@435 | 1095 | jzentry *cache; /* we cache the most recently freed jzentry */ |
duke@435 | 1096 | /* Information on metadata names in META-INF directory */ |
duke@435 | 1097 | char **metanames; /* array of meta names (may have null names) */ |
duke@435 | 1098 | jint metacount; /* number of slots in metanames array */ |
duke@435 | 1099 | /* If there are any per-entry comments, they are in the comments array */ |
duke@435 | 1100 | char **comments; |
duke@435 | 1101 | } real_jzfile13; |
duke@435 | 1102 | |
duke@435 | 1103 | // JDK 1.2 version |
duke@435 | 1104 | typedef struct real_jzentry12 { /* Zip file entry */ |
duke@435 | 1105 | char *name; /* entry name */ |
duke@435 | 1106 | jint time; /* modification time */ |
duke@435 | 1107 | jint size; /* size of uncompressed data */ |
duke@435 | 1108 | jint csize; /* size of compressed data (zero if uncompressed) */ |
duke@435 | 1109 | jint crc; /* crc of uncompressed data */ |
duke@435 | 1110 | char *comment; /* optional zip file comment */ |
duke@435 | 1111 | jbyte *extra; /* optional extra data */ |
duke@435 | 1112 | jint pos; /* position of LOC header (if negative) or data */ |
duke@435 | 1113 | struct real_jzentry12 *next; /* next entry in hash table */ |
duke@435 | 1114 | } real_jzentry12; |
duke@435 | 1115 | |
duke@435 | 1116 | typedef struct real_jzfile12 { /* Zip file */ |
duke@435 | 1117 | char *name; /* zip file name */ |
duke@435 | 1118 | jint refs; /* number of active references */ |
duke@435 | 1119 | jint fd; /* open file descriptor */ |
duke@435 | 1120 | void *lock; /* read lock */ |
duke@435 | 1121 | char *comment; /* zip file comment */ |
duke@435 | 1122 | char *msg; /* zip error message */ |
duke@435 | 1123 | real_jzentry12 *entries; /* array of zip entries */ |
duke@435 | 1124 | jint total; /* total number of entries */ |
duke@435 | 1125 | real_jzentry12 **table; /* hash table of entries */ |
duke@435 | 1126 | jint tablelen; /* number of buckets */ |
duke@435 | 1127 | jzfile *next; /* next zip file in search list */ |
duke@435 | 1128 | } real_jzfile12; |
duke@435 | 1129 | |
duke@435 | 1130 | |
duke@435 | 1131 | void ClassPathDirEntry::compile_the_world(Handle loader, TRAPS) { |
duke@435 | 1132 | // For now we only compile all methods in all classes in zip/jar files |
duke@435 | 1133 | tty->print_cr("CompileTheWorld : Skipped classes in %s", _dir); |
duke@435 | 1134 | tty->cr(); |
duke@435 | 1135 | } |
duke@435 | 1136 | |
duke@435 | 1137 | |
duke@435 | 1138 | bool ClassPathDirEntry::is_rt_jar() { |
duke@435 | 1139 | return false; |
duke@435 | 1140 | } |
duke@435 | 1141 | |
duke@435 | 1142 | void ClassPathZipEntry::compile_the_world(Handle loader, TRAPS) { |
duke@435 | 1143 | if (JDK_Version::is_jdk12x_version()) { |
duke@435 | 1144 | compile_the_world12(loader, THREAD); |
duke@435 | 1145 | } else { |
duke@435 | 1146 | compile_the_world13(loader, THREAD); |
duke@435 | 1147 | } |
duke@435 | 1148 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1149 | if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) { |
duke@435 | 1150 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1151 | tty->print_cr("\nCompileTheWorld : Ran out of memory\n"); |
duke@435 | 1152 | size_t used = Universe::heap()->permanent_used(); |
duke@435 | 1153 | size_t capacity = Universe::heap()->permanent_capacity(); |
duke@435 | 1154 | tty->print_cr("Permanent generation used %dK of %dK", used/K, capacity/K); |
duke@435 | 1155 | tty->print_cr("Increase size by setting e.g. -XX:MaxPermSize=%dK\n", capacity*2/K); |
duke@435 | 1156 | } else { |
duke@435 | 1157 | tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n"); |
duke@435 | 1158 | } |
duke@435 | 1159 | } |
duke@435 | 1160 | } |
duke@435 | 1161 | |
duke@435 | 1162 | // Version that works for JDK 1.3.x |
duke@435 | 1163 | void ClassPathZipEntry::compile_the_world13(Handle loader, TRAPS) { |
duke@435 | 1164 | real_jzfile13* zip = (real_jzfile13*) _zip; |
duke@435 | 1165 | tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name); |
duke@435 | 1166 | tty->cr(); |
duke@435 | 1167 | // Iterate over all entries in zip file |
duke@435 | 1168 | for (int n = 0; ; n++) { |
duke@435 | 1169 | real_jzentry13 * ze = (real_jzentry13 *)((*GetNextEntry)(_zip, n)); |
duke@435 | 1170 | if (ze == NULL) break; |
duke@435 | 1171 | ClassLoader::compile_the_world_in(ze->name, loader, CHECK); |
duke@435 | 1172 | } |
duke@435 | 1173 | } |
duke@435 | 1174 | |
duke@435 | 1175 | |
duke@435 | 1176 | // Version that works for JDK 1.2.x |
duke@435 | 1177 | void ClassPathZipEntry::compile_the_world12(Handle loader, TRAPS) { |
duke@435 | 1178 | real_jzfile12* zip = (real_jzfile12*) _zip; |
duke@435 | 1179 | tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name); |
duke@435 | 1180 | tty->cr(); |
duke@435 | 1181 | // Iterate over all entries in zip file |
duke@435 | 1182 | for (int n = 0; ; n++) { |
duke@435 | 1183 | real_jzentry12 * ze = (real_jzentry12 *)((*GetNextEntry)(_zip, n)); |
duke@435 | 1184 | if (ze == NULL) break; |
duke@435 | 1185 | ClassLoader::compile_the_world_in(ze->name, loader, CHECK); |
duke@435 | 1186 | } |
duke@435 | 1187 | } |
duke@435 | 1188 | |
duke@435 | 1189 | bool ClassPathZipEntry::is_rt_jar() { |
duke@435 | 1190 | if (JDK_Version::is_jdk12x_version()) { |
duke@435 | 1191 | return is_rt_jar12(); |
duke@435 | 1192 | } else { |
duke@435 | 1193 | return is_rt_jar13(); |
duke@435 | 1194 | } |
duke@435 | 1195 | } |
duke@435 | 1196 | |
duke@435 | 1197 | // JDK 1.3 version |
duke@435 | 1198 | bool ClassPathZipEntry::is_rt_jar13() { |
duke@435 | 1199 | real_jzfile13* zip = (real_jzfile13*) _zip; |
duke@435 | 1200 | int len = (int)strlen(zip->name); |
duke@435 | 1201 | // Check whether zip name ends in "rt.jar" |
duke@435 | 1202 | // This will match other archives named rt.jar as well, but this is |
duke@435 | 1203 | // only used for debugging. |
duke@435 | 1204 | return (len >= 6) && (strcasecmp(zip->name + len - 6, "rt.jar") == 0); |
duke@435 | 1205 | } |
duke@435 | 1206 | |
duke@435 | 1207 | // JDK 1.2 version |
duke@435 | 1208 | bool ClassPathZipEntry::is_rt_jar12() { |
duke@435 | 1209 | real_jzfile12* zip = (real_jzfile12*) _zip; |
duke@435 | 1210 | int len = (int)strlen(zip->name); |
duke@435 | 1211 | // Check whether zip name ends in "rt.jar" |
duke@435 | 1212 | // This will match other archives named rt.jar as well, but this is |
duke@435 | 1213 | // only used for debugging. |
duke@435 | 1214 | return (len >= 6) && (strcasecmp(zip->name + len - 6, "rt.jar") == 0); |
duke@435 | 1215 | } |
duke@435 | 1216 | |
duke@435 | 1217 | void LazyClassPathEntry::compile_the_world(Handle loader, TRAPS) { |
duke@435 | 1218 | resolve_entry()->compile_the_world(loader, CHECK); |
duke@435 | 1219 | } |
duke@435 | 1220 | |
duke@435 | 1221 | bool LazyClassPathEntry::is_rt_jar() { |
duke@435 | 1222 | return resolve_entry()->is_rt_jar(); |
duke@435 | 1223 | } |
duke@435 | 1224 | |
duke@435 | 1225 | void ClassLoader::compile_the_world() { |
duke@435 | 1226 | EXCEPTION_MARK; |
duke@435 | 1227 | HandleMark hm(THREAD); |
duke@435 | 1228 | ResourceMark rm(THREAD); |
duke@435 | 1229 | // Make sure we don't run with background compilation |
duke@435 | 1230 | BackgroundCompilation = false; |
duke@435 | 1231 | // Find bootstrap loader |
duke@435 | 1232 | Handle system_class_loader (THREAD, SystemDictionary::java_system_loader()); |
duke@435 | 1233 | // Iterate over all bootstrap class path entries |
duke@435 | 1234 | ClassPathEntry* e = _first_entry; |
duke@435 | 1235 | while (e != NULL) { |
duke@435 | 1236 | // We stop at rt.jar, unless it is the first bootstrap path entry |
duke@435 | 1237 | if (e->is_rt_jar() && e != _first_entry) break; |
duke@435 | 1238 | e->compile_the_world(system_class_loader, CATCH); |
duke@435 | 1239 | e = e->next(); |
duke@435 | 1240 | } |
duke@435 | 1241 | tty->print_cr("CompileTheWorld : Done"); |
duke@435 | 1242 | { |
duke@435 | 1243 | // Print statistics as if before normal exit: |
duke@435 | 1244 | extern void print_statistics(); |
duke@435 | 1245 | print_statistics(); |
duke@435 | 1246 | } |
duke@435 | 1247 | vm_exit(0); |
duke@435 | 1248 | } |
duke@435 | 1249 | |
duke@435 | 1250 | int ClassLoader::_compile_the_world_counter = 0; |
kvn@1623 | 1251 | static int _codecache_sweep_counter = 0; |
duke@435 | 1252 | |
duke@435 | 1253 | void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { |
duke@435 | 1254 | int len = (int)strlen(name); |
duke@435 | 1255 | if (len > 6 && strcmp(".class", name + len - 6) == 0) { |
duke@435 | 1256 | // We have a .class file |
duke@435 | 1257 | char buffer[2048]; |
duke@435 | 1258 | strncpy(buffer, name, len - 6); |
duke@435 | 1259 | buffer[len-6] = 0; |
duke@435 | 1260 | // If the file has a period after removing .class, it's not really a |
duke@435 | 1261 | // valid class file. The class loader will check everything else. |
duke@435 | 1262 | if (strchr(buffer, '.') == NULL) { |
duke@435 | 1263 | _compile_the_world_counter++; |
never@1158 | 1264 | if (_compile_the_world_counter > CompileTheWorldStopAt) return; |
never@1158 | 1265 | |
never@1158 | 1266 | // Construct name without extension |
never@1158 | 1267 | symbolHandle sym = oopFactory::new_symbol_handle(buffer, CHECK); |
never@1158 | 1268 | // Use loader to load and initialize class |
never@1158 | 1269 | klassOop ik = SystemDictionary::resolve_or_null(sym, loader, Handle(), THREAD); |
never@1158 | 1270 | instanceKlassHandle k (THREAD, ik); |
never@1158 | 1271 | if (k.not_null() && !HAS_PENDING_EXCEPTION) { |
never@1158 | 1272 | k->initialize(THREAD); |
never@1158 | 1273 | } |
never@1158 | 1274 | bool exception_occurred = HAS_PENDING_EXCEPTION; |
never@1158 | 1275 | CLEAR_PENDING_EXCEPTION; |
never@1158 | 1276 | if (CompileTheWorldPreloadClasses && k.not_null()) { |
never@1158 | 1277 | constantPoolKlass::preload_and_initialize_all_classes(k->constants(), THREAD); |
never@1158 | 1278 | if (HAS_PENDING_EXCEPTION) { |
never@1158 | 1279 | // If something went wrong in preloading we just ignore it |
never@1158 | 1280 | CLEAR_PENDING_EXCEPTION; |
never@1158 | 1281 | tty->print_cr("Preloading failed for (%d) %s", _compile_the_world_counter, buffer); |
duke@435 | 1282 | } |
never@1158 | 1283 | } |
never@1158 | 1284 | |
never@1158 | 1285 | if (_compile_the_world_counter >= CompileTheWorldStartAt) { |
duke@435 | 1286 | if (k.is_null() || (exception_occurred && !CompileTheWorldIgnoreInitErrors)) { |
duke@435 | 1287 | // If something went wrong (e.g. ExceptionInInitializerError) we skip this class |
duke@435 | 1288 | tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_counter, buffer); |
duke@435 | 1289 | } else { |
duke@435 | 1290 | tty->print_cr("CompileTheWorld (%d) : %s", _compile_the_world_counter, buffer); |
duke@435 | 1291 | // Preload all classes to get around uncommon traps |
duke@435 | 1292 | // Iterate over all methods in class |
duke@435 | 1293 | for (int n = 0; n < k->methods()->length(); n++) { |
duke@435 | 1294 | methodHandle m (THREAD, methodOop(k->methods()->obj_at(n))); |
duke@435 | 1295 | if (CompilationPolicy::canBeCompiled(m)) { |
kvn@1623 | 1296 | |
kvn@1623 | 1297 | if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) { |
kvn@1623 | 1298 | // Give sweeper a chance to keep up with CTW |
kvn@1623 | 1299 | VM_ForceSafepoint op; |
kvn@1623 | 1300 | VMThread::execute(&op); |
kvn@1623 | 1301 | _codecache_sweep_counter = 0; |
kvn@1623 | 1302 | } |
duke@435 | 1303 | // Force compilation |
duke@435 | 1304 | CompileBroker::compile_method(m, InvocationEntryBci, |
duke@435 | 1305 | methodHandle(), 0, "CTW", THREAD); |
duke@435 | 1306 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1307 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1308 | tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_counter, m->name()->as_C_string()); |
duke@435 | 1309 | } |
never@1158 | 1310 | if (TieredCompilation) { |
never@1158 | 1311 | // Clobber the first compile and force second tier compilation |
never@1158 | 1312 | nmethod* nm = m->code(); |
never@1158 | 1313 | if (nm != NULL) { |
never@1158 | 1314 | // Throw out the code so that the code cache doesn't fill up |
never@1158 | 1315 | nm->make_not_entrant(); |
never@1158 | 1316 | m->clear_code(); |
never@1158 | 1317 | } |
never@1158 | 1318 | CompileBroker::compile_method(m, InvocationEntryBci, |
never@1158 | 1319 | methodHandle(), 0, "CTW", THREAD); |
never@1158 | 1320 | if (HAS_PENDING_EXCEPTION) { |
never@1158 | 1321 | CLEAR_PENDING_EXCEPTION; |
never@1158 | 1322 | tty->print_cr("CompileTheWorld (%d) : Skipping method: %s", _compile_the_world_counter, m->name()->as_C_string()); |
never@1158 | 1323 | } |
duke@435 | 1324 | } |
duke@435 | 1325 | } |
never@1158 | 1326 | |
never@1158 | 1327 | nmethod* nm = m->code(); |
never@1158 | 1328 | if (nm != NULL) { |
never@1158 | 1329 | // Throw out the code so that the code cache doesn't fill up |
never@1158 | 1330 | nm->make_not_entrant(); |
never@1158 | 1331 | m->clear_code(); |
duke@435 | 1332 | } |
duke@435 | 1333 | } |
duke@435 | 1334 | } |
duke@435 | 1335 | } |
duke@435 | 1336 | } |
duke@435 | 1337 | } |
duke@435 | 1338 | } |
duke@435 | 1339 | |
duke@435 | 1340 | #endif //PRODUCT |