summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2022-09-29 11:55:37 +0200
committer VladimĂ­r Marko <vmarko@google.com> 2022-09-29 12:09:38 +0000
commit7dec3562e903bf038f22c763fccd4dfa77f0468b (patch)
treea05c6048127fe1b1a211c09d3b8743ec439676ab
parent8a9b1a801acc633a4e1ea2226843c899a542ed70 (diff)
Rename `GetInstructionSet{,Code}Alignment`.
Update the `GetInstructionSetAlignment()` function name to `GetInstructionSetCodeAlignment()` in line with renames from https://android-review.googlesource.com/2229498 . Move the function to `instruction_set.h` and change the handling of unknown instruction sets to the approach used in other functions in the header file. Test: buildbot-build.sh --target Change-Id: I8239b94b56bf24f4e99a2d72ba10ec1f5a055d36
-rw-r--r--compiler/common_compiler_test.cc2
-rw-r--r--compiler/compiled_method.cc2
-rw-r--r--compiler/exception_test.cc2
-rw-r--r--dex2oat/linker/arm/relative_patcher_arm_base.cc4
-rw-r--r--dex2oat/linker/oat_writer.cc4
-rw-r--r--libartbase/arch/instruction_set.cc20
-rw-r--r--libartbase/arch/instruction_set.h19
-rw-r--r--runtime/jit/jit_code_cache.cc4
-rw-r--r--runtime/jit/jit_memory_region.cc4
-rw-r--r--runtime/oat_quick_method_header.h6
10 files changed, 32 insertions, 35 deletions
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index ab0e3e17cf..a63d21d4ca 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -58,7 +58,7 @@ class CommonCompilerTestImpl::CodeAndMetadata {
const uint32_t vmap_table_offset = vmap_table.empty() ? 0u
: sizeof(OatQuickMethodHeader) + vmap_table.size();
OatQuickMethodHeader method_header(vmap_table_offset);
- const size_t code_alignment = GetInstructionSetAlignment(instruction_set);
+ 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);
diff --git a/compiler/compiled_method.cc b/compiler/compiled_method.cc
index 03b87ef09e..e7cdd6eec5 100644
--- a/compiler/compiled_method.cc
+++ b/compiler/compiled_method.cc
@@ -51,7 +51,7 @@ size_t CompiledCode::AlignCode(size_t offset) const {
}
size_t CompiledCode::AlignCode(size_t offset, InstructionSet instruction_set) {
- return RoundUp(offset, GetInstructionSetAlignment(instruction_set));
+ return RoundUp(offset, GetInstructionSetCodeAlignment(instruction_set));
}
size_t CompiledCode::CodeDelta() const {
diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc
index a49c6c630e..f86e0b9b01 100644
--- a/compiler/exception_test.cc
+++ b/compiler/exception_test.cc
@@ -91,7 +91,7 @@ class ExceptionTest : public CommonRuntimeTest {
const size_t stack_maps_size = stack_map.size();
const size_t header_size = sizeof(OatQuickMethodHeader);
- const size_t code_alignment = GetInstructionSetAlignment(kRuntimeISA);
+ const size_t code_alignment = GetInstructionSetCodeAlignment(kRuntimeISA);
fake_header_code_and_maps_.resize(stack_maps_size + header_size + code_size + code_alignment);
// NB: The start of the vector might not have been allocated the desired alignment.
diff --git a/dex2oat/linker/arm/relative_patcher_arm_base.cc b/dex2oat/linker/arm/relative_patcher_arm_base.cc
index 35e799ac73..6d913228f8 100644
--- a/dex2oat/linker/arm/relative_patcher_arm_base.cc
+++ b/dex2oat/linker/arm/relative_patcher_arm_base.cc
@@ -462,7 +462,7 @@ void ArmBaseRelativePatcher::AddUnreservedThunk(ThunkData* data) {
}
unreserved_thunks_.insert(unreserved_thunks_.begin() + index, data);
// We may need to update the max next offset(s) if the thunk code would not fit.
- size_t alignment = GetInstructionSetAlignment(instruction_set_);
+ size_t alignment = GetInstructionSetCodeAlignment(instruction_set_);
if (index + 1u != unreserved_thunks_.size()) {
// Note: Ignore the return value as we need to process previous thunks regardless.
data->MakeSpaceBefore(*unreserved_thunks_[index + 1u], alignment);
@@ -535,7 +535,7 @@ void ArmBaseRelativePatcher::ResolveMethodCalls(uint32_t quick_code_offset,
inline uint32_t ArmBaseRelativePatcher::CalculateMaxNextOffset(uint32_t patch_offset,
const ThunkKey& key) {
return RoundDown(patch_offset + MaxPositiveDisplacement(key),
- GetInstructionSetAlignment(instruction_set_));
+ GetInstructionSetCodeAlignment(instruction_set_));
}
inline ArmBaseRelativePatcher::ThunkData ArmBaseRelativePatcher::ThunkDataForPatch(
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index 19e77de10b..e40caaded4 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -1486,7 +1486,7 @@ class OatWriter::LayoutReserveOffsetCodeMethodVisitor : public OrderedMethodVisi
offset_ = relative_patcher_->ReserveSpace(offset_, compiled_method, method_ref);
offset_ += CodeAlignmentSize(offset_, *compiled_method);
DCHECK_ALIGNED_PARAM(offset_ + sizeof(OatQuickMethodHeader),
- GetInstructionSetAlignment(compiled_method->GetInstructionSet()));
+ GetInstructionSetCodeAlignment(compiled_method->GetInstructionSet()));
return offset_ + sizeof(OatQuickMethodHeader) + thumb_offset;
}
@@ -1797,7 +1797,7 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor {
DCHECK_OFFSET_();
}
DCHECK_ALIGNED_PARAM(offset_ + sizeof(OatQuickMethodHeader),
- GetInstructionSetAlignment(compiled_method->GetInstructionSet()));
+ GetInstructionSetCodeAlignment(compiled_method->GetInstructionSet()));
DCHECK_EQ(method_offsets.code_offset_,
offset_ + sizeof(OatQuickMethodHeader) + compiled_method->CodeDelta())
<< dex_file_->PrettyMethod(method_ref.index);
diff --git a/libartbase/arch/instruction_set.cc b/libartbase/arch/instruction_set.cc
index 852f681a05..7f1e4c7dd7 100644
--- a/libartbase/arch/instruction_set.cc
+++ b/libartbase/arch/instruction_set.cc
@@ -73,26 +73,6 @@ InstructionSet GetInstructionSetFromString(const char* isa_str) {
return InstructionSet::kNone;
}
-size_t GetInstructionSetAlignment(InstructionSet isa) {
- switch (isa) {
- case InstructionSet::kArm:
- // Fall-through.
- case InstructionSet::kThumb2:
- return kArmCodeAlignment;
- case InstructionSet::kArm64:
- return kArm64CodeAlignment;
- case InstructionSet::kX86:
- // Fall-through.
- case InstructionSet::kX86_64:
- return kX86CodeAlignment;
- case InstructionSet::kNone:
- LOG(FATAL) << "ISA kNone does not have alignment.";
- UNREACHABLE();
- }
- LOG(FATAL) << "Unknown ISA " << isa;
- UNREACHABLE();
-}
-
std::vector<InstructionSet> GetSupportedInstructionSets(std::string* error_msg) {
std::string zygote_kinds = android::base::GetProperty("ro.zygote", {});
if (zygote_kinds.empty()) {
diff --git a/libartbase/arch/instruction_set.h b/libartbase/arch/instruction_set.h
index 1516df9417..69983d2fe8 100644
--- a/libartbase/arch/instruction_set.h
+++ b/libartbase/arch/instruction_set.h
@@ -133,7 +133,24 @@ constexpr bool IsValidInstructionSet(InstructionSet isa) {
return false;
}
-size_t GetInstructionSetAlignment(InstructionSet isa);
+constexpr size_t GetInstructionSetCodeAlignment(InstructionSet isa) {
+ switch (isa) {
+ case InstructionSet::kArm:
+ // Fall-through.
+ case InstructionSet::kThumb2:
+ return kArmCodeAlignment;
+ case InstructionSet::kArm64:
+ return kArm64CodeAlignment;
+ case InstructionSet::kX86:
+ // Fall-through.
+ case InstructionSet::kX86_64:
+ return kX86CodeAlignment;
+
+ case InstructionSet::kNone:
+ break;
+ }
+ InstructionSetAbort(isa);
+}
constexpr bool Is64BitInstructionSet(InstructionSet isa) {
switch (isa) {
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 39f165d7e2..819ec874f8 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -353,12 +353,12 @@ bool JitCodeCache::WaitForPotentialCollectionToComplete(Thread* self) {
}
static uintptr_t FromCodeToAllocation(const void* code) {
- size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
+ size_t alignment = GetInstructionSetCodeAlignment(kRuntimeISA);
return reinterpret_cast<uintptr_t>(code) - RoundUp(sizeof(OatQuickMethodHeader), alignment);
}
static const void* FromAllocationToCode(const uint8_t* alloc) {
- size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
+ size_t alignment = GetInstructionSetCodeAlignment(kRuntimeISA);
return reinterpret_cast<const void*>(alloc + RoundUp(sizeof(OatQuickMethodHeader), alignment));
}
diff --git a/runtime/jit/jit_memory_region.cc b/runtime/jit/jit_memory_region.cc
index 3f43aca932..410bf7004a 100644
--- a/runtime/jit/jit_memory_region.cc
+++ b/runtime/jit/jit_memory_region.cc
@@ -360,7 +360,7 @@ const uint8_t* JitMemoryRegion::CommitCode(ArrayRef<const uint8_t> reserved_code
DCHECK(IsInExecSpace(reserved_code.data()));
ScopedCodeCacheWrite scc(*this);
- size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
+ size_t alignment = GetInstructionSetCodeAlignment(kRuntimeISA);
size_t header_size = OatQuickMethodHeader::InstructionAlignedSize();
size_t total_size = header_size + code.size();
@@ -468,7 +468,7 @@ bool JitMemoryRegion::CommitData(ArrayRef<const uint8_t> reserved_data,
}
const uint8_t* JitMemoryRegion::AllocateCode(size_t size) {
- size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
+ size_t alignment = GetInstructionSetCodeAlignment(kRuntimeISA);
void* result = mspace_memalign(exec_mspace_, alignment, size);
if (UNLIKELY(result == nullptr)) {
return nullptr;
diff --git a/runtime/oat_quick_method_header.h b/runtime/oat_quick_method_header.h
index 0bbf23fc27..8e6d08e3a1 100644
--- a/runtime/oat_quick_method_header.h
+++ b/runtime/oat_quick_method_header.h
@@ -52,8 +52,8 @@ class PACKED(4) OatQuickMethodHeader {
static OatQuickMethodHeader* FromCodePointer(const void* code_ptr) {
uintptr_t code = reinterpret_cast<uintptr_t>(code_ptr);
uintptr_t header = code - OFFSETOF_MEMBER(OatQuickMethodHeader, code_);
- DCHECK(IsAlignedParam(code, GetInstructionSetAlignment(kRuntimeISA)) ||
- IsAlignedParam(header, GetInstructionSetAlignment(kRuntimeISA)))
+ DCHECK(IsAlignedParam(code, GetInstructionSetCodeAlignment(kRuntimeISA)) ||
+ IsAlignedParam(header, GetInstructionSetCodeAlignment(kRuntimeISA)))
<< std::hex << code << " " << std::hex << header;
return reinterpret_cast<OatQuickMethodHeader*>(header);
}
@@ -63,7 +63,7 @@ class PACKED(4) OatQuickMethodHeader {
}
static size_t InstructionAlignedSize() {
- return RoundUp(sizeof(OatQuickMethodHeader), GetInstructionSetAlignment(kRuntimeISA));
+ return RoundUp(sizeof(OatQuickMethodHeader), GetInstructionSetCodeAlignment(kRuntimeISA));
}
OatQuickMethodHeader(const OatQuickMethodHeader&) = default;