Skip to content

Commit 56ea490

Browse files
committed
8233343: Deprecate -XX:+CriticalJNINatives flag which implements JavaCritical native functions
Reviewed-by: rehn, mdoerr, zgu
1 parent 615b759 commit 56ea490

18 files changed

+146
-1202
lines changed

src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,20 +1081,6 @@ static void restore_args(MacroAssembler *masm, int arg_count, int first_arg, VMR
10811081
}
10821082
}
10831083

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-
10981084
// Unpack an array argument into a pointer to the body and the length
10991085
// if the array is non-null, otherwise pass 0 for both.
11001086
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,
12601246
// Critical native functions are a shorthand for the use of
12611247
// GetPrimtiveArrayCritical and disallow the use of any other JNI
12621248
// 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
12671252
// block and the check for pending exceptions it's impossible for them
12681253
// to be thrown.
12691254
//
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-
//
12821255
nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
12831256
const methodHandle& method,
12841257
int compile_id,
@@ -1546,11 +1519,6 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
15461519

15471520
const Register oop_handle_reg = r20;
15481521

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-
15541522
//
15551523
// We immediately shuffle the arguments so that any vm call we have to
15561524
// make from here on out (sync slow path, jvmti, etc.) we will have
@@ -1823,12 +1791,12 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
18231791
// get JNIEnv* which is first argument to native
18241792
if (!is_critical_native) {
18251793
__ lea(c_rarg0, Address(rthread, in_bytes(JavaThread::jni_environment_offset())));
1826-
}
18271794

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+
}
18321800

18331801
rt_call(masm, native_func);
18341802

@@ -1856,6 +1824,21 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
18561824
default : ShouldNotReachHere();
18571825
}
18581826

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+
18591842
// Switch thread to "native transition" state before reading the synchronization state.
18601843
// This additional state is necessary because reading and testing the synchronization
18611844
// state is not atomic w.r.t. GC, as this scenario demonstrates:
@@ -1876,7 +1859,6 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
18761859
}
18771860

18781861
// check for safepoint operation in progress and/or pending suspend requests
1879-
Label safepoint_in_progress, safepoint_in_progress_done;
18801862
{
18811863
// We need an acquire here to ensure that any subsequent load of the
18821864
// global SafepointSynchronize::_state flag is ordered after this load
@@ -1894,7 +1876,6 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
18941876
}
18951877

18961878
// change thread state
1897-
Label after_transition;
18981879
__ mov(rscratch1, _thread_in_Java);
18991880
__ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset()));
19001881
__ stlrw(rscratch1, rscratch2);
@@ -2099,22 +2080,12 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
20992080
#ifndef PRODUCT
21002081
assert(frame::arg_reg_save_area_bytes == 0, "not expecting frame reg save area");
21012082
#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)));
21072084
__ blr(rscratch1);
21082085
__ maybe_isb();
21092086
// Restore any method result value
21102087
restore_native_result(masm, ret_type, stack_slots);
21112088

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-
21182089
__ b(safepoint_in_progress_done);
21192090
__ block_comment("} safepoint");
21202091
}
@@ -2163,12 +2134,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
21632134
in_ByteSize(lock_slot_offset*VMRegImpl::stack_slot_size),
21642135
oop_maps);
21652136

2166-
if (is_critical_native) {
2167-
nm->set_lazy_critical_native(true);
2168-
}
2169-
21702137
return nm;
2171-
21722138
}
21732139

21742140
// this function returns the adjust size (in number of words) to a c2i adapter

0 commit comments

Comments
 (0)