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