< prev index next >

src/share/vm/classfile/classLoader.cpp

Print this page




 487   }
 488 }
 489 
 490 // For a class in a named module, look it up in the jimage file using this syntax:
 491 //    /<module-name>/<package-name>/<base-class>
 492 //
 493 // Assumptions:
 494 //     1. There are no unnamed modules in the jimage file.
 495 //     2. A package is in at most one module in the jimage file.
 496 //
 497 ClassFileStream* ClassPathImageEntry::open_stream(const char* name, TRAPS) {
 498   jlong size;
 499   JImageLocationRef location = (*JImageFindResource)(_jimage, "", get_jimage_version_string(), name, &size);
 500 
 501   if (location == 0) {
 502     ResourceMark rm;
 503     const char* pkg_name = ClassLoader::package_from_name(name);
 504 
 505     if (pkg_name != NULL) {
 506       if (!Universe::is_module_initialized()) {
 507         location = (*JImageFindResource)(_jimage, "java.base", get_jimage_version_string(), name, &size);
 508 #if INCLUDE_CDS
 509         // CDS uses the boot class loader to load classes whose packages are in
 510         // modules defined for other class loaders.  So, for now, get their module
 511         // names from the "modules" jimage file.
 512         if (DumpSharedSpaces && location == 0) {
 513           const char* module_name = (*JImagePackageToModule)(_jimage, pkg_name);
 514           if (module_name != NULL) {
 515             location = (*JImageFindResource)(_jimage, module_name, get_jimage_version_string(), name, &size);
 516           }
 517         }
 518 #endif
 519 
 520       } else {
 521         PackageEntry* package_entry = get_package_entry(name, ClassLoaderData::the_null_class_loader_data(), CHECK_NULL);
 522         if (package_entry != NULL) {
 523           ResourceMark rm;
 524           // Get the module name
 525           ModuleEntry* module = package_entry->module();
 526           assert(module != NULL, "Boot classLoader package missing module");
 527           assert(module->is_named(), "Boot classLoader package is in unnamed module");


 754 void ClassLoader::setup_search_path(const char *class_path, bool bootstrap_search) {
 755   int len = (int)strlen(class_path);
 756   int end = 0;
 757   bool set_base_piece = bootstrap_search;
 758 
 759   // Iterate over class path entries
 760   for (int start = 0; start < len; start = end) {
 761     while (class_path[end] && class_path[end] != os::path_separator()[0]) {
 762       end++;
 763     }
 764     EXCEPTION_MARK;
 765     ResourceMark rm(THREAD);
 766     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
 767     strncpy(path, &class_path[start], end - start);
 768     path[end - start] = '\0';
 769 
 770     // The first time through the bootstrap_search setup, it must be determined
 771     // what the base or core piece of the boot loader search is.  Either a java runtime
 772     // image is present or this is an exploded module build situation.
 773     if (set_base_piece) {
 774       assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, "java.base"),
 775              "Incorrect boot loader search path, no java runtime image or java.base exploded build");
 776       struct stat st;
 777       if (os::stat(path, &st) == 0) {
 778         // Directory found
 779         Thread* THREAD = Thread::current();
 780         ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, CHECK);
 781 
 782         // Check for a jimage
 783         if (Arguments::has_jimage()) {
 784           assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice");
 785           assert(new_entry != NULL && new_entry->is_jrt(), "No java runtime image present");
 786           _jrt_entry = new_entry;
 787           ++_num_entries;
 788 #if INCLUDE_CDS
 789           if (DumpSharedSpaces) {
 790             JImageFile *jimage = _jrt_entry->jimage();
 791             assert(jimage != NULL, "No java runtime image file present");
 792             ClassLoader::initialize_module_loader_map(jimage);
 793           }
 794 #endif
 795         }


1124   guarantee(JImageResourcePath != NULL, "function JIMAGE_ResourcePath not found");
1125 }
1126 
1127 jboolean ClassLoader::decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg) {
1128   return (*ZipInflateFully)(in, inSize, out, outSize, pmsg);
1129 }
1130 
1131 int ClassLoader::crc32(int crc, const char* buf, int len) {
1132   assert(Crc32 != NULL, "ZIP_CRC32 is not found");
1133   return (*Crc32)(crc, (const jbyte*)buf, len);
1134 }
1135 
1136 #if INCLUDE_CDS
1137 void ClassLoader::initialize_module_loader_map(JImageFile* jimage) {
1138   if (!DumpSharedSpaces) {
1139     return; // only needed for CDS dump time
1140   }
1141 
1142   ResourceMark rm;
1143   jlong size;
1144   JImageLocationRef location = (*JImageFindResource)(jimage, "java.base", get_jimage_version_string(), MODULE_LOADER_MAP, &size);
1145   if (location == 0) {
1146     vm_exit_during_initialization(
1147       "Cannot find ModuleLoaderMap location from modules jimage.", NULL);
1148   }
1149   char* buffer = NEW_RESOURCE_ARRAY(char, size + 1);
1150   buffer[size] = '\0';
1151   jlong read = (*JImageGetResource)(jimage, location, buffer, size);
1152   if (read != size) {
1153     vm_exit_during_initialization(
1154       "Cannot find ModuleLoaderMap resource from modules jimage.", NULL);
1155   }
1156   char* char_buf = (char*)buffer;
1157   int buflen = (int)strlen(char_buf);
1158   char* begin_ptr = char_buf;
1159   char* end_ptr = strchr(begin_ptr, '\n');
1160   bool process_boot_modules = false;
1161   _boot_modules_array = new (ResourceObj::C_HEAP, mtModule)
1162     GrowableArray<char*>(INITIAL_BOOT_MODULES_ARRAY_SIZE, true);
1163   _platform_modules_array = new (ResourceObj::C_HEAP, mtModule)
1164     GrowableArray<char*>(INITIAL_PLATFORM_MODULES_ARRAY_SIZE, true);


1806   return true;
1807 }
1808 
1809 void ClassLoader::create_javabase() {
1810   Thread* THREAD = Thread::current();
1811 
1812   // Create java.base's module entry for the boot
1813   // class loader prior to loading j.l.Ojbect.
1814   ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data();
1815 
1816   // Get module entry table
1817   ModuleEntryTable* null_cld_modules = null_cld->modules();
1818   if (null_cld_modules == NULL) {
1819     vm_exit_during_initialization("No ModuleEntryTable for the boot class loader");
1820   }
1821 
1822   {
1823     MutexLocker ml(Module_lock, THREAD);
1824     ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(NULL), vmSymbols::java_base(), NULL, NULL, null_cld);
1825     if (jb_module == NULL) {
1826       vm_exit_during_initialization("Unable to create ModuleEntry for java.base");
1827     }
1828     ModuleEntryTable::set_javabase_moduleEntry(jb_module);
1829   }
1830 }
1831 
1832 #ifndef PRODUCT
1833 
1834 // CompileTheWorld
1835 //
1836 // Iterates over all class path entries and forces compilation of all methods
1837 // in all classes found. Currently, only zip/jar archives are searched.
1838 //
1839 // The classes are loaded by the Java level bootstrap class loader, and the
1840 // initializer is called. If DelayCompilationDuringStartup is true (default),
1841 // the interpreter will run the initialization code. Note that forcing
1842 // initialization in this way could potentially lead to initialization order
1843 // problems, in which case we could just force the initialization bit to be set.
1844 
1845 
1846 // We need to iterate over the contents of a zip/jar file, so we replicate the




 487   }
 488 }
 489 
 490 // For a class in a named module, look it up in the jimage file using this syntax:
 491 //    /<module-name>/<package-name>/<base-class>
 492 //
 493 // Assumptions:
 494 //     1. There are no unnamed modules in the jimage file.
 495 //     2. A package is in at most one module in the jimage file.
 496 //
 497 ClassFileStream* ClassPathImageEntry::open_stream(const char* name, TRAPS) {
 498   jlong size;
 499   JImageLocationRef location = (*JImageFindResource)(_jimage, "", get_jimage_version_string(), name, &size);
 500 
 501   if (location == 0) {
 502     ResourceMark rm;
 503     const char* pkg_name = ClassLoader::package_from_name(name);
 504 
 505     if (pkg_name != NULL) {
 506       if (!Universe::is_module_initialized()) {
 507         location = (*JImageFindResource)(_jimage, JAVA_BASE_NAME, get_jimage_version_string(), name, &size);
 508 #if INCLUDE_CDS
 509         // CDS uses the boot class loader to load classes whose packages are in
 510         // modules defined for other class loaders.  So, for now, get their module
 511         // names from the "modules" jimage file.
 512         if (DumpSharedSpaces && location == 0) {
 513           const char* module_name = (*JImagePackageToModule)(_jimage, pkg_name);
 514           if (module_name != NULL) {
 515             location = (*JImageFindResource)(_jimage, module_name, get_jimage_version_string(), name, &size);
 516           }
 517         }
 518 #endif
 519 
 520       } else {
 521         PackageEntry* package_entry = get_package_entry(name, ClassLoaderData::the_null_class_loader_data(), CHECK_NULL);
 522         if (package_entry != NULL) {
 523           ResourceMark rm;
 524           // Get the module name
 525           ModuleEntry* module = package_entry->module();
 526           assert(module != NULL, "Boot classLoader package missing module");
 527           assert(module->is_named(), "Boot classLoader package is in unnamed module");


 754 void ClassLoader::setup_search_path(const char *class_path, bool bootstrap_search) {
 755   int len = (int)strlen(class_path);
 756   int end = 0;
 757   bool set_base_piece = bootstrap_search;
 758 
 759   // Iterate over class path entries
 760   for (int start = 0; start < len; start = end) {
 761     while (class_path[end] && class_path[end] != os::path_separator()[0]) {
 762       end++;
 763     }
 764     EXCEPTION_MARK;
 765     ResourceMark rm(THREAD);
 766     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
 767     strncpy(path, &class_path[start], end - start);
 768     path[end - start] = '\0';
 769 
 770     // The first time through the bootstrap_search setup, it must be determined
 771     // what the base or core piece of the boot loader search is.  Either a java runtime
 772     // image is present or this is an exploded module build situation.
 773     if (set_base_piece) {
 774       assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, JAVA_BASE_NAME),
 775              "Incorrect boot loader search path, no java runtime image or " JAVA_BASE_NAME " exploded build");
 776       struct stat st;
 777       if (os::stat(path, &st) == 0) {
 778         // Directory found
 779         Thread* THREAD = Thread::current();
 780         ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, CHECK);
 781 
 782         // Check for a jimage
 783         if (Arguments::has_jimage()) {
 784           assert(_jrt_entry == NULL, "should not setup bootstrap class search path twice");
 785           assert(new_entry != NULL && new_entry->is_jrt(), "No java runtime image present");
 786           _jrt_entry = new_entry;
 787           ++_num_entries;
 788 #if INCLUDE_CDS
 789           if (DumpSharedSpaces) {
 790             JImageFile *jimage = _jrt_entry->jimage();
 791             assert(jimage != NULL, "No java runtime image file present");
 792             ClassLoader::initialize_module_loader_map(jimage);
 793           }
 794 #endif
 795         }


1124   guarantee(JImageResourcePath != NULL, "function JIMAGE_ResourcePath not found");
1125 }
1126 
1127 jboolean ClassLoader::decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg) {
1128   return (*ZipInflateFully)(in, inSize, out, outSize, pmsg);
1129 }
1130 
1131 int ClassLoader::crc32(int crc, const char* buf, int len) {
1132   assert(Crc32 != NULL, "ZIP_CRC32 is not found");
1133   return (*Crc32)(crc, (const jbyte*)buf, len);
1134 }
1135 
1136 #if INCLUDE_CDS
1137 void ClassLoader::initialize_module_loader_map(JImageFile* jimage) {
1138   if (!DumpSharedSpaces) {
1139     return; // only needed for CDS dump time
1140   }
1141 
1142   ResourceMark rm;
1143   jlong size;
1144   JImageLocationRef location = (*JImageFindResource)(jimage, JAVA_BASE_NAME, get_jimage_version_string(), MODULE_LOADER_MAP, &size);
1145   if (location == 0) {
1146     vm_exit_during_initialization(
1147       "Cannot find ModuleLoaderMap location from modules jimage.", NULL);
1148   }
1149   char* buffer = NEW_RESOURCE_ARRAY(char, size + 1);
1150   buffer[size] = '\0';
1151   jlong read = (*JImageGetResource)(jimage, location, buffer, size);
1152   if (read != size) {
1153     vm_exit_during_initialization(
1154       "Cannot find ModuleLoaderMap resource from modules jimage.", NULL);
1155   }
1156   char* char_buf = (char*)buffer;
1157   int buflen = (int)strlen(char_buf);
1158   char* begin_ptr = char_buf;
1159   char* end_ptr = strchr(begin_ptr, '\n');
1160   bool process_boot_modules = false;
1161   _boot_modules_array = new (ResourceObj::C_HEAP, mtModule)
1162     GrowableArray<char*>(INITIAL_BOOT_MODULES_ARRAY_SIZE, true);
1163   _platform_modules_array = new (ResourceObj::C_HEAP, mtModule)
1164     GrowableArray<char*>(INITIAL_PLATFORM_MODULES_ARRAY_SIZE, true);


1806   return true;
1807 }
1808 
1809 void ClassLoader::create_javabase() {
1810   Thread* THREAD = Thread::current();
1811 
1812   // Create java.base's module entry for the boot
1813   // class loader prior to loading j.l.Ojbect.
1814   ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data();
1815 
1816   // Get module entry table
1817   ModuleEntryTable* null_cld_modules = null_cld->modules();
1818   if (null_cld_modules == NULL) {
1819     vm_exit_during_initialization("No ModuleEntryTable for the boot class loader");
1820   }
1821 
1822   {
1823     MutexLocker ml(Module_lock, THREAD);
1824     ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(NULL), vmSymbols::java_base(), NULL, NULL, null_cld);
1825     if (jb_module == NULL) {
1826       vm_exit_during_initialization("Unable to create ModuleEntry for " JAVA_BASE_NAME);
1827     }
1828     ModuleEntryTable::set_javabase_moduleEntry(jb_module);
1829   }
1830 }
1831 
1832 #ifndef PRODUCT
1833 
1834 // CompileTheWorld
1835 //
1836 // Iterates over all class path entries and forces compilation of all methods
1837 // in all classes found. Currently, only zip/jar archives are searched.
1838 //
1839 // The classes are loaded by the Java level bootstrap class loader, and the
1840 // initializer is called. If DelayCompilationDuringStartup is true (default),
1841 // the interpreter will run the initialization code. Note that forcing
1842 // initialization in this way could potentially lead to initialization order
1843 // problems, in which case we could just force the initialization bit to be set.
1844 
1845 
1846 // We need to iterate over the contents of a zip/jar file, so we replicate the


< prev index next >