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 {
static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
Handle<FixedArrayBase> backing_store);
static void GrowCapacityAndConvert(Handle<JSObject> obj, int capacity) {
static void GrowCapacityAndConvertImpl(Handle<JSObject> obj,
uint32_t capacity) {
UNIMPLEMENTED();
}
virtual void GrowCapacityAndConvert(Handle<JSObject> object,
uint32_t capacity) final {
ElementsAccessorSubclass::GrowCapacityAndConvertImpl(object, capacity);
}
virtual void Delete(Handle<JSObject> obj, uint32_t key,
LanguageMode language_mode) override = 0;
......@@ -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 =
obj->HasFastSmiElements()
? JSObject::kAllowSmiElements
......@@ -1098,8 +1105,32 @@ class FastDoubleElementsAccessor
: FastElementsAccessor<FastElementsAccessorSubclass,
KindTraits>(name) {}
static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) {
JSObject::SetFastDoubleElementsCapacity(obj, capacity);
static void GrowCapacityAndConvertImpl(Handle<JSObject> object,
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:
......@@ -1664,7 +1695,7 @@ void ElementsAccessorBase<ElementsAccessorSubclass, ElementsKindTraits>::
} else {
// Check whether the backing store should be expanded.
capacity = Max(length, JSObject::NewElementsCapacity(capacity));
ElementsAccessorSubclass::GrowCapacityAndConvert(array, capacity);
ElementsAccessorSubclass::GrowCapacityAndConvertImpl(array, capacity);
}
array->set_length(Smi::FromInt(length));
......
......@@ -121,6 +121,9 @@ class ElementsAccessor {
*from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole);
}
virtual void GrowCapacityAndConvert(Handle<JSObject> object,
uint32_t capacity) = 0;
virtual Handle<FixedArray> AddElementsToFixedArray(
Handle<JSObject> receiver, Handle<FixedArray> to,
FixedArray::KeyFilter filter) = 0;
......
......@@ -121,26 +121,10 @@ void LookupIterator::PrepareForDataProperty(Handle<Object> value) {
JSObject::UpdateAllocationSite(holder, new_kind);
if (IsFastDoubleElementsKind(old_kind) !=
IsFastDoubleElementsKind(new_kind)) {
Handle<FixedArrayBase> old_elements(holder->elements());
int capacity = old_elements->length();
Handle<FixedArrayBase> new_elements;
if (IsFastDoubleElementsKind(new_kind)) {
new_elements = factory()->NewFixedDoubleArray(capacity);
} else {
new_elements = factory()->NewFixedArray(capacity);
}
uint32_t capacity = holder->elements()->length();
ElementsAccessor* accessor = ElementsAccessor::ForKind(new_kind);
accessor->CopyElements(holder, new_elements, old_kind);
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
accessor->GrowCapacityAndConvert(holder, capacity);
// GrowCapacityAndConvert migrated the object. No reloading of property
// infomation is necessary for elements.
return;
} else if (FLAG_trace_elements_transitions) {
......
......@@ -11874,49 +11874,14 @@ Handle<FixedArray> JSObject::SetFastElementsCapacityAndLength(
}
Handle<FixedArrayBase> JSObject::SetFastDoubleElementsCapacity(
Handle<JSObject> object, int capacity) {
// We should never end in here with a pixel or external array.
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());
void JSObject::SetFastDoubleElementsCapacityAndLength(Handle<JSObject> object,
int capacity,
int length) {
ElementsAccessor* accessor = ElementsAccessor::ForKind(FAST_DOUBLE_ELEMENTS);
accessor->CopyElements(object, elems, elements_kind);
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);
accessor->GrowCapacityAndConvert(object, capacity);
if (object->IsJSArray()) {
Handle<JSArray>::cast(object)->set_length(Smi::FromInt(length));
}
return new_elements;
}
......
......@@ -2049,8 +2049,6 @@ class JSObject: public JSReceiver {
static Handle<FixedArray> SetFastElementsCapacity(
Handle<JSObject> object, int capacity,
SetFastElementsCapacitySmiMode smi_mode);
static Handle<FixedArrayBase> SetFastDoubleElementsCapacity(
Handle<JSObject> object, int capacity);
// Replace the elements' backing store with fast elements of the given
// capacity. Update the length for JSArrays. Returns the new backing
......@@ -2060,8 +2058,8 @@ class JSObject: public JSReceiver {
int capacity,
int length,
SetFastElementsCapacitySmiMode smi_mode);
static Handle<FixedArrayBase> SetFastDoubleElementsCapacityAndLength(
Handle<JSObject> object, int capacity, int length);
static void SetFastDoubleElementsCapacityAndLength(Handle<JSObject> object,
int capacity, int length);
// Lookup interceptors are used for handling properties controlled by host
// objects.
......
......@@ -1258,16 +1258,7 @@ RUNTIME_FUNCTION(Runtime_GrowArrayElements) {
}
uint32_t new_capacity = JSObject::NewElementsCapacity(index + 1);
ElementsKind kind = object->GetElementsKind();
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);
}
object->GetElementsAccessor()->GrowCapacityAndConvert(object, new_capacity);
}
// 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