Reviewers: Benedikt Meurer, Hannes Payer,

Message:
This is the first part of fixing the GC's handling of alignment. The next CL
will fix the templated scavenging collector functions.

Description:
Generalize HeapObject alignment requirements.
Removes EnsureDouble* methods.
Adds a RequiredAlignment method.
Changes call sites.

LOG=N
BUG=v8:4124

Please review this at https://codereview.chromium.org/1150953002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+15, -28 lines):
  M src/heap/mark-compact.cc
  M src/objects.h
  M src/objects-debug.cc
  M src/objects-inl.h
  M src/snapshot/serialize.cc


Index: src/heap/mark-compact.cc
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index b4159f2e60f52194bf8b2e883fe09e83671f239d..18bb1ccc4405110d64e9ff14676c75e6d6afce65 100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -1941,9 +1941,7 @@ int MarkCompactCollector::DiscoverAndEvacuateBlackObjectsOnPage(
         continue;
       }

- AllocationAlignment alignment = object->NeedsToEnsureDoubleAlignment()
-                                          ? kDoubleAligned
-                                          : kWordAligned;
+      AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = new_space->AllocateRaw(size, alignment);
       if (allocation.IsRetry()) {
         if (!new_space->AddFreshPage()) {
@@ -3105,8 +3103,7 @@ bool MarkCompactCollector::TryPromoteObject(HeapObject* object,
   OldSpace* old_space = heap()->old_space();

   HeapObject* target;
-  AllocationAlignment alignment =
- object->NeedsToEnsureDoubleAlignment() ? kDoubleAligned : kWordAligned;
+  AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = old_space->AllocateRaw(object_size, alignment);
   if (allocation.To(&target)) {
     MigrateObject(target, object, object_size, old_space->identity());
@@ -3330,10 +3327,7 @@ void MarkCompactCollector::EvacuateLiveObjectsFromPage(Page* p) {
       DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object)));

       int size = object->Size();
-
- AllocationAlignment alignment = object->NeedsToEnsureDoubleAlignment()
-                                          ? kDoubleAligned
-                                          : kWordAligned;
+      AllocationAlignment alignment = object->RequiredAlignment();
       HeapObject* target_object;
       AllocationResult allocation = space->AllocateRaw(size, alignment);
       if (!allocation.To(&target_object)) {
Index: src/objects-debug.cc
diff --git a/src/objects-debug.cc b/src/objects-debug.cc
index a4c58244ef417818a754bd998ac4919c7b6ce74e..98b0aa5e65ae184ed11fd2701b2b4a21f9df7a04 100644
--- a/src/objects-debug.cc
+++ b/src/objects-debug.cc
@@ -48,7 +48,7 @@ void HeapObject::HeapObjectVerify() {
   }

   // TODO(yangguo): Use this check once crbug/436911 has been fixed.
-  //  DCHECK(!NeedsToEnsureDoubleAlignment() ||
+  //  DCHECK(RequiredAlignment() != kDoubleAlignment ||
   //         IsAligned(OffsetFrom(address()), kDoubleAlignment));

   switch (instance_type) {
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 50d02f9f655e887b10cf5dc4e290d0a343cd7480..b76b2c9764241a50a2bd19400b5d304e1bb60e15 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -2829,23 +2829,16 @@ WriteBarrierMode HeapObject::GetWriteBarrierMode(
 }


-bool HeapObject::NeedsToEnsureDoubleAlignment() {
+AllocationAlignment HeapObject::RequiredAlignment() {
 #ifdef V8_HOST_ARCH_32_BIT
-  return (IsFixedFloat64Array() || IsFixedDoubleArray() ||
-          IsConstantPoolArray()) &&
-         FixedArrayBase::cast(this)->length() != 0;
-#else
-  return false;
-#endif  // V8_HOST_ARCH_32_BIT
-}
-
-
-bool HeapObject::NeedsToEnsureDoubleUnalignment() {
-#ifdef V8_HOST_ARCH_32_BIT
-  return IsHeapNumber();
-#else
-  return false;
+  if ((IsFixedFloat64Array() || IsFixedDoubleArray() ||
+       IsConstantPoolArray()) &&
+      FixedArrayBase::cast(this)->length() != 0) {
+    return kDoubleAligned;
+  }
+  if (IsHeapNumber()) return kDoubleUnaligned;
 #endif  // V8_HOST_ARCH_32_BIT
+  return kWordAligned;
 }


Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 4b7341ece9f02d2e7f1aa0886c2a67cfc47f1f1c..4affb924575eeb3409936d5f7c577bed1e6ad48e 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -1486,8 +1486,7 @@ class HeapObject: public Object {
   static void VerifyHeapPointer(Object* p);
 #endif

-  inline bool NeedsToEnsureDoubleAlignment();
-  inline bool NeedsToEnsureDoubleUnalignment();
+  inline AllocationAlignment RequiredAlignment();

   // Layout description.
   // First field in a heap object is map.
Index: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index b311f9dcda065c2c3b1f8dad3bfafe383e7f2a92..eaebd68e5d78970e888ac75867fa555f98137158 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -1729,7 +1729,8 @@ void Serializer::ObjectSerializer::SerializePrologue(AllocationSpace space,
     back_reference = serializer_->AllocateLargeObject(size);
   } else {
     bool needs_double_align = false;
-    if (object_->NeedsToEnsureDoubleAlignment()) {
+    // TODO(bbudge) Generalize to other alignment constraints.
+    if (object_->RequiredAlignment() == kDoubleAligned) {
       // Add wriggle room for double alignment padding.
       back_reference = serializer_->Allocate(space, size + kPointerSize);
       needs_double_align = true;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to