src/hotspot/share/classfile/classLoader.cpp
changeset 57898 5ddb746d45e0
parent 57897 e2e315f1aa63
child 58084 cddef3bde924
equal deleted inserted replaced
57897:e2e315f1aa63 57898:5ddb746d45e0
    71 #include "services/threadService.hpp"
    71 #include "services/threadService.hpp"
    72 #include "utilities/classpathStream.hpp"
    72 #include "utilities/classpathStream.hpp"
    73 #include "utilities/events.hpp"
    73 #include "utilities/events.hpp"
    74 #include "utilities/hashtable.inline.hpp"
    74 #include "utilities/hashtable.inline.hpp"
    75 #include "utilities/macros.hpp"
    75 #include "utilities/macros.hpp"
    76 #if INCLUDE_CDS
       
    77 #include "classfile/sharedPathsMiscInfo.hpp"
       
    78 #endif
       
    79 
    76 
    80 // Entry points in zip.dll for loading zip/jar file entries
    77 // Entry points in zip.dll for loading zip/jar file entries
    81 
    78 
    82 typedef void * * (*ZipOpen_t)(const char *name, char **pmsg);
    79 typedef void * * (*ZipOpen_t)(const char *name, char **pmsg);
    83 typedef void (*ZipClose_t)(jzfile *zip);
    80 typedef void (*ZipClose_t)(jzfile *zip);
   145 #if INCLUDE_CDS
   142 #if INCLUDE_CDS
   146 ClassPathEntry* ClassLoader::_app_classpath_entries = NULL;
   143 ClassPathEntry* ClassLoader::_app_classpath_entries = NULL;
   147 ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL;
   144 ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL;
   148 ClassPathEntry* ClassLoader::_module_path_entries = NULL;
   145 ClassPathEntry* ClassLoader::_module_path_entries = NULL;
   149 ClassPathEntry* ClassLoader::_last_module_path_entry = NULL;
   146 ClassPathEntry* ClassLoader::_last_module_path_entry = NULL;
   150 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
       
   151 #endif
   147 #endif
   152 
   148 
   153 // helper routines
   149 // helper routines
   154 bool string_starts_with(const char* str, const char* str_to_find) {
   150 bool string_starts_with(const char* str, const char* str_to_find) {
   155   size_t str_len = strlen(str);
   151   size_t str_len = strlen(str);
   248   PackageEntryTable* pkgEntryTable = loader_data->packages();
   244   PackageEntryTable* pkgEntryTable = loader_data->packages();
   249   TempNewSymbol pkg_symbol = SymbolTable::new_symbol(pkg_name);
   245   TempNewSymbol pkg_symbol = SymbolTable::new_symbol(pkg_name);
   250   return pkgEntryTable->lookup_only(pkg_symbol);
   246   return pkgEntryTable->lookup_only(pkg_symbol);
   251 }
   247 }
   252 
   248 
   253 ClassPathDirEntry::ClassPathDirEntry(const char* dir) : ClassPathEntry() {
   249 const char* ClassPathEntry::copy_path(const char* path) {
   254   char* copy = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass);
   250   char* copy = NEW_C_HEAP_ARRAY(char, strlen(path)+1, mtClass);
   255   strcpy(copy, dir);
   251   strcpy(copy, path);
   256   _dir = copy;
   252   return copy;
   257 }
   253 }
   258 
       
   259 
   254 
   260 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
   255 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
   261   // construct full path name
   256   // construct full path name
   262   assert((_dir != NULL) && (name != NULL), "sanity");
   257   assert((_dir != NULL) && (name != NULL), "sanity");
   263   size_t path_len = strlen(_dir) + strlen(name) + strlen(os::file_separator()) + 1;
   258   size_t path_len = strlen(_dir) + strlen(name) + strlen(os::file_separator()) + 1;
   294 }
   289 }
   295 
   290 
   296 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name,
   291 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name,
   297                                      bool is_boot_append, bool from_class_path_attr) : ClassPathEntry() {
   292                                      bool is_boot_append, bool from_class_path_attr) : ClassPathEntry() {
   298   _zip = zip;
   293   _zip = zip;
   299   char *copy = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass);
   294   _zip_name = copy_path(zip_name);
   300   strcpy(copy, zip_name);
       
   301   _zip_name = copy;
       
   302   _from_class_path_attr = from_class_path_attr;
   295   _from_class_path_attr = from_class_path_attr;
   303 }
   296 }
   304 
   297 
   305 ClassPathZipEntry::~ClassPathZipEntry() {
   298 ClassPathZipEntry::~ClassPathZipEntry() {
   306   if (ZipClose != NULL) {
   299   if (ZipClose != NULL) {
   381   guarantee(jimage != NULL, "jimage file is null");
   374   guarantee(jimage != NULL, "jimage file is null");
   382   guarantee(name != NULL, "jimage file name is null");
   375   guarantee(name != NULL, "jimage file name is null");
   383   assert(_singleton == NULL, "VM supports only one jimage");
   376   assert(_singleton == NULL, "VM supports only one jimage");
   384   DEBUG_ONLY(_singleton = this);
   377   DEBUG_ONLY(_singleton = this);
   385   size_t len = strlen(name) + 1;
   378   size_t len = strlen(name) + 1;
   386   _name = NEW_C_HEAP_ARRAY(const char, len, mtClass);
   379   _name = copy_path(name);
   387   strncpy((char *)_name, name, len);
       
   388 }
   380 }
   389 
   381 
   390 ClassPathImageEntry::~ClassPathImageEntry() {
   382 ClassPathImageEntry::~ClassPathImageEntry() {
   391   assert(_singleton == this, "must be");
   383   assert(_singleton == this, "must be");
   392   DEBUG_ONLY(_singleton = NULL);
   384   DEBUG_ONLY(_singleton = NULL);
   535     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
   527     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
   536     // the same as the bootcp of the shared archive.
   528     // the same as the bootcp of the shared archive.
   537   } else {
   529   } else {
   538     trace_class_path("bootstrap loader class path=", sys_class_path);
   530     trace_class_path("bootstrap loader class path=", sys_class_path);
   539   }
   531   }
       
   532   setup_boot_search_path(sys_class_path);
       
   533 }
       
   534 
   540 #if INCLUDE_CDS
   535 #if INCLUDE_CDS
   541   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
       
   542     _shared_paths_misc_info->add_boot_classpath(sys_class_path);
       
   543   }
       
   544 #endif
       
   545   setup_boot_search_path(sys_class_path);
       
   546 }
       
   547 
       
   548 #if INCLUDE_CDS
       
   549 int ClassLoader::get_shared_paths_misc_info_size() {
       
   550   return _shared_paths_misc_info->get_used_bytes();
       
   551 }
       
   552 
       
   553 void* ClassLoader::get_shared_paths_misc_info() {
       
   554   return _shared_paths_misc_info->buffer();
       
   555 }
       
   556 
       
   557 bool ClassLoader::check_shared_paths_misc_info(void *buf, int size, bool is_static) {
       
   558   SharedPathsMiscInfo* checker = new SharedPathsMiscInfo((char*)buf, size);
       
   559   bool result = checker->check(is_static);
       
   560   delete checker;
       
   561   return result;
       
   562 }
       
   563 
       
   564 void ClassLoader::setup_app_search_path(const char *class_path) {
   536 void ClassLoader::setup_app_search_path(const char *class_path) {
   565   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Sanity");
   537   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Sanity");
   566 
   538 
   567   ResourceMark rm;
   539   ResourceMark rm;
   568   ClasspathStream cp_stream(class_path);
   540   ClasspathStream cp_stream(class_path);
   941     } else {
   913     } else {
   942       add_to_app_classpath_entries(path, new_entry, check_for_duplicates);
   914       add_to_app_classpath_entries(path, new_entry, check_for_duplicates);
   943     }
   915     }
   944     return true;
   916     return true;
   945   } else {
   917   } else {
   946 #if INCLUDE_CDS
       
   947     if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
       
   948       _shared_paths_misc_info->add_nonexist_path(path);
       
   949     }
       
   950 #endif
       
   951     return false;
   918     return false;
   952   }
   919   }
   953 }
   920 }
   954 
   921 
   955 static void print_module_entry_table(const GrowableArray<ModuleClassPathList*>* const module_list) {
   922 static void print_module_entry_table(const GrowableArray<ModuleClassPathList*>* const module_list) {
  1565 
  1532 
  1566   // lookup zip library entry points
  1533   // lookup zip library entry points
  1567   load_zip_library();
  1534   load_zip_library();
  1568   // lookup jimage library entry points
  1535   // lookup jimage library entry points
  1569   load_jimage_library();
  1536   load_jimage_library();
  1570 #if INCLUDE_CDS
       
  1571   // initialize search path
       
  1572   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
       
  1573     _shared_paths_misc_info = new SharedPathsMiscInfo();
       
  1574   }
       
  1575 #endif
       
  1576   setup_bootstrap_search_path();
  1537   setup_bootstrap_search_path();
  1577 }
  1538 }
  1578 
  1539 
  1579 #if INCLUDE_CDS
  1540 #if INCLUDE_CDS
  1580 void ClassLoader::initialize_shared_path() {
  1541 void ClassLoader::initialize_shared_path() {
  1581   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
  1542   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
  1582     ClassLoaderExt::setup_search_paths();
  1543     ClassLoaderExt::setup_search_paths();
  1583     _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
       
  1584   }
  1544   }
  1585 }
  1545 }
  1586 
  1546 
  1587 void ClassLoader::initialize_module_path(TRAPS) {
  1547 void ClassLoader::initialize_module_path(TRAPS) {
  1588   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
  1548   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {