Move and rewrite bit loading/storing methods.
Move bit loading/storing methods to BitMemoryRegion and rewrite them.
Enforce natural alignment of the data pointer in BitMemoryRegion.
This probably would not be reasonable in MemoryRegion, but it is
fine here since the BitMemoryRegion already has extra bit offset.
The alignment makes it possible to simplify and optimize the methods.
This makes the stackmap reading code 33% faster.
(measured by the time needed to verify all stackmap fields on ARM).
Test: m -j40 test-art-host-gtest
Change-Id: I00be8052969a6056b262df4cd2066ffd86043196
diff --git a/runtime/stack_map.h b/runtime/stack_map.h
index 3839764..7d3d56a 100644
--- a/runtime/stack_map.h
+++ b/runtime/stack_map.h
@@ -452,7 +452,7 @@
explicit DexRegisterMap(MemoryRegion region) : region_(region) {}
DexRegisterMap() {}
- bool IsValid() const { return region_.pointer() != nullptr; }
+ bool IsValid() const { return region_.IsValid(); }
// Get the surface kind of Dex register `dex_register_number`.
DexRegisterLocation::Kind GetLocationKind(uint16_t dex_register_number,
@@ -627,7 +627,7 @@
// Return the size of the DexRegisterMap object, in bytes.
size_t Size() const {
- return region_.size();
+ return BitsToBytesRoundUp(region_.size_in_bits());
}
void Dump(VariableIndentationOutputStream* vios,
@@ -650,7 +650,7 @@
static constexpr int kFixedSize = 0;
- MemoryRegion region_;
+ BitMemoryRegion region_;
friend class CodeInfo;
friend class StackMapStream;
@@ -678,7 +678,7 @@
template <typename Region>
ALWAYS_INLINE void Store(Region region, int32_t value) const {
- region.StoreBits(start_offset_, value - min_value_, BitSize());
+ region.StoreBits(start_offset_, static_cast<uint32_t>(value - min_value_), BitSize());
DCHECK_EQ(Load(region), value);
}
@@ -805,7 +805,7 @@
StackMap() {}
explicit StackMap(BitMemoryRegion region) : region_(region) {}
- ALWAYS_INLINE bool IsValid() const { return region_.pointer() != nullptr; }
+ ALWAYS_INLINE bool IsValid() const { return region_.IsValid(); }
ALWAYS_INLINE uint32_t GetDexPc(const StackMapEncoding& encoding) const {
return encoding.GetDexPcEncoding().Load(region_);
@@ -868,9 +868,7 @@
}
ALWAYS_INLINE bool Equals(const StackMap& other) const {
- return region_.pointer() == other.region_.pointer() &&
- region_.size() == other.region_.size() &&
- region_.BitOffset() == other.region_.BitOffset();
+ return region_.Equals(other.region_);
}
void Dump(VariableIndentationOutputStream* vios,
@@ -1257,7 +1255,7 @@
return method_info.GetMethodIndex(GetMethodIndexIdx(encoding));
}
- bool IsValid() const { return region_.pointer() != nullptr; }
+ bool IsValid() const { return region_.IsValid(); }
private:
BitMemoryRegion region_;