diff options
author | Brian Carlstrom <bdc@google.com> | 2013-07-11 16:00:56 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2013-07-11 21:16:04 -0700 |
commit | 51c2467e8771b56e25ae4f17f66522f979f57a7e (patch) | |
tree | 16a66abbb45ea3fcc8c513c8511f34a46cd454c4 /src | |
parent | 27c590edf6c24107b6473e84e526c432bd081f6e (diff) | |
download | android_art-51c2467e8771b56e25ae4f17f66522f979f57a7e.tar.gz android_art-51c2467e8771b56e25ae4f17f66522f979f57a7e.tar.bz2 android_art-51c2467e8771b56e25ae4f17f66522f979f57a7e.zip |
libart-compiler cleanup
- Move compile-time code to src/compiler and libart-compiler
OatWriter, ImageWriter, ElfWriter, ElfFixup, ElfStripper, stub generation
- Move ClassReference and MethodReference to remove MethodVerifier dependency on CompilerDriver
- Move runtime_support_llvm.cc out of src/compiler and next to runtime_support.cc
- Change dex2oat and gtests to directly depend on libart-compiler
- Move non-common definitions from Android.common.mk to more specific makefiles
- Add LOCAL_ADDITIONAL_DEPENDENCIES on appropriate makefiles
Change-Id: I897027e69945914128f21f317a92caf9255bc600
Diffstat (limited to 'src')
44 files changed, 265 insertions, 320 deletions
diff --git a/src/class_reference.h b/src/class_reference.h new file mode 100644 index 0000000000..c3be720ea5 --- /dev/null +++ b/src/class_reference.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_SRC_CLASS_REFERENCE_H_ +#define ART_SRC_CLASS_REFERENCE_H_ + +#include <stdint.h> + +namespace art { + +class DexFile; + +// A class is uniquely located by its DexFile and the class_defs_ table index into that DexFile +typedef std::pair<const DexFile*, uint32_t> ClassReference; + +inline bool operator<(const ClassReference& lhs, const ClassReference& rhs) { + if (lhs.second < rhs.second) { + return true; + } else if (lhs.second > rhs.second) { + return false; + } else { + return (lhs.first < rhs.first); + } +} + +} // namespace art + +#endif // ART_SRC_CLASS_REFERENCE_H_ diff --git a/src/common_test.h b/src/common_test.h index 11bd4f0957..f03b1f9cdb 100644 --- a/src/common_test.h +++ b/src/common_test.h @@ -188,8 +188,8 @@ class CommonTest : public testing::Test { const mirror::DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache(); const DexFile& dex_file = *dex_cache->GetDexFile(); compiled_method = - compiler_driver_->GetCompiledMethod(CompilerDriver::MethodReference(&dex_file, - method->GetDexMethodIndex())); + compiler_driver_->GetCompiledMethod(MethodReference(&dex_file, + method->GetDexMethodIndex())); #ifndef ART_LIGHT_MODE CHECK(compiled_method != NULL) << PrettyMethod(method); diff --git a/src/compiler/dex/dex_to_dex_compiler.cc b/src/compiler/dex/dex_to_dex_compiler.cc index afb29f4163..ce512ec382 100644 --- a/src/compiler/dex/dex_to_dex_compiler.cc +++ b/src/compiler/dex/dex_to_dex_compiler.cc @@ -206,7 +206,7 @@ void DexCompiler::CompileInvokeVirtual(Instruction* inst, return; } uint32_t method_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c(); - CompilerDriver::MethodReference target_method(&GetDexFile(), method_idx); + MethodReference target_method(&GetDexFile(), method_idx); InvokeType invoke_type = kVirtual; InvokeType original_invoke_type = invoke_type; int vtable_idx; diff --git a/src/compiler/dex/mir_dataflow.cc b/src/compiler/dex/mir_dataflow.cc index 3b2c1a6c5e..381afb122e 100644 --- a/src/compiler/dex/mir_dataflow.cc +++ b/src/compiler/dex/mir_dataflow.cc @@ -1225,7 +1225,7 @@ bool MIRGraph::InvokeUsesMethodStar(MIR* mir) return false; } DexCompilationUnit m_unit(cu_); - CompilerDriver::MethodReference target_method(cu_->dex_file, mir->dalvikInsn.vB); + MethodReference target_method(cu_->dex_file, mir->dalvikInsn.vB); int vtable_idx; uintptr_t direct_code; uintptr_t direct_method; diff --git a/src/compiler/dex/quick/codegen_util.cc b/src/compiler/dex/quick/codegen_util.cc index ac2828c276..766cdce235 100644 --- a/src/compiler/dex/quick/codegen_util.cc +++ b/src/compiler/dex/quick/codegen_util.cc @@ -632,7 +632,7 @@ void Mir2Lir::CreateNativeGcMap() { max_native_offset = native_offset; } } - CompilerDriver::MethodReference method_ref(cu_->dex_file, cu_->method_idx); + MethodReference method_ref(cu_->dex_file, cu_->method_idx); const std::vector<uint8_t>* gc_map_raw = verifier::MethodVerifier::GetDexGcMap(method_ref); verifier::DexPcToReferenceMap dex_gc_map(&(*gc_map_raw)[4], gc_map_raw->size() - 4); // Compute native offset to references size. diff --git a/src/compiler/dex/quick/gen_common.cc b/src/compiler/dex/quick/gen_common.cc index 7aa71cfd10..2980acbd06 100644 --- a/src/compiler/dex/quick/gen_common.cc +++ b/src/compiler/dex/quick/gen_common.cc @@ -1077,7 +1077,7 @@ void Mir2Lir::GenCheckCast(uint32_t insn_idx, uint32_t type_idx, RegLocation rl_ // Note: currently type_known_final is unused, as optimizing will only improve the performance // of the exception throw path. DexCompilationUnit* cu = mir_graph_->GetCurrentDexCompilationUnit(); - const CompilerDriver::MethodReference mr(cu->GetDexFile(), cu->GetDexMethodIndex()); + const MethodReference mr(cu->GetDexFile(), cu->GetDexMethodIndex()); if (!needs_access_check && cu_->compiler_driver->IsSafeCast(mr, insn_idx)) { // Verifier type analysis proved this check cast would never cause an exception. return; diff --git a/src/compiler/dex/quick/gen_invoke.cc b/src/compiler/dex/quick/gen_invoke.cc index 4b12bb407a..3bc73401cf 100644 --- a/src/compiler/dex/quick/gen_invoke.cc +++ b/src/compiler/dex/quick/gen_invoke.cc @@ -313,7 +313,7 @@ void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) * emit the next instruction in static & direct invoke sequences. */ static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info, - int state, const CompilerDriver::MethodReference& target_method, + int state, const MethodReference& target_method, uint32_t unused, uintptr_t direct_code, uintptr_t direct_method, InvokeType type) @@ -418,7 +418,7 @@ static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info, * kArg1 here rather than the standard LoadArgRegs. */ static int NextVCallInsn(CompilationUnit* cu, CallInfo* info, - int state, const CompilerDriver::MethodReference& target_method, + int state, const MethodReference& target_method, uint32_t method_idx, uintptr_t unused, uintptr_t unused2, InvokeType unused3) { @@ -467,7 +467,7 @@ static int NextVCallInsn(CompilationUnit* cu, CallInfo* info, * which will locate the target and continue on via a tail call. */ static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t unused, uintptr_t unused2, uintptr_t direct_method, InvokeType unused4) { @@ -535,7 +535,7 @@ static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state, } static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info, int trampoline, - int state, const CompilerDriver::MethodReference& target_method, + int state, const MethodReference& target_method, uint32_t method_idx) { Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); @@ -558,7 +558,7 @@ static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info, int trampoline, static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t method_idx, uintptr_t unused, uintptr_t unused2, InvokeType unused3) @@ -568,7 +568,7 @@ static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info, } static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t method_idx, uintptr_t unused, uintptr_t unused2, InvokeType unused3) { @@ -577,7 +577,7 @@ static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, } static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t method_idx, uintptr_t unused, uintptr_t unused2, InvokeType unused3) { @@ -586,7 +586,7 @@ static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, } static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t method_idx, uintptr_t unused, uintptr_t unused2, InvokeType unused3) { @@ -596,7 +596,7 @@ static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu, CallInfo* info, int state, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t unused, uintptr_t unused2, uintptr_t unused3, InvokeType unused4) @@ -607,7 +607,7 @@ static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu, int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state, NextCallInsn next_call_insn, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, InvokeType type, bool skip_this) { @@ -647,7 +647,7 @@ int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state, */ int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel, NextCallInsn next_call_insn, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, InvokeType type, bool skip_this) { @@ -747,7 +747,7 @@ int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info, */ int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel, NextCallInsn next_call_insn, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, InvokeType type, bool skip_this) { @@ -1373,7 +1373,7 @@ void Mir2Lir::GenInvoke(CallInfo* info) LockCallTemps(); DexCompilationUnit* cUnit = mir_graph_->GetCurrentDexCompilationUnit(); - CompilerDriver::MethodReference target_method(cUnit->GetDexFile(), info->index); + MethodReference target_method(cUnit->GetDexFile(), info->index); int vtable_idx; uintptr_t direct_code; uintptr_t direct_method; diff --git a/src/compiler/dex/quick/mir_to_lir.h b/src/compiler/dex/quick/mir_to_lir.h index 9eb4524d0d..93098dbfd1 100644 --- a/src/compiler/dex/quick/mir_to_lir.h +++ b/src/compiler/dex/quick/mir_to_lir.h @@ -100,7 +100,7 @@ class MIRGraph; class Mir2Lir; typedef int (*NextCallInsn)(CompilationUnit*, CallInfo*, int, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t method_idx, uintptr_t direct_code, uintptr_t direct_method, InvokeType type); @@ -467,13 +467,13 @@ class Mir2Lir : public Backend { void FlushIns(RegLocation* ArgLocs, RegLocation rl_method); int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel, NextCallInsn next_call_insn, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, InvokeType type, bool skip_this); int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel, NextCallInsn next_call_insn, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, InvokeType type, bool skip_this); @@ -495,7 +495,7 @@ class Mir2Lir : public Backend { bool GenIntrinsic(CallInfo* info); int LoadArgRegs(CallInfo* info, int call_state, NextCallInsn next_call_insn, - const CompilerDriver::MethodReference& target_method, + const MethodReference& target_method, uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, InvokeType type, bool skip_this); diff --git a/src/compiler/dex/write_elf.cc b/src/compiler/dex/write_elf.cc deleted file mode 100644 index d9e45a9c19..0000000000 --- a/src/compiler/dex/write_elf.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "elf_fixup.h" -#include "elf_stripper.h" -#include "os.h" - -#if defined(ART_USE_PORTABLE_COMPILER) -#include "elf_writer_mclinker.h" -#else -#include "elf_writer_quick.h" -#endif - -namespace art { -class CompilerDriver; -class DexFile; -} // namespace art - -extern "C" bool WriteElf(art::CompilerDriver& driver, - const std::string& android_root, - bool is_host, - const std::vector<const art::DexFile*>& dex_files, - std::vector<uint8_t>& oat_contents, - art::File* file) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { -#if defined(ART_USE_PORTABLE_COMPILER) - return art::ElfWriterMclinker::Create(file, oat_contents, dex_files, android_root, is_host, driver); -#else - return art::ElfWriterQuick::Create(file, oat_contents, dex_files, android_root, is_host, driver); -#endif -} -extern "C" bool FixupElf(art::File* file, uintptr_t oat_data_begin) { - return art::ElfFixup::Fixup(file, oat_data_begin); -} -extern "C" void GetOatElfInformation(art::File* file, - size_t& oat_loaded_size, - size_t& oat_data_offset) { - art::ElfWriter::GetOatElfInformation(file, oat_loaded_size, oat_data_offset); -} -extern "C" bool StripElf(art::File* file) { - return art::ElfStripper::Strip(file); -} diff --git a/src/compiler/driver/compiler_driver.cc b/src/compiler/driver/compiler_driver.cc index c8ccbe9dbb..c876252d45 100644 --- a/src/compiler/driver/compiler_driver.cc +++ b/src/compiler/driver/compiler_driver.cc @@ -18,7 +18,6 @@ #include <vector> -#include <dlfcn.h> #include <unistd.h> #include "base/stl_util.h" @@ -48,8 +47,10 @@ #include "thread_pool.h" #include "verifier/method_verifier.h" -#if defined(__APPLE__) -#include <mach-o/dyld.h> +#if defined(ART_USE_PORTABLE_COMPILER) +#include "compiler/elf_writer_mclinker.h" +#else +#include "compiler/elf_writer_quick.h" #endif namespace art { @@ -281,48 +282,57 @@ class AOTCompilationStats { DISALLOW_COPY_AND_ASSIGN(AOTCompilationStats); }; -static std::string MakeCompilerSoName(CompilerBackend compiler_backend) { - - // Bad things happen if we pull in the libartd-compiler to a libart dex2oat or vice versa, - // because we end up with both libart and libartd in the same address space! - const char* suffix = (kIsDebugBuild ? "d" : ""); - - // Work out the filename for the compiler library. - std::string library_name(StringPrintf("art%s-compiler", suffix)); - std::string filename(StringPrintf(OS_SHARED_LIB_FORMAT_STR, library_name.c_str())); - -#if defined(__APPLE__) - // On Linux, dex2oat will have been built with an RPATH of $ORIGIN/../lib, so dlopen(3) will find - // the .so by itself. On Mac OS, there isn't really an equivalent, so we have to manually do the - // same work. - uint32_t executable_path_length = 0; - _NSGetExecutablePath(NULL, &executable_path_length); - std::string path(executable_path_length, static_cast<char>(0)); - CHECK_EQ(_NSGetExecutablePath(&path[0], &executable_path_length), 0); - - // Strip the "/dex2oat". - size_t last_slash = path.find_last_of('/'); - CHECK_NE(last_slash, std::string::npos) << path; - path.resize(last_slash); - - // Strip the "/bin". - last_slash = path.find_last_of('/'); - path.resize(last_slash); - - filename = path + "/lib/" + filename; -#endif - return filename; -} - -template<typename Fn> -static Fn FindFunction(const std::string& compiler_so_name, void* library, const char* name) { - Fn fn = reinterpret_cast<Fn>(dlsym(library, name)); - if (fn == NULL) { - LOG(FATAL) << "Couldn't find \"" << name << "\" in compiler library " << compiler_so_name << ": " << dlerror(); - } - VLOG(compiler) << "Found \"" << name << "\" at " << reinterpret_cast<void*>(fn); - return fn; -} +extern "C" void ArtInitCompilerContext(art::CompilerDriver& driver); +extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver& compiler); + +extern "C" void ArtUnInitCompilerContext(art::CompilerDriver& driver); +extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver& compiler); + +extern "C" art::CompiledMethod* ArtCompileMethod(art::CompilerDriver& driver, + const art::DexFile::CodeItem* code_item, + uint32_t access_flags, + art::InvokeType invoke_type, + uint32_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const art::DexFile& dex_file); +extern "C" art::CompiledMethod* ArtQuickCompileMethod(art::CompilerDriver& compiler, + const art::DexFile::CodeItem* code_item, + uint32_t access_flags, + art::InvokeType invoke_type, + uint32_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const art::DexFile& dex_file); + +extern "C" art::CompiledMethod* ArtCompileDEX(art::CompilerDriver& compiler, + const art::DexFile::CodeItem* code_item, + uint32_t access_flags, + art::InvokeType invoke_type, + uint32_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const art::DexFile& dex_file); + +extern "C" art::CompiledMethod* SeaIrCompileMethod(art::CompilerDriver& compiler, + const art::DexFile::CodeItem* code_item, + uint32_t access_flags, + art::InvokeType invoke_type, + uint32_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const art::DexFile& dex_file); + +extern "C" art::CompiledMethod* ArtLLVMJniCompileMethod(art::CompilerDriver& driver, + uint32_t access_flags, uint32_t method_idx, + const art::DexFile& dex_file); + +extern "C" art::CompiledMethod* ArtQuickJniCompileMethod(art::CompilerDriver& compiler, + uint32_t access_flags, uint32_t method_idx, + const art::DexFile& dex_file); + +extern "C" void compilerLLVMSetBitcodeFileName(art::CompilerDriver& driver, + std::string const& filename); CompilerDriver::CompilerDriver(CompilerBackend compiler_backend, InstructionSet instruction_set, bool image, DescriptorSet* image_classes, @@ -349,13 +359,6 @@ CompilerDriver::CompilerDriver(CompilerBackend compiler_backend, InstructionSet compiler_get_method_code_addr_(NULL), support_boot_image_fixup_(true) { - std::string compiler_so_name(MakeCompilerSoName(compiler_backend_)); - compiler_library_ = dlopen(compiler_so_name.c_str(), RTLD_LAZY); - if (compiler_library_ == NULL) { - LOG(FATAL) << "Couldn't find compiler library " << compiler_so_name << ": " << dlerror(); - } - VLOG(compiler) << "dlopen(\"" << compiler_so_name << "\", RTLD_LAZY) returned " << compiler_library_; - CHECK_PTHREAD_CALL(pthread_key_create, (&tls_key_, NULL), "compiler tls key"); // TODO: more work needed to combine initializations and allow per-method backend selection @@ -363,28 +366,28 @@ CompilerDriver::CompilerDriver(CompilerBackend compiler_backend, InstructionSet InitCompilerContextFn init_compiler_context; if (compiler_backend_ == kPortable){ // Initialize compiler_context_ - init_compiler_context = FindFunction<void (*)(CompilerDriver&)>(compiler_so_name, - compiler_library_, "ArtInitCompilerContext"); - compiler_ = FindFunction<CompilerFn>(compiler_so_name, compiler_library_, "ArtCompileMethod"); + init_compiler_context = reinterpret_cast<void (*)(CompilerDriver&)>(ArtInitCompilerContext); + compiler_ = reinterpret_cast<CompilerFn>(ArtCompileMethod); } else { - init_compiler_context = FindFunction<void (*)(CompilerDriver&)>(compiler_so_name, - compiler_library_, "ArtInitQuickCompilerContext"); - compiler_ = FindFunction<CompilerFn>(compiler_so_name, compiler_library_, "ArtQuickCompileMethod"); + init_compiler_context = reinterpret_cast<void (*)(CompilerDriver&)>(ArtInitQuickCompilerContext); + compiler_ = reinterpret_cast<CompilerFn>(ArtQuickCompileMethod); } - dex_to_dex_compiler_ = FindFunction<CompilerFn>(compiler_so_name, compiler_library_, "ArtCompileDEX"); + dex_to_dex_compiler_ = reinterpret_cast<CompilerFn>(ArtCompileDEX); +#ifdef ART_SEA_IR_MODE sea_ir_compiler_ = NULL; if (Runtime::Current()->IsSeaIRMode()) { - sea_ir_compiler_ = FindFunction<CompilerFn>(compiler_so_name, compiler_library_, "SeaIrCompileMethod"); + sea_ir_compiler_ = reinterpret_cast<CompilerFn>(SeaIrCompileMethod); } +#endif init_compiler_context(*this); if (compiler_backend_ == kPortable) { - jni_compiler_ = FindFunction<JniCompilerFn>(compiler_so_name, compiler_library_, "ArtLLVMJniCompileMethod"); + jni_compiler_ = reinterpret_cast<JniCompilerFn>(ArtLLVMJniCompileMethod); } else { - jni_compiler_ = FindFunction<JniCompilerFn>(compiler_so_name, compiler_library_, "ArtQuickJniCompileMethod"); + jni_compiler_ = reinterpret_cast<JniCompilerFn>(ArtQuickJniCompileMethod); } CHECK(!Runtime::Current()->IsStarted()); @@ -413,39 +416,15 @@ CompilerDriver::~CompilerDriver() { } CHECK_PTHREAD_CALL(pthread_key_delete, (tls_key_), "delete tls key"); typedef void (*UninitCompilerContextFn)(CompilerDriver&); - std::string compiler_so_name(MakeCompilerSoName(compiler_backend_)); UninitCompilerContextFn uninit_compiler_context; // Uninitialize compiler_context_ // TODO: rework to combine initialization/uninitialization if (compiler_backend_ == kPortable) { - uninit_compiler_context = FindFunction<void (*)(CompilerDriver&)>(compiler_so_name, - compiler_library_, "ArtUnInitCompilerContext"); + uninit_compiler_context = reinterpret_cast<void (*)(CompilerDriver&)>(ArtUnInitCompilerContext); } else { - uninit_compiler_context = FindFunction<void (*)(CompilerDriver&)>(compiler_so_name, - compiler_library_, "ArtUnInitQuickCompilerContext"); + uninit_compiler_context = reinterpret_cast<void (*)(CompilerDriver&)>(ArtUnInitQuickCompilerContext); } uninit_compiler_context(*this); -#if 0 - if (compiler_library_ != NULL) { - VLOG(compiler) << "dlclose(" << compiler_library_ << ")"; - /* - * FIXME: Temporary workaround - * Apparently, llvm is adding dctors to atexit, but if we unload - * the library here the code will no longer be around at exit time - * and we die a flaming death in __cxa_finalize(). Apparently, some - * dlclose() implementations will scan the atexit list on unload and - * handle any associated with the soon-to-be-unloaded library. - * However, this is not required by POSIX and we don't do it. - * See: http://b/issue?id=4998315 - * What's the right thing to do here? - * - * This has now been completely disabled because mclinker was - * closing stdout on exit, which was affecting both quick and - * portable. - */ - dlclose(compiler_library_); - } -#endif } CompilerTls* CompilerDriver::GetTls() { @@ -1217,9 +1196,8 @@ bool CompilerDriver::ComputeInvokeInfo(const DexCompilationUnit* mUnit, const ui if (kEnableVerifierBasedSharpening && (invoke_type == kVirtual || invoke_type == kInterface)) { // Did the verifier record a more precise invoke target based on its type information? - const CompilerDriver::MethodReference caller_method(mUnit->GetDexFile(), - mUnit->GetDexMethodIndex()); - const CompilerDriver::MethodReference* devirt_map_target = + const MethodReference caller_method(mUnit->GetDexFile(), mUnit->GetDexMethodIndex()); + const MethodReference* devirt_map_target = verifier::MethodVerifier::GetDevirtMap(caller_method, dex_pc); if (devirt_map_target != NULL) { mirror::DexCache* target_dex_cache = @@ -2138,7 +2116,7 @@ static void InitializeClass(const ParallelCompilationManager* manager, size_t cl } // Record the final class status if necessary. mirror::Class::Status status = klass->GetStatus(); - CompilerDriver::ClassReference ref(manager->GetDexFile(), class_def_index); + ClassReference ref(manager->GetDexFile(), class_def_index); CompiledClass* compiled_class = manager->GetCompiler()->GetCompiledClass(ref); if (compiled_class == NULL) { compiled_class = new CompiledClass(status); @@ -2287,21 +2265,16 @@ void CompilerDriver::CompileMethod(const DexFile::CodeItem* code_item, uint32_t dont_compile = false; } if (!dont_compile) { - bool use_sea = false; - - if (Runtime::Current()->IsSeaIRMode()) { - use_sea = true; - } + CompilerFn compiler = compiler_; +#ifdef ART_SEA_IR_MODE + bool use_sea = Runtime::Current()->IsSeaIRMode(); + use_sea &&= (std::string::npos != PrettyMethod(method_idx, dex_file).find("fibonacci")); if (use_sea) { - use_sea = (std::string::npos != PrettyMethod(method_idx, dex_file).find("fibonacci")); - } - if (!use_sea) { - compiled_method = (*compiler_)(*this, code_item, access_flags, invoke_type, class_def_idx, - method_idx, class_loader, dex_file); - } else { - compiled_method = (*sea_ir_compiler_)(*this, code_item, access_flags, invoke_type, class_def_idx, - method_idx, class_loader, dex_file); + compiler = sea_ir_compiler_; } +#endif + compiled_method = (*compiler)(*this, code_item, access_flags, invoke_type, class_def_idx, + method_idx, class_loader, dex_file); CHECK(compiled_method != NULL) << PrettyMethod(method_idx, dex_file); } else if (allow_dex_to_dex_compilation) { // TODO: add a mode to disable DEX-to-DEX compilation ? @@ -2365,8 +2338,7 @@ void CompilerDriver::SetBitcodeFileName(std::string const& filename) { typedef void (*SetBitcodeFileNameFn)(CompilerDriver&, std::string const&); SetBitcodeFileNameFn set_bitcode_file_name = - FindFunction<SetBitcodeFileNameFn>(MakeCompilerSoName(compiler_backend_), compiler_library_, - "compilerLLVMSetBitcodeFileName"); + reinterpret_cast<SetBitcodeFileNameFn>(compilerLLVMSetBitcodeFileName); set_bitcode_file_name(*this, filename); } @@ -2386,45 +2358,16 @@ bool CompilerDriver::RequiresConstructorBarrier(Thread* self, const DexFile* dex bool CompilerDriver::WriteElf(const std::string& android_root, bool is_host, - const std::vector<const DexFile*>& dex_files, + const std::vector<const art::DexFile*>& dex_files, std::vector<uint8_t>& oat_contents, - File* file) { - typedef bool (*WriteElfFn)(CompilerDriver&, - const std::string& android_root, - bool is_host, - const std::vector<const DexFile*>& dex_files, - std::vector<uint8_t>&, - File*); - WriteElfFn WriteElf = - FindFunction<WriteElfFn>(MakeCompilerSoName(compiler_backend_), compiler_library_, "WriteElf"); - Locks::mutator_lock_->AssertSharedHeld(Thread::Current()); - return WriteElf(*this, android_root, is_host, dex_files, oat_contents, file); -} - -bool CompilerDriver::FixupElf(File* file, uintptr_t oat_data_begin) const { - typedef bool (*FixupElfFn)(File*, uintptr_t oat_data_begin); - FixupElfFn FixupElf = - FindFunction<FixupElfFn>(MakeCompilerSoName(compiler_backend_), compiler_library_, "FixupElf"); - return FixupElf(file, oat_data_begin); -} - -void CompilerDriver::GetOatElfInformation(File* file, - size_t& oat_loaded_size, - size_t& oat_data_offset) const { - typedef bool (*GetOatElfInformationFn)(File*, size_t& oat_loaded_size, size_t& oat_data_offset); - GetOatElfInformationFn GetOatElfInformation = - FindFunction<GetOatElfInformationFn>(MakeCompilerSoName(compiler_backend_), compiler_library_, - "GetOatElfInformation"); - GetOatElfInformation(file, oat_loaded_size, oat_data_offset); -} - -bool CompilerDriver::StripElf(File* file) const { - typedef bool (*StripElfFn)(File*); - StripElfFn StripElf = - FindFunction<StripElfFn>(MakeCompilerSoName(compiler_backend_), compiler_library_, "StripElf"); - return StripElf(file); + art::File* file) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { +#if defined(ART_USE_PORTABLE_COMPILER) + return art::ElfWriterMclinker::Create(file, oat_contents, dex_files, android_root, is_host, *this); +#else + return art::ElfWriterQuick::Create(file, oat_contents, dex_files, android_root, is_host, *this); +#endif } - void CompilerDriver::InstructionSetToLLVMTarget(InstructionSet instruction_set, std::string& target_triple, std::string& target_cpu, diff --git a/src/compiler/driver/compiler_driver.h b/src/compiler/driver/compiler_driver.h index b37b74b042..d37f494ef1 100644 --- a/src/compiler/driver/compiler_driver.h +++ b/src/compiler/driver/compiler_driver.h @@ -22,11 +22,13 @@ #include <vector> #include "base/mutex.h" +#include "class_reference.h" #include "compiled_class.h" #include "compiled_method.h" #include "dex_file.h" #include "instruction_set.h" #include "invoke_type.h" +#include "method_reference.h" #include "oat_file.h" #include "runtime.h" #include "safe_map.h" @@ -114,30 +116,9 @@ class CompilerDriver { const std::vector<uint8_t>* CreateInterpreterToQuickEntry() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - // A class is uniquely located by its DexFile and the class_defs_ table index into that DexFile - typedef std::pair<const DexFile*, uint32_t> ClassReference; - CompiledClass* GetCompiledClass(ClassReference ref) const LOCKS_EXCLUDED(compiled_classes_lock_); - // A method is uniquely located by its DexFile and the method_ids_ table index into that DexFile - struct MethodReference { - MethodReference(const DexFile* file, uint32_t index) : dex_file(file), dex_method_index(index) { - } - const DexFile* dex_file; - uint32_t dex_method_index; - }; - - struct MethodReferenceComparator { - bool operator()(MethodReference mr1, MethodReference mr2) const { - if (mr1.dex_file == mr2.dex_file) { - return mr1.dex_method_index < mr2.dex_method_index; - } else { - return mr1.dex_file < mr2.dex_file; - } - } - }; - CompiledMethod* GetCompiledMethod(MethodReference ref) const LOCKS_EXCLUDED(compiled_methods_lock_); @@ -212,15 +193,11 @@ class CompilerDriver { } - // TODO: remove these Elf wrappers when libart links against LLVM (when separate compiler library is gone) bool WriteElf(const std::string& android_root, bool is_host, const std::vector<const DexFile*>& dex_files, std::vector<uint8_t>& oat_contents, File* file); - bool FixupElf(File* file, uintptr_t oat_data_begin) const; - void GetOatElfInformation(File* file, size_t& oat_loaded_size, size_t& oat_data_offset) const; - bool StripElf(File* file) const; // TODO: move to a common home for llvm helpers once quick/portable are merged static void InstructionSetToLLVMTarget(InstructionSet instruction_set, @@ -404,7 +381,9 @@ class CompilerDriver { uint32_t class_dex_idx, uint32_t method_idx, jobject class_loader, const DexFile& dex_file); CompilerFn compiler_; +#ifdef ART_SEA_IR_MODE CompilerFn sea_ir_compiler_; +#endif CompilerFn dex_to_dex_compiler_; @@ -429,16 +408,6 @@ class CompilerDriver { DISALLOW_COPY_AND_ASSIGN(CompilerDriver); }; -inline bool operator<(const CompilerDriver::ClassReference& lhs, const CompilerDriver::ClassReference& rhs) { - if (lhs.second < rhs.second) { - return true; - } else if (lhs.second > rhs.second) { - return false; - } else { - return (lhs.first < rhs.first); - } -} - } // namespace art #endif // ART_SRC_COMPILER_DRIVER_COMPILER_DRIVER_H_ diff --git a/src/elf_fixup.cc b/src/compiler/elf_fixup.cc index 127bc85d2c..127bc85d2c 100644 --- a/src/elf_fixup.cc +++ b/src/compiler/elf_fixup.cc diff --git a/src/elf_fixup.h b/src/compiler/elf_fixup.h index 79c45c1874..79c45c1874 100644 --- a/src/elf_fixup.h +++ b/src/compiler/elf_fixup.h diff --git a/src/elf_stripper.cc b/src/compiler/elf_stripper.cc index 7fc662ca1d..7fc662ca1d 100644 --- a/src/elf_stripper.cc +++ b/src/compiler/elf_stripper.cc diff --git a/src/elf_stripper.h b/src/compiler/elf_stripper.h index b202e6e1f0..b202e6e1f0 100644 --- a/src/elf_stripper.h +++ b/src/compiler/elf_stripper.h diff --git a/src/elf_writer.cc b/src/compiler/elf_writer.cc index 7592eb5edb..7592eb5edb 100644 --- a/src/elf_writer.cc +++ b/src/compiler/elf_writer.cc diff --git a/src/elf_writer.h b/src/compiler/elf_writer.h index 7392e67d7f..7392e67d7f 100644 --- a/src/elf_writer.h +++ b/src/compiler/elf_writer.h diff --git a/src/elf_writer_mclinker.cc b/src/compiler/elf_writer_mclinker.cc index e1d98f6919..e1d98f6919 100644 --- a/src/elf_writer_mclinker.cc +++ b/src/compiler/elf_writer_mclinker.cc diff --git a/src/elf_writer_mclinker.h b/src/compiler/elf_writer_mclinker.h index 21f23e113d..21f23e113d 100644 --- a/src/elf_writer_mclinker.h +++ b/src/compiler/elf_writer_mclinker.h diff --git a/src/elf_writer_quick.cc b/src/compiler/elf_writer_quick.cc index c3c5415733..c3c5415733 100644 --- a/src/elf_writer_quick.cc +++ b/src/compiler/elf_writer_quick.cc diff --git a/src/elf_writer_quick.h b/src/compiler/elf_writer_quick.h index a1a386b3d7..a1a386b3d7 100644 --- a/src/elf_writer_quick.h +++ b/src/compiler/elf_writer_quick.h diff --git a/src/elf_writer_test.cc b/src/compiler/elf_writer_test.cc index d4486d2c56..d4486d2c56 100644 --- a/src/elf_writer_test.cc +++ b/src/compiler/elf_writer_test.cc diff --git a/src/image_writer.cc b/src/compiler/image_writer.cc index f0b49be8a2..8b84e124e7 100644 --- a/src/image_writer.cc +++ b/src/compiler/image_writer.cc @@ -25,6 +25,7 @@ #include "class_linker.h" #include "compiled_method.h" #include "compiler/driver/compiler_driver.h" +#include "compiler/elf_writer.h" #include "dex_file-inl.h" #include "gc/accounting/card_table-inl.h" #include "gc/accounting/heap_bitmap.h" @@ -115,7 +116,7 @@ bool ImageWriter::Write(const std::string& image_filename, Thread::Current()->TransitionFromSuspendedToRunnable(); size_t oat_loaded_size = 0; size_t oat_data_offset = 0; - compiler_driver_.GetOatElfInformation(oat_file.get(), oat_loaded_size, oat_data_offset); + ElfWriter::GetOatElfInformation(oat_file.get(), oat_loaded_size, oat_data_offset); CalculateNewObjectOffsets(oat_loaded_size, oat_data_offset); CopyAndFixupObjects(); PatchOatCodeAndMethods(); diff --git a/src/image_writer.h b/src/compiler/image_writer.h index b79cb2f0c2..b79cb2f0c2 100644 --- a/src/image_writer.h +++ b/src/compiler/image_writer.h diff --git a/src/compiler/jni/portable/jni_compiler.cc b/src/compiler/jni/portable/jni_compiler.cc index 2795d05f4e..cd8158d0ed 100644 --- a/src/compiler/jni/portable/jni_compiler.cc +++ b/src/compiler/jni/portable/jni_compiler.cc @@ -24,7 +24,7 @@ #include "compiler/llvm/compiler_llvm.h" #include "compiler/llvm/ir_builder.h" #include "compiler/llvm/llvm_compilation_unit.h" -#include "compiler/llvm/runtime_support_func.h" +#include "compiler/llvm/runtime_support_llvm_func.h" #include "compiler/llvm/utils_llvm.h" #include "dex_file-inl.h" #include "mirror/abstract_method.h" diff --git a/src/compiler/llvm/compiler_llvm.cc b/src/compiler/llvm/compiler_llvm.cc index dfd0e326d2..3af6687f65 100644 --- a/src/compiler/llvm/compiler_llvm.cc +++ b/src/compiler/llvm/compiler_llvm.cc @@ -152,8 +152,8 @@ CompileDexMethod(DexCompilationUnit* dex_compilation_unit, InvokeType invoke_typ cunit->Materialize(); - CompilerDriver::MethodReference mref(dex_compilation_unit->GetDexFile(), - dex_compilation_unit->GetDexMethodIndex()); + MethodReference mref(dex_compilation_unit->GetDexFile(), + dex_compilation_unit->GetDexMethodIndex()); return new CompiledMethod(compiler_driver_->GetInstructionSet(), cunit->GetElfObject(), *verifier::MethodVerifier::GetDexGcMap(mref), diff --git a/src/compiler/llvm/gbc_expander.cc b/src/compiler/llvm/gbc_expander.cc index bdf9aca68f..4702b37de1 100644 --- a/src/compiler/llvm/gbc_expander.cc +++ b/src/compiler/llvm/gbc_expander.cc @@ -19,6 +19,7 @@ #include "dex_file-inl.h" #include "intrinsic_helper.h" #include "ir_builder.h" +#include "method_reference.h" #include "mirror/abstract_method.h" #include "mirror/array.h" #include "mirror/string.h" @@ -776,8 +777,8 @@ llvm::Value* GBCExpanderPass::EmitInvoke(llvm::CallInst& call_inst) { art::InvokeType invoke_type = static_cast<art::InvokeType>(LV2UInt(call_inst.getArgOperand(0))); bool is_static = (invoke_type == art::kStatic); - art::CompilerDriver::MethodReference target_method(dex_compilation_unit_->GetDexFile(), - LV2UInt(call_inst.getArgOperand(1))); + art::MethodReference target_method(dex_compilation_unit_->GetDexFile(), + LV2UInt(call_inst.getArgOperand(1))); // Load *this* actual parameter llvm::Value* this_addr = (!is_static) ? call_inst.getArgOperand(3) : NULL; diff --git a/src/compiler/llvm/ir_builder.h b/src/compiler/llvm/ir_builder.h index 9d78fe6eaa..eb88fcac18 100644 --- a/src/compiler/llvm/ir_builder.h +++ b/src/compiler/llvm/ir_builder.h @@ -22,7 +22,7 @@ #include "intrinsic_helper.h" #include "md_builder.h" #include "runtime_support_builder.h" -#include "runtime_support_func.h" +#include "runtime_support_llvm_func.h" #include <llvm/IR/Constants.h> #include <llvm/IR/DerivedTypes.h> diff --git a/src/compiler/llvm/llvm_compilation_unit.h b/src/compiler/llvm/llvm_compilation_unit.h index 857d924840..a5d4e117e6 100644 --- a/src/compiler/llvm/llvm_compilation_unit.h +++ b/src/compiler/llvm/llvm_compilation_unit.h @@ -25,7 +25,7 @@ #include "instruction_set.h" #include "compiler/driver/dex_compilation_unit.h" #include "runtime_support_builder.h" -#include "runtime_support_func.h" +#include "runtime_support_llvm_func.h" #include "safe_map.h" #include <UniquePtr.h> diff --git a/src/compiler/llvm/runtime_support_builder.cc b/src/compiler/llvm/runtime_support_builder.cc index 2be2ddf36f..28405f67d4 100644 --- a/src/compiler/llvm/runtime_support_builder.cc +++ b/src/compiler/llvm/runtime_support_builder.cc @@ -48,7 +48,7 @@ RuntimeSupportBuilder::RuntimeSupportBuilder(::llvm::LLVMContext& context, runtime_support_func_decls_[runtime_support::ID] = fn; \ } while (0); -#include "runtime_support_func_list.h" +#include "runtime_support_llvm_func_list.h" RUNTIME_SUPPORT_FUNC_LIST(GET_RUNTIME_SUPPORT_FUNC_DECL) #undef RUNTIME_SUPPORT_FUNC_LIST #undef GET_RUNTIME_SUPPORT_FUNC_DECL diff --git a/src/compiler/llvm/runtime_support_builder.h b/src/compiler/llvm/runtime_support_builder.h index 04d72b85b0..267b406232 100644 --- a/src/compiler/llvm/runtime_support_builder.h +++ b/src/compiler/llvm/runtime_support_builder.h @@ -19,7 +19,7 @@ #include "backend_types.h" #include "base/logging.h" -#include "runtime_support_func.h" +#include "runtime_support_llvm_func.h" #include <stdint.h> diff --git a/src/compiler/llvm/runtime_support_func.h b/src/compiler/llvm/runtime_support_llvm_func.h index 6dfa961242..ac6f3b869f 100644 --- a/src/compiler/llvm/runtime_support_func.h +++ b/src/compiler/llvm/runtime_support_llvm_func.h @@ -23,7 +23,7 @@ namespace runtime_support { enum RuntimeId { #define DEFINE_RUNTIME_SUPPORT_FUNC_ID(ID, NAME) ID, -#include "runtime_support_func_list.h" +#include "runtime_support_llvm_func_list.h" RUNTIME_SUPPORT_FUNC_LIST(DEFINE_RUNTIME_SUPPORT_FUNC_ID) #undef RUNTIME_SUPPORT_FUNC_LIST #undef DEFINE_RUNTIME_SUPPORT_FUNC_ID diff --git a/src/oat_writer.cc b/src/compiler/oat_writer.cc index 1d249d674f..0bfa4ec328 100644 --- a/src/oat_writer.cc +++ b/src/compiler/oat_writer.cc @@ -161,7 +161,7 @@ size_t OatWriter::InitOatClasses(size_t offset) { num_methods = num_direct_methods + num_virtual_methods; } - CompilerDriver::ClassReference class_ref = CompilerDriver::ClassReference(dex_file, class_def_index); + ClassReference class_ref(dex_file, class_def_index); CompiledClass* compiled_class = compiler_driver_->GetCompiledClass(class_ref); mirror::Class::Status status; if (compiled_class != NULL) { @@ -303,7 +303,7 @@ size_t OatWriter::InitOatCodeMethod(size_t offset, size_t oat_class_index, #endif CompiledMethod* compiled_method = - compiler_driver_->GetCompiledMethod(CompilerDriver::MethodReference(dex_file, method_idx)); + compiler_driver_->GetCompiledMethod(MethodReference(dex_file, method_idx)); if (compiled_method != NULL) { #if defined(ART_USE_PORTABLE_COMPILER) compiled_method->AddOatdataOffsetToCompliledCodeOffset( @@ -366,7 +366,7 @@ size_t OatWriter::InitOatCodeMethod(size_t offset, size_t oat_class_index, #if !defined(NDEBUG) // We expect GC maps except when the class hasn't been verified or the method is native - CompilerDriver::ClassReference class_ref = CompilerDriver::ClassReference(dex_file, class_def_index); + ClassReference class_ref(dex_file, class_def_index); CompiledClass* compiled_class = compiler_driver_->GetCompiledClass(class_ref); mirror::Class::Status status; if (compiled_class != NULL) { @@ -670,7 +670,7 @@ size_t OatWriter::WriteCodeMethod(OutputStream& out, size_t offset, size_t oat_c size_t class_def_method_index, bool is_static, uint32_t method_idx, const DexFile& dex_file) { const CompiledMethod* compiled_method = - compiler_driver_->GetCompiledMethod(CompilerDriver::MethodReference(&dex_file, method_idx)); + compiler_driver_->GetCompiledMethod(MethodReference(&dex_file, method_idx)); OatMethodOffsets method_offsets = oat_classes_[oat_class_index]->method_offsets_[class_def_method_index]; diff --git a/src/oat_writer.h b/src/compiler/oat_writer.h index b201d6b4ee..b201d6b4ee 100644 --- a/src/oat_writer.h +++ b/src/compiler/oat_writer.h diff --git a/src/dex2oat.cc b/src/dex2oat.cc index 6397f40b44..6c5ba52584 100644 --- a/src/dex2oat.cc +++ b/src/dex2oat.cc @@ -30,17 +30,19 @@ #include "base/unix_file/fd_file.h" #include "class_linker.h" #include "compiler/driver/compiler_driver.h" +#include "compiler/elf_fixup.h" +#include "compiler/elf_stripper.h" +#include "compiler/image_writer.h" +#include "compiler/oat_writer.h" #include "dex_file-inl.h" #include "gc/space/image_space.h" #include "gc/space/space-inl.h" -#include "image_writer.h" #include "leb128.h" #include "mirror/abstract_method-inl.h" #include "mirror/class-inl.h" #include "mirror/class_loader.h" #include "mirror/object-inl.h" #include "mirror/object_array-inl.h" -#include "oat_writer.h" #include "object_utils.h" #include "os.h" #include "runtime.h" @@ -325,7 +327,7 @@ class Dex2Oat { PLOG(ERROR) << "Failed to open ELF file: " << oat_filename; return false; } - if (!compiler.FixupElf(oat_file.get(), oat_data_begin)) { + if (!ElfFixup::Fixup(oat_file.get(), oat_data_begin)) { LOG(ERROR) << "Failed to fixup ELF file " << oat_file->GetPath(); return false; } @@ -1044,7 +1046,7 @@ static int dex2oat(int argc, char** argv) { // Strip unneeded sections for target off_t seek_actual = lseek(oat_file->Fd(), 0, SEEK_SET); CHECK_EQ(0, seek_actual); - compiler->StripElf(oat_file.get()); + ElfStripper::Strip(oat_file.get()); // We wrote the oat file successfully, and want to keep it. LOG(INFO) << "Oat file written successfully (stripped): " << oat_location; diff --git a/src/image_test.cc b/src/image_test.cc index 9f86a1aedf..9ab1d7475b 100644 --- a/src/image_test.cc +++ b/src/image_test.cc @@ -18,11 +18,12 @@ #include <vector> #include "common_test.h" +#include "compiler/elf_fixup.h" +#include "compiler/image_writer.h" +#include "compiler/oat_writer.h" +#include "gc/space/image_space.h" #include "image.h" -#include "image_writer.h" -#include "oat_writer.h" #include "signal_catcher.h" -#include "gc/space/image_space.h" #include "UniquePtr.h" #include "utils.h" #include "vector_output_stream.h" @@ -72,7 +73,7 @@ TEST_F(ImageTest, WriteRead) { bool success_image = writer.Write(tmp_image.GetFilename(), requested_image_base, tmp_oat->GetPath(), tmp_oat->GetPath()); ASSERT_TRUE(success_image); - bool success_fixup = compiler_driver_->FixupElf(tmp_oat.get(), writer.GetOatDataBegin()); + bool success_fixup = ElfFixup::Fixup(tmp_oat.get(), writer.GetOatDataBegin()); ASSERT_TRUE(success_fixup); } diff --git a/src/method_reference.h b/src/method_reference.h new file mode 100644 index 0000000000..ff8bf313f0 --- /dev/null +++ b/src/method_reference.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_SRC_METHOD_REFERENCE_H_ +#define ART_SRC_METHOD_REFERENCE_H_ + +namespace art { + +class DexFile; + +// A class is uniquely located by its DexFile and the class_defs_ table index into that DexFile +typedef std::pair<const DexFile*, uint32_t> ClassReference; + +// A method is uniquely located by its DexFile and the method_ids_ table index into that DexFile +struct MethodReference { + MethodReference(const DexFile* file, uint32_t index) : dex_file(file), dex_method_index(index) { + } + const DexFile* dex_file; + uint32_t dex_method_index; +}; + +struct MethodReferenceComparator { + bool operator()(MethodReference mr1, MethodReference mr2) const { + if (mr1.dex_file == mr2.dex_file) { + return mr1.dex_method_index < mr2.dex_method_index; + } else { + return mr1.dex_file < mr2.dex_file; + } + } +}; + +} // namespace art + +#endif // ART_SRC_METHOD_REFERENCE_H_ diff --git a/src/oat_test.cc b/src/oat_test.cc index 29e2891b40..f41a7bad95 100644 --- a/src/oat_test.cc +++ b/src/oat_test.cc @@ -14,12 +14,12 @@ * limitations under the License. */ +#include "compiler/oat_writer.h" #include "mirror/abstract_method-inl.h" #include "mirror/class-inl.h" #include "mirror/object_array-inl.h" #include "mirror/object-inl.h" #include "oat_file.h" -#include "oat_writer.h" #include "vector_output_stream.h" #include "common_test.h" @@ -33,8 +33,8 @@ class OatTest : public CommonTest { const DexFile* dex_file) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { const CompiledMethod* compiled_method = - compiler_driver_->GetCompiledMethod(CompilerDriver::MethodReference(dex_file, - method->GetDexMethodIndex())); + compiler_driver_->GetCompiledMethod(MethodReference(dex_file, + method->GetDexMethodIndex())); if (compiled_method == NULL) { EXPECT_TRUE(oat_method.GetCode() == NULL) << PrettyMethod(method) << " " diff --git a/src/runtime.h b/src/runtime.h index 0b893a341d..fc0ce83d95 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -134,9 +134,11 @@ class Runtime { return is_concurrent_gc_enabled_; } +#ifdef ART_SEA_IR_MODE bool IsSeaIRMode() const { return sea_ir_mode_; } +#endif void SetSeaIRMode(bool sea_ir_mode) { sea_ir_mode_ = sea_ir_mode; diff --git a/src/compiler/llvm/runtime_support_llvm.cc b/src/runtime_support_llvm.cc index bff13f9dc9..cbdefe8a03 100644 --- a/src/compiler/llvm/runtime_support_llvm.cc +++ b/src/runtime_support_llvm.cc @@ -33,11 +33,10 @@ #include "object_utils.h" #include "reflection.h" #include "runtime_support.h" -#include "runtime_support_func_list.h" +#include "runtime_support_llvm_func_list.h" #include "scoped_thread_state_change.h" #include "thread.h" #include "thread_list.h" -#include "utils_llvm.h" #include "verifier/dex_gc_map.h" #include "verifier/method_verifier.h" #include "well_known_classes.h" diff --git a/src/compiler/llvm/runtime_support_llvm.h b/src/runtime_support_llvm.h index af99842089..af99842089 100644 --- a/src/compiler/llvm/runtime_support_llvm.h +++ b/src/runtime_support_llvm.h diff --git a/src/compiler/llvm/runtime_support_func_list.h b/src/runtime_support_llvm_func_list.h index a58b061e16..a58b061e16 100644 --- a/src/compiler/llvm/runtime_support_func_list.h +++ b/src/runtime_support_llvm_func_list.h diff --git a/src/verifier/method_verifier.cc b/src/verifier/method_verifier.cc index 74a79e0ae2..31aec47f88 100644 --- a/src/verifier/method_verifier.cc +++ b/src/verifier/method_verifier.cc @@ -22,7 +22,6 @@ #include "base/mutex-inl.h" #include "base/stringpiece.h" #include "class_linker.h" -#include "compiler/driver/compiler_driver.h" #include "dex_file-inl.h" #include "dex_instruction-inl.h" #include "dex_instruction_visitor.h" @@ -426,7 +425,7 @@ std::ostream& MethodVerifier::Fail(VerifyError error) { // marked as rejected to prevent it from being compiled. case VERIFY_ERROR_BAD_CLASS_HARD: { if (Runtime::Current()->IsCompiler()) { - CompilerDriver::ClassReference ref(dex_file_, class_def_idx_); + ClassReference ref(dex_file_, class_def_idx_); AddRejectedClass(ref); } have_pending_hard_failure_ = true; @@ -1001,9 +1000,6 @@ bool MethodVerifier::VerifyCodeFlow() { return false; } - CompilerDriver::MethodReference ref(dex_file_, dex_method_idx_); - - /* Generate a register map and add it to the method. */ UniquePtr<const std::vector<uint8_t> > map(GenerateGcMap()); if (map.get() == NULL) { @@ -1013,6 +1009,7 @@ bool MethodVerifier::VerifyCodeFlow() { if (kIsDebugBuild) { VerifyGcMap(*map); } + MethodReference ref(dex_file_, dex_method_idx_); const std::vector<uint8_t>* dex_gc_map = CreateLengthPrefixedDexGcMap(*(map.get())); verifier::MethodVerifier::SetDexGcMap(ref, *dex_gc_map); @@ -3816,7 +3813,7 @@ MethodVerifier::PcToConcreteMethodMap* MethodVerifier::GenerateDevirtMap() { if (pc_to_concrete_method_map.get() == NULL) { pc_to_concrete_method_map.reset(new PcToConcreteMethodMap()); } - CompilerDriver::MethodReference concrete_ref( + MethodReference concrete_ref( concrete_method->GetDeclaringClass()->GetDexCache()->GetDexFile(), concrete_method->GetDexMethodIndex()); pc_to_concrete_method_map->Put(dex_pc, concrete_ref); @@ -3914,8 +3911,7 @@ void MethodVerifier::VerifyGcMap(const std::vector<uint8_t>& data) { } } -void MethodVerifier::SetDexGcMap(CompilerDriver::MethodReference ref, - const std::vector<uint8_t>& gc_map) { +void MethodVerifier::SetDexGcMap(MethodReference ref, const std::vector<uint8_t>& gc_map) { { WriterMutexLock mu(Thread::Current(), *dex_gc_maps_lock_); DexGcMapTable::iterator it = dex_gc_maps_->find(ref); @@ -3929,8 +3925,7 @@ void MethodVerifier::SetDexGcMap(CompilerDriver::MethodReference ref, } -void MethodVerifier::SetSafeCastMap(CompilerDriver::MethodReference ref, - const MethodSafeCastSet* cast_set) { +void MethodVerifier::SetSafeCastMap(MethodReference ref, const MethodSafeCastSet* cast_set) { MutexLock mu(Thread::Current(), *safecast_map_lock_); SafeCastMap::iterator it = safecast_map_->find(ref); if (it != safecast_map_->end()) { @@ -3942,7 +3937,7 @@ void MethodVerifier::SetSafeCastMap(CompilerDriver::MethodReference ref, CHECK(safecast_map_->find(ref) != safecast_map_->end()); } -bool MethodVerifier::IsSafeCast(CompilerDriver::MethodReference ref, uint32_t pc) { +bool MethodVerifier::IsSafeCast(MethodReference ref, uint32_t pc) { MutexLock mu(Thread::Current(), *safecast_map_lock_); SafeCastMap::const_iterator it = safecast_map_->find(ref); if (it == safecast_map_->end()) { @@ -3954,7 +3949,7 @@ bool MethodVerifier::IsSafeCast(CompilerDriver::MethodReference ref, uint32_t pc return cast_it != it->second->end(); } -const std::vector<uint8_t>* MethodVerifier::GetDexGcMap(CompilerDriver::MethodReference ref) { +const std::vector<uint8_t>* MethodVerifier::GetDexGcMap(MethodReference ref) { ReaderMutexLock mu(Thread::Current(), *dex_gc_maps_lock_); DexGcMapTable::const_iterator it = dex_gc_maps_->find(ref); if (it == dex_gc_maps_->end()) { @@ -3965,7 +3960,7 @@ const std::vector<uint8_t>* MethodVerifier::GetDexGcMap(CompilerDriver::MethodRe return it->second; } -void MethodVerifier::SetDevirtMap(CompilerDriver::MethodReference ref, +void MethodVerifier::SetDevirtMap(MethodReference ref, const PcToConcreteMethodMap* devirt_map) { WriterMutexLock mu(Thread::Current(), *devirt_maps_lock_); DevirtualizationMapTable::iterator it = devirt_maps_->find(ref); @@ -3978,7 +3973,7 @@ void MethodVerifier::SetDevirtMap(CompilerDriver::MethodReference ref, CHECK(devirt_maps_->find(ref) != devirt_maps_->end()); } -const CompilerDriver::MethodReference* MethodVerifier::GetDevirtMap(const CompilerDriver::MethodReference& ref, +const MethodReference* MethodVerifier::GetDevirtMap(const MethodReference& ref, uint32_t dex_pc) { ReaderMutexLock mu(Thread::Current(), *devirt_maps_lock_); DevirtualizationMapTable::const_iterator it = devirt_maps_->find(ref); @@ -4110,7 +4105,7 @@ void MethodVerifier::Shutdown() { verifier::RegTypeCache::ShutDown(); } -void MethodVerifier::AddRejectedClass(CompilerDriver::ClassReference ref) { +void MethodVerifier::AddRejectedClass(ClassReference ref) { { MutexLock mu(Thread::Current(), *rejected_classes_lock_); rejected_classes_->insert(ref); @@ -4118,7 +4113,7 @@ void MethodVerifier::AddRejectedClass(CompilerDriver::ClassReference ref) { CHECK(IsClassRejected(ref)); } -bool MethodVerifier::IsClassRejected(CompilerDriver::ClassReference ref) { +bool MethodVerifier::IsClassRejected(ClassReference ref) { MutexLock mu(Thread::Current(), *rejected_classes_lock_); return (rejected_classes_->find(ref) != rejected_classes_->end()); } diff --git a/src/verifier/method_verifier.h b/src/verifier/method_verifier.h index e90f9d95b0..ac0de9e1f7 100644 --- a/src/verifier/method_verifier.h +++ b/src/verifier/method_verifier.h @@ -23,10 +23,11 @@ #include "base/casts.h" #include "base/macros.h" #include "base/stl_util.h" -#include "compiler/driver/compiler_driver.h" +#include "class_reference.h" #include "dex_file.h" #include "dex_instruction.h" #include "instruction_flags.h" +#include "method_reference.h" #include "mirror/object.h" #include "reg_type.h" #include "reg_type_cache-inl.h" @@ -184,17 +185,15 @@ class MethodVerifier { // information void Dump(std::ostream& os) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - static const std::vector<uint8_t>* GetDexGcMap(CompilerDriver::MethodReference ref) + static const std::vector<uint8_t>* GetDexGcMap(MethodReference ref) LOCKS_EXCLUDED(dex_gc_maps_lock_); - static const CompilerDriver::MethodReference* GetDevirtMap(const CompilerDriver::MethodReference& ref, - uint32_t dex_pc) + static const MethodReference* GetDevirtMap(const MethodReference& ref, uint32_t dex_pc) LOCKS_EXCLUDED(devirt_maps_lock_); // Returns true if the cast can statically be verified to be redundant // by using the check-cast elision peephole optimization in the verifier - static bool IsSafeCast(CompilerDriver::MethodReference ref, uint32_t pc) - LOCKS_EXCLUDED(safecast_map_lock_); + static bool IsSafeCast(MethodReference ref, uint32_t pc) LOCKS_EXCLUDED(safecast_map_lock_); // Fills 'monitor_enter_dex_pcs' with the dex pcs of the monitor-enter instructions corresponding // to the locks held at 'dex_pc' in method 'm'. @@ -217,7 +216,7 @@ class MethodVerifier { static void Init() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); static void Shutdown(); - static bool IsClassRejected(CompilerDriver::ClassReference ref) + static bool IsClassRejected(ClassReference ref) LOCKS_EXCLUDED(rejected_classes_lock_); bool CanLoadClasses() const { @@ -622,42 +621,42 @@ class MethodVerifier { InstructionFlags* CurrentInsnFlags(); // All the GC maps that the verifier has created - typedef SafeMap<const CompilerDriver::MethodReference, const std::vector<uint8_t>*, - CompilerDriver::MethodReferenceComparator> DexGcMapTable; + typedef SafeMap<const MethodReference, const std::vector<uint8_t>*, + MethodReferenceComparator> DexGcMapTable; static ReaderWriterMutex* dex_gc_maps_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; static DexGcMapTable* dex_gc_maps_ GUARDED_BY(dex_gc_maps_lock_); - static void SetDexGcMap(CompilerDriver::MethodReference ref, const std::vector<uint8_t>& dex_gc_map) + static void SetDexGcMap(MethodReference ref, const std::vector<uint8_t>& dex_gc_map) LOCKS_EXCLUDED(dex_gc_maps_lock_); // Cast elision types. typedef std::set<uint32_t> MethodSafeCastSet; - typedef SafeMap<const CompilerDriver::MethodReference, const MethodSafeCastSet*, - CompilerDriver::MethodReferenceComparator> SafeCastMap; + typedef SafeMap<const MethodReference, const MethodSafeCastSet*, + MethodReferenceComparator> SafeCastMap; MethodVerifier::MethodSafeCastSet* GenerateSafeCastSet() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - static void SetSafeCastMap(CompilerDriver::MethodReference ref, const MethodSafeCastSet* mscs); + static void SetSafeCastMap(MethodReference ref, const MethodSafeCastSet* mscs); LOCKS_EXCLUDED(safecast_map_lock_); static Mutex* safecast_map_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; static SafeCastMap* safecast_map_ GUARDED_BY(safecast_map_lock_); // Devirtualization map. - typedef SafeMap<const uint32_t, CompilerDriver::MethodReference> PcToConcreteMethodMap; - typedef SafeMap<const CompilerDriver::MethodReference, const PcToConcreteMethodMap*, - CompilerDriver::MethodReferenceComparator> DevirtualizationMapTable; + typedef SafeMap<const uint32_t, MethodReference> PcToConcreteMethodMap; + typedef SafeMap<const MethodReference, const PcToConcreteMethodMap*, + MethodReferenceComparator> DevirtualizationMapTable; MethodVerifier::PcToConcreteMethodMap* GenerateDevirtMap() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); static ReaderWriterMutex* devirt_maps_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; static DevirtualizationMapTable* devirt_maps_ GUARDED_BY(devirt_maps_lock_); - static void SetDevirtMap(CompilerDriver::MethodReference ref, + static void SetDevirtMap(MethodReference ref, const PcToConcreteMethodMap* pc_method_map) LOCKS_EXCLUDED(devirt_maps_lock_); - typedef std::set<CompilerDriver::ClassReference> RejectedClassesTable; + typedef std::set<ClassReference> RejectedClassesTable; static Mutex* rejected_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; static RejectedClassesTable* rejected_classes_; - static void AddRejectedClass(CompilerDriver::ClassReference ref) + static void AddRejectedClass(ClassReference ref) LOCKS_EXCLUDED(rejected_classes_lock_); RegTypeCache reg_types_; |