Reviewers: Toon Verwaest,

Message:
PTAL

Description:
Callers of ElementsAccessor::SetCapacityAndLength() handlified.

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

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

Affected files (+40, -46 lines):
  M src/ast.cc
  M src/elements.h
  M src/elements.cc
  M src/factory.h
  M src/factory.cc
  M src/json-stringifier.h
  M src/jsregexp.cc
  M src/objects-inl.h
  M src/objects.h
  M src/objects.cc


Index: src/ast.cc
diff --git a/src/ast.cc b/src/ast.cc
index 086d0153623dd4b33c3749f424f4dfdc46c7b56d..f6cf18915b0932395e43d76188f98426acf37f8c 100644
--- a/src/ast.cc
+++ b/src/ast.cc
@@ -357,8 +357,7 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
   // Allocate a fixed array to hold all the object literals.
   Handle<JSArray> array =
       isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS);
-  isolate->factory()->SetElementsCapacityAndLength(
-      array, values()->length(), values()->length());
+  JSArray::Expand(array, values()->length());

   // Fill in the literals.
   bool is_simple = true;
Index: src/elements.cc
diff --git a/src/elements.cc b/src/elements.cc
index 527df6e3d753cf9386839413d78dc5f9a610447b..c52ba0e047343c496e5fb15176ead8c2493a06e7 100644
--- a/src/elements.cc
+++ b/src/elements.cc
@@ -766,14 +766,16 @@ class ElementsAccessorBase : public ElementsAccessor {
       Handle<Object> length,
       Handle<FixedArrayBase> backing_store);

-  MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(
-      JSArray* array,
+  virtual void SetCapacityAndLength(
+      Handle<JSArray> array,
       int capacity,
       int length) V8_FINAL V8_OVERRIDE {
-    return ElementsAccessorSubclass::SetFastElementsCapacityAndLength(
-        array,
-        capacity,
-        length);
+    CALL_HEAP_FUNCTION_VOID(
+        array->GetIsolate(),
+        ElementsAccessorSubclass::SetFastElementsCapacityAndLength(
+            *array,
+            capacity,
+            length));
   }

   MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength(
Index: src/elements.h
diff --git a/src/elements.h b/src/elements.h
index bd5e7229b934609fae0c4a30ef780baf1ef62311..2ee07aa4746bf7cb2920b7324d4a3129b9b54961 100644
--- a/src/elements.h
+++ b/src/elements.h
@@ -126,9 +126,10 @@ class ElementsAccessor {
   // elements. This method should only be called for array expansion OR by
   // runtime JavaScript code that use InternalArrays and don't care about
   // EcmaScript 5.1 semantics.
-  MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(JSArray* array,
-                                                            int capacity,
- int length) = 0;
+  virtual void SetCapacityAndLength(
+      Handle<JSArray> array,
+      int capacity,
+      int length) = 0;

// Deletes an element in an object, returning a new elements backing store.
   MUST_USE_RESULT virtual Handle<Object> Delete(
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 5e66202ded50ffeb8047f7c150377cef71423f5b..40a0d43099b7bc5c16101ab0838d08c140367089 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -1486,16 +1486,6 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array,
 }


-void Factory::SetElementsCapacityAndLength(Handle<JSArray> array,
-                                           int capacity,
-                                           int length) {
-  ElementsAccessor* accessor = array->GetElementsAccessor();
-  CALL_HEAP_FUNCTION_VOID(
-      isolate(),
-      accessor->SetCapacityAndLength(*array, capacity, length));
-}
-
-
 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
     Handle<JSFunction> function) {
   ASSERT(function->shared()->is_generator());
Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index 5562ef4ec2a608ba9c4176dd77da4011fe767f79..e57e1301d2bcab0139d0059d55b7d8d189338090 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -387,10 +387,6 @@ class Factory {
       int capacity,
       ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);

-  void SetElementsCapacityAndLength(Handle<JSArray> array,
-                                    int capacity,
-                                    int length);
-
Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);

   Handle<JSArrayBuffer> NewJSArrayBuffer();
Index: src/json-stringifier.h
diff --git a/src/json-stringifier.h b/src/json-stringifier.h
index a75b3deed50eacb0863ef2eed4957302674e3ac6..012094aee8f3aef16121f14d97d2af0d56dfd78c 100644
--- a/src/json-stringifier.h
+++ b/src/json-stringifier.h
@@ -390,13 +390,16 @@ BasicJsonStringifier::Result BasicJsonStringifier::StackPush(
   if (check.HasOverflowed()) return STACK_OVERFLOW;

   int length = Smi::cast(stack_->length())->value();
-  FixedArray* elements = FixedArray::cast(stack_->elements());
-  for (int i = 0; i < length; i++) {
-    if (elements->get(i) == *object) {
-      return CIRCULAR;
+  {
+    DisallowHeapAllocation no_allocation;
+    FixedArray* elements = FixedArray::cast(stack_->elements());
+    for (int i = 0; i < length; i++) {
+      if (elements->get(i) == *object) {
+        return CIRCULAR;
+      }
     }
   }
-  stack_->EnsureSize(length + 1);
+  JSArray::EnsureSize(stack_, length + 1);
   FixedArray::cast(stack_->elements())->set(length, *object);
   stack_->set_length(Smi::FromInt(length + 1));
   return SUCCESS;
Index: src/jsregexp.cc
diff --git a/src/jsregexp.cc b/src/jsregexp.cc
index 012c251e21d3035d3a290eb88f635851888f06f2..6844f712b4fef385902447cfd1378fd65a8fecda 100644
--- a/src/jsregexp.cc
+++ b/src/jsregexp.cc
@@ -690,7 +690,8 @@ Handle<JSArray> RegExpImpl::SetLastMatchInfo(Handle<JSArray> last_match_info,
                                              int32_t* match) {
   ASSERT(last_match_info->HasFastObjectElements());
   int capture_register_count = (capture_count + 1) * 2;
-  last_match_info->EnsureSize(capture_register_count + kLastMatchOverhead);
+  JSArray::EnsureSize(last_match_info,
+                      capture_register_count + kLastMatchOverhead);
   DisallowHeapAllocation no_allocation;
   FixedArray* array = FixedArray::cast(last_match_info->elements());
   if (match != NULL) {
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index b3f23e65e3d2998a43dbd04b21213dde5ebf2e4e..e454e2ebdf8a0005bf54da5f71c17daa30e51e9b 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -6527,20 +6527,20 @@ void Map::ClearCodeCache(Heap* heap) {
 }


-void JSArray::EnsureSize(int required_size) {
-  ASSERT(HasFastSmiOrObjectElements());
-  FixedArray* elts = FixedArray::cast(elements());
+void JSArray::EnsureSize(Handle<JSArray> array, int required_size) {
+  ASSERT(array->HasFastSmiOrObjectElements());
+  Handle<FixedArray> elts = handle(FixedArray::cast(array->elements()));
   const int kArraySizeThatFitsComfortablyInNewSpace = 128;
   if (elts->length() < required_size) {
     // Doubling in size would be overkill, but leave some slack to avoid
     // constantly growing.
-    Expand(required_size + (required_size >> 3));
+    Expand(array, required_size + (required_size >> 3));
// It's a performance benefit to keep a frequently used array in new-space.
-  } else if (!GetHeap()->new_space()->Contains(elts) &&
+  } else if (!array->GetHeap()->new_space()->Contains(*elts) &&
              required_size < kArraySizeThatFitsComfortablyInNewSpace) {
// Expand will allocate a new backing store in new space even if the size
     // we asked for isn't larger than what we had before.
-    Expand(required_size);
+    Expand(array, required_size);
   }
 }

Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index c764b33e6793ee169d0866318e19483a888e4b08..131d031dcdb8e0a36aee15c518ab53c3b2211f9a 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -11279,9 +11279,9 @@ void JSArray::Initialize(Handle<JSArray> array, int capacity, int length) {
 }


-void JSArray::Expand(int required_size) {
-  GetIsolate()->factory()->SetElementsCapacityAndLength(
-      Handle<JSArray>(this), required_size, required_size);
+void JSArray::Expand(Handle<JSArray> array, int required_size) {
+  ElementsAccessor* accessor = array->GetElementsAccessor();
+  accessor->SetCapacityAndLength(array, required_size, required_size);
 }


Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index c4d3f251c318173946ab614ff661c3da679eb6fa..bb0f0f11d379240195f71c148418f9bd26bfe88c 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -10028,9 +10028,15 @@ class JSArray: public JSObject {
   // Casting.
   static inline JSArray* cast(Object* obj);

-  // Uses handles.  Ensures that the fixed array backing the JSArray has at
+  // Ensures that the fixed array backing the JSArray has at
   // least the stated size.
-  inline void EnsureSize(int minimum_size_of_backing_fixed_array);
+  static inline void EnsureSize(Handle<JSArray> array,
+                                int minimum_size_of_backing_fixed_array);
+
+  // Expand the fixed array backing of a fast-case JSArray to at least
+  // the requested size.
+  static void Expand(Handle<JSArray> array,
+                     int minimum_size_of_backing_fixed_array);

   // Dispatched behavior.
   DECLARE_PRINTER(JSArray)
@@ -10044,10 +10050,6 @@ class JSArray: public JSObject {
   static const int kSize = kLengthOffset + kPointerSize;

  private:
-  // Expand the fixed array backing of a fast-case JSArray to at least
-  // the requested size.
-  void Expand(int minimum_size_of_backing_fixed_array);
-
   DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
 };



--
--
v8-dev mailing list
v8-dev@googlegroups.com
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 v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to