Commit 6c7449a6 authored by verwaest's avatar verwaest Committed by Commit bot

Move SetFastDoubleElementsCapacity into GrowCapacityAndConvert

BUG=v8:4137
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#29182}
parent d195c6f9
...@@ -644,10 +644,16 @@ class ElementsAccessorBase : public ElementsAccessor { ...@@ -644,10 +644,16 @@ class ElementsAccessorBase : public ElementsAccessor {
static void SetLengthImpl(Handle<JSArray> array, uint32_t length, static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
Handle<FixedArrayBase> backing_store); Handle<FixedArrayBase> backing_store);
static void GrowCapacityAndConvert(Handle<JSObject> obj, int capacity) { static void GrowCapacityAndConvertImpl(Handle<JSObject> obj,
uint32_t capacity) {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
virtual void GrowCapacityAndConvert(Handle<JSObject> object,
uint32_t capacity) final {
ElementsAccessorSubclass::GrowCapacityAndConvertImpl(object, capacity);
}
virtual void Delete(Handle<JSObject> obj, uint32_t key, virtual void Delete(Handle<JSObject> obj, uint32_t key,
LanguageMode language_mode) override = 0; LanguageMode language_mode) override = 0;
...@@ -1031,7 +1037,8 @@ class FastSmiOrObjectElementsAccessor ...@@ -1031,7 +1037,8 @@ class FastSmiOrObjectElementsAccessor
} }
static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) { static void GrowCapacityAndConvertImpl(Handle<JSObject> obj,
uint32_t capacity) {
JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = JSObject::SetFastElementsCapacitySmiMode set_capacity_mode =
obj->HasFastSmiElements() obj->HasFastSmiElements()
? JSObject::kAllowSmiElements ? JSObject::kAllowSmiElements
...@@ -1098,8 +1105,32 @@ class FastDoubleElementsAccessor ...@@ -1098,8 +1105,32 @@ class FastDoubleElementsAccessor
: FastElementsAccessor<FastElementsAccessorSubclass, : FastElementsAccessor<FastElementsAccessorSubclass,
KindTraits>(name) {} KindTraits>(name) {}
static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) { static void GrowCapacityAndConvertImpl(Handle<JSObject> object,
JSObject::SetFastDoubleElementsCapacity(obj, capacity); uint32_t capacity) {
Handle<FixedArrayBase> elements =
object->GetIsolate()->factory()->NewFixedDoubleArray(capacity);
ElementsKind from_kind = object->GetElementsKind();
ElementsKind to_kind = IsHoleyElementsKind(from_kind)
? FAST_HOLEY_DOUBLE_ELEMENTS
: FAST_DOUBLE_ELEMENTS;
Handle<Map> new_map = JSObject::GetElementsTransitionMap(object, to_kind);
Handle<FixedArrayBase> old_elements(object->elements());
int packed = kPackedSizeNotKnown;
if (IsFastPackedElementsKind(from_kind) && object->IsJSArray()) {
packed = Smi::cast(JSArray::cast(*object)->length())->value();
}
CopyElementsImpl(*old_elements, 0, *elements, from_kind, 0, packed,
ElementsAccessor::kCopyToEndAndInitializeToHole);
JSObject::SetMapAndElements(object, new_map, elements);
JSObject::ValidateElements(object);
if (FLAG_trace_elements_transitions) {
JSObject::PrintElementsTransition(stdout, object, from_kind, old_elements,
to_kind, elements);
}
} }
protected: protected:
...@@ -1664,7 +1695,7 @@ void ElementsAccessorBase<ElementsAccessorSubclass, ElementsKindTraits>:: ...@@ -1664,7 +1695,7 @@ void ElementsAccessorBase<ElementsAccessorSubclass, ElementsKindTraits>::
} else { } else {
// Check whether the backing store should be expanded. // Check whether the backing store should be expanded.
capacity = Max(length, JSObject::NewElementsCapacity(capacity)); capacity = Max(length, JSObject::NewElementsCapacity(capacity));
ElementsAccessorSubclass::GrowCapacityAndConvert(array, capacity); ElementsAccessorSubclass::GrowCapacityAndConvertImpl(array, capacity);
} }
array->set_length(Smi::FromInt(length)); array->set_length(Smi::FromInt(length));
......
...@@ -121,6 +121,9 @@ class ElementsAccessor { ...@@ -121,6 +121,9 @@ class ElementsAccessor {
*from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole); *from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole);
} }
virtual void GrowCapacityAndConvert(Handle<JSObject> object,
uint32_t capacity) = 0;
virtual Handle<FixedArray> AddElementsToFixedArray( virtual Handle<FixedArray> AddElementsToFixedArray(
Handle<JSObject> receiver, Handle<FixedArray> to, Handle<JSObject> receiver, Handle<FixedArray> to,
FixedArray::KeyFilter filter) = 0; FixedArray::KeyFilter filter) = 0;
......
...@@ -121,26 +121,10 @@ void LookupIterator::PrepareForDataProperty(Handle<Object> value) { ...@@ -121,26 +121,10 @@ void LookupIterator::PrepareForDataProperty(Handle<Object> value) {
JSObject::UpdateAllocationSite(holder, new_kind); JSObject::UpdateAllocationSite(holder, new_kind);
if (IsFastDoubleElementsKind(old_kind) != if (IsFastDoubleElementsKind(old_kind) !=
IsFastDoubleElementsKind(new_kind)) { IsFastDoubleElementsKind(new_kind)) {
Handle<FixedArrayBase> old_elements(holder->elements()); uint32_t capacity = holder->elements()->length();
int capacity = old_elements->length();
Handle<FixedArrayBase> new_elements;
if (IsFastDoubleElementsKind(new_kind)) {
new_elements = factory()->NewFixedDoubleArray(capacity);
} else {
new_elements = factory()->NewFixedArray(capacity);
}
ElementsAccessor* accessor = ElementsAccessor::ForKind(new_kind); ElementsAccessor* accessor = ElementsAccessor::ForKind(new_kind);
accessor->CopyElements(holder, new_elements, old_kind); accessor->GrowCapacityAndConvert(holder, capacity);
// GrowCapacityAndConvert migrated the object. No reloading of property
JSObject::ValidateElements(holder);
JSObject::SetMapAndElements(holder, holder_map_, new_elements);
if (FLAG_trace_elements_transitions) {
JSObject::PrintElementsTransition(
stdout, holder, old_kind, old_elements, new_kind, new_elements);
}
// SetMapAndElements above migrated the object. No reloading of property
// infomation is necessary for elements. // infomation is necessary for elements.
return; return;
} else if (FLAG_trace_elements_transitions) { } else if (FLAG_trace_elements_transitions) {
......
...@@ -11874,49 +11874,14 @@ Handle<FixedArray> JSObject::SetFastElementsCapacityAndLength( ...@@ -11874,49 +11874,14 @@ Handle<FixedArray> JSObject::SetFastElementsCapacityAndLength(
} }
Handle<FixedArrayBase> JSObject::SetFastDoubleElementsCapacity( void JSObject::SetFastDoubleElementsCapacityAndLength(Handle<JSObject> object,
Handle<JSObject> object, int capacity) { int capacity,
// We should never end in here with a pixel or external array. int length) {
DCHECK(!object->HasExternalArrayElements());
Handle<FixedArrayBase> elems =
object->GetIsolate()->factory()->NewFixedDoubleArray(capacity);
ElementsKind elements_kind = object->GetElementsKind();
CHECK(elements_kind != SLOPPY_ARGUMENTS_ELEMENTS);
ElementsKind new_elements_kind = elements_kind;
if (IsHoleyElementsKind(elements_kind)) {
new_elements_kind = FAST_HOLEY_DOUBLE_ELEMENTS;
} else {
new_elements_kind = FAST_DOUBLE_ELEMENTS;
}
Handle<Map> new_map = GetElementsTransitionMap(object, new_elements_kind);
Handle<FixedArrayBase> old_elements(object->elements());
ElementsAccessor* accessor = ElementsAccessor::ForKind(FAST_DOUBLE_ELEMENTS); ElementsAccessor* accessor = ElementsAccessor::ForKind(FAST_DOUBLE_ELEMENTS);
accessor->CopyElements(object, elems, elements_kind); accessor->GrowCapacityAndConvert(object, capacity);
JSObject::ValidateElements(object);
JSObject::SetMapAndElements(object, new_map, elems);
if (FLAG_trace_elements_transitions) {
PrintElementsTransition(stdout, object, elements_kind, old_elements,
object->GetElementsKind(), elems);
}
return elems;
}
Handle<FixedArrayBase> JSObject::SetFastDoubleElementsCapacityAndLength(
Handle<JSObject> object, int capacity, int length) {
Handle<FixedArrayBase> new_elements =
SetFastDoubleElementsCapacity(object, capacity);
if (object->IsJSArray()) { if (object->IsJSArray()) {
Handle<JSArray>::cast(object)->set_length(Smi::FromInt(length)); Handle<JSArray>::cast(object)->set_length(Smi::FromInt(length));
} }
return new_elements;
} }
......
...@@ -2049,8 +2049,6 @@ class JSObject: public JSReceiver { ...@@ -2049,8 +2049,6 @@ class JSObject: public JSReceiver {
static Handle<FixedArray> SetFastElementsCapacity( static Handle<FixedArray> SetFastElementsCapacity(
Handle<JSObject> object, int capacity, Handle<JSObject> object, int capacity,
SetFastElementsCapacitySmiMode smi_mode); SetFastElementsCapacitySmiMode smi_mode);
static Handle<FixedArrayBase> SetFastDoubleElementsCapacity(
Handle<JSObject> object, int capacity);
// Replace the elements' backing store with fast elements of the given // Replace the elements' backing store with fast elements of the given
// capacity. Update the length for JSArrays. Returns the new backing // capacity. Update the length for JSArrays. Returns the new backing
...@@ -2060,8 +2058,8 @@ class JSObject: public JSReceiver { ...@@ -2060,8 +2058,8 @@ class JSObject: public JSReceiver {
int capacity, int capacity,
int length, int length,
SetFastElementsCapacitySmiMode smi_mode); SetFastElementsCapacitySmiMode smi_mode);
static Handle<FixedArrayBase> SetFastDoubleElementsCapacityAndLength( static void SetFastDoubleElementsCapacityAndLength(Handle<JSObject> object,
Handle<JSObject> object, int capacity, int length); int capacity, int length);
// Lookup interceptors are used for handling properties controlled by host // Lookup interceptors are used for handling properties controlled by host
// objects. // objects.
......
...@@ -1258,16 +1258,7 @@ RUNTIME_FUNCTION(Runtime_GrowArrayElements) { ...@@ -1258,16 +1258,7 @@ RUNTIME_FUNCTION(Runtime_GrowArrayElements) {
} }
uint32_t new_capacity = JSObject::NewElementsCapacity(index + 1); uint32_t new_capacity = JSObject::NewElementsCapacity(index + 1);
ElementsKind kind = object->GetElementsKind(); object->GetElementsAccessor()->GrowCapacityAndConvert(object, new_capacity);
if (IsFastDoubleElementsKind(kind)) {
JSObject::SetFastDoubleElementsCapacity(object, new_capacity);
} else {
JSObject::SetFastElementsCapacitySmiMode set_capacity_mode =
object->HasFastSmiElements() ? JSObject::kAllowSmiElements
: JSObject::kDontAllowSmiElements;
JSObject::SetFastElementsCapacity(object, new_capacity,
set_capacity_mode);
}
} }
// On success, return the fixed array elements. // On success, return the fixed array elements.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment