hotspot/src/share/vm/classfile/classLoader.cpp
changeset 26419 25abc4a3285c
parent 26135 82b516c550f7
child 26583 2ef7b85da46b
equal deleted inserted replaced
26418:16ac9bcf600a 26419:25abc4a3285c
   187 
   187 
   188 bool ClassPathEntry::is_lazy() {
   188 bool ClassPathEntry::is_lazy() {
   189   return false;
   189   return false;
   190 }
   190 }
   191 
   191 
   192 ClassPathDirEntry::ClassPathDirEntry(char* dir) : ClassPathEntry() {
   192 ClassPathDirEntry::ClassPathDirEntry(const char* dir) : ClassPathEntry() {
   193   _dir = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass);
   193   char* copy = NEW_C_HEAP_ARRAY(char, strlen(dir)+1, mtClass);
   194   strcpy(_dir, dir);
   194   strcpy(copy, dir);
       
   195   _dir = copy;
   195 }
   196 }
   196 
   197 
   197 
   198 
   198 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
   199 ClassFileStream* ClassPathDirEntry::open_stream(const char* name, TRAPS) {
   199   // construct full path name
   200   // construct full path name
   233 }
   234 }
   234 
   235 
   235 
   236 
   236 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() {
   237 ClassPathZipEntry::ClassPathZipEntry(jzfile* zip, const char* zip_name) : ClassPathEntry() {
   237   _zip = zip;
   238   _zip = zip;
   238   _zip_name = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass);
   239   char *copy = NEW_C_HEAP_ARRAY(char, strlen(zip_name)+1, mtClass);
   239   strcpy(_zip_name, zip_name);
   240   strcpy(copy, zip_name);
       
   241   _zip_name = copy;
   240 }
   242 }
   241 
   243 
   242 ClassPathZipEntry::~ClassPathZipEntry() {
   244 ClassPathZipEntry::~ClassPathZipEntry() {
   243   if (ZipClose != NULL) {
   245   if (ZipClose != NULL) {
   244     (*ZipClose)(_zip);
   246     (*ZipClose)(_zip);
   302     if (ze == NULL) break;
   304     if (ze == NULL) break;
   303     (*f)(ze->name, context);
   305     (*f)(ze->name, context);
   304   }
   306   }
   305 }
   307 }
   306 
   308 
   307 LazyClassPathEntry::LazyClassPathEntry(char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() {
   309 LazyClassPathEntry::LazyClassPathEntry(const char* path, const struct stat* st, bool throw_exception) : ClassPathEntry() {
   308   _path = os::strdup_check_oom(path);
   310   _path = os::strdup_check_oom(path);
   309   _st = *st;
   311   _st = *st;
   310   _meta_index = NULL;
   312   _meta_index = NULL;
   311   _resolved_entry = NULL;
   313   _resolved_entry = NULL;
   312   _has_error = false;
   314   _has_error = false;
   313   _throw_exception = throw_exception;
   315   _throw_exception = throw_exception;
   314 }
   316 }
   315 
   317 
   316 LazyClassPathEntry::~LazyClassPathEntry() {
   318 LazyClassPathEntry::~LazyClassPathEntry() {
   317   os::free(_path);
   319   os::free((void*)_path);
   318 }
   320 }
   319 
   321 
   320 bool LazyClassPathEntry::is_jar_file() {
   322 bool LazyClassPathEntry::is_jar_file() {
   321   return ((_st.st_mode & S_IFREG) == S_IFREG);
   323   return ((_st.st_mode & S_IFREG) == S_IFREG);
   322 }
   324 }
   561 }
   563 }
   562 #endif
   564 #endif
   563 
   565 
   564 void ClassLoader::setup_bootstrap_search_path() {
   566 void ClassLoader::setup_bootstrap_search_path() {
   565   assert(_first_entry == NULL, "should not setup bootstrap class search path twice");
   567   assert(_first_entry == NULL, "should not setup bootstrap class search path twice");
   566   char* sys_class_path = os::strdup_check_oom(Arguments::get_sysclasspath());
   568   const char* sys_class_path = Arguments::get_sysclasspath();
   567   if (!PrintSharedArchiveAndExit) {
   569   if (PrintSharedArchiveAndExit) {
       
   570     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
       
   571     // the same as the bootcp of the shared archive.
       
   572   } else {
   568     trace_class_path("[Bootstrap loader class path=", sys_class_path);
   573     trace_class_path("[Bootstrap loader class path=", sys_class_path);
   569   }
   574   }
   570 #if INCLUDE_CDS
   575 #if INCLUDE_CDS
   571   if (DumpSharedSpaces) {
   576   if (DumpSharedSpaces) {
   572     _shared_paths_misc_info->add_boot_classpath(Arguments::get_sysclasspath());
   577     _shared_paths_misc_info->add_boot_classpath(sys_class_path);
   573   }
   578   }
   574 #endif
   579 #endif
   575   setup_search_path(sys_class_path);
   580   setup_search_path(sys_class_path);
   576   os::free(sys_class_path);
       
   577 }
   581 }
   578 
   582 
   579 #if INCLUDE_CDS
   583 #if INCLUDE_CDS
   580 int ClassLoader::get_shared_paths_misc_info_size() {
   584 int ClassLoader::get_shared_paths_misc_info_size() {
   581   return _shared_paths_misc_info->get_used_bytes();
   585   return _shared_paths_misc_info->get_used_bytes();
   591   delete checker;
   595   delete checker;
   592   return result;
   596   return result;
   593 }
   597 }
   594 #endif
   598 #endif
   595 
   599 
   596 void ClassLoader::setup_search_path(char *class_path) {
   600 void ClassLoader::setup_search_path(const char *class_path) {
   597   int offset = 0;
   601   int offset = 0;
   598   int len = (int)strlen(class_path);
   602   int len = (int)strlen(class_path);
   599   int end = 0;
   603   int end = 0;
   600 
   604 
   601   // Iterate over class path entries
   605   // Iterate over class path entries
   618       end++;
   622       end++;
   619     }
   623     }
   620   }
   624   }
   621 }
   625 }
   622 
   626 
   623 ClassPathEntry* ClassLoader::create_class_path_entry(char *path, const struct stat* st,
   627 ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const struct stat* st,
   624                                                      bool lazy, bool throw_exception, TRAPS) {
   628                                                      bool lazy, bool throw_exception, TRAPS) {
   625   JavaThread* thread = JavaThread::current();
   629   JavaThread* thread = JavaThread::current();
   626   if (lazy) {
   630   if (lazy) {
   627     return new LazyClassPathEntry(path, st, throw_exception);
   631     return new LazyClassPathEntry(path, st, throw_exception);
   628   }
   632   }
   685 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) {
   689 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path) {
   686   // check for a regular file
   690   // check for a regular file
   687   struct stat st;
   691   struct stat st;
   688   if (os::stat(path, &st) == 0) {
   692   if (os::stat(path, &st) == 0) {
   689     if ((st.st_mode & S_IFREG) == S_IFREG) {
   693     if ((st.st_mode & S_IFREG) == S_IFREG) {
   690       char orig_path[JVM_MAXPATHLEN];
       
   691       char canonical_path[JVM_MAXPATHLEN];
   694       char canonical_path[JVM_MAXPATHLEN];
   692 
   695       if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) {
   693       strcpy(orig_path, path);
       
   694       if (get_canonical_path(orig_path, canonical_path, JVM_MAXPATHLEN)) {
       
   695         char* error_msg = NULL;
   696         char* error_msg = NULL;
   696         jzfile* zip;
   697         jzfile* zip;
   697         {
   698         {
   698           // enable call to C land
   699           // enable call to C land
   699           JavaThread* thread = JavaThread::current();
   700           JavaThread* thread = JavaThread::current();
   735   }
   736   }
   736   _num_entries ++;
   737   _num_entries ++;
   737 }
   738 }
   738 
   739 
   739 // Returns true IFF the file/dir exists and the entry was successfully created.
   740 // Returns true IFF the file/dir exists and the entry was successfully created.
   740 bool ClassLoader::update_class_path_entry_list(char *path,
   741 bool ClassLoader::update_class_path_entry_list(const char *path,
   741                                                bool check_for_duplicates,
   742                                                bool check_for_duplicates,
   742                                                bool throw_exception) {
   743                                                bool throw_exception) {
   743   struct stat st;
   744   struct stat st;
   744   if (os::stat(path, &st) == 0) {
   745   if (os::stat(path, &st) == 0) {
   745     // File or directory found
   746     // File or directory found
   760   } else {
   761   } else {
   761 #if INCLUDE_CDS
   762 #if INCLUDE_CDS
   762     if (DumpSharedSpaces) {
   763     if (DumpSharedSpaces) {
   763       _shared_paths_misc_info->add_nonexist_path(path);
   764       _shared_paths_misc_info->add_nonexist_path(path);
   764     }
   765     }
       
   766 #endif
   765     return false;
   767     return false;
   766 #endif
       
   767   }
   768   }
   768 }
   769 }
   769 
   770 
   770 void ClassLoader::print_bootclasspath() {
   771 void ClassLoader::print_bootclasspath() {
   771   ClassPathEntry* e = _first_entry;
   772   ClassPathEntry* e = _first_entry;
  1267 void classLoader_init() {
  1268 void classLoader_init() {
  1268   ClassLoader::initialize();
  1269   ClassLoader::initialize();
  1269 }
  1270 }
  1270 
  1271 
  1271 
  1272 
  1272 bool ClassLoader::get_canonical_path(char* orig, char* out, int len) {
  1273 bool ClassLoader::get_canonical_path(const char* orig, char* out, int len) {
  1273   assert(orig != NULL && out != NULL && len > 0, "bad arguments");
  1274   assert(orig != NULL && out != NULL && len > 0, "bad arguments");
  1274   if (CanonicalizeEntry != NULL) {
  1275   if (CanonicalizeEntry != NULL) {
  1275     JNIEnv* env = JavaThread::current()->jni_environment();
  1276     JavaThread* THREAD = JavaThread::current();
  1276     if ((CanonicalizeEntry)(env, os::native_path(orig), out, len) < 0) {
  1277     JNIEnv* env = THREAD->jni_environment();
       
  1278     ResourceMark rm(THREAD);
       
  1279 
       
  1280     // os::native_path writes into orig_copy
       
  1281     char* orig_copy = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, strlen(orig)+1);
       
  1282     strcpy(orig_copy, orig);
       
  1283     if ((CanonicalizeEntry)(env, os::native_path(orig_copy), out, len) < 0) {
  1277       return false;
  1284       return false;
  1278     }
  1285     }
  1279   } else {
  1286   } else {
  1280     // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing
  1287     // On JDK 1.2.2 the Canonicalize does not exist, so just do nothing
  1281     strncpy(out, orig, len);
  1288     strncpy(out, orig, len);