| 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 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 | 1652 |
| 1653 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1653 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1654 Comment cmnt(masm_, "[ ArrayLiteral"); | 1654 Comment cmnt(masm_, "[ ArrayLiteral"); |
| 1655 | 1655 |
| 1656 ZoneList<Expression*>* subexprs = expr->values(); | 1656 ZoneList<Expression*>* subexprs = expr->values(); |
| 1657 int length = subexprs->length(); | 1657 int length = subexprs->length(); |
| 1658 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1658 Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1659 ASSERT_EQ(2, constant_elements->length()); | 1659 ASSERT_EQ(2, constant_elements->length()); |
| 1660 ElementsKind constant_elements_kind = | 1660 ElementsKind constant_elements_kind = |
| 1661 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | 1661 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1662 bool has_constant_fast_elements = constant_elements_kind == FAST_ELEMENTS; | 1662 bool has_constant_fast_elements = |
| 1663 IsFastObjectElementsKind(constant_elements_kind); |
| 1663 Handle<FixedArrayBase> constant_elements_values( | 1664 Handle<FixedArrayBase> constant_elements_values( |
| 1664 FixedArrayBase::cast(constant_elements->get(1))); | 1665 FixedArrayBase::cast(constant_elements->get(1))); |
| 1665 | 1666 |
| 1666 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1667 __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1667 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); | 1668 __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
| 1668 __ Push(Smi::FromInt(expr->literal_index())); | 1669 __ Push(Smi::FromInt(expr->literal_index())); |
| 1669 __ Push(constant_elements); | 1670 __ Push(constant_elements); |
| 1670 Heap* heap = isolate()->heap(); | 1671 Heap* heap = isolate()->heap(); |
| 1671 if (has_constant_fast_elements && | 1672 if (has_constant_fast_elements && |
| 1672 constant_elements_values->map() == heap->fixed_cow_array_map()) { | 1673 constant_elements_values->map() == heap->fixed_cow_array_map()) { |
| 1673 // If the elements are already FAST_ELEMENTS, the boilerplate cannot | 1674 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
| 1674 // change, so it's possible to specialize the stub in advance. | 1675 // change, so it's possible to specialize the stub in advance. |
| 1675 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); | 1676 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
| 1676 FastCloneShallowArrayStub stub( | 1677 FastCloneShallowArrayStub stub( |
| 1677 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, | 1678 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
| 1678 length); | 1679 length); |
| 1679 __ CallStub(&stub); | 1680 __ CallStub(&stub); |
| 1680 } else if (expr->depth() > 1) { | 1681 } else if (expr->depth() > 1) { |
| 1681 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1682 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
| 1682 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1683 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 1683 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1684 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
| 1684 } else { | 1685 } else { |
| 1685 ASSERT(constant_elements_kind == FAST_ELEMENTS || | 1686 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
| 1686 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || | |
| 1687 FLAG_smi_only_arrays); | 1687 FLAG_smi_only_arrays); |
| 1688 // If the elements are already FAST_ELEMENTS, the boilerplate cannot | 1688 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
| 1689 // change, so it's possible to specialize the stub in advance. | 1689 // change, so it's possible to specialize the stub in advance. |
| 1690 FastCloneShallowArrayStub::Mode mode = has_constant_fast_elements | 1690 FastCloneShallowArrayStub::Mode mode = has_constant_fast_elements |
| 1691 ? FastCloneShallowArrayStub::CLONE_ELEMENTS | 1691 ? FastCloneShallowArrayStub::CLONE_ELEMENTS |
| 1692 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; | 1692 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
| 1693 FastCloneShallowArrayStub stub(mode, length); | 1693 FastCloneShallowArrayStub stub(mode, length); |
| 1694 __ CallStub(&stub); | 1694 __ CallStub(&stub); |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 bool result_saved = false; // Is the result saved to the stack? | 1697 bool result_saved = false; // Is the result saved to the stack? |
| 1698 | 1698 |
| 1699 // Emit code to evaluate all the non-constant subexpressions and to store | 1699 // Emit code to evaluate all the non-constant subexpressions and to store |
| 1700 // them into the newly cloned array. | 1700 // them into the newly cloned array. |
| 1701 for (int i = 0; i < length; i++) { | 1701 for (int i = 0; i < length; i++) { |
| 1702 Expression* subexpr = subexprs->at(i); | 1702 Expression* subexpr = subexprs->at(i); |
| 1703 // If the subexpression is a literal or a simple materialized literal it | 1703 // If the subexpression is a literal or a simple materialized literal it |
| 1704 // is already set in the cloned array. | 1704 // is already set in the cloned array. |
| 1705 if (subexpr->AsLiteral() != NULL || | 1705 if (subexpr->AsLiteral() != NULL || |
| 1706 CompileTimeValue::IsCompileTimeValue(subexpr)) { | 1706 CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1707 continue; | 1707 continue; |
| 1708 } | 1708 } |
| 1709 | 1709 |
| 1710 if (!result_saved) { | 1710 if (!result_saved) { |
| 1711 __ push(rax); | 1711 __ push(rax); |
| 1712 result_saved = true; | 1712 result_saved = true; |
| 1713 } | 1713 } |
| 1714 VisitForAccumulatorValue(subexpr); | 1714 VisitForAccumulatorValue(subexpr); |
| 1715 | 1715 |
| 1716 if (constant_elements_kind == FAST_ELEMENTS) { | 1716 if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1717 // Fast-case array literal with ElementsKind of FAST_ELEMENTS, they cannot | 1717 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1718 // transition and don't need to call the runtime stub. | 1718 // cannot transition and don't need to call the runtime stub. |
| 1719 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1719 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1720 __ movq(rbx, Operand(rsp, 0)); // Copy of array literal. | 1720 __ movq(rbx, Operand(rsp, 0)); // Copy of array literal. |
| 1721 __ movq(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); | 1721 __ movq(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); |
| 1722 // Store the subexpression value in the array's elements. | 1722 // Store the subexpression value in the array's elements. |
| 1723 __ movq(FieldOperand(rbx, offset), result_register()); | 1723 __ movq(FieldOperand(rbx, offset), result_register()); |
| 1724 // Update the write barrier for the array store. | 1724 // Update the write barrier for the array store. |
| 1725 __ RecordWriteField(rbx, offset, result_register(), rcx, | 1725 __ RecordWriteField(rbx, offset, result_register(), rcx, |
| 1726 kDontSaveFPRegs, | 1726 kDontSaveFPRegs, |
| 1727 EMIT_REMEMBERED_SET, | 1727 EMIT_REMEMBERED_SET, |
| 1728 INLINE_SMI_CHECK); | 1728 INLINE_SMI_CHECK); |
| (...skipping 2870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4599 *context_length = 0; | 4599 *context_length = 0; |
| 4600 return previous_; | 4600 return previous_; |
| 4601 } | 4601 } |
| 4602 | 4602 |
| 4603 | 4603 |
| 4604 #undef __ | 4604 #undef __ |
| 4605 | 4605 |
| 4606 } } // namespace v8::internal | 4606 } } // namespace v8::internal |
| 4607 | 4607 |
| 4608 #endif // V8_TARGET_ARCH_X64 | 4608 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |