Skip to content

Commit

Permalink
8258015: [JVMCI] JVMCI_lock shouldn't be held while initializing box …
Browse files Browse the repository at this point in the history
…classes

Reviewed-by: iveresov
  • Loading branch information
Doug Simon committed Dec 10, 2020
1 parent b35401d commit d163c6f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/hotspot/share/jvmci/jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
JVMCIRuntime* JVMCI::_compiler_runtime = NULL;
JVMCIRuntime* JVMCI::_java_runtime = NULL;
volatile bool JVMCI::_is_initialized = false;
volatile bool JVMCI::_box_caches_initialized = false;
bool JVMCI::_box_caches_initialized = false;
void* JVMCI::_shared_library_handle = NULL;
char* JVMCI::_shared_library_path = NULL;
volatile bool JVMCI::_in_shutdown = false;
Expand Down Expand Up @@ -130,12 +130,9 @@ void JVMCI::ensure_box_caches_initialized(TRAPS) {
if (_box_caches_initialized) {
return;
}
MutexLocker locker(JVMCI_lock);
// Check again after locking
if (_box_caches_initialized) {
return;
}

// While multiple threads may reach here, that's fine
// since class initialization is synchronized.
Symbol* box_classes[] = {
java_lang_Boolean::symbol(),
java_lang_Byte_ByteCache::symbol(),
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/jvmci/jvmci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class JVMCI : public AllStatic {
// execution has completed successfully.
static volatile bool _is_initialized;

// used to synchronize lazy initialization of boxing cache classes.
static volatile bool _box_caches_initialized;
// True once boxing cache classes are guaranteed to be initialized.
static bool _box_caches_initialized;

// Handle created when loading the JVMCI shared library with os::dll_load.
// Must hold JVMCI_lock when initializing.
Expand Down
11 changes: 5 additions & 6 deletions src/hotspot/share/jvmci/jvmciCodeInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ JVMCI::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer, bo
}
}
#endif
if (_has_auto_box) {
JavaThread* THREAD = JavaThread::current();
JVMCI::ensure_box_caches_initialized(CHECK_(JVMCI::ok));
}
return JVMCI::ok;
}

Expand Down Expand Up @@ -1022,15 +1026,14 @@ GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(JVMCIObject de
}
GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(JVMCIENV->get_length(virtualObjects), JVMCIENV->get_length(virtualObjects), NULL);
// Create the unique ObjectValues
bool has_auto_box = false;
for (int i = 0; i < JVMCIENV->get_length(virtualObjects); i++) {
// HandleMark hm(THREAD);
JVMCIObject value = JVMCIENV->get_object_at(virtualObjects, i);
int id = jvmci_env()->get_VirtualObject_id(value);
JVMCIObject type = jvmci_env()->get_VirtualObject_type(value);
bool is_auto_box = jvmci_env()->get_VirtualObject_isAutoBox(value);
if (is_auto_box) {
has_auto_box = true;
_has_auto_box = true;
}
Klass* klass = jvmci_env()->asKlass(type);
oop javaMirror = klass->java_mirror();
Expand All @@ -1054,10 +1057,6 @@ GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(JVMCIObject de
}
_debug_recorder->dump_object_pool(objects);

if (has_auto_box) {
JavaThread* THREAD = JavaThread::current();
JVMCI::ensure_box_caches_initialized(CHECK_NULL);
}
return objects;
}

Expand Down
7 changes: 6 additions & 1 deletion src/hotspot/share/jvmci/jvmciCodeInstaller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class CodeInstaller : public StackObj {
Dependencies* _dependencies;
ExceptionHandlerTable _exception_handler_table;
ImplicitExceptionTable _implicit_exception_table;
bool _has_auto_box;

bool _immutable_pic_compilation; // Installer is called for Immutable PIC compilation.

Expand Down Expand Up @@ -230,7 +231,11 @@ class CodeInstaller : public StackObj {

public:

CodeInstaller(JVMCIEnv* jvmci_env, bool immutable_pic_compilation) : _arena(mtJVMCI), _jvmci_env(jvmci_env), _immutable_pic_compilation(immutable_pic_compilation) {}
CodeInstaller(JVMCIEnv* jvmci_env, bool immutable_pic_compilation) :
_arena(mtJVMCI),
_jvmci_env(jvmci_env),
_has_auto_box(false),
_immutable_pic_compilation(immutable_pic_compilation) {}

#if INCLUDE_AOT
JVMCI::CodeInstallResult gather_metadata(JVMCIObject target, JVMCIObject compiled_code, CodeMetadata& metadata, JVMCI_TRAPS);
Expand Down

1 comment on commit d163c6f

@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.