Revert^2 "Suspend the runtime when switching interpreters."
This reverts commit 9fd68f6795eab7085986f80b1c4d00dc45a68485.
Test: art/test.py -b --host --64
Test: art/tools/run-libcore-tests.sh '--mode=host' '--variant=X64'
Test: art/tools/run-libjdwp-tests.sh '--mode=host' '--variant=X64'
Change-Id: I9d2faeb8b88ce7cf42915890c6089c725907e6dd
diff --git a/runtime/runtime-inl.h b/runtime/runtime-inl.h
index 2ffaf98..c7731f4 100644
--- a/runtime/runtime-inl.h
+++ b/runtime/runtime-inl.h
@@ -28,6 +28,7 @@
#include "gc_root-inl.h"
#include "interpreter/mterp/mterp.h"
#include "obj_ptr-inl.h"
+#include "scoped_thread_state_change-inl.h"
#include "thread_list.h"
namespace art {
@@ -90,12 +91,23 @@
}
template<typename Action>
-void Runtime::DoAndMaybeSwitchInterpreter(Action lamda) {
- MutexLock tll_mu(Thread::Current(), *Locks::thread_list_lock_);
- lamda();
- Runtime::Current()->GetThreadList()->ForEach([](Thread* thread, void*) {
- thread->tls32_.use_mterp.store(interpreter::CanUseMterp());
- }, nullptr);
+void Runtime::DoAndMaybeSwitchInterpreter(Action lambda) {
+ Thread* self = Thread::Current();
+ if (Runtime::Current()->IsShuttingDown(self) || Locks::mutator_lock_->IsExclusiveHeld(self)) {
+ MutexLock tll_mu(self, *Locks::thread_list_lock_);
+ lambda();
+ Runtime::Current()->GetThreadList()->ForEach([](Thread* thread, void*) {
+ thread->tls32_.use_mterp.store(interpreter::CanUseMterp());
+ }, nullptr);
+ } else {
+ ScopedThreadStateChange tsc(self, kSuspended);
+ ScopedSuspendAll ssa(__FUNCTION__);
+ MutexLock tll_mu(self, *Locks::thread_list_lock_);
+ lambda();
+ Runtime::Current()->GetThreadList()->ForEach([](Thread* thread, void*) {
+ thread->tls32_.use_mterp.store(interpreter::CanUseMterp());
+ }, nullptr);
+ }
}
} // namespace art