From ced69858bdbbc7297fd5702a64e70fa39e505790 Mon Sep 17 00:00:00 2001 From: TheRealMDoerr Date: Sat, 5 Jul 2025 00:46:04 +0200 Subject: [PATCH 1/2] 8361433: [Big Endian] assert(verify_guards()) failed: Expected valid memory guards after 8357601 --- src/hotspot/share/memory/guardedMemory.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/memory/guardedMemory.hpp b/src/hotspot/share/memory/guardedMemory.hpp index b40b1e8950d88..00cfaf7def053 100644 --- a/src/hotspot/share/memory/guardedMemory.hpp +++ b/src/hotspot/share/memory/guardedMemory.hpp @@ -119,7 +119,7 @@ class GuardedMemory : StackObj { // Wrapper on stack // We may not be able to dereference directly so use // SafeFetch. It doesn't matter if the value read happens // to be 0xFF as that is not what we expect anyway. - u_char val = (u_char) SafeFetch32((int*)c, 0xFF); + u_char val = (u_char) (SafeFetch32((int*)c, 0xFF) BIG_ENDIAN_ONLY(>> 24)); if (val != badResourceValue) { return false; } From 2f467b3acd25d7f95fdfb57e2a65cd068a12ab75 Mon Sep 17 00:00:00 2001 From: TheRealMDoerr Date: Sat, 5 Jul 2025 19:27:30 +0200 Subject: [PATCH 2/2] Use os::is_readable_range(). --- src/hotspot/share/memory/guardedMemory.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hotspot/share/memory/guardedMemory.hpp b/src/hotspot/share/memory/guardedMemory.hpp index 00cfaf7def053..baced96a3f5a4 100644 --- a/src/hotspot/share/memory/guardedMemory.hpp +++ b/src/hotspot/share/memory/guardedMemory.hpp @@ -26,6 +26,7 @@ #define SHARE_MEMORY_GUARDEDMEMORY_HPP #include "memory/allocation.hpp" +#include "runtime/os.hpp" #include "runtime/safefetch.hpp" #include "utilities/globalDefinitions.hpp" @@ -113,14 +114,14 @@ class GuardedMemory : StackObj { // Wrapper on stack } bool verify() const { + // We may not be able to dereference directly. + if (!os::is_readable_range((const void*) _guard, (const void*) (_guard + GUARD_SIZE))) { + return false; + } u_char* c = (u_char*) _guard; u_char* end = c + GUARD_SIZE; while (c < end) { - // We may not be able to dereference directly so use - // SafeFetch. It doesn't matter if the value read happens - // to be 0xFF as that is not what we expect anyway. - u_char val = (u_char) (SafeFetch32((int*)c, 0xFF) BIG_ENDIAN_ONLY(>> 24)); - if (val != badResourceValue) { + if (*c != badResourceValue) { return false; } c++;