src/hotspot/share/classfile/classLoaderExt.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff src/hotspot/share/classfile

src/hotspot/share/classfile/classLoaderExt.cpp

Print this page
rev 49528 : [mq]: module_path


  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classFileParser.hpp"
  27 #include "classfile/classFileStream.hpp"
  28 #include "classfile/classListParser.hpp"
  29 #include "classfile/classLoader.inline.hpp"
  30 #include "classfile/classLoaderExt.hpp"
  31 #include "classfile/classLoaderData.inline.hpp"
  32 #include "classfile/klassFactory.hpp"

  33 #include "classfile/sharedClassUtil.hpp"
  34 #include "classfile/sharedPathsMiscInfo.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #include "classfile/vmSymbols.hpp"
  37 #include "memory/allocation.inline.hpp"
  38 #include "memory/filemap.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "oops/instanceKlass.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "oops/symbol.hpp"
  43 #include "runtime/arguments.hpp"

  44 #include "runtime/java.hpp"
  45 #include "runtime/javaCalls.hpp"
  46 #include "runtime/os.hpp"
  47 #include "services/threadService.hpp"
  48 #include "utilities/stringUtils.hpp"
  49 
  50 jshort ClassLoaderExt::_app_paths_start_index = ClassLoaderExt::max_classpath_index;

  51 bool ClassLoaderExt::_has_app_classes = false;
  52 bool ClassLoaderExt::_has_platform_classes = false;
  53 
  54 void ClassLoaderExt::setup_app_search_path() {
  55   assert(DumpSharedSpaces, "this function is only used with -Xshare:dump and -XX:+UseAppCDS");
  56   _app_paths_start_index = ClassLoader::num_boot_classpath_entries();
  57   char* app_class_path = os::strdup(Arguments::get_appclasspath());
  58 
  59   if (strcmp(app_class_path, ".") == 0) {
  60     // This doesn't make any sense, even for AppCDS, so let's skip it. We
  61     // don't want to throw an error here because -cp "." is usually assigned
  62     // by the launcher when classpath is not specified.
  63     trace_class_path("app loader class path (skipped)=", app_class_path);
  64   } else {
  65     trace_class_path("app loader class path=", app_class_path);
  66     shared_paths_misc_info()->add_app_classpath(app_class_path);
  67     ClassLoader::setup_app_search_path(app_class_path);
  68   }
  69 }
  70 
























  71 char* ClassLoaderExt::read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS) {
  72   const char* name = "META-INF/MANIFEST.MF";
  73   char* manifest;
  74   jint size;
  75 
  76   assert(entry->is_jar_file(), "must be");
  77   manifest = (char*) ((ClassPathZipEntry*)entry )->open_entry(name, &size, true, CHECK_NULL);
  78 
  79   if (manifest == NULL) { // No Manifest
  80     *manifest_size = 0;
  81     return NULL;
  82   }
  83 
  84 
  85   if (clean_text) {
  86     // See http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest
  87     // (1): replace all CR/LF and CR with LF
  88     StringUtils::replace_no_expand(manifest, "\r\n", "\n");
  89 
  90     // (2) remove all new-line continuation (remove all "\n " substrings)


 175       int name_len = (int)strlen(file_start);
 176       if (name_len > 0) {
 177         ResourceMark rm(THREAD);
 178         char* libname = NEW_RESOURCE_ARRAY(char, dir_len + name_len + 1);
 179         *libname = 0;
 180         strncat(libname, dir_name, dir_len);
 181         strncat(libname, file_start, name_len);
 182         trace_class_path("library = ", libname);
 183         ClassLoader::update_class_path_entry_list(libname, true, false);
 184       }
 185 
 186       file_start = file_end;
 187     }
 188   }
 189 }
 190 
 191 void ClassLoaderExt::setup_search_paths() {
 192   if (UseAppCDS) {
 193     shared_paths_misc_info()->record_app_offset();
 194     ClassLoaderExt::setup_app_search_path();






 195   }
 196 }
 197 
 198 Thread* ClassLoaderExt::Context::_dump_thread = NULL;
 199 
 200 void ClassLoaderExt::record_result(ClassLoaderExt::Context *context,
 201                                    Symbol* class_name,
 202                                    const s2 classpath_index,
 203                                    InstanceKlass* result,
 204                                    TRAPS) {
 205   assert(DumpSharedSpaces, "Sanity");
 206 
 207   // We need to remember where the class comes from during dumping.
 208   oop loader = result->class_loader();
 209   s2 classloader_type = ClassLoader::BOOT_LOADER;
 210   if (SystemDictionary::is_system_class_loader(loader)) {
 211     classloader_type = ClassLoader::APP_LOADER;
 212     ClassLoaderExt::set_has_app_classes();
 213   } else if (SystemDictionary::is_platform_class_loader(loader)) {
 214     classloader_type = ClassLoader::PLATFORM_LOADER;




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classFileParser.hpp"
  27 #include "classfile/classFileStream.hpp"
  28 #include "classfile/classListParser.hpp"
  29 #include "classfile/classLoader.inline.hpp"
  30 #include "classfile/classLoaderExt.hpp"
  31 #include "classfile/classLoaderData.inline.hpp"
  32 #include "classfile/klassFactory.hpp"
  33 #include "classfile/modules.hpp"
  34 #include "classfile/sharedClassUtil.hpp"
  35 #include "classfile/sharedPathsMiscInfo.hpp"
  36 #include "classfile/systemDictionaryShared.hpp"
  37 #include "classfile/vmSymbols.hpp"
  38 #include "memory/allocation.inline.hpp"
  39 #include "memory/filemap.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "oops/instanceKlass.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "oops/symbol.hpp"
  44 #include "runtime/arguments.hpp"
  45 #include "runtime/handles.inline.hpp"
  46 #include "runtime/java.hpp"
  47 #include "runtime/javaCalls.hpp"
  48 #include "runtime/os.hpp"
  49 #include "services/threadService.hpp"
  50 #include "utilities/stringUtils.hpp"
  51 
  52 jshort ClassLoaderExt::_app_class_paths_start_index = ClassLoaderExt::max_classpath_index;
  53 jshort ClassLoaderExt::_app_module_paths_start_index = ClassLoaderExt::max_classpath_index;
  54 bool ClassLoaderExt::_has_app_classes = false;
  55 bool ClassLoaderExt::_has_platform_classes = false;
  56 
  57 void ClassLoaderExt::setup_app_search_path() {
  58   assert(DumpSharedSpaces, "this function is only used with -Xshare:dump and -XX:+UseAppCDS");
  59   _app_class_paths_start_index = ClassLoader::num_boot_classpath_entries();
  60   char* app_class_path = os::strdup(Arguments::get_appclasspath());
  61 
  62   if (strcmp(app_class_path, ".") == 0) {
  63     // This doesn't make any sense, even for AppCDS, so let's skip it. We
  64     // don't want to throw an error here because -cp "." is usually assigned
  65     // by the launcher when classpath is not specified.
  66     trace_class_path("app loader class path (skipped)=", app_class_path);
  67   } else {
  68     trace_class_path("app loader class path=", app_class_path);
  69     shared_paths_misc_info()->add_app_classpath(app_class_path);
  70     ClassLoader::setup_app_search_path(app_class_path);
  71   }
  72 }
  73 
  74 void ClassLoaderExt::process_module_table(ModuleEntryTable* met) {
  75   ResourceMark rm;
  76   for (int i = 0; i < met->table_size(); i++) {
  77     for (ModuleEntry* m = met->bucket(i); m != NULL;) {
  78       char* path = m->location()->as_C_string();
  79       if (strncmp(path, "file:", 5) == 0 && ClassLoader::string_ends_with(path, ".jar")) {
  80         m->print();
  81         path = ClassLoader::skip_uri_protocol(path);
  82         ClassLoader::setup_module_search_path(path);
  83       }
  84       m = m->next();
  85     }
  86   }
  87 }
  88 void ClassLoaderExt::setup_module_search_path() {
  89   assert(DumpSharedSpaces, "this function is only used with -Xshare:dump and -XX:+UseAppCDS");
  90   _app_module_paths_start_index = ClassLoader::num_boot_classpath_entries() +
  91                               ClassLoader::num_app_classpath_entries();
  92   Thread* thread = Thread::current();
  93   Handle system_class_loader (thread, SystemDictionary::java_system_loader());
  94   ModuleEntryTable* met = Modules::get_module_entry_table(system_class_loader);
  95   process_module_table(met);
  96 }
  97 
  98 char* ClassLoaderExt::read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS) {
  99   const char* name = "META-INF/MANIFEST.MF";
 100   char* manifest;
 101   jint size;
 102 
 103   assert(entry->is_jar_file(), "must be");
 104   manifest = (char*) ((ClassPathZipEntry*)entry )->open_entry(name, &size, true, CHECK_NULL);
 105 
 106   if (manifest == NULL) { // No Manifest
 107     *manifest_size = 0;
 108     return NULL;
 109   }
 110 
 111 
 112   if (clean_text) {
 113     // See http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest
 114     // (1): replace all CR/LF and CR with LF
 115     StringUtils::replace_no_expand(manifest, "\r\n", "\n");
 116 
 117     // (2) remove all new-line continuation (remove all "\n " substrings)


 202       int name_len = (int)strlen(file_start);
 203       if (name_len > 0) {
 204         ResourceMark rm(THREAD);
 205         char* libname = NEW_RESOURCE_ARRAY(char, dir_len + name_len + 1);
 206         *libname = 0;
 207         strncat(libname, dir_name, dir_len);
 208         strncat(libname, file_start, name_len);
 209         trace_class_path("library = ", libname);
 210         ClassLoader::update_class_path_entry_list(libname, true, false);
 211       }
 212 
 213       file_start = file_end;
 214     }
 215   }
 216 }
 217 
 218 void ClassLoaderExt::setup_search_paths() {
 219   if (UseAppCDS) {
 220     shared_paths_misc_info()->record_app_offset();
 221     ClassLoaderExt::setup_app_search_path();
 222   }
 223 }
 224 
 225 void ClassLoaderExt::setup_module_paths() {
 226   if (UseAppCDS) {
 227     ClassLoaderExt::setup_module_search_path();
 228   }
 229 }
 230 
 231 Thread* ClassLoaderExt::Context::_dump_thread = NULL;
 232 
 233 void ClassLoaderExt::record_result(ClassLoaderExt::Context *context,
 234                                    Symbol* class_name,
 235                                    const s2 classpath_index,
 236                                    InstanceKlass* result,
 237                                    TRAPS) {
 238   assert(DumpSharedSpaces, "Sanity");
 239 
 240   // We need to remember where the class comes from during dumping.
 241   oop loader = result->class_loader();
 242   s2 classloader_type = ClassLoader::BOOT_LOADER;
 243   if (SystemDictionary::is_system_class_loader(loader)) {
 244     classloader_type = ClassLoader::APP_LOADER;
 245     ClassLoaderExt::set_has_app_classes();
 246   } else if (SystemDictionary::is_platform_class_loader(loader)) {
 247     classloader_type = ClassLoader::PLATFORM_LOADER;


src/hotspot/share/classfile/classLoaderExt.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File