< prev index next >

src/hotspot/share/classfile/classLoader.cpp

Print this page


  55 #include "oops/objArrayOop.inline.hpp"
  56 #include "oops/oop.inline.hpp"
  57 #include "oops/symbol.hpp"
  58 #include "prims/jvm_misc.hpp"
  59 #include "runtime/arguments.hpp"
  60 #include "runtime/compilationPolicy.hpp"
  61 #include "runtime/handles.inline.hpp"
  62 #include "runtime/init.hpp"
  63 #include "runtime/interfaceSupport.inline.hpp"
  64 #include "runtime/java.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/os.inline.hpp"
  67 #include "runtime/threadCritical.hpp"
  68 #include "runtime/timer.hpp"
  69 #include "runtime/vm_version.hpp"
  70 #include "services/management.hpp"
  71 #include "services/threadService.hpp"
  72 #include "utilities/events.hpp"
  73 #include "utilities/hashtable.inline.hpp"
  74 #include "utilities/macros.hpp"
  75 #if INCLUDE_CDS
  76 #include "classfile/sharedPathsMiscInfo.hpp"
  77 #endif
  78 
  79 // Entry points in zip.dll for loading zip/jar file entries
  80 
  81 typedef void * * (*ZipOpen_t)(const char *name, char **pmsg);
  82 typedef void (*ZipClose_t)(jzfile *zip);
  83 typedef jzentry* (*FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen);
  84 typedef jboolean (*ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf);
  85 typedef jzentry* (*GetNextEntry_t)(jzfile *zip, jint n);
  86 typedef jboolean (*ZipInflateFully_t)(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg);
  87 typedef jint     (*Crc32_t)(jint crc, const jbyte *buf, jint len);
  88 
  89 static ZipOpen_t         ZipOpen            = NULL;
  90 static ZipClose_t        ZipClose           = NULL;
  91 static FindEntry_t       FindEntry          = NULL;
  92 static ReadEntry_t       ReadEntry          = NULL;
  93 static GetNextEntry_t    GetNextEntry       = NULL;
  94 static canonicalize_fn_t CanonicalizeEntry  = NULL;
  95 static ZipInflateFully_t ZipInflateFully    = NULL;
  96 static Crc32_t           Crc32              = NULL;
  97 


 129 PerfCounter*    ClassLoader::_perf_define_appclass_selftime = NULL;
 130 PerfCounter*    ClassLoader::_perf_app_classfile_bytes_read = NULL;
 131 PerfCounter*    ClassLoader::_perf_sys_classfile_bytes_read = NULL;
 132 PerfCounter*    ClassLoader::_sync_systemLoaderLockContentionRate = NULL;
 133 PerfCounter*    ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL;
 134 PerfCounter*    ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL;
 135 PerfCounter*    ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL;
 136 PerfCounter*    ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
 137 PerfCounter*    ClassLoader::_unsafe_defineClassCallCounter = NULL;
 138 
 139 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = NULL;
 140 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
 141 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
 142 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
 143 ClassPathEntry* ClassLoader::_last_append_entry  = NULL;
 144 #if INCLUDE_CDS
 145 ClassPathEntry* ClassLoader::_app_classpath_entries = NULL;
 146 ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL;
 147 ClassPathEntry* ClassLoader::_module_path_entries = NULL;
 148 ClassPathEntry* ClassLoader::_last_module_path_entry = NULL;
 149 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
 150 #endif
 151 
 152 // helper routines
 153 bool string_starts_with(const char* str, const char* str_to_find) {
 154   size_t str_len = strlen(str);
 155   size_t str_to_find_len = strlen(str_to_find);
 156   if (str_to_find_len > str_len) {
 157     return false;
 158   }
 159   return (strncmp(str, str_to_find, str_to_find_len) == 0);
 160 }
 161 
 162 static const char* get_jimage_version_string() {
 163   static char version_string[10] = "";
 164   if (version_string[0] == '\0') {
 165     jio_snprintf(version_string, sizeof(version_string), "%d.%d",
 166                  VM_Version::vm_major_version(), VM_Version::vm_minor_version());
 167   }
 168   return (const char*)version_string;
 169 }


 267   char* pkg_name = NEW_RESOURCE_ARRAY(char, length + 1);
 268   strncpy(pkg_name, class_name_ptr, length);
 269   *(pkg_name+length) = '\0';
 270 
 271   return (const char *)pkg_name;
 272 }
 273 
 274 // Given a fully qualified class name, find its defining package in the class loader's
 275 // package entry table.
 276 PackageEntry* ClassLoader::get_package_entry(const char* class_name, ClassLoaderData* loader_data, TRAPS) {
 277   ResourceMark rm(THREAD);
 278   const char *pkg_name = ClassLoader::package_from_name(class_name);
 279   if (pkg_name == NULL) {
 280     return NULL;
 281   }
 282   PackageEntryTable* pkgEntryTable = loader_data->packages();
 283   TempNewSymbol pkg_symbol = SymbolTable::new_symbol(pkg_name);
 284   return pkgEntryTable->lookup_only(pkg_symbol);
 285 }
 286 
 287 ClassPathDirEntry::ClassPathDirEntry(const char* dir) : ClassPathEntry() {
 288   char* copy = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass);
 289   strcpy(copy, dir);
 290   _dir = copy;
 291 }
 292 
 293 
 294 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
 295   // construct full path name
 296   assert((_dir != NULL) && (name != NULL), "sanity");
 297   size_t path_len = strlen(_dir) + strlen(name) + strlen(os::file_separator()) + 1;
 298   char* path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, path_len);
 299   int len = jio_snprintf(path, path_len, "%s%s%s", _dir, os::file_separator(), name);
 300   assert(len == (int)(path_len - 1), "sanity");
 301   // check if file exists
 302   struct stat st;
 303   if (os::stat(path, &st) == 0) {
 304     // found file, open it
 305     int file_handle = os::open(path, 0, 0);
 306     if (file_handle != -1) {
 307       // read contents into resource array
 308       u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size);
 309       size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
 310       // close file
 311       os::close(file_handle);
 312       // construct ClassFileStream
 313       if (num_read == (size_t)st.st_size) {
 314         if (UsePerfData) {
 315           ClassLoader::perf_sys_classfile_bytes_read()->inc(num_read);
 316         }
 317         FREE_RESOURCE_ARRAY(char, path, path_len);
 318         // Resource allocated
 319         return new ClassFileStream(buffer,
 320                                    st.st_size,
 321                                    _dir,
 322                                    ClassFileStream::verify);
 323       }
 324     }
 325   }
 326   FREE_RESOURCE_ARRAY(char, path, path_len);
 327   return NULL;
 328 }
 329 
 330 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name,
 331                                      bool is_boot_append, bool from_class_path_attr) : ClassPathEntry() {
 332   _zip = zip;
 333   char *copy = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass);
 334   strcpy(copy, zip_name);
 335   _zip_name = copy;
 336   _from_class_path_attr = from_class_path_attr;
 337 }
 338 
 339 ClassPathZipEntry::~ClassPathZipEntry() {
 340   if (ZipClose != NULL) {
 341     (*ZipClose)(_zip);
 342   }
 343   FREE_C_HEAP_ARRAY(char, _zip_name);
 344 }
 345 
 346 u1* ClassPathZipEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) {
 347     // enable call to C land
 348   JavaThread* thread = JavaThread::current();
 349   ThreadToNativeFromVM ttn(thread);
 350   // check whether zip archive contains name
 351   jint name_len;
 352   jzentry* entry = (*FindEntry)(_zip, name, filesize, &name_len);
 353   if (entry == NULL) return NULL;
 354   u1* buffer;
 355   char name_buf[128];


 400   }
 401 }
 402 
 403 DEBUG_ONLY(ClassPathImageEntry* ClassPathImageEntry::_singleton = NULL;)
 404 
 405 void ClassPathImageEntry::close_jimage() {
 406   if (_jimage != NULL) {
 407     (*JImageClose)(_jimage);
 408     _jimage = NULL;
 409   }
 410 }
 411 
 412 ClassPathImageEntry::ClassPathImageEntry(JImageFile* jimage, const char* name) :
 413   ClassPathEntry(),
 414   _jimage(jimage) {
 415   guarantee(jimage != NULL, "jimage file is null");
 416   guarantee(name != NULL, "jimage file name is null");
 417   assert(_singleton == NULL, "VM supports only one jimage");
 418   DEBUG_ONLY(_singleton = this);
 419   size_t len = strlen(name) + 1;
 420   _name = NEW_C_HEAP_ARRAY(const char, len, mtClass);
 421   strncpy((char *)_name, name, len);
 422 }
 423 
 424 ClassPathImageEntry::~ClassPathImageEntry() {
 425   assert(_singleton == this, "must be");
 426   DEBUG_ONLY(_singleton = NULL);
 427 
 428   if (_name != NULL) {
 429     FREE_C_HEAP_ARRAY(const char, _name);
 430     _name = NULL;
 431   }
 432   if (_jimage != NULL) {
 433     (*JImageClose)(_jimage);
 434     _jimage = NULL;
 435   }
 436 }
 437 
 438 ClassFileStream* ClassPathImageEntry::open_stream(const char* name, TRAPS) {
 439   return open_stream_for_loader(name, ClassLoaderData::the_null_class_loader_data(), THREAD);
 440 }
 441 


 554         // as print_cr() has a length limit
 555         while (name[0] != '\0') {
 556           ls.print("%c", name[0]);
 557           name++;
 558         }
 559       }
 560     }
 561     ls.cr();
 562   }
 563 }
 564 
 565 void ClassLoader::setup_bootstrap_search_path() {
 566   const char* sys_class_path = Arguments::get_sysclasspath();
 567   assert(sys_class_path != NULL, "System boot class path must not be NULL");
 568   if (PrintSharedArchiveAndExit) {
 569     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
 570     // the same as the bootcp of the shared archive.
 571   } else {
 572     trace_class_path("bootstrap loader class path=", sys_class_path);
 573   }
 574 #if INCLUDE_CDS
 575   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
 576     _shared_paths_misc_info->add_boot_classpath(sys_class_path);
 577   }
 578 #endif
 579   setup_boot_search_path(sys_class_path);
 580 }
 581 
 582 #if INCLUDE_CDS
 583 int ClassLoader::get_shared_paths_misc_info_size() {
 584   return _shared_paths_misc_info->get_used_bytes();
 585 }
 586 
 587 void* ClassLoader::get_shared_paths_misc_info() {
 588   return _shared_paths_misc_info->buffer();
 589 }
 590 
 591 bool ClassLoader::check_shared_paths_misc_info(void *buf, int size, bool is_static) {
 592   SharedPathsMiscInfo* checker = new SharedPathsMiscInfo((char*)buf, size);
 593   bool result = checker->check(is_static);
 594   delete checker;
 595   return result;
 596 }
 597 
 598 void ClassLoader::setup_app_search_path(const char *class_path) {
 599   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Sanity");
 600 
 601   ResourceMark rm;
 602   ClasspathStream cp_stream(class_path);
 603 
 604   while (cp_stream.has_next()) {
 605     const char* path = cp_stream.get_next();
 606     update_class_path_entry_list(path, false, false, false);
 607   }
 608 }
 609 
 610 void ClassLoader::add_to_module_path_entries(const char* path,
 611                                              ClassPathEntry* entry) {
 612   assert(entry != NULL, "ClassPathEntry should not be NULL");
 613   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "dump time only");
 614 
 615   // The entry does not exist, add to the list
 616   if (_module_path_entries == NULL) {
 617     assert(_last_module_path_entry == NULL, "Sanity");


 960                                                bool throw_exception) {
 961   struct stat st;
 962   if (os::stat(path, &st) == 0) {
 963     // File or directory found
 964     ClassPathEntry* new_entry = NULL;
 965     Thread* THREAD = Thread::current();
 966     new_entry = create_class_path_entry(path, &st, throw_exception, is_boot_append, from_class_path_attr, CHECK_(false));
 967     if (new_entry == NULL) {
 968       return false;
 969     }
 970 
 971     // Do not reorder the bootclasspath which would break get_system_package().
 972     // Add new entry to linked list
 973     if (is_boot_append) {
 974       add_to_boot_append_entries(new_entry);
 975     } else {
 976       add_to_app_classpath_entries(path, new_entry, check_for_duplicates);
 977     }
 978     return true;
 979   } else {
 980 #if INCLUDE_CDS
 981     if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
 982       _shared_paths_misc_info->add_nonexist_path(path);
 983     }
 984 #endif
 985     return false;
 986   }
 987 }
 988 
 989 static void print_module_entry_table(const GrowableArray<ModuleClassPathList*>* const module_list) {
 990   ResourceMark rm;
 991   int num_of_entries = module_list->length();
 992   for (int i = 0; i < num_of_entries; i++) {
 993     ClassPathEntry* e;
 994     ModuleClassPathList* mpl = module_list->at(i);
 995     tty->print("%s=", mpl->module_name()->as_C_string());
 996     e = mpl->module_first_entry();
 997     while (e != NULL) {
 998       tty->print("%s", e->name());
 999       e = e->next();
1000       if (e != NULL) {
1001         tty->print("%s", os::path_separator());
1002       }
1003     }
1004     tty->print(" ;");


1584     NEWPERFEVENTCOUNTER(_sync_systemLoaderLockContentionRate, SUN_CLS,
1585                         "systemLoaderLockContentionRate");
1586     NEWPERFEVENTCOUNTER(_sync_nonSystemLoaderLockContentionRate, SUN_CLS,
1587                         "nonSystemLoaderLockContentionRate");
1588     NEWPERFEVENTCOUNTER(_sync_JVMFindLoadedClassLockFreeCounter, SUN_CLS,
1589                         "jvmFindLoadedClassNoLockCalls");
1590     NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS,
1591                         "jvmDefineClassNoLockCalls");
1592 
1593     NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS,
1594                         "jniDefineClassNoLockCalls");
1595 
1596     NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS,
1597                         "unsafeDefineClassCalls");
1598   }
1599 
1600   // lookup zip library entry points
1601   load_zip_library();
1602   // lookup jimage library entry points
1603   load_jimage_library();
1604 #if INCLUDE_CDS
1605   // initialize search path
1606   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
1607     _shared_paths_misc_info = new SharedPathsMiscInfo();
1608   }
1609 #endif
1610   setup_bootstrap_search_path();
1611 }
1612 
1613 #if INCLUDE_CDS
1614 void ClassLoader::initialize_shared_path() {
1615   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
1616     ClassLoaderExt::setup_search_paths();
1617     _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1618   }
1619 }
1620 
1621 void ClassLoader::initialize_module_path(TRAPS) {
1622   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
1623     ClassLoaderExt::setup_module_paths(THREAD);
1624     FileMapInfo::allocate_shared_path_table();
1625   }
1626 }
1627 #endif
1628 
1629 jlong ClassLoader::classloader_time_ms() {
1630   return UsePerfData ?
1631     Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1632 }
1633 
1634 jlong ClassLoader::class_init_count() {
1635   return UsePerfData ? _perf_classes_inited->get_value() : -1;
1636 }
1637 




  55 #include "oops/objArrayOop.inline.hpp"
  56 #include "oops/oop.inline.hpp"
  57 #include "oops/symbol.hpp"
  58 #include "prims/jvm_misc.hpp"
  59 #include "runtime/arguments.hpp"
  60 #include "runtime/compilationPolicy.hpp"
  61 #include "runtime/handles.inline.hpp"
  62 #include "runtime/init.hpp"
  63 #include "runtime/interfaceSupport.inline.hpp"
  64 #include "runtime/java.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/os.inline.hpp"
  67 #include "runtime/threadCritical.hpp"
  68 #include "runtime/timer.hpp"
  69 #include "runtime/vm_version.hpp"
  70 #include "services/management.hpp"
  71 #include "services/threadService.hpp"
  72 #include "utilities/events.hpp"
  73 #include "utilities/hashtable.inline.hpp"
  74 #include "utilities/macros.hpp"



  75 
  76 // Entry points in zip.dll for loading zip/jar file entries
  77 
  78 typedef void * * (*ZipOpen_t)(const char *name, char **pmsg);
  79 typedef void (*ZipClose_t)(jzfile *zip);
  80 typedef jzentry* (*FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen);
  81 typedef jboolean (*ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf);
  82 typedef jzentry* (*GetNextEntry_t)(jzfile *zip, jint n);
  83 typedef jboolean (*ZipInflateFully_t)(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg);
  84 typedef jint     (*Crc32_t)(jint crc, const jbyte *buf, jint len);
  85 
  86 static ZipOpen_t         ZipOpen            = NULL;
  87 static ZipClose_t        ZipClose           = NULL;
  88 static FindEntry_t       FindEntry          = NULL;
  89 static ReadEntry_t       ReadEntry          = NULL;
  90 static GetNextEntry_t    GetNextEntry       = NULL;
  91 static canonicalize_fn_t CanonicalizeEntry  = NULL;
  92 static ZipInflateFully_t ZipInflateFully    = NULL;
  93 static Crc32_t           Crc32              = NULL;
  94 


 126 PerfCounter*    ClassLoader::_perf_define_appclass_selftime = NULL;
 127 PerfCounter*    ClassLoader::_perf_app_classfile_bytes_read = NULL;
 128 PerfCounter*    ClassLoader::_perf_sys_classfile_bytes_read = NULL;
 129 PerfCounter*    ClassLoader::_sync_systemLoaderLockContentionRate = NULL;
 130 PerfCounter*    ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL;
 131 PerfCounter*    ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL;
 132 PerfCounter*    ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL;
 133 PerfCounter*    ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
 134 PerfCounter*    ClassLoader::_unsafe_defineClassCallCounter = NULL;
 135 
 136 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = NULL;
 137 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
 138 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
 139 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
 140 ClassPathEntry* ClassLoader::_last_append_entry  = NULL;
 141 #if INCLUDE_CDS
 142 ClassPathEntry* ClassLoader::_app_classpath_entries = NULL;
 143 ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL;
 144 ClassPathEntry* ClassLoader::_module_path_entries = NULL;
 145 ClassPathEntry* ClassLoader::_last_module_path_entry = NULL;

 146 #endif
 147 
 148 // helper routines
 149 bool string_starts_with(const char* str, const char* str_to_find) {
 150   size_t str_len = strlen(str);
 151   size_t str_to_find_len = strlen(str_to_find);
 152   if (str_to_find_len > str_len) {
 153     return false;
 154   }
 155   return (strncmp(str, str_to_find, str_to_find_len) == 0);
 156 }
 157 
 158 static const char* get_jimage_version_string() {
 159   static char version_string[10] = "";
 160   if (version_string[0] == '\0') {
 161     jio_snprintf(version_string, sizeof(version_string), "%d.%d",
 162                  VM_Version::vm_major_version(), VM_Version::vm_minor_version());
 163   }
 164   return (const char*)version_string;
 165 }


 263   char* pkg_name = NEW_RESOURCE_ARRAY(char, length + 1);
 264   strncpy(pkg_name, class_name_ptr, length);
 265   *(pkg_name+length) = '\0';
 266 
 267   return (const char *)pkg_name;
 268 }
 269 
 270 // Given a fully qualified class name, find its defining package in the class loader's
 271 // package entry table.
 272 PackageEntry* ClassLoader::get_package_entry(const char* class_name, ClassLoaderData* loader_data, TRAPS) {
 273   ResourceMark rm(THREAD);
 274   const char *pkg_name = ClassLoader::package_from_name(class_name);
 275   if (pkg_name == NULL) {
 276     return NULL;
 277   }
 278   PackageEntryTable* pkgEntryTable = loader_data->packages();
 279   TempNewSymbol pkg_symbol = SymbolTable::new_symbol(pkg_name);
 280   return pkgEntryTable->lookup_only(pkg_symbol);
 281 }
 282 
 283 const char* ClassPathEntry::copy_path(const char* path) {
 284   char* copy = NEW_C_HEAP_ARRAY(char, strlen(path)+1, mtClass);
 285   strcpy(copy, path);
 286   return copy;
 287 }
 288 

 289 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
 290   // construct full path name
 291   assert((_dir != NULL) && (name != NULL), "sanity");
 292   size_t path_len = strlen(_dir) + strlen(name) + strlen(os::file_separator()) + 1;
 293   char* path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, path_len);
 294   int len = jio_snprintf(path, path_len, "%s%s%s", _dir, os::file_separator(), name);
 295   assert(len == (int)(path_len - 1), "sanity");
 296   // check if file exists
 297   struct stat st;
 298   if (os::stat(path, &st) == 0) {
 299     // found file, open it
 300     int file_handle = os::open(path, 0, 0);
 301     if (file_handle != -1) {
 302       // read contents into resource array
 303       u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size);
 304       size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
 305       // close file
 306       os::close(file_handle);
 307       // construct ClassFileStream
 308       if (num_read == (size_t)st.st_size) {
 309         if (UsePerfData) {
 310           ClassLoader::perf_sys_classfile_bytes_read()->inc(num_read);
 311         }
 312         FREE_RESOURCE_ARRAY(char, path, path_len);
 313         // Resource allocated
 314         return new ClassFileStream(buffer,
 315                                    st.st_size,
 316                                    _dir,
 317                                    ClassFileStream::verify);
 318       }
 319     }
 320   }
 321   FREE_RESOURCE_ARRAY(char, path, path_len);
 322   return NULL;
 323 }
 324 
 325 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name,
 326                                      bool is_boot_append, bool from_class_path_attr) : ClassPathEntry() {
 327   _zip = zip;
 328   _zip_name = copy_path(zip_name);


 329   _from_class_path_attr = from_class_path_attr;
 330 }
 331 
 332 ClassPathZipEntry::~ClassPathZipEntry() {
 333   if (ZipClose != NULL) {
 334     (*ZipClose)(_zip);
 335   }
 336   FREE_C_HEAP_ARRAY(char, _zip_name);
 337 }
 338 
 339 u1* ClassPathZipEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) {
 340     // enable call to C land
 341   JavaThread* thread = JavaThread::current();
 342   ThreadToNativeFromVM ttn(thread);
 343   // check whether zip archive contains name
 344   jint name_len;
 345   jzentry* entry = (*FindEntry)(_zip, name, filesize, &name_len);
 346   if (entry == NULL) return NULL;
 347   u1* buffer;
 348   char name_buf[128];


 393   }
 394 }
 395 
 396 DEBUG_ONLY(ClassPathImageEntry* ClassPathImageEntry::_singleton = NULL;)
 397 
 398 void ClassPathImageEntry::close_jimage() {
 399   if (_jimage != NULL) {
 400     (*JImageClose)(_jimage);
 401     _jimage = NULL;
 402   }
 403 }
 404 
 405 ClassPathImageEntry::ClassPathImageEntry(JImageFile* jimage, const char* name) :
 406   ClassPathEntry(),
 407   _jimage(jimage) {
 408   guarantee(jimage != NULL, "jimage file is null");
 409   guarantee(name != NULL, "jimage file name is null");
 410   assert(_singleton == NULL, "VM supports only one jimage");
 411   DEBUG_ONLY(_singleton = this);
 412   size_t len = strlen(name) + 1;
 413   _name = copy_path(name);

 414 }
 415 
 416 ClassPathImageEntry::~ClassPathImageEntry() {
 417   assert(_singleton == this, "must be");
 418   DEBUG_ONLY(_singleton = NULL);
 419 
 420   if (_name != NULL) {
 421     FREE_C_HEAP_ARRAY(const char, _name);
 422     _name = NULL;
 423   }
 424   if (_jimage != NULL) {
 425     (*JImageClose)(_jimage);
 426     _jimage = NULL;
 427   }
 428 }
 429 
 430 ClassFileStream* ClassPathImageEntry::open_stream(const char* name, TRAPS) {
 431   return open_stream_for_loader(name, ClassLoaderData::the_null_class_loader_data(), THREAD);
 432 }
 433 


 546         // as print_cr() has a length limit
 547         while (name[0] != '\0') {
 548           ls.print("%c", name[0]);
 549           name++;
 550         }
 551       }
 552     }
 553     ls.cr();
 554   }
 555 }
 556 
 557 void ClassLoader::setup_bootstrap_search_path() {
 558   const char* sys_class_path = Arguments::get_sysclasspath();
 559   assert(sys_class_path != NULL, "System boot class path must not be NULL");
 560   if (PrintSharedArchiveAndExit) {
 561     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
 562     // the same as the bootcp of the shared archive.
 563   } else {
 564     trace_class_path("bootstrap loader class path=", sys_class_path);
 565   }





 566   setup_boot_search_path(sys_class_path);
 567 }
 568 
 569 #if INCLUDE_CDS















 570 void ClassLoader::setup_app_search_path(const char *class_path) {
 571   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Sanity");
 572 
 573   ResourceMark rm;
 574   ClasspathStream cp_stream(class_path);
 575 
 576   while (cp_stream.has_next()) {
 577     const char* path = cp_stream.get_next();
 578     update_class_path_entry_list(path, false, false, false);
 579   }
 580 }
 581 
 582 void ClassLoader::add_to_module_path_entries(const char* path,
 583                                              ClassPathEntry* entry) {
 584   assert(entry != NULL, "ClassPathEntry should not be NULL");
 585   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "dump time only");
 586 
 587   // The entry does not exist, add to the list
 588   if (_module_path_entries == NULL) {
 589     assert(_last_module_path_entry == NULL, "Sanity");


 932                                                bool throw_exception) {
 933   struct stat st;
 934   if (os::stat(path, &st) == 0) {
 935     // File or directory found
 936     ClassPathEntry* new_entry = NULL;
 937     Thread* THREAD = Thread::current();
 938     new_entry = create_class_path_entry(path, &st, throw_exception, is_boot_append, from_class_path_attr, CHECK_(false));
 939     if (new_entry == NULL) {
 940       return false;
 941     }
 942 
 943     // Do not reorder the bootclasspath which would break get_system_package().
 944     // Add new entry to linked list
 945     if (is_boot_append) {
 946       add_to_boot_append_entries(new_entry);
 947     } else {
 948       add_to_app_classpath_entries(path, new_entry, check_for_duplicates);
 949     }
 950     return true;
 951   } else {





 952     return false;
 953   }
 954 }
 955 
 956 static void print_module_entry_table(const GrowableArray<ModuleClassPathList*>* const module_list) {
 957   ResourceMark rm;
 958   int num_of_entries = module_list->length();
 959   for (int i = 0; i < num_of_entries; i++) {
 960     ClassPathEntry* e;
 961     ModuleClassPathList* mpl = module_list->at(i);
 962     tty->print("%s=", mpl->module_name()->as_C_string());
 963     e = mpl->module_first_entry();
 964     while (e != NULL) {
 965       tty->print("%s", e->name());
 966       e = e->next();
 967       if (e != NULL) {
 968         tty->print("%s", os::path_separator());
 969       }
 970     }
 971     tty->print(" ;");


1551     NEWPERFEVENTCOUNTER(_sync_systemLoaderLockContentionRate, SUN_CLS,
1552                         "systemLoaderLockContentionRate");
1553     NEWPERFEVENTCOUNTER(_sync_nonSystemLoaderLockContentionRate, SUN_CLS,
1554                         "nonSystemLoaderLockContentionRate");
1555     NEWPERFEVENTCOUNTER(_sync_JVMFindLoadedClassLockFreeCounter, SUN_CLS,
1556                         "jvmFindLoadedClassNoLockCalls");
1557     NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS,
1558                         "jvmDefineClassNoLockCalls");
1559 
1560     NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS,
1561                         "jniDefineClassNoLockCalls");
1562 
1563     NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS,
1564                         "unsafeDefineClassCalls");
1565   }
1566 
1567   // lookup zip library entry points
1568   load_zip_library();
1569   // lookup jimage library entry points
1570   load_jimage_library();
1571 





1572   setup_bootstrap_search_path();
1573 }
1574 
1575 #if INCLUDE_CDS
1576 void ClassLoader::initialize_shared_path() {
1577   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
1578     ClassLoaderExt::setup_search_paths();

1579   }
1580 }
1581 
1582 void ClassLoader::initialize_module_path(TRAPS) {
1583   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
1584     ClassLoaderExt::setup_module_paths(THREAD);
1585     FileMapInfo::allocate_shared_path_table();
1586   }
1587 }
1588 #endif
1589 
1590 jlong ClassLoader::classloader_time_ms() {
1591   return UsePerfData ?
1592     Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1593 }
1594 
1595 jlong ClassLoader::class_init_count() {
1596   return UsePerfData ? _perf_classes_inited->get_value() : -1;
1597 }
1598 


< prev index next >