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 #if V8_TARGET_ARCH_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/api-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 2998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3009 StubFailureTrampolineFrameConstants::kArgumentsLengthOffset; | 3009 StubFailureTrampolineFrameConstants::kArgumentsLengthOffset; |
3010 __ mov(ebx, MemOperand(ebp, parameter_count_offset)); | 3010 __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
3011 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); | 3011 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
3012 __ pop(ecx); | 3012 __ pop(ecx); |
3013 int additional_offset = | 3013 int additional_offset = |
3014 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; | 3014 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; |
3015 __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); | 3015 __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
3016 __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. | 3016 __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
3017 } | 3017 } |
3018 | 3018 |
3019 | |
3020 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { | |
3021 __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); | |
3022 KeyedLoadICStub stub(isolate()); | |
3023 stub.GenerateForTrampoline(masm); | |
3024 } | |
3025 | |
3026 | |
3027 static void HandleArrayCases(MacroAssembler* masm, Register receiver, | |
3028 Register key, Register vector, Register slot, | |
3029 Register feedback, bool is_polymorphic, | |
3030 Label* miss) { | |
3031 // feedback initially contains the feedback array | |
3032 Label next, next_loop, prepare_next; | |
3033 Label load_smi_map, compare_map; | |
3034 Label start_polymorphic; | |
3035 | |
3036 __ push(receiver); | |
3037 __ push(vector); | |
3038 | |
3039 Register receiver_map = receiver; | |
3040 Register cached_map = vector; | |
3041 | |
3042 // Receiver might not be a heap object. | |
3043 __ JumpIfSmi(receiver, &load_smi_map); | |
3044 __ mov(receiver_map, FieldOperand(receiver, 0)); | |
3045 __ bind(&compare_map); | |
3046 __ mov(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0))); | |
3047 | |
3048 // A named keyed load might have a 2 element array, all other cases can count | |
3049 // on an array with at least 2 {map, handler} pairs, so they can go right | |
3050 // into polymorphic array handling. | |
3051 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); | |
3052 __ j(not_equal, is_polymorphic ? &start_polymorphic : &next); | |
3053 | |
3054 // found, now call handler. | |
3055 Register handler = feedback; | |
3056 __ mov(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1))); | |
3057 __ pop(vector); | |
3058 __ pop(receiver); | |
3059 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); | |
3060 __ jmp(handler); | |
3061 | |
3062 if (!is_polymorphic) { | |
3063 __ bind(&next); | |
3064 __ cmp(FieldOperand(feedback, FixedArray::kLengthOffset), | |
3065 Immediate(Smi::FromInt(2))); | |
3066 __ j(not_equal, &start_polymorphic); | |
3067 __ pop(vector); | |
3068 __ pop(receiver); | |
3069 __ jmp(miss); | |
3070 } | |
3071 | |
3072 // Polymorphic, we have to loop from 2 to N | |
3073 __ bind(&start_polymorphic); | |
3074 __ push(key); | |
3075 Register counter = key; | |
3076 __ mov(counter, Immediate(Smi::FromInt(2))); | |
3077 __ bind(&next_loop); | |
3078 __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size, | |
3079 FixedArray::kHeaderSize)); | |
3080 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); | |
3081 __ j(not_equal, &prepare_next); | |
3082 __ mov(handler, FieldOperand(feedback, counter, times_half_pointer_size, | |
3083 FixedArray::kHeaderSize + kPointerSize)); | |
3084 __ pop(key); | |
3085 __ pop(vector); | |
3086 __ pop(receiver); | |
3087 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); | |
3088 __ jmp(handler); | |
3089 | |
3090 __ bind(&prepare_next); | |
3091 __ add(counter, Immediate(Smi::FromInt(2))); | |
3092 __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset)); | |
3093 __ j(less, &next_loop); | |
3094 | |
3095 // We exhausted our array of map handler pairs. | |
3096 __ pop(key); | |
3097 __ pop(vector); | |
3098 __ pop(receiver); | |
3099 __ jmp(miss); | |
3100 | |
3101 __ bind(&load_smi_map); | |
3102 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); | |
3103 __ jmp(&compare_map); | |
3104 } | |
3105 | |
3106 | |
3107 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, | |
3108 Register key, Register vector, Register slot, | |
3109 Register weak_cell, Label* miss) { | |
3110 // feedback initially contains the feedback array | |
3111 Label compare_smi_map; | |
3112 | |
3113 // Move the weak map into the weak_cell register. | |
3114 Register ic_map = weak_cell; | |
3115 __ mov(ic_map, FieldOperand(weak_cell, WeakCell::kValueOffset)); | |
3116 | |
3117 // Receiver might not be a heap object. | |
3118 __ JumpIfSmi(receiver, &compare_smi_map); | |
3119 __ cmp(ic_map, FieldOperand(receiver, 0)); | |
3120 __ j(not_equal, miss); | |
3121 Register handler = weak_cell; | |
3122 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size, | |
3123 FixedArray::kHeaderSize + kPointerSize)); | |
3124 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); | |
3125 __ jmp(handler); | |
3126 | |
3127 // In microbenchmarks, it made sense to unroll this code so that the call to | |
3128 // the handler is duplicated for a HeapObject receiver and a Smi receiver. | |
3129 __ bind(&compare_smi_map); | |
3130 __ CompareRoot(ic_map, Heap::kHeapNumberMapRootIndex); | |
3131 __ j(not_equal, miss); | |
3132 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size, | |
3133 FixedArray::kHeaderSize + kPointerSize)); | |
3134 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); | |
3135 __ jmp(handler); | |
3136 } | |
3137 | |
3138 | |
3139 void KeyedLoadICStub::Generate(MacroAssembler* masm) { | |
3140 GenerateImpl(masm, false); | |
3141 } | |
3142 | |
3143 | |
3144 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) { | |
3145 GenerateImpl(masm, true); | |
3146 } | |
3147 | |
3148 | |
3149 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { | |
3150 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // edx | |
3151 Register key = LoadWithVectorDescriptor::NameRegister(); // ecx | |
3152 Register vector = LoadWithVectorDescriptor::VectorRegister(); // ebx | |
3153 Register slot = LoadWithVectorDescriptor::SlotRegister(); // eax | |
3154 Register feedback = edi; | |
3155 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size, | |
3156 FixedArray::kHeaderSize)); | |
3157 // Is it a weak cell? | |
3158 Label try_array; | |
3159 Label not_array, smi_key, key_okay, miss; | |
3160 __ CompareRoot(FieldOperand(feedback, 0), Heap::kWeakCellMapRootIndex); | |
3161 __ j(not_equal, &try_array); | |
3162 HandleMonomorphicCase(masm, receiver, key, vector, slot, feedback, &miss); | |
3163 | |
3164 __ bind(&try_array); | |
3165 // Is it a fixed array? | |
3166 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex); | |
3167 __ j(not_equal, ¬_array); | |
3168 | |
3169 // We have a polymorphic element handler. | |
3170 Label polymorphic, try_poly_name; | |
3171 __ bind(&polymorphic); | |
3172 HandleArrayCases(masm, receiver, key, vector, slot, feedback, true, &miss); | |
3173 | |
3174 __ bind(¬_array); | |
3175 // Is it generic? | |
3176 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex); | |
3177 __ j(not_equal, &try_poly_name); | |
3178 Handle<Code> megamorphic_stub = | |
3179 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); | |
3180 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET); | |
3181 | |
3182 __ bind(&try_poly_name); | |
3183 // We might have a name in feedback, and a fixed array in the next slot. | |
3184 __ cmp(key, feedback); | |
3185 __ j(not_equal, &miss); | |
3186 // If the name comparison succeeded, we know we have a fixed array with | |
3187 // at least one map/handler pair. | |
3188 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size, | |
3189 FixedArray::kHeaderSize + kPointerSize)); | |
3190 HandleArrayCases(masm, receiver, key, vector, slot, feedback, false, &miss); | |
3191 | |
3192 __ bind(&miss); | |
3193 KeyedLoadIC::GenerateMiss(masm); | |
3194 } | |
3195 | |
3196 void KeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) { | 3019 void KeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
3197 __ EmitLoadTypeFeedbackVector(StoreWithVectorDescriptor::VectorRegister()); | 3020 __ EmitLoadTypeFeedbackVector(StoreWithVectorDescriptor::VectorRegister()); |
3198 KeyedStoreICStub stub(isolate(), state()); | 3021 KeyedStoreICStub stub(isolate(), state()); |
3199 stub.GenerateForTrampoline(masm); | 3022 stub.GenerateForTrampoline(masm); |
3200 } | 3023 } |
3201 | 3024 |
3202 // value is on the stack already. | 3025 // value is on the stack already. |
3203 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register receiver, | 3026 static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register receiver, |
3204 Register key, Register vector, | 3027 Register key, Register vector, |
3205 Register slot, Register feedback, | 3028 Register slot, Register feedback, |
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4929 kStackUnwindSpace, nullptr, return_value_operand, | 4752 kStackUnwindSpace, nullptr, return_value_operand, |
4930 NULL); | 4753 NULL); |
4931 } | 4754 } |
4932 | 4755 |
4933 #undef __ | 4756 #undef __ |
4934 | 4757 |
4935 } // namespace internal | 4758 } // namespace internal |
4936 } // namespace v8 | 4759 } // namespace v8 |
4937 | 4760 |
4938 #endif // V8_TARGET_ARCH_IA32 | 4761 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |