Reviewers: Jakob,
Message:
ptal
Description:
Get rid of JSArray::Expand and friends
BUG=
Please review this at https://codereview.chromium.org/1194943004/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+13, -75 lines):
M src/ast.cc
M src/elements.h
M src/elements.cc
M src/json-stringifier.h
M src/jsregexp.cc
M src/objects.h
M src/objects.cc
M src/objects-inl.h
Index: src/ast.cc
diff --git a/src/ast.cc b/src/ast.cc
index
31cfee3cac72783cac74aab5d18f1f149ca2b187..0bd101ff6eb4300e3aa7b1812c305f39e13bcfaa
100644
--- a/src/ast.cc
+++ b/src/ast.cc
@@ -521,9 +521,9 @@ void ArrayLiteral::BuildConstantElements(Isolate*
isolate) {
if (!constant_elements_.is_null()) return;
// Allocate a fixed array to hold all the object literals.
- Handle<JSArray> array =
- isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS);
- JSArray::Expand(array, values()->length());
+ Handle<JSArray> 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;
Index: src/elements.cc
diff --git a/src/elements.cc b/src/elements.cc
index
f1cddc45fd7b8104b073ec1d616ec10669608ad2..6d462fa9a6fc39ac4a67fe0ce2143397881b99b0
100644
--- a/src/elements.cc
+++ b/src/elements.cc
@@ -644,16 +644,7 @@ class ElementsAccessorBase : public ElementsAccessor {
static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
Handle<FixedArrayBase> backing_store);
- virtual void SetCapacityAndLength(Handle<JSArray> array, int capacity,
- int length) final {
- ElementsAccessorSubclass::
- SetFastElementsCapacityAndLength(array, capacity, length);
- }
-
- static void SetFastElementsCapacityAndLength(
- Handle<JSObject> obj,
- int capacity,
- int length) {
+ static void GrowCapacityAndConvert(Handle<JSObject> 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<JSObject> obj,
- uint32_t capacity,
- uint32_t length) {
+ static void GrowCapacityAndConvert(Handle<JSObject> 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<FastElementsAccessorSubclass,
KindTraits>(name) {}
- static void SetFastElementsCapacityAndLength(Handle<JSObject> obj,
- uint32_t capacity,
- uint32_t length) {
- JSObject::SetFastDoubleElementsCapacityAndLength(obj, capacity,
length);
+ static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t
capacity) {
+ JSObject::SetFastDoubleElementsCapacity(obj, capacity);
}
protected:
@@ -1679,8 +1664,7 @@ void ElementsAccessorBase<ElementsAccessorSubclass,
ElementsKindTraits>::
} 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));
Index: src/elements.h
diff --git a/src/elements.h b/src/elements.h
index
18e47d2146d6ccdc3525ff5627bd9b42450f2c03..28b23e375e4a059c453ab82a6da33ff3f5a840cf
100644
--- a/src/elements.h
+++ b/src/elements.h
@@ -76,17 +76,6 @@ class ElementsAccessor {
// element that is non-deletable.
virtual void SetLength(Handle<JSArray> 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<JSArray> array,
- int capacity,
- int length) = 0;
-
// Deletes an element in an object.
virtual void Delete(Handle<JSObject> holder, uint32_t key,
LanguageMode language_mode) = 0;
Index: src/json-stringifier.h
diff --git a/src/json-stringifier.h b/src/json-stringifier.h
index
482d7920d3dcce0007e29c8b6bec970fe37fb248..1ba99c1e9ac5439753a3422fffae296ac3e08c9a
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;
}
Index: src/jsregexp.cc
diff --git a/src/jsregexp.cc b/src/jsregexp.cc
index
6de8596071544929e7300a8c05c8f1069498b48c..be6e2a92027b5cf56bb9628036b2fb13f8ead5b3
100644
--- a/src/jsregexp.cc
+++ b/src/jsregexp.cc
@@ -624,8 +624,8 @@ Handle<JSArray>
RegExpImpl::SetLastMatchInfo(Handle<JSArray> 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) {
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
39891513caedde2ee0179e71d31a14af71040e70..7a82c941119df597708a57abc46739803dc9870d
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -6945,24 +6945,6 @@ int Map::SlackForArraySize(int old_size, int
size_limit) {
}
-void JSArray::EnsureSize(Handle<JSArray> array, int required_size) {
- DCHECK(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(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<Object*>(length), SKIP_WRITE_BARRIER);
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
1554a0970656eec5d19c29296132054142f2e24d..aea8c3ba92464212fa57ab705134e90cfa12cb5b
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -11903,12 +11903,6 @@ void JSArray::Initialize(Handle<JSArray> array,
int capacity, int length) {
}
-void JSArray::Expand(Handle<JSArray> 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.
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
e417e32582a662be111d28aaf5af2bfd8944fd27..26bae06855405b91f7b9fc70d03a76445b9bf496
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -10200,16 +10200,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<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)
DECLARE_VERIFIER(JSArray)
--
--
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.