Revert "Enable alignment checks when reading object fields"

This reverts commit 5ce68669bebc50e1c1c5a3429b34f9df04dfbdcd.

Reason for revert: Fails on win32 debug: https://ci.chromium.org/p/v8/builders/ci/V8%20Win32%20-%20debug/20394

Original change's description:
> Enable alignment checks when reading object fields
> 
> Drive-by: Fix alignment bugs caused by DCHECKS.
> 
> Bug: v8:9264
> 
> Change-Id: I0836b1d08fea2ce11d8f7929e12f303b6ae06efe
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1617676
> Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#61643}

TBR=ulan@chromium.org,jkummerow@chromium.org,sigurds@chromium.org,petermarshall@chromium.org,ishell@chromium.org

Change-Id: I0ac73a880f2b7bd718e23e90c0867192def39dbb
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:9264
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1619750
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61651}
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 41ad575..c2e00bd 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -5690,7 +5690,7 @@
   }
 }
 
-bool Heap::AllowedToBeMigrated(Map map, HeapObject obj, AllocationSpace dst) {
+bool Heap::AllowedToBeMigrated(HeapObject obj, AllocationSpace dst) {
   // Object migration is governed by the following rules:
   //
   // 1) Objects in new-space can be migrated to the old space
@@ -5703,8 +5703,8 @@
   //
   // Since this function is used for debugging only, we do not place
   // asserts here, but check everything explicitly.
-  if (map == ReadOnlyRoots(this).one_pointer_filler_map()) return false;
-  InstanceType type = map->instance_type();
+  if (obj->map() == ReadOnlyRoots(this).one_pointer_filler_map()) return false;
+  InstanceType type = obj->map()->instance_type();
   MemoryChunk* chunk = MemoryChunk::FromHeapObject(obj);
   AllocationSpace src = chunk->owner()->identity();
   switch (src) {
diff --git a/src/heap/heap.h b/src/heap/heap.h
index c2d12f7..1aad0a3 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -464,7 +464,7 @@
 
   // Checks whether the given object is allowed to be migrated from it's
   // current space into the given destination space. Used for debugging.
-  bool AllowedToBeMigrated(Map map, HeapObject object, AllocationSpace dest);
+  bool AllowedToBeMigrated(HeapObject object, AllocationSpace dest);
 
   void CheckHandleCount();
 
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index df723c0..da112e2 100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -1231,7 +1231,7 @@
                                HeapObject src, int size, AllocationSpace dest) {
     Address dst_addr = dst->address();
     Address src_addr = src->address();
-    DCHECK(base->heap_->AllowedToBeMigrated(src->map(), src, dest));
+    DCHECK(base->heap_->AllowedToBeMigrated(src, dest));
     DCHECK_NE(dest, LO_SPACE);
     DCHECK_NE(dest, CODE_LO_SPACE);
     if (dest == OLD_SPACE) {
diff --git a/src/heap/scavenger-inl.h b/src/heap/scavenger-inl.h
index e577a47..4736519 100644
--- a/src/heap/scavenger-inl.h
+++ b/src/heap/scavenger-inl.h
@@ -135,7 +135,7 @@
   static_assert(std::is_same<THeapObjectSlot, FullHeapObjectSlot>::value ||
                     std::is_same<THeapObjectSlot, HeapObjectSlot>::value,
                 "Only FullHeapObjectSlot and HeapObjectSlot are expected here");
-  DCHECK(heap()->AllowedToBeMigrated(map, object, NEW_SPACE));
+  DCHECK(heap()->AllowedToBeMigrated(object, NEW_SPACE));
   AllocationAlignment alignment = HeapObject::RequiredAlignment(map);
   AllocationResult allocation =
       allocator_.Allocate(NEW_SPACE, object_size, alignment);
diff --git a/src/heap/scavenger.cc b/src/heap/scavenger.cc
index ad56d1c..87479ee 100644
--- a/src/heap/scavenger.cc
+++ b/src/heap/scavenger.cc
@@ -463,6 +463,7 @@
     struct PromotionListEntry entry;
     while (promotion_list_.Pop(&entry)) {
       HeapObject target = entry.heap_object;
+      DCHECK(!target->IsMap());
       IterateAndScavengePromotedObject(target, entry.map, entry.size);
       done = false;
       if (have_barrier && ((++objects % kInterruptThreshold) == 0)) {
diff --git a/src/objects/fixed-array-inl.h b/src/objects/fixed-array-inl.h
index 281a90c..bbb1e03 100644
--- a/src/objects/fixed-array-inl.h
+++ b/src/objects/fixed-array-inl.h
@@ -66,11 +66,8 @@
 SYNCHRONIZED_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
 
 int FixedArrayBase::length() const {
-#ifdef DEBUG
-  DCHECK(map_word().IsForwardingAddress() ||
-         !IsInRange(map()->instance_type(), FIRST_FIXED_TYPED_ARRAY_TYPE,
+  DCHECK(!IsInRange(map()->instance_type(), FIRST_FIXED_TYPED_ARRAY_TYPE,
                     LAST_FIXED_TYPED_ARRAY_TYPE));
-#endif
   Object value = READ_FIELD(*this, kLengthOffset);
   return Smi::ToInt(value);
 }
diff --git a/src/objects/object-macros.h b/src/objects/object-macros.h
index 52c0918..a06dbd8 100644
--- a/src/objects/object-macros.h
+++ b/src/objects/object-macros.h
@@ -336,14 +336,13 @@
     }                                                                        \
   } while (false)
 
-// BUG(v8:8875): Double fields may be unaligned.
-#define READ_DOUBLE_FIELD(p, offset) \
-  ReadUnalignedValue<double>(FIELD_ADDR(p, offset))
+#define READ_DOUBLE_FIELD(p, offset) ReadDoubleValue(FIELD_ADDR(p, offset))
 
 #define WRITE_DOUBLE_FIELD(p, offset, value) \
-  WriteUnalignedValue<double>(FIELD_ADDR(p, offset), value)
+  WriteDoubleValue(FIELD_ADDR(p, offset), value)
 
-#define READ_INT_FIELD(p, offset) (Memory<const int>(FIELD_ADDR(p, offset)))
+#define READ_INT_FIELD(p, offset) \
+  (*reinterpret_cast<const int*>(FIELD_ADDR(p, offset)))
 
 #define WRITE_INT_FIELD(p, offset, value) \
   (*reinterpret_cast<int*>(FIELD_ADDR(p, offset)) = value)
@@ -353,7 +352,7 @@
       reinterpret_cast<const base::Atomic32*>(FIELD_ADDR(p, offset))))
 
 #define READ_UINT8_FIELD(p, offset) \
-  (Memory<const uint8_t>(FIELD_ADDR(p, offset)))
+  (*reinterpret_cast<const uint8_t*>(FIELD_ADDR(p, offset)))
 
 #define WRITE_UINT8_FIELD(p, offset, value) \
   (*reinterpret_cast<uint8_t*>(FIELD_ADDR(p, offset)) = value)
@@ -362,7 +361,8 @@
   base::Relaxed_Store(reinterpret_cast<base::Atomic8*>(FIELD_ADDR(p, offset)), \
                       static_cast<base::Atomic8>(value));
 
-#define READ_INT8_FIELD(p, offset) (Memory<const int8_t>(FIELD_ADDR(p, offset)))
+#define READ_INT8_FIELD(p, offset) \
+  (*reinterpret_cast<const int8_t*>(FIELD_ADDR(p, offset)))
 
 #define RELAXED_READ_INT8_FIELD(p, offset) \
   static_cast<int8_t>(base::Relaxed_Load(  \
@@ -372,13 +372,13 @@
   (*reinterpret_cast<int8_t*>(FIELD_ADDR(p, offset)) = value)
 
 #define READ_UINT16_FIELD(p, offset) \
-  (Memory<const uint16_t>(FIELD_ADDR(p, offset)))
+  (*reinterpret_cast<const uint16_t*>(FIELD_ADDR(p, offset)))
 
 #define WRITE_UINT16_FIELD(p, offset, value) \
   (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value)
 
 #define READ_INT16_FIELD(p, offset) \
-  (Memory<const int16_t>(FIELD_ADDR(p, offset)))
+  (*reinterpret_cast<const int16_t*>(FIELD_ADDR(p, offset)))
 
 #define WRITE_INT16_FIELD(p, offset, value) \
   (*reinterpret_cast<int16_t*>(FIELD_ADDR(p, offset)) = value)
@@ -392,7 +392,8 @@
       reinterpret_cast<base::Atomic16*>(FIELD_ADDR(p, offset)), \
       static_cast<base::Atomic16>(value));
 
-#define READ_UINT32_FIELD(p, offset) (Memory<uint32_t>(FIELD_ADDR(p, offset)))
+#define READ_UINT32_FIELD(p, offset) \
+  (*reinterpret_cast<const uint32_t*>(FIELD_ADDR(p, offset)))
 
 #define RELAXED_READ_UINT32_FIELD(p, offset) \
   static_cast<uint32_t>(base::Relaxed_Load(  \
@@ -406,7 +407,8 @@
       reinterpret_cast<base::Atomic32*>(FIELD_ADDR(p, offset)), \
       static_cast<base::Atomic32>(value));
 
-#define READ_INT32_FIELD(p, offset) (Memory<int32_t>(FIELD_ADDR(p, offset)))
+#define READ_INT32_FIELD(p, offset) \
+  (*reinterpret_cast<const int32_t*>(FIELD_ADDR(p, offset)))
 
 #define RELAXED_READ_INT32_FIELD(p, offset) \
   static_cast<int32_t>(base::Relaxed_Load(  \
@@ -425,7 +427,8 @@
       reinterpret_cast<base::Atomic32*>(FIELD_ADDR(p, offset)), \
       static_cast<base::Atomic32>(value));
 
-#define READ_FLOAT_FIELD(p, offset) (Memory<const float>(FIELD_ADDR(p, offset)))
+#define READ_FLOAT_FIELD(p, offset) \
+  (*reinterpret_cast<const float*>(FIELD_ADDR(p, offset)))
 
 #define WRITE_FLOAT_FIELD(p, offset, value) \
   (*reinterpret_cast<float*>(FIELD_ADDR(p, offset)) = value)
@@ -456,24 +459,28 @@
 
 #else  // V8_COMPRESS_POINTERS
 
-#define READ_INTPTR_FIELD(p, offset) (Memory<intptr_t>(FIELD_ADDR(p, offset)))
+#define READ_INTPTR_FIELD(p, offset) \
+  (*reinterpret_cast<const intptr_t*>(FIELD_ADDR(p, offset)))
 
 #define WRITE_INTPTR_FIELD(p, offset, value) \
   (*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset)) = value)
 
-#define READ_UINTPTR_FIELD(p, offset) (Memory<uintptr_t>(FIELD_ADDR(p, offset)))
+#define READ_UINTPTR_FIELD(p, offset) \
+  (*reinterpret_cast<const uintptr_t*>(FIELD_ADDR(p, offset)))
 
 #define WRITE_UINTPTR_FIELD(p, offset, value) \
   (*reinterpret_cast<uintptr_t*>(FIELD_ADDR(p, offset)) = value)
 
-#define READ_UINT64_FIELD(p, offset) (Memory<uint64_t>(FIELD_ADDR(p, offset)))
+#define READ_UINT64_FIELD(p, offset) \
+  (*reinterpret_cast<const uint64_t*>(FIELD_ADDR(p, offset)))
 
 #define WRITE_UINT64_FIELD(p, offset, value) \
   (*reinterpret_cast<uint64_t*>(FIELD_ADDR(p, offset)) = value)
 
 #endif  // V8_COMPRESS_POINTERS
 
-#define READ_BYTE_FIELD(p, offset) (Memory<byte>(FIELD_ADDR(p, offset)))
+#define READ_BYTE_FIELD(p, offset) \
+  (*reinterpret_cast<const byte*>(FIELD_ADDR(p, offset)))
 
 #define RELAXED_READ_BYTE_FIELD(p, offset) \
   static_cast<byte>(base::Relaxed_Load(    \
diff --git a/src/v8memory.h b/src/v8memory.h
index fbbe0d4..e927962 100644
--- a/src/v8memory.h
+++ b/src/v8memory.h
@@ -5,7 +5,6 @@
 #ifndef V8_V8MEMORY_H_
 #define V8_V8MEMORY_H_
 
-#include "src/base/macros.h"
 #include "src/globals.h"
 
 namespace v8 {
@@ -16,12 +15,13 @@
 // Note that this class currently relies on undefined behaviour. There is a
 // proposal (http://wg21.link/p0593r2) to make it defined behaviour though.
 template <class T>
-inline T& Memory(Address addr) {
-  DCHECK(IsAligned(addr, alignof(T)));
+T& Memory(Address addr) {
+  // {addr} must be aligned.
+  DCHECK_EQ(0, addr & (alignof(T) - 1));
   return *reinterpret_cast<T*>(addr);
 }
 template <class T>
-inline T& Memory(byte* addr) {
+T& Memory(byte* addr) {
   return Memory<T>(reinterpret_cast<Address>(addr));
 }
 
@@ -39,6 +39,18 @@
   memcpy(reinterpret_cast<void*>(p), &value, sizeof(V));
 }
 
+static inline double ReadFloatValue(Address p) {
+  return ReadUnalignedValue<float>(p);
+}
+
+static inline double ReadDoubleValue(Address p) {
+  return ReadUnalignedValue<double>(p);
+}
+
+static inline void WriteDoubleValue(Address p, double value) {
+  WriteUnalignedValue(p, value);
+}
+
 static inline uint16_t ReadUnalignedUInt16(Address p) {
   return ReadUnalignedValue<uint16_t>(p);
 }