| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 __ push(Immediate(isolate()->factory()->null_value())); | 1568 __ push(Immediate(isolate()->factory()->null_value())); |
| 1569 } else { | 1569 } else { |
| 1570 VisitForStackValue(expression); | 1570 VisitForStackValue(expression); |
| 1571 } | 1571 } |
| 1572 } | 1572 } |
| 1573 | 1573 |
| 1574 | 1574 |
| 1575 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | 1575 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1576 Comment cmnt(masm_, "[ ObjectLiteral"); | 1576 Comment cmnt(masm_, "[ ObjectLiteral"); |
| 1577 | 1577 |
| 1578 int depth = 1; | 1578 expr->BuildConstantProperties(isolate()); |
| 1579 expr->BuildConstantProperties(isolate(), &depth); | |
| 1580 Handle<FixedArray> constant_properties = expr->constant_properties(); | 1579 Handle<FixedArray> constant_properties = expr->constant_properties(); |
| 1581 int flags = expr->fast_elements() | 1580 int flags = expr->fast_elements() |
| 1582 ? ObjectLiteral::kFastElements | 1581 ? ObjectLiteral::kFastElements |
| 1583 : ObjectLiteral::kNoFlags; | 1582 : ObjectLiteral::kNoFlags; |
| 1584 flags |= expr->has_function() | 1583 flags |= expr->has_function() |
| 1585 ? ObjectLiteral::kHasFunction | 1584 ? ObjectLiteral::kHasFunction |
| 1586 : ObjectLiteral::kNoFlags; | 1585 : ObjectLiteral::kNoFlags; |
| 1587 int properties_count = constant_properties->length() / 2; | 1586 int properties_count = constant_properties->length() / 2; |
| 1588 if ((FLAG_track_double_fields && expr->may_store_doubles()) || | 1587 if ((FLAG_track_double_fields && expr->may_store_doubles()) || |
| 1589 depth > 1 || Serializer::enabled() || | 1588 expr->depth() > 1 || Serializer::enabled() || |
| 1590 flags != ObjectLiteral::kFastElements || | 1589 flags != ObjectLiteral::kFastElements || |
| 1591 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { | 1590 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
| 1592 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1591 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1593 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); | 1592 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1594 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1593 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1595 __ push(Immediate(constant_properties)); | 1594 __ push(Immediate(constant_properties)); |
| 1596 __ push(Immediate(Smi::FromInt(flags))); | 1595 __ push(Immediate(Smi::FromInt(flags))); |
| 1597 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); | 1596 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
| 1598 } else { | 1597 } else { |
| 1599 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1598 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 context()->PlugTOS(); | 1697 context()->PlugTOS(); |
| 1699 } else { | 1698 } else { |
| 1700 context()->Plug(eax); | 1699 context()->Plug(eax); |
| 1701 } | 1700 } |
| 1702 } | 1701 } |
| 1703 | 1702 |
| 1704 | 1703 |
| 1705 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1704 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1706 Comment cmnt(masm_, "[ ArrayLiteral"); | 1705 Comment cmnt(masm_, "[ ArrayLiteral"); |
| 1707 | 1706 |
| 1708 int depth = 1; | 1707 expr->BuildConstantElements(isolate()); |
| 1709 expr->BuildConstantElements(isolate(), &depth); | 1708 int flags = expr->depth() == 1 |
| 1709 ? ArrayLiteral::kShallowElements |
| 1710 : ArrayLiteral::kNoFlags; |
| 1711 |
| 1710 ZoneList<Expression*>* subexprs = expr->values(); | 1712 ZoneList<Expression*>* subexprs = expr->values(); |
| 1711 int length = subexprs->length(); | 1713 int length = subexprs->length(); |
| 1712 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1714 Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1713 ASSERT_EQ(2, constant_elements->length()); | 1715 ASSERT_EQ(2, constant_elements->length()); |
| 1714 ElementsKind constant_elements_kind = | 1716 ElementsKind constant_elements_kind = |
| 1715 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | 1717 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1716 bool has_constant_fast_elements = | 1718 bool has_constant_fast_elements = |
| 1717 IsFastObjectElementsKind(constant_elements_kind); | 1719 IsFastObjectElementsKind(constant_elements_kind); |
| 1718 Handle<FixedArrayBase> constant_elements_values( | 1720 Handle<FixedArrayBase> constant_elements_values( |
| 1719 FixedArrayBase::cast(constant_elements->get(1))); | 1721 FixedArrayBase::cast(constant_elements->get(1))); |
| 1720 | 1722 |
| 1721 Heap* heap = isolate()->heap(); | 1723 Heap* heap = isolate()->heap(); |
| 1722 if (has_constant_fast_elements && | 1724 if (has_constant_fast_elements && |
| 1723 constant_elements_values->map() == heap->fixed_cow_array_map()) { | 1725 constant_elements_values->map() == heap->fixed_cow_array_map()) { |
| 1724 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot | 1726 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
| 1725 // change, so it's possible to specialize the stub in advance. | 1727 // change, so it's possible to specialize the stub in advance. |
| 1726 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); | 1728 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
| 1727 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1729 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1728 __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1730 __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1729 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); | 1731 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1730 __ mov(ecx, Immediate(constant_elements)); | 1732 __ mov(ecx, Immediate(constant_elements)); |
| 1731 FastCloneShallowArrayStub stub( | 1733 FastCloneShallowArrayStub stub( |
| 1732 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, | 1734 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
| 1733 DONT_TRACK_ALLOCATION_SITE, | 1735 DONT_TRACK_ALLOCATION_SITE, |
| 1734 length); | 1736 length); |
| 1735 __ CallStub(&stub); | 1737 __ CallStub(&stub); |
| 1736 } else if (depth > 1 || Serializer::enabled() || | 1738 } else if (expr->depth() > 1 || Serializer::enabled() || |
| 1737 length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1739 length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 1738 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1740 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1739 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); | 1741 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1740 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1742 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1741 __ push(Immediate(constant_elements)); | 1743 __ push(Immediate(constant_elements)); |
| 1742 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1744 __ push(Immediate(Smi::FromInt(flags))); |
| 1745 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
| 1743 } else { | 1746 } else { |
| 1744 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || | 1747 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
| 1745 FLAG_smi_only_arrays); | 1748 FLAG_smi_only_arrays); |
| 1746 FastCloneShallowArrayStub::Mode mode = | 1749 FastCloneShallowArrayStub::Mode mode = |
| 1747 FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; | 1750 FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
| 1748 AllocationSiteMode allocation_site_mode = FLAG_track_allocation_sites | 1751 AllocationSiteMode allocation_site_mode = FLAG_track_allocation_sites |
| 1749 ? TRACK_ALLOCATION_SITE : DONT_TRACK_ALLOCATION_SITE; | 1752 ? TRACK_ALLOCATION_SITE : DONT_TRACK_ALLOCATION_SITE; |
| 1750 | 1753 |
| 1751 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot | 1754 // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
| 1752 // change, so it's possible to specialize the stub in advance. | 1755 // change, so it's possible to specialize the stub in advance. |
| (...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3291 VisitForStackValue(args->at(1)); | 3294 VisitForStackValue(args->at(1)); |
| 3292 VisitForStackValue(args->at(2)); | 3295 VisitForStackValue(args->at(2)); |
| 3293 __ CallRuntime(Runtime::kLog, 2); | 3296 __ CallRuntime(Runtime::kLog, 2); |
| 3294 } | 3297 } |
| 3295 // Finally, we're expected to leave a value on the top of the stack. | 3298 // Finally, we're expected to leave a value on the top of the stack. |
| 3296 __ mov(eax, isolate()->factory()->undefined_value()); | 3299 __ mov(eax, isolate()->factory()->undefined_value()); |
| 3297 context()->Plug(eax); | 3300 context()->Plug(eax); |
| 3298 } | 3301 } |
| 3299 | 3302 |
| 3300 | 3303 |
| 3301 void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) { | |
| 3302 ASSERT(expr->arguments()->length() == 0); | |
| 3303 | |
| 3304 Label slow_allocate_heapnumber; | |
| 3305 Label heapnumber_allocated; | |
| 3306 | |
| 3307 __ AllocateHeapNumber(edi, ebx, ecx, &slow_allocate_heapnumber); | |
| 3308 __ jmp(&heapnumber_allocated); | |
| 3309 | |
| 3310 __ bind(&slow_allocate_heapnumber); | |
| 3311 // Allocate a heap number. | |
| 3312 __ CallRuntime(Runtime::kNumberAlloc, 0); | |
| 3313 __ mov(edi, eax); | |
| 3314 | |
| 3315 __ bind(&heapnumber_allocated); | |
| 3316 | |
| 3317 __ PrepareCallCFunction(1, ebx); | |
| 3318 __ mov(eax, ContextOperand(context_register(), Context::GLOBAL_OBJECT_INDEX)); | |
| 3319 __ mov(eax, FieldOperand(eax, GlobalObject::kNativeContextOffset)); | |
| 3320 __ mov(Operand(esp, 0), eax); | |
| 3321 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); | |
| 3322 | |
| 3323 // Convert 32 random bits in eax to 0.(32 random bits) in a double | |
| 3324 // by computing: | |
| 3325 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | |
| 3326 // This is implemented on both SSE2 and FPU. | |
| 3327 if (CpuFeatures::IsSupported(SSE2)) { | |
| 3328 CpuFeatureScope fscope(masm(), SSE2); | |
| 3329 __ mov(ebx, Immediate(0x49800000)); // 1.0 x 2^20 as single. | |
| 3330 __ movd(xmm1, ebx); | |
| 3331 __ movd(xmm0, eax); | |
| 3332 __ cvtss2sd(xmm1, xmm1); | |
| 3333 __ xorps(xmm0, xmm1); | |
| 3334 __ subsd(xmm0, xmm1); | |
| 3335 __ movsd(FieldOperand(edi, HeapNumber::kValueOffset), xmm0); | |
| 3336 } else { | |
| 3337 // 0x4130000000000000 is 1.0 x 2^20 as a double. | |
| 3338 __ mov(FieldOperand(edi, HeapNumber::kExponentOffset), | |
| 3339 Immediate(0x41300000)); | |
| 3340 __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), eax); | |
| 3341 __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset)); | |
| 3342 __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), Immediate(0)); | |
| 3343 __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset)); | |
| 3344 __ fsubp(1); | |
| 3345 __ fstp_d(FieldOperand(edi, HeapNumber::kValueOffset)); | |
| 3346 } | |
| 3347 __ mov(eax, edi); | |
| 3348 context()->Plug(eax); | |
| 3349 } | |
| 3350 | |
| 3351 | |
| 3352 void FullCodeGenerator::EmitSubString(CallRuntime* expr) { | 3304 void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
| 3353 // Load the arguments on the stack and call the stub. | 3305 // Load the arguments on the stack and call the stub. |
| 3354 SubStringStub stub; | 3306 SubStringStub stub; |
| 3355 ZoneList<Expression*>* args = expr->arguments(); | 3307 ZoneList<Expression*>* args = expr->arguments(); |
| 3356 ASSERT(args->length() == 3); | 3308 ASSERT(args->length() == 3); |
| 3357 VisitForStackValue(args->at(0)); | 3309 VisitForStackValue(args->at(0)); |
| 3358 VisitForStackValue(args->at(1)); | 3310 VisitForStackValue(args->at(1)); |
| 3359 VisitForStackValue(args->at(2)); | 3311 VisitForStackValue(args->at(2)); |
| 3360 __ CallStub(&stub); | 3312 __ CallStub(&stub); |
| 3361 context()->Plug(eax); | 3313 context()->Plug(eax); |
| (...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4956 | 4908 |
| 4957 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4909 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 4958 Assembler::target_address_at(call_target_address)); | 4910 Assembler::target_address_at(call_target_address)); |
| 4959 return OSR_AFTER_STACK_CHECK; | 4911 return OSR_AFTER_STACK_CHECK; |
| 4960 } | 4912 } |
| 4961 | 4913 |
| 4962 | 4914 |
| 4963 } } // namespace v8::internal | 4915 } } // namespace v8::internal |
| 4964 | 4916 |
| 4965 #endif // V8_TARGET_ARCH_IA32 | 4917 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |