From: Mathieu Chartier Date: Fri, 25 Sep 2015 21:39:40 +0000 (-0700) Subject: Fix bug in WaitForCompilationToFinish X-Git-Tag: android-x86-7.1-r1~889^2~296^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=36c0136e848e14993ad8e0f85c94caae14e2246a;p=android-x86%2Fart.git Fix bug in WaitForCompilationToFinish We now pass the barrier inside of Finalize, previously we did it in Run. This was buggy since Finalize is called after Run and there was a race condition where WaitForCompilationToFinish would delete the task before we called Finalize. Change-Id: I3f624fa9cdfcf2b266775c6927c336fb987dd58c --- diff --git a/runtime/jit/jit_instrumentation.cc b/runtime/jit/jit_instrumentation.cc index af6aba3df..4f4a97f45 100644 --- a/runtime/jit/jit_instrumentation.cc +++ b/runtime/jit/jit_instrumentation.cc @@ -24,7 +24,7 @@ namespace art { namespace jit { -class JitCompileTask : public Task { +class JitCompileTask FINAL : public Task { public: explicit JitCompileTask(ArtMethod* method) : method_(method) { ScopedObjectAccess soa(Thread::Current()); @@ -38,7 +38,7 @@ class JitCompileTask : public Task { soa.Vm()->DeleteGlobalRef(soa.Self(), klass_); } - virtual void Run(Thread* self) OVERRIDE { + void Run(Thread* self) OVERRIDE { ScopedObjectAccess soa(self); VLOG(jit) << "JitCompileTask compiling method " << PrettyMethod(method_); if (!Runtime::Current()->GetJit()->CompileMethod(method_, self)) { @@ -46,7 +46,7 @@ class JitCompileTask : public Task { } } - virtual void Finalize() OVERRIDE { + void Finalize() OVERRIDE { delete this; } @@ -115,7 +115,7 @@ void JitInstrumentationListener::InvokeVirtualOrInterface(Thread* thread, } } -class WaitForCompilationToFinishTask : public Task { +class WaitForCompilationToFinishTask FINAL : public Task { public: WaitForCompilationToFinishTask() : barrier_(0) {} @@ -123,8 +123,11 @@ class WaitForCompilationToFinishTask : public Task { barrier_.Increment(self, 1); } - virtual void Run(Thread* self) OVERRIDE { - barrier_.Pass(self); + void Run(Thread* self ATTRIBUTE_UNUSED) OVERRIDE {} + + void Finalize() OVERRIDE { + // Do this in Finalize since Finalize is called after Run by the thread pool. + barrier_.Pass(Thread::Current()); } private: