Skip to content

Commit c96a9bc

Browse files
swesongaJava Platform Infrastructure
authored andcommitted
Revert exception handling changes (#45)
* Revert "Do not report errors unless FAILED returns true for the exception code (#16)" This reverts commit 5fa147b. * Revert "Perform error reporting for uncaught native exceptions (#11)" This reverts commit 07c3446. * Revert "Fix bug causing missing core dumps on Windows AArch64" This reverts commit 3ef2c63. * Revert "Windows AArch64 safefetch implementation should not use structured exception handling" This reverts commit 62651d6.
1 parent 0865ab6 commit c96a9bc

File tree

8 files changed

+35
-152
lines changed

8 files changed

+35
-152
lines changed

src/hotspot/os/windows/os_windows.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,10 +2729,6 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
27292729
// Verify that OS save/restore AVX registers.
27302730
return Handle_Exception(exceptionInfo, VM_Version::cpuinfo_cont_addr());
27312731
}
2732-
#elif defined(_M_ARM64)
2733-
if (handle_safefetch(exception_code, pc, (void*)exceptionInfo->ContextRecord)) {
2734-
return EXCEPTION_CONTINUE_EXECUTION;
2735-
}
27362732
#endif
27372733

27382734
if (t != nullptr && t->is_Java_thread()) {
@@ -2765,8 +2761,10 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
27652761
// Fatal red zone violation.
27662762
overflow_state->disable_stack_red_zone();
27672763
tty->print_raw_cr("An unrecoverable stack overflow has occurred.");
2764+
#if !defined(USE_VECTORED_EXCEPTION_HANDLING)
27682765
report_error(t, exception_code, pc, exception_record,
27692766
exceptionInfo->ContextRecord);
2767+
#endif
27702768
return EXCEPTION_CONTINUE_SEARCH;
27712769
}
27722770
} else if (exception_code == EXCEPTION_ACCESS_VIOLATION) {
@@ -2822,8 +2820,10 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
28222820
#endif
28232821

28242822
// Stack overflow or null pointer exception in native code.
2823+
#if !defined(USE_VECTORED_EXCEPTION_HANDLING)
28252824
report_error(t, exception_code, pc, exception_record,
28262825
exceptionInfo->ContextRecord);
2826+
#endif
28272827
return EXCEPTION_CONTINUE_SEARCH;
28282828
} // /EXCEPTION_ACCESS_VIOLATION
28292829
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -2897,21 +2897,41 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
28972897
}
28982898
}
28992899

2900-
bool should_report_error = (exception_code != EXCEPTION_BREAKPOINT);
2900+
#if !defined(USE_VECTORED_EXCEPTION_HANDLING)
2901+
if (exception_code != EXCEPTION_BREAKPOINT) {
2902+
report_error(t, exception_code, pc, exception_record,
2903+
exceptionInfo->ContextRecord);
2904+
}
2905+
#endif
2906+
return EXCEPTION_CONTINUE_SEARCH;
2907+
}
29012908

2909+
#if defined(USE_VECTORED_EXCEPTION_HANDLING)
2910+
LONG WINAPI topLevelVectoredExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
2911+
PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
29022912
#if defined(_M_ARM64)
2903-
should_report_error = should_report_error &&
2904-
FAILED(exception_code) &&
2905-
(exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION);
2913+
address pc = (address) exceptionInfo->ContextRecord->Pc;
2914+
#elif defined(_M_AMD64)
2915+
address pc = (address) exceptionInfo->ContextRecord->Rip;
2916+
#else
2917+
address pc = (address) exceptionInfo->ContextRecord->Eip;
29062918
#endif
29072919

2908-
if (should_report_error) {
2909-
report_error(t, exception_code, pc, exception_record,
2910-
exceptionInfo->ContextRecord);
2920+
// Fast path for code part of the code cache
2921+
if (CodeCache::low_bound() <= pc && pc < CodeCache::high_bound()) {
2922+
return topLevelExceptionFilter(exceptionInfo);
2923+
}
2924+
2925+
// If the exception occurred in the codeCache, pass control
2926+
// to our normal exception handler.
2927+
CodeBlob* cb = CodeCache::find_blob(pc);
2928+
if (cb != nullptr) {
2929+
return topLevelExceptionFilter(exceptionInfo);
29112930
}
29122931

29132932
return EXCEPTION_CONTINUE_SEARCH;
29142933
}
2934+
#endif
29152935

29162936
#if defined(USE_VECTORED_EXCEPTION_HANDLING)
29172937
LONG WINAPI topLevelUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
@@ -4638,7 +4658,7 @@ jint os::init_2(void) {
46384658
// Setup Windows Exceptions
46394659

46404660
#if defined(USE_VECTORED_EXCEPTION_HANDLING)
4641-
topLevelVectoredExceptionHandler = AddVectoredExceptionHandler(1, topLevelExceptionFilter);
4661+
topLevelVectoredExceptionHandler = AddVectoredExceptionHandler(1, topLevelVectoredExceptionFilter);
46424662
previousUnhandledExceptionFilter = SetUnhandledExceptionFilter(topLevelUnhandledExceptionFilter);
46434663
#endif
46444664

src/hotspot/os/windows/os_windows.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ class os::win32 {
172172
// signal support
173173
static void* install_signal_handler(int sig, signal_handler_t handler);
174174
static void* user_handler();
175-
176-
static void context_set_pc(CONTEXT* uc, address pc);
177175
};
178176

179177
#endif // OS_WINDOWS_OS_WINDOWS_HPP

src/hotspot/os/windows/safefetch_static_windows.cpp

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/hotspot/os_cpu/windows_aarch64/os_windows_aarch64.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ frame os::fetch_frame_from_context(const void* ucVoid) {
9999
return frame(sp, fp, epc);
100100
}
101101

102-
void os::win32::context_set_pc(CONTEXT* uc, address pc) {
103-
uc->Pc = (intptr_t)pc;
104-
}
105-
106102
bool os::win32::get_frame_at_stack_banging_point(JavaThread* thread,
107103
struct _EXCEPTION_POINTERS* exceptionInfo, address pc, frame* fr) {
108104
PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;

src/hotspot/os_cpu/windows_aarch64/safefetch_windows_aarch64.S

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/hotspot/share/runtime/safefetch.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// Safefetch allows to load a value from a location that's not known
3232
// to be valid. If the load causes a fault, the error value is returned.
3333

34-
#if defined(_WIN32) && !defined(_M_ARM64)
34+
#ifdef _WIN32
3535
// Windows uses Structured Exception Handling
3636
#include "safefetch_windows.hpp"
3737
#elif defined(ZERO) || defined (_AIX)

test/hotspot/jtreg/runtime/ErrorHandling/UncaughtNativeExceptionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testNativeExceptionReporting() throws Exception {
6464
assertTrue(Files.exists(hsErrPath));
6565

6666
Pattern[] positivePatterns = {
67-
Pattern.compile(".*Internal Error \\(0xdeadbeef\\).*")
67+
Pattern.compile(".*Internal Error \\(0x2a\\).*")
6868
};
6969
HsErrFileUtils.checkHsErrFileContent(hsErrFile, positivePatterns, null, true /* check end marker */, false /* verbose */);
7070
}

test/hotspot/jtreg/runtime/ErrorHandling/libNativeException.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
#include <Windows.h>
2727

28-
// Use an exception code that causes the FAILED() macro to return true.
29-
const DWORD EX_CODE = 0xdeadbeef;
28+
const DWORD EX_CODE = 42;
3029

3130
JNIEXPORT void JNICALL Java_UncaughtNativeExceptionTest_00024Crasher_throwException(JNIEnv* env, jclass cls) {
3231
RaiseException(EX_CODE, EXCEPTION_NONCONTINUABLE, 0, NULL);

0 commit comments

Comments
 (0)