Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 1037273002: Ensure object literal element boilerplates aren't modified. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added comment and REBASE. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-literals.cc ('k') | test/mjsunit/regress/regress-466993.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 VisitForStackValue(expression); 1650 VisitForStackValue(expression);
1651 } 1651 }
1652 } 1652 }
1653 1653
1654 1654
1655 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { 1655 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
1656 Comment cmnt(masm_, "[ ObjectLiteral"); 1656 Comment cmnt(masm_, "[ ObjectLiteral");
1657 1657
1658 expr->BuildConstantProperties(isolate()); 1658 expr->BuildConstantProperties(isolate());
1659 Handle<FixedArray> constant_properties = expr->constant_properties(); 1659 Handle<FixedArray> constant_properties = expr->constant_properties();
1660 int flags = expr->fast_elements() 1660 int flags = expr->ComputeFlags();
1661 ? ObjectLiteral::kFastElements 1661 if (MustCreateObjectLiteralWithRuntime(expr)) {
1662 : ObjectLiteral::kNoFlags;
1663 flags |= expr->has_function()
1664 ? ObjectLiteral::kHasFunction
1665 : ObjectLiteral::kNoFlags;
1666 int properties_count = constant_properties->length() / 2;
1667 if (expr->may_store_doubles() || expr->depth() > 1 ||
1668 masm()->serializer_enabled() || flags != ObjectLiteral::kFastElements ||
1669 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) {
1670 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1662 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1671 __ Push(FieldOperand(rdi, JSFunction::kLiteralsOffset)); 1663 __ Push(FieldOperand(rdi, JSFunction::kLiteralsOffset));
1672 __ Push(Smi::FromInt(expr->literal_index())); 1664 __ Push(Smi::FromInt(expr->literal_index()));
1673 __ Push(constant_properties); 1665 __ Push(constant_properties);
1674 __ Push(Smi::FromInt(flags)); 1666 __ Push(Smi::FromInt(flags));
1675 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); 1667 __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
1676 } else { 1668 } else {
1677 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1669 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1678 __ movp(rax, FieldOperand(rdi, JSFunction::kLiteralsOffset)); 1670 __ movp(rax, FieldOperand(rdi, JSFunction::kLiteralsOffset));
1679 __ Move(rbx, Smi::FromInt(expr->literal_index())); 1671 __ Move(rbx, Smi::FromInt(expr->literal_index()));
1680 __ Move(rcx, constant_properties); 1672 __ Move(rcx, constant_properties);
1681 __ Move(rdx, Smi::FromInt(flags)); 1673 __ Move(rdx, Smi::FromInt(flags));
1682 FastCloneShallowObjectStub stub(isolate(), properties_count); 1674 FastCloneShallowObjectStub stub(isolate(), expr->properties_count());
1683 __ CallStub(&stub); 1675 __ CallStub(&stub);
1684 } 1676 }
1685 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); 1677 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1686 1678
1687 // If result_saved is true the result is on top of the stack. If 1679 // If result_saved is true the result is on top of the stack. If
1688 // result_saved is false the result is in rax. 1680 // result_saved is false the result is in rax.
1689 bool result_saved = false; 1681 bool result_saved = false;
1690 1682
1691 // Mark all computed expressions that are bound to a key that 1683 // Mark all computed expressions that are bound to a key that
1692 // is shadowed by a later occurrence of the same key. For the 1684 // is shadowed by a later occurrence of the same key. For the
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 } else { 1843 } else {
1852 context()->Plug(rax); 1844 context()->Plug(rax);
1853 } 1845 }
1854 } 1846 }
1855 1847
1856 1848
1857 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { 1849 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1858 Comment cmnt(masm_, "[ ArrayLiteral"); 1850 Comment cmnt(masm_, "[ ArrayLiteral");
1859 1851
1860 expr->BuildConstantElements(isolate()); 1852 expr->BuildConstantElements(isolate());
1861 int flags = expr->depth() == 1
1862 ? ArrayLiteral::kShallowElements
1863 : ArrayLiteral::kNoFlags;
1864
1865 ZoneList<Expression*>* subexprs = expr->values();
1866 int length = subexprs->length();
1867 Handle<FixedArray> constant_elements = expr->constant_elements(); 1853 Handle<FixedArray> constant_elements = expr->constant_elements();
1868 DCHECK_EQ(2, constant_elements->length());
1869 ElementsKind constant_elements_kind =
1870 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value());
1871 bool has_constant_fast_elements = 1854 bool has_constant_fast_elements =
1872 IsFastObjectElementsKind(constant_elements_kind); 1855 IsFastObjectElementsKind(expr->constant_elements_kind());
1873 Handle<FixedArrayBase> constant_elements_values(
1874 FixedArrayBase::cast(constant_elements->get(1)));
1875 1856
1876 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; 1857 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE;
1877 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { 1858 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) {
1878 // If the only customer of allocation sites is transitioning, then 1859 // If the only customer of allocation sites is transitioning, then
1879 // we can turn it off if we don't have anywhere else to transition to. 1860 // we can turn it off if we don't have anywhere else to transition to.
1880 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; 1861 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE;
1881 } 1862 }
1882 1863
1883 if (expr->depth() > 1 || length > JSObject::kInitialMaxFastElementArray) { 1864 if (MustCreateArrayLiteralWithRuntime(expr)) {
1884 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1865 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1885 __ Push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); 1866 __ Push(FieldOperand(rbx, JSFunction::kLiteralsOffset));
1886 __ Push(Smi::FromInt(expr->literal_index())); 1867 __ Push(Smi::FromInt(expr->literal_index()));
1887 __ Push(constant_elements); 1868 __ Push(constant_elements);
1888 __ Push(Smi::FromInt(flags)); 1869 __ Push(Smi::FromInt(expr->ComputeFlags()));
1889 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); 1870 __ CallRuntime(Runtime::kCreateArrayLiteral, 4);
1890 } else { 1871 } else {
1891 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 1872 __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1892 __ movp(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset)); 1873 __ movp(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset));
1893 __ Move(rbx, Smi::FromInt(expr->literal_index())); 1874 __ Move(rbx, Smi::FromInt(expr->literal_index()));
1894 __ Move(rcx, constant_elements); 1875 __ Move(rcx, constant_elements);
1895 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); 1876 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode);
1896 __ CallStub(&stub); 1877 __ CallStub(&stub);
1897 } 1878 }
1898 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); 1879 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1899 1880
1900 bool result_saved = false; // Is the result saved to the stack? 1881 bool result_saved = false; // Is the result saved to the stack?
1882 ZoneList<Expression*>* subexprs = expr->values();
1883 int length = subexprs->length();
1901 1884
1902 // Emit code to evaluate all the non-constant subexpressions and to store 1885 // Emit code to evaluate all the non-constant subexpressions and to store
1903 // them into the newly cloned array. 1886 // them into the newly cloned array.
1904 for (int i = 0; i < length; i++) { 1887 for (int i = 0; i < length; i++) {
1905 Expression* subexpr = subexprs->at(i); 1888 Expression* subexpr = subexprs->at(i);
1906 // If the subexpression is a literal or a simple materialized literal it 1889 // If the subexpression is a literal or a simple materialized literal it
1907 // is already set in the cloned array. 1890 // is already set in the cloned array.
1908 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; 1891 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
1909 1892
1910 if (!result_saved) { 1893 if (!result_saved) {
1911 __ Push(rax); // array literal 1894 __ Push(rax); // array literal
1912 __ Push(Smi::FromInt(expr->literal_index())); 1895 __ Push(Smi::FromInt(expr->literal_index()));
1913 result_saved = true; 1896 result_saved = true;
1914 } 1897 }
1915 VisitForAccumulatorValue(subexpr); 1898 VisitForAccumulatorValue(subexpr);
1916 1899
1917 if (IsFastObjectElementsKind(constant_elements_kind)) { 1900 if (has_constant_fast_elements) {
1918 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they 1901 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they
1919 // cannot transition and don't need to call the runtime stub. 1902 // cannot transition and don't need to call the runtime stub.
1920 int offset = FixedArray::kHeaderSize + (i * kPointerSize); 1903 int offset = FixedArray::kHeaderSize + (i * kPointerSize);
1921 __ movp(rbx, Operand(rsp, kPointerSize)); // Copy of array literal. 1904 __ movp(rbx, Operand(rsp, kPointerSize)); // Copy of array literal.
1922 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); 1905 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
1923 // Store the subexpression value in the array's elements. 1906 // Store the subexpression value in the array's elements.
1924 __ movp(FieldOperand(rbx, offset), result_register()); 1907 __ movp(FieldOperand(rbx, offset), result_register());
1925 // Update the write barrier for the array store. 1908 // Update the write barrier for the array store.
1926 __ RecordWriteField(rbx, offset, result_register(), rcx, 1909 __ RecordWriteField(rbx, offset, result_register(), rcx,
1927 kDontSaveFPRegs, 1910 kDontSaveFPRegs,
(...skipping 3451 matching lines...) Expand 10 before | Expand all | Expand 10 after
5379 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 5362 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
5380 Assembler::target_address_at(call_target_address, 5363 Assembler::target_address_at(call_target_address,
5381 unoptimized_code)); 5364 unoptimized_code));
5382 return OSR_AFTER_STACK_CHECK; 5365 return OSR_AFTER_STACK_CHECK;
5383 } 5366 }
5384 5367
5385 5368
5386 } } // namespace v8::internal 5369 } } // namespace v8::internal
5387 5370
5388 #endif // V8_TARGET_ARCH_X64 5371 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/runtime/runtime-literals.cc ('k') | test/mjsunit/regress/regress-466993.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698