src/share/vm/classfile/classLoader.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File bug_8068687_metaindex.2 Sdiff src/share/vm/classfile

src/share/vm/classfile/classLoader.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 135 // helper routines
 136 bool string_starts_with(const char* str, const char* str_to_find) {
 137   size_t str_len = strlen(str);
 138   size_t str_to_find_len = strlen(str_to_find);
 139   if (str_to_find_len > str_len) {
 140     return false;
 141   }
 142   return (strncmp(str, str_to_find, str_to_find_len) == 0);
 143 }
 144 
 145 bool string_ends_with(const char* str, const char* str_to_find) {
 146   size_t str_len = strlen(str);
 147   size_t str_to_find_len = strlen(str_to_find);
 148   if (str_to_find_len > str_len) {
 149     return false;
 150   }
 151   return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0);
 152 }
 153 
 154 
 155 MetaIndex::MetaIndex(char** meta_package_names, int num_meta_package_names) {
 156   if (num_meta_package_names == 0) {
 157     _meta_package_names = NULL;
 158     _num_meta_package_names = 0;
 159   } else {
 160     _meta_package_names = NEW_C_HEAP_ARRAY(char*, num_meta_package_names, mtClass);
 161     _num_meta_package_names = num_meta_package_names;
 162     memcpy(_meta_package_names, meta_package_names, num_meta_package_names * sizeof(char*));
 163   }
 164 }
 165 
 166 
 167 MetaIndex::~MetaIndex() {
 168   FREE_C_HEAP_ARRAY(char*, _meta_package_names);
 169 }
 170 
 171 
 172 bool MetaIndex::may_contain(const char* class_name) {
 173   if ( _num_meta_package_names == 0) {
 174     return false;
 175   }
 176   size_t class_name_len = strlen(class_name);
 177   for (int i = 0; i < _num_meta_package_names; i++) {
 178     char* pkg = _meta_package_names[i];
 179     size_t pkg_len = strlen(pkg);
 180     size_t min_len = MIN2(class_name_len, pkg_len);
 181     if (!strncmp(class_name, pkg, min_len)) {
 182       return true;
 183     }
 184   }
 185   return false;
 186 }
 187 
 188 
 189 ClassPathEntry::ClassPathEntry() {
 190   set_next(NULL);
 191 }
 192 
 193 
 194 bool ClassPathEntry::is_lazy() {
 195   return false;
 196 }
 197 
 198 ClassPathDirEntry::ClassPathDirEntry(const char* dir) : ClassPathEntry() {
 199   char* copy = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass);
 200   strcpy(copy, dir);
 201   _dir = copy;
 202 }
 203 
 204 
 205 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
 206   // construct full path name
 207   char path[JVM_MAXPATHLEN];
 208   if (jio_snprintf(path, sizeof(path), "%s%s%s", _dir, os::file_separator(), name) == -1) {


 298     ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize);
 299   }
 300   return new ClassFileStream(buffer, filesize, _zip_name); // Resource allocated
 301 }
 302 
 303 // invoke function for each entry in the zip file
 304 void ClassPathZipEntry::contents_do(void f(const char* name, void* context), void* context) {
 305   JavaThread* thread = JavaThread::current();
 306   HandleMark  handle_mark(thread);
 307   ThreadToNativeFromVM ttn(thread);
 308   for (int n = 0; ; n++) {
 309     jzentry * ze = ((*GetNextEntry)(_zip, n));
 310     if (ze == NULL) break;
 311     (*f)(ze->name, context);
 312   }
 313 }
 314 
 315 LazyClassPathEntry::LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() {
 316   _path = os::strdup_check_oom(path);
 317   _st = *st;
 318   _meta_index = NULL;
 319   _resolved_entry = NULL;
 320   _has_error = false;
 321   _throw_exception = throw_exception;
 322 }
 323 
 324 LazyClassPathEntry::~LazyClassPathEntry() {
 325   os::free((void*)_path);
 326 }
 327 
 328 bool LazyClassPathEntry::is_jar_file() {
 329   size_t len = strlen(_path);
 330   if (len < 4 || strcmp(_path + len - 4, ".jar") != 0) return false;
 331   return ((_st.st_mode & S_IFREG) == S_IFREG);
 332 }
 333 
 334 ClassPathEntry* LazyClassPathEntry::resolve_entry(TRAPS) {
 335   if (_resolved_entry != NULL) {
 336     return (ClassPathEntry*) _resolved_entry;
 337   }
 338   ClassPathEntry* new_entry = NULL;
 339   new_entry = ClassLoader::create_class_path_entry(_path, &_st, false, _throw_exception, CHECK_NULL);
 340   if (!_throw_exception && new_entry == NULL) {
 341     assert(!HAS_PENDING_EXCEPTION, "must be");
 342     return NULL;
 343   }
 344   {
 345     ThreadCritical tc;
 346     if (_resolved_entry == NULL) {
 347       _resolved_entry = new_entry;
 348       return new_entry;
 349     }
 350   }
 351   assert(_resolved_entry != NULL, "bug in MT-safe resolution logic");
 352   delete new_entry;
 353   return (ClassPathEntry*) _resolved_entry;
 354 }
 355 
 356 ClassFileStream* LazyClassPathEntry::open_stream(const char* name, TRAPS) {
 357   if (_meta_index != NULL &&
 358       !_meta_index->may_contain(name)) {
 359     return NULL;
 360   }
 361   if (_has_error) {
 362     return NULL;
 363   }
 364   ClassPathEntry* cpe = resolve_entry(THREAD);
 365   if (cpe == NULL) {
 366     _has_error = true;
 367     return NULL;
 368   } else {
 369     return cpe->open_stream(name, THREAD);
 370   }
 371 }
 372 
 373 bool LazyClassPathEntry::is_lazy() {
 374   return true;
 375 }
 376 
 377 u1* LazyClassPathEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) {
 378   if (_has_error) {
 379     return NULL;
 380   }


 446        strcat(path, extension);
 447        ClassLoader::compile_the_world_in(path, loader, CHECK);
 448     }
 449   }
 450   if (HAS_PENDING_EXCEPTION) {
 451   if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
 452     CLEAR_PENDING_EXCEPTION;
 453     tty->print_cr("\nCompileTheWorld : Ran out of memory\n");
 454     tty->print_cr("Increase class metadata storage if a limit was set");
 455   } else {
 456     tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n");
 457   }
 458   }
 459 }
 460 
 461 bool ClassPathImageEntry::is_jrt() {
 462   return string_ends_with(name(), "bootmodules.jimage");
 463 }
 464 #endif
 465 
 466 static void print_meta_index(LazyClassPathEntry* entry,
 467                              GrowableArray<char*>& meta_packages) {
 468   tty->print("[Meta index for %s=", entry->name());
 469   for (int i = 0; i < meta_packages.length(); i++) {
 470     if (i > 0) tty->print(" ");
 471     tty->print("%s", meta_packages.at(i));
 472   }
 473   tty->print_cr("]");
 474 }
 475 
 476 #if INCLUDE_CDS
 477 void ClassLoader::exit_with_path_failure(const char* error, const char* message) {
 478   assert(DumpSharedSpaces, "only called at dump time");
 479   tty->print_cr("Hint: enable -XX:+TraceClassPaths to diagnose the failure");
 480   vm_exit_during_initialization(error, message);
 481 }
 482 #endif
 483 
 484 void ClassLoader::trace_class_path(const char* msg, const char* name) {
 485   if (!TraceClassPaths) {
 486     return;
 487   }
 488 
 489   if (msg) {
 490     tty->print("%s", msg);
 491   }
 492   if (name) {
 493     if (strlen(name) < 256) {
 494       tty->print("%s", name);
 495     } else {
 496       // For very long paths, we need to print each character separately,
 497       // as print_cr() has a length limit
 498       while (name[0] != '\0') {
 499         tty->print("%c", name[0]);
 500         name++;
 501       }
 502     }
 503   }
 504   if (msg && msg[0] == '[') {
 505     tty->print_cr("]");
 506   } else {
 507     tty->cr();
 508   }
 509 }
 510 
 511 void ClassLoader::setup_bootstrap_meta_index() {
 512   // Set up meta index which allows us to open boot jars lazily if
 513   // class data sharing is enabled
 514   const char* meta_index_path = Arguments::get_meta_index_path();
 515   const char* meta_index_dir  = Arguments::get_meta_index_dir();
 516   setup_meta_index(meta_index_path, meta_index_dir, 0);
 517 }
 518 
 519 void ClassLoader::setup_meta_index(const char* meta_index_path, const char* meta_index_dir, int start_index) {
 520   const char* known_version = "% VERSION 2";
 521   FILE* file = fopen(meta_index_path, "r");
 522   int line_no = 0;
 523 #if INCLUDE_CDS
 524   if (DumpSharedSpaces) {
 525     if (file != NULL) {
 526       _shared_paths_misc_info->add_required_file(meta_index_path);
 527     } else {
 528       _shared_paths_misc_info->add_nonexist_path(meta_index_path);
 529     }
 530   }
 531 #endif
 532   if (file != NULL) {
 533     ResourceMark rm;
 534     LazyClassPathEntry* cur_entry = NULL;
 535     GrowableArray<char*> boot_class_path_packages(10);
 536     char package_name[256];
 537     bool skipCurrentJar = false;
 538     while (fgets(package_name, sizeof(package_name), file) != NULL) {
 539       ++line_no;
 540       // Remove trailing newline
 541       package_name[strlen(package_name) - 1] = '\0';
 542       switch(package_name[0]) {
 543         case '%':
 544         {
 545           if ((line_no == 1) && (strcmp(package_name, known_version) != 0)) {
 546             if (TraceClassLoading && Verbose) {
 547               tty->print("[Unsupported meta index version]");
 548             }
 549             fclose(file);
 550             return;
 551           }
 552         }
 553 
 554         // These directives indicate jar files which contain only
 555         // classes, only non-classfile resources, or a combination of
 556         // the two. See src/share/classes/sun/misc/MetaIndex.java and
 557         // make/tools/MetaIndex/BuildMetaIndex.java in the J2SE
 558         // workspace.
 559         case '#':
 560         case '!':
 561         case '@':
 562         {
 563           // Hand off current packages to current lazy entry (if any)
 564           if ((cur_entry != NULL) &&
 565               (boot_class_path_packages.length() > 0)) {
 566             if ((TraceClassLoading || TraceClassPaths) && Verbose) {
 567               print_meta_index(cur_entry, boot_class_path_packages);
 568             }
 569             MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0),
 570                                              boot_class_path_packages.length());
 571             cur_entry->set_meta_index(index);
 572           }
 573           cur_entry = NULL;
 574           boot_class_path_packages.clear();
 575 
 576           // Find lazy entry corresponding to this jar file
 577           int count = 0;
 578           for (ClassPathEntry* entry = _first_entry; entry != NULL; entry = entry->next(), count++) {
 579             if (count >= start_index &&
 580                 entry->is_lazy() &&
 581                 string_starts_with(entry->name(), meta_index_dir) &&
 582                 string_ends_with(entry->name(), &package_name[2])) {
 583               cur_entry = (LazyClassPathEntry*) entry;
 584               break;
 585             }
 586           }
 587 
 588           // If the first character is '@', it indicates the following jar
 589           // file is a resource only jar file in which case, we should skip
 590           // reading the subsequent entries since the resource loading is
 591           // totally handled by J2SE side.
 592           if (package_name[0] == '@') {
 593             if (cur_entry != NULL) {
 594               cur_entry->set_meta_index(new MetaIndex(NULL, 0));
 595             }
 596             cur_entry = NULL;
 597             skipCurrentJar = true;
 598           } else {
 599             skipCurrentJar = false;
 600           }
 601 
 602           break;
 603         }
 604 
 605         default:
 606         {
 607           if (!skipCurrentJar && cur_entry != NULL) {
 608             char* new_name = os::strdup_check_oom(package_name);
 609             boot_class_path_packages.append(new_name);
 610           }
 611         }
 612       }
 613     }
 614     // Hand off current packages to current lazy entry (if any)
 615     if ((cur_entry != NULL) &&
 616         (boot_class_path_packages.length() > 0)) {
 617       if ((TraceClassLoading || TraceClassPaths) && Verbose) {
 618         print_meta_index(cur_entry, boot_class_path_packages);
 619       }
 620       MetaIndex* index = new MetaIndex(boot_class_path_packages.adr_at(0),
 621                                        boot_class_path_packages.length());
 622       cur_entry->set_meta_index(index);
 623     }
 624     fclose(file);
 625   }
 626 }
 627 
 628 #if INCLUDE_CDS
 629 void ClassLoader::check_shared_classpath(const char *path) {
 630   if (strcmp(path, "") == 0) {
 631     exit_with_path_failure("Cannot have empty path in archived classpaths", NULL);
 632   }
 633 
 634   struct stat st;
 635   if (os::stat(path, &st) == 0) {
 636     if ((st.st_mode & S_IFREG) != S_IFREG) { // is directory
 637       if (!os::dir_is_empty(path)) {
 638         tty->print_cr("Error: non-empty directory '%s'", path);
 639         exit_with_path_failure("CDS allows only empty directories in archived classpaths", NULL);
 640       }
 641     }
 642   }
 643 }
 644 #endif
 645 
 646 void ClassLoader::setup_bootstrap_search_path() {
 647   assert(_first_entry == NULL, "should not setup bootstrap class search path twice");


1298 
1299     NEWPERFEVENTCOUNTER(_isUnsyncloadClass, SUN_CLS, "isUnsyncloadClassSet");
1300     NEWPERFEVENTCOUNTER(_load_instance_class_failCounter, SUN_CLS,
1301                         "loadInstanceClassFailRate");
1302 
1303     // increment the isUnsyncloadClass counter if UnsyncloadClass is set.
1304     if (UnsyncloadClass) {
1305       _isUnsyncloadClass->inc();
1306     }
1307   }
1308 
1309   // lookup zip library entry points
1310   load_zip_library();
1311 #if INCLUDE_CDS
1312   // initialize search path
1313   if (DumpSharedSpaces) {
1314     _shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info();
1315   }
1316 #endif
1317   setup_bootstrap_search_path();
1318   if (LazyBootClassLoader) {
1319     // set up meta index which makes boot classpath initialization lazier
1320     setup_bootstrap_meta_index();
1321   }
1322 }
1323 
1324 #if INCLUDE_CDS
1325 void ClassLoader::initialize_shared_path() {
1326   if (DumpSharedSpaces) {
1327     ClassLoaderExt::setup_search_paths();
1328     _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1329   }
1330 }
1331 #endif
1332 
1333 jlong ClassLoader::classloader_time_ms() {
1334   return UsePerfData ?
1335     Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1336 }
1337 
1338 jlong ClassLoader::class_init_count() {
1339   return UsePerfData ? _perf_classes_inited->get_value() : -1;
1340 }
1341 


1469   tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name);
1470   tty->cr();
1471   // Iterate over all entries in zip file
1472   for (int n = 0; ; n++) {
1473     real_jzentry * ze = (real_jzentry *)((*GetNextEntry)(_zip, n));
1474     if (ze == NULL) break;
1475     ClassLoader::compile_the_world_in(ze->name, loader, CHECK);
1476   }
1477   if (HAS_PENDING_EXCEPTION) {
1478     if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
1479       CLEAR_PENDING_EXCEPTION;
1480       tty->print_cr("\nCompileTheWorld : Ran out of memory\n");
1481       tty->print_cr("Increase class metadata storage if a limit was set");
1482     } else {
1483       tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n");
1484     }
1485   }
1486 }
1487 
1488 bool ClassPathZipEntry::is_jrt() {
1489   real_jzfile* zip = (real_jzfile*) _zip;
1490   int len = (int)strlen(zip->name);
1491   // Check whether zip name ends in "rt.jar"
1492   // This will match other archives named rt.jar as well, but this is
1493   // only used for debugging.
1494   return string_ends_with(zip->name, "rt.jar");
1495 }
1496 
1497 void LazyClassPathEntry::compile_the_world(Handle loader, TRAPS) {
1498   ClassPathEntry* cpe = resolve_entry(THREAD);
1499   if (cpe != NULL) {
1500     cpe->compile_the_world(loader, CHECK);
1501   }
1502 }
1503 
1504 bool LazyClassPathEntry::is_jrt() {
1505   Thread* THREAD = Thread::current();
1506   ClassPathEntry* cpe = resolve_entry(THREAD);
1507   return (cpe != NULL) ? cpe->is_jar_file() : false;
1508 }
1509 
1510 void ClassLoader::compile_the_world() {
1511   EXCEPTION_MARK;
1512   HandleMark hm(THREAD);
1513   ResourceMark rm(THREAD);
1514   // Make sure we don't run with background compilation
1515   BackgroundCompilation = false;
1516   // Find bootstrap loader
1517   Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
1518   // Iterate over all bootstrap class path entries
1519   ClassPathEntry* e = _first_entry;
1520   jlong start = os::javaTimeMillis();
1521   while (e != NULL) {
1522     // We stop at rt.jar, unless it is the first bootstrap path entry
1523     if (e->is_jrt() && e != _first_entry) break;
1524     e->compile_the_world(system_class_loader, CATCH);
1525     e = e->next();
1526   }
1527   jlong end = os::javaTimeMillis();
1528   tty->print_cr("CompileTheWorld : Done (%d classes, %d methods, " JLONG_FORMAT " ms)",
1529                 _compile_the_world_class_counter, _compile_the_world_method_counter, (end - start));
1530   {
1531     // Print statistics as if before normal exit:
1532     extern void print_statistics();
1533     print_statistics();
1534   }
1535   vm_exit(0);
1536 }
1537 
1538 int ClassLoader::_compile_the_world_class_counter = 0;
1539 int ClassLoader::_compile_the_world_method_counter = 0;
1540 static int _codecache_sweep_counter = 0;
1541 
1542 // Filter out all exceptions except OOMs


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 135 // helper routines
 136 bool string_starts_with(const char* str, const char* str_to_find) {
 137   size_t str_len = strlen(str);
 138   size_t str_to_find_len = strlen(str_to_find);
 139   if (str_to_find_len > str_len) {
 140     return false;
 141   }
 142   return (strncmp(str, str_to_find, str_to_find_len) == 0);
 143 }
 144 
 145 bool string_ends_with(const char* str, const char* str_to_find) {
 146   size_t str_len = strlen(str);
 147   size_t str_to_find_len = strlen(str_to_find);
 148   if (str_to_find_len > str_len) {
 149     return false;
 150   }
 151   return (strncmp(str + (str_len - str_to_find_len), str_to_find, str_to_find_len) == 0);
 152 }
 153 
 154 


































 155 ClassPathEntry::ClassPathEntry() {
 156   set_next(NULL);
 157 }
 158 
 159 
 160 bool ClassPathEntry::is_lazy() {
 161   return false;
 162 }
 163 
 164 ClassPathDirEntry::ClassPathDirEntry(const char* dir) : ClassPathEntry() {
 165   char* copy = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass);
 166   strcpy(copy, dir);
 167   _dir = copy;
 168 }
 169 
 170 
 171 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
 172   // construct full path name
 173   char path[JVM_MAXPATHLEN];
 174   if (jio_snprintf(path, sizeof(path), "%s%s%s", _dir, os::file_separator(), name) == -1) {


 264     ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize);
 265   }
 266   return new ClassFileStream(buffer, filesize, _zip_name); // Resource allocated
 267 }
 268 
 269 // invoke function for each entry in the zip file
 270 void ClassPathZipEntry::contents_do(void f(const char* name, void* context), void* context) {
 271   JavaThread* thread = JavaThread::current();
 272   HandleMark  handle_mark(thread);
 273   ThreadToNativeFromVM ttn(thread);
 274   for (int n = 0; ; n++) {
 275     jzentry * ze = ((*GetNextEntry)(_zip, n));
 276     if (ze == NULL) break;
 277     (*f)(ze->name, context);
 278   }
 279 }
 280 
 281 LazyClassPathEntry::LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() {
 282   _path = os::strdup_check_oom(path);
 283   _st = *st;

 284   _resolved_entry = NULL;
 285   _has_error = false;
 286   _throw_exception = throw_exception;
 287 }
 288 
 289 LazyClassPathEntry::~LazyClassPathEntry() {
 290   os::free((void*)_path);
 291 }
 292 
 293 bool LazyClassPathEntry::is_jar_file() {
 294   size_t len = strlen(_path);
 295   if (len < 4 || strcmp(_path + len - 4, ".jar") != 0) return false;
 296   return ((_st.st_mode & S_IFREG) == S_IFREG);
 297 }
 298 
 299 ClassPathEntry* LazyClassPathEntry::resolve_entry(TRAPS) {
 300   if (_resolved_entry != NULL) {
 301     return (ClassPathEntry*) _resolved_entry;
 302   }
 303   ClassPathEntry* new_entry = NULL;
 304   new_entry = ClassLoader::create_class_path_entry(_path, &_st, false, _throw_exception, CHECK_NULL);
 305   if (!_throw_exception && new_entry == NULL) {
 306     assert(!HAS_PENDING_EXCEPTION, "must be");
 307     return NULL;
 308   }
 309   {
 310     ThreadCritical tc;
 311     if (_resolved_entry == NULL) {
 312       _resolved_entry = new_entry;
 313       return new_entry;
 314     }
 315   }
 316   assert(_resolved_entry != NULL, "bug in MT-safe resolution logic");
 317   delete new_entry;
 318   return (ClassPathEntry*) _resolved_entry;
 319 }
 320 
 321 ClassFileStream* LazyClassPathEntry::open_stream(const char* name, TRAPS) {




 322   if (_has_error) {
 323     return NULL;
 324   }
 325   ClassPathEntry* cpe = resolve_entry(THREAD);
 326   if (cpe == NULL) {
 327     _has_error = true;
 328     return NULL;
 329   } else {
 330     return cpe->open_stream(name, THREAD);
 331   }
 332 }
 333 
 334 bool LazyClassPathEntry::is_lazy() {
 335   return true;
 336 }
 337 
 338 u1* LazyClassPathEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) {
 339   if (_has_error) {
 340     return NULL;
 341   }


 407        strcat(path, extension);
 408        ClassLoader::compile_the_world_in(path, loader, CHECK);
 409     }
 410   }
 411   if (HAS_PENDING_EXCEPTION) {
 412   if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
 413     CLEAR_PENDING_EXCEPTION;
 414     tty->print_cr("\nCompileTheWorld : Ran out of memory\n");
 415     tty->print_cr("Increase class metadata storage if a limit was set");
 416   } else {
 417     tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n");
 418   }
 419   }
 420 }
 421 
 422 bool ClassPathImageEntry::is_jrt() {
 423   return string_ends_with(name(), "bootmodules.jimage");
 424 }
 425 #endif
 426 










 427 #if INCLUDE_CDS
 428 void ClassLoader::exit_with_path_failure(const char* error, const char* message) {
 429   assert(DumpSharedSpaces, "only called at dump time");
 430   tty->print_cr("Hint: enable -XX:+TraceClassPaths to diagnose the failure");
 431   vm_exit_during_initialization(error, message);
 432 }
 433 #endif
 434 
 435 void ClassLoader::trace_class_path(const char* msg, const char* name) {
 436   if (!TraceClassPaths) {
 437     return;
 438   }
 439 
 440   if (msg) {
 441     tty->print("%s", msg);
 442   }
 443   if (name) {
 444     if (strlen(name) < 256) {
 445       tty->print("%s", name);
 446     } else {
 447       // For very long paths, we need to print each character separately,
 448       // as print_cr() has a length limit
 449       while (name[0] != '\0') {
 450         tty->print("%c", name[0]);
 451         name++;
 452       }
 453     }
 454   }
 455   if (msg && msg[0] == '[') {
 456     tty->print_cr("]");
 457   } else {
 458     tty->cr();
 459   }
 460 }
 461 





















































































































 462 #if INCLUDE_CDS
 463 void ClassLoader::check_shared_classpath(const char *path) {
 464   if (strcmp(path, "") == 0) {
 465     exit_with_path_failure("Cannot have empty path in archived classpaths", NULL);
 466   }
 467 
 468   struct stat st;
 469   if (os::stat(path, &st) == 0) {
 470     if ((st.st_mode & S_IFREG) != S_IFREG) { // is directory
 471       if (!os::dir_is_empty(path)) {
 472         tty->print_cr("Error: non-empty directory '%s'", path);
 473         exit_with_path_failure("CDS allows only empty directories in archived classpaths", NULL);
 474       }
 475     }
 476   }
 477 }
 478 #endif
 479 
 480 void ClassLoader::setup_bootstrap_search_path() {
 481   assert(_first_entry == NULL, "should not setup bootstrap class search path twice");


1132 
1133     NEWPERFEVENTCOUNTER(_isUnsyncloadClass, SUN_CLS, "isUnsyncloadClassSet");
1134     NEWPERFEVENTCOUNTER(_load_instance_class_failCounter, SUN_CLS,
1135                         "loadInstanceClassFailRate");
1136 
1137     // increment the isUnsyncloadClass counter if UnsyncloadClass is set.
1138     if (UnsyncloadClass) {
1139       _isUnsyncloadClass->inc();
1140     }
1141   }
1142 
1143   // lookup zip library entry points
1144   load_zip_library();
1145 #if INCLUDE_CDS
1146   // initialize search path
1147   if (DumpSharedSpaces) {
1148     _shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info();
1149   }
1150 #endif
1151   setup_bootstrap_search_path();




1152 }
1153 
1154 #if INCLUDE_CDS
1155 void ClassLoader::initialize_shared_path() {
1156   if (DumpSharedSpaces) {
1157     ClassLoaderExt::setup_search_paths();
1158     _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1159   }
1160 }
1161 #endif
1162 
1163 jlong ClassLoader::classloader_time_ms() {
1164   return UsePerfData ?
1165     Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1166 }
1167 
1168 jlong ClassLoader::class_init_count() {
1169   return UsePerfData ? _perf_classes_inited->get_value() : -1;
1170 }
1171 


1299   tty->print_cr("CompileTheWorld : Compiling all classes in %s", zip->name);
1300   tty->cr();
1301   // Iterate over all entries in zip file
1302   for (int n = 0; ; n++) {
1303     real_jzentry * ze = (real_jzentry *)((*GetNextEntry)(_zip, n));
1304     if (ze == NULL) break;
1305     ClassLoader::compile_the_world_in(ze->name, loader, CHECK);
1306   }
1307   if (HAS_PENDING_EXCEPTION) {
1308     if (PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())) {
1309       CLEAR_PENDING_EXCEPTION;
1310       tty->print_cr("\nCompileTheWorld : Ran out of memory\n");
1311       tty->print_cr("Increase class metadata storage if a limit was set");
1312     } else {
1313       tty->print_cr("\nCompileTheWorld : Unexpected exception occurred\n");
1314     }
1315   }
1316 }
1317 
1318 bool ClassPathZipEntry::is_jrt() {
1319   return false;





1320 }
1321 
1322 void LazyClassPathEntry::compile_the_world(Handle loader, TRAPS) {
1323   ClassPathEntry* cpe = resolve_entry(THREAD);
1324   if (cpe != NULL) {
1325     cpe->compile_the_world(loader, CHECK);
1326   }
1327 }
1328 
1329 bool LazyClassPathEntry::is_jrt() {
1330   Thread* THREAD = Thread::current();
1331   ClassPathEntry* cpe = resolve_entry(THREAD);
1332   return (cpe != NULL) ? cpe->is_jar_file() : false;
1333 }
1334 
1335 void ClassLoader::compile_the_world() {
1336   EXCEPTION_MARK;
1337   HandleMark hm(THREAD);
1338   ResourceMark rm(THREAD);
1339   // Make sure we don't run with background compilation
1340   BackgroundCompilation = false;
1341   // Find bootstrap loader
1342   Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
1343   // Iterate over all bootstrap class path entries
1344   ClassPathEntry* e = _first_entry;
1345   jlong start = os::javaTimeMillis();
1346   while (e != NULL) {
1347     // We stop at bootmodules.jimage, unless it is the first bootstrap path entry
1348     if (e->is_jrt() && e != _first_entry) break;
1349     e->compile_the_world(system_class_loader, CATCH);
1350     e = e->next();
1351   }
1352   jlong end = os::javaTimeMillis();
1353   tty->print_cr("CompileTheWorld : Done (%d classes, %d methods, " JLONG_FORMAT " ms)",
1354                 _compile_the_world_class_counter, _compile_the_world_method_counter, (end - start));
1355   {
1356     // Print statistics as if before normal exit:
1357     extern void print_statistics();
1358     print_statistics();
1359   }
1360   vm_exit(0);
1361 }
1362 
1363 int ClassLoader::_compile_the_world_class_counter = 0;
1364 int ClassLoader::_compile_the_world_method_counter = 0;
1365 static int _codecache_sweep_counter = 0;
1366 
1367 // Filter out all exceptions except OOMs


src/share/vm/classfile/classLoader.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File