Skip to content

Commit

Permalink
8291840: Avoid JavaCalls for setting up _java_system_loader and _java…
Browse files Browse the repository at this point in the history
…_platform_loader

Reviewed-by: coleenp, iklam
  • Loading branch information
calvinccheung committed Aug 4, 2022
1 parent 6e6c64c commit 27c8826
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/classfile/classLoaderData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ class ClassLoaderData : public CHeapObj<mtClass> {
bool is_builtin_class_loader_data() const;
bool is_permanent_class_loader_data() const;

OopHandle class_loader_handle() const { return _class_loader; }

// The Metaspace is created lazily so may be NULL. This
// method will allocate a Metaspace if needed.
ClassLoaderMetaspace* metaspace_non_null();
Expand Down
8 changes: 8 additions & 0 deletions src/hotspot/share/classfile/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "logging/logStream.hpp"
#include "memory/resourceArea.hpp"
#include "prims/jvmtiExport.hpp"
#include "runtime/arguments.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/javaCalls.hpp"
Expand Down Expand Up @@ -499,9 +500,16 @@ void Modules::define_archived_modules(Handle h_platform_loader, Handle h_system_
}

ClassLoaderData* platform_loader_data = SystemDictionary::register_loader(h_platform_loader);
SystemDictionary::set_platform_loader(platform_loader_data);
ClassLoaderDataShared::restore_java_platform_loader_from_archive(platform_loader_data);

ClassLoaderData* system_loader_data = SystemDictionary::register_loader(h_system_loader);
SystemDictionary::set_system_loader(system_loader_data);
// system_loader_data here is always an instance of jdk.internal.loader.ClassLoader$AppClassLoader.
// However, if -Djava.system.class.loader=xxx is specified, java_platform_loader() would
// be an instance of a user-defined class, so make sure this never happens.
assert(Arguments::get_property("java.system.class.loader") == NULL,
"archived full module should have been disabled if -Djava.system.class.loader is specified");
ClassLoaderDataShared::restore_java_system_loader_from_archive(system_loader_data);
}

Expand Down
54 changes: 48 additions & 6 deletions src/hotspot/share/classfile/systemDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,53 @@ oop SystemDictionary::java_platform_loader() {
}

void SystemDictionary::compute_java_loaders(TRAPS) {
if (_java_system_loader.is_empty()) {
oop system_loader = get_system_class_loader_impl(CHECK);
_java_system_loader = OopHandle(Universe::vm_global(), system_loader);
} else {
// It must have been restored from the archived module graph
assert(UseSharedSpaces, "must be");
assert(MetaspaceShared::use_full_module_graph(), "must be");
DEBUG_ONLY(
oop system_loader = get_system_class_loader_impl(CHECK);
assert(_java_system_loader.resolve() == system_loader, "must be");
)
}

if (_java_platform_loader.is_empty()) {
oop platform_loader = get_platform_class_loader_impl(CHECK);
_java_platform_loader = OopHandle(Universe::vm_global(), platform_loader);
} else {
// It must have been restored from the archived module graph
assert(UseSharedSpaces, "must be");
assert(MetaspaceShared::use_full_module_graph(), "must be");
DEBUG_ONLY(
oop platform_loader = get_platform_class_loader_impl(CHECK);
assert(_java_platform_loader.resolve() == platform_loader, "must be");
)
}
}

oop SystemDictionary::get_system_class_loader_impl(TRAPS) {
JavaValue result(T_OBJECT);
InstanceKlass* class_loader_klass = vmClasses::ClassLoader_klass();
JavaCalls::call_static(&result,
class_loader_klass,
vmSymbols::getSystemClassLoader_name(),
vmSymbols::void_classloader_signature(),
CHECK);

_java_system_loader = OopHandle(Universe::vm_global(), result.get_oop());
CHECK_NULL);
return result.get_oop();
}

oop SystemDictionary::get_platform_class_loader_impl(TRAPS) {
JavaValue result(T_OBJECT);
InstanceKlass* class_loader_klass = vmClasses::ClassLoader_klass();
JavaCalls::call_static(&result,
class_loader_klass,
vmSymbols::getPlatformClassLoader_name(),
vmSymbols::void_classloader_signature(),
CHECK);

_java_platform_loader = OopHandle(Universe::vm_global(), result.get_oop());
CHECK_NULL);
return result.get_oop();
}

ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, bool create_mirror_cld) {
Expand All @@ -176,6 +206,18 @@ ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, bool cre
}
}

void SystemDictionary::set_system_loader(ClassLoaderData *cld) {
if (_java_system_loader.is_empty()) {
_java_system_loader = cld->class_loader_handle();
}
}

void SystemDictionary::set_platform_loader(ClassLoaderData *cld) {
if (_java_platform_loader.is_empty()) {
_java_platform_loader = cld->class_loader_handle();
}
}

// ----------------------------------------------------------------------------
// Parallel class loading check

Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/classfile/systemDictionary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class SystemDictionary : AllStatic {
const ClassLoadInfo& cl_info,
TRAPS);

static oop get_system_class_loader_impl(TRAPS);
static oop get_platform_class_loader_impl(TRAPS);

public:
// Resolve either a hidden or normal class from a stream of bytes, based on ClassLoadInfo
static InstanceKlass* resolve_from_stream(ClassFileStream* st,
Expand Down Expand Up @@ -217,6 +220,9 @@ class SystemDictionary : AllStatic {
// Register a new class loader
static ClassLoaderData* register_loader(Handle class_loader, bool create_mirror_cld = false);

static void set_system_loader(ClassLoaderData *cld);
static void set_platform_loader(ClassLoaderData *cld);

static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked,
Handle loader1, Handle loader2, bool is_method);

Expand Down

1 comment on commit 27c8826

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.