Skip to content

Commit 27d2abe

Browse files
Boris UlasevichPaul Hohensee
authored andcommitted
8320892: AArch64: Restore FPU control state after JNI
Backport-of: 50f31240555888018f0f496ab29c8a5932dce459
1 parent fe4b0fa commit 27d2abe

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

src/hotspot/cpu/aarch64/downcallLinker_aarch64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ void DowncallStubGenerator::generate() {
269269
Label L_reguard;
270270
Label L_after_reguard;
271271
if (_needs_transition) {
272+
// Restore cpu control state after JNI call
273+
__ restore_cpu_control_state_after_jni(rscratch1, tmp1);
274+
272275
__ mov(tmp1, _thread_in_native_trans);
273276
__ strw(tmp1, Address(rthread, JavaThread::thread_state_offset()));
274277

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4435,6 +4435,23 @@ void MacroAssembler::load_klass(Register dst, Register src) {
44354435
}
44364436
}
44374437

4438+
void MacroAssembler::restore_cpu_control_state_after_jni(Register tmp1, Register tmp2) {
4439+
if (RestoreMXCSROnJNICalls) {
4440+
Label OK;
4441+
get_fpcr(tmp1);
4442+
mov(tmp2, tmp1);
4443+
// Set FPCR to the state we need. We do want Round to Nearest. We
4444+
// don't want non-IEEE rounding modes or floating-point traps.
4445+
bfi(tmp1, zr, 22, 4); // Clear DN, FZ, and Rmode
4446+
bfi(tmp1, zr, 8, 5); // Clear exception-control bits (8-12)
4447+
bfi(tmp1, zr, 0, 2); // Clear AH:FIZ
4448+
eor(tmp2, tmp1, tmp2);
4449+
cbz(tmp2, OK); // Only reset FPCR if it's wrong
4450+
set_fpcr(tmp1);
4451+
bind(OK);
4452+
}
4453+
}
4454+
44384455
// ((OopHandle)result).resolve();
44394456
void MacroAssembler::resolve_oop_handle(Register result, Register tmp1, Register tmp2) {
44404457
// OopHandle::resolve is an indirection.

src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,8 @@ class MacroAssembler: public Assembler {
10461046
#define verify_method_ptr(reg) _verify_method_ptr(reg, "broken method " #reg, __FILE__, __LINE__)
10471047
#define verify_klass_ptr(reg) _verify_klass_ptr(reg, "broken klass " #reg, __FILE__, __LINE__)
10481048

1049-
// only if +VerifyFPU
1050-
void verify_FPU(int stack_depth, const char* s = "illegal FPU state");
1049+
// Restore cpu control state after JNI call
1050+
void restore_cpu_control_state_after_jni(Register tmp1, Register tmp2);
10511051

10521052
// prints msg, dumps registers and stops execution
10531053
void stop(const char* msg);

src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,9 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
18451845
intptr_t return_pc = (intptr_t) __ pc();
18461846
oop_maps->add_gc_map(return_pc - start, map);
18471847

1848+
// Verify or restore cpu control state after JNI call
1849+
__ restore_cpu_control_state_after_jni(rscratch1, rscratch2);
1850+
18481851
// Unpack native results.
18491852
switch (ret_type) {
18501853
case T_BOOLEAN: __ c2bool(r0); break;

src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,9 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
13661366
__ get_method(rmethod);
13671367
// result potentially in r0 or v0
13681368

1369+
// Restore cpu control state after JNI call
1370+
__ restore_cpu_control_state_after_jni(rscratch1, rscratch2);
1371+
13691372
// make room for the pushes we're about to do
13701373
__ sub(rscratch1, esp, 4 * wordSize);
13711374
__ andr(sp, rscratch1, -16);

0 commit comments

Comments
 (0)