Align CodeInfo regions instead of their inner subregions.

Instead of word-aligning every stack map region, as well as
the Dex register maps region of a CodeInfo object, just
align the whole CodeInfo region itself.

Change-Id: Ia35d213d2bd184729aa0d048874c76f7bc6da0f6
diff --git a/compiler/optimizing/stack_map_stream.h b/compiler/optimizing/stack_map_stream.h
index 8fb58d1..863bab2 100644
--- a/compiler/optimizing/stack_map_stream.h
+++ b/compiler/optimizing/stack_map_stream.h
@@ -99,10 +99,12 @@
   }
 
   size_t ComputeNeededSize() const {
-    return CodeInfo::kFixedSize
+    size_t size = CodeInfo::kFixedSize
         + ComputeStackMapsSize()
         + ComputeDexRegisterMapsSize()
         + ComputeInlineInfoSize();
+    // On ARM, CodeInfo data must be 4-byte aligned.
+    return RoundUp(size, kWordAlignment);
   }
 
   size_t ComputeStackMaskSize() const {
@@ -110,7 +112,7 @@
   }
 
   size_t ComputeStackMapsSize() const {
-    return stack_maps_.Size() * StackMap::ComputeAlignedStackMapSize(ComputeStackMaskSize());
+    return stack_maps_.Size() * StackMap::ComputeStackMapSize(ComputeStackMaskSize());
   }
 
   // Compute the size of the Dex register map of `entry`.
@@ -133,8 +135,7 @@
       DexRegisterLocation entry = dex_register_maps_.Get(i);
       size += DexRegisterMap::EntrySize(entry);
     }
-    // On ARM, the Dex register maps must be 4-byte aligned.
-    return RoundUp(size, kWordAlignment);
+    return size;
   }
 
   // Compute the size of all the inline information pieces.
diff --git a/runtime/stack_map.h b/runtime/stack_map.h
index 3856da3..8ebafc5 100644
--- a/runtime/stack_map.h
+++ b/runtime/stack_map.h
@@ -46,19 +46,19 @@
   explicit InlineInfo(MemoryRegion region) : region_(region) {}
 
   uint8_t GetDepth() const {
-    return region_.Load<uint8_t>(kDepthOffset);
+    return region_.LoadUnaligned<uint8_t>(kDepthOffset);
   }
 
   void SetDepth(uint8_t depth) {
-    region_.Store<uint8_t>(kDepthOffset, depth);
+    region_.StoreUnaligned<uint8_t>(kDepthOffset, depth);
   }
 
   uint32_t GetMethodReferenceIndexAtDepth(uint8_t depth) const {
-    return region_.Load<uint32_t>(kFixedSize + depth * SingleEntrySize());
+    return region_.LoadUnaligned<uint32_t>(kFixedSize + depth * SingleEntrySize());
   }
 
   void SetMethodReferenceIndexAtDepth(uint8_t depth, uint32_t index) {
-    region_.Store<uint32_t>(kFixedSize + depth * SingleEntrySize(), index);
+    region_.StoreUnaligned<uint32_t>(kFixedSize + depth * SingleEntrySize(), index);
   }
 
   static size_t SingleEntrySize() {
@@ -466,43 +466,43 @@
   explicit StackMap(MemoryRegion region) : region_(region) {}
 
   uint32_t GetDexPc() const {
-    return region_.Load<uint32_t>(kDexPcOffset);
+    return region_.LoadUnaligned<uint32_t>(kDexPcOffset);
   }
 
   void SetDexPc(uint32_t dex_pc) {
-    region_.Store<uint32_t>(kDexPcOffset, dex_pc);
+    region_.StoreUnaligned<uint32_t>(kDexPcOffset, dex_pc);
   }
 
   uint32_t GetNativePcOffset() const {
-    return region_.Load<uint32_t>(kNativePcOffsetOffset);
+    return region_.LoadUnaligned<uint32_t>(kNativePcOffsetOffset);
   }
 
   void SetNativePcOffset(uint32_t native_pc_offset) {
-    region_.Store<uint32_t>(kNativePcOffsetOffset, native_pc_offset);
+    region_.StoreUnaligned<uint32_t>(kNativePcOffsetOffset, native_pc_offset);
   }
 
   uint32_t GetDexRegisterMapOffset() const {
-    return region_.Load<uint32_t>(kDexRegisterMapOffsetOffset);
+    return region_.LoadUnaligned<uint32_t>(kDexRegisterMapOffsetOffset);
   }
 
   void SetDexRegisterMapOffset(uint32_t offset) {
-    region_.Store<uint32_t>(kDexRegisterMapOffsetOffset, offset);
+    region_.StoreUnaligned<uint32_t>(kDexRegisterMapOffsetOffset, offset);
   }
 
   uint32_t GetInlineDescriptorOffset() const {
-    return region_.Load<uint32_t>(kInlineDescriptorOffsetOffset);
+    return region_.LoadUnaligned<uint32_t>(kInlineDescriptorOffsetOffset);
   }
 
   void SetInlineDescriptorOffset(uint32_t offset) {
-    region_.Store<uint32_t>(kInlineDescriptorOffsetOffset, offset);
+    region_.StoreUnaligned<uint32_t>(kInlineDescriptorOffsetOffset, offset);
   }
 
   uint32_t GetRegisterMask() const {
-    return region_.Load<uint32_t>(kRegisterMaskOffset);
+    return region_.LoadUnaligned<uint32_t>(kRegisterMaskOffset);
   }
 
   void SetRegisterMask(uint32_t mask) {
-    region_.Store<uint32_t>(kRegisterMaskOffset, mask);
+    region_.StoreUnaligned<uint32_t>(kRegisterMaskOffset, mask);
   }
 
   MemoryRegion GetStackMask() const {
@@ -529,9 +529,8 @@
        && region_.size() == other.region_.size();
   }
 
-  static size_t ComputeAlignedStackMapSize(size_t stack_mask_size) {
-    // On ARM, the stack maps must be 4-byte aligned.
-    return RoundUp(StackMap::kFixedSize + stack_mask_size, kWordAlignment);
+  static size_t ComputeStackMapSize(size_t stack_mask_size) {
+    return StackMap::kFixedSize + stack_mask_size;
   }
 
   // Special (invalid) offset for the DexRegisterMapOffset field meaning
@@ -609,7 +608,7 @@
   // Get the size of one stack map of this CodeInfo object, in bytes.
   // All stack maps of a CodeInfo have the same size.
   size_t StackMapSize() const {
-    return StackMap::ComputeAlignedStackMapSize(GetStackMaskSize());
+    return StackMap::ComputeStackMapSize(GetStackMaskSize());
   }
 
   // Get the size all the stack maps of this CodeInfo object, in bytes.