From f149b3fc6fd315d34244bce709898fdbbddc246f Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Wed, 16 Nov 2016 14:58:24 -0800 Subject: [PATCH] ART: Add ScopedJitSuspend Add a helper to suspend the JIT in a scope. This will wait for the JIT to quiesce, finishing already running compile jobs. Note that the queue will not be drained, jobs not picked up by the pool, yet, will remain in the queue. Bug: 31385354 Test: m test-art-host Change-Id: I576e7926423f19a8f382be1263838cd924955f1c --- runtime/jit/jit.cc | 19 +++++++++++++++++++ runtime/jit/jit.h | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 23a5ddd07..803e9d5e6 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -701,5 +701,24 @@ void Jit::WaitForCompilationToFinish(Thread* self) { } } +ScopedJitSuspend::ScopedJitSuspend() { + jit::Jit* jit = Runtime::Current()->GetJit(); + was_on_ = (jit != nullptr) && (jit->GetThreadPool() != nullptr); + if (was_on_) { + Thread* self = Thread::Current(); + jit->WaitForCompilationToFinish(self); + jit->GetThreadPool()->StopWorkers(self); + jit->WaitForCompilationToFinish(self); + } +} + +ScopedJitSuspend::~ScopedJitSuspend() { + if (was_on_) { + DCHECK(Runtime::Current()->GetJit() != nullptr); + DCHECK(Runtime::Current()->GetJit()->GetThreadPool() != nullptr); + Runtime::Current()->GetJit()->GetThreadPool()->StartWorkers(Thread::Current()); + } +} + } // namespace jit } // namespace art diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h index a7824378c..a230c7803 100644 --- a/runtime/jit/jit.h +++ b/runtime/jit/jit.h @@ -175,6 +175,10 @@ class Jit { static bool LoadCompilerLibrary(std::string* error_msg); + ThreadPool* GetThreadPool() const { + return thread_pool_.get(); + } + private: Jit(); @@ -278,6 +282,16 @@ class JitOptions { DISALLOW_COPY_AND_ASSIGN(JitOptions); }; +// Helper class to stop the JIT for a given scope. This will wait for the JIT to quiesce. +class ScopedJitSuspend { + public: + ScopedJitSuspend(); + ~ScopedJitSuspend(); + + private: + bool was_on_; +}; + } // namespace jit } // namespace art -- 2.11.0