OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 | 1529 |
1530 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1530 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
1531 Comment cmnt(masm_, "[ ArrayLiteral"); | 1531 Comment cmnt(masm_, "[ ArrayLiteral"); |
1532 | 1532 |
1533 ZoneList<Expression*>* subexprs = expr->values(); | 1533 ZoneList<Expression*>* subexprs = expr->values(); |
1534 int length = subexprs->length(); | 1534 int length = subexprs->length(); |
1535 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1535 Handle<FixedArray> constant_elements = expr->constant_elements(); |
1536 ASSERT_EQ(2, constant_elements->length()); | 1536 ASSERT_EQ(2, constant_elements->length()); |
1537 ElementsKind constant_elements_kind = | 1537 ElementsKind constant_elements_kind = |
1538 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | 1538 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1539 bool has_fast_elements = constant_elements_kind == FAST_ELEMENTS; |
1539 Handle<FixedArrayBase> constant_elements_values( | 1540 Handle<FixedArrayBase> constant_elements_values( |
1540 FixedArrayBase::cast(constant_elements->get(1))); | 1541 FixedArrayBase::cast(constant_elements->get(1))); |
1541 | 1542 |
1542 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 1543 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
1543 __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); | 1544 __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
1544 __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); | 1545 __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); |
1545 __ mov(r1, Operand(constant_elements)); | 1546 __ mov(r1, Operand(constant_elements)); |
1546 __ Push(r3, r2, r1); | 1547 __ Push(r3, r2, r1); |
1547 if (constant_elements_values->map() == | 1548 if (has_fast_elements && constant_elements_values->map() == |
1548 isolate()->heap()->fixed_cow_array_map()) { | 1549 isolate()->heap()->fixed_cow_array_map()) { |
1549 FastCloneShallowArrayStub stub( | 1550 FastCloneShallowArrayStub stub( |
1550 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); | 1551 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
1551 __ CallStub(&stub); | 1552 __ CallStub(&stub); |
1552 __ IncrementCounter( | 1553 __ IncrementCounter( |
1553 isolate()->counters()->cow_arrays_created_stub(), 1, r1, r2); | 1554 isolate()->counters()->cow_arrays_created_stub(), 1, r1, r2); |
1554 } else if (expr->depth() > 1) { | 1555 } else if (expr->depth() > 1) { |
1555 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1556 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
1556 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1557 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
1557 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1558 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
1558 } else { | 1559 } else { |
1559 ASSERT(constant_elements_kind == FAST_ELEMENTS || | 1560 ASSERT(constant_elements_kind == FAST_ELEMENTS || |
1560 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || | 1561 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || |
1561 FLAG_smi_only_arrays); | 1562 FLAG_smi_only_arrays); |
1562 FastCloneShallowArrayStub::Mode mode = | 1563 FastCloneShallowArrayStub::Mode mode = has_fast_elements |
1563 constant_elements_kind == FAST_DOUBLE_ELEMENTS | 1564 ? FastCloneShallowArrayStub::CLONE_ELEMENTS |
1564 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | 1565 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
1565 : FastCloneShallowArrayStub::CLONE_ELEMENTS; | |
1566 FastCloneShallowArrayStub stub(mode, length); | 1566 FastCloneShallowArrayStub stub(mode, length); |
1567 __ CallStub(&stub); | 1567 __ CallStub(&stub); |
1568 } | 1568 } |
1569 | 1569 |
1570 bool result_saved = false; // Is the result saved to the stack? | 1570 bool result_saved = false; // Is the result saved to the stack? |
1571 | 1571 |
1572 // Emit code to evaluate all the non-constant subexpressions and to store | 1572 // Emit code to evaluate all the non-constant subexpressions and to store |
1573 // them into the newly cloned array. | 1573 // them into the newly cloned array. |
1574 for (int i = 0; i < length; i++) { | 1574 for (int i = 0; i < length; i++) { |
1575 Expression* subexpr = subexprs->at(i); | 1575 Expression* subexpr = subexprs->at(i); |
1576 // If the subexpression is a literal or a simple materialized literal it | 1576 // If the subexpression is a literal or a simple materialized literal it |
1577 // is already set in the cloned array. | 1577 // is already set in the cloned array. |
1578 if (subexpr->AsLiteral() != NULL || | 1578 if (subexpr->AsLiteral() != NULL || |
1579 CompileTimeValue::IsCompileTimeValue(subexpr)) { | 1579 CompileTimeValue::IsCompileTimeValue(subexpr)) { |
1580 continue; | 1580 continue; |
1581 } | 1581 } |
1582 | 1582 |
1583 if (!result_saved) { | 1583 if (!result_saved) { |
1584 __ push(r0); | 1584 __ push(r0); |
1585 result_saved = true; | 1585 result_saved = true; |
1586 } | 1586 } |
1587 VisitForAccumulatorValue(subexpr); | 1587 VisitForAccumulatorValue(subexpr); |
1588 | 1588 |
1589 __ ldr(r1, MemOperand(sp)); // Copy of array literal. | 1589 if (constant_elements_kind == FAST_ELEMENTS) { |
1590 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset)); | 1590 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
1591 __ mov(r3, Operand(Smi::FromInt(i))); | 1591 __ ldr(r6, MemOperand(sp)); // Copy of array literal. |
1592 __ mov(r4, Operand(Smi::FromInt(expr->literal_index()))); | 1592 __ ldr(r1, FieldMemOperand(r6, JSObject::kElementsOffset)); |
1593 StoreArrayLiteralElementStub stub; | 1593 __ str(result_register(), FieldMemOperand(r1, offset)); |
1594 __ CallStub(&stub); | 1594 // Update the write barrier for the array store. |
| 1595 __ RecordWriteField(r1, offset, result_register(), r2, |
| 1596 kLRHasBeenSaved, kDontSaveFPRegs, |
| 1597 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); |
| 1598 } else { |
| 1599 __ ldr(r1, MemOperand(sp)); // Copy of array literal. |
| 1600 __ ldr(r2, FieldMemOperand(r1, JSObject::kMapOffset)); |
| 1601 __ mov(r3, Operand(Smi::FromInt(i))); |
| 1602 __ mov(r4, Operand(Smi::FromInt(expr->literal_index()))); |
| 1603 StoreArrayLiteralElementStub stub; |
| 1604 __ CallStub(&stub); |
| 1605 } |
1595 | 1606 |
1596 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); | 1607 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
1597 } | 1608 } |
1598 | 1609 |
1599 if (result_saved) { | 1610 if (result_saved) { |
1600 context()->PlugTOS(); | 1611 context()->PlugTOS(); |
1601 } else { | 1612 } else { |
1602 context()->Plug(r0); | 1613 context()->Plug(r0); |
1603 } | 1614 } |
1604 } | 1615 } |
(...skipping 2770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4375 *context_length = 0; | 4386 *context_length = 0; |
4376 return previous_; | 4387 return previous_; |
4377 } | 4388 } |
4378 | 4389 |
4379 | 4390 |
4380 #undef __ | 4391 #undef __ |
4381 | 4392 |
4382 } } // namespace v8::internal | 4393 } } // namespace v8::internal |
4383 | 4394 |
4384 #endif // V8_TARGET_ARCH_ARM | 4395 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |