diff options
author | 2016-11-18 16:03:10 +0000 | |
---|---|---|
committer | 2016-11-22 13:08:29 +0000 | |
commit | 340dafabc8e88378e395cda9027cf17726910e91 (patch) | |
tree | f742cfc9b9eb3fdf0245a66491d39fb841da7c01 /compiler/driver/compiler_driver.cc | |
parent | 71d15102b52af67e8fe1193192aa2b4cd1956ae0 (diff) |
Use a per-thread VerifierDeps.
Avoid lock contention on a singleton VerifierDeps by allocating
temporary per-thread VerifierDeps that get merged after verification.
This saves around ~35% compile-times on interpret-only.
Only the creation of extra strings is guarded by a lock, for simplicity.
Test: test-art-host, test-art-target
bug: 32641252
bug: 30937355
Change-Id: I11a2367da882b58e39afa7b42cba2e74a209b75d
Diffstat (limited to 'compiler/driver/compiler_driver.cc')
-rw-r--r-- | compiler/driver/compiler_driver.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index c62e2142b7..e155e106f8 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -1980,8 +1980,16 @@ void CompilerDriver::Verify(jobject jclass_loader, // non boot image compilation. The verifier will need it to record the new dependencies. // Then dex2oat can update the vdex file with these new dependencies. if (!GetCompilerOptions().IsBootImage()) { + // Create the main VerifierDeps, and set it to this thread. Runtime::Current()->GetCompilerCallbacks()->SetVerifierDeps( new verifier::VerifierDeps(dex_files)); + Thread::Current()->SetVerifierDeps( + Runtime::Current()->GetCompilerCallbacks()->GetVerifierDeps()); + // Create per-thread VerifierDeps to avoid contention on the main one. + // We will merge them after verification. + for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) { + worker->GetThread()->SetVerifierDeps(new verifier::VerifierDeps(dex_files)); + } } // Note: verification should not be pulling in classes anymore when compiling the boot image, // as all should have been resolved before. As such, doing this in parallel should still @@ -1995,6 +2003,19 @@ void CompilerDriver::Verify(jobject jclass_loader, parallel_thread_count_, timings); } + + if (!GetCompilerOptions().IsBootImage()) { + verifier::VerifierDeps* main_deps = + Runtime::Current()->GetCompilerCallbacks()->GetVerifierDeps(); + // Merge all VerifierDeps into the main one. + for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) { + verifier::VerifierDeps* thread_deps = worker->GetThread()->GetVerifierDeps(); + worker->GetThread()->SetVerifierDeps(nullptr); + main_deps->MergeWith(*thread_deps, dex_files);; + delete thread_deps; + } + Thread::Current()->SetVerifierDeps(nullptr); + } } class VerifyClassVisitor : public CompilationVisitor { |