8138600: eliminate the need of ModuleLoaderMap.dat for CDS
Removed the code which generates the ModuleLoaderMap.dat and the code which references it Reviewed-by: mchung, jiangli
This commit is contained in:
parent
e31bc5637a
commit
6213838f11
@ -54,15 +54,4 @@ $(SUPPORT_OUTPUTDIR)/gensrc/java.base/jdk/internal/module/ModuleLoaderMap.java:
|
||||
|
||||
GENSRC_JAVA_BASE += $(SUPPORT_OUTPUTDIR)/gensrc/java.base/jdk/internal/module/ModuleLoaderMap.java
|
||||
|
||||
$(SUPPORT_OUTPUTDIR)/gensrc/java.base/jdk/internal/vm/cds/resources/ModuleLoaderMap.dat: \
|
||||
$(TOPDIR)/src/java.base/share/classes/jdk/internal/vm/cds/resources/ModuleLoaderMap.dat \
|
||||
$(VARDEPS_FILE) $(BUILD_TOOLS_JDK)
|
||||
$(MKDIR) -p $(@D)
|
||||
$(RM) $@ $@.tmp
|
||||
$(TOOL_GENCLASSLOADERMAP) -boot $(BOOT_MODULES_LIST) \
|
||||
-platform $(PLATFORM_MODULES_LIST) -o $@.tmp $<
|
||||
$(MV) $@.tmp $@
|
||||
|
||||
GENSRC_JAVA_BASE += $(SUPPORT_OUTPUTDIR)/gensrc/java.base/jdk/internal/vm/cds/resources/ModuleLoaderMap.dat
|
||||
|
||||
################################################################################
|
||||
|
@ -77,30 +77,22 @@ public class GenModuleLoaderMap {
|
||||
throw new IllegalArgumentException(source + " not exist");
|
||||
}
|
||||
|
||||
boolean needsQuotes = outfile.toString().contains(".java.tmp");
|
||||
|
||||
try (BufferedWriter bw = Files.newBufferedWriter(outfile, StandardCharsets.UTF_8);
|
||||
PrintWriter writer = new PrintWriter(bw)) {
|
||||
for (String line : Files.readAllLines(source)) {
|
||||
if (line.contains("@@BOOT_MODULE_NAMES@@")) {
|
||||
line = patch(line, "@@BOOT_MODULE_NAMES@@", bootModules, needsQuotes);
|
||||
line = patch(line, "@@BOOT_MODULE_NAMES@@", bootModules);
|
||||
} else if (line.contains("@@PLATFORM_MODULE_NAMES@@")) {
|
||||
line = patch(line, "@@PLATFORM_MODULE_NAMES@@", platformModules, needsQuotes);
|
||||
line = patch(line, "@@PLATFORM_MODULE_NAMES@@", platformModules);
|
||||
}
|
||||
writer.println(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String patch(String s, String tag, Stream<String> stream, boolean needsQuotes) {
|
||||
String mns = null;
|
||||
if (needsQuotes) {
|
||||
mns = stream.sorted()
|
||||
.collect(Collectors.joining("\",\n \""));
|
||||
} else {
|
||||
mns = stream.sorted()
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
private static String patch(String s, String tag, Stream<String> stream) {
|
||||
String mns = stream.sorted()
|
||||
.collect(Collectors.joining("\",\n \""));
|
||||
return s.replace(tag, mns);
|
||||
}
|
||||
|
||||
|
@ -802,7 +802,6 @@ void ClassLoader::setup_search_path(const char *class_path, bool bootstrap_searc
|
||||
if (DumpSharedSpaces) {
|
||||
JImageFile *jimage = _jrt_entry->jimage();
|
||||
assert(jimage != NULL, "No java runtime image file present");
|
||||
ClassLoader::initialize_module_loader_map(jimage);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1144,61 +1143,6 @@ int ClassLoader::crc32(int crc, const char* buf, int len) {
|
||||
return (*Crc32)(crc, (const jbyte*)buf, len);
|
||||
}
|
||||
|
||||
#if INCLUDE_CDS
|
||||
void ClassLoader::initialize_module_loader_map(JImageFile* jimage) {
|
||||
if (!DumpSharedSpaces) {
|
||||
return; // only needed for CDS dump time
|
||||
}
|
||||
|
||||
ResourceMark rm;
|
||||
jlong size;
|
||||
JImageLocationRef location = (*JImageFindResource)(jimage, JAVA_BASE_NAME, get_jimage_version_string(), MODULE_LOADER_MAP, &size);
|
||||
if (location == 0) {
|
||||
vm_exit_during_initialization(
|
||||
"Cannot find ModuleLoaderMap location from modules jimage.", NULL);
|
||||
}
|
||||
char* buffer = NEW_RESOURCE_ARRAY(char, size + 1);
|
||||
buffer[size] = '\0';
|
||||
jlong read = (*JImageGetResource)(jimage, location, buffer, size);
|
||||
if (read != size) {
|
||||
vm_exit_during_initialization(
|
||||
"Cannot find ModuleLoaderMap resource from modules jimage.", NULL);
|
||||
}
|
||||
char* char_buf = (char*)buffer;
|
||||
int buflen = (int)strlen(char_buf);
|
||||
char* begin_ptr = char_buf;
|
||||
char* end_ptr = strchr(begin_ptr, '\n');
|
||||
bool process_boot_modules = false;
|
||||
_boot_modules_array = new (ResourceObj::C_HEAP, mtModule)
|
||||
GrowableArray<char*>(INITIAL_BOOT_MODULES_ARRAY_SIZE, true);
|
||||
_platform_modules_array = new (ResourceObj::C_HEAP, mtModule)
|
||||
GrowableArray<char*>(INITIAL_PLATFORM_MODULES_ARRAY_SIZE, true);
|
||||
while (end_ptr != NULL && (end_ptr - char_buf) < buflen) {
|
||||
// Allocate a buffer from the C heap to be appended to the _boot_modules_array
|
||||
// or the _platform_modules_array.
|
||||
char* temp_name = NEW_C_HEAP_ARRAY(char, (size_t)(end_ptr - begin_ptr + 1), mtInternal);
|
||||
strncpy(temp_name, begin_ptr, end_ptr - begin_ptr);
|
||||
temp_name[end_ptr - begin_ptr] = '\0';
|
||||
if (strncmp(temp_name, "BOOT", 4) == 0) {
|
||||
process_boot_modules = true;
|
||||
FREE_C_HEAP_ARRAY(char, temp_name);
|
||||
} else if (strncmp(temp_name, "PLATFORM", 8) == 0) {
|
||||
process_boot_modules = false;
|
||||
FREE_C_HEAP_ARRAY(char, temp_name);
|
||||
} else {
|
||||
// module name
|
||||
if (process_boot_modules) {
|
||||
_boot_modules_array->append(temp_name);
|
||||
} else {
|
||||
_platform_modules_array->append(temp_name);
|
||||
}
|
||||
}
|
||||
begin_ptr = ++end_ptr;
|
||||
end_ptr = strchr(begin_ptr, '\n');
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Function add_package extracts the package from the fully qualified class name
|
||||
// and checks if the package is in the boot loader's package entry table. If so,
|
||||
// then it sets the classpath_index in the package entry record.
|
||||
@ -1290,58 +1234,6 @@ objArrayOop ClassLoader::get_system_packages(TRAPS) {
|
||||
return result();
|
||||
}
|
||||
|
||||
#if INCLUDE_CDS
|
||||
s2 ClassLoader::module_to_classloader(const char* module_name) {
|
||||
|
||||
assert(DumpSharedSpaces, "dump time only");
|
||||
assert(_boot_modules_array != NULL, "_boot_modules_array is NULL");
|
||||
assert(_platform_modules_array != NULL, "_platform_modules_array is NULL");
|
||||
|
||||
int array_size = _boot_modules_array->length();
|
||||
for (int i = 0; i < array_size; i++) {
|
||||
if (strcmp(module_name, _boot_modules_array->at(i)) == 0) {
|
||||
return BOOT_LOADER;
|
||||
}
|
||||
}
|
||||
|
||||
array_size = _platform_modules_array->length();
|
||||
for (int i = 0; i < array_size; i++) {
|
||||
if (strcmp(module_name, _platform_modules_array->at(i)) == 0) {
|
||||
return PLATFORM_LOADER;
|
||||
}
|
||||
}
|
||||
|
||||
return APP_LOADER;
|
||||
}
|
||||
|
||||
s2 ClassLoader::classloader_type(Symbol* class_name, ClassPathEntry* e, int classpath_index, TRAPS) {
|
||||
assert(DumpSharedSpaces, "Only used for CDS dump time");
|
||||
|
||||
// obtain the classloader type based on the class name.
|
||||
// First obtain the package name based on the class name. Then obtain
|
||||
// the classloader type based on the package name from the jimage using
|
||||
// a jimage API. If the classloader type cannot be found from the
|
||||
// jimage, it is determined by the class path entry.
|
||||
jshort loader_type = ClassLoader::APP_LOADER;
|
||||
if (e->is_jrt()) {
|
||||
ResourceMark rm;
|
||||
TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK_0);
|
||||
if (pkg_name != NULL) {
|
||||
const char* pkg_name_C_string = (const char*)(pkg_name->as_C_string());
|
||||
ClassPathImageEntry* cpie = (ClassPathImageEntry*)e;
|
||||
JImageFile* jimage = cpie->jimage();
|
||||
char* module_name = (char*)(*JImagePackageToModule)(jimage, pkg_name_C_string);
|
||||
if (module_name != NULL) {
|
||||
loader_type = ClassLoader::module_to_classloader(module_name);
|
||||
}
|
||||
}
|
||||
} else if (ClassLoaderExt::is_boot_classpath(classpath_index)) {
|
||||
loader_type = ClassLoader::BOOT_LOADER;
|
||||
}
|
||||
return loader_type;
|
||||
}
|
||||
#endif
|
||||
|
||||
// caller needs ResourceMark
|
||||
const char* ClassLoader::file_name_for_class_name(const char* class_name,
|
||||
int class_name_len) {
|
||||
|
@ -37,13 +37,6 @@
|
||||
// Name of boot "modules" image
|
||||
#define MODULES_IMAGE_NAME "modules"
|
||||
|
||||
// Name of the resource containing mapping from module names to defining class loader type
|
||||
#define MODULE_LOADER_MAP "jdk/internal/vm/cds/resources/ModuleLoaderMap.dat"
|
||||
|
||||
// Initial sizes of the following arrays are based on the generated ModuleLoaderMap.dat
|
||||
#define INITIAL_BOOT_MODULES_ARRAY_SIZE 30
|
||||
#define INITIAL_PLATFORM_MODULES_ARRAY_SIZE 15
|
||||
|
||||
// Class path entry (directory or zip file)
|
||||
|
||||
class JImageFile;
|
||||
@ -439,10 +432,6 @@ class ClassLoader: AllStatic {
|
||||
static bool check_shared_paths_misc_info(void* info, int size);
|
||||
static void exit_with_path_failure(const char* error, const char* message);
|
||||
|
||||
static s2 module_to_classloader(const char* module_name);
|
||||
static void initialize_module_loader_map(JImageFile* jimage);
|
||||
static s2 classloader_type(Symbol* class_name, ClassPathEntry* e,
|
||||
int classpath_index, TRAPS);
|
||||
static void record_shared_class_loader_type(InstanceKlass* ik, const ClassFileStream* stream);
|
||||
#endif
|
||||
static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
|
||||
|
@ -1,4 +0,0 @@
|
||||
BOOT
|
||||
@@BOOT_MODULE_NAMES@@
|
||||
PLATFORM
|
||||
@@PLATFORM_MODULE_NAMES@@
|
Loading…
x
Reference in New Issue
Block a user