@@ -2036,47 +2036,46 @@ Method* SystemDictionary::find_method_handle_intrinsic(vmIntrinsicID iid,
2036
2036
Symbol* signature,
2037
2037
TRAPS) {
2038
2038
2039
- methodHandle empty;
2040
2039
const int iid_as_int = vmIntrinsics::as_int (iid);
2041
2040
assert (MethodHandles::is_signature_polymorphic (iid) &&
2042
2041
MethodHandles::is_signature_polymorphic_intrinsic (iid) &&
2043
2042
iid != vmIntrinsics::_invokeGeneric,
2044
2043
" must be a known MH intrinsic iid=%d: %s" , iid_as_int, vmIntrinsics::name_at (iid));
2045
2044
2046
- Method** met;
2047
- InvokeMethodKey key (signature, iid_as_int);
2048
2045
{
2049
2046
MutexLocker ml (THREAD, InvokeMethodTable_lock);
2050
- met = _invoke_method_intrinsic_table.get (key);
2047
+ InvokeMethodKey key (signature, iid_as_int);
2048
+ Method** met = _invoke_method_intrinsic_table.get (key);
2051
2049
if (met != nullptr ) {
2052
2050
return *met;
2053
2051
}
2054
- }
2055
2052
2056
- methodHandle m = Method::make_method_handle_intrinsic (iid, signature, CHECK_NULL);
2057
- if (!Arguments::is_interpreter_only () || iid == vmIntrinsics::_linkToNative) {
2058
- // Generate a compiled form of the MH intrinsic
2059
- // linkToNative doesn't have interpreter-specific implementation, so always has to go through compiled version.
2060
- AdapterHandlerLibrary::create_native_wrapper (m);
2061
- // Check if have the compiled code.
2062
- if (!m->has_compiled_code ()) {
2063
- THROW_MSG_NULL (vmSymbols::java_lang_VirtualMachineError (),
2064
- " Out of space in CodeCache for method handle intrinsic" );
2065
- }
2066
- }
2067
- // Now grab the lock. We might have to throw away the new method,
2068
- // if a racing thread has managed to install one at the same time.
2069
- {
2070
- MutexLocker ml (THREAD, InvokeMethodTable_lock);
2071
- signature->make_permanent (); // The signature is never unloaded.
2072
- bool created;
2073
- met = _invoke_method_intrinsic_table.put_if_absent (key, m (), &created);
2074
- Method* saved_method = *met;
2075
- assert (Arguments::is_interpreter_only () || (saved_method->has_compiled_code () &&
2076
- saved_method->code ()->entry_point () == saved_method->from_compiled_entry ()),
2077
- " MH intrinsic invariant" );
2078
- return saved_method;
2053
+ bool throw_error = false ;
2054
+ // This function could get an OOM but it is safe to call inside of a lock because
2055
+ // throwing OutOfMemoryError doesn't call Java code.
2056
+ methodHandle m = Method::make_method_handle_intrinsic (iid, signature, CHECK_NULL);
2057
+ if (!Arguments::is_interpreter_only () || iid == vmIntrinsics::_linkToNative) {
2058
+ // Generate a compiled form of the MH intrinsic
2059
+ // linkToNative doesn't have interpreter-specific implementation, so always has to go through compiled version.
2060
+ AdapterHandlerLibrary::create_native_wrapper (m);
2061
+ // Check if have the compiled code.
2062
+ throw_error = (!m->has_compiled_code ());
2063
+ }
2064
+
2065
+ if (!throw_error) {
2066
+ signature->make_permanent (); // The signature is never unloaded.
2067
+ bool created = _invoke_method_intrinsic_table.put (key, m ());
2068
+ assert (created, " must be since we still hold the lock" );
2069
+ assert (Arguments::is_interpreter_only () || (m->has_compiled_code () &&
2070
+ m->code ()->entry_point () == m->from_compiled_entry ()),
2071
+ " MH intrinsic invariant" );
2072
+ return m ();
2073
+ }
2079
2074
}
2075
+
2076
+ // Throw error outside of the lock.
2077
+ THROW_MSG_NULL (vmSymbols::java_lang_VirtualMachineError (),
2078
+ " Out of space in CodeCache for method handle intrinsic" );
2080
2079
}
2081
2080
2082
2081
// Helper for unpacking the return value from linkMethod and linkCallSite.
0 commit comments