src/hotspot/share/classfile/classLoader.cpp
changeset 49931 840e26123940
parent 49843 e0af66d6e968
child 49982 9042ffe5b7fe
equal deleted inserted replaced
49930:3aaaa5370999 49931:840e26123940
   268   int len = jio_snprintf(path, path_len, "%s%s%s", _dir, os::file_separator(), name);
   268   int len = jio_snprintf(path, path_len, "%s%s%s", _dir, os::file_separator(), name);
   269   assert(len == (int)(path_len - 1), "sanity");
   269   assert(len == (int)(path_len - 1), "sanity");
   270   // check if file exists
   270   // check if file exists
   271   struct stat st;
   271   struct stat st;
   272   if (os::stat(path, &st) == 0) {
   272   if (os::stat(path, &st) == 0) {
   273 #if INCLUDE_CDS
       
   274     if (DumpSharedSpaces) {
       
   275       // We have already check in ClassLoader::check_shared_classpath() that the directory is empty, so
       
   276       // we should never find a file underneath it -- unless user has added a new file while we are running
       
   277       // the dump, in which case let's quit!
       
   278       ShouldNotReachHere();
       
   279     }
       
   280 #endif
       
   281     // found file, open it
   273     // found file, open it
   282     int file_handle = os::open(path, 0, 0);
   274     int file_handle = os::open(path, 0, 0);
   283     if (file_handle != -1) {
   275     if (file_handle != -1) {
   284       // read contents into resource array
   276       // read contents into resource array
   285       u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size);
   277       u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size);
   642     }
   634     }
   643     ls.cr();
   635     ls.cr();
   644   }
   636   }
   645 }
   637 }
   646 
   638 
   647 #if INCLUDE_CDS
       
   648 void ClassLoader::check_shared_classpath(const char *path) {
       
   649   if (strcmp(path, "") == 0) {
       
   650     exit_with_path_failure("Cannot have empty path in archived classpaths", NULL);
       
   651   }
       
   652 
       
   653   struct stat st;
       
   654   if (os::stat(path, &st) == 0) {
       
   655     if ((st.st_mode & S_IFMT) != S_IFREG) { // is not a regular file
       
   656       if (!os::dir_is_empty(path)) {
       
   657         tty->print_cr("Error: non-empty directory '%s'", path);
       
   658         exit_with_path_failure("CDS allows only empty directories in archived classpaths", NULL);
       
   659       }
       
   660     }
       
   661   }
       
   662 }
       
   663 #endif
       
   664 
       
   665 void ClassLoader::setup_bootstrap_search_path() {
   639 void ClassLoader::setup_bootstrap_search_path() {
   666   const char* sys_class_path = Arguments::get_sysclasspath();
   640   const char* sys_class_path = Arguments::get_sysclasspath();
   667   if (PrintSharedArchiveAndExit) {
   641   if (PrintSharedArchiveAndExit) {
   668     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
   642     // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
   669     // the same as the bootcp of the shared archive.
   643     // the same as the bootcp of the shared archive.
   710     EXCEPTION_MARK;
   684     EXCEPTION_MARK;
   711     ResourceMark rm(THREAD);
   685     ResourceMark rm(THREAD);
   712     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
   686     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
   713     strncpy(path, &class_path[start], end - start);
   687     strncpy(path, &class_path[start], end - start);
   714     path[end - start] = '\0';
   688     path[end - start] = '\0';
   715 
       
   716     check_shared_classpath(path);
       
   717 
   689 
   718     update_class_path_entry_list(path, false, false);
   690     update_class_path_entry_list(path, false, false);
   719 
   691 
   720     while (class_path[end] == os::path_separator()[0]) {
   692     while (class_path[end] == os::path_separator()[0]) {
   721       end++;
   693       end++;
   755   add_to_module_path_entries(path, new_entry);
   727   add_to_module_path_entries(path, new_entry);
   756   return;
   728   return;
   757 }
   729 }
   758 
   730 
   759 void ClassLoader::setup_module_search_path(const char* path, TRAPS) {
   731 void ClassLoader::setup_module_search_path(const char* path, TRAPS) {
   760   check_shared_classpath(path);
       
   761   update_module_path_entry_list(path, THREAD);
   732   update_module_path_entry_list(path, THREAD);
   762 }
   733 }
   763 #endif // INCLUDE_CDS
   734 #endif // INCLUDE_CDS
   764 
   735 
   765 // Construct the array of module/path pairs as specified to --patch-module
   736 // Construct the array of module/path pairs as specified to --patch-module
   884       // Every entry on the system boot class path after the initial base piece,
   855       // Every entry on the system boot class path after the initial base piece,
   885       // which is set by os::set_boot_path(), is considered an appended entry.
   856       // which is set by os::set_boot_path(), is considered an appended entry.
   886       update_class_path_entry_list(path, false, true);
   857       update_class_path_entry_list(path, false, true);
   887     }
   858     }
   888 
   859 
   889 #if INCLUDE_CDS
       
   890     if (DumpSharedSpaces) {
       
   891       check_shared_classpath(path);
       
   892     }
       
   893 #endif
       
   894     while (class_path[end] == os::path_separator()[0]) {
   860     while (class_path[end] == os::path_separator()[0]) {
   895       end++;
   861       end++;
   896     }
   862     }
   897   }
   863   }
   898 }
   864 }
  1080     _last_app_classpath_entry = entry;
  1046     _last_app_classpath_entry = entry;
  1081   }
  1047   }
  1082 
  1048 
  1083   if (entry->is_jar_file()) {
  1049   if (entry->is_jar_file()) {
  1084     ClassLoaderExt::process_jar_manifest(entry, check_for_duplicates);
  1050     ClassLoaderExt::process_jar_manifest(entry, check_for_duplicates);
  1085   } else {
       
  1086     if (!os::dir_is_empty(path)) {
       
  1087       tty->print_cr("Error: non-empty directory '%s'", path);
       
  1088       exit_with_path_failure("Cannot have non-empty directory in app classpaths", NULL);
       
  1089     }
       
  1090   }
  1051   }
  1091 #endif
  1052 #endif
  1092 }
  1053 }
  1093 
  1054 
  1094 // Returns true IFF the file/dir exists and the entry was successfully created.
  1055 // Returns true IFF the file/dir exists and the entry was successfully created.