Reviewers: Hannes Payer,

Description:
Fully deprecate FixedArray::CopySize method.

[email protected]

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

Base URL: https://chromium.googlesource.com/v8/v8.git@local_issue-cr-513507

Affected files (+44, -55 lines):
  M src/api.cc
  M src/contexts.cc
  M src/factory.h
  M src/factory.cc
  M src/heap/heap.h
  M src/heap/heap.cc
  M src/isolate.cc
  M src/objects.h
  M src/objects.cc
  M src/runtime/runtime-debug.cc
  M src/transitions.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 586fd8613a5a4b9dcaa5b47bfa4d56e65d804c7b..ceadd4ed8b62776d355a0ea96f8efe2702cd444c 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -775,6 +775,7 @@ static i::Handle<i::FixedArray> EmbedderDataFor(Context* context,
                                                 bool can_grow,
                                                 const char* location) {
   i::Handle<i::Context> env = Utils::OpenHandle(context);
+  i::Isolate* isolate = env->GetIsolate();
   bool ok =
       Utils::ApiCheck(env->IsNativeContext(),
                       location,
@@ -787,7 +788,8 @@ static i::Handle<i::FixedArray> EmbedderDataFor(Context* context,
     return i::Handle<i::FixedArray>();
   }
   int new_size = i::Max(index, data->length() << 1) + 1;
-  data = i::FixedArray::CopySize(data, new_size);
+  int grow_by = new_size - data->length();
+  data = isolate->factory()->CopyFixedArrayAndGrow(data, grow_by);
   env->set_embedder_data(*data);
   return data;
 }
Index: src/contexts.cc
diff --git a/src/contexts.cc b/src/contexts.cc
index 8263269d117c2d06a6f8fd2947f31097ef942895..9f39aecd542ca24dbbad3bf7baf1109e853494ba 100644
--- a/src/contexts.cc
+++ b/src/contexts.cc
@@ -20,8 +20,11 @@ Handle<ScriptContextTable> ScriptContextTable::Extend(
   CHECK(used >= 0 && length > 0 && used < length);
   if (used + 1 == length) {
     CHECK(length < Smi::kMaxValue / 2);
-    result = Handle<ScriptContextTable>::cast(
-        FixedArray::CopySize(table, length * 2));
+    Isolate* isolate = table->GetIsolate();
+    Handle<FixedArray> copy =
+        isolate->factory()->CopyFixedArrayAndGrow(table, length);
+    copy->set_map(isolate->heap()->script_context_table_map());
+    result = Handle<ScriptContextTable>::cast(copy);
   } else {
     result = table;
   }
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index bc5d1e4e0ecbd424df06bcf248678116d5fcbfda..8944905d96190d991e4051306a471ae43cc17d91 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -979,9 +979,10 @@ Handle<FixedArray> Factory::CopyFixedArrayWithMap(Handle<FixedArray> array,


 Handle<FixedArray> Factory::CopyFixedArrayAndGrow(Handle<FixedArray> array,
-                                                  int grow_by) {
-  CALL_HEAP_FUNCTION(isolate(),
- isolate()->heap()->CopyFixedArrayAndGrow(*array, grow_by),
+                                                  int grow_by,
+ PretenureFlag pretenure) {
+  CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->CopyFixedArrayAndGrow(
+                                    *array, grow_by, pretenure),
                      FixedArray);
 }

Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index c52d6d31d94c2543881198c93e5de18ccfc1dca7..c71382a9de8d3f1042619d7105c3ef982af6f9ab 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -322,8 +322,9 @@ class Factory final {
   Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
                                            Handle<Map> map);

-  Handle<FixedArray> CopyFixedArrayAndGrow(Handle<FixedArray> array,
-                                           int grow_by);
+  Handle<FixedArray> CopyFixedArrayAndGrow(
+      Handle<FixedArray> array, int grow_by,
+      PretenureFlag pretenure = NOT_TENURED);

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

Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 03af4c4e59a935d6cba4ec7b96dc395ab9a9da93..00f636e6bd4cbdedd2fb78114e2d070d60328279 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -4445,12 +4445,14 @@ AllocationResult Heap::AllocateEmptyFixedTypedArray(
 }


-AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by) {
+AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by,
+                                             PretenureFlag pretenure) {
   int old_len = src->length();
   int new_len = old_len + grow_by;
+  DCHECK(new_len >= old_len);
   HeapObject* obj;
   {
- AllocationResult allocation = AllocateRawFixedArray(new_len, NOT_TENURED); + AllocationResult allocation = AllocateRawFixedArray(new_len, pretenure);
     if (!allocation.To(&obj)) return allocation;
   }
   obj->set_map_no_write_barrier(fixed_array_map());
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index 6d75879374cf72351a64d9da48716ccdcf27b39e..be659811623eba680f47f740f549ffaaf9abb81b 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -2024,7 +2024,7 @@ class Heap {

   // Make a copy of src, also grow the copy, and return the copy.
   MUST_USE_RESULT AllocationResult
-      CopyFixedArrayAndGrow(FixedArray* src, int grow_by);
+ CopyFixedArrayAndGrow(FixedArray* src, int grow_by, PretenureFlag pretenure);

   // Make a copy of src, set the map, and return the copy.
   MUST_USE_RESULT AllocationResult
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index f7916ed7fc5baecba2bdb5152b93991d21c4252a..ccbeadc79c920f01c170bba2503f5756d8497ad6 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -2643,7 +2643,7 @@ void Isolate::EnqueueMicrotask(Handle<Object> microtask) {
     queue = factory()->NewFixedArray(8);
     heap()->set_microtask_queue(*queue);
   } else if (num_tasks == queue->length()) {
-    queue = FixedArray::CopySize(queue, num_tasks * 2);
+    queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks);
     heap()->set_microtask_queue(*queue);
   }
   DCHECK(queue->get(num_tasks)->IsUndefined());
@@ -2744,7 +2744,7 @@ void Isolate::AddDetachedContext(Handle<Context> context) {
   Handle<WeakCell> cell = factory()->NewWeakCell(context);
   Handle<FixedArray> detached_contexts(heap()->detached_contexts());
   int length = detached_contexts->length();
-  detached_contexts = FixedArray::CopySize(detached_contexts, length + 2);
+ detached_contexts = factory()->CopyFixedArrayAndGrow(detached_contexts, 2);
   detached_contexts->set(length, Smi::FromInt(0));
   detached_contexts->set(length + 1, *cell);
   heap()->set_detached_contexts(*detached_contexts);
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index f4a637c008612f9faaf858d14d00855c3865576e..aea01dc8a93473b3eb09fcad2f069845e304a41b 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -2015,9 +2015,10 @@ void JSObject::MigrateFastToFast(Handle<JSObject> object, Handle<Map> new_map) {
     DCHECK(number_of_fields == old_number_of_fields + 1);
// This migration is a transition from a map that has run out of property
     // space. Therefore it could be done by extending the backing store.
+    int grow_by = external - object->properties()->length();
     Handle<FixedArray> old_storage = handle(object->properties(), isolate);
     Handle<FixedArray> new_storage =
-        FixedArray::CopySize(old_storage, external);
+        isolate->factory()->CopyFixedArrayAndGrow(old_storage, grow_by);

     // Properly initialize newly added property.
     Handle<Object> value;
@@ -7496,10 +7497,11 @@ void CodeCache::UpdateDefaultCache(

   // Extend the code cache with some new entries (at least one). Must be a
   // multiple of the entry size.
-  int new_length = length + ((length >> 1)) + kCodeCacheEntrySize;
+  Isolate* isolate = cache->GetIsolate();
+  int new_length = length + (length >> 1) + kCodeCacheEntrySize;
   new_length = new_length - new_length % kCodeCacheEntrySize;
   DCHECK((new_length % kCodeCacheEntrySize) == 0);
-  cache = FixedArray::CopySize(cache, new_length);
+ cache = isolate->factory()->CopyFixedArrayAndGrow(cache, new_length - length);

   // Add the (name, code) pair to the new cache.
   cache->set(length + kCodeCacheEntryNameOffset, *name);
@@ -7892,27 +7894,6 @@ MaybeHandle<FixedArray> FixedArray::UnionOfKeys(Handle<FixedArray> first,
 }


-Handle<FixedArray> FixedArray::CopySize(
-    Handle<FixedArray> array, int new_length, PretenureFlag pretenure) {
-  Isolate* isolate = array->GetIsolate();
-  if (new_length == 0) return isolate->factory()->empty_fixed_array();
-  Handle<FixedArray> result =
-      isolate->factory()->NewFixedArray(new_length, pretenure);
-  // Copy the content
-  DisallowHeapAllocation no_gc;
-  int len = array->length();
-  if (new_length < len) len = new_length;
-  // We are taking the map from the old fixed array so the map is sure to
-  // be an immortal immutable object.
-  result->set_map_no_write_barrier(array->map());
-  WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
-  for (int i = 0; i < len; i++) {
-    result->set(i, array->get(i), mode);
-  }
-  return result;
-}
-
-
 void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) {
   DisallowHeapAllocation no_gc;
   WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc);
@@ -8097,9 +8078,12 @@ Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) {
   int capacity = array->length();
   bool empty = (capacity == 0);
   if (capacity < kFirstIndex + length) {
-    capacity = kFirstIndex + length;
-    capacity = capacity + Max(capacity / 2, 2);
-    array = Handle<ArrayList>::cast(FixedArray::CopySize(array, capacity));
+    Isolate* isolate = array->GetIsolate();
+    int new_capacity = kFirstIndex + length;
+    new_capacity = new_capacity + Max(new_capacity / 2, 2);
+    int grow_by = new_capacity - capacity;
+    array = Handle<ArrayList>::cast(
+        isolate->factory()->CopyFixedArrayAndGrow(array, grow_by));
     if (empty) array->SetLength(0);
   }
   return array;
@@ -11929,9 +11913,10 @@ Handle<DependentCode> DependentCode::Insert(Handle<DependentCode> entries,

 Handle<DependentCode> DependentCode::EnsureSpace(
     Handle<DependentCode> entries) {
+  Isolate* isolate = entries->GetIsolate();
   if (entries->length() == 0) {
     entries = Handle<DependentCode>::cast(
-        FixedArray::CopySize(entries, kCodesStartIndex + 1, TENURED));
+        isolate->factory()->NewFixedArray(kCodesStartIndex + 1, TENURED));
     for (int g = 0; g < kGroupCount; g++) {
       entries->set_number_of_entries(static_cast<DependencyGroup>(g), 0);
     }
@@ -11941,8 +11926,9 @@ Handle<DependentCode> DependentCode::EnsureSpace(
   GroupStartIndexes starts(*entries);
   int capacity =
       kCodesStartIndex + DependentCode::Grow(starts.number_of_entries());
+  int grow_by = capacity - entries->length();
   return Handle<DependentCode>::cast(
-      FixedArray::CopySize(entries, capacity, TENURED));
+ isolate->factory()->CopyFixedArrayAndGrow(entries, grow_by, TENURED));
 }


Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index fb97f2804a732edf438b903c65332f48c869ef42..f8861797784c664a037920c6b6df552b9c16dc39 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -2398,12 +2398,6 @@ class FixedArray: public FixedArrayBase {
   // Shrink length and insert filler objects.
   void Shrink(int length);

-  // Copy operation.
-  // TODO(mstarzinger): Deprecated, use Factory::CopyFixedArrayAndGrow!
-  static Handle<FixedArray> CopySize(Handle<FixedArray> array,
-                                     int new_length,
- PretenureFlag pretenure = NOT_TENURED);
-
   enum KeyFilter { ALL_KEYS, NON_SYMBOL_KEYS };

   // Add the elements of a JSArray to this FixedArray.
Index: src/runtime/runtime-debug.cc
diff --git a/src/runtime/runtime-debug.cc b/src/runtime/runtime-debug.cc
index c3862f08d927e8dbf6d51bb5b0141b60b09bd8fa..33e1de8c8592f3d2487344be4c9e829457482a00 100644
--- a/src/runtime/runtime-debug.cc
+++ b/src/runtime/runtime-debug.cc
@@ -2486,9 +2486,8 @@ class EvaluationContextBuilder {
         RecordContextsInChain(&inner_context, with_context, with_context);
       } else if (scope_type == ScopeIterator::ScopeTypeCatch ||
                  scope_type == ScopeIterator::ScopeTypeWith) {
-        Handle<Context> cloned_context =
-            Handle<Context>::cast(FixedArray::CopySize(
-                it.CurrentContext(), it.CurrentContext()->length()));
+        Handle<Context> cloned_context = Handle<Context>::cast(
+            isolate->factory()->CopyFixedArray(it.CurrentContext()));

         ContextChainElement context_chain_element;
         context_chain_element.original_context = it.CurrentContext();
@@ -2503,9 +2502,8 @@ class EvaluationContextBuilder {
                                                  it.CurrentScopeInfo(),
                                                  &frame_inspector);
         if (it.HasContext()) {
-          Handle<Context> cloned_context =
-              Handle<Context>::cast(FixedArray::CopySize(
-                  it.CurrentContext(), it.CurrentContext()->length()));
+          Handle<Context> cloned_context = Handle<Context>::cast(
+              isolate->factory()->CopyFixedArray(it.CurrentContext()));
Handle<Context> with_context = isolate->factory()->NewWithContext(
               function, cloned_context, materialized_object);

Index: src/transitions.cc
diff --git a/src/transitions.cc b/src/transitions.cc
index f00f33146792df503ffe9cd333bb0206e87c97b2..9870e17d83925040e952876c4263cc662f09be78 100644
--- a/src/transitions.cc
+++ b/src/transitions.cc
@@ -255,8 +255,10 @@ void TransitionArray::PutPrototypeTransition(Handle<Map> map,
     // Grow array by factor 2 up to MaxCachedPrototypeTransitions.
int new_capacity = Min(kMaxCachedPrototypeTransitions, transitions * 2);
     if (new_capacity == capacity) return;
+    int grow_by = new_capacity - capacity;

-    cache = FixedArray::CopySize(cache, header + new_capacity);
+    Isolate* isolate = map->GetIsolate();
+    cache = isolate->factory()->CopyFixedArrayAndGrow(cache, grow_by);
     if (capacity < 0) {
       // There was no prototype transitions array before, so the size
       // couldn't be copied. Initialize it explicitly.


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