Skip to content
Permalink
Browse files
8240245: Avoid calling is_shared_class_visible() in SystemDictionary:…
…:load_shared_class()

SystemDitionary::load_shared_class can avoid calling is_shared_class_visible if dumptime and runtime do not use modulepath and boot classpath appending.

Reviewed-by: iklam, ccheung
  • Loading branch information
yminqi committed Jun 11, 2020
1 parent 6d8c81f commit 96fadefaa314fae8df1e7613072492fe650ed3ac
Showing 14 changed files with 496 additions and 17 deletions.
@@ -1528,6 +1528,19 @@ void ClassLoader::initialize_module_path(TRAPS) {
FileMapInfo::allocate_shared_path_table();
}
}

// Helper function used by CDS code to get the number of module path
// entries during shared classpath setup time.
int ClassLoader::num_module_path_entries() {
Arguments::assert_is_dumping_archive();
int num_entries = 0;
ClassPathEntry* e= ClassLoader::_module_path_entries;
while (e != NULL) {
num_entries ++;
e = e->next();
}
return num_entries;
}
#endif

jlong ClassLoader::classloader_time_ms() {
@@ -388,16 +388,7 @@ class ClassLoader: AllStatic {

// Helper function used by CDS code to get the number of module path
// entries during shared classpath setup time.
static int num_module_path_entries() {
Arguments::assert_is_dumping_archive();
int num_entries = 0;
ClassPathEntry* e= ClassLoader::_module_path_entries;
while (e != NULL) {
num_entries ++;
e = e->next();
}
return num_entries;
}
static int num_module_path_entries();
static void exit_with_path_failure(const char* error, const char* message);
static char* skip_uri_protocol(char* source);
static void record_result(InstanceKlass* ik, const ClassFileStream* stream, TRAPS);
@@ -1232,6 +1232,7 @@ InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
PackageEntry* pkg_entry,
TRAPS) {
assert(UseSharedSpaces, "Sanity check");
InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
if (ik != NULL && ik->is_shared_boot_class()) {
return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD);
@@ -1251,18 +1252,30 @@ bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
Handle class_loader, TRAPS) {
assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
"Cannot use sharing if java.base is patched");
ResourceMark rm(THREAD);
int path_index = ik->shared_classpath_index();
ClassLoaderData* loader_data = class_loader_data(class_loader);
if (path_index < 0) {
if (ik->shared_classpath_index() < 0) {
// path_index < 0 indicates that the class is intended for a custom loader
// and should not be loaded by boot/platform/app loaders
if (loader_data->is_builtin_class_loader_data()) {
if (is_builtin_class_loader(class_loader())) {
return false;
} else {
return true;
}
}

// skip class visibility check
if (MetaspaceShared::use_optimized_module_handling()) {
assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD), "Optimizing module handling failed.");
return true;
}
return is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD);
}

bool SystemDictionary::is_shared_class_visible_impl(Symbol* class_name,
InstanceKlass* ik,
PackageEntry* pkg_entry,
Handle class_loader, TRAPS) {
int path_index = ik->shared_classpath_index();
ClassLoaderData* loader_data = class_loader_data(class_loader);
SharedClassPathEntry* ent =
(SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
if (!Universe::is_module_initialized()) {
@@ -1596,12 +1609,14 @@ InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle

// Search for classes in the CDS archive.
InstanceKlass* k = NULL;
{

#if INCLUDE_CDS
if (UseSharedSpaces)
{
PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
k = load_shared_boot_class(class_name, pkg_entry, THREAD);
#endif
}
#endif

if (k == NULL) {
// Use VM class loader
@@ -629,6 +629,10 @@ class SystemDictionary : AllStatic {
static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik,
PackageEntry* pkg_entry,
Handle class_loader, TRAPS);
static bool is_shared_class_visible_impl(Symbol* class_name,
InstanceKlass* ik,
PackageEntry* pkg_entry,
Handle class_loader, TRAPS);
static bool check_shared_class_super_type(InstanceKlass* child, InstanceKlass* super,
Handle class_loader, Handle protection_domain,
bool is_superclass, TRAPS);
@@ -217,6 +217,7 @@ void FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
_compressed_class_ptrs = UseCompressedClassPointers;
_max_heap_size = MaxHeapSize;
_narrow_klass_shift = CompressedKlassPointers::shift();
_use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();

// The following fields are for sanity checks for whether this archive
// will function correctly with this JVM and the bootclasspath it's
@@ -2130,6 +2131,11 @@ bool FileMapHeader::validate() {
return false;
}

if (!_use_optimized_module_handling) {
MetaspaceShared::disable_optimized_module_handling();
log_info(cds)("use_optimized_module_handling disabled: archive was created without optimized module handling");
}

return true;
}

@@ -227,6 +227,8 @@ class FileMapHeader: private CDSFileMapHeaderBase {
char* _mapped_base_address; // Actual base address where archive is mapped.

bool _allow_archiving_with_java_agent; // setting of the AllowArchivingWithJavaAgent option
bool _use_optimized_module_handling;// No module-relation VM options were specified, so we can skip
// some expensive operations.
size_t _ptrmap_size_in_bits; // Size of pointer relocation bitmap

char* from_mapped_offset(size_t offset) const {
@@ -89,6 +89,7 @@ size_t MetaspaceShared::_i2i_entry_code_buffers_size = 0;
void* MetaspaceShared::_shared_metaspace_static_top = NULL;
intx MetaspaceShared::_relocation_delta;
char* MetaspaceShared::_requested_base_address;
bool MetaspaceShared::_use_optimized_module_handling = true;

// The CDS archive is divided into the following regions:
// mc - misc code (the method entry trampolines, c++ vtables)
@@ -2376,6 +2377,7 @@ MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, File
static_mapinfo->map_heap_regions();
}
});
log_info(cds)("Using optimized module handling %s", MetaspaceShared::use_optimized_module_handling() ? "enabled" : "disabled");
} else {
unmap_archive(static_mapinfo);
unmap_archive(dynamic_mapinfo);
@@ -184,6 +184,7 @@ class MetaspaceShared : AllStatic {
static void* _shared_metaspace_static_top;
static intx _relocation_delta;
static char* _requested_base_address;
static bool _use_optimized_module_handling;
public:
enum {
// core archive spaces
@@ -372,6 +373,11 @@ class MetaspaceShared : AllStatic {
static void write_core_archive_regions(FileMapInfo* mapinfo,
GrowableArray<ArchiveHeapOopmapInfo>* closed_oopmaps,
GrowableArray<ArchiveHeapOopmapInfo>* open_oopmaps);

// Can we skip some expensive operations related to modules?
static bool use_optimized_module_handling() { return _use_optimized_module_handling; }
static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }

private:
#if INCLUDE_CDS
static void write_region(FileMapInfo* mapinfo, int region_idx, DumpRegion* dump_region,
@@ -1467,6 +1467,12 @@ bool Arguments::add_property(const char* prop, PropertyWriteable writeable, Prop
value = &prop[key_len + 1];
}

if (is_internal_module_property(key) ||
strcmp(key, "jdk.module.main") == 0) {
MetaspaceShared::disable_optimized_module_handling();
log_info(cds)("Using optimized module handling disabled due to incompatible property: %s=%s", key, value);
}

if (strcmp(key, "java.compiler") == 0) {
process_java_compiler_argument(value);
// Record value in Arguments, but let it get passed to Java.
@@ -2510,6 +2516,8 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
// -bootclasspath/a:
} else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
Arguments::append_sysclasspath(tail);
MetaspaceShared::disable_optimized_module_handling();
log_info(cds)("Using optimized module handling disabled due to bootclasspath was appended");
// -bootclasspath/p:
} else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
jio_fprintf(defaultStream::output_stream(),

0 comments on commit 96fadef

Please sign in to comment.