From 57a3810280390a2d9599b8c41f831eac82ab57c4 Mon Sep 17 00:00:00 2001 From: verwaest Date: Mon, 22 Jun 2015 03:44:11 -0700 Subject: [PATCH] Get rid of JSArray::Expand and friends BUG= Review URL: https://codereview.chromium.org/1194943004 Cr-Commit-Position: refs/heads/master@{#29180} --- src/ast.cc | 6 +++--- src/elements.cc | 30 +++++++----------------------- src/elements.h | 11 ----------- src/json-stringifier.h | 3 +-- src/jsregexp.cc | 4 ++-- src/objects-inl.h | 18 ------------------ src/objects.cc | 6 ------ src/objects.h | 10 ---------- 8 files changed, 13 insertions(+), 75 deletions(-) diff --git a/src/ast.cc b/src/ast.cc index 99344142b..0c7a5dfb8 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -506,9 +506,9 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) { if (!constant_elements_.is_null()) return; // Allocate a fixed array to hold all the object literals. - Handle array = - isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS); - JSArray::Expand(array, values()->length()); + Handle array = isolate->factory()->NewJSArray( + FAST_HOLEY_SMI_ELEMENTS, values()->length(), values()->length(), + Strength::WEAK, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); // Fill in the literals. bool is_simple = true; diff --git a/src/elements.cc b/src/elements.cc index f1cddc45f..6d462fa9a 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -644,16 +644,7 @@ class ElementsAccessorBase : public ElementsAccessor { static void SetLengthImpl(Handle array, uint32_t length, Handle backing_store); - virtual void SetCapacityAndLength(Handle array, int capacity, - int length) final { - ElementsAccessorSubclass:: - SetFastElementsCapacityAndLength(array, capacity, length); - } - - static void SetFastElementsCapacityAndLength( - Handle obj, - int capacity, - int length) { + static void GrowCapacityAndConvert(Handle obj, int capacity) { UNIMPLEMENTED(); } @@ -1021,7 +1012,7 @@ class FastSmiOrObjectElementsAccessor break; case SLOPPY_ARGUMENTS_ELEMENTS: { // TODO(verwaest): This is a temporary hack to support extending - // SLOPPY_ARGUMENTS_ELEMENTS in SetFastElementsCapacityAndLength. + // SLOPPY_ARGUMENTS_ELEMENTS in GrowCapacityAndConvert. // This case should be UNREACHABLE(). FixedArray* parameter_map = FixedArray::cast(from); FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); @@ -1040,16 +1031,12 @@ class FastSmiOrObjectElementsAccessor } - static void SetFastElementsCapacityAndLength( - Handle obj, - uint32_t capacity, - uint32_t length) { + static void GrowCapacityAndConvert(Handle obj, uint32_t capacity) { JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = obj->HasFastSmiElements() ? JSObject::kAllowSmiElements : JSObject::kDontAllowSmiElements; - JSObject::SetFastElementsCapacityAndLength( - obj, capacity, length, set_capacity_mode); + JSObject::SetFastElementsCapacity(obj, capacity, set_capacity_mode); } }; @@ -1111,10 +1098,8 @@ class FastDoubleElementsAccessor : FastElementsAccessor(name) {} - static void SetFastElementsCapacityAndLength(Handle obj, - uint32_t capacity, - uint32_t length) { - JSObject::SetFastDoubleElementsCapacityAndLength(obj, capacity, length); + static void GrowCapacityAndConvert(Handle obj, uint32_t capacity) { + JSObject::SetFastDoubleElementsCapacity(obj, capacity); } protected: @@ -1679,8 +1664,7 @@ void ElementsAccessorBase:: } else { // Check whether the backing store should be expanded. capacity = Max(length, JSObject::NewElementsCapacity(capacity)); - ElementsAccessorSubclass::SetFastElementsCapacityAndLength(array, capacity, - length); + ElementsAccessorSubclass::GrowCapacityAndConvert(array, capacity); } array->set_length(Smi::FromInt(length)); diff --git a/src/elements.h b/src/elements.h index 18e47d214..28b23e375 100644 --- a/src/elements.h +++ b/src/elements.h @@ -76,17 +76,6 @@ class ElementsAccessor { // element that is non-deletable. virtual void SetLength(Handle holder, uint32_t new_length) = 0; - // Modifies both the length and capacity of a JSArray, resizing the underlying - // backing store as necessary. This method does NOT honor the semantics of - // EcmaScript 5.1 15.4.5.2, arrays can be shrunk beyond non-deletable - // 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. - virtual void SetCapacityAndLength( - Handle array, - int capacity, - int length) = 0; - // Deletes an element in an object. virtual void Delete(Handle holder, uint32_t key, LanguageMode language_mode) = 0; diff --git a/src/json-stringifier.h b/src/json-stringifier.h index 482d7920d..1ba99c1e9 100644 --- a/src/json-stringifier.h +++ b/src/json-stringifier.h @@ -280,9 +280,8 @@ BasicJsonStringifier::Result BasicJsonStringifier::StackPush( } } } - JSArray::EnsureSize(stack_, length + 1); + JSArray::SetLength(stack_, length + 1); FixedArray::cast(stack_->elements())->set(length, *object); - stack_->set_length(Smi::FromInt(length + 1)); return SUCCESS; } diff --git a/src/jsregexp.cc b/src/jsregexp.cc index 6de859607..be6e2a920 100644 --- a/src/jsregexp.cc +++ b/src/jsregexp.cc @@ -624,8 +624,8 @@ Handle RegExpImpl::SetLastMatchInfo(Handle last_match_info, int32_t* match) { DCHECK(last_match_info->HasFastObjectElements()); int capture_register_count = (capture_count + 1) * 2; - JSArray::EnsureSize(last_match_info, - capture_register_count + kLastMatchOverhead); + JSArray::SetLength(last_match_info, + capture_register_count + kLastMatchOverhead); DisallowHeapAllocation no_allocation; FixedArray* array = FixedArray::cast(last_match_info->elements()); if (match != NULL) { diff --git a/src/objects-inl.h b/src/objects-inl.h index 9043dde81..0cb870d62 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6943,24 +6943,6 @@ int Map::SlackForArraySize(int old_size, int size_limit) { } -void JSArray::EnsureSize(Handle array, int required_size) { - DCHECK(array->HasFastSmiOrObjectElements()); - Handle 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(array, required_size + (required_size >> 3)); - // It's a performance benefit to keep a frequently used array in new-space. - } 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(array, required_size); - } -} - - void JSArray::set_length(Smi* length) { // Don't need a write barrier for a Smi. set_length(static_cast(length), SKIP_WRITE_BARRIER); diff --git a/src/objects.cc b/src/objects.cc index f85a3d8a3..21037be4f 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -11928,12 +11928,6 @@ void JSArray::Initialize(Handle array, int capacity, int length) { } -void JSArray::Expand(Handle array, int required_size) { - ElementsAccessor* accessor = array->GetElementsAccessor(); - accessor->SetCapacityAndLength(array, required_size, required_size); -} - - // Returns false if the passed-in index is marked non-configurable, which will // cause the truncation operation to halt, and thus no further old values need // be collected. diff --git a/src/objects.h b/src/objects.h index 97f8af196..a0078cb6a 100644 --- a/src/objects.h +++ b/src/objects.h @@ -10199,16 +10199,6 @@ class JSArray: public JSObject { DECLARE_CAST(JSArray) - // Ensures that the fixed array backing the JSArray has at - // least the stated size. - static inline void EnsureSize(Handle 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 array, - int minimum_size_of_backing_fixed_array); - // Dispatched behavior. DECLARE_PRINTER(JSArray) DECLARE_VERIFIER(JSArray) -- 2.34.1