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_X64 | 7 #if V8_TARGET_ARCH_X64 |
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 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1643 VisitForStackValue(expression); | 1643 VisitForStackValue(expression); |
1644 } | 1644 } |
1645 } | 1645 } |
1646 | 1646 |
1647 | 1647 |
1648 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | 1648 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
1649 Comment cmnt(masm_, "[ ObjectLiteral"); | 1649 Comment cmnt(masm_, "[ ObjectLiteral"); |
1650 | 1650 |
1651 expr->BuildConstantProperties(isolate()); | 1651 expr->BuildConstantProperties(isolate()); |
1652 Handle<FixedArray> constant_properties = expr->constant_properties(); | 1652 Handle<FixedArray> constant_properties = expr->constant_properties(); |
1653 int flags = expr->fast_elements() | 1653 int flags = expr->ComputeFlags(); |
1654 ? ObjectLiteral::kFastElements | 1654 if (MustCreateObjectLiteralWithRuntime(expr)) { |
1655 : ObjectLiteral::kNoFlags; | |
1656 flags |= expr->has_function() | |
1657 ? ObjectLiteral::kHasFunction | |
1658 : ObjectLiteral::kNoFlags; | |
1659 int properties_count = constant_properties->length() / 2; | |
1660 if (expr->may_store_doubles() || expr->depth() > 1 || | |
1661 masm()->serializer_enabled() || flags != ObjectLiteral::kFastElements || | |
1662 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { | |
1663 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1655 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
1664 __ Push(FieldOperand(rdi, JSFunction::kLiteralsOffset)); | 1656 __ Push(FieldOperand(rdi, JSFunction::kLiteralsOffset)); |
1665 __ Push(Smi::FromInt(expr->literal_index())); | 1657 __ Push(Smi::FromInt(expr->literal_index())); |
1666 __ Push(constant_properties); | 1658 __ Push(constant_properties); |
1667 __ Push(Smi::FromInt(flags)); | 1659 __ Push(Smi::FromInt(flags)); |
1668 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); | 1660 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
1669 } else { | 1661 } else { |
1670 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1662 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
1671 __ movp(rax, FieldOperand(rdi, JSFunction::kLiteralsOffset)); | 1663 __ movp(rax, FieldOperand(rdi, JSFunction::kLiteralsOffset)); |
1672 __ Move(rbx, Smi::FromInt(expr->literal_index())); | 1664 __ Move(rbx, Smi::FromInt(expr->literal_index())); |
1673 __ Move(rcx, constant_properties); | 1665 __ Move(rcx, constant_properties); |
1674 __ Move(rdx, Smi::FromInt(flags)); | 1666 __ Move(rdx, Smi::FromInt(flags)); |
1675 FastCloneShallowObjectStub stub(isolate(), properties_count); | 1667 FastCloneShallowObjectStub stub(isolate(), expr->properties_count()); |
1676 __ CallStub(&stub); | 1668 __ CallStub(&stub); |
1677 } | 1669 } |
1678 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | 1670 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
1679 | 1671 |
1680 // If result_saved is true the result is on top of the stack. If | 1672 // If result_saved is true the result is on top of the stack. If |
1681 // result_saved is false the result is in rax. | 1673 // result_saved is false the result is in rax. |
1682 bool result_saved = false; | 1674 bool result_saved = false; |
1683 | 1675 |
1684 // Mark all computed expressions that are bound to a key that | 1676 // Mark all computed expressions that are bound to a key that |
1685 // is shadowed by a later occurrence of the same key. For the | 1677 // 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... |
1844 } else { | 1836 } else { |
1845 context()->Plug(rax); | 1837 context()->Plug(rax); |
1846 } | 1838 } |
1847 } | 1839 } |
1848 | 1840 |
1849 | 1841 |
1850 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1842 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
1851 Comment cmnt(masm_, "[ ArrayLiteral"); | 1843 Comment cmnt(masm_, "[ ArrayLiteral"); |
1852 | 1844 |
1853 expr->BuildConstantElements(isolate()); | 1845 expr->BuildConstantElements(isolate()); |
1854 int flags = expr->depth() == 1 | |
1855 ? ArrayLiteral::kShallowElements | |
1856 : ArrayLiteral::kNoFlags; | |
1857 | |
1858 ZoneList<Expression*>* subexprs = expr->values(); | |
1859 int length = subexprs->length(); | |
1860 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1846 Handle<FixedArray> constant_elements = expr->constant_elements(); |
1861 DCHECK_EQ(2, constant_elements->length()); | |
1862 ElementsKind constant_elements_kind = | |
1863 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | |
1864 bool has_constant_fast_elements = | 1847 bool has_constant_fast_elements = |
1865 IsFastObjectElementsKind(constant_elements_kind); | 1848 IsFastObjectElementsKind(expr->constant_elements_kind()); |
1866 Handle<FixedArrayBase> constant_elements_values( | |
1867 FixedArrayBase::cast(constant_elements->get(1))); | |
1868 | 1849 |
1869 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; | 1850 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; |
1870 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { | 1851 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { |
1871 // If the only customer of allocation sites is transitioning, then | 1852 // If the only customer of allocation sites is transitioning, then |
1872 // we can turn it off if we don't have anywhere else to transition to. | 1853 // we can turn it off if we don't have anywhere else to transition to. |
1873 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; | 1854 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
1874 } | 1855 } |
1875 | 1856 |
1876 if (expr->depth() > 1 || length > JSObject::kInitialMaxFastElementArray) { | 1857 if (MustCreateArrayLiteralWithRuntime(expr)) { |
1877 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1858 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
1878 __ Push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); | 1859 __ Push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
1879 __ Push(Smi::FromInt(expr->literal_index())); | 1860 __ Push(Smi::FromInt(expr->literal_index())); |
1880 __ Push(constant_elements); | 1861 __ Push(constant_elements); |
1881 __ Push(Smi::FromInt(flags)); | 1862 __ Push(Smi::FromInt(expr->ComputeFlags())); |
1882 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); | 1863 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
1883 } else { | 1864 } else { |
1884 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1865 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
1885 __ movp(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset)); | 1866 __ movp(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
1886 __ Move(rbx, Smi::FromInt(expr->literal_index())); | 1867 __ Move(rbx, Smi::FromInt(expr->literal_index())); |
1887 __ Move(rcx, constant_elements); | 1868 __ Move(rcx, constant_elements); |
1888 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); | 1869 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); |
1889 __ CallStub(&stub); | 1870 __ CallStub(&stub); |
1890 } | 1871 } |
1891 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | 1872 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
1892 | 1873 |
1893 bool result_saved = false; // Is the result saved to the stack? | 1874 bool result_saved = false; // Is the result saved to the stack? |
| 1875 ZoneList<Expression*>* subexprs = expr->values(); |
| 1876 int length = subexprs->length(); |
1894 | 1877 |
1895 // Emit code to evaluate all the non-constant subexpressions and to store | 1878 // Emit code to evaluate all the non-constant subexpressions and to store |
1896 // them into the newly cloned array. | 1879 // them into the newly cloned array. |
1897 for (int i = 0; i < length; i++) { | 1880 for (int i = 0; i < length; i++) { |
1898 Expression* subexpr = subexprs->at(i); | 1881 Expression* subexpr = subexprs->at(i); |
1899 // If the subexpression is a literal or a simple materialized literal it | 1882 // If the subexpression is a literal or a simple materialized literal it |
1900 // is already set in the cloned array. | 1883 // is already set in the cloned array. |
1901 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; | 1884 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
1902 | 1885 |
1903 if (!result_saved) { | 1886 if (!result_saved) { |
1904 __ Push(rax); // array literal | 1887 __ Push(rax); // array literal |
1905 __ Push(Smi::FromInt(expr->literal_index())); | 1888 __ Push(Smi::FromInt(expr->literal_index())); |
1906 result_saved = true; | 1889 result_saved = true; |
1907 } | 1890 } |
1908 VisitForAccumulatorValue(subexpr); | 1891 VisitForAccumulatorValue(subexpr); |
1909 | 1892 |
1910 if (IsFastObjectElementsKind(constant_elements_kind)) { | 1893 if (has_constant_fast_elements) { |
1911 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they | 1894 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
1912 // cannot transition and don't need to call the runtime stub. | 1895 // cannot transition and don't need to call the runtime stub. |
1913 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1896 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
1914 __ movp(rbx, Operand(rsp, kPointerSize)); // Copy of array literal. | 1897 __ movp(rbx, Operand(rsp, kPointerSize)); // Copy of array literal. |
1915 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); | 1898 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); |
1916 // Store the subexpression value in the array's elements. | 1899 // Store the subexpression value in the array's elements. |
1917 __ movp(FieldOperand(rbx, offset), result_register()); | 1900 __ movp(FieldOperand(rbx, offset), result_register()); |
1918 // Update the write barrier for the array store. | 1901 // Update the write barrier for the array store. |
1919 __ RecordWriteField(rbx, offset, result_register(), rcx, | 1902 __ RecordWriteField(rbx, offset, result_register(), rcx, |
1920 kDontSaveFPRegs, | 1903 kDontSaveFPRegs, |
(...skipping 3467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5388 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5371 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
5389 Assembler::target_address_at(call_target_address, | 5372 Assembler::target_address_at(call_target_address, |
5390 unoptimized_code)); | 5373 unoptimized_code)); |
5391 return OSR_AFTER_STACK_CHECK; | 5374 return OSR_AFTER_STACK_CHECK; |
5392 } | 5375 } |
5393 | 5376 |
5394 | 5377 |
5395 } } // namespace v8::internal | 5378 } } // namespace v8::internal |
5396 | 5379 |
5397 #endif // V8_TARGET_ARCH_X64 | 5380 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |