diff options
| -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 |