| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1642 | 1642 |
| 1643 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1643 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1644 Comment cmnt(masm_, "[ ArrayLiteral"); | 1644 Comment cmnt(masm_, "[ ArrayLiteral"); |
| 1645 | 1645 |
| 1646 ZoneList<Expression*>* subexprs = expr->values(); | 1646 ZoneList<Expression*>* subexprs = expr->values(); |
| 1647 int length = subexprs->length(); | 1647 int length = subexprs->length(); |
| 1648 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1648 Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1649 ASSERT_EQ(2, constant_elements->length()); | 1649 ASSERT_EQ(2, constant_elements->length()); |
| 1650 ElementsKind constant_elements_kind = | 1650 ElementsKind constant_elements_kind = |
| 1651 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | 1651 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1652 bool has_constant_fast_elements = constant_elements_kind == FAST_ELEMENTS; | 1652 bool has_constant_fast_elements = |
| 1653 IsFastObjectElementsKind(constant_elements_kind); |
| 1653 Handle<FixedArrayBase> constant_elements_values( | 1654 Handle<FixedArrayBase> constant_elements_values( |
| 1654 FixedArrayBase::cast(constant_elements->get(1))); | 1655 FixedArrayBase::cast(constant_elements->get(1))); |
| 1655 | 1656 |
| 1656 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1657 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1657 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1658 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1658 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1659 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1659 __ push(Immediate(constant_elements)); | 1660 __ push(Immediate(constant_elements)); |
| 1660 Heap* heap = isolate()->heap(); | 1661 Heap* heap = isolate()->heap(); |
| 1661 if (has_constant_fast_elements && | 1662 if (has_constant_fast_elements && |
| 1662 constant_elements_values->map() == heap->fixed_cow_array_map()) { | 1663 constant_elements_values->map() == heap->fixed_cow_array_map()) { |
| 1663 // If the elements are already FAST_ELEMENTS, the boilerplate cannot | 1664 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
| 1664 // change, so it's possible to specialize the stub in advance. | 1665 // change, so it's possible to specialize the stub in advance. |
| 1665 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); | 1666 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
| 1666 FastCloneShallowArrayStub stub( | 1667 FastCloneShallowArrayStub stub( |
| 1667 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, | 1668 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
| 1668 length); | 1669 length); |
| 1669 __ CallStub(&stub); | 1670 __ CallStub(&stub); |
| 1670 } else if (expr->depth() > 1) { | 1671 } else if (expr->depth() > 1) { |
| 1671 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1672 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
| 1672 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1673 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 1673 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1674 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
| 1674 } else { | 1675 } else { |
| 1675 ASSERT(constant_elements_kind == FAST_ELEMENTS || | 1676 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
| 1676 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || | |
| 1677 FLAG_smi_only_arrays); | 1677 FLAG_smi_only_arrays); |
| 1678 // If the elements are already FAST_ELEMENTS, the boilerplate cannot | 1678 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
| 1679 // change, so it's possible to specialize the stub in advance. | 1679 // change, so it's possible to specialize the stub in advance. |
| 1680 FastCloneShallowArrayStub::Mode mode = has_constant_fast_elements | 1680 FastCloneShallowArrayStub::Mode mode = has_constant_fast_elements |
| 1681 ? FastCloneShallowArrayStub::CLONE_ELEMENTS | 1681 ? FastCloneShallowArrayStub::CLONE_ELEMENTS |
| 1682 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; | 1682 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
| 1683 FastCloneShallowArrayStub stub(mode, length); | 1683 FastCloneShallowArrayStub stub(mode, length); |
| 1684 __ CallStub(&stub); | 1684 __ CallStub(&stub); |
| 1685 } | 1685 } |
| 1686 | 1686 |
| 1687 bool result_saved = false; // Is the result saved to the stack? | 1687 bool result_saved = false; // Is the result saved to the stack? |
| 1688 | 1688 |
| 1689 // Emit code to evaluate all the non-constant subexpressions and to store | 1689 // Emit code to evaluate all the non-constant subexpressions and to store |
| 1690 // them into the newly cloned array. | 1690 // them into the newly cloned array. |
| 1691 for (int i = 0; i < length; i++) { | 1691 for (int i = 0; i < length; i++) { |
| 1692 Expression* subexpr = subexprs->at(i); | 1692 Expression* subexpr = subexprs->at(i); |
| 1693 // If the subexpression is a literal or a simple materialized literal it | 1693 // If the subexpression is a literal or a simple materialized literal it |
| 1694 // is already set in the cloned array. | 1694 // is already set in the cloned array. |
| 1695 if (subexpr->AsLiteral() != NULL || | 1695 if (subexpr->AsLiteral() != NULL || |
| 1696 CompileTimeValue::IsCompileTimeValue(subexpr)) { | 1696 CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1697 continue; | 1697 continue; |
| 1698 } | 1698 } |
| 1699 | 1699 |
| 1700 if (!result_saved) { | 1700 if (!result_saved) { |
| 1701 __ push(eax); | 1701 __ push(eax); |
| 1702 result_saved = true; | 1702 result_saved = true; |
| 1703 } | 1703 } |
| 1704 VisitForAccumulatorValue(subexpr); | 1704 VisitForAccumulatorValue(subexpr); |
| 1705 | 1705 |
| 1706 if (constant_elements_kind == FAST_ELEMENTS) { | 1706 if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1707 // Fast-case array literal with ElementsKind of FAST_ELEMENTS, they cannot | 1707 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1708 // transition and don't need to call the runtime stub. | 1708 // cannot transition and don't need to call the runtime stub. |
| 1709 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1709 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1710 __ mov(ebx, Operand(esp, 0)); // Copy of array literal. | 1710 __ mov(ebx, Operand(esp, 0)); // Copy of array literal. |
| 1711 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); | 1711 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1712 // Store the subexpression value in the array's elements. | 1712 // Store the subexpression value in the array's elements. |
| 1713 __ mov(FieldOperand(ebx, offset), result_register()); | 1713 __ mov(FieldOperand(ebx, offset), result_register()); |
| 1714 // Update the write barrier for the array store. | 1714 // Update the write barrier for the array store. |
| 1715 __ RecordWriteField(ebx, offset, result_register(), ecx, | 1715 __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1716 kDontSaveFPRegs, | 1716 kDontSaveFPRegs, |
| 1717 EMIT_REMEMBERED_SET, | 1717 EMIT_REMEMBERED_SET, |
| 1718 INLINE_SMI_CHECK); | 1718 INLINE_SMI_CHECK); |
| (...skipping 2892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4611 *context_length = 0; | 4611 *context_length = 0; |
| 4612 return previous_; | 4612 return previous_; |
| 4613 } | 4613 } |
| 4614 | 4614 |
| 4615 | 4615 |
| 4616 #undef __ | 4616 #undef __ |
| 4617 | 4617 |
| 4618 } } // namespace v8::internal | 4618 } } // namespace v8::internal |
| 4619 | 4619 |
| 4620 #endif // V8_TARGET_ARCH_IA32 | 4620 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |