JSObject::EnsureCanContainElements() handlified.

R=verwaest@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20166 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ishell@chromium.org 2014-03-21 14:29:27 +00:00
parent 265ae63173
commit deca3f3677
3 changed files with 50 additions and 79 deletions

View File

@ -1621,85 +1621,79 @@ void JSObject::EnsureCanContainHeapObjectElements(Handle<JSObject> object) {
}
MaybeObject* JSObject::EnsureCanContainElements(Object** objects,
uint32_t count,
EnsureElementsMode mode) {
ElementsKind current_kind = map()->elements_kind();
void JSObject::EnsureCanContainElements(Handle<JSObject> object,
Object** objects,
uint32_t count,
EnsureElementsMode mode) {
ElementsKind current_kind = object->map()->elements_kind();
ElementsKind target_kind = current_kind;
ASSERT(mode != ALLOW_COPIED_DOUBLE_ELEMENTS);
bool is_holey = IsFastHoleyElementsKind(current_kind);
if (current_kind == FAST_HOLEY_ELEMENTS) return this;
Heap* heap = GetHeap();
Object* the_hole = heap->the_hole_value();
for (uint32_t i = 0; i < count; ++i) {
Object* current = *objects++;
if (current == the_hole) {
is_holey = true;
target_kind = GetHoleyElementsKind(target_kind);
} else if (!current->IsSmi()) {
if (mode == ALLOW_CONVERTED_DOUBLE_ELEMENTS && current->IsNumber()) {
if (IsFastSmiElementsKind(target_kind)) {
if (is_holey) {
target_kind = FAST_HOLEY_DOUBLE_ELEMENTS;
} else {
target_kind = FAST_DOUBLE_ELEMENTS;
{
DisallowHeapAllocation no_allocation;
ASSERT(mode != ALLOW_COPIED_DOUBLE_ELEMENTS);
bool is_holey = IsFastHoleyElementsKind(current_kind);
if (current_kind == FAST_HOLEY_ELEMENTS) return;
Heap* heap = object->GetHeap();
Object* the_hole = heap->the_hole_value();
for (uint32_t i = 0; i < count; ++i) {
Object* current = *objects++;
if (current == the_hole) {
is_holey = true;
target_kind = GetHoleyElementsKind(target_kind);
} else if (!current->IsSmi()) {
if (mode == ALLOW_CONVERTED_DOUBLE_ELEMENTS && current->IsNumber()) {
if (IsFastSmiElementsKind(target_kind)) {
if (is_holey) {
target_kind = FAST_HOLEY_DOUBLE_ELEMENTS;
} else {
target_kind = FAST_DOUBLE_ELEMENTS;
}
}
} else if (is_holey) {
target_kind = FAST_HOLEY_ELEMENTS;
break;
} else {
target_kind = FAST_ELEMENTS;
}
} else if (is_holey) {
target_kind = FAST_HOLEY_ELEMENTS;
break;
} else {
target_kind = FAST_ELEMENTS;
}
}
}
if (target_kind != current_kind) {
return TransitionElementsKind(target_kind);
TransitionElementsKind(object, target_kind);
}
return this;
}
// TODO(ishell): Temporary wrapper until handlified.
void JSObject::EnsureCanContainElements(Handle<JSObject> object,
Handle<FixedArrayBase> elements,
uint32_t length,
EnsureElementsMode mode) {
CALL_HEAP_FUNCTION_VOID(object->GetIsolate(),
object->EnsureCanContainElements(*elements,
length,
mode));
}
MaybeObject* JSObject::EnsureCanContainElements(FixedArrayBase* elements,
uint32_t length,
EnsureElementsMode mode) {
if (elements->map() != GetHeap()->fixed_double_array_map()) {
ASSERT(elements->map() == GetHeap()->fixed_array_map() ||
elements->map() == GetHeap()->fixed_cow_array_map());
Heap* heap = object->GetHeap();
if (elements->map() != heap->fixed_double_array_map()) {
ASSERT(elements->map() == heap->fixed_array_map() ||
elements->map() == heap->fixed_cow_array_map());
if (mode == ALLOW_COPIED_DOUBLE_ELEMENTS) {
mode = DONT_ALLOW_DOUBLE_ELEMENTS;
}
Object** objects = FixedArray::cast(elements)->GetFirstElementAddress();
return EnsureCanContainElements(objects, length, mode);
Object** objects =
Handle<FixedArray>::cast(elements)->GetFirstElementAddress();
EnsureCanContainElements(object, objects, length, mode);
return;
}
ASSERT(mode == ALLOW_COPIED_DOUBLE_ELEMENTS);
if (GetElementsKind() == FAST_HOLEY_SMI_ELEMENTS) {
return TransitionElementsKind(FAST_HOLEY_DOUBLE_ELEMENTS);
} else if (GetElementsKind() == FAST_SMI_ELEMENTS) {
FixedDoubleArray* double_array = FixedDoubleArray::cast(elements);
if (object->GetElementsKind() == FAST_HOLEY_SMI_ELEMENTS) {
TransitionElementsKind(object, FAST_HOLEY_DOUBLE_ELEMENTS);
} else if (object->GetElementsKind() == FAST_SMI_ELEMENTS) {
Handle<FixedDoubleArray> double_array =
Handle<FixedDoubleArray>::cast(elements);
for (uint32_t i = 0; i < length; ++i) {
if (double_array->is_the_hole(i)) {
return TransitionElementsKind(FAST_HOLEY_DOUBLE_ELEMENTS);
TransitionElementsKind(object, FAST_HOLEY_DOUBLE_ELEMENTS);
return;
}
}
return TransitionElementsKind(FAST_DOUBLE_ELEMENTS);
TransitionElementsKind(object, FAST_DOUBLE_ELEMENTS);
}
return this;
}

View File

@ -11818,31 +11818,16 @@ Handle<Object> JSObject::SetPrototype(Handle<JSObject> object,
}
// TODO(ishell): temporary wrapper until handilfied.
// static
void JSObject::EnsureCanContainElements(Handle<JSObject> object,
Arguments* args,
uint32_t first_arg,
uint32_t arg_count,
EnsureElementsMode mode) {
CALL_HEAP_FUNCTION_VOID(object->GetIsolate(),
object->EnsureCanContainElements(args,
first_arg,
arg_count,
mode));
}
MaybeObject* JSObject::EnsureCanContainElements(Arguments* args,
uint32_t first_arg,
uint32_t arg_count,
EnsureElementsMode mode) {
// Elements in |Arguments| are ordered backwards (because they're on the
// stack), but the method that's called here iterates over them in forward
// direction.
return EnsureCanContainElements(
args->arguments() - first_arg - (arg_count - 1),
arg_count, mode);
object, args->arguments() - first_arg - (arg_count - 1), arg_count, mode);
}

View File

@ -2420,7 +2420,8 @@ class JSObject: public JSReceiver {
static inline void EnsureCanContainHeapObjectElements(Handle<JSObject> obj);
// Makes sure that this object can contain the specified elements.
MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
static inline void EnsureCanContainElements(
Handle<JSObject> object,
Object** elements,
uint32_t count,
EnsureElementsMode mode);
@ -2429,21 +2430,12 @@ class JSObject: public JSReceiver {
Handle<FixedArrayBase> elements,
uint32_t length,
EnsureElementsMode mode);
MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
FixedArrayBase* elements,
uint32_t length,
EnsureElementsMode mode);
static void EnsureCanContainElements(
Handle<JSObject> object,
Arguments* arguments,
uint32_t first_arg,
uint32_t arg_count,
EnsureElementsMode mode);
MUST_USE_RESULT MaybeObject* EnsureCanContainElements(
Arguments* arguments,
uint32_t first_arg,
uint32_t arg_count,
EnsureElementsMode mode);
// Would we convert a fast elements array to dictionary mode given
// an access at key?