56
56
#include " runtime/atomic.hpp"
57
57
#include " runtime/handles.inline.hpp"
58
58
#include " runtime/mutexLocker.hpp"
59
+ #include " runtime/synchronizer.hpp"
59
60
#include " runtime/vm_version.hpp"
60
61
#include " utilities/macros.hpp"
61
62
@@ -174,7 +175,7 @@ void ConstantPoolCache::set_direct_or_vtable_call(Bytecodes::Code invoke_code,
174
175
}
175
176
if (invoke_code == Bytecodes::_invokestatic) {
176
177
assert (method->method_holder ()->is_initialized () ||
177
- method->method_holder ()->is_init_thread (JavaThread::current ()),
178
+ method->method_holder ()->is_reentrant_initialization (JavaThread::current ()),
178
179
" invalid class initialization state for invoke_static" );
179
180
180
181
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
269
270
// A losing writer waits on the lock until the winner writes the method and leaves
270
271
// the lock, so that when the losing writer returns, he can use the linked
271
272
// cache entry.
273
+
272
274
// Lock fields to write
273
275
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);
276
276
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);
277
287
if (method_entry->is_resolved (invoke_code)) {
278
288
return method_entry;
279
289
}
@@ -311,7 +321,6 @@ ResolvedMethodEntry* ConstantPoolCache::set_method_handle(int method_index, cons
311
321
// Store appendix, if any.
312
322
if (has_appendix) {
313
323
const int appendix_index = method_entry->resolved_references_index ();
314
- objArrayOop resolved_references = constant_pool ()->resolved_references ();
315
324
assert (appendix_index >= 0 && appendix_index < resolved_references->length (), " oob" );
316
325
assert (resolved_references->obj_at (appendix_index) == nullptr , " init just once" );
317
326
resolved_references->obj_at_put (appendix_index, appendix ());
@@ -587,7 +596,14 @@ bool ConstantPoolCache::save_and_throw_indy_exc(
587
596
assert (PENDING_EXCEPTION->is_a (vmClasses::LinkageError_klass ()),
588
597
" No LinkageError exception" );
589
598
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);
591
607
592
608
// if the indy_info is resolved or the indy_resolution_failed flag is set then another
593
609
// thread either succeeded in resolving the method or got a LinkageError
@@ -610,21 +626,29 @@ bool ConstantPoolCache::save_and_throw_indy_exc(
610
626
611
627
oop ConstantPoolCache::set_dynamic_call (const CallInfo &call_info, int index) {
612
628
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);
614
640
assert (index >= 0 , " Indy index must be positive at this point" );
615
641
616
642
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 );
618
644
}
619
645
620
646
if (resolved_indy_entry_at (index )->resolution_failed ()) {
621
647
// Before we got here, another thread got a LinkageError exception during
622
648
// resolution. Ignore our success and throw their exception.
623
649
guarantee (index >= 0 , " Invalid indy index" );
624
650
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);
628
652
return nullptr ;
629
653
}
630
654
@@ -648,7 +672,6 @@ oop ConstantPoolCache::set_dynamic_call(const CallInfo &call_info, int index) {
648
672
649
673
if (has_appendix) {
650
674
const int appendix_index = resolved_indy_entry_at (index )->resolved_references_index ();
651
- objArrayOop resolved_references = constant_pool ()->resolved_references ();
652
675
assert (appendix_index >= 0 && appendix_index < resolved_references->length (), " oob" );
653
676
assert (resolved_references->obj_at (appendix_index) == nullptr , " init just once" );
654
677
resolved_references->obj_at_put (appendix_index, appendix ());
0 commit comments