OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_X87 | 7 #if V8_TARGET_ARCH_X87 |
8 | 8 |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 VisitForStackValue(expression); | 1604 VisitForStackValue(expression); |
1605 } | 1605 } |
1606 } | 1606 } |
1607 | 1607 |
1608 | 1608 |
1609 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | 1609 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
1610 Comment cmnt(masm_, "[ ObjectLiteral"); | 1610 Comment cmnt(masm_, "[ ObjectLiteral"); |
1611 | 1611 |
1612 expr->BuildConstantProperties(isolate()); | 1612 expr->BuildConstantProperties(isolate()); |
1613 Handle<FixedArray> constant_properties = expr->constant_properties(); | 1613 Handle<FixedArray> constant_properties = expr->constant_properties(); |
1614 int flags = expr->fast_elements() | 1614 int flags = expr->ComputeFlags(); |
1615 ? ObjectLiteral::kFastElements | 1615 // If any of the keys would store to the elements array, then we shouldn't |
1616 : ObjectLiteral::kNoFlags; | 1616 // allow it. |
1617 flags |= expr->has_function() | 1617 if (MustCreateObjectLiteralWithRuntime(expr)) { |
1618 ? ObjectLiteral::kHasFunction | |
1619 : ObjectLiteral::kNoFlags; | |
1620 int properties_count = constant_properties->length() / 2; | |
1621 if (expr->may_store_doubles() || expr->depth() > 1 || | |
1622 masm()->serializer_enabled() || | |
1623 flags != ObjectLiteral::kFastElements || | |
1624 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { | |
1625 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1618 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1626 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); | 1619 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
1627 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1620 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
1628 __ push(Immediate(constant_properties)); | 1621 __ push(Immediate(constant_properties)); |
1629 __ push(Immediate(Smi::FromInt(flags))); | 1622 __ push(Immediate(Smi::FromInt(flags))); |
1630 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); | 1623 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
1631 } else { | 1624 } else { |
1632 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1625 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1633 __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); | 1626 __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
1634 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); | 1627 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
1635 __ mov(ecx, Immediate(constant_properties)); | 1628 __ mov(ecx, Immediate(constant_properties)); |
1636 __ mov(edx, Immediate(Smi::FromInt(flags))); | 1629 __ mov(edx, Immediate(Smi::FromInt(flags))); |
1637 FastCloneShallowObjectStub stub(isolate(), properties_count); | 1630 FastCloneShallowObjectStub stub(isolate(), expr->properties_count()); |
1638 __ CallStub(&stub); | 1631 __ CallStub(&stub); |
1639 } | 1632 } |
1640 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | 1633 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
1641 | 1634 |
1642 // If result_saved is true the result is on top of the stack. If | 1635 // If result_saved is true the result is on top of the stack. If |
1643 // result_saved is false the result is in eax. | 1636 // result_saved is false the result is in eax. |
1644 bool result_saved = false; | 1637 bool result_saved = false; |
1645 | 1638 |
1646 // Mark all computed expressions that are bound to a key that | 1639 // Mark all computed expressions that are bound to a key that |
1647 // is shadowed by a later occurrence of the same key. For the | 1640 // is shadowed by a later occurrence of the same key. For the |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 } else { | 1799 } else { |
1807 context()->Plug(eax); | 1800 context()->Plug(eax); |
1808 } | 1801 } |
1809 } | 1802 } |
1810 | 1803 |
1811 | 1804 |
1812 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1805 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
1813 Comment cmnt(masm_, "[ ArrayLiteral"); | 1806 Comment cmnt(masm_, "[ ArrayLiteral"); |
1814 | 1807 |
1815 expr->BuildConstantElements(isolate()); | 1808 expr->BuildConstantElements(isolate()); |
1816 int flags = expr->depth() == 1 | |
1817 ? ArrayLiteral::kShallowElements | |
1818 : ArrayLiteral::kNoFlags; | |
1819 | |
1820 ZoneList<Expression*>* subexprs = expr->values(); | |
1821 int length = subexprs->length(); | |
1822 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1809 Handle<FixedArray> constant_elements = expr->constant_elements(); |
1823 DCHECK_EQ(2, constant_elements->length()); | |
1824 ElementsKind constant_elements_kind = | |
1825 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | |
1826 bool has_constant_fast_elements = | 1810 bool has_constant_fast_elements = |
1827 IsFastObjectElementsKind(constant_elements_kind); | 1811 IsFastObjectElementsKind(expr->constant_elements_kind()); |
1828 Handle<FixedArrayBase> constant_elements_values( | |
1829 FixedArrayBase::cast(constant_elements->get(1))); | |
1830 | 1812 |
1831 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; | 1813 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; |
1832 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { | 1814 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { |
1833 // If the only customer of allocation sites is transitioning, then | 1815 // If the only customer of allocation sites is transitioning, then |
1834 // we can turn it off if we don't have anywhere else to transition to. | 1816 // we can turn it off if we don't have anywhere else to transition to. |
1835 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; | 1817 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
1836 } | 1818 } |
1837 | 1819 |
1838 if (expr->depth() > 1 || length > JSObject::kInitialMaxFastElementArray) { | 1820 if (MustCreateArrayLiteralWithRuntime(expr)) { |
1839 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1821 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1840 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1822 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
1841 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1823 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
1842 __ push(Immediate(constant_elements)); | 1824 __ push(Immediate(constant_elements)); |
1843 __ push(Immediate(Smi::FromInt(flags))); | 1825 __ push(Immediate(Smi::FromInt(expr->ComputeFlags()))); |
1844 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); | 1826 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
1845 } else { | 1827 } else { |
1846 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1828 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1847 __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1829 __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
1848 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); | 1830 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
1849 __ mov(ecx, Immediate(constant_elements)); | 1831 __ mov(ecx, Immediate(constant_elements)); |
1850 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); | 1832 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); |
1851 __ CallStub(&stub); | 1833 __ CallStub(&stub); |
1852 } | 1834 } |
1853 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | 1835 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
1854 | 1836 |
1855 bool result_saved = false; // Is the result saved to the stack? | 1837 bool result_saved = false; // Is the result saved to the stack? |
| 1838 ZoneList<Expression*>* subexprs = expr->values(); |
| 1839 int length = subexprs->length(); |
1856 | 1840 |
1857 // Emit code to evaluate all the non-constant subexpressions and to store | 1841 // Emit code to evaluate all the non-constant subexpressions and to store |
1858 // them into the newly cloned array. | 1842 // them into the newly cloned array. |
1859 for (int i = 0; i < length; i++) { | 1843 for (int i = 0; i < length; i++) { |
1860 Expression* subexpr = subexprs->at(i); | 1844 Expression* subexpr = subexprs->at(i); |
1861 // If the subexpression is a literal or a simple materialized literal it | 1845 // If the subexpression is a literal or a simple materialized literal it |
1862 // is already set in the cloned array. | 1846 // is already set in the cloned array. |
1863 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; | 1847 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
1864 | 1848 |
1865 if (!result_saved) { | 1849 if (!result_saved) { |
1866 __ push(eax); // array literal. | 1850 __ push(eax); // array literal. |
1867 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1851 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
1868 result_saved = true; | 1852 result_saved = true; |
1869 } | 1853 } |
1870 VisitForAccumulatorValue(subexpr); | 1854 VisitForAccumulatorValue(subexpr); |
1871 | 1855 |
1872 if (IsFastObjectElementsKind(constant_elements_kind)) { | 1856 if (has_constant_fast_elements) { |
1873 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they | 1857 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
1874 // cannot transition and don't need to call the runtime stub. | 1858 // cannot transition and don't need to call the runtime stub. |
1875 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1859 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
1876 __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. | 1860 __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. |
1877 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); | 1861 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
1878 // Store the subexpression value in the array's elements. | 1862 // Store the subexpression value in the array's elements. |
1879 __ mov(FieldOperand(ebx, offset), result_register()); | 1863 __ mov(FieldOperand(ebx, offset), result_register()); |
1880 // Update the write barrier for the array store. | 1864 // Update the write barrier for the array store. |
1881 __ RecordWriteField(ebx, offset, result_register(), ecx, kDontSaveFPRegs, | 1865 __ RecordWriteField(ebx, offset, result_register(), ecx, kDontSaveFPRegs, |
1882 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); | 1866 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); |
(...skipping 3460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5343 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5327 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
5344 Assembler::target_address_at(call_target_address, | 5328 Assembler::target_address_at(call_target_address, |
5345 unoptimized_code)); | 5329 unoptimized_code)); |
5346 return OSR_AFTER_STACK_CHECK; | 5330 return OSR_AFTER_STACK_CHECK; |
5347 } | 5331 } |
5348 | 5332 |
5349 | 5333 |
5350 } } // namespace v8::internal | 5334 } } // namespace v8::internal |
5351 | 5335 |
5352 #endif // V8_TARGET_ARCH_X87 | 5336 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |