From aeced07db376d34cf1f4db1bbbe62061bc4a6475 Mon Sep 17 00:00:00 2001 From: Volodymyr Paprotski Date: Tue, 10 Dec 2024 23:02:16 +0000 Subject: [PATCH 1/8] fix mxcsr JNI checks --- Hello.java | 5 +++++ src/hotspot/cpu/x86/macroAssembler_x86.cpp | 14 ++++++++++++++ src/hotspot/cpu/x86/macroAssembler_x86.hpp | 1 + src/hotspot/cpu/x86/stubGenerator_x86_32.cpp | 12 ++---------- src/hotspot/cpu/x86/stubGenerator_x86_64.cpp | 10 ++-------- src/hotspot/cpu/x86/upcallLinker_x86_64.cpp | 7 +------ src/hotspot/os/windows/os_windows.cpp | 2 +- test/jdk/java/lang/String/IndexOf.java | 2 +- test/jdk/java/lang/StringBuffer/ECoreIndexOf.java | 2 +- 9 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 Hello.java diff --git a/Hello.java b/Hello.java new file mode 100644 index 0000000000000..ba55eaf0c9a54 --- /dev/null +++ b/Hello.java @@ -0,0 +1,5 @@ +class Hello { + public static void main(String[] args) { + System.out.println("Hello"); + } +} diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp index a798dea08cc79..6d641d52823d8 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp @@ -2376,6 +2376,20 @@ void MacroAssembler::jump_cc(Condition cc, AddressLiteral dst, Register rscratch } } +void MacroAssembler::cmp_mxcsr(Address mxcsr_save, Register tmp, Register rscratch) { + ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); + assert(rscratch != noreg || always_reachable(mxcsr_std), "missing"); + + stmxcsr(mxcsr_save); + movl(tmp, mxcsr_save); + if (EnableX86ECoreOpts) { + orl(tmp, 0x003f); // Mask out any pending exceptions (only check control and mask bits) + } else { + andl(tmp, 0xFFC0); // Mask out any pending exceptions (only check control and mask bits) + } + cmp32(tmp, mxcsr_std, rscratch); +} + void MacroAssembler::ldmxcsr(AddressLiteral src, Register rscratch) { assert(rscratch != noreg || always_reachable(src), "missing"); diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.hpp b/src/hotspot/cpu/x86/macroAssembler_x86.hpp index c6e5b2a115f03..eed3446916f0e 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.hpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.hpp @@ -1135,6 +1135,7 @@ class MacroAssembler: public Assembler { void fmul_s(AddressLiteral src) { Assembler::fmul_s(as_Address(src)); } #endif // !_LP64 + void cmp_mxcsr(Address mxcsr_save, Register tmp, Register rscratch = noreg); void ldmxcsr(Address src) { Assembler::ldmxcsr(src); } void ldmxcsr(AddressLiteral src, Register rscratch = noreg); diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp index de13772dcfb0d..7b872769cb5da 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp @@ -62,7 +62,6 @@ #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") -const int MXCSR_MASK = 0xFFC0; // Mask out any pending exceptions const int FPU_CNTRL_WRD_MASK = 0xFFFF; ATTRIBUTE_ALIGNED(16) static const uint32_t KEY_SHUFFLE_MASK[] = { @@ -175,11 +174,7 @@ class StubGenerator: public StubCodeGenerator { // save and initialize %mxcsr if (sse_save) { Label skip_ldmx; - __ stmxcsr(mxcsr_save); - __ movl(rax, mxcsr_save); - __ andl(rax, MXCSR_MASK); // Only check control and mask bits - ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); - __ cmp32(rax, mxcsr_std); + __ cmp_mxcsr(mxcsr_save, rax, noreg); __ jcc(Assembler::equal, skip_ldmx); __ ldmxcsr(mxcsr_std); __ bind(skip_ldmx); @@ -465,10 +460,7 @@ class StubGenerator: public StubCodeGenerator { ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); __ push(rax); __ subptr(rsp, wordSize); // allocate a temp location - __ stmxcsr(mxcsr_save); - __ movl(rax, mxcsr_save); - __ andl(rax, MXCSR_MASK); - __ cmp32(rax, mxcsr_std); + __ cmp_mxcsr(mxcsr_save, rax); __ jcc(Assembler::equal, ok_ret); __ warn("MXCSR changed by native JNI code."); diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp index 3979237619c92..603997ac73d05 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp @@ -248,11 +248,8 @@ address StubGenerator::generate_call_stub(address& return_address) { const Address mxcsr_save(rbp, mxcsr_off * wordSize); { Label skip_ldmx; - __ stmxcsr(mxcsr_save); - __ movl(rax, mxcsr_save); - __ andl(rax, 0xFFC0); // Mask out any pending exceptions (only check control and mask bits) ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); - __ cmp32(rax, mxcsr_std, rscratch1); + __ cmp_mxcsr(mxcsr_save, rax, rscratch1); __ jcc(Assembler::equal, skip_ldmx); __ ldmxcsr(mxcsr_std, rscratch1); __ bind(skip_ldmx); @@ -574,10 +571,7 @@ address StubGenerator::generate_verify_mxcsr() { ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); __ push(rax); __ subptr(rsp, wordSize); // allocate a temp location - __ stmxcsr(mxcsr_save); - __ movl(rax, mxcsr_save); - __ andl(rax, 0xFFC0); // Mask out any pending exceptions (only check control and mask bits) - __ cmp32(rax, mxcsr_std, rscratch1); + __ cmp_mxcsr(mxcsr_save, rax, rscratch1); __ jcc(Assembler::equal, ok_ret); __ warn("MXCSR changed by native JNI code, use -XX:+RestoreMXCSROnJNICall"); diff --git a/src/hotspot/cpu/x86/upcallLinker_x86_64.cpp b/src/hotspot/cpu/x86/upcallLinker_x86_64.cpp index e2dadf7f0ef98..2756c5e660b89 100644 --- a/src/hotspot/cpu/x86/upcallLinker_x86_64.cpp +++ b/src/hotspot/cpu/x86/upcallLinker_x86_64.cpp @@ -77,8 +77,6 @@ static int compute_reg_save_area_size(const ABIDescriptor& abi) { return size; } -constexpr int MXCSR_MASK = 0xFFC0; // Mask out any pending exceptions - static void preserve_callee_saved_registers(MacroAssembler* _masm, const ABIDescriptor& abi, int reg_save_area_offset) { // 1. iterate all registers in the architecture // - check if they are volatile or not for the given abi @@ -115,11 +113,8 @@ static void preserve_callee_saved_registers(MacroAssembler* _masm, const ABIDesc { const Address mxcsr_save(rsp, offset); Label skip_ldmx; - __ stmxcsr(mxcsr_save); - __ movl(rax, mxcsr_save); - __ andl(rax, MXCSR_MASK); // Only check control and mask bits ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); - __ cmp32(rax, mxcsr_std, rscratch1); + __ cmp_mxcsr(mxcsr_save, rax, rscratch1); __ jcc(Assembler::equal, skip_ldmx); __ ldmxcsr(mxcsr_std, rscratch1); __ bind(skip_ldmx); diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index afd8fe01752b0..635d09a23a28b 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -2588,7 +2588,7 @@ static bool handle_FLT_exception(struct _EXCEPTION_POINTERS* exceptionInfo) { // On Windows, the mxcsr control bits are non-volatile across calls // See also CR 6192333 // - jint MxCsr = INITIAL_MXCSR; + jint MxCsr = INITIAL_MXCSR; // FIXME? this is `define INITIAL_MXCSR 0x1f80` in windows sdk // we can't use StubRoutines::x86::addr_mxcsr_std() // because in Win64 mxcsr is not saved there if (MxCsr != ctx->MxCsr) { diff --git a/test/jdk/java/lang/String/IndexOf.java b/test/jdk/java/lang/String/IndexOf.java index e37e253f2516c..b4fd17105a8a5 100644 --- a/test/jdk/java/lang/String/IndexOf.java +++ b/test/jdk/java/lang/String/IndexOf.java @@ -34,7 +34,7 @@ * @summary test String indexOf() intrinsic * @requires vm.cpu.features ~= ".*avx2.*" * @requires vm.compiler2.enabled - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -Xcomp -XX:-TieredCompilation -XX:UseAVX=2 -XX:+UnlockDiagnosticVMOptions -XX:+EnableX86ECoreOpts -XX:-CheckJNICalls IndexOf + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -Xcomp -XX:-TieredCompilation -XX:UseAVX=2 -XX:+UnlockDiagnosticVMOptions -XX:+EnableX86ECoreOpts IndexOf */ public class IndexOf { diff --git a/test/jdk/java/lang/StringBuffer/ECoreIndexOf.java b/test/jdk/java/lang/StringBuffer/ECoreIndexOf.java index 942486e85b8dc..ccaee0f77ea22 100644 --- a/test/jdk/java/lang/StringBuffer/ECoreIndexOf.java +++ b/test/jdk/java/lang/StringBuffer/ECoreIndexOf.java @@ -34,7 +34,7 @@ * @summary Test indexOf and lastIndexOf * @requires vm.cpu.features ~= ".*avx2.*" * @requires vm.compiler2.enabled - * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+EnableX86ECoreOpts -XX:-CheckJNICalls -XX:UseAVX=2 -Xbatch -XX:-TieredCompilation -XX:CompileCommand=dontinline,ECoreIndexOf.indexOfKernel ECoreIndexOf + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+EnableX86ECoreOpts -XX:UseAVX=2 -Xbatch -XX:-TieredCompilation -XX:CompileCommand=dontinline,ECoreIndexOf.indexOfKernel ECoreIndexOf * @key randomness */ From c106e35057f185a621f212c79f117d4a01130d01 Mon Sep 17 00:00:00 2001 From: Volodymyr Paprotski Date: Wed, 11 Dec 2024 01:23:34 +0000 Subject: [PATCH 2/8] whitespace --- Hello.java | 5 ----- src/hotspot/cpu/x86/macroAssembler_x86.cpp | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 Hello.java diff --git a/Hello.java b/Hello.java deleted file mode 100644 index ba55eaf0c9a54..0000000000000 --- a/Hello.java +++ /dev/null @@ -1,5 +0,0 @@ -class Hello { - public static void main(String[] args) { - System.out.println("Hello"); - } -} diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp index 6d641d52823d8..8c5de4b74be63 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp @@ -2379,11 +2379,11 @@ void MacroAssembler::jump_cc(Condition cc, AddressLiteral dst, Register rscratch void MacroAssembler::cmp_mxcsr(Address mxcsr_save, Register tmp, Register rscratch) { ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); assert(rscratch != noreg || always_reachable(mxcsr_std), "missing"); - + stmxcsr(mxcsr_save); movl(tmp, mxcsr_save); if (EnableX86ECoreOpts) { - orl(tmp, 0x003f); // Mask out any pending exceptions (only check control and mask bits) + orl(tmp, 0x003f); // Set exceptions bits, addr_mxcsr_std has them set for ECore } else { andl(tmp, 0xFFC0); // Mask out any pending exceptions (only check control and mask bits) } From 6768b9df6ef296714b9a11187a5eb61aec4bcaf0 Mon Sep 17 00:00:00 2001 From: Volodymyr Paprotski Date: Thu, 23 Jan 2025 13:01:58 -0500 Subject: [PATCH 3/8] cleanup --- src/hotspot/cpu/x86/macroAssembler_x86.cpp | 7 ++-- src/hotspot/cpu/x86/macroAssembler_x86.hpp | 2 +- src/hotspot/cpu/x86/stubGenerator_x86_32.cpp | 6 +-- src/hotspot/cpu/x86/stubGenerator_x86_64.cpp | 6 +-- src/hotspot/cpu/x86/upcallLinker_x86_64.cpp | 4 +- src/hotspot/os/windows/os_windows.cpp | 33 +---------------- .../os_cpu/windows_x86/os_windows_x86.cpp | 37 +++++++++++++++++++ 7 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp index 8c5de4b74be63..29c7cf28809b8 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp @@ -2376,16 +2376,17 @@ void MacroAssembler::jump_cc(Condition cc, AddressLiteral dst, Register rscratch } } -void MacroAssembler::cmp_mxcsr(Address mxcsr_save, Register tmp, Register rscratch) { +void MacroAssembler::cmp32_mxcsr_std(Address mxcsr_save, Register tmp, Register rscratch) { ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); assert(rscratch != noreg || always_reachable(mxcsr_std), "missing"); stmxcsr(mxcsr_save); movl(tmp, mxcsr_save); + // Mask out any pending exceptions (only check control and mask bits) if (EnableX86ECoreOpts) { - orl(tmp, 0x003f); // Set exceptions bits, addr_mxcsr_std has them set for ECore + orl(tmp, 0x003f); // On Ecore, exception bits are set by default } else { - andl(tmp, 0xFFC0); // Mask out any pending exceptions (only check control and mask bits) + andl(tmp, 0xFFC0); } cmp32(tmp, mxcsr_std, rscratch); } diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.hpp b/src/hotspot/cpu/x86/macroAssembler_x86.hpp index eed3446916f0e..b6f229661a8e9 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.hpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.hpp @@ -1135,7 +1135,7 @@ class MacroAssembler: public Assembler { void fmul_s(AddressLiteral src) { Assembler::fmul_s(as_Address(src)); } #endif // !_LP64 - void cmp_mxcsr(Address mxcsr_save, Register tmp, Register rscratch = noreg); + void cmp32_mxcsr_std(Address mxcsr_save, Register tmp, Register rscratch = noreg); void ldmxcsr(Address src) { Assembler::ldmxcsr(src); } void ldmxcsr(AddressLiteral src, Register rscratch = noreg); diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp index 7b872769cb5da..88490dabccbe8 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_32.cpp @@ -174,7 +174,7 @@ class StubGenerator: public StubCodeGenerator { // save and initialize %mxcsr if (sse_save) { Label skip_ldmx; - __ cmp_mxcsr(mxcsr_save, rax, noreg); + __ cmp32_mxcsr_std(mxcsr_save, rax); __ jcc(Assembler::equal, skip_ldmx); __ ldmxcsr(mxcsr_std); __ bind(skip_ldmx); @@ -457,14 +457,14 @@ class StubGenerator: public StubCodeGenerator { if (CheckJNICalls && UseSSE > 0 ) { Label ok_ret; - ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); __ push(rax); __ subptr(rsp, wordSize); // allocate a temp location - __ cmp_mxcsr(mxcsr_save, rax); + __ cmp32_mxcsr_std(mxcsr_save, rax); __ jcc(Assembler::equal, ok_ret); __ warn("MXCSR changed by native JNI code."); + ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); __ ldmxcsr(mxcsr_std); __ bind(ok_ret); diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp index 603997ac73d05..705511914b700 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp @@ -248,9 +248,9 @@ address StubGenerator::generate_call_stub(address& return_address) { const Address mxcsr_save(rbp, mxcsr_off * wordSize); { Label skip_ldmx; - ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); - __ cmp_mxcsr(mxcsr_save, rax, rscratch1); + __ cmp32_mxcsr_std(mxcsr_save, rax, rscratch1); __ jcc(Assembler::equal, skip_ldmx); + ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); __ ldmxcsr(mxcsr_std, rscratch1); __ bind(skip_ldmx); } @@ -571,7 +571,7 @@ address StubGenerator::generate_verify_mxcsr() { ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); __ push(rax); __ subptr(rsp, wordSize); // allocate a temp location - __ cmp_mxcsr(mxcsr_save, rax, rscratch1); + __ cmp32_mxcsr_std(mxcsr_save, rax, rscratch1); __ jcc(Assembler::equal, ok_ret); __ warn("MXCSR changed by native JNI code, use -XX:+RestoreMXCSROnJNICall"); diff --git a/src/hotspot/cpu/x86/upcallLinker_x86_64.cpp b/src/hotspot/cpu/x86/upcallLinker_x86_64.cpp index 2756c5e660b89..7769316714957 100644 --- a/src/hotspot/cpu/x86/upcallLinker_x86_64.cpp +++ b/src/hotspot/cpu/x86/upcallLinker_x86_64.cpp @@ -113,9 +113,9 @@ static void preserve_callee_saved_registers(MacroAssembler* _masm, const ABIDesc { const Address mxcsr_save(rsp, offset); Label skip_ldmx; - ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); - __ cmp_mxcsr(mxcsr_save, rax, rscratch1); + __ cmp32_mxcsr_std(mxcsr_save, rax, rscratch1); __ jcc(Assembler::equal, skip_ldmx); + ExternalAddress mxcsr_std(StubRoutines::x86::addr_mxcsr_std()); __ ldmxcsr(mxcsr_std, rscratch1); __ bind(skip_ldmx); } diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 635d09a23a28b..6487bb692cddc 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -2570,38 +2570,6 @@ LONG Handle_IDiv_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) { return EXCEPTION_CONTINUE_EXECUTION; } -#if defined(_M_AMD64) -//----------------------------------------------------------------------------- -static bool handle_FLT_exception(struct _EXCEPTION_POINTERS* exceptionInfo) { - // handle exception caused by native method modifying control word - DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode; - - switch (exception_code) { - case EXCEPTION_FLT_DENORMAL_OPERAND: - case EXCEPTION_FLT_DIVIDE_BY_ZERO: - case EXCEPTION_FLT_INEXACT_RESULT: - case EXCEPTION_FLT_INVALID_OPERATION: - case EXCEPTION_FLT_OVERFLOW: - case EXCEPTION_FLT_STACK_CHECK: - case EXCEPTION_FLT_UNDERFLOW: { - PCONTEXT ctx = exceptionInfo->ContextRecord; - // On Windows, the mxcsr control bits are non-volatile across calls - // See also CR 6192333 - // - jint MxCsr = INITIAL_MXCSR; // FIXME? this is `define INITIAL_MXCSR 0x1f80` in windows sdk - // we can't use StubRoutines::x86::addr_mxcsr_std() - // because in Win64 mxcsr is not saved there - if (MxCsr != ctx->MxCsr) { - ctx->MxCsr = MxCsr; - return true; - } - } - } - - return false; -} -#endif - static inline void report_error(Thread* t, DWORD exception_code, address addr, void* siginfo, void* context) { VMError::report_and_die(t, exception_code, addr, siginfo, context); @@ -2786,6 +2754,7 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { } #if defined(_M_AMD64) + extern bool handle_FLT_exception(struct _EXCEPTION_POINTERS* exceptionInfo); if ((in_java || in_native) && handle_FLT_exception(exceptionInfo)) { return EXCEPTION_CONTINUE_EXECUTION; } diff --git a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp index 9a23ac6733521..eb8fefb5ace0e 100644 --- a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp +++ b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp @@ -160,6 +160,43 @@ bool os::win32::register_code_area(char *low, char *high) { return true; } +#if defined(_M_AMD64) +//----------------------------------------------------------------------------- +bool handle_FLT_exception(struct _EXCEPTION_POINTERS* exceptionInfo) { + // handle exception caused by native method modifying control word + DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode; + + switch (exception_code) { + case EXCEPTION_FLT_DENORMAL_OPERAND: + case EXCEPTION_FLT_DIVIDE_BY_ZERO: + case EXCEPTION_FLT_INEXACT_RESULT: + case EXCEPTION_FLT_INVALID_OPERATION: + case EXCEPTION_FLT_OVERFLOW: + case EXCEPTION_FLT_STACK_CHECK: + case EXCEPTION_FLT_UNDERFLOW: { + PCONTEXT ctx = exceptionInfo->ContextRecord; + // On Windows, the mxcsr control bits are non-volatile across calls + // See also CR 6192333 + // + jint MxCsr = INITIAL_MXCSR; // set to 0x1f80` in winnt.h + if (EnableX86ECoreOpts) { + // On ECore, restore with signaling flags enabled + MxCsr |= 0x3F; + } + + // we can't use StubRoutines::x86::addr_mxcsr_std() + // because in Win64 mxcsr is not saved there + if (MxCsr != ctx->MxCsr) { + ctx->MxCsr = MxCsr; + return true; + } + } + } + + return false; +} +#endif + #ifdef HAVE_PLATFORM_PRINT_NATIVE_STACK /* * Windows/x64 does not use stack frames the way expected by Java: From 2b15f99a95022beb4f4ebbc19c6cd94bb68a011d Mon Sep 17 00:00:00 2001 From: Volodymyr Paprotski Date: Thu, 23 Jan 2025 13:19:06 -0500 Subject: [PATCH 4/8] whitespace --- src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp index eb8fefb5ace0e..82c541d95e444 100644 --- a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp +++ b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp @@ -183,7 +183,7 @@ bool handle_FLT_exception(struct _EXCEPTION_POINTERS* exceptionInfo) { // On ECore, restore with signaling flags enabled MxCsr |= 0x3F; } - + // we can't use StubRoutines::x86::addr_mxcsr_std() // because in Win64 mxcsr is not saved there if (MxCsr != ctx->MxCsr) { From b1a712bf67a6d4364b7a7420a378d4a614101f18 Mon Sep 17 00:00:00 2001 From: Volodymyr Paprotski Date: Mon, 3 Feb 2025 11:39:45 -0500 Subject: [PATCH 5/8] fix crash in fxrstor --- src/hotspot/cpu/x86/macroAssembler_x86.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp index 29c7cf28809b8..6b0aa77b2d0e0 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp @@ -779,9 +779,17 @@ void MacroAssembler::warn(const char* msg) { andq(rsp, -16); // align stack as required by push_CPU_state and call push_CPU_state(); // keeps alignment at 16 bytes +#ifdef _WIN64 + // Windows always allocates space for it's register args + subq(rsp, frame::arg_reg_save_area_bytes); +#endif lea(c_rarg0, ExternalAddress((address) msg)); call(RuntimeAddress(CAST_FROM_FN_PTR(address, warning))); +#ifdef _WIN64 + // restore stack pointer + addq(rsp, frame::arg_reg_save_area_bytes); +#endif pop_CPU_state(); mov(rsp, rbp); pop(rbp); @@ -2383,7 +2391,8 @@ void MacroAssembler::cmp32_mxcsr_std(Address mxcsr_save, Register tmp, Register stmxcsr(mxcsr_save); movl(tmp, mxcsr_save); // Mask out any pending exceptions (only check control and mask bits) - if (EnableX86ECoreOpts) { + if (!EnableX86ECoreOpts) { + // On Ecore, status bits are set by default (for performance) orl(tmp, 0x003f); // On Ecore, exception bits are set by default } else { andl(tmp, 0xFFC0); From 2e372f29134883bb781016004bd2c7d0774575de Mon Sep 17 00:00:00 2001 From: Volodymyr Paprotski <101140609+vpaprotsk@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:39:45 -0500 Subject: [PATCH 6/8] typo --- src/hotspot/cpu/x86/macroAssembler_x86.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp index 6b0aa77b2d0e0..a71aadcd1def6 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp @@ -2391,7 +2391,7 @@ void MacroAssembler::cmp32_mxcsr_std(Address mxcsr_save, Register tmp, Register stmxcsr(mxcsr_save); movl(tmp, mxcsr_save); // Mask out any pending exceptions (only check control and mask bits) - if (!EnableX86ECoreOpts) { + if (EnableX86ECoreOpts) { // On Ecore, status bits are set by default (for performance) orl(tmp, 0x003f); // On Ecore, exception bits are set by default } else { From b23764ab56c3729598b52bdb660e43e342f9286b Mon Sep 17 00:00:00 2001 From: Volodymyr Paprotski Date: Tue, 11 Feb 2025 21:48:51 +0000 Subject: [PATCH 7/8] comments from Sandhya --- src/hotspot/cpu/x86/macroAssembler_x86.cpp | 6 +++--- src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp index a71aadcd1def6..e03fae06af14e 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp @@ -2390,11 +2390,11 @@ void MacroAssembler::cmp32_mxcsr_std(Address mxcsr_save, Register tmp, Register stmxcsr(mxcsr_save); movl(tmp, mxcsr_save); - // Mask out any pending exceptions (only check control and mask bits) if (EnableX86ECoreOpts) { - // On Ecore, status bits are set by default (for performance) - orl(tmp, 0x003f); // On Ecore, exception bits are set by default + // The mxcsr_std has status bits set for performance on ECore + orl(tmp, 0x003f); } else { + // Mask out status bits (only check control and mask bits) andl(tmp, 0xFFC0); } cmp32(tmp, mxcsr_std, rscratch); diff --git a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp index 82c541d95e444..ff59c637c3053 100644 --- a/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp +++ b/src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp @@ -180,7 +180,7 @@ bool handle_FLT_exception(struct _EXCEPTION_POINTERS* exceptionInfo) { // jint MxCsr = INITIAL_MXCSR; // set to 0x1f80` in winnt.h if (EnableX86ECoreOpts) { - // On ECore, restore with signaling flags enabled + // On ECore restore with status bits enabled MxCsr |= 0x3F; } From cbd3812d18811e4b05e4d677cac1f8d4975a674a Mon Sep 17 00:00:00 2001 From: Volodymyr Paprotski <101140609+vpaprotsk@users.noreply.github.com> Date: Wed, 12 Feb 2025 10:42:49 -0500 Subject: [PATCH 8/8] Update src/hotspot/cpu/x86/macroAssembler_x86.cpp Co-authored-by: Julian Waters <32636402+TheShermanTanker@users.noreply.github.com> --- src/hotspot/cpu/x86/macroAssembler_x86.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp index e03fae06af14e..6a0c4871545f1 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp @@ -780,7 +780,7 @@ void MacroAssembler::warn(const char* msg) { push_CPU_state(); // keeps alignment at 16 bytes #ifdef _WIN64 - // Windows always allocates space for it's register args + // Windows always allocates space for its register args subq(rsp, frame::arg_reg_save_area_bytes); #endif lea(c_rarg0, ExternalAddress((address) msg));