Reviewers: Hannes Payer,

Message:
Hi Hannes, here is the issue with splay pause times we diagnosed Monday. After
landing pretenure call new support, I'd like to revisit and just always
pretenure boilerplates (if possible), then this change can be removed.
PTAL, thanks,
--Michael

Description:
Pretenure code generation corner case with new space COW arrays.

When advised to pretenure in crankshaft, and the boilerplate is a cow
array, move the elements to old space if it's not already there to avoid
overflowing the store buffer.

[email protected]

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+46, -0 lines):
  M src/factory.h
  M src/factory.cc
  M src/heap.h
  M src/heap.cc
  M src/hydrogen.cc


Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 60727d952abc8382b1f6a4a77f5e433b28a46489..b06d3c8c49e4b6ef751082b9448eaa02f38220a9 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -887,6 +887,14 @@ Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) {
 }


+Handle<FixedArray> Factory::CopyAndTenureFixedCOWArray(
+    Handle<FixedArray> array) {
+  CALL_HEAP_FUNCTION(isolate(),
+                     isolate()->heap()->CopyAndTenureFixedCOWArray(*array),
+                     FixedArray);
+}
+
+
 Handle<FixedArray> Factory::CopySizeFixedArray(Handle<FixedArray> array,
                                                int new_length,
                                                PretenureFlag pretenure) {
Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index 86c26044c0b78451ec5527d19a6e3c9a03a4619b..7fed9e8837bb60796a69499facdf30ae4b4d63ba 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -289,6 +289,10 @@ class Factory {

   Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);

+  // This method expects a COW array in new space, and creates a copy
+  // of it in old space.
+  Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
+
   Handle<FixedArray> CopySizeFixedArray(Handle<FixedArray> array,
                                         int new_length,
PretenureFlag pretenure = NOT_TENURED);
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index 4e0e8a67c2217213c0c0a28939d8d147f01fec47..336608daf116c116c1f66dff6264f0671faf91ab 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -5038,6 +5038,27 @@ MaybeObject* Heap::AllocateEmptyExternalArray(ExternalArrayType array_type) {
 }


+MaybeObject* Heap::CopyAndTenureFixedCOWArray(FixedArray* src) {
+  ASSERT(InNewSpace(src));
+  int len = src->length();
+  Object* obj;
+  { MaybeObject* maybe_obj = AllocateRawFixedArray(len, TENURED);
+    if (!maybe_obj->ToObject(&obj)) return maybe_obj;
+  }
+  HeapObject::cast(obj)->set_map_no_write_barrier(fixed_array_map());
+  FixedArray* result = FixedArray::cast(obj);
+  result->set_length(len);
+
+  // Copy the content
+  DisallowHeapAllocation no_gc;
+  WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
+  for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
+
+  HeapObject::cast(obj)->set_map_no_write_barrier(fixed_cow_array_map());
+  return result;
+}
+
+
 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
   int len = src->length();
   Object* obj;
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index f99bb51617e1cf8145802cc81fe70a19326cbdc9..73c990a8988148dc98ed7d27e57de9eab79b1727 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -979,6 +979,10 @@ class Heap {
// Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
   MUST_USE_RESULT inline MaybeObject* CopyFixedArray(FixedArray* src);

+  // Make a copy of src and return it. Returns
+ // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
+  MUST_USE_RESULT MaybeObject* CopyAndTenureFixedCOWArray(FixedArray* src);
+
   // Make a copy of src, set the map, and return the copy. Returns
// Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. MUST_USE_RESULT MaybeObject* CopyFixedArrayWithMap(FixedArray* src, Map* map);
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 5324ef39cb320f0662ffbefec360cf87a4bf93f8..de5dae1759416c94cfe4972bd0e966c43fb3b7e1 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -9774,6 +9774,15 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
       elements->map() != isolate()->heap()->fixed_cow_array_map()) ?
           elements->Size() : 0;

+  if (pretenure_flag == TENURED &&
+      elements->map() == isolate()->heap()->fixed_cow_array_map() &&
+      isolate()->heap()->InNewSpace(*elements)) {
+    elements = Handle<FixedArrayBase>(
+        isolate()->factory()->CopyAndTenureFixedCOWArray(
+            Handle<FixedArray>::cast(elements)));
+    boilerplate_object->set_elements(*elements);
+  }
+
   HInstruction* object_elements = NULL;
   if (elements_size > 0) {
     HValue* object_elements_size = Add<HConstant>(elements_size);


--
--
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