diff options
author | 2022-10-06 13:46:55 +0200 | |
---|---|---|
committer | 2022-10-06 15:02:53 +0000 | |
commit | 8c5e881904c30de5dbc03536ea67bbe2d48088fd (patch) | |
tree | b0bbf7c5120d7894d21131478640e6f7b8761975 | |
parent | e1b8877890147b8572809266653677084e1a5112 (diff) |
Remove `CompiledCode::CodePointer()`.
And clean up some related test helpers in preparation for
moving `CompiledMethod` to dex2oat/.
Test: m test-art-host-gtest
Test: run-gtests.sh
Change-Id: I13b42bfb4f6ee3a7f7f22bbc8d22203c5d56e00b
-rw-r--r-- | compiler/common_compiler_test.cc | 49 | ||||
-rw-r--r-- | compiler/common_compiler_test.h | 4 | ||||
-rw-r--r-- | compiler/compiled_method.cc | 19 | ||||
-rw-r--r-- | compiler/compiled_method.h | 5 | ||||
-rw-r--r-- | compiler/optimizing/codegen_test_utils.h | 8 | ||||
-rw-r--r-- | dex2oat/driver/compiler_driver_test.cc | 18 |
6 files changed, 34 insertions, 69 deletions
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc index 7d7b70bb6d..99fb581090 100644 --- a/compiler/common_compiler_test.cc +++ b/compiler/common_compiler_test.cc @@ -59,8 +59,8 @@ class CommonCompilerTestImpl::CodeAndMetadata { OatQuickMethodHeader method_header(vmap_table_offset); const size_t code_alignment = GetInstructionSetCodeAlignment(instruction_set); DCHECK_ALIGNED_PARAM(kPageSize, code_alignment); - code_offset_ = RoundUp(vmap_table.size() + sizeof(method_header), code_alignment); - const uint32_t capacity = RoundUp(code_offset_ + code_size, kPageSize); + const uint32_t code_offset = RoundUp(vmap_table.size() + sizeof(method_header), code_alignment); + const uint32_t capacity = RoundUp(code_offset + code_size, kPageSize); // Create a memfd handle with sufficient capacity. android::base::unique_fd mem_fd(art::memfd_create_compat("test code", /*flags=*/ 0)); @@ -81,12 +81,12 @@ class CommonCompilerTestImpl::CodeAndMetadata { CHECK(rw_map_.IsValid()) << error_msg; // Store data. - uint8_t* code_addr = rw_map_.Begin() + code_offset_; + uint8_t* code_addr = rw_map_.Begin() + code_offset; CHECK_ALIGNED_PARAM(code_addr, code_alignment); - CHECK_LE(vmap_table_offset, code_offset_); + CHECK_LE(vmap_table_offset, code_offset); memcpy(code_addr - vmap_table_offset, vmap_table.data(), vmap_table.size()); static_assert(std::is_trivially_copyable<OatQuickMethodHeader>::value, "Cannot use memcpy"); - CHECK_LE(sizeof(method_header), code_offset_); + CHECK_LE(sizeof(method_header), code_offset); memcpy(code_addr - sizeof(method_header), &method_header, sizeof(method_header)); CHECK_LE(code_size, static_cast<size_t>(rw_map_.End() - code_addr)); memcpy(code_addr, code.data(), code_size); @@ -107,18 +107,21 @@ class CommonCompilerTestImpl::CodeAndMetadata { /*filename=*/ "test code", &error_msg); CHECK(rx_map_.IsValid()) << error_msg; + + DCHECK_LT(code_offset, rx_map_.Size()); + size_t adjustment = GetInstructionSetEntryPointAdjustment(instruction_set); + entry_point_ = rx_map_.Begin() + code_offset + adjustment; } - const void* GetCodePointer() const { + const void* GetEntryPoint() const { DCHECK(rx_map_.IsValid()); - DCHECK_LE(code_offset_, rx_map_.Size()); - return rx_map_.Begin() + code_offset_; + return entry_point_; } private: MemMap rw_map_; MemMap rx_map_; - uint32_t code_offset_; + const void* entry_point_; DISALLOW_COPY_AND_ASSIGN(CodeAndMetadata); }; @@ -142,24 +145,7 @@ const void* CommonCompilerTestImpl::MakeExecutable(ArrayRef<const uint8_t> code, InstructionSet instruction_set) { CHECK_NE(code.size(), 0u); code_and_metadata_.emplace_back(code, vmap_table, instruction_set); - return code_and_metadata_.back().GetCodePointer(); -} - -void CommonCompilerTestImpl::MakeExecutable(ArtMethod* method, - const CompiledMethod* compiled_method) { - CHECK(method != nullptr); - const void* method_code = nullptr; - // If the code size is 0 it means the method was skipped due to profile guided compilation. - if (compiled_method != nullptr && compiled_method->GetQuickCode().size() != 0u) { - const void* code_ptr = MakeExecutable(compiled_method->GetQuickCode(), - compiled_method->GetVmapTable(), - compiled_method->GetInstructionSet()); - method_code = - CompiledMethod::CodePointer(code_ptr, compiled_method->GetInstructionSet()); - LOG(INFO) << "MakeExecutable " << method->PrettyMethod() << " code=" << method_code; - } - Runtime::Current()->GetInstrumentation()->InitializeMethodsCode( - method, /*aot_code=*/ method_code); + return code_and_metadata_.back().GetEntryPoint(); } void CommonCompilerTestImpl::SetUp() { @@ -253,11 +239,16 @@ void CommonCompilerTestImpl::CompileMethod(ArtMethod* method) { dex_file, dex_cache); } + CHECK(compiled_method != nullptr) << "Failed to compile " << method->PrettyMethod(); + CHECK_NE(compiled_method->GetQuickCode().size(), 0u); } - CHECK(method != nullptr); { TimingLogger::ScopedTiming t2("MakeExecutable", &timings); - MakeExecutable(method, compiled_method); + const void* method_code = MakeExecutable(compiled_method->GetQuickCode(), + compiled_method->GetVmapTable(), + compiled_method->GetInstructionSet()); + LOG(INFO) << "MakeExecutable " << method->PrettyMethod() << " code=" << method_code; + GetRuntime()->GetInstrumentation()->InitializeMethodsCode(method, /*aot_code=*/ method_code); } CompiledMethod::ReleaseSwapAllocatedCompiledMethod(&storage, compiled_method); } diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h index cc74f8f6b4..be2e483225 100644 --- a/compiler/common_compiler_test.h +++ b/compiler/common_compiler_test.h @@ -33,7 +33,6 @@ namespace mirror { class ClassLoader; } // namespace mirror -class CompiledMethod; class CompilerOptions; class CumulativeLogger; class DexFile; @@ -54,9 +53,6 @@ class CommonCompilerTestImpl { ArrayRef<const uint8_t> vmap_table, InstructionSet instruction_set); - void MakeExecutable(ArtMethod* method, const CompiledMethod* compiled_method) - REQUIRES_SHARED(Locks::mutator_lock_); - protected: void SetUp(); diff --git a/compiler/compiled_method.cc b/compiler/compiled_method.cc index 21d5ed927f..0a0a0057d4 100644 --- a/compiler/compiled_method.cc +++ b/compiler/compiled_method.cc @@ -58,25 +58,6 @@ size_t CompiledCode::GetEntryPointAdjustment() const { return GetInstructionSetEntryPointAdjustment(GetInstructionSet()); } -const void* CompiledCode::CodePointer(const void* code_pointer, InstructionSet instruction_set) { - switch (instruction_set) { - case InstructionSet::kArm: - case InstructionSet::kArm64: - case InstructionSet::kX86: - case InstructionSet::kX86_64: - return code_pointer; - case InstructionSet::kThumb2: { - uintptr_t address = reinterpret_cast<uintptr_t>(code_pointer); - // Set the low-order bit so a BLX will switch to Thumb mode - address |= 0x1; - return reinterpret_cast<const void*>(address); - } - default: - LOG(FATAL) << "Unknown InstructionSet: " << instruction_set; - UNREACHABLE(); - } -} - CompiledMethod::CompiledMethod(CompiledMethodStorage* storage, InstructionSet instruction_set, const ArrayRef<const uint8_t>& quick_code, diff --git a/compiler/compiled_method.h b/compiler/compiled_method.h index fa80d67b40..ed31ca7cf6 100644 --- a/compiler/compiled_method.h +++ b/compiler/compiled_method.h @@ -62,11 +62,6 @@ class CompiledCode { // Mainly to cope with `kThumb2` where the lower bit must be set. size_t GetEntryPointAdjustment() const; - // Returns a pointer suitable for invoking the code at the argument - // code_pointer address. Mainly to cope with kThumb2 where the - // lower bit must be set to indicate Thumb mode. - static const void* CodePointer(const void* code_pointer, InstructionSet instruction_set); - protected: static constexpr size_t kInstructionSetFieldSize = MinimumBitsToStore(static_cast<size_t>(InstructionSet::kLast)); diff --git a/compiler/optimizing/codegen_test_utils.h b/compiler/optimizing/codegen_test_utils.h index 95cb548905..8e93f4d55a 100644 --- a/compiler/optimizing/codegen_test_utils.h +++ b/compiler/optimizing/codegen_test_utils.h @@ -254,15 +254,11 @@ static void Run(const InternalCodeAllocator& allocator, Runtime* GetRuntime() override { return nullptr; } }; CodeHolder code_holder; - const void* code_ptr = + const void* method_code = code_holder.MakeExecutable(allocator.GetMemory(), ArrayRef<const uint8_t>(), target_isa); using fptr = Expected (*)(); - fptr f = reinterpret_cast<fptr>(reinterpret_cast<uintptr_t>(code_ptr)); - if (target_isa == InstructionSet::kThumb2) { - // For thumb we need the bottom bit set. - f = reinterpret_cast<fptr>(reinterpret_cast<uintptr_t>(f) + 1); - } + fptr f = reinterpret_cast<fptr>(reinterpret_cast<uintptr_t>(method_code)); VerifyGeneratedCode(target_isa, f, has_result, expected); } diff --git a/dex2oat/driver/compiler_driver_test.cc b/dex2oat/driver/compiler_driver_test.cc index 65aa88869f..7e3f40ce05 100644 --- a/dex2oat/driver/compiler_driver_test.cc +++ b/dex2oat/driver/compiler_driver_test.cc @@ -25,6 +25,7 @@ #include "base/casts.h" #include "class_linker-inl.h" #include "common_compiler_driver_test.h" +#include "compiled_method-inl.h" #include "compiler_callbacks.h" #include "dex/dex_file.h" #include "dex/dex_file_types.h" @@ -80,14 +81,19 @@ class CompilerDriverTest : public CommonCompilerDriverTest { void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) { CHECK(method != nullptr); - const CompiledMethod* compiled_method = nullptr; + const void* method_code = nullptr; if (!method->IsAbstract()) { - const DexFile& dex_file = *method->GetDexFile(); - compiled_method = - compiler_driver_->GetCompiledMethod(MethodReference(&dex_file, - method->GetDexMethodIndex())); + MethodReference method_ref(method->GetDexFile(), method->GetDexMethodIndex()); + const CompiledMethod* compiled_method = compiler_driver_->GetCompiledMethod(method_ref); + // If the code size is 0 it means the method was skipped due to profile guided compilation. + if (compiled_method != nullptr && compiled_method->GetQuickCode().size() != 0u) { + method_code = CommonCompilerTest::MakeExecutable(compiled_method->GetQuickCode(), + compiled_method->GetVmapTable(), + compiled_method->GetInstructionSet()); + LOG(INFO) << "MakeExecutable " << method->PrettyMethod() << " code=" << method_code; + } } - CommonCompilerTest::MakeExecutable(method, compiled_method); + runtime_->GetInstrumentation()->InitializeMethodsCode(method, /*aot_code=*/ method_code); } void MakeDexFileExecutable(jobject class_loader, const DexFile& dex_file) { |