Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8249096: Clean up code for DumpLoadedClassList
Clean up code for DumpLoadedClassList output code, centralize in InstanceKlass.

Reviewed-by: iklam, dcubed
  • Loading branch information
yminqi committed Aug 22, 2020
1 parent ea02307 commit 3a78fa5adb1ae4e429863886ccb2bfd09b1a37e5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 54 deletions.
@@ -5474,11 +5474,7 @@ void ClassFileParser::fill_instance_klass(InstanceKlass* ik,
ClassLoadingService::notify_class_loaded(ik, false /* not shared class */);

if (!is_internal()) {
if (log_is_enabled(Info, class, load)) {
ResourceMark rm;
const char* module_name = (module_entry->name() == NULL) ? UNNAMED_MODULE : module_entry->name()->as_C_string();
ik->print_class_load_logging(_loader_data, module_name, _stream);
}
ik->print_class_load_logging(_loader_data, module_entry, _stream);

if (ik->minor_version() == JAVA_PREVIEW_MINOR_VERSION &&
ik->major_version() == JVM_CLASSFILE_MAJOR_VERSION &&
@@ -5985,44 +5981,6 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
}
ls.cr();
}

#if INCLUDE_CDS
if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) {
if (!ClassLoader::has_jrt_entry()) {
warning("DumpLoadedClassList and CDS are not supported in exploded build");
DumpLoadedClassList = NULL;
} else if (SystemDictionaryShared::is_sharing_possible(_loader_data) &&
!_is_hidden &&
_unsafe_anonymous_host == NULL) {
// Only dump the classes that can be stored into CDS archive.
// Hidden and unsafe anonymous classes such as generated LambdaForm classes are also not included.
oop class_loader = _loader_data->class_loader();
ResourceMark rm(THREAD);
bool skip = false;
if (class_loader == NULL || SystemDictionary::is_platform_class_loader(class_loader)) {
// For the boot and platform class loaders, skip classes that are not found in the
// java runtime image, such as those found in the --patch-module entries.
// These classes can't be loaded from the archive during runtime.
if (!stream->from_boot_loader_modules_image() && strncmp(stream->source(), "jrt:", 4) != 0) {
skip = true;
}

if (class_loader == NULL && ClassLoader::contains_append_entry(stream->source())) {
// .. but don't skip the boot classes that are loaded from -Xbootclasspath/a
// as they can be loaded from the archive during runtime.
skip = false;
}
}
if (skip) {
tty->print_cr("skip writing class %s from source %s to classlist file",
_class_name->as_C_string(), stream->source());
} else {
classlist_file->print_cr("%s", _class_name->as_C_string());
classlist_file->flush();
}
}
}
#endif
}

// SUPERKLASS
@@ -1470,15 +1470,6 @@ void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData
ik->set_classpath_index(path_index, THREAD);
}

if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
// Only dump the classes that can be stored into CDS archive
if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
ResourceMark rm(THREAD);
classlist_file->print_cr("%s", ik->name()->as_C_string());
classlist_file->flush();
}
}

// notify a class loaded from shared object
ClassLoadingService::notify_class_loaded(ik, true /* shared class */);

@@ -3599,8 +3599,10 @@ const char* InstanceKlass::internal_name() const {
}

void InstanceKlass::print_class_load_logging(ClassLoaderData* loader_data,
const char* module_name,
const ModuleEntry* module_entry,
const ClassFileStream* cfs) const {
log_to_classlist(cfs);

if (!log_is_enabled(Info, class, load)) {
return;
}
@@ -3615,6 +3617,7 @@ void InstanceKlass::print_class_load_logging(ClassLoaderData* loader_data,
// Source
if (cfs != NULL) {
if (cfs->source() != NULL) {
const char* module_name = (module_entry->name() == NULL) ? UNNAMED_MODULE : module_entry->name()->as_C_string();
if (module_name != NULL) {
// When the boot loader created the stream, it didn't know the module name
// yet. Let's format it now.
@@ -4190,3 +4193,52 @@ unsigned char * InstanceKlass::get_cached_class_file_bytes() {
return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file);
}
#endif

void InstanceKlass::log_to_classlist(const ClassFileStream* stream) const {
#if INCLUDE_CDS
if (DumpLoadedClassList && classlist_file->is_open()) {
if (!ClassLoader::has_jrt_entry()) {
warning("DumpLoadedClassList and CDS are not supported in exploded build");
DumpLoadedClassList = NULL;
return;
}
ClassLoaderData* loader_data = class_loader_data();
if (!SystemDictionaryShared::is_sharing_possible(loader_data)) {
return;
}
bool skip = false;
if (is_shared()) {
assert(stream == NULL, "shared class with stream");
} else {
assert(stream != NULL, "non-shared class without stream");
// skip hidden class and unsafe anonymous class.
if ( is_hidden() || unsafe_anonymous_host() != NULL) {
return;
}
oop class_loader = loader_data->class_loader();
if (class_loader == NULL || SystemDictionary::is_platform_class_loader(class_loader)) {
// For the boot and platform class loaders, skip classes that are not found in the
// java runtime image, such as those found in the --patch-module entries.
// These classes can't be loaded from the archive during runtime.
if (!stream->from_boot_loader_modules_image() && strncmp(stream->source(), "jrt:", 4) != 0) {
skip = true;
}

if (class_loader == NULL && ClassLoader::contains_append_entry(stream->source())) {
// .. but don't skip the boot classes that are loaded from -Xbootclasspath/a
// as they can be loaded from the archive during runtime.
skip = false;
}
}
}
ResourceMark rm;
if (skip) {
tty->print_cr("skip writing class %s from source %s to classlist file",
name()->as_C_string(), stream->source());
} else {
classlist_file->print_cr("%s", name()->as_C_string());
classlist_file->flush();
}
}
#endif // INCLUDE_CDS
}
@@ -1322,6 +1322,8 @@ class InstanceKlass: public Klass {
void link_previous_versions(InstanceKlass* pv) { _previous_versions = pv; }
void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count);
#endif
// log class name to classlist
void log_to_classlist(const ClassFileStream* cfs) const;
public:
// CDS support - remove and restore oops from metadata. Oops are not shared.
virtual void remove_unshareable_info();
@@ -1363,7 +1365,7 @@ class InstanceKlass: public Klass {

// Logging
void print_class_load_logging(ClassLoaderData* loader_data,
const char* module_name,
const ModuleEntry* module_entry,
const ClassFileStream* cfs) const;
};

0 comments on commit 3a78fa5

Please sign in to comment.