< prev index next >

src/hotspot/share/classfile/classLoader.cpp

Print this page




 122 PerfCounter*    ClassLoader::_perf_app_classload_time = NULL;
 123 PerfCounter*    ClassLoader::_perf_app_classload_selftime = NULL;
 124 PerfCounter*    ClassLoader::_perf_app_classload_count = NULL;
 125 PerfCounter*    ClassLoader::_perf_define_appclasses = NULL;
 126 PerfCounter*    ClassLoader::_perf_define_appclass_time = NULL;
 127 PerfCounter*    ClassLoader::_perf_define_appclass_selftime = NULL;
 128 PerfCounter*    ClassLoader::_perf_app_classfile_bytes_read = NULL;
 129 PerfCounter*    ClassLoader::_perf_sys_classfile_bytes_read = NULL;
 130 PerfCounter*    ClassLoader::_sync_systemLoaderLockContentionRate = NULL;
 131 PerfCounter*    ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL;
 132 PerfCounter*    ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL;
 133 PerfCounter*    ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL;
 134 PerfCounter*    ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
 135 PerfCounter*    ClassLoader::_unsafe_defineClassCallCounter = NULL;
 136 
 137 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = NULL;
 138 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
 139 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
 140 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
 141 ClassPathEntry* ClassLoader::_last_append_entry  = NULL;

 142 #if INCLUDE_CDS
 143 ClassPathEntry* ClassLoader::_app_classpath_entries = NULL;
 144 ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL;
 145 ClassPathEntry* ClassLoader::_module_path_entries = NULL;
 146 ClassPathEntry* ClassLoader::_last_module_path_entry = NULL;
 147 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
 148 #endif
 149 
 150 // helper routines
 151 bool string_starts_with(const char* str, const char* str_to_find) {
 152   size_t str_len = strlen(str);
 153   size_t str_to_find_len = strlen(str_to_find);
 154   if (str_to_find_len > str_len) {
 155     return false;
 156   }
 157   return (strncmp(str, str_to_find, str_to_find_len) == 0);
 158 }
 159 
 160 static const char* get_jimage_version_string() {
 161   static char version_string[10] = "";


 681       _patch_mod_entries->push(module_cpl);
 682     }
 683   }
 684 }
 685 
 686 // Determine whether the module has been patched via the command-line
 687 // option --patch-module
 688 bool ClassLoader::is_in_patch_mod_entries(Symbol* module_name) {
 689   if (_patch_mod_entries != NULL && _patch_mod_entries->is_nonempty()) {
 690     int table_len = _patch_mod_entries->length();
 691     for (int i = 0; i < table_len; i++) {
 692       ModuleClassPathList* patch_mod = _patch_mod_entries->at(i);
 693       if (module_name->fast_compare(patch_mod->module_name()) == 0) {
 694         return true;
 695       }
 696     }
 697   }
 698   return false;
 699 }
 700 
































 701 // Set up the _jrt_entry if present and boot append path
 702 void ClassLoader::setup_boot_search_path(const char *class_path) {
 703   int len = (int)strlen(class_path);
 704   int end = 0;
 705   bool set_base_piece = true;
 706 
 707 #if INCLUDE_CDS
 708   if (DumpSharedSpaces) {
 709     if (!Arguments::has_jimage()) {
 710       vm_exit_during_initialization("CDS is not supported in exploded JDK build", NULL);
 711     }
 712   }
 713 #endif
 714 
 715   // Iterate over class path entries
 716   for (int start = 0; start < len; start = end) {
 717     while (class_path[end] && class_path[end] != os::path_separator()[0]) {
 718       end++;
 719     }
 720     EXCEPTION_MARK;
 721     ResourceMark rm(THREAD);
 722     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
 723     strncpy(path, &class_path[start], end - start);
 724     path[end - start] = '\0';
 725 
 726     if (set_base_piece) {
 727       // The first time through the bootstrap_search setup, it must be determined
 728       // what the base or core piece of the boot loader search is.  Either a java runtime
 729       // image is present or this is an exploded module build situation.
 730       assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, JAVA_BASE_NAME),
 731              "Incorrect boot loader search path, no java runtime image or " JAVA_BASE_NAME " exploded build");
 732       struct stat st;
 733       if (os::stat(path, &st) == 0) {
 734         // Directory found
 735         ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, CHECK);
 736 
 737         // Check for a jimage
 738         if (Arguments::has_jimage()) {


 739           assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice");
 740           assert(new_entry != NULL && new_entry->is_modules_image(), "No java runtime image present");
 741           _jrt_entry = new_entry;
 742           assert(_jrt_entry->jimage() != NULL, "No java runtime image");
 743         }
 744       } else {
 745         // If path does not exist, exit
 746         vm_exit_during_initialization("Unable to establish the boot loader search path", path);
 747       }
 748       set_base_piece = false;
 749     } else {
 750       // Every entry on the system boot class path after the initial base piece,
 751       // which is set by os::set_boot_path(), is considered an appended entry.
 752       update_class_path_entry_list(path, false, true);
 753     }
 754 
 755     while (class_path[end] == os::path_separator()[0]) {
 756       end++;
 757     }
 758   }


 829       if (zip != NULL && error_msg == NULL) {
 830         new_entry = new ClassPathZipEntry(zip, path, is_boot_append);
 831       } else {
 832         char *msg;
 833         if (error_msg == NULL) {
 834           msg = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, strlen(path) + 128); ;
 835           jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path);
 836         } else {
 837           int len = (int)(strlen(path) + strlen(error_msg) + 128);
 838           msg = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, len); ;
 839           jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path);
 840         }
 841         // Don't complain about bad jar files added via -Xbootclasspath/a:.
 842         if (throw_exception && is_init_completed()) {
 843           THROW_MSG_(vmSymbols::java_lang_ClassNotFoundException(), msg, NULL);
 844         } else {
 845           return NULL;
 846         }
 847       }
 848     }
 849     log_info(class, path)("opened: %s", path);
 850     log_info(class, load)("opened: %s", path);
 851   } else {
 852     // Directory
 853     new_entry = new ClassPathDirEntry(path);
 854     log_info(class, load)("path: %s", path);
 855   }
 856   return new_entry;
 857 }
 858 
 859 
 860 // Create a class path zip entry for a given path (return NULL if not found
 861 // or zip/JAR file cannot be opened)
 862 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path, bool is_boot_append) {
 863   // check for a regular file
 864   struct stat st;
 865   if (os::stat(path, &st) == 0) {
 866     if ((st.st_mode & S_IFMT) == S_IFREG) {
 867       char canonical_path[JVM_MAXPATHLEN];
 868       if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) {
 869         char* error_msg = NULL;




 122 PerfCounter*    ClassLoader::_perf_app_classload_time = NULL;
 123 PerfCounter*    ClassLoader::_perf_app_classload_selftime = NULL;
 124 PerfCounter*    ClassLoader::_perf_app_classload_count = NULL;
 125 PerfCounter*    ClassLoader::_perf_define_appclasses = NULL;
 126 PerfCounter*    ClassLoader::_perf_define_appclass_time = NULL;
 127 PerfCounter*    ClassLoader::_perf_define_appclass_selftime = NULL;
 128 PerfCounter*    ClassLoader::_perf_app_classfile_bytes_read = NULL;
 129 PerfCounter*    ClassLoader::_perf_sys_classfile_bytes_read = NULL;
 130 PerfCounter*    ClassLoader::_sync_systemLoaderLockContentionRate = NULL;
 131 PerfCounter*    ClassLoader::_sync_nonSystemLoaderLockContentionRate = NULL;
 132 PerfCounter*    ClassLoader::_sync_JVMFindLoadedClassLockFreeCounter = NULL;
 133 PerfCounter*    ClassLoader::_sync_JVMDefineClassLockFreeCounter = NULL;
 134 PerfCounter*    ClassLoader::_sync_JNIDefineClassLockFreeCounter = NULL;
 135 PerfCounter*    ClassLoader::_unsafe_defineClassCallCounter = NULL;
 136 
 137 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = NULL;
 138 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = NULL;
 139 ClassPathEntry* ClassLoader::_jrt_entry = NULL;
 140 ClassPathEntry* ClassLoader::_first_append_entry = NULL;
 141 ClassPathEntry* ClassLoader::_last_append_entry  = NULL;
 142 const char*     ClassLoader::_modules_image_name = MODULES_IMAGE_NAME;
 143 #if INCLUDE_CDS
 144 ClassPathEntry* ClassLoader::_app_classpath_entries = NULL;
 145 ClassPathEntry* ClassLoader::_last_app_classpath_entry = NULL;
 146 ClassPathEntry* ClassLoader::_module_path_entries = NULL;
 147 ClassPathEntry* ClassLoader::_last_module_path_entry = NULL;
 148 SharedPathsMiscInfo* ClassLoader::_shared_paths_misc_info = NULL;
 149 #endif
 150 
 151 // helper routines
 152 bool string_starts_with(const char* str, const char* str_to_find) {
 153   size_t str_len = strlen(str);
 154   size_t str_to_find_len = strlen(str_to_find);
 155   if (str_to_find_len > str_len) {
 156     return false;
 157   }
 158   return (strncmp(str, str_to_find, str_to_find_len) == 0);
 159 }
 160 
 161 static const char* get_jimage_version_string() {
 162   static char version_string[10] = "";


 682       _patch_mod_entries->push(module_cpl);
 683     }
 684   }
 685 }
 686 
 687 // Determine whether the module has been patched via the command-line
 688 // option --patch-module
 689 bool ClassLoader::is_in_patch_mod_entries(Symbol* module_name) {
 690   if (_patch_mod_entries != NULL && _patch_mod_entries->is_nonempty()) {
 691     int table_len = _patch_mod_entries->length();
 692     for (int i = 0; i < table_len; i++) {
 693       ModuleClassPathList* patch_mod = _patch_mod_entries->at(i);
 694       if (module_name->fast_compare(patch_mod->module_name()) == 0) {
 695         return true;
 696       }
 697     }
 698   }
 699   return false;
 700 }
 701 
 702 const char* ClassLoader::skip_directories(const char* path) {
 703   assert(path != NULL, "sanity");
 704 
 705   const char *p1 = path, *p2 = NULL;
 706   const char* fileSep = os::file_separator();
 707   int len = (int)strlen(fileSep);
 708   if (len == 1) {
 709     p2 = strrchr(path, fileSep[0]);
 710     if (p2 != NULL) {
 711       p1 = p2 + 1;
 712     }
 713   } else {
 714     while ((p2 = strstr(p1, fileSep)) != NULL) {
 715       p1 = p2 + len;
 716     }
 717   }
 718   return p1;
 719 }
 720 
 721 // Obtain the canonical name of the MODULES_IMAGE_NAME and save it in
 722 // _modules_image_name.
 723 //
 724 // For most of use cases, ClassLoader::modules_image_name(), which returns the
 725 // canonical name should be used. When dealing with the system boot path string
 726 // that's set up by os::set_boot_path(), then the canonical name cannot be
 727 // used and MODULES_IMAGE_NAME should be used directly.
 728 void ClassLoader::init_modules_image_name(const char* modules_path) {
 729   const char* p = skip_directories(modules_path);
 730   guarantee(strlen(p) > 0, "must be a valid name");
 731   _modules_image_name = os::strdup(p);
 732 }
 733 
 734 // Set up the _jrt_entry if present and boot append path
 735 void ClassLoader::setup_boot_search_path(const char *class_path) {
 736   int len = (int)strlen(class_path);
 737   int end = 0;
 738   bool set_base_piece = true;
 739 
 740 #if INCLUDE_CDS
 741   if (DumpSharedSpaces) {
 742     if (!Arguments::has_jimage()) {
 743       vm_exit_during_initialization("CDS is not supported in exploded JDK build", NULL);
 744     }
 745   }
 746 #endif
 747 
 748   // Iterate over class path entries
 749   for (int start = 0; start < len; start = end) {
 750     while (class_path[end] && class_path[end] != os::path_separator()[0]) {
 751       end++;
 752     }
 753     EXCEPTION_MARK;
 754     ResourceMark rm(THREAD);
 755     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
 756     strncpy(path, &class_path[start], end - start);
 757     path[end - start] = '\0';
 758 
 759     if (set_base_piece) {
 760       // The first time through the bootstrap_search setup, it must be determined
 761       // what the base or core piece of the boot loader search is.  Either a java runtime
 762       // image is present or this is an exploded module build situation.
 763       assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, JAVA_BASE_NAME),
 764              "Incorrect boot loader search path, no java runtime image or " JAVA_BASE_NAME " exploded build");
 765       struct stat st;
 766       if (os::stat(path, &st) == 0) {
 767         // Directory found
 768         ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, CHECK);
 769 
 770         // Check for a jimage
 771         if (Arguments::has_jimage()) {
 772           init_modules_image_name(new_entry->name());
 773 
 774           assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice");
 775           assert(new_entry != NULL && new_entry->is_modules_image(), "No java runtime image present");
 776           _jrt_entry = new_entry;
 777           assert(_jrt_entry->jimage() != NULL, "No java runtime image");
 778         }
 779       } else {
 780         // If path does not exist, exit
 781         vm_exit_during_initialization("Unable to establish the boot loader search path", path);
 782       }
 783       set_base_piece = false;
 784     } else {
 785       // Every entry on the system boot class path after the initial base piece,
 786       // which is set by os::set_boot_path(), is considered an appended entry.
 787       update_class_path_entry_list(path, false, true);
 788     }
 789 
 790     while (class_path[end] == os::path_separator()[0]) {
 791       end++;
 792     }
 793   }


 864       if (zip != NULL && error_msg == NULL) {
 865         new_entry = new ClassPathZipEntry(zip, path, is_boot_append);
 866       } else {
 867         char *msg;
 868         if (error_msg == NULL) {
 869           msg = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, strlen(path) + 128); ;
 870           jio_snprintf(msg, strlen(path) + 127, "error in opening JAR file %s", path);
 871         } else {
 872           int len = (int)(strlen(path) + strlen(error_msg) + 128);
 873           msg = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, len); ;
 874           jio_snprintf(msg, len - 1, "error in opening JAR file <%s> %s", error_msg, path);
 875         }
 876         // Don't complain about bad jar files added via -Xbootclasspath/a:.
 877         if (throw_exception && is_init_completed()) {
 878           THROW_MSG_(vmSymbols::java_lang_ClassNotFoundException(), msg, NULL);
 879         } else {
 880           return NULL;
 881         }
 882       }
 883     }
 884     log_info(class, path)("opened: %s (real path: %s)", path, canonical_path);
 885     log_info(class, load)("opened: %s", path);
 886   } else {
 887     // Directory
 888     new_entry = new ClassPathDirEntry(path);
 889     log_info(class, load)("path: %s", path);
 890   }
 891   return new_entry;
 892 }
 893 
 894 
 895 // Create a class path zip entry for a given path (return NULL if not found
 896 // or zip/JAR file cannot be opened)
 897 ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path, bool is_boot_append) {
 898   // check for a regular file
 899   struct stat st;
 900   if (os::stat(path, &st) == 0) {
 901     if ((st.st_mode & S_IFMT) == S_IFREG) {
 902       char canonical_path[JVM_MAXPATHLEN];
 903       if (get_canonical_path(path, canonical_path, JVM_MAXPATHLEN)) {
 904         char* error_msg = NULL;


< prev index next >