8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
Summary: Removed this function, added JavaCalls::construct_new_instance and moved SharedDictionary_lock
Reviewed-by: jiangli, ccheung, dholmes, coleenp
--- a/src/hotspot/share/classfile/systemDictionary.cpp Wed May 16 10:27:25 2018 -0700
+++ b/src/hotspot/share/classfile/systemDictionary.cpp Tue May 15 14:49:10 2018 -0700
@@ -149,8 +149,6 @@
CHECK);
_java_platform_loader = (oop)result.get_jobject();
-
- CDS_ONLY(SystemDictionaryShared::initialize(CHECK);)
}
ClassLoaderData* SystemDictionary::register_loader(Handle class_loader) {
--- a/src/hotspot/share/classfile/systemDictionary.hpp Wed May 16 10:27:25 2018 -0700
+++ b/src/hotspot/share/classfile/systemDictionary.hpp Tue May 15 14:49:10 2018 -0700
@@ -181,14 +181,12 @@
\
/* support for CDS */ \
do_klass(ByteArrayInputStream_klass, java_io_ByteArrayInputStream, Pre ) \
- do_klass(File_klass, java_io_File, Pre ) \
do_klass(URL_klass, java_net_URL, Pre ) \
do_klass(Jar_Manifest_klass, java_util_jar_Manifest, Pre ) \
do_klass(jdk_internal_loader_ClassLoaders_klass, jdk_internal_loader_ClassLoaders, Pre ) \
do_klass(jdk_internal_loader_ClassLoaders_AppClassLoader_klass, jdk_internal_loader_ClassLoaders_AppClassLoader, Pre ) \
do_klass(jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass, jdk_internal_loader_ClassLoaders_PlatformClassLoader, Pre ) \
do_klass(CodeSource_klass, java_security_CodeSource, Pre ) \
- do_klass(ParseUtil_klass, sun_net_www_ParseUtil, Pre ) \
\
do_klass(StackTraceElement_klass, java_lang_StackTraceElement, Opt ) \
\
@@ -743,6 +741,7 @@
// table of box klasses (int_klass, etc.)
static InstanceKlass* _box_klasses[T_VOID+1];
+private:
static oop _java_system_loader;
static oop _java_platform_loader;
--- a/src/hotspot/share/classfile/systemDictionaryShared.cpp Wed May 16 10:27:25 2018 -0700
+++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp Tue May 15 14:49:10 2018 -0700
@@ -60,20 +60,6 @@
objArrayOop SystemDictionaryShared::_shared_jar_urls = NULL;
objArrayOop SystemDictionaryShared::_shared_jar_manifests = NULL;
-static Mutex* SharedDictionary_lock = NULL;
-
-void SystemDictionaryShared::initialize(TRAPS) {
- if (_java_system_loader != NULL) {
- SharedDictionary_lock = new Mutex(Mutex::leaf, "SharedDictionary_lock", true);
-
- // These classes need to be initialized before calling get_shared_jar_manifest(), etc.
- SystemDictionary::ByteArrayInputStream_klass()->initialize(CHECK);
- SystemDictionary::File_klass()->initialize(CHECK);
- SystemDictionary::Jar_Manifest_klass()->initialize(CHECK);
- SystemDictionary::CodeSource_klass()->initialize(CHECK);
- }
-}
-
oop SystemDictionaryShared::shared_protection_domain(int index) {
return _shared_protection_domains->obj_at(index);
}
@@ -88,43 +74,30 @@
Handle SystemDictionaryShared::get_shared_jar_manifest(int shared_path_index, TRAPS) {
- Handle empty;
Handle manifest ;
if (shared_jar_manifest(shared_path_index) == NULL) {
SharedClassPathEntry* ent = FileMapInfo::shared_path(shared_path_index);
long size = ent->manifest_size();
if (size <= 0) {
- return empty; // No manifest - return NULL handle
+ return Handle();
}
// ByteArrayInputStream bais = new ByteArrayInputStream(buf);
- InstanceKlass* bais_klass = SystemDictionary::ByteArrayInputStream_klass();
- Handle bais = bais_klass->allocate_instance_handle(CHECK_(empty));
- {
- const char* src = ent->manifest();
- assert(src != NULL, "No Manifest data");
- typeArrayOop buf = oopFactory::new_byteArray(size, CHECK_(empty));
- typeArrayHandle bufhandle(THREAD, buf);
- char* dst = (char*)(buf->byte_at_addr(0));
- memcpy(dst, src, (size_t)size);
+ const char* src = ent->manifest();
+ assert(src != NULL, "No Manifest data");
+ typeArrayOop buf = oopFactory::new_byteArray(size, CHECK_NH);
+ typeArrayHandle bufhandle(THREAD, buf);
+ char* dst = (char*)(buf->byte_at_addr(0));
+ memcpy(dst, src, (size_t)size);
- JavaValue result(T_VOID);
- JavaCalls::call_special(&result, bais, bais_klass,
- vmSymbols::object_initializer_name(),
- vmSymbols::byte_array_void_signature(),
- bufhandle, CHECK_(empty));
- }
+ Handle bais = JavaCalls::construct_new_instance(SystemDictionary::ByteArrayInputStream_klass(),
+ vmSymbols::byte_array_void_signature(),
+ bufhandle, CHECK_NH);
// manifest = new Manifest(bais)
- InstanceKlass* manifest_klass = SystemDictionary::Jar_Manifest_klass();
- manifest = manifest_klass->allocate_instance_handle(CHECK_(empty));
- {
- JavaValue result(T_VOID);
- JavaCalls::call_special(&result, manifest, manifest_klass,
- vmSymbols::object_initializer_name(),
- vmSymbols::input_stream_void_signature(),
- bais, CHECK_(empty));
- }
+ manifest = JavaCalls::construct_new_instance(SystemDictionary::Jar_Manifest_klass(),
+ vmSymbols::input_stream_void_signature(),
+ bais, CHECK_NH);
atomic_set_shared_jar_manifest(shared_path_index, manifest());
}
@@ -141,10 +114,10 @@
Handle path_string = java_lang_String::create_from_str(path, CHECK_(url_h));
Klass* classLoaders_klass =
SystemDictionary::jdk_internal_loader_ClassLoaders_klass();
- JavaCalls::call_static(&result, classLoaders_klass,
- vmSymbols::toFileURL_name(),
- vmSymbols::toFileURL_signature(),
- path_string, CHECK_(url_h));
+ JavaCalls::call_static(&result, classLoaders_klass,
+ vmSymbols::toFileURL_name(),
+ vmSymbols::toFileURL_signature(),
+ path_string, CHECK_(url_h));
atomic_set_shared_jar_url(shared_path_index, (oop)result.get_jobject());
}
@@ -174,7 +147,7 @@
Handle manifest,
Handle url,
TRAPS) {
- assert(class_loader == _java_system_loader, "unexpected class loader");
+ assert(SystemDictionary::is_system_class_loader(class_loader()), "unexpected class loader");
// get_package_name() returns a NULL handle if the class is in unnamed package
Handle pkgname_string = get_package_name(class_name, CHECK);
if (pkgname_string.not_null()) {
@@ -228,13 +201,9 @@
Handle SystemDictionaryShared::get_protection_domain_from_classloader(Handle class_loader,
Handle url, TRAPS) {
// CodeSource cs = new CodeSource(url, null);
- InstanceKlass* cs_klass = SystemDictionary::CodeSource_klass();
- Handle cs = cs_klass->allocate_instance_handle(CHECK_NH);
- JavaValue void_result(T_VOID);
- JavaCalls::call_special(&void_result, cs, cs_klass,
- vmSymbols::object_initializer_name(),
- vmSymbols::url_code_signer_array_void_signature(),
- url, Handle(), CHECK_NH);
+ Handle cs = JavaCalls::construct_new_instance(SystemDictionary::CodeSource_klass(),
+ vmSymbols::url_code_signer_array_void_signature(),
+ url, Handle(), CHECK_NH);
// protection_domain = SecureClassLoader.getProtectionDomain(cs);
Klass* secureClassLoader_klass = SystemDictionary::SecureClassLoader_klass();
@@ -278,7 +247,7 @@
JavaValue result(T_OBJECT);
Klass* classLoaders_klass =
SystemDictionary::jdk_internal_loader_ClassLoaders_klass();
- JavaCalls::call_static(&result, classLoaders_klass, vmSymbols::toFileURL_name(),
+ JavaCalls::call_static(&result, classLoaders_klass, vmSymbols::toFileURL_name(),
vmSymbols::toFileURL_signature(),
url_string, CHECK_(protection_domain));
Handle url = Handle(THREAD, (oop)result.get_jobject());
--- a/src/hotspot/share/classfile/systemDictionaryShared.hpp Wed May 16 10:27:25 2018 -0700
+++ b/src/hotspot/share/classfile/systemDictionaryShared.hpp Tue May 15 14:49:10 2018 -0700
@@ -285,8 +285,6 @@
TRAPS);
public:
- static void initialize(TRAPS);
-
// Called by PLATFORM/APP loader only
static InstanceKlass* find_or_load_shared_class(Symbol* class_name,
Handle class_loader,
--- a/src/hotspot/share/runtime/javaCalls.cpp Wed May 16 10:27:25 2018 -0700
+++ b/src/hotspot/share/runtime/javaCalls.cpp Tue May 15 14:49:10 2018 -0700
@@ -199,13 +199,13 @@
void JavaCalls::call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, TRAPS) {
- JavaCallArguments args(receiver); // One oop argument
+ JavaCallArguments args(receiver);
call_virtual(result, spec_klass, name, signature, &args, CHECK);
}
void JavaCalls::call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
- JavaCallArguments args(receiver); // One oop argument
+ JavaCallArguments args(receiver);
args.push_oop(arg1);
call_virtual(result, spec_klass, name, signature, &args, CHECK);
}
@@ -213,7 +213,7 @@
void JavaCalls::call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
- JavaCallArguments args(receiver); // One oop argument
+ JavaCallArguments args(receiver);
args.push_oop(arg1);
args.push_oop(arg2);
call_virtual(result, spec_klass, name, signature, &args, CHECK);
@@ -235,20 +235,20 @@
void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, TRAPS) {
- JavaCallArguments args(receiver); // One oop argument
+ JavaCallArguments args(receiver);
call_special(result, klass, name, signature, &args, CHECK);
}
void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
- JavaCallArguments args(receiver); // One oop argument
+ JavaCallArguments args(receiver);
args.push_oop(arg1);
call_special(result, klass, name, signature, &args, CHECK);
}
void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
- JavaCallArguments args(receiver); // One oop argument
+ JavaCallArguments args(receiver);
args.push_oop(arg1);
args.push_oop(arg2);
call_special(result, klass, name, signature, &args, CHECK);
@@ -270,19 +270,19 @@
void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, TRAPS) {
- JavaCallArguments args; // No argument
+ JavaCallArguments args;
call_static(result, klass, name, signature, &args, CHECK);
}
void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
- JavaCallArguments args(arg1); // One oop argument
+ JavaCallArguments args(arg1);
call_static(result, klass, name, signature, &args, CHECK);
}
void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
- JavaCallArguments args; // One oop argument
+ JavaCallArguments args;
args.push_oop(arg1);
args.push_oop(arg2);
call_static(result, klass, name, signature, &args, CHECK);
@@ -290,13 +290,44 @@
void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, Handle arg3, TRAPS) {
- JavaCallArguments args; // One oop argument
+ JavaCallArguments args;
args.push_oop(arg1);
args.push_oop(arg2);
args.push_oop(arg3);
call_static(result, klass, name, signature, &args, CHECK);
}
+// ============ allocate and initialize new object instance ============
+
+Handle JavaCalls::construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, JavaCallArguments* args, TRAPS) {
+ klass->initialize(CHECK_NH); // Quick no-op if already initialized.
+ Handle obj = klass->allocate_instance_handle(CHECK_NH);
+ JavaValue void_result(T_VOID);
+ args->set_receiver(obj); // inserts <obj> as the first argument.
+ JavaCalls::call_special(&void_result, klass,
+ vmSymbols::object_initializer_name(),
+ constructor_signature, args, CHECK_NH);
+ return obj;
+}
+
+Handle JavaCalls::construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, TRAPS) {
+ JavaCallArguments args;
+ return JavaCalls::construct_new_instance(klass, constructor_signature, &args, CHECK_NH);
+}
+
+Handle JavaCalls::construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, Handle arg1, TRAPS) {
+ JavaCallArguments args;
+ args.push_oop(arg1);
+ return JavaCalls::construct_new_instance(klass, constructor_signature, &args, CHECK_NH);
+}
+
+Handle JavaCalls::construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, Handle arg1, Handle arg2, TRAPS) {
+ JavaCallArguments args;
+ args.push_oop(arg1);
+ args.push_oop(arg2);
+ return JavaCalls::construct_new_instance(klass, constructor_signature, &args, CHECK_NH);
+}
+
// -------------------------------------------------
// Implementation of JavaCalls (low level)
--- a/src/hotspot/share/runtime/javaCalls.hpp Wed May 16 10:27:25 2018 -0700
+++ b/src/hotspot/share/runtime/javaCalls.hpp Tue May 15 14:49:10 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -257,6 +257,13 @@
static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, Handle arg3, TRAPS);
+ // Allocate instance + invoke constructor. This is equivalent to "new Klass(args ...)" expression in Java code.
+ static Handle construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, JavaCallArguments* args, TRAPS);
+
+ static Handle construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, TRAPS);
+ static Handle construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, Handle arg1, TRAPS);
+ static Handle construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, Handle arg1, Handle arg2, TRAPS);
+
// Low-level interface
static void call(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS);
};
--- a/src/hotspot/share/runtime/mutexLocker.cpp Wed May 16 10:27:25 2018 -0700
+++ b/src/hotspot/share/runtime/mutexLocker.cpp Tue May 15 14:49:10 2018 -0700
@@ -39,6 +39,7 @@
Mutex* Patching_lock = NULL;
Monitor* SystemDictionary_lock = NULL;
+Mutex* SharedDictionary_lock = NULL;
Mutex* Module_lock = NULL;
Mutex* CompiledIC_lock = NULL;
Mutex* InlineCacheBuffer_lock = NULL;
@@ -221,6 +222,7 @@
def(JmethodIdCreation_lock , PaddedMutex , leaf, true, Monitor::_safepoint_check_always); // used for creating jmethodIDs.
def(SystemDictionary_lock , PaddedMonitor, leaf, true, Monitor::_safepoint_check_always); // lookups done by VM thread
+ def(SharedDictionary_lock , PaddedMutex, leaf, true, Monitor::_safepoint_check_always); // lookups done by VM thread
def(Module_lock , PaddedMutex , leaf+2, true, Monitor::_safepoint_check_always);
def(InlineCacheBuffer_lock , PaddedMutex , leaf, true, Monitor::_safepoint_check_always);
def(VMStatistic_lock , PaddedMutex , leaf, false, Monitor::_safepoint_check_always);
--- a/src/hotspot/share/runtime/mutexLocker.hpp Wed May 16 10:27:25 2018 -0700
+++ b/src/hotspot/share/runtime/mutexLocker.hpp Tue May 15 14:49:10 2018 -0700
@@ -33,6 +33,7 @@
extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
extern Monitor* SystemDictionary_lock; // a lock on the system dictionary
+extern Mutex* SharedDictionary_lock; // a lock on the CDS shared dictionary
extern Mutex* Module_lock; // a lock on module and package related data structures
extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
extern Mutex* InlineCacheBuffer_lock; // a lock used to guard the InlineCacheBuffer