summaryrefslogtreecommitdiffstats
path: root/compiler/utils
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/dex_cache_arrays_layout-inl.h50
-rw-r--r--compiler/utils/dex_cache_arrays_layout.h18
-rw-r--r--compiler/utils/x86_64/assembler_x86_64.cc8
-rw-r--r--compiler/utils/x86_64/assembler_x86_64.h69
4 files changed, 71 insertions, 74 deletions
diff --git a/compiler/utils/dex_cache_arrays_layout-inl.h b/compiler/utils/dex_cache_arrays_layout-inl.h
index 7d02ce35d8..2c50c96305 100644
--- a/compiler/utils/dex_cache_arrays_layout-inl.h
+++ b/compiler/utils/dex_cache_arrays_layout-inl.h
@@ -26,7 +26,6 @@
#include "utils.h"
namespace mirror {
-class ArtField;
class ArtMethod;
class Class;
class String;
@@ -34,40 +33,55 @@ class String;
namespace art {
-inline DexCacheArraysLayout::DexCacheArraysLayout(const DexFile* dex_file)
+inline DexCacheArraysLayout::DexCacheArraysLayout(size_t pointer_size, const DexFile* dex_file)
: /* types_offset_ is always 0u */
- methods_offset_(types_offset_ + ArraySize<mirror::Class>(dex_file->NumTypeIds())),
- strings_offset_(methods_offset_ + ArraySize<mirror::ArtMethod>(dex_file->NumMethodIds())),
- fields_offset_(strings_offset_ + ArraySize<mirror::String>(dex_file->NumStringIds())),
- size_(fields_offset_ + ArraySize<mirror::ArtField>(dex_file->NumFieldIds())) {
+ pointer_size_(pointer_size),
+ methods_offset_(types_offset_ + TypesSize(dex_file->NumTypeIds())),
+ strings_offset_(methods_offset_ + MethodsSize(dex_file->NumMethodIds())),
+ fields_offset_(strings_offset_ + StringsSize(dex_file->NumStringIds())),
+ size_(fields_offset_ + FieldsSize(dex_file->NumFieldIds())) {
+ DCHECK(pointer_size == 4u || pointer_size == 8u);
}
inline size_t DexCacheArraysLayout::TypeOffset(uint32_t type_idx) const {
- return types_offset_ + ElementOffset<mirror::Class>(type_idx);
+ return types_offset_ + ElementOffset(sizeof(mirror::HeapReference<mirror::Class>), type_idx);
+}
+
+inline size_t DexCacheArraysLayout::TypesSize(size_t num_elements) const {
+ return ArraySize(sizeof(mirror::HeapReference<mirror::Class>), num_elements);
}
inline size_t DexCacheArraysLayout::MethodOffset(uint32_t method_idx) const {
- return methods_offset_ + ElementOffset<mirror::ArtMethod>(method_idx);
+ return methods_offset_ + ElementOffset(
+ sizeof(mirror::HeapReference<mirror::ArtMethod>), method_idx);
+}
+
+inline size_t DexCacheArraysLayout::MethodsSize(size_t num_elements) const {
+ return ArraySize(sizeof(mirror::HeapReference<mirror::ArtMethod>), num_elements);
}
inline size_t DexCacheArraysLayout::StringOffset(uint32_t string_idx) const {
- return strings_offset_ + ElementOffset<mirror::String>(string_idx);
+ return strings_offset_ + ElementOffset(sizeof(mirror::HeapReference<mirror::String>), string_idx);
+}
+
+inline size_t DexCacheArraysLayout::StringsSize(size_t num_elements) const {
+ return ArraySize(sizeof(mirror::HeapReference<mirror::String>), num_elements);
}
inline size_t DexCacheArraysLayout::FieldOffset(uint32_t field_idx) const {
- return fields_offset_ + ElementOffset<mirror::ArtField>(field_idx);
+ return fields_offset_ + ElementOffset(pointer_size_, field_idx);
+}
+
+inline size_t DexCacheArraysLayout::FieldsSize(size_t num_elements) const {
+ return ArraySize(pointer_size_, num_elements);
}
-template <typename MirrorType>
-inline size_t DexCacheArraysLayout::ElementOffset(uint32_t idx) {
- return mirror::Array::DataOffset(sizeof(mirror::HeapReference<MirrorType>)).Uint32Value() +
- sizeof(mirror::HeapReference<MirrorType>) * idx;
+inline size_t DexCacheArraysLayout::ElementOffset(size_t element_size, uint32_t idx) {
+ return mirror::Array::DataOffset(element_size).Uint32Value() + element_size * idx;
}
-template <typename MirrorType>
-inline size_t DexCacheArraysLayout::ArraySize(uint32_t num_elements) {
- size_t array_size = mirror::ComputeArraySize(
- num_elements, ComponentSizeShiftWidth<sizeof(mirror::HeapReference<MirrorType>)>());
+inline size_t DexCacheArraysLayout::ArraySize(size_t element_size, uint32_t num_elements) {
+ size_t array_size = mirror::ComputeArraySize(num_elements, ComponentSizeShiftWidth(element_size));
DCHECK_NE(array_size, 0u); // No overflow expected for dex cache arrays.
return RoundUp(array_size, kObjectAlignment);
}
diff --git a/compiler/utils/dex_cache_arrays_layout.h b/compiler/utils/dex_cache_arrays_layout.h
index b461256f63..8f98ea11ba 100644
--- a/compiler/utils/dex_cache_arrays_layout.h
+++ b/compiler/utils/dex_cache_arrays_layout.h
@@ -29,6 +29,7 @@ class DexCacheArraysLayout {
// Construct an invalid layout.
DexCacheArraysLayout()
: /* types_offset_ is always 0u */
+ pointer_size_(0u),
methods_offset_(0u),
strings_offset_(0u),
fields_offset_(0u),
@@ -36,7 +37,7 @@ class DexCacheArraysLayout {
}
// Construct a layout for a particular dex file.
- explicit DexCacheArraysLayout(const DexFile* dex_file);
+ explicit DexCacheArraysLayout(size_t pointer_size, const DexFile* dex_file);
bool Valid() const {
return Size() != 0u;
@@ -52,36 +53,43 @@ class DexCacheArraysLayout {
size_t TypeOffset(uint32_t type_idx) const;
+ size_t TypesSize(size_t num_elements) const;
+
size_t MethodsOffset() const {
return methods_offset_;
}
size_t MethodOffset(uint32_t method_idx) const;
+ size_t MethodsSize(size_t num_elements) const;
+
size_t StringsOffset() const {
return strings_offset_;
}
size_t StringOffset(uint32_t string_idx) const;
+ size_t StringsSize(size_t num_elements) const;
+
size_t FieldsOffset() const {
return fields_offset_;
}
size_t FieldOffset(uint32_t field_idx) const;
+ size_t FieldsSize(size_t num_elements) const;
+
private:
static constexpr size_t types_offset_ = 0u;
+ const size_t pointer_size_; // Must be first for construction initialization order.
const size_t methods_offset_;
const size_t strings_offset_;
const size_t fields_offset_;
const size_t size_;
- template <typename MirrorType>
- static size_t ElementOffset(uint32_t idx);
+ static size_t ElementOffset(size_t element_size, uint32_t idx);
- template <typename MirrorType>
- static size_t ArraySize(uint32_t num_elements);
+ static size_t ArraySize(size_t element_size, uint32_t num_elements);
};
} // namespace art
diff --git a/compiler/utils/x86_64/assembler_x86_64.cc b/compiler/utils/x86_64/assembler_x86_64.cc
index cb6d400618..638659d635 100644
--- a/compiler/utils/x86_64/assembler_x86_64.cc
+++ b/compiler/utils/x86_64/assembler_x86_64.cc
@@ -2742,14 +2742,14 @@ void X86_64ExceptionSlowPath::Emit(Assembler *sasm) {
void X86_64Assembler::AddConstantArea() {
const std::vector<int32_t>& area = constant_area_.GetBuffer();
- for (size_t i = 0, u = area.size(); i < u; i++) {
+ for (size_t i = 0, e = area.size(); i < e; i++) {
AssemblerBuffer::EnsureCapacity ensured(&buffer_);
EmitInt32(area[i]);
}
}
int ConstantArea::AddInt32(int32_t v) {
- for (size_t i = 0, u = buffer_.size(); i < u; i++) {
+ for (size_t i = 0, e = buffer_.size(); i < e; i++) {
if (v == buffer_[i]) {
return i * elem_size_;
}
@@ -2766,8 +2766,8 @@ int ConstantArea::AddInt64(int64_t v) {
int32_t v_high = v >> 32;
if (buffer_.size() > 1) {
// Ensure we don't pass the end of the buffer.
- for (size_t i = 0, u = buffer_.size() - 1; i < u; i++) {
- if (v_low == buffer_[i] && v_high == buffer_[i+1]) {
+ for (size_t i = 0, e = buffer_.size() - 1; i < e; i++) {
+ if (v_low == buffer_[i] && v_high == buffer_[i + 1]) {
return i * elem_size_;
}
}
diff --git a/compiler/utils/x86_64/assembler_x86_64.h b/compiler/utils/x86_64/assembler_x86_64.h
index ef6205c870..15b8b15c74 100644
--- a/compiler/utils/x86_64/assembler_x86_64.h
+++ b/compiler/utils/x86_64/assembler_x86_64.h
@@ -235,6 +235,8 @@ class Address : public Operand {
result.SetSIB(TIMES_1, CpuRegister(RSP), CpuRegister(RBP));
result.SetDisp32(addr);
} else {
+ // RIP addressing is done using RBP as the base register.
+ // The value in RBP isn't used. Instead the offset is added to RIP.
result.SetModRM(0, CpuRegister(RBP));
result.SetDisp32(addr);
}
@@ -244,6 +246,8 @@ class Address : public Operand {
// An RIP relative address that will be fixed up later.
static Address RIP(AssemblerFixup* fixup) {
Address result;
+ // RIP addressing is done using RBP as the base register.
+ // The value in RBP isn't used. Instead the offset is added to RIP.
result.SetModRM(0, CpuRegister(RBP));
result.SetDisp32(0);
result.SetFixup(fixup);
@@ -267,32 +271,20 @@ class ConstantArea {
public:
ConstantArea() {}
- /**
- * Add a double to the constant area.
- * @param v literal to be added to the constant area.
- * @returns the offset in the constant area where the literal resides.
- */
+ // Add a double to the constant area, returning the offset into
+ // the constant area where the literal resides.
int AddDouble(double v);
- /**
- * Add a float to the constant area.
- * @param v literal to be added to the constant area.
- * @returns the offset in the constant area where the literal resides.
- */
+ // Add a float to the constant area, returning the offset into
+ // the constant area where the literal resides.
int AddFloat(float v);
- /**
- * Add an int32_t to the constant area.
- * @param v literal to be added to the constant area.
- * @returns the offset in the constant area where the literal resides.
- */
+ // Add an int32_t to the constant area, returning the offset into
+ // the constant area where the literal resides.
int AddInt32(int32_t v);
- /**
- * Add an int64_t to the constant area.
- * @param v literal to be added to the constant area.
- * @returns the offset in the constant area where the literal resides.
- */
+ // Add an int64_t to the constant area, returning the offset into
+ // the constant area where the literal resides.
int AddInt64(int64_t v);
int GetSize() const {
@@ -736,43 +728,26 @@ class X86_64Assembler FINAL : public Assembler {
// and branch to a ExceptionSlowPath if it is.
void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) OVERRIDE;
- /**
- * Add a double to the constant area.
- * @param v literal to be added to the constant area.
- * @returns the offset in the constant area where the literal resides.
- */
+ // Add a double to the constant area, returning the offset into
+ // the constant area where the literal resides.
int AddDouble(double v) { return constant_area_.AddDouble(v); }
- /**
- * Add a float to the constant area.
- * @param v literal to be added to the constant area.
- * @returns the offset in the constant area where the literal resides.
- */
+ // Add a float to the constant area, returning the offset into
+ // the constant area where the literal resides.
int AddFloat(float v) { return constant_area_.AddFloat(v); }
- /**
- * Add an int32_t to the constant area.
- * @param v literal to be added to the constant area.
- * @returns the offset in the constant area where the literal resides.
- */
+ // Add an int32_t to the constant area, returning the offset into
+ // the constant area where the literal resides.
int AddInt32(int32_t v) { return constant_area_.AddInt32(v); }
- /**
- * Add an int64_t to the constant area.
- * @param v literal to be added to the constant area.
- * @returns the offset in the constant area where the literal resides.
- */
+ // Add an int64_t to the constant area, returning the offset into
+ // the constant area where the literal resides.
int AddInt64(int64_t v) { return constant_area_.AddInt64(v); }
- /**
- * Add the contents of the constant area to the assembler buffer.
- */
+ // Add the contents of the constant area to the assembler buffer.
void AddConstantArea();
- /**
- * Is the constant area empty?
- * @returns 'true' if there are no literals in the constant area.
- */
+ // Is the constant area empty? Return true if there are no literals in the constant area.
bool IsConstantAreaEmpty() const { return constant_area_.GetSize() == 0; }
private: