@@ -1583,13 +1583,11 @@ void SystemDictionary::methods_do(void f(Method*)) {
1583
1583
}
1584
1584
1585
1585
auto doit = [&] (InvokeMethodKey key, Method* method) {
1586
- if (method != nullptr ) {
1587
- f (method);
1588
- }
1586
+ f (method);
1589
1587
};
1590
1588
1591
1589
{
1592
- MutexLocker ml (InvokeMethodIntrinsicTable_lock );
1590
+ MutexLocker ml (InvokeMethodTable_lock );
1593
1591
_invoke_method_intrinsic_table.iterate_all (doit);
1594
1592
}
1595
1593
@@ -1941,62 +1939,40 @@ Method* SystemDictionary::find_method_handle_intrinsic(vmIntrinsicID iid,
1941
1939
iid != vmIntrinsics::_invokeGeneric,
1942
1940
" must be a known MH intrinsic iid=%d: %s" , iid_as_int, vmIntrinsics::name_at (iid));
1943
1941
1944
- InvokeMethodKey key (signature, iid_as_int);
1945
- Method** met = nullptr ;
1946
-
1947
- // We only want one entry in the table for this (signature/id, method) pair but the code
1948
- // to create the intrinsic method needs to be outside the lock.
1949
- // The first thread claims the entry by adding the key and the other threads wait, until the
1950
- // Method has been added as the value.
1951
1942
{
1952
- MonitorLocker ml (THREAD, InvokeMethodIntrinsicTable_lock);
1953
- while (met == nullptr ) {
1954
- bool created;
1955
- met = _invoke_method_intrinsic_table.put_if_absent (key, &created);
1956
- if (met != nullptr && *met != nullptr ) {
1957
- return *met;
1958
- } else if (!created) {
1959
- // Second thread waits for first to actually create the entry and returns
1960
- // it after notify. Loop until method return is non-null.
1961
- ml.wait ();
1962
- }
1943
+ MutexLocker ml (THREAD, InvokeMethodTable_lock);
1944
+ InvokeMethodKey key (signature, iid_as_int);
1945
+ Method** met = _invoke_method_intrinsic_table.get (key);
1946
+ if (met != nullptr ) {
1947
+ return *met;
1963
1948
}
1964
- }
1965
1949
1966
- methodHandle m = Method::make_method_handle_intrinsic (iid, signature, THREAD);
1967
- bool throw_error = HAS_PENDING_EXCEPTION;
1968
- if (!throw_error && (!Arguments::is_interpreter_only () || iid == vmIntrinsics::_linkToNative)) {
1969
- // Generate a compiled form of the MH intrinsic
1970
- // linkToNative doesn't have interpreter-specific implementation, so always has to go through compiled version.
1971
- AdapterHandlerLibrary::create_native_wrapper (m);
1972
- // Check if have the compiled code.
1973
- throw_error = (!m->has_compiled_code ());
1974
- }
1950
+ bool throw_error = false ;
1951
+ // This function could get an OOM but it is safe to call inside of a lock because
1952
+ // throwing OutOfMemoryError doesn't call Java code.
1953
+ methodHandle m = Method::make_method_handle_intrinsic (iid, signature, CHECK_NULL);
1954
+ if (!Arguments::is_interpreter_only () || iid == vmIntrinsics::_linkToNative) {
1955
+ // Generate a compiled form of the MH intrinsic
1956
+ // linkToNative doesn't have interpreter-specific implementation, so always has to go through compiled version.
1957
+ AdapterHandlerLibrary::create_native_wrapper (m);
1958
+ // Check if have the compiled code.
1959
+ throw_error = (!m->has_compiled_code ());
1960
+ }
1975
1961
1976
- {
1977
- MonitorLocker ml (THREAD, InvokeMethodIntrinsicTable_lock);
1978
- if (throw_error) {
1979
- // Remove the entry and let another thread try, or get the same exception.
1980
- bool removed = _invoke_method_intrinsic_table.remove (key);
1981
- assert (removed, " must be the owner" );
1982
- ml.notify_all ();
1983
- } else {
1962
+ if (!throw_error) {
1984
1963
signature->make_permanent (); // The signature is never unloaded.
1964
+ bool created = _invoke_method_intrinsic_table.put (key, m ());
1965
+ assert (created, " must be since we still hold the lock" );
1985
1966
assert (Arguments::is_interpreter_only () || (m->has_compiled_code () &&
1986
1967
m->code ()->entry_point () == m->from_compiled_entry ()),
1987
1968
" MH intrinsic invariant" );
1988
- *met = m (); // insert the element
1989
- ml.notify_all ();
1990
1969
return m ();
1991
1970
}
1992
1971
}
1993
1972
1994
- // Throw VirtualMachineError or the pending exception in the JavaThread
1995
- if (throw_error && !HAS_PENDING_EXCEPTION) {
1996
- THROW_MSG_NULL (vmSymbols::java_lang_VirtualMachineError (),
1997
- " Out of space in CodeCache for method handle intrinsic" );
1998
- }
1999
- return nullptr ;
1973
+ // Throw error outside of the lock.
1974
+ THROW_MSG_NULL (vmSymbols::java_lang_VirtualMachineError (),
1975
+ " Out of space in CodeCache for method handle intrinsic" );
2000
1976
}
2001
1977
2002
1978
// Helper for unpacking the return value from linkMethod and linkCallSite.
@@ -2139,7 +2115,7 @@ Handle SystemDictionary::find_method_handle_type(Symbol* signature,
2139
2115
Handle empty;
2140
2116
OopHandle* o;
2141
2117
{
2142
- MutexLocker ml (THREAD, InvokeMethodTypeTable_lock );
2118
+ MutexLocker ml (THREAD, InvokeMethodTable_lock );
2143
2119
o = _invoke_method_type_table.get (signature);
2144
2120
}
2145
2121
@@ -2208,7 +2184,7 @@ Handle SystemDictionary::find_method_handle_type(Symbol* signature,
2208
2184
2209
2185
if (can_be_cached) {
2210
2186
// We can cache this MethodType inside the JVM.
2211
- MutexLocker ml (THREAD, InvokeMethodTypeTable_lock );
2187
+ MutexLocker ml (THREAD, InvokeMethodTable_lock );
2212
2188
bool created = false ;
2213
2189
assert (method_type != nullptr , " unexpected null" );
2214
2190
OopHandle* h = _invoke_method_type_table.get (signature);
0 commit comments