diff options
author | 2018-10-08 10:43:06 -0700 | |
---|---|---|
committer | 2018-10-08 10:51:12 -0700 | |
commit | 59b950f53152c169464ba8c63d44102eeba1e594 (patch) | |
tree | 4d1124b540984f970acaf494f4fd85cc347fbd57 | |
parent | d8ee1f5a8b36280e56e0c723774d0a5575e3cca0 (diff) |
Prevent jit-compilation from loading classes in jit-on-first-use
Unlike with normal jit, jit-on-first-use (-Xjitthreshold:0) causes the
jit-compilation to be done synchronously on the current thread. Since
this thread is not a runtime thread it will allow the jit to load
classes even on a debuggable runtime. This can cause some tests to
fail. To fix this (and prevent any future issues) we mark threads
running in jit-code for jit-on-first-use as runtime-threads
temporarily.
Test: ./test/run-test --host --jit --runtime-option -Xjitthreshold:0 1953
Change-Id: I06410bc3cbdb28ba51e907b71556481ba405c1d0
-rw-r--r-- | runtime/jit/jit.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index d8316288f3..c1f69b8712 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -718,6 +718,22 @@ void Jit::AddSamples(Thread* self, ArtMethod* method, uint16_t count, bool with_ method->SetCounter(new_count); } +class ScopedSetRuntimeThread { + public: + explicit ScopedSetRuntimeThread(Thread* self) + : self_(self), was_runtime_thread_(self_->IsRuntimeThread()) { + self_->SetIsRuntimeThread(true); + } + + ~ScopedSetRuntimeThread() { + self_->SetIsRuntimeThread(was_runtime_thread_); + } + + private: + Thread* self_; + bool was_runtime_thread_; +}; + void Jit::MethodEntered(Thread* thread, ArtMethod* method) { Runtime* runtime = Runtime::Current(); if (UNLIKELY(runtime->UseJitCompilation() && runtime->GetJit()->JitAtFirstUse())) { @@ -728,6 +744,8 @@ void Jit::MethodEntered(Thread* thread, ArtMethod* method) { ProfilingInfo::Create(thread, np_method, /* retry_allocation */ true); } JitCompileTask compile_task(method, JitCompileTask::kCompile); + // Fake being in a runtime thread so that class-load behavior will be the same as normal jit. + ScopedSetRuntimeThread ssrt(thread); compile_task.Run(thread); } return; |