diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiler.cc | 56 | ||||
| -rw-r--r-- | src/compiler.h | 26 |
2 files changed, 42 insertions, 40 deletions
diff --git a/src/compiler.cc b/src/compiler.cc index 4c9860cecb..e730f9dd6c 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -312,8 +312,7 @@ Compiler::Compiler(CompilerBackend compiler_backend, InstructionSet instruction_ compiler_(NULL), compiler_context_(NULL), jni_compiler_(NULL), - create_invoke_stub_(NULL), - thread_pool_(new ThreadPool(thread_count)) + create_invoke_stub_(NULL) { std::string compiler_so_name(MakeCompilerSoName(compiler_backend_, instruction_set_)); compiler_library_ = dlopen(compiler_so_name.c_str(), RTLD_LAZY); @@ -471,11 +470,12 @@ void Compiler::CompileAll(jobject class_loader, const std::vector<const DexFile*>& dex_files) { DCHECK(!Runtime::Current()->IsStarted()); + ThreadPool thread_pool(thread_count_); TimingLogger timings("compiler"); - PreCompile(class_loader, dex_files, timings); + PreCompile(class_loader, dex_files, thread_pool, timings); - Compile(class_loader, dex_files, timings); + Compile(class_loader, dex_files, thread_pool, timings); if (dump_timings_ && timings.GetTotalNs() > MsToNs(1000)) { timings.Dump(); @@ -507,8 +507,9 @@ void Compiler::CompileOne(const AbstractMethod* method) { std::vector<const DexFile*> dex_files; dex_files.push_back(dex_file); + ThreadPool thread_pool(1U); TimingLogger timings("CompileOne"); - PreCompile(class_loader, dex_files, timings); + PreCompile(class_loader, dex_files, thread_pool, timings); uint32_t method_idx = method->GetDexMethodIndex(); const DexFile::CodeItem* code_item = dex_file->GetCodeItem(method->GetCodeItemOffset()); @@ -521,21 +522,21 @@ void Compiler::CompileOne(const AbstractMethod* method) { } void Compiler::Resolve(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings) { + ThreadPool& thread_pool, TimingLogger& timings) { for (size_t i = 0; i != dex_files.size(); ++i) { const DexFile* dex_file = dex_files[i]; CHECK(dex_file != NULL); - ResolveDexFile(class_loader, *dex_file, timings); + ResolveDexFile(class_loader, *dex_file, thread_pool, timings); } } void Compiler::PreCompile(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings) { - Resolve(class_loader, dex_files, timings); + ThreadPool& thread_pool, TimingLogger& timings) { + Resolve(class_loader, dex_files, thread_pool, timings); - Verify(class_loader, dex_files, timings); + Verify(class_loader, dex_files, thread_pool, timings); - InitializeClasses(class_loader, dex_files, timings); + InitializeClasses(class_loader, dex_files, thread_pool, timings); } bool Compiler::IsImageClass(const std::string& descriptor) const { @@ -962,12 +963,12 @@ class CompilationContext { jobject class_loader, Compiler* compiler, const DexFile* dex_file, - ThreadPool* thread_pool) + ThreadPool& thread_pool) : class_linker_(class_linker), class_loader_(class_loader), compiler_(compiler), dex_file_(dex_file), - thread_pool_(thread_pool) {} + thread_pool_(&thread_pool) {} ClassLinker* GetClassLinker() const { CHECK(class_linker_ != NULL); @@ -1160,13 +1161,13 @@ static void ResolveType(const CompilationContext* context, size_t type_idx) } void Compiler::ResolveDexFile(jobject class_loader, const DexFile& dex_file, - TimingLogger& timings) { + ThreadPool& thread_pool, TimingLogger& timings) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); // TODO: we could resolve strings here, although the string table is largely filled with class // and method names. - CompilationContext context(class_linker, class_loader, this, &dex_file, thread_pool_.get()); + CompilationContext context(class_linker, class_loader, this, &dex_file, thread_pool); context.ForAll(0, dex_file.NumTypeIds(), ResolveType, thread_count_); timings.AddSplit("Resolve " + dex_file.GetLocation() + " Types"); @@ -1175,11 +1176,11 @@ void Compiler::ResolveDexFile(jobject class_loader, const DexFile& dex_file, } void Compiler::Verify(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings) { + ThreadPool& thread_pool, TimingLogger& timings) { for (size_t i = 0; i != dex_files.size(); ++i) { const DexFile* dex_file = dex_files[i]; CHECK(dex_file != NULL); - VerifyDexFile(class_loader, *dex_file, timings); + VerifyDexFile(class_loader, *dex_file, thread_pool, timings); } } @@ -1229,9 +1230,10 @@ static void VerifyClass(const CompilationContext* context, size_t class_def_inde CHECK(!Thread::Current()->IsExceptionPending()) << PrettyTypeOf(Thread::Current()->GetException()); } -void Compiler::VerifyDexFile(jobject class_loader, const DexFile& dex_file, TimingLogger& timings) { +void Compiler::VerifyDexFile(jobject class_loader, const DexFile& dex_file, + ThreadPool& thread_pool, TimingLogger& timings) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - CompilationContext context(class_linker, class_loader, this, &dex_file, thread_pool_.get()); + CompilationContext context(class_linker, class_loader, this, &dex_file, thread_pool); context.ForAll(0, dex_file.NumClassDefs(), VerifyClass, thread_count_); timings.AddSplit("Verify " + dex_file.GetLocation()); } @@ -1485,7 +1487,7 @@ static void InitializeClass(const CompilationContext* context, size_t class_def_ } void Compiler::InitializeClasses(jobject jni_class_loader, const DexFile& dex_file, - TimingLogger& timings) { + ThreadPool& thread_pool, TimingLogger& timings) { #ifndef NDEBUG for (size_t i = 0; i < arraysize(class_initializer_black_list); ++i) { const char* descriptor = class_initializer_black_list[i]; @@ -1493,27 +1495,27 @@ void Compiler::InitializeClasses(jobject jni_class_loader, const DexFile& dex_fi } #endif ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - CompilationContext context(class_linker, jni_class_loader, this, &dex_file, thread_pool_.get()); + CompilationContext context(class_linker, jni_class_loader, this, &dex_file, thread_pool); context.ForAll(0, dex_file.NumClassDefs(), InitializeClass, thread_count_); timings.AddSplit("InitializeNoClinit " + dex_file.GetLocation()); } void Compiler::InitializeClasses(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings) { + ThreadPool& thread_pool, TimingLogger& timings) { for (size_t i = 0; i != dex_files.size(); ++i) { const DexFile* dex_file = dex_files[i]; CHECK(dex_file != NULL); - InitializeClasses(class_loader, *dex_file, timings); + InitializeClasses(class_loader, *dex_file, thread_pool, timings); } } void Compiler::Compile(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings) { + ThreadPool& thread_pool, TimingLogger& timings) { for (size_t i = 0; i != dex_files.size(); ++i) { const DexFile* dex_file = dex_files[i]; CHECK(dex_file != NULL); - CompileDexFile(class_loader, *dex_file, timings); + CompileDexFile(class_loader, *dex_file, thread_pool, timings); } } @@ -1582,8 +1584,8 @@ void Compiler::CompileClass(const CompilationContext* context, size_t class_def_ } void Compiler::CompileDexFile(jobject class_loader, const DexFile& dex_file, - TimingLogger& timings) { - CompilationContext context(NULL, class_loader, this, &dex_file, thread_pool_.get()); + ThreadPool& thread_pool, TimingLogger& timings) { + CompilationContext context(NULL, class_loader, this, &dex_file, thread_pool); context.ForAll(0, dex_file.NumClassDefs(), Compiler::CompileClass, thread_count_); timings.AddSplit("Compile " + dex_file.GetLocation()); } diff --git a/src/compiler.h b/src/compiler.h index 39ee5e4ddb..bafd9d26eb 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -264,34 +264,36 @@ class Compiler { SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void PreCompile(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings) + ThreadPool& thread_pool, TimingLogger& timings) LOCKS_EXCLUDED(Locks::mutator_lock_); // Attempt to resolve all type, methods, fields, and strings // referenced from code in the dex file following PathClassLoader // ordering semantics. void Resolve(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings) + ThreadPool& thread_pool, TimingLogger& timings) LOCKS_EXCLUDED(Locks::mutator_lock_); - void ResolveDexFile(jobject class_loader, const DexFile& dex_file, TimingLogger& timings) + void ResolveDexFile(jobject class_loader, const DexFile& dex_file, + ThreadPool& thread_pool, TimingLogger& timings) LOCKS_EXCLUDED(Locks::mutator_lock_); void Verify(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings); - void VerifyDexFile(jobject class_loader, const DexFile& dex_file, TimingLogger& timings) + ThreadPool& thread_pool, TimingLogger& timings); + void VerifyDexFile(jobject class_loader, const DexFile& dex_file, + ThreadPool& thread_pool, TimingLogger& timings) LOCKS_EXCLUDED(Locks::mutator_lock_); - void InitializeClasses(jobject class_loader, - const std::vector<const DexFile*>& dex_files, - TimingLogger& timings) + void InitializeClasses(jobject class_loader, const std::vector<const DexFile*>& dex_files, + ThreadPool& thread_pool, TimingLogger& timings) LOCKS_EXCLUDED(Locks::mutator_lock_); void InitializeClasses(jobject class_loader, const DexFile& dex_file, - TimingLogger& timings) + ThreadPool& thread_pool, TimingLogger& timings) LOCKS_EXCLUDED(Locks::mutator_lock_, compiled_classes_lock_); void Compile(jobject class_loader, const std::vector<const DexFile*>& dex_files, - TimingLogger& timings); - void CompileDexFile(jobject class_loader, const DexFile& dex_file, TimingLogger& timings) + ThreadPool& thread_pool, TimingLogger& timings); + void CompileDexFile(jobject class_loader, const DexFile& dex_file, + ThreadPool& thread_pool, TimingLogger& timings) LOCKS_EXCLUDED(Locks::mutator_lock_); void CompileMethod(const DexFile::CodeItem* code_item, uint32_t access_flags, InvokeType invoke_type, uint32_t method_idx, @@ -367,8 +369,6 @@ class Compiler { const char* shorty, uint32_t shorty_len); CreateInvokeStubFn create_invoke_stub_; - UniquePtr<ThreadPool> thread_pool_; - pthread_key_t tls_key_; typedef CompiledInvokeStub* (*CreateProxyStubFn) |