Ensure MemoryRegion::Load & MemoryRegion::Store are word-aligned.

Change-Id: Ib19fb93abec4789a111dfd48fcac6065e2d3ec82
diff --git a/runtime/memory_region.h b/runtime/memory_region.h
index f867f6a..3dcb0dd 100644
--- a/runtime/memory_region.h
+++ b/runtime/memory_region.h
@@ -48,17 +48,20 @@
   uint8_t* end() const { return start() + size_; }
 
   // Load value of type `T` at `offset`.  The memory address corresponding
-  // to `offset` should be word-aligned.
+  // to `offset` should be word-aligned (on ARM, this is a requirement).
   template<typename T> T Load(uintptr_t offset) const {
-    // TODO: DCHECK that the address is word-aligned.
-    return *ComputeInternalPointer<T>(offset);
+    T* address = ComputeInternalPointer<T>(offset);
+    DCHECK(IsWordAligned(address));
+    return *address;
   }
 
   // Store `value` (of type `T`) at `offset`.  The memory address
-  // corresponding to `offset` should be word-aligned.
+  // corresponding to `offset` should be word-aligned (on ARM, this is
+  // a requirement).
   template<typename T> void Store(uintptr_t offset, T value) const {
-    // TODO: DCHECK that the address is word-aligned.
-    *ComputeInternalPointer<T>(offset) = value;
+    T* address = ComputeInternalPointer<T>(offset);
+    DCHECK(IsWordAligned(address));
+    *address = value;
   }
 
   // Load value of type `T` at `offset`.  The memory address corresponding
@@ -141,6 +144,13 @@
     return ComputeInternalPointer<uint8_t>(byte_offset);
   }
 
+  // Is `address` aligned on a machine word?
+  template<typename T> static bool IsWordAligned(const T* address) {
+    // Word alignment in bytes.
+    size_t kWordAlignment = GetInstructionSetPointerSize(kRuntimeISA);
+    return IsAlignedParam(address, kWordAlignment);
+  }
+
   void* pointer_;
   size_t size_;
 };
diff --git a/runtime/stack_map.h b/runtime/stack_map.h
index 6ec7cc8..2c6240a 100644
--- a/runtime/stack_map.h
+++ b/runtime/stack_map.h
@@ -28,9 +28,6 @@
 // (signed) values.
 static ssize_t constexpr kFrameSlotSize = 4;
 
-// Word alignment required on ARM, in bytes.
-static constexpr size_t kWordAlignment = 4;
-
 // Size of Dex virtual registers.
 static size_t constexpr kVRegSize = 4;