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