@@ -1081,20 +1081,6 @@ static void restore_args(MacroAssembler *masm, int arg_count, int first_arg, VMR
1081
1081
}
1082
1082
}
1083
1083
1084
-
1085
- // Check GCLocker::needs_gc and enter the runtime if it's true. This
1086
- // keeps a new JNI critical region from starting until a GC has been
1087
- // forced. Save down any oops in registers and describe them in an
1088
- // OopMap.
1089
- static void check_needs_gc_for_critical_native (MacroAssembler* masm,
1090
- int stack_slots,
1091
- int total_c_args,
1092
- int total_in_args,
1093
- int arg_save_area,
1094
- OopMapSet* oop_maps,
1095
- VMRegPair* in_regs,
1096
- BasicType* in_sig_bt) { Unimplemented (); }
1097
-
1098
1084
// Unpack an array argument into a pointer to the body and the length
1099
1085
// if the array is non-null, otherwise pass 0 for both.
1100
1086
static void unpack_array_argument (MacroAssembler* masm, VMRegPair reg, BasicType in_elem_type, VMRegPair body_arg, VMRegPair length_arg) { Unimplemented (); }
@@ -1260,25 +1246,12 @@ static void gen_special_dispatch(MacroAssembler* masm,
1260
1246
// Critical native functions are a shorthand for the use of
1261
1247
// GetPrimtiveArrayCritical and disallow the use of any other JNI
1262
1248
// functions. The wrapper is expected to unpack the arguments before
1263
- // passing them to the callee and perform checks before and after the
1264
- // native call to ensure that they GCLocker
1265
- // lock_critical/unlock_critical semantics are followed. Some other
1266
- // parts of JNI setup are skipped like the tear down of the JNI handle
1249
+ // passing them to the callee. Critical native functions leave the state _in_Java,
1250
+ // since they block out GC.
1251
+ // Some other parts of JNI setup are skipped like the tear down of the JNI handle
1267
1252
// block and the check for pending exceptions it's impossible for them
1268
1253
// to be thrown.
1269
1254
//
1270
- // They are roughly structured like this:
1271
- // if (GCLocker::needs_gc())
1272
- // SharedRuntime::block_for_jni_critical();
1273
- // tranistion to thread_in_native
1274
- // unpack arrray arguments and call native entry point
1275
- // check for safepoint in progress
1276
- // check if any thread suspend flags are set
1277
- // call into JVM and possible unlock the JNI critical
1278
- // if a GC was suppressed while in the critical native.
1279
- // transition back to thread_in_Java
1280
- // return to caller
1281
- //
1282
1255
nmethod* SharedRuntime::generate_native_wrapper (MacroAssembler* masm,
1283
1256
const methodHandle& method,
1284
1257
int compile_id,
@@ -1546,11 +1519,6 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
1546
1519
1547
1520
const Register oop_handle_reg = r20;
1548
1521
1549
- if (is_critical_native) {
1550
- check_needs_gc_for_critical_native (masm, stack_slots, total_c_args, total_in_args,
1551
- oop_handle_offset, oop_maps, in_regs, in_sig_bt);
1552
- }
1553
-
1554
1522
//
1555
1523
// We immediately shuffle the arguments so that any vm call we have to
1556
1524
// make from here on out (sync slow path, jvmti, etc.) we will have
@@ -1823,12 +1791,12 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
1823
1791
// get JNIEnv* which is first argument to native
1824
1792
if (!is_critical_native) {
1825
1793
__ lea (c_rarg0, Address (rthread, in_bytes (JavaThread::jni_environment_offset ())));
1826
- }
1827
1794
1828
- // Now set thread in native
1829
- __ mov (rscratch1, _thread_in_native);
1830
- __ lea (rscratch2, Address (rthread, JavaThread::thread_state_offset ()));
1831
- __ stlrw (rscratch1, rscratch2);
1795
+ // Now set thread in native
1796
+ __ mov (rscratch1, _thread_in_native);
1797
+ __ lea (rscratch2, Address (rthread, JavaThread::thread_state_offset ()));
1798
+ __ stlrw (rscratch1, rscratch2);
1799
+ }
1832
1800
1833
1801
rt_call (masm, native_func);
1834
1802
@@ -1856,6 +1824,21 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
1856
1824
default : ShouldNotReachHere ();
1857
1825
}
1858
1826
1827
+ Label safepoint_in_progress, safepoint_in_progress_done;
1828
+ Label after_transition;
1829
+
1830
+ // If this is a critical native, check for a safepoint or suspend request after the call.
1831
+ // If a safepoint is needed, transition to native, then to native_trans to handle
1832
+ // safepoints like the native methods that are not critical natives.
1833
+ if (is_critical_native) {
1834
+ Label needs_safepoint;
1835
+ __ safepoint_poll (needs_safepoint, false /* at_return */ , true /* acquire */ , false /* in_nmethod */ );
1836
+ __ ldrw (rscratch1, Address (rthread, JavaThread::suspend_flags_offset ()));
1837
+ __ cbnzw (rscratch1, needs_safepoint);
1838
+ __ b (after_transition);
1839
+ __ bind (needs_safepoint);
1840
+ }
1841
+
1859
1842
// Switch thread to "native transition" state before reading the synchronization state.
1860
1843
// This additional state is necessary because reading and testing the synchronization
1861
1844
// state is not atomic w.r.t. GC, as this scenario demonstrates:
@@ -1876,7 +1859,6 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
1876
1859
}
1877
1860
1878
1861
// check for safepoint operation in progress and/or pending suspend requests
1879
- Label safepoint_in_progress, safepoint_in_progress_done;
1880
1862
{
1881
1863
// We need an acquire here to ensure that any subsequent load of the
1882
1864
// global SafepointSynchronize::_state flag is ordered after this load
@@ -1894,7 +1876,6 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
1894
1876
}
1895
1877
1896
1878
// change thread state
1897
- Label after_transition;
1898
1879
__ mov (rscratch1, _thread_in_Java);
1899
1880
__ lea (rscratch2, Address (rthread, JavaThread::thread_state_offset ()));
1900
1881
__ stlrw (rscratch1, rscratch2);
@@ -2099,22 +2080,12 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
2099
2080
#ifndef PRODUCT
2100
2081
assert (frame::arg_reg_save_area_bytes == 0 , " not expecting frame reg save area" );
2101
2082
#endif
2102
- if (!is_critical_native) {
2103
- __ lea (rscratch1, RuntimeAddress (CAST_FROM_FN_PTR (address, JavaThread::check_special_condition_for_native_trans)));
2104
- } else {
2105
- __ lea (rscratch1, RuntimeAddress (CAST_FROM_FN_PTR (address, JavaThread::check_special_condition_for_native_trans_and_transition)));
2106
- }
2083
+ __ lea (rscratch1, RuntimeAddress (CAST_FROM_FN_PTR (address, JavaThread::check_special_condition_for_native_trans)));
2107
2084
__ blr (rscratch1);
2108
2085
__ maybe_isb ();
2109
2086
// Restore any method result value
2110
2087
restore_native_result (masm, ret_type, stack_slots);
2111
2088
2112
- if (is_critical_native) {
2113
- // The call above performed the transition to thread_in_Java so
2114
- // skip the transition logic above.
2115
- __ b (after_transition);
2116
- }
2117
-
2118
2089
__ b (safepoint_in_progress_done);
2119
2090
__ block_comment (" } safepoint" );
2120
2091
}
@@ -2163,12 +2134,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
2163
2134
in_ByteSize (lock_slot_offset*VMRegImpl::stack_slot_size),
2164
2135
oop_maps);
2165
2136
2166
- if (is_critical_native) {
2167
- nm->set_lazy_critical_native (true );
2168
- }
2169
-
2170
2137
return nm;
2171
-
2172
2138
}
2173
2139
2174
2140
// this function returns the adjust size (in number of words) to a c2i adapter
0 commit comments