8266742: Check W^X state on possible safepoint

Reviewed-by: dholmes, gziemski
This commit is contained in:
Anton Kozlov 2021-05-17 19:15:18 +00:00
parent 79b39445f6
commit 3b11d811a2
3 changed files with 25 additions and 7 deletions

View File

@ -28,13 +28,17 @@
//
// Declare Bsd specific flags. They are not available on other platforms.
//
#define RUNTIME_OS_FLAGS(develop, \
develop_pd, \
product, \
product_pd, \
notproduct, \
range, \
constraint)
#define RUNTIME_OS_FLAGS(develop, \
develop_pd, \
product, \
product_pd, \
notproduct, \
range, \
constraint) \
\
AARCH64_ONLY(develop(bool, AssertWXAtThreadSync, false, \
"Conservatively check W^X thread state at possible safepoint" \
"or handshake"))
// end of RUNTIME_OS_FLAGS

View File

@ -65,6 +65,16 @@ bool SafepointMechanism::should_process(JavaThread* thread) {
}
void SafepointMechanism::process_if_requested(JavaThread* thread) {
// Macos/aarch64 should be in the right state for safepoint (e.g.
// deoptimization needs WXWrite). Crashes caused by the wrong state rarely
// happens in practice, making such issues hard to find and reproduce.
#if defined(ASSERT) && defined(__APPLE__) && defined(AARCH64)
if (AssertWXAtThreadSync) {
thread->assert_wx_state(WXWrite);
}
#endif
if (local_poll_armed(thread)) {
process_if_requested_slow(thread);
}

View File

@ -649,6 +649,10 @@ protected:
public:
void init_wx();
WXMode enable_wx(WXMode new_state);
void assert_wx_state(WXMode expected) {
assert(_wx_state == expected, "wrong state");
}
#endif // __APPLE__ && AARCH64
};