Skip to content

Commit 3b11d81

Browse files
committed
8266742: Check W^X state on possible safepoint
Reviewed-by: dholmes, gziemski
1 parent 79b3944 commit 3b11d81

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/hotspot/os/bsd/globals_bsd.hpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828
//
2929
// Declare Bsd specific flags. They are not available on other platforms.
3030
//
31-
#define RUNTIME_OS_FLAGS(develop, \
32-
develop_pd, \
33-
product, \
34-
product_pd, \
35-
notproduct, \
36-
range, \
37-
constraint)
31+
#define RUNTIME_OS_FLAGS(develop, \
32+
develop_pd, \
33+
product, \
34+
product_pd, \
35+
notproduct, \
36+
range, \
37+
constraint) \
38+
\
39+
AARCH64_ONLY(develop(bool, AssertWXAtThreadSync, false, \
40+
"Conservatively check W^X thread state at possible safepoint" \
41+
"or handshake"))
3842

3943
// end of RUNTIME_OS_FLAGS
4044

src/hotspot/share/runtime/safepointMechanism.inline.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ bool SafepointMechanism::should_process(JavaThread* thread) {
6565
}
6666

6767
void SafepointMechanism::process_if_requested(JavaThread* thread) {
68+
69+
// Macos/aarch64 should be in the right state for safepoint (e.g.
70+
// deoptimization needs WXWrite). Crashes caused by the wrong state rarely
71+
// happens in practice, making such issues hard to find and reproduce.
72+
#if defined(ASSERT) && defined(__APPLE__) && defined(AARCH64)
73+
if (AssertWXAtThreadSync) {
74+
thread->assert_wx_state(WXWrite);
75+
}
76+
#endif
77+
6878
if (local_poll_armed(thread)) {
6979
process_if_requested_slow(thread);
7080
}

src/hotspot/share/runtime/thread.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,10 @@ class Thread: public ThreadShadow {
649649
public:
650650
void init_wx();
651651
WXMode enable_wx(WXMode new_state);
652+
653+
void assert_wx_state(WXMode expected) {
654+
assert(_wx_state == expected, "wrong state");
655+
}
652656
#endif // __APPLE__ && AARCH64
653657
};
654658

0 commit comments

Comments
 (0)