Skip to content

8364034: [lworld] Pre-register boxing classes in class loaders #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/hotspot/share/classfile/classFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6227,6 +6227,13 @@ void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const st
if (HAS_PENDING_EXCEPTION) {
CLEAR_PENDING_EXCEPTION;
}
} else {
// Just poking the system dictionary to see if the class has already be loaded
oop loader = loader_data()->class_loader();
InstanceKlass* klass = SystemDictionary::find_instance_klass(THREAD, name, Handle(THREAD, loader));
if (klass != nullptr && klass->is_inline_klass()) {
_inline_layout_info_array->adr_at(fieldinfo.index())->set_klass(InlineKlass::cast(klass));
}
}
}
}
Expand Down
40 changes: 32 additions & 8 deletions src/hotspot/share/classfile/systemDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,37 @@ inline ClassLoaderData* class_loader_data(Handle class_loader) {
return ClassLoaderData::class_loader_data(class_loader());
}

static void add_wrapper_class(JavaThread* current, ClassLoaderData* cld, Symbol* classname) {
InstanceKlass* ik = SystemDictionary::find_instance_klass(current, classname, Handle(current, nullptr));
assert(ik != nullptr, "Must exist");
SystemDictionary::add_to_initiating_loader(current, ik, cld);
}

static void add_wrapper_classes(ClassLoaderData* cld) {
MonitorLocker mu1(SystemDictionary_lock);
JavaThread* current = JavaThread::current();
add_wrapper_class(current, cld, vmSymbols::java_lang_Boolean());
add_wrapper_class(current, cld, vmSymbols::java_lang_Byte());
add_wrapper_class(current, cld, vmSymbols::java_lang_Character());
add_wrapper_class(current, cld, vmSymbols::java_lang_Short());
add_wrapper_class(current, cld, vmSymbols::java_lang_Integer());
add_wrapper_class(current, cld, vmSymbols::java_lang_Long());
add_wrapper_class(current, cld, vmSymbols::java_lang_Float());
add_wrapper_class(current, cld, vmSymbols::java_lang_Double());
}

ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, bool create_mirror_cld) {
if (create_mirror_cld) {
// Add a new class loader data to the graph.
return ClassLoaderDataGraph::add(class_loader, true);
} else {
return (class_loader() == nullptr) ? ClassLoaderData::the_null_class_loader_data() :
ClassLoaderDataGraph::find_or_create(class_loader);
if (class_loader() == nullptr) {
return ClassLoaderData::the_null_class_loader_data();
} else {
ClassLoaderData* cld = ClassLoaderDataGraph::find_or_create(class_loader);
add_wrapper_classes(cld);
return cld;
}
}
}

Expand Down Expand Up @@ -1746,23 +1770,23 @@ void SystemDictionary::update_dictionary(JavaThread* current,
mu1.notify_all();
}

#if INCLUDE_CDS
// Indicate that loader_data has initiated the loading of class k, which
// has already been defined by a parent loader.
// This API should be used only by AOTLinkedClassBulkLoader
// This API is used by AOTLinkedClassBulkLoader and to register boxing
// classes from java.lang in all class loaders to enable more value
// classes optimizations
void SystemDictionary::add_to_initiating_loader(JavaThread* current,
InstanceKlass* k,
ClassLoaderData* loader_data) {
assert(CDSConfig::is_using_aot_linked_classes(), "must be");
assert_locked_or_safepoint(SystemDictionary_lock);
Symbol* name = k->name();
Dictionary* dictionary = loader_data->dictionary();
assert(k->is_loaded(), "must be");
assert(k->class_loader_data() != loader_data, "only for classes defined by a parent loader");
assert(dictionary->find_class(current, name) == nullptr, "sanity");
dictionary->add_klass(current, name, k);
if (dictionary->find_class(current, name) == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also keep the assert and have it be:
assert(!CDSConfig::is_using_aot_linked_classes() || dictionary->find_class() == nullptr, "Ioi would like this probably");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no this assert isn't right because you add wrapper classes when using_aot_linked_classes too. Never mind this.

dictionary->add_klass(current, name, k);
}
}
#endif

// Try to find a class name using the loader constraints. The
// loader constraints might know about a class that isn't fully loaded
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/systemDictionary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class SystemDictionary : AllStatic {
static const char* find_nest_host_error(const constantPoolHandle& pool, int which);

static void add_to_initiating_loader(JavaThread* current, InstanceKlass* k,
ClassLoaderData* loader_data) NOT_CDS_RETURN;
ClassLoaderData* loader_data);

static OopHandle _java_system_loader;
static OopHandle _java_platform_loader;
Expand Down