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/code-stubs.h" | 5 #include "src/code-stubs.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 4491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4502 assembler->Parameter( | 4502 assembler->Parameter( |
4503 ArrayNoArgumentConstructorDescriptor::kFunctionIndex), | 4503 ArrayNoArgumentConstructorDescriptor::kFunctionIndex), |
4504 JSFunction::kPrototypeOrInitialMapOffset); | 4504 JSFunction::kPrototypeOrInitialMapOffset); |
4505 Node* array = assembler->AllocateJSArray( | 4505 Node* array = assembler->AllocateJSArray( |
4506 elements_kind(), array_map, | 4506 elements_kind(), array_map, |
4507 assembler->IntPtrConstant(JSArray::kPreallocatedArrayElements), | 4507 assembler->IntPtrConstant(JSArray::kPreallocatedArrayElements), |
4508 assembler->IntPtrConstant(0), nullptr); | 4508 assembler->IntPtrConstant(0), nullptr); |
4509 assembler->Return(array); | 4509 assembler->Return(array); |
4510 } | 4510 } |
4511 | 4511 |
| 4512 namespace { |
| 4513 |
| 4514 void SingleArgumentConstructorCommon(CodeStubAssembler* assembler, |
| 4515 ElementsKind elements_kind, |
| 4516 compiler::Node* array_map, |
| 4517 compiler::Node* allocation_site, |
| 4518 Runtime::FunctionId runtime_fallback, |
| 4519 AllocationSiteMode mode) { |
| 4520 typedef compiler::Node Node; |
| 4521 typedef CodeStubAssembler::Label Label; |
| 4522 |
| 4523 Label ok(assembler); |
| 4524 Label smi_size(assembler); |
| 4525 Label small_smi_size(assembler); |
| 4526 Label call_runtime(assembler, Label::kDeferred); |
| 4527 |
| 4528 Node* size = assembler->Parameter( |
| 4529 ArraySingleArgumentConstructorDescriptor::kArraySizeSmiParameterIndex); |
| 4530 assembler->Branch(assembler->WordIsSmi(size), &smi_size, &call_runtime); |
| 4531 |
| 4532 assembler->Bind(&smi_size); |
| 4533 int element_size = |
| 4534 IsFastDoubleElementsKind(elements_kind) ? kDoubleSize : kPointerSize; |
| 4535 int max_fast_elements = |
| 4536 (Page::kMaxRegularHeapObjectSize - FixedArray::kHeaderSize - |
| 4537 JSArray::kSize - AllocationMemento::kSize) / |
| 4538 element_size; |
| 4539 assembler->Branch( |
| 4540 assembler->SmiAboveOrEqual( |
| 4541 size, assembler->SmiConstant(Smi::FromInt(max_fast_elements))), |
| 4542 &call_runtime, &small_smi_size); |
| 4543 |
| 4544 assembler->Bind(&small_smi_size); |
| 4545 { |
| 4546 Node* array = assembler->AllocateJSArray( |
| 4547 elements_kind, array_map, size, size, |
| 4548 mode == DONT_TRACK_ALLOCATION_SITE ? nullptr : allocation_site, |
| 4549 CodeStubAssembler::SMI_PARAMETERS); |
| 4550 assembler->Return(array); |
| 4551 } |
| 4552 |
| 4553 assembler->Bind(&call_runtime); |
| 4554 { |
| 4555 Node* context = assembler->Parameter( |
| 4556 ArraySingleArgumentConstructorDescriptor::kContextIndex); |
| 4557 Node* constructor = assembler->Parameter( |
| 4558 ArraySingleArgumentConstructorDescriptor::kFunctionIndex); |
| 4559 Node* argument_count = assembler->Parameter( |
| 4560 ArraySingleArgumentConstructorDescriptor::kArgumentsCountIndex); |
| 4561 Node* argument_base_offset = assembler->IntPtrAdd( |
| 4562 assembler->IntPtrConstant(CommonFrameConstants::kFixedFrameSizeAboveFp - |
| 4563 kPointerSize), |
| 4564 assembler->Word32Shl(argument_count, |
| 4565 assembler->IntPtrConstant(kPointerSizeLog2))); |
| 4566 Node* argument_base = assembler->IntPtrAdd(assembler->LoadFramePointer(), |
| 4567 argument_base_offset); |
| 4568 Node* array = assembler->CallRuntime( |
| 4569 runtime_fallback, context, constructor, argument_base, |
| 4570 assembler->SmiTag(argument_count), allocation_site); |
| 4571 assembler->Return(array); |
| 4572 } |
| 4573 } |
| 4574 } // namespace |
| 4575 |
| 4576 void ArraySingleArgumentConstructorStub::GenerateAssembly( |
| 4577 CodeStubAssembler* assembler) const { |
| 4578 typedef compiler::Node Node; |
| 4579 Node* function = assembler->Parameter( |
| 4580 ArraySingleArgumentConstructorDescriptor::kFunctionIndex); |
| 4581 Node* native_context = |
| 4582 assembler->LoadObjectField(function, JSFunction::kContextOffset); |
| 4583 Node* array_map = |
| 4584 assembler->LoadJSArrayElementsMap(elements_kind(), native_context); |
| 4585 AllocationSiteMode mode = override_mode() == DISABLE_ALLOCATION_SITES |
| 4586 ? DONT_TRACK_ALLOCATION_SITE |
| 4587 : AllocationSite::GetMode(elements_kind()); |
| 4588 Node* allocation_site = assembler->Parameter( |
| 4589 ArrayNoArgumentConstructorDescriptor::kAllocationSiteIndex); |
| 4590 SingleArgumentConstructorCommon( |
| 4591 assembler, elements_kind(), array_map, allocation_site, |
| 4592 Runtime::kArraySingleArgumentConstructor, mode); |
| 4593 } |
| 4594 |
| 4595 void InternalArraySingleArgumentConstructorStub::GenerateAssembly( |
| 4596 CodeStubAssembler* assembler) const { |
| 4597 typedef compiler::Node Node; |
| 4598 Node* function = assembler->Parameter( |
| 4599 ArraySingleArgumentConstructorDescriptor::kFunctionIndex); |
| 4600 Node* array_map = assembler->LoadObjectField( |
| 4601 function, JSFunction::kPrototypeOrInitialMapOffset); |
| 4602 SingleArgumentConstructorCommon( |
| 4603 assembler, elements_kind(), array_map, assembler->UndefinedConstant(), |
| 4604 Runtime::kArraySingleArgumentConstructor, DONT_TRACK_ALLOCATION_SITE); |
| 4605 } |
| 4606 |
4512 ArrayConstructorStub::ArrayConstructorStub(Isolate* isolate) | 4607 ArrayConstructorStub::ArrayConstructorStub(Isolate* isolate) |
4513 : PlatformCodeStub(isolate) { | 4608 : PlatformCodeStub(isolate) { |
4514 minor_key_ = ArgumentCountBits::encode(ANY); | 4609 minor_key_ = ArgumentCountBits::encode(ANY); |
4515 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); | 4610 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
4516 } | 4611 } |
4517 | 4612 |
4518 | 4613 |
4519 ArrayConstructorStub::ArrayConstructorStub(Isolate* isolate, | 4614 ArrayConstructorStub::ArrayConstructorStub(Isolate* isolate, |
4520 int argument_count) | 4615 int argument_count) |
4521 : PlatformCodeStub(isolate) { | 4616 : PlatformCodeStub(isolate) { |
(...skipping 28 matching lines...) Expand all Loading... |
4550 if (type->Is(Type::UntaggedPointer())) { | 4645 if (type->Is(Type::UntaggedPointer())) { |
4551 return Representation::External(); | 4646 return Representation::External(); |
4552 } | 4647 } |
4553 | 4648 |
4554 DCHECK(!type->Is(Type::Untagged())); | 4649 DCHECK(!type->Is(Type::Untagged())); |
4555 return Representation::Tagged(); | 4650 return Representation::Tagged(); |
4556 } | 4651 } |
4557 | 4652 |
4558 } // namespace internal | 4653 } // namespace internal |
4559 } // namespace v8 | 4654 } // namespace v8 |
OLD | NEW |