8304725: AsyncGetCallTrace can cause SIGBUS on M1

Reviewed-by: dholmes, stuefe, mbaesken
This commit is contained in:
Johannes Bechberger 2023-04-12 06:49:10 +00:00 committed by Matthias Baesken
parent b9bdbe9ab3
commit d8af7a6014
3 changed files with 33 additions and 1 deletions
src/hotspot/share

@ -2136,7 +2136,11 @@ PcDesc* PcDescContainer::find_pc_desc_internal(address pc, bool approximate, con
if (match_desc(upper, pc_offset, approximate)) {
assert(upper == linear_search(search, pc_offset, approximate), "search ok");
_pc_desc_cache.add_pc_desc(upper);
if (!Thread::current_in_asgct()) {
// we don't want to modify the cache if we're in ASGCT
// which is typically called in a signal handler
_pc_desc_cache.add_pc_desc(upper);
}
return upper;
} else {
assert(nullptr == linear_search(search, pc_offset, approximate), "search ok");

@ -606,6 +606,9 @@ void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {
return;
}
// signify to other code in the VM that we're in ASGCT
ThreadInAsgct tia(thread);
switch (thread->thread_state()) {
case _thread_new:
case _thread_uninitialized:

@ -631,6 +631,31 @@ protected:
assert(_wx_state == expected, "wrong state");
}
#endif // __APPLE__ && AARCH64
private:
bool _in_asgct = false;
public:
bool in_asgct() const { return _in_asgct; }
void set_in_asgct(bool value) { _in_asgct = value; }
static bool current_in_asgct() {
Thread *cur = Thread::current_or_null_safe();
return cur != nullptr && cur->in_asgct();
}
};
class ThreadInAsgct {
private:
Thread* _thread;
public:
ThreadInAsgct(Thread* thread) : _thread(thread) {
assert(thread != nullptr, "invariant");
assert(!thread->in_asgct(), "invariant");
thread->set_in_asgct(true);
}
~ThreadInAsgct() {
assert(_thread->in_asgct(), "invariant");
_thread->set_in_asgct(false);
}
};
// Inline implementation of Thread::current()