5656#include " runtime/atomic.hpp"
5757#include " runtime/handles.inline.hpp"
5858#include " runtime/mutexLocker.hpp"
59+ #include " runtime/synchronizer.hpp"
5960#include " runtime/vm_version.hpp"
6061#include " utilities/macros.hpp"
6162
@@ -174,7 +175,7 @@ void ConstantPoolCache::set_direct_or_vtable_call(Bytecodes::Code invoke_code,
174175 }
175176 if (invoke_code == Bytecodes::_invokestatic) {
176177 assert (method->method_holder ()->is_initialized () ||
177- method->method_holder ()->is_init_thread (JavaThread::current ()),
178+ method->method_holder ()->is_reentrant_initialization (JavaThread::current ()),
178179 " invalid class initialization state for invoke_static" );
179180
180181 if (!VM_Version::supports_fast_class_init_checks () && method->needs_clinit_barrier ()) {
@@ -269,11 +270,20 @@ ResolvedMethodEntry* ConstantPoolCache::set_method_handle(int method_index, cons
269270 // A losing writer waits on the lock until the winner writes the method and leaves
270271 // the lock, so that when the losing writer returns, he can use the linked
271272 // cache entry.
273+
272274 // Lock fields to write
273275 Bytecodes::Code invoke_code = Bytecodes::_invokehandle;
274- MutexLocker ml (constant_pool ()->pool_holder ()->init_monitor ());
275- ResolvedMethodEntry* method_entry = resolved_method_entry_at (method_index);
276276
277+ JavaThread* current = JavaThread::current ();
278+ objArrayHandle resolved_references (current, constant_pool ()->resolved_references ());
279+ // Use the resolved_references() lock for this cpCache entry.
280+ // resolved_references are created for all classes with Invokedynamic, MethodHandle
281+ // or MethodType constant pool cache entries.
282+ assert (resolved_references () != nullptr ,
283+ " a resolved_references array should have been created for this class" );
284+ ObjectLocker ol (resolved_references, current);
285+
286+ ResolvedMethodEntry* method_entry = resolved_method_entry_at (method_index);
277287 if (method_entry->is_resolved (invoke_code)) {
278288 return method_entry;
279289 }
@@ -311,7 +321,6 @@ ResolvedMethodEntry* ConstantPoolCache::set_method_handle(int method_index, cons
311321 // Store appendix, if any.
312322 if (has_appendix) {
313323 const int appendix_index = method_entry->resolved_references_index ();
314- objArrayOop resolved_references = constant_pool ()->resolved_references ();
315324 assert (appendix_index >= 0 && appendix_index < resolved_references->length (), " oob" );
316325 assert (resolved_references->obj_at (appendix_index) == nullptr , " init just once" );
317326 resolved_references->obj_at_put (appendix_index, appendix ());
@@ -587,7 +596,14 @@ bool ConstantPoolCache::save_and_throw_indy_exc(
587596 assert (PENDING_EXCEPTION->is_a (vmClasses::LinkageError_klass ()),
588597 " No LinkageError exception" );
589598
590- MutexLocker ml (THREAD, cpool->pool_holder ()->init_monitor ());
599+ // Use the resolved_references() lock for this cpCache entry.
600+ // resolved_references are created for all classes with Invokedynamic, MethodHandle
601+ // or MethodType constant pool cache entries.
602+ JavaThread* current = THREAD;
603+ objArrayHandle resolved_references (current, cpool->resolved_references ());
604+ assert (resolved_references () != nullptr ,
605+ " a resolved_references array should have been created for this class" );
606+ ObjectLocker ol (resolved_references, current);
591607
592608 // if the indy_info is resolved or the indy_resolution_failed flag is set then another
593609 // thread either succeeded in resolving the method or got a LinkageError
@@ -610,21 +626,29 @@ bool ConstantPoolCache::save_and_throw_indy_exc(
610626
611627oop ConstantPoolCache::set_dynamic_call (const CallInfo &call_info, int index) {
612628 ResourceMark rm;
613- MutexLocker ml (constant_pool ()->pool_holder ()->init_monitor ());
629+
630+ // Use the resolved_references() lock for this cpCache entry.
631+ // resolved_references are created for all classes with Invokedynamic, MethodHandle
632+ // or MethodType constant pool cache entries.
633+ JavaThread* current = JavaThread::current ();
634+ constantPoolHandle cp (current, constant_pool ());
635+
636+ objArrayHandle resolved_references (current, cp->resolved_references ());
637+ assert (resolved_references () != nullptr ,
638+ " a resolved_references array should have been created for this class" );
639+ ObjectLocker ol (resolved_references, current);
614640 assert (index >= 0 , " Indy index must be positive at this point" );
615641
616642 if (resolved_indy_entry_at (index)->method () != nullptr ) {
617- return constant_pool () ->resolved_reference_from_indy (index);
643+ return cp ->resolved_reference_from_indy (index);
618644 }
619645
620646 if (resolved_indy_entry_at (index)->resolution_failed ()) {
621647 // Before we got here, another thread got a LinkageError exception during
622648 // resolution. Ignore our success and throw their exception.
623649 guarantee (index >= 0 , " Invalid indy index" );
624650 int encoded_index = ResolutionErrorTable::encode_indy_index (index);
625- JavaThread* THREAD = JavaThread::current (); // For exception macros.
626- constantPoolHandle cp (THREAD, constant_pool ());
627- ConstantPool::throw_resolution_error (cp, encoded_index, THREAD);
651+ ConstantPool::throw_resolution_error (cp, encoded_index, current);
628652 return nullptr ;
629653 }
630654
@@ -648,7 +672,6 @@ oop ConstantPoolCache::set_dynamic_call(const CallInfo &call_info, int index) {
648672
649673 if (has_appendix) {
650674 const int appendix_index = resolved_indy_entry_at (index)->resolved_references_index ();
651- objArrayOop resolved_references = constant_pool ()->resolved_references ();
652675 assert (appendix_index >= 0 && appendix_index < resolved_references->length (), " oob" );
653676 assert (resolved_references->obj_at (appendix_index) == nullptr , " init just once" );
654677 resolved_references->obj_at_put (appendix_index, appendix ());
0 commit comments