Activate smi-only optimizations for large array literals.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/8177005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9553 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
danno@chromium.org 2011-10-10 08:31:06 +00:00
parent e340163301
commit 3b07abbdbe
14 changed files with 152 additions and 179 deletions

View File

@ -1524,12 +1524,10 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
__ RecordWriteField( __ RecordWriteField(
r1, offset, result_register(), r2, kLRHasBeenSaved, kDontSaveFPRegs, r1, offset, result_register(), r2, kLRHasBeenSaved, kDontSaveFPRegs,
EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
if (FLAG_smi_only_arrays) {
__ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
__ CheckFastSmiOnlyElements(r3, r2, &no_map_change); __ CheckFastSmiOnlyElements(r3, r2, &no_map_change);
__ push(r6); // Copy of array literal. __ push(r6); // Copy of array literal.
__ CallRuntime(Runtime::kNonSmiElementStored, 1); __ CallRuntime(Runtime::kNonSmiElementStored, 1);
}
__ bind(&no_map_change); __ bind(&no_map_change);
PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);

View File

@ -1380,10 +1380,8 @@ void KeyedStoreIC::GenerateGeneric(MacroAssembler* masm,
__ Ret(); __ Ret();
__ bind(&non_smi_value); __ bind(&non_smi_value);
if (FLAG_smi_only_arrays) {
// Escape to slow case when writing non-smi into smi-only array. // Escape to slow case when writing non-smi into smi-only array.
__ CheckFastObjectElements(receiver_map, scratch_value, &slow); __ CheckFastObjectElements(receiver_map, scratch_value, &slow);
}
// Fast elements array, store the value to the elements backing store. // Fast elements array, store the value to the elements backing store.
__ add(address, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); __ add(address, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
__ add(address, address, Operand(key, LSL, kPointerSizeLog2 - kSmiTagSize)); __ add(address, address, Operand(key, LSL, kPointerSizeLog2 - kSmiTagSize));

View File

@ -1618,10 +1618,8 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
__ bind(&with_write_barrier); __ bind(&with_write_barrier);
if (FLAG_smi_only_arrays) {
__ ldr(r6, FieldMemOperand(receiver, HeapObject::kMapOffset)); __ ldr(r6, FieldMemOperand(receiver, HeapObject::kMapOffset));
__ CheckFastSmiOnlyElements(r6, r6, &call_builtin); __ CheckFastSmiOnlyElements(r6, r6, &call_builtin);
}
// Save new length. // Save new length.
__ str(r0, FieldMemOperand(receiver, JSArray::kLengthOffset)); __ str(r0, FieldMemOperand(receiver, JSArray::kLengthOffset));
@ -1652,7 +1650,6 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
} }
__ ldr(r2, MemOperand(sp, (argc - 1) * kPointerSize)); __ ldr(r2, MemOperand(sp, (argc - 1) * kPointerSize));
if (FLAG_smi_only_arrays) {
// Growing elements that are SMI-only requires special handling in case // Growing elements that are SMI-only requires special handling in case
// the new element is non-Smi. For now, delegate to the builtin. // the new element is non-Smi. For now, delegate to the builtin.
Label no_fast_elements_check; Label no_fast_elements_check;
@ -1660,7 +1657,6 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
__ ldr(r7, FieldMemOperand(receiver, HeapObject::kMapOffset)); __ ldr(r7, FieldMemOperand(receiver, HeapObject::kMapOffset));
__ CheckFastObjectElements(r7, r7, &call_builtin); __ CheckFastObjectElements(r7, r7, &call_builtin);
__ bind(&no_fast_elements_check); __ bind(&no_fast_elements_check);
}
Isolate* isolate = masm()->isolate(); Isolate* isolate = masm()->isolate();
ExternalReference new_space_allocation_top = ExternalReference new_space_allocation_top =

View File

@ -242,11 +242,9 @@ BUILTIN(ArrayCodeGeneric) {
} }
// Set length and elements on the array. // Set length and elements on the array.
if (FLAG_smi_only_arrays) {
MaybeObject* maybe_object = MaybeObject* maybe_object =
array->EnsureCanContainElements(FixedArray::cast(obj)); array->EnsureCanContainElements(FixedArray::cast(obj));
if (maybe_object->IsFailure()) return maybe_object; if (maybe_object->IsFailure()) return maybe_object;
}
AssertNoAllocation no_gc; AssertNoAllocation no_gc;
FixedArray* elms = FixedArray::cast(obj); FixedArray* elms = FixedArray::cast(obj);
@ -402,17 +400,38 @@ static bool ArrayPrototypeHasNoElements(Heap* heap,
MUST_USE_RESULT MUST_USE_RESULT
static inline MaybeObject* EnsureJSArrayWithWritableFastElements( static inline MaybeObject* EnsureJSArrayWithWritableFastElements(
Heap* heap, Object* receiver) { Heap* heap, Object* receiver, Arguments* args, int first_added_arg) {
if (!receiver->IsJSArray()) return NULL; if (!receiver->IsJSArray()) return NULL;
JSArray* array = JSArray::cast(receiver); JSArray* array = JSArray::cast(receiver);
HeapObject* elms = array->elements(); HeapObject* elms = array->elements();
if (elms->map() == heap->fixed_array_map()) return elms; Map* map = elms->map();
if (elms->map() == heap->fixed_cow_array_map()) { if (map == heap->fixed_array_map()) {
return array->EnsureWritableFastElements(); if (args == NULL || !array->HasFastSmiOnlyElements()) {
return elms;
} }
} else if (map == heap->fixed_cow_array_map()) {
MaybeObject* maybe_writable_result = array->EnsureWritableFastElements();
if (args == NULL || !array->HasFastSmiOnlyElements() ||
maybe_writable_result->IsFailure()) {
return maybe_writable_result;
}
} else {
return NULL; return NULL;
} }
// Need to ensure that the arguments passed in args can be contained in
// the array.
int args_length = args->length();
if (first_added_arg >= args_length) return array->elements();
MaybeObject* maybe_array = array->EnsureCanContainElements(
args,
first_added_arg,
args_length - first_added_arg);
if (maybe_array->IsFailure()) return maybe_array;
return array->elements();
}
static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap,
JSArray* receiver) { JSArray* receiver) {
@ -455,7 +474,7 @@ BUILTIN(ArrayPush) {
Object* receiver = *args.receiver(); Object* receiver = *args.receiver();
Object* elms_obj; Object* elms_obj;
{ MaybeObject* maybe_elms_obj = { MaybeObject* maybe_elms_obj =
EnsureJSArrayWithWritableFastElements(heap, receiver); EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 1);
if (maybe_elms_obj == NULL) { if (maybe_elms_obj == NULL) {
return CallJsBuiltin(isolate, "ArrayPush", args); return CallJsBuiltin(isolate, "ArrayPush", args);
} }
@ -493,9 +512,6 @@ BUILTIN(ArrayPush) {
elms = new_elms; elms = new_elms;
} }
MaybeObject* maybe = array->EnsureCanContainElements(&args, 1, to_add);
if (maybe->IsFailure()) return maybe;
// Add the provided values. // Add the provided values.
AssertNoAllocation no_gc; AssertNoAllocation no_gc;
WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
@ -518,7 +534,7 @@ BUILTIN(ArrayPop) {
Object* receiver = *args.receiver(); Object* receiver = *args.receiver();
Object* elms_obj; Object* elms_obj;
{ MaybeObject* maybe_elms_obj = { MaybeObject* maybe_elms_obj =
EnsureJSArrayWithWritableFastElements(heap, receiver); EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0);
if (maybe_elms_obj == NULL) return CallJsBuiltin(isolate, "ArrayPop", args); if (maybe_elms_obj == NULL) return CallJsBuiltin(isolate, "ArrayPop", args);
if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
} }
@ -551,7 +567,7 @@ BUILTIN(ArrayShift) {
Object* receiver = *args.receiver(); Object* receiver = *args.receiver();
Object* elms_obj; Object* elms_obj;
{ MaybeObject* maybe_elms_obj = { MaybeObject* maybe_elms_obj =
EnsureJSArrayWithWritableFastElements(heap, receiver); EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0);
if (maybe_elms_obj == NULL) if (maybe_elms_obj == NULL)
return CallJsBuiltin(isolate, "ArrayShift", args); return CallJsBuiltin(isolate, "ArrayShift", args);
if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
@ -593,7 +609,7 @@ BUILTIN(ArrayUnshift) {
Object* receiver = *args.receiver(); Object* receiver = *args.receiver();
Object* elms_obj; Object* elms_obj;
{ MaybeObject* maybe_elms_obj = { MaybeObject* maybe_elms_obj =
EnsureJSArrayWithWritableFastElements(heap, receiver); EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0);
if (maybe_elms_obj == NULL) if (maybe_elms_obj == NULL)
return CallJsBuiltin(isolate, "ArrayUnshift", args); return CallJsBuiltin(isolate, "ArrayUnshift", args);
if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
@ -612,11 +628,9 @@ BUILTIN(ArrayUnshift) {
// we should never hit this case. // we should never hit this case.
ASSERT(to_add <= (Smi::kMaxValue - len)); ASSERT(to_add <= (Smi::kMaxValue - len));
if (FLAG_smi_only_arrays) {
MaybeObject* maybe_object = MaybeObject* maybe_object =
array->EnsureCanContainElements(&args, 1, to_add); array->EnsureCanContainElements(&args, 1, to_add);
if (maybe_object->IsFailure()) return maybe_object; if (maybe_object->IsFailure()) return maybe_object;
}
if (new_length > elms->length()) { if (new_length > elms->length()) {
// New backing storage is needed. // New backing storage is needed.
@ -745,11 +759,9 @@ BUILTIN(ArraySlice) {
} }
FixedArray* result_elms = FixedArray::cast(result); FixedArray* result_elms = FixedArray::cast(result);
if (FLAG_smi_only_arrays) {
MaybeObject* maybe_object = MaybeObject* maybe_object =
result_array->EnsureCanContainElements(result_elms); result_array->EnsureCanContainElements(result_elms);
if (maybe_object->IsFailure()) return maybe_object; if (maybe_object->IsFailure()) return maybe_object;
}
AssertNoAllocation no_gc; AssertNoAllocation no_gc;
CopyElements(heap, &no_gc, result_elms, 0, elms, k, result_len); CopyElements(heap, &no_gc, result_elms, 0, elms, k, result_len);
@ -768,7 +780,7 @@ BUILTIN(ArraySplice) {
Object* receiver = *args.receiver(); Object* receiver = *args.receiver();
Object* elms_obj; Object* elms_obj;
{ MaybeObject* maybe_elms_obj = { MaybeObject* maybe_elms_obj =
EnsureJSArrayWithWritableFastElements(heap, receiver); EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 3);
if (maybe_elms_obj == NULL) if (maybe_elms_obj == NULL)
return CallJsBuiltin(isolate, "ArraySplice", args); return CallJsBuiltin(isolate, "ArraySplice", args);
if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj;
@ -855,12 +867,6 @@ BUILTIN(ArraySplice) {
} }
int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0;
if (FLAG_smi_only_arrays) {
MaybeObject* maybe = array->EnsureCanContainElements(&args, 3, item_count);
if (maybe->IsFailure()) return maybe;
}
int new_length = len - actual_delete_count + item_count; int new_length = len - actual_delete_count + item_count;
bool elms_changed = false; bool elms_changed = false;
@ -997,15 +1003,13 @@ BUILTIN(ArrayConcat) {
} }
FixedArray* result_elms = FixedArray::cast(result); FixedArray* result_elms = FixedArray::cast(result);
if (FLAG_smi_only_arrays) { // Ensure element type transitions happen before copying elements in.
if (result_array->HasFastSmiOnlyElements()) {
for (int i = 0; i < n_arguments; i++) { for (int i = 0; i < n_arguments; i++) {
JSArray* array = JSArray::cast(args[i]); JSArray* array = JSArray::cast(args[i]);
int len = Smi::cast(array->length())->value(); if (!array->HasFastSmiOnlyElements()) {
if (len > 0) { result_array->EnsureCanContainNonSmiElements();
FixedArray* elms = FixedArray::cast(array->elements()); break;
MaybeObject* maybe_object =
result_array->EnsureCanContainElements(elms);
if (maybe_object->IsFailure()) return maybe_object;
} }
} }
} }

View File

@ -3346,7 +3346,6 @@ void HGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
HValue* key = AddInstruction( HValue* key = AddInstruction(
new(zone()) HConstant(Handle<Object>(Smi::FromInt(i)), new(zone()) HConstant(Handle<Object>(Smi::FromInt(i)),
Representation::Integer32())); Representation::Integer32()));
if (FLAG_smi_only_arrays) {
HInstruction* elements_kind = HInstruction* elements_kind =
AddInstruction(new(zone()) HElementsKind(literal)); AddInstruction(new(zone()) HElementsKind(literal));
HBasicBlock* store_fast = graph()->CreateBasicBlock(); HBasicBlock* store_fast = graph()->CreateBasicBlock();
@ -3383,9 +3382,6 @@ void HGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
join->SetJoinId(expr->id()); join->SetJoinId(expr->id());
set_current_block(join); set_current_block(join);
} else {
AddInstruction(new(zone()) HStoreKeyedFastElement(elements, key, value));
}
AddSimulate(expr->GetIdForElement(i)); AddSimulate(expr->GetIdForElement(i));
} }

View File

@ -1505,12 +1505,10 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
kDontSaveFPRegs, kDontSaveFPRegs,
EMIT_REMEMBERED_SET, EMIT_REMEMBERED_SET,
OMIT_SMI_CHECK); OMIT_SMI_CHECK);
if (FLAG_smi_only_arrays) {
__ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset));
__ CheckFastSmiOnlyElements(edi, &no_map_change, Label::kNear); __ CheckFastSmiOnlyElements(edi, &no_map_change, Label::kNear);
__ push(Operand(esp, 0)); __ push(Operand(esp, 0));
__ CallRuntime(Runtime::kNonSmiElementStored, 1); __ CallRuntime(Runtime::kNonSmiElementStored, 1);
}
__ bind(&no_map_change); __ bind(&no_map_change);
PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);

View File

@ -833,11 +833,9 @@ void KeyedStoreIC::GenerateGeneric(MacroAssembler* masm,
__ ret(0); __ ret(0);
__ bind(&non_smi_value); __ bind(&non_smi_value);
if (FLAG_smi_only_arrays) {
// Escape to slow case when writing non-smi into smi-only array. // Escape to slow case when writing non-smi into smi-only array.
__ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset));
__ CheckFastObjectElements(edi, &slow, Label::kNear); __ CheckFastObjectElements(edi, &slow, Label::kNear);
}
// Fast elements array, store the value to the elements backing store. // Fast elements array, store the value to the elements backing store.
__ mov(CodeGenerator::FixedArrayElementOperand(ebx, ecx), eax); __ mov(CodeGenerator::FixedArrayElementOperand(ebx, ecx), eax);

View File

@ -1486,10 +1486,8 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
__ bind(&with_write_barrier); __ bind(&with_write_barrier);
if (FLAG_smi_only_arrays) {
__ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset));
__ CheckFastObjectElements(edi, &call_builtin); __ CheckFastObjectElements(edi, &call_builtin);
}
// Save new length. // Save new length.
__ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax);
@ -1511,7 +1509,6 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
} }
__ mov(edi, Operand(esp, argc * kPointerSize)); __ mov(edi, Operand(esp, argc * kPointerSize));
if (FLAG_smi_only_arrays) {
// Growing elements that are SMI-only requires special handling in case // Growing elements that are SMI-only requires special handling in case
// the new element is non-Smi. For now, delegate to the builtin. // the new element is non-Smi. For now, delegate to the builtin.
Label no_fast_elements_check; Label no_fast_elements_check;
@ -1519,7 +1516,6 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
__ mov(esi, FieldOperand(edx, HeapObject::kMapOffset)); __ mov(esi, FieldOperand(edx, HeapObject::kMapOffset));
__ CheckFastObjectElements(esi, &call_builtin, Label::kFar); __ CheckFastObjectElements(esi, &call_builtin, Label::kFar);
__ bind(&no_fast_elements_check); __ bind(&no_fast_elements_check);
}
// We could be lucky and the elements array could be at the top of // We could be lucky and the elements array could be at the top of
// new-space. In this case we can just grow it in place by moving the // new-space. In this case we can just grow it in place by moving the

View File

@ -1306,8 +1306,7 @@ FixedArrayBase* JSObject::elements() {
void JSObject::ValidateSmiOnlyElements() { void JSObject::ValidateSmiOnlyElements() {
#if DEBUG #if DEBUG
if (FLAG_smi_only_arrays && if (map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS) {
map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS) {
Heap* heap = GetHeap(); Heap* heap = GetHeap();
// Don't use elements, since integrity checks will fail if there // Don't use elements, since integrity checks will fail if there
// are filler pointers in the array. // are filler pointers in the array.
@ -1332,8 +1331,7 @@ MaybeObject* JSObject::EnsureCanContainNonSmiElements() {
#if DEBUG #if DEBUG
ValidateSmiOnlyElements(); ValidateSmiOnlyElements();
#endif #endif
if (FLAG_smi_only_arrays && if ((map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS)) {
(map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS)) {
Object* obj; Object* obj;
MaybeObject* maybe_obj = GetElementsTransitionMap(FAST_ELEMENTS); MaybeObject* maybe_obj = GetElementsTransitionMap(FAST_ELEMENTS);
if (!maybe_obj->ToObject(&obj)) return maybe_obj; if (!maybe_obj->ToObject(&obj)) return maybe_obj;
@ -1345,8 +1343,7 @@ MaybeObject* JSObject::EnsureCanContainNonSmiElements() {
MaybeObject* JSObject::EnsureCanContainElements(Object** objects, MaybeObject* JSObject::EnsureCanContainElements(Object** objects,
uint32_t count) { uint32_t count) {
if (FLAG_smi_only_arrays && if (map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS) {
map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS) {
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
Object* current = *objects++; Object* current = *objects++;
if (!current->IsSmi() && current != GetHeap()->the_hole_value()) { if (!current->IsSmi() && current != GetHeap()->the_hole_value()) {
@ -1359,13 +1356,9 @@ MaybeObject* JSObject::EnsureCanContainElements(Object** objects,
MaybeObject* JSObject::EnsureCanContainElements(FixedArray* elements) { MaybeObject* JSObject::EnsureCanContainElements(FixedArray* elements) {
if (FLAG_smi_only_arrays) {
Object** objects = reinterpret_cast<Object**>( Object** objects = reinterpret_cast<Object**>(
FIELD_ADDR(elements, elements->OffsetOfElementAt(0))); FIELD_ADDR(elements, elements->OffsetOfElementAt(0)));
return EnsureCanContainElements(objects, elements->length()); return EnsureCanContainElements(objects, elements->length());
} else {
return this;
}
} }

View File

@ -7765,7 +7765,6 @@ MaybeObject* JSObject::SetFastElementsCapacityAndLength(
if (elements()->map() != heap->non_strict_arguments_elements_map()) { if (elements()->map() != heap->non_strict_arguments_elements_map()) {
Object* object; Object* object;
bool has_fast_smi_only_elements = bool has_fast_smi_only_elements =
FLAG_smi_only_arrays &&
(set_capacity_mode == kAllowSmiOnlyElements) && (set_capacity_mode == kAllowSmiOnlyElements) &&
(elements()->map()->has_fast_smi_only_elements() || (elements()->map()->has_fast_smi_only_elements() ||
elements() == heap->empty_fixed_array()); elements() == heap->empty_fixed_array());

View File

@ -422,6 +422,9 @@ static Handle<Object> CreateObjectLiteralBoilerplate(
} }
static const int kSmiOnlyLiteralMinimumLength = 1024;
static Handle<Object> CreateArrayLiteralBoilerplate( static Handle<Object> CreateArrayLiteralBoilerplate(
Isolate* isolate, Isolate* isolate,
Handle<FixedArray> literals, Handle<FixedArray> literals,
@ -431,6 +434,13 @@ static Handle<Object> CreateArrayLiteralBoilerplate(
JSFunction::GlobalContextFromLiterals(*literals)->array_function()); JSFunction::GlobalContextFromLiterals(*literals)->array_function());
Handle<Object> object = isolate->factory()->NewJSObject(constructor); Handle<Object> object = isolate->factory()->NewJSObject(constructor);
if (elements->length() > kSmiOnlyLiteralMinimumLength) {
Handle<Map> smi_array_map = isolate->factory()->GetElementsTransitionMap(
Handle<JSObject>::cast(object),
FAST_SMI_ONLY_ELEMENTS);
HeapObject::cast(*object)->set_map(*smi_array_map);
}
const bool is_cow = const bool is_cow =
(elements->map() == isolate->heap()->fixed_cow_array_map()); (elements->map() == isolate->heap()->fixed_cow_array_map());
Handle<FixedArray> copied_elements = Handle<FixedArray> copied_elements =
@ -440,7 +450,6 @@ static Handle<Object> CreateArrayLiteralBoilerplate(
bool has_non_smi = false; bool has_non_smi = false;
if (is_cow) { if (is_cow) {
// Copy-on-write arrays must be shallow (and simple). // Copy-on-write arrays must be shallow (and simple).
if (FLAG_smi_only_arrays) {
for (int i = 0; i < content->length(); i++) { for (int i = 0; i < content->length(); i++) {
Object* current = content->get(i); Object* current = content->get(i);
ASSERT(!current->IsFixedArray()); ASSERT(!current->IsFixedArray());
@ -448,13 +457,11 @@ static Handle<Object> CreateArrayLiteralBoilerplate(
has_non_smi = true; has_non_smi = true;
} }
} }
} else {
#if DEBUG #if DEBUG
for (int i = 0; i < content->length(); i++) { for (int i = 0; i < content->length(); i++) {
ASSERT(!content->get(i)->IsFixedArray()); ASSERT(!content->get(i)->IsFixedArray());
} }
#endif #endif
}
} else { } else {
for (int i = 0; i < content->length(); i++) { for (int i = 0; i < content->length(); i++) {
Object* current = content->get(i); Object* current = content->get(i);
@ -479,11 +486,9 @@ static Handle<Object> CreateArrayLiteralBoilerplate(
Handle<JSArray> js_object(Handle<JSArray>::cast(object)); Handle<JSArray> js_object(Handle<JSArray>::cast(object));
isolate->factory()->SetContent(js_object, content); isolate->factory()->SetContent(js_object, content);
if (FLAG_smi_only_arrays) {
if (has_non_smi && js_object->HasFastSmiOnlyElements()) { if (has_non_smi && js_object->HasFastSmiOnlyElements()) {
isolate->factory()->EnsureCanContainNonSmiElements(js_object); isolate->factory()->EnsureCanContainNonSmiElements(js_object);
} }
}
return object; return object;
} }
@ -1661,7 +1666,7 @@ RUNTIME_FUNCTION(MaybeObject*,
RUNTIME_FUNCTION(MaybeObject*, Runtime_NonSmiElementStored) { RUNTIME_FUNCTION(MaybeObject*, Runtime_NonSmiElementStored) {
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_ARG_CHECKED(JSObject, object, 0); CONVERT_ARG_CHECKED(JSObject, object, 0);
if (FLAG_smi_only_arrays && object->HasFastSmiOnlyElements()) { if (object->HasFastSmiOnlyElements()) {
MaybeObject* maybe_map = object->GetElementsTransitionMap(FAST_ELEMENTS); MaybeObject* maybe_map = object->GetElementsTransitionMap(FAST_ELEMENTS);
Map* map; Map* map;
if (!maybe_map->To<Map>(&map)) return maybe_map; if (!maybe_map->To<Map>(&map)) return maybe_map;

View File

@ -1473,12 +1473,10 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
kDontSaveFPRegs, kDontSaveFPRegs,
EMIT_REMEMBERED_SET, EMIT_REMEMBERED_SET,
OMIT_SMI_CHECK); OMIT_SMI_CHECK);
if (FLAG_smi_only_arrays) {
__ movq(rdi, FieldOperand(rbx, JSObject::kMapOffset)); __ movq(rdi, FieldOperand(rbx, JSObject::kMapOffset));
__ CheckFastSmiOnlyElements(rdi, &no_map_change, Label::kNear); __ CheckFastSmiOnlyElements(rdi, &no_map_change, Label::kNear);
__ push(r8); __ push(r8);
__ CallRuntime(Runtime::kNonSmiElementStored, 1); __ CallRuntime(Runtime::kNonSmiElementStored, 1);
}
__ bind(&no_map_change); __ bind(&no_map_change);
PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);

View File

@ -709,11 +709,9 @@ void KeyedStoreIC::GenerateGeneric(MacroAssembler* masm,
__ ret(0); __ ret(0);
__ bind(&non_smi_value); __ bind(&non_smi_value);
if (FLAG_smi_only_arrays) {
// Writing a non-smi, check whether array allows non-smi elements. // Writing a non-smi, check whether array allows non-smi elements.
// r9: receiver's map // r9: receiver's map
__ CheckFastObjectElements(r9, &slow, Label::kNear); __ CheckFastObjectElements(r9, &slow, Label::kNear);
}
__ lea(rcx, __ lea(rcx,
FieldOperand(rbx, rcx, times_pointer_size, FixedArray::kHeaderSize)); FieldOperand(rbx, rcx, times_pointer_size, FixedArray::kHeaderSize));
__ movq(Operand(rcx, 0), rax); __ movq(Operand(rcx, 0), rax);

View File

@ -1460,10 +1460,8 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
__ bind(&with_write_barrier); __ bind(&with_write_barrier);
if (FLAG_smi_only_arrays) {
__ movq(rdi, FieldOperand(rdx, HeapObject::kMapOffset)); __ movq(rdi, FieldOperand(rdx, HeapObject::kMapOffset));
__ CheckFastObjectElements(rdi, &call_builtin); __ CheckFastObjectElements(rdi, &call_builtin);
}
// Save new length. // Save new length.
__ Integer32ToSmiField(FieldOperand(rdx, JSArray::kLengthOffset), rax); __ Integer32ToSmiField(FieldOperand(rdx, JSArray::kLengthOffset), rax);
@ -1486,7 +1484,6 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
} }
__ movq(rdi, Operand(rsp, argc * kPointerSize)); __ movq(rdi, Operand(rsp, argc * kPointerSize));
if (FLAG_smi_only_arrays) {
// Growing elements that are SMI-only requires special handling in case // Growing elements that are SMI-only requires special handling in case
// the new element is non-Smi. For now, delegate to the builtin. // the new element is non-Smi. For now, delegate to the builtin.
Label no_fast_elements_check; Label no_fast_elements_check;
@ -1494,7 +1491,6 @@ MaybeObject* CallStubCompiler::CompileArrayPushCall(Object* object,
__ movq(rsi, FieldOperand(rdx, HeapObject::kMapOffset)); __ movq(rsi, FieldOperand(rdx, HeapObject::kMapOffset));
__ CheckFastObjectElements(rsi, &call_builtin, Label::kFar); __ CheckFastObjectElements(rsi, &call_builtin, Label::kFar);
__ bind(&no_fast_elements_check); __ bind(&no_fast_elements_check);
}
ExternalReference new_space_allocation_top = ExternalReference new_space_allocation_top =
ExternalReference::new_space_allocation_top_address(isolate()); ExternalReference::new_space_allocation_top_address(isolate());