diff options
| author | 2016-11-16 14:58:24 -0800 | |
|---|---|---|
| committer | 2016-11-17 08:33:16 -0800 | |
| commit | f149b3fc6fd315d34244bce709898fdbbddc246f (patch) | |
| tree | 34cc0b2f23865db2c065a9e19cf624290e6f2250 | |
| parent | 6f3a70f316f2f3dcde5b3bde5fb258c556c46da6 (diff) | |
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
| -rw-r--r-- | runtime/jit/jit.cc | 19 | ||||
| -rw-r--r-- | runtime/jit/jit.h | 14 |
2 files changed, 33 insertions, 0 deletions
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 23a5ddd071..803e9d5e61 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 a7824378c2..a230c78033 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 |