8246381: VM crashes with "Current BasicObjectLock* below than low_mark"

Save and restores "donotunlock" flag in check_and_handle_async_exceptions

Reviewed-by: coleenp, dholmes
This commit is contained in:
Jamsheed Mohammed C M 2020-07-16 08:28:55 -07:00
parent 4320afbd58
commit d63aebe6cb
3 changed files with 22 additions and 17 deletions
src/hotspot/share

@ -74,21 +74,6 @@
#include "opto/runtime.hpp"
#endif
class UnlockFlagSaver {
private:
JavaThread* _thread;
bool _do_not_unlock;
public:
UnlockFlagSaver(JavaThread* t) {
_thread = t;
_do_not_unlock = t->do_not_unlock_if_synchronized();
t->set_do_not_unlock_if_synchronized(false);
}
~UnlockFlagSaver() {
_thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
}
};
// Helper class to access current interpreter state
class LastFrameAccessor : public StackObj {
frame _last_frame;
@ -1064,6 +1049,9 @@ nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, addr
JRT_ENTRY(nmethod*,
InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
if (HAS_PENDING_EXCEPTION) {
return NULL;
}
// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
// flag, in case this method triggers classloading which will call into Java.
UnlockFlagSaver fs(thread);
@ -1074,7 +1062,6 @@ JRT_ENTRY(nmethod*,
const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
const int bci = branch_bcp != NULL ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;
assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");
nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");
@ -1117,6 +1104,9 @@ JRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
JRT_END
JRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
if (HAS_PENDING_EXCEPTION) {
return;
}
// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
// flag, in case this method triggers classloading which will call into Java.
UnlockFlagSaver fs(thread);

@ -2281,7 +2281,8 @@ void JavaThread::remove_monitor_chunk(MonitorChunk* chunk) {
// _thread_in_native_trans state (such as from
// check_special_condition_for_native_trans()).
void JavaThread::check_and_handle_async_exceptions(bool check_unsafe_error) {
// May be we are at method entry and requires to save do not unlock flag.
UnlockFlagSaver fs(this);
if (has_last_Java_frame() && has_async_condition()) {
// If we are at a polling page safepoint (not a poll return)
// then we must defer async exception because live registers

@ -2345,5 +2345,19 @@ class SignalHandlerMark: public StackObj {
}
};
class UnlockFlagSaver {
private:
JavaThread* _thread;
bool _do_not_unlock;
public:
UnlockFlagSaver(JavaThread* t) {
_thread = t;
_do_not_unlock = t->do_not_unlock_if_synchronized();
t->set_do_not_unlock_if_synchronized(false);
}
~UnlockFlagSaver() {
_thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
}
};
#endif // SHARE_RUNTIME_THREAD_HPP