Get rid of JSArray::Expand and friends

BUG=

Review URL: https://codereview.chromium.org/1194943004

Cr-Commit-Position: refs/heads/master@{#29180}
This commit is contained in:
verwaest 2015-06-22 03:44:11 -07:00 committed by Commit bot
parent 7c43967bb7
commit 57a3810280
8 changed files with 13 additions and 75 deletions

View File

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

View File

@ -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));

View File

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

View File

@ -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;
}

View File

@ -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) {

View File

@ -6943,24 +6943,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);

View File

@ -11928,12 +11928,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.

View File

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