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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 CodeStubInterfaceDescriptor* descriptor) { | 89 CodeStubInterfaceDescriptor* descriptor) { |
90 static Register registers[] = { r0, r1 }; | 90 static Register registers[] = { r0, r1 }; |
91 descriptor->register_param_count_ = 2; | 91 descriptor->register_param_count_ = 2; |
92 descriptor->register_params_ = registers; | 92 descriptor->register_params_ = registers; |
93 Address entry = | 93 Address entry = |
94 Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; | 94 Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
95 descriptor->deoptimization_handler_ = FUNCTION_ADDR(entry); | 95 descriptor->deoptimization_handler_ = FUNCTION_ADDR(entry); |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 static void InitializeArrayConstructorDescriptor(Isolate* isolate, | 99 static void InitializeArrayConstructorDescriptor( |
100 CodeStubInterfaceDescriptor* descriptor) { | 100 Isolate* isolate, |
| 101 CodeStubInterfaceDescriptor* descriptor, |
| 102 int constant_stack_parameter_count) { |
101 // register state | 103 // register state |
102 // r1 -- constructor function | |
103 // r2 -- type info cell with elements kind | 104 // r2 -- type info cell with elements kind |
104 // r0 -- number of arguments to the constructor function | 105 static Register registers[] = { r2 }; |
105 static Register registers[] = { r1, r2 }; | 106 descriptor->register_param_count_ = 1; |
106 descriptor->register_param_count_ = 2; | 107 if (constant_stack_parameter_count != 0) { |
107 // stack param count needs (constructor pointer, and single argument) | 108 // stack param count needs (constructor pointer, and single argument) |
108 descriptor->stack_parameter_count_ = &r0; | 109 descriptor->stack_parameter_count_ = &r0; |
| 110 } |
| 111 descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
109 descriptor->register_params_ = registers; | 112 descriptor->register_params_ = registers; |
110 descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; | 113 descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
111 descriptor->deoptimization_handler_ = | 114 descriptor->deoptimization_handler_ = |
112 FUNCTION_ADDR(ArrayConstructor_StubFailure); | 115 FUNCTION_ADDR(ArrayConstructor_StubFailure); |
113 } | 116 } |
114 | 117 |
115 | 118 |
116 void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( | 119 void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
117 Isolate* isolate, | 120 Isolate* isolate, |
118 CodeStubInterfaceDescriptor* descriptor) { | 121 CodeStubInterfaceDescriptor* descriptor) { |
119 InitializeArrayConstructorDescriptor(isolate, descriptor); | 122 InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
120 } | 123 } |
121 | 124 |
122 | 125 |
123 void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( | 126 void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
124 Isolate* isolate, | 127 Isolate* isolate, |
125 CodeStubInterfaceDescriptor* descriptor) { | 128 CodeStubInterfaceDescriptor* descriptor) { |
126 InitializeArrayConstructorDescriptor(isolate, descriptor); | 129 InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
127 } | 130 } |
128 | 131 |
129 | 132 |
130 void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( | 133 void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
131 Isolate* isolate, | 134 Isolate* isolate, |
132 CodeStubInterfaceDescriptor* descriptor) { | 135 CodeStubInterfaceDescriptor* descriptor) { |
133 InitializeArrayConstructorDescriptor(isolate, descriptor); | 136 InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
134 } | 137 } |
135 | 138 |
136 | 139 |
137 #define __ ACCESS_MASM(masm) | 140 #define __ ACCESS_MASM(masm) |
138 | 141 |
139 static void EmitIdenticalObjectComparison(MacroAssembler* masm, | 142 static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
140 Label* slow, | 143 Label* slow, |
141 Condition cond); | 144 Condition cond); |
142 static void EmitSmiNonsmiComparison(MacroAssembler* masm, | 145 static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
143 Register lhs, | 146 Register lhs, |
(...skipping 3234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3378 result_size_ == 1; | 3381 result_size_ == 1; |
3379 } | 3382 } |
3380 | 3383 |
3381 | 3384 |
3382 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { | 3385 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
3383 CEntryStub::GenerateAheadOfTime(isolate); | 3386 CEntryStub::GenerateAheadOfTime(isolate); |
3384 WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(isolate); | 3387 WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(isolate); |
3385 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); | 3388 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
3386 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); | 3389 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
3387 RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); | 3390 RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
| 3391 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
3388 } | 3392 } |
3389 | 3393 |
3390 | 3394 |
3391 void CodeStub::GenerateFPStubs(Isolate* isolate) { | 3395 void CodeStub::GenerateFPStubs(Isolate* isolate) { |
3392 SaveFPRegsMode mode = kSaveFPRegs; | 3396 SaveFPRegsMode mode = kSaveFPRegs; |
3393 CEntryStub save_doubles(1, mode); | 3397 CEntryStub save_doubles(1, mode); |
3394 StoreBufferOverflowStub stub(mode); | 3398 StoreBufferOverflowStub stub(mode); |
3395 // These stubs might already be in the snapshot, detect that and don't | 3399 // These stubs might already be in the snapshot, detect that and don't |
3396 // regenerate, which would lead to code stub initialization state being messed | 3400 // regenerate, which would lead to code stub initialization state being messed |
3397 // up. | 3401 // up. |
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5082 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); | 5086 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); |
5083 __ b(eq, &done); | 5087 __ b(eq, &done); |
5084 | 5088 |
5085 // Special handling of the Array() function, which caches not only the | 5089 // Special handling of the Array() function, which caches not only the |
5086 // monomorphic Array function but the initial ElementsKind with special | 5090 // monomorphic Array function but the initial ElementsKind with special |
5087 // sentinels | 5091 // sentinels |
5088 Handle<Object> terminal_kind_sentinel = | 5092 Handle<Object> terminal_kind_sentinel = |
5089 TypeFeedbackCells::MonomorphicArraySentinel(masm->isolate(), | 5093 TypeFeedbackCells::MonomorphicArraySentinel(masm->isolate(), |
5090 LAST_FAST_ELEMENTS_KIND); | 5094 LAST_FAST_ELEMENTS_KIND); |
5091 __ cmp(r3, Operand(terminal_kind_sentinel)); | 5095 __ cmp(r3, Operand(terminal_kind_sentinel)); |
5092 __ b(ne, &miss); | 5096 __ b(gt, &miss); |
5093 // Make sure the function is the Array() function | 5097 // Make sure the function is the Array() function |
5094 __ LoadArrayFunction(r3); | 5098 __ LoadArrayFunction(r3); |
5095 __ cmp(r1, r3); | 5099 __ cmp(r1, r3); |
5096 __ b(ne, &megamorphic); | 5100 __ b(ne, &megamorphic); |
5097 __ jmp(&done); | 5101 __ jmp(&done); |
5098 | 5102 |
5099 __ bind(&miss); | 5103 __ bind(&miss); |
5100 | 5104 |
5101 // A monomorphic miss (i.e, here the cache is not uninitialized) goes | 5105 // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
5102 // megamorphic. | 5106 // megamorphic. |
(...skipping 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7163 } | 7167 } |
7164 } | 7168 } |
7165 return false; | 7169 return false; |
7166 } | 7170 } |
7167 | 7171 |
7168 | 7172 |
7169 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( | 7173 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
7170 Isolate* isolate) { | 7174 Isolate* isolate) { |
7171 StoreBufferOverflowStub stub1(kDontSaveFPRegs); | 7175 StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
7172 stub1.GetCode(isolate)->set_is_pregenerated(true); | 7176 stub1.GetCode(isolate)->set_is_pregenerated(true); |
| 7177 StoreBufferOverflowStub stub2(kSaveFPRegs); |
| 7178 stub2.GetCode(isolate)->set_is_pregenerated(true); |
7173 } | 7179 } |
7174 | 7180 |
7175 | 7181 |
7176 void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { | 7182 void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
7177 for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; | 7183 for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
7178 !entry->object.is(no_reg); | 7184 !entry->object.is(no_reg); |
7179 entry++) { | 7185 entry++) { |
7180 RecordWriteStub stub(entry->object, | 7186 RecordWriteStub stub(entry->object, |
7181 entry->value, | 7187 entry->value, |
7182 entry->address, | 7188 entry->address, |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7521 | 7527 |
7522 // Restore the stack pointer if needed. | 7528 // Restore the stack pointer if needed. |
7523 if (frame_alignment > kPointerSize) { | 7529 if (frame_alignment > kPointerSize) { |
7524 __ mov(sp, r5); | 7530 __ mov(sp, r5); |
7525 } | 7531 } |
7526 | 7532 |
7527 __ Pop(lr, r5, r1); | 7533 __ Pop(lr, r5, r1); |
7528 __ Ret(); | 7534 __ Ret(); |
7529 } | 7535 } |
7530 | 7536 |
| 7537 |
| 7538 template<class T> |
| 7539 static void CreateArrayDispatch(MacroAssembler* masm) { |
| 7540 int last_index = GetSequenceIndexFromFastElementsKind( |
| 7541 TERMINAL_FAST_ELEMENTS_KIND); |
| 7542 for (int i = 0; i <= last_index; ++i) { |
| 7543 Label next; |
| 7544 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7545 __ cmp(r3, Operand(kind)); |
| 7546 __ b(ne, &next); |
| 7547 T stub(kind); |
| 7548 __ TailCallStub(&stub); |
| 7549 __ bind(&next); |
| 7550 } |
| 7551 |
| 7552 // If we reached this point there is a problem. |
| 7553 __ Abort("Unexpected ElementsKind in array constructor"); |
| 7554 } |
| 7555 |
| 7556 |
| 7557 static void CreateArrayDispatchOneArgument(MacroAssembler* masm) { |
| 7558 // r2 - type info cell |
| 7559 // r3 - kind |
| 7560 // r0 - number of arguments |
| 7561 // r1 - constructor? |
| 7562 // sp[0] - last argument |
| 7563 ASSERT(FAST_SMI_ELEMENTS == 0); |
| 7564 ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 7565 ASSERT(FAST_ELEMENTS == 2); |
| 7566 ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 7567 ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 7568 ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 7569 |
| 7570 Handle<Object> undefined_sentinel( |
| 7571 masm->isolate()->heap()->undefined_value(), |
| 7572 masm->isolate()); |
| 7573 |
| 7574 // is the low bit set? If so, we are holey and that is good. |
| 7575 __ tst(r3, Operand(1)); |
| 7576 Label normal_sequence; |
| 7577 __ b(ne, &normal_sequence); |
| 7578 |
| 7579 // look at the first argument |
| 7580 __ ldr(r5, MemOperand(sp, 0)); |
| 7581 __ cmp(r5, Operand::Zero()); |
| 7582 __ b(eq, &normal_sequence); |
| 7583 |
| 7584 // We are going to create a holey array, but our kind is non-holey. |
| 7585 // Fix kind and retry |
| 7586 __ add(r3, r3, Operand(1)); |
| 7587 __ cmp(r2, Operand(undefined_sentinel)); |
| 7588 __ b(eq, &normal_sequence); |
| 7589 |
| 7590 // Save the resulting elements kind in type info |
| 7591 __ SmiTag(r3); |
| 7592 __ str(r3, FieldMemOperand(r2, kPointerSize)); |
| 7593 __ SmiUntag(r3); |
| 7594 |
| 7595 __ bind(&normal_sequence); |
| 7596 int last_index = GetSequenceIndexFromFastElementsKind( |
| 7597 TERMINAL_FAST_ELEMENTS_KIND); |
| 7598 for (int i = 0; i <= last_index; ++i) { |
| 7599 Label next; |
| 7600 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7601 __ cmp(r3, Operand(kind)); |
| 7602 __ b(ne, &next); |
| 7603 ArraySingleArgumentConstructorStub stub(kind); |
| 7604 __ TailCallStub(&stub); |
| 7605 __ bind(&next); |
| 7606 } |
| 7607 |
| 7608 // If we reached this point there is a problem. |
| 7609 __ Abort("Unexpected ElementsKind in array constructor"); |
| 7610 } |
| 7611 |
| 7612 |
| 7613 template<class T> |
| 7614 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 7615 int to_index = GetSequenceIndexFromFastElementsKind( |
| 7616 TERMINAL_FAST_ELEMENTS_KIND); |
| 7617 for (int i = 0; i <= to_index; ++i) { |
| 7618 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7619 T stub(kind); |
| 7620 stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7621 } |
| 7622 } |
| 7623 |
| 7624 |
| 7625 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 7626 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 7627 isolate); |
| 7628 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 7629 isolate); |
| 7630 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 7631 isolate); |
| 7632 } |
| 7633 |
| 7634 |
| 7635 void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7636 // ----------- S t a t e ------------- |
| 7637 // -- r0 : argc (only if argument_count_ == ANY) |
| 7638 // -- r1 : constructor |
| 7639 // -- r2 : type info cell |
| 7640 // -- sp[0] : return address |
| 7641 // -- sp[4] : last argument |
| 7642 // ----------------------------------- |
| 7643 Handle<Object> undefined_sentinel( |
| 7644 masm->isolate()->heap()->undefined_value(), |
| 7645 masm->isolate()); |
| 7646 |
| 7647 if (FLAG_debug_code) { |
| 7648 // The array construct code is only set for the global and natives |
| 7649 // builtin Array functions which always have maps. |
| 7650 |
| 7651 // Initial map for the builtin Array function should be a map. |
| 7652 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7653 // Will both indicate a NULL and a Smi. |
| 7654 __ tst(r3, Operand(kSmiTagMask)); |
| 7655 __ Assert(ne, "Unexpected initial map for Array function"); |
| 7656 __ CompareObjectType(r3, r3, r4, MAP_TYPE); |
| 7657 __ Assert(eq, "Unexpected initial map for Array function"); |
| 7658 |
| 7659 // We should either have undefined in ebx or a valid jsglobalpropertycell |
| 7660 Label okay_here; |
| 7661 Handle<Map> global_property_cell_map( |
| 7662 masm->isolate()->heap()->global_property_cell_map()); |
| 7663 __ cmp(r2, Operand(undefined_sentinel)); |
| 7664 __ b(eq, &okay_here); |
| 7665 __ ldr(r3, FieldMemOperand(r2, 0)); |
| 7666 __ cmp(r3, Operand(global_property_cell_map)); |
| 7667 __ Assert(eq, "Expected property cell in register ebx"); |
| 7668 __ bind(&okay_here); |
| 7669 } |
| 7670 |
| 7671 if (FLAG_optimize_constructed_arrays) { |
| 7672 Label no_info, switch_ready; |
| 7673 // Get the elements kind and case on that. |
| 7674 __ cmp(r2, Operand(undefined_sentinel)); |
| 7675 __ b(eq, &no_info); |
| 7676 __ ldr(r3, FieldMemOperand(r2, kPointerSize)); |
| 7677 |
| 7678 // There is no info if the call site went megamorphic either |
| 7679 // TODO(mvstanton): Really? I thought if it was the array function that |
| 7680 // the cell wouldn't get stamped as megamorphic. |
| 7681 __ cmp(r3, |
| 7682 Operand(TypeFeedbackCells::MegamorphicSentinel(masm->isolate()))); |
| 7683 __ b(eq, &no_info); |
| 7684 __ SmiUntag(r3); |
| 7685 __ jmp(&switch_ready); |
| 7686 __ bind(&no_info); |
| 7687 __ mov(r3, Operand(GetInitialFastElementsKind())); |
| 7688 __ bind(&switch_ready); |
| 7689 |
| 7690 if (argument_count_ == ANY) { |
| 7691 Label not_zero_case, not_one_case; |
| 7692 __ tst(r0, r0); |
| 7693 __ b(ne, ¬_zero_case); |
| 7694 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7695 |
| 7696 __ bind(¬_zero_case); |
| 7697 __ cmp(r0, Operand(1)); |
| 7698 __ b(gt, ¬_one_case); |
| 7699 CreateArrayDispatchOneArgument(masm); |
| 7700 |
| 7701 __ bind(¬_one_case); |
| 7702 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7703 } else if (argument_count_ == NONE) { |
| 7704 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7705 } else if (argument_count_ == ONE) { |
| 7706 CreateArrayDispatchOneArgument(masm); |
| 7707 } else if (argument_count_ == MORE_THAN_ONE) { |
| 7708 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7709 } else { |
| 7710 UNREACHABLE(); |
| 7711 } |
| 7712 } else { |
| 7713 Label generic_constructor; |
| 7714 // Run the native code for the Array function called as a constructor. |
| 7715 ArrayNativeCode(masm, &generic_constructor); |
| 7716 |
| 7717 // Jump to the generic construct code in case the specialized code cannot |
| 7718 // handle the construction. |
| 7719 __ bind(&generic_constructor); |
| 7720 Handle<Code> generic_construct_stub = |
| 7721 masm->isolate()->builtins()->JSConstructStubGeneric(); |
| 7722 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 7723 } |
| 7724 } |
| 7725 |
| 7726 |
7531 #undef __ | 7727 #undef __ |
7532 | 7728 |
7533 } } // namespace v8::internal | 7729 } } // namespace v8::internal |
7534 | 7730 |
7535 #endif // V8_TARGET_ARCH_ARM | 7731 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |