# HG changeset patch # User stuefe # Date 1562663772 -7200 # Tue Jul 09 11:16:12 2019 +0200 # Node ID 8bdfaf4259261ae0d2ecde6b69f023093acd8e11 # Parent eb1fbe4d61b29346fdbff750efd14e156f6cfe03 [mq]: 8227275-native-oom-hanging-assertions diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/os/posix/vmError_posix.cpp --- a/src/hotspot/os/posix/vmError_posix.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/os/posix/vmError_posix.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -132,8 +132,9 @@ // Needed because asserts may happen in error handling too. #ifdef CAN_SHOW_REGISTERS_ON_ASSERT if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { - handle_assert_poison_fault(ucVoid, info->si_addr); - return; + if (handle_assert_poison_fault(ucVoid, info->si_addr)) { + return; + } } #endif // CAN_SHOW_REGISTERS_ON_ASSERT diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp --- a/src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -306,8 +306,9 @@ #ifdef CAN_SHOW_REGISTERS_ON_ASSERT if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { - handle_assert_poison_fault(ucVoid, info->si_addr); - return 1; + if (handle_assert_poison_fault(ucVoid, info->si_addr)) { + return 1; + } } #endif diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp --- a/src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -301,8 +301,9 @@ #ifdef CAN_SHOW_REGISTERS_ON_ASSERT if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { - handle_assert_poison_fault(ucVoid, info->si_addr); - return 1; + if (handle_assert_poison_fault(ucVoid, info->si_addr)) { + return 1; + } } #endif diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp --- a/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -271,8 +271,9 @@ #ifdef CAN_SHOW_REGISTERS_ON_ASSERT if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { - handle_assert_poison_fault(ucVoid, info->si_addr); - return 1; + if (handle_assert_poison_fault(ucVoid, info->si_addr)) { + return 1; + } } #endif diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp --- a/src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -270,8 +270,9 @@ #ifdef CAN_SHOW_REGISTERS_ON_ASSERT if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { - handle_assert_poison_fault(ucVoid, info->si_addr); - return 1; + if (handle_assert_poison_fault(ucVoid, info->si_addr)) { + return 1; + } } #endif diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp --- a/src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -510,8 +510,9 @@ #ifdef CAN_SHOW_REGISTERS_ON_ASSERT if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { - handle_assert_poison_fault(ucVoid, info->si_addr); - return 1; + if (handle_assert_poison_fault(ucVoid, info->si_addr)) { + return 1; + } } #endif diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp --- a/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -303,8 +303,9 @@ #ifdef CAN_SHOW_REGISTERS_ON_ASSERT if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { - handle_assert_poison_fault(ucVoid, info->si_addr); - return 1; + if (handle_assert_poison_fault(ucVoid, info->si_addr)) { + return 1; + } } #endif diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/share/utilities/debug.cpp --- a/src/hotspot/share/utilities/debug.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/share/utilities/debug.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -734,6 +734,10 @@ } } +void disarm_assert_poison() { + g_assert_poison = &g_dummy; +} + static void store_context(const void* context) { memcpy(&g_stored_assertion_context, context, sizeof(ucontext_t)); #if defined(__linux) && defined(PPC64) @@ -746,7 +750,14 @@ bool handle_assert_poison_fault(const void* ucVoid, const void* faulting_address) { if (faulting_address == g_assert_poison) { // Disarm poison page. - os::protect_memory((char*)g_assert_poison, os::vm_page_size(), os::MEM_PROT_RWX); + if (os::protect_memory((char*)g_assert_poison, os::vm_page_size(), os::MEM_PROT_RWX) == false) { +#ifdef ASSERT + fprintf(stderr, "Assertion poison page cannot be unprotected - mprotect failed with %d (%s)", + errno, os::strerror(errno)); + fflush(stderr); +#endif + return false; // unprotecting memory may fail in OOM situations, as surprising as this sounds. + } // Store Context away. if (ucVoid) { const intx my_tid = os::current_thread_id(); diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/share/utilities/debug.hpp --- a/src/hotspot/share/utilities/debug.hpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/share/utilities/debug.hpp Tue Jul 09 11:16:12 2019 +0200 @@ -37,6 +37,7 @@ extern char* g_assert_poison; #define TOUCH_ASSERT_POISON (*g_assert_poison) = 'X'; void initialize_assert_poison(); +void disarm_assert_poison(); bool handle_assert_poison_fault(const void* ucVoid, const void* faulting_address); #else #define TOUCH_ASSERT_POISON diff -r eb1fbe4d61b2 -r 8bdfaf425926 src/hotspot/share/utilities/vmError.cpp --- a/src/hotspot/share/utilities/vmError.cpp Mon Jul 08 12:16:13 2019 -0400 +++ b/src/hotspot/share/utilities/vmError.cpp Tue Jul 09 11:16:12 2019 +0200 @@ -1327,6 +1327,10 @@ // File descriptor to the error log file. static int fd_log = -1; + // Disarm assertion poison page, since from this point on we do not need this mechanism anymore and it may + // cause problems in error handling during native OOM, see JDK-8227275. + disarm_assert_poison(); + // Use local fdStream objects only. Do not use global instances whose initialization // relies on dynamic initialization (see JDK-8214975). Do not rely on these instances // to carry over into recursions or invocations from other threads.