| 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_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
| 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 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 VisitForStackValue(expression); | 1615 VisitForStackValue(expression); |
| 1616 } | 1616 } |
| 1617 } | 1617 } |
| 1618 | 1618 |
| 1619 | 1619 |
| 1620 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | 1620 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1621 Comment cmnt(masm_, "[ ObjectLiteral"); | 1621 Comment cmnt(masm_, "[ ObjectLiteral"); |
| 1622 | 1622 |
| 1623 expr->BuildConstantProperties(isolate()); | 1623 expr->BuildConstantProperties(isolate()); |
| 1624 Handle<FixedArray> constant_properties = expr->constant_properties(); | 1624 Handle<FixedArray> constant_properties = expr->constant_properties(); |
| 1625 int flags = expr->fast_elements() | 1625 int flags = expr->ComputeFlags(); |
| 1626 ? ObjectLiteral::kFastElements | 1626 // If any of the keys would store to the elements array, then we shouldn't |
| 1627 : ObjectLiteral::kNoFlags; | 1627 // allow it. |
| 1628 flags |= expr->has_function() | 1628 if (MustCreateObjectLiteralWithRuntime(expr)) { |
| 1629 ? ObjectLiteral::kHasFunction | |
| 1630 : ObjectLiteral::kNoFlags; | |
| 1631 int properties_count = constant_properties->length() / 2; | |
| 1632 if (expr->may_store_doubles() || expr->depth() > 1 || | |
| 1633 masm()->serializer_enabled() || | |
| 1634 flags != ObjectLiteral::kFastElements || | |
| 1635 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { | |
| 1636 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1629 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1637 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); | 1630 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1638 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1631 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1639 __ push(Immediate(constant_properties)); | 1632 __ push(Immediate(constant_properties)); |
| 1640 __ push(Immediate(Smi::FromInt(flags))); | 1633 __ push(Immediate(Smi::FromInt(flags))); |
| 1641 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); | 1634 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
| 1642 } else { | 1635 } else { |
| 1643 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1636 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1644 __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); | 1637 __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1645 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); | 1638 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1646 __ mov(ecx, Immediate(constant_properties)); | 1639 __ mov(ecx, Immediate(constant_properties)); |
| 1647 __ mov(edx, Immediate(Smi::FromInt(flags))); | 1640 __ mov(edx, Immediate(Smi::FromInt(flags))); |
| 1648 FastCloneShallowObjectStub stub(isolate(), properties_count); | 1641 FastCloneShallowObjectStub stub(isolate(), expr->properties_count()); |
| 1649 __ CallStub(&stub); | 1642 __ CallStub(&stub); |
| 1650 } | 1643 } |
| 1651 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | 1644 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
| 1652 | 1645 |
| 1653 // If result_saved is true the result is on top of the stack. If | 1646 // If result_saved is true the result is on top of the stack. If |
| 1654 // result_saved is false the result is in eax. | 1647 // result_saved is false the result is in eax. |
| 1655 bool result_saved = false; | 1648 bool result_saved = false; |
| 1656 | 1649 |
| 1657 // Mark all computed expressions that are bound to a key that | 1650 // Mark all computed expressions that are bound to a key that |
| 1658 // is shadowed by a later occurrence of the same key. For the | 1651 // 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... |
| 1817 } else { | 1810 } else { |
| 1818 context()->Plug(eax); | 1811 context()->Plug(eax); |
| 1819 } | 1812 } |
| 1820 } | 1813 } |
| 1821 | 1814 |
| 1822 | 1815 |
| 1823 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1816 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1824 Comment cmnt(masm_, "[ ArrayLiteral"); | 1817 Comment cmnt(masm_, "[ ArrayLiteral"); |
| 1825 | 1818 |
| 1826 expr->BuildConstantElements(isolate()); | 1819 expr->BuildConstantElements(isolate()); |
| 1827 int flags = expr->depth() == 1 | |
| 1828 ? ArrayLiteral::kShallowElements | |
| 1829 : ArrayLiteral::kNoFlags; | |
| 1830 | |
| 1831 ZoneList<Expression*>* subexprs = expr->values(); | |
| 1832 int length = subexprs->length(); | |
| 1833 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1820 Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1834 DCHECK_EQ(2, constant_elements->length()); | |
| 1835 ElementsKind constant_elements_kind = | |
| 1836 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | |
| 1837 bool has_constant_fast_elements = | 1821 bool has_constant_fast_elements = |
| 1838 IsFastObjectElementsKind(constant_elements_kind); | 1822 IsFastObjectElementsKind(expr->constant_elements_kind()); |
| 1839 Handle<FixedArrayBase> constant_elements_values( | |
| 1840 FixedArrayBase::cast(constant_elements->get(1))); | |
| 1841 | 1823 |
| 1842 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; | 1824 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; |
| 1843 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { | 1825 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { |
| 1844 // If the only customer of allocation sites is transitioning, then | 1826 // If the only customer of allocation sites is transitioning, then |
| 1845 // we can turn it off if we don't have anywhere else to transition to. | 1827 // we can turn it off if we don't have anywhere else to transition to. |
| 1846 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; | 1828 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
| 1847 } | 1829 } |
| 1848 | 1830 |
| 1849 if (expr->depth() > 1 || length > JSObject::kInitialMaxFastElementArray) { | 1831 if (MustCreateArrayLiteralWithRuntime(expr)) { |
| 1850 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1832 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1851 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1833 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1852 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1834 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1853 __ push(Immediate(constant_elements)); | 1835 __ push(Immediate(constant_elements)); |
| 1854 __ push(Immediate(Smi::FromInt(flags))); | 1836 __ push(Immediate(Smi::FromInt(expr->ComputeFlags()))); |
| 1855 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); | 1837 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
| 1856 } else { | 1838 } else { |
| 1857 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1839 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1858 __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1840 __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1859 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); | 1841 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1860 __ mov(ecx, Immediate(constant_elements)); | 1842 __ mov(ecx, Immediate(constant_elements)); |
| 1861 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); | 1843 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); |
| 1862 __ CallStub(&stub); | 1844 __ CallStub(&stub); |
| 1863 } | 1845 } |
| 1864 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | 1846 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
| 1865 | 1847 |
| 1866 bool result_saved = false; // Is the result saved to the stack? | 1848 bool result_saved = false; // Is the result saved to the stack? |
| 1849 ZoneList<Expression*>* subexprs = expr->values(); |
| 1850 int length = subexprs->length(); |
| 1867 | 1851 |
| 1868 // Emit code to evaluate all the non-constant subexpressions and to store | 1852 // Emit code to evaluate all the non-constant subexpressions and to store |
| 1869 // them into the newly cloned array. | 1853 // them into the newly cloned array. |
| 1870 for (int i = 0; i < length; i++) { | 1854 for (int i = 0; i < length; i++) { |
| 1871 Expression* subexpr = subexprs->at(i); | 1855 Expression* subexpr = subexprs->at(i); |
| 1872 // If the subexpression is a literal or a simple materialized literal it | 1856 // If the subexpression is a literal or a simple materialized literal it |
| 1873 // is already set in the cloned array. | 1857 // is already set in the cloned array. |
| 1874 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; | 1858 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
| 1875 | 1859 |
| 1876 if (!result_saved) { | 1860 if (!result_saved) { |
| 1877 __ push(eax); // array literal. | 1861 __ push(eax); // array literal. |
| 1878 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1862 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1879 result_saved = true; | 1863 result_saved = true; |
| 1880 } | 1864 } |
| 1881 VisitForAccumulatorValue(subexpr); | 1865 VisitForAccumulatorValue(subexpr); |
| 1882 | 1866 |
| 1883 if (IsFastObjectElementsKind(constant_elements_kind)) { | 1867 if (has_constant_fast_elements) { |
| 1884 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they | 1868 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1885 // cannot transition and don't need to call the runtime stub. | 1869 // cannot transition and don't need to call the runtime stub. |
| 1886 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1870 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1887 __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. | 1871 __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. |
| 1888 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); | 1872 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1889 // Store the subexpression value in the array's elements. | 1873 // Store the subexpression value in the array's elements. |
| 1890 __ mov(FieldOperand(ebx, offset), result_register()); | 1874 __ mov(FieldOperand(ebx, offset), result_register()); |
| 1891 // Update the write barrier for the array store. | 1875 // Update the write barrier for the array store. |
| 1892 __ RecordWriteField(ebx, offset, result_register(), ecx, | 1876 __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1893 kDontSaveFPRegs, | 1877 kDontSaveFPRegs, |
| (...skipping 3464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5358 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5342 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5359 Assembler::target_address_at(call_target_address, | 5343 Assembler::target_address_at(call_target_address, |
| 5360 unoptimized_code)); | 5344 unoptimized_code)); |
| 5361 return OSR_AFTER_STACK_CHECK; | 5345 return OSR_AFTER_STACK_CHECK; |
| 5362 } | 5346 } |
| 5363 | 5347 |
| 5364 | 5348 |
| 5365 } } // namespace v8::internal | 5349 } } // namespace v8::internal |
| 5366 | 5350 |
| 5367 #endif // V8_TARGET_ARCH_IA32 | 5351 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |