Revert^4 "Remove Global deopt requirement for several jvmti events"
It was possible for the top frame of a thread to enter the
artQuickToInterpreterBridge during runtime shutdown. This could be
caused by the libjdwp agent. If this happens the caller of the frame
will be 'null', which could cause a segv if not detected correctly.
This reverts commit 939798e6a565a92e597136c589428e89c28bffd5.
Reason for revert: Fixed issue that could cause crash during process
shutdown.
Test: ./art/tools/run-libjdwp-tests.sh --mode=host
Test: ./test.py --host
Change-Id: I2aad1705c761edb4ed788cec4fc8a3068d67aee5
diff --git a/openjdkjvmti/deopt_manager.cc b/openjdkjvmti/deopt_manager.cc
index d456d83..ee77b7b 100644
--- a/openjdkjvmti/deopt_manager.cc
+++ b/openjdkjvmti/deopt_manager.cc
@@ -49,6 +49,7 @@
#include "nativehelper/scoped_local_ref.h"
#include "runtime_callbacks.h"
#include "scoped_thread_state_change-inl.h"
+#include "scoped_thread_state_change.h"
#include "thread-current-inl.h"
#include "thread_list.h"
#include "ti_phase.h"
@@ -356,6 +357,47 @@
kDeoptManagerInstrumentationKey);
}
+jvmtiError DeoptManager::AddDeoptimizeThreadMethods(art::ScopedObjectAccessUnchecked& soa, jthread jtarget) {
+ art::Locks::thread_list_lock_->ExclusiveLock(soa.Self());
+ art::Thread* target = nullptr;
+ jvmtiError err = OK;
+ if (!ThreadUtil::GetNativeThread(jtarget, soa, &target, &err)) {
+ art::Locks::thread_list_lock_->ExclusiveUnlock(soa.Self());
+ return err;
+ }
+ // We don't need additional locking here because we hold the Thread_list_lock_.
+ target->SetForceInterpreterCount(target->ForceInterpreterCount() + 1);
+ if (target->ForceInterpreterCount() == 1) {
+ struct DeoptClosure : public art::Closure {
+ public:
+ explicit DeoptClosure(DeoptManager* man) : man_(man) {}
+ void Run(art::Thread* self) override REQUIRES_SHARED(art::Locks::mutator_lock_) {
+ man_->DeoptimizeThread(self);
+ }
+
+ private:
+ DeoptManager* man_;
+ };
+ DeoptClosure c(this);
+ target->RequestSynchronousCheckpoint(&c);
+ } else {
+ art::Locks::thread_list_lock_->ExclusiveUnlock(soa.Self());
+ }
+ return OK;
+}
+
+jvmtiError DeoptManager::RemoveDeoptimizeThreadMethods(art::ScopedObjectAccessUnchecked& soa, jthread jtarget) {
+ art::MutexLock mu(soa.Self(), *art::Locks::thread_list_lock_);
+ art::Thread* target = nullptr;
+ jvmtiError err = OK;
+ if (!ThreadUtil::GetNativeThread(jtarget, soa, &target, &err)) {
+ return err;
+ }
+ // We don't need additional locking here because we hold the Thread_list_lock_.
+ DCHECK_GT(target->ForceInterpreterCount(), 0u);
+ target->DecrementForceInterpreterCount();
+ return OK;
+}
void DeoptManager::RemoveDeoptimizationRequester() {
art::Thread* self = art::Thread::Current();