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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_X87 | 7 #if V8_TARGET_ARCH_X87 |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
11 #include "src/code-stubs.h" | 11 #include "src/code-stubs.h" |
12 #include "src/codegen.h" | 12 #include "src/codegen.h" |
13 #include "src/ic/handler-compiler.h" | 13 #include "src/ic/handler-compiler.h" |
14 #include "src/ic/ic.h" | 14 #include "src/ic/ic.h" |
| 15 #include "src/ic/stub-cache.h" |
15 #include "src/isolate.h" | 16 #include "src/isolate.h" |
16 #include "src/jsregexp.h" | 17 #include "src/jsregexp.h" |
17 #include "src/regexp-macro-assembler.h" | 18 #include "src/regexp-macro-assembler.h" |
18 #include "src/runtime/runtime.h" | 19 #include "src/runtime/runtime.h" |
19 | 20 |
20 namespace v8 { | 21 namespace v8 { |
21 namespace internal { | 22 namespace internal { |
22 | 23 |
23 | 24 |
24 static void InitializeArrayConstructorDescriptor( | 25 static void InitializeArrayConstructorDescriptor( |
(...skipping 4020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4045 __ pop(ecx); | 4046 __ pop(ecx); |
4046 int additional_offset = | 4047 int additional_offset = |
4047 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; | 4048 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; |
4048 __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); | 4049 __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
4049 __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. | 4050 __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
4050 } | 4051 } |
4051 | 4052 |
4052 | 4053 |
4053 void LoadICTrampolineStub::Generate(MacroAssembler* masm) { | 4054 void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
4054 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); | 4055 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); |
4055 VectorLoadStub stub(isolate(), state()); | 4056 VectorRawLoadStub stub(isolate(), state()); |
4056 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); | 4057 stub.GenerateForTrampoline(masm); |
4057 } | 4058 } |
4058 | 4059 |
4059 | 4060 |
4060 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { | 4061 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
4061 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); | 4062 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); |
4062 VectorKeyedLoadStub stub(isolate()); | 4063 VectorRawKeyedLoadStub stub(isolate()); |
4063 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); | 4064 stub.GenerateForTrampoline(masm); |
4064 } | 4065 } |
4065 | 4066 |
4066 | 4067 |
| 4068 static void HandleArrayCases(MacroAssembler* masm, Register receiver, |
| 4069 Register key, Register vector, Register slot, |
| 4070 Register feedback, bool is_polymorphic, |
| 4071 Label* miss) { |
| 4072 // feedback initially contains the feedback array |
| 4073 Label next, next_loop, prepare_next; |
| 4074 Label load_smi_map, compare_map; |
| 4075 Label start_polymorphic; |
| 4076 |
| 4077 __ push(receiver); |
| 4078 __ push(vector); |
| 4079 |
| 4080 Register receiver_map = receiver; |
| 4081 Register cached_map = vector; |
| 4082 |
| 4083 // Receiver might not be a heap object. |
| 4084 __ JumpIfSmi(receiver, &load_smi_map); |
| 4085 __ mov(receiver_map, FieldOperand(receiver, 0)); |
| 4086 __ bind(&compare_map); |
| 4087 __ mov(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 4088 |
| 4089 // A named keyed load might have a 2 element array, all other cases can count |
| 4090 // on an array with at least 2 {map, handler} pairs, so they can go right |
| 4091 // into polymorphic array handling. |
| 4092 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 4093 __ j(not_equal, is_polymorphic ? &start_polymorphic : &next); |
| 4094 |
| 4095 // found, now call handler. |
| 4096 Register handler = feedback; |
| 4097 __ mov(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 4098 __ pop(vector); |
| 4099 __ pop(receiver); |
| 4100 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4101 __ jmp(handler); |
| 4102 |
| 4103 if (!is_polymorphic) { |
| 4104 __ bind(&next); |
| 4105 __ cmp(FieldOperand(feedback, FixedArray::kLengthOffset), |
| 4106 Immediate(Smi::FromInt(2))); |
| 4107 __ j(not_equal, &start_polymorphic); |
| 4108 __ pop(vector); |
| 4109 __ pop(receiver); |
| 4110 __ jmp(miss); |
| 4111 } |
| 4112 |
| 4113 // Polymorphic, we have to loop from 2 to N |
| 4114 __ bind(&start_polymorphic); |
| 4115 __ push(key); |
| 4116 Register counter = key; |
| 4117 __ mov(counter, Immediate(Smi::FromInt(2))); |
| 4118 __ bind(&next_loop); |
| 4119 __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4120 FixedArray::kHeaderSize)); |
| 4121 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 4122 __ j(not_equal, &prepare_next); |
| 4123 __ mov(handler, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4124 FixedArray::kHeaderSize + kPointerSize)); |
| 4125 __ pop(key); |
| 4126 __ pop(vector); |
| 4127 __ pop(receiver); |
| 4128 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4129 __ jmp(handler); |
| 4130 |
| 4131 __ bind(&prepare_next); |
| 4132 __ add(counter, Immediate(Smi::FromInt(2))); |
| 4133 __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset)); |
| 4134 __ j(less, &next_loop); |
| 4135 |
| 4136 // We exhausted our array of map handler pairs. |
| 4137 __ pop(key); |
| 4138 __ pop(vector); |
| 4139 __ pop(receiver); |
| 4140 __ jmp(miss); |
| 4141 |
| 4142 __ bind(&load_smi_map); |
| 4143 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4144 __ jmp(&compare_map); |
| 4145 } |
| 4146 |
| 4147 |
| 4148 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
| 4149 Register key, Register vector, Register slot, |
| 4150 Register weak_cell, Label* miss) { |
| 4151 // feedback initially contains the feedback array |
| 4152 Label compare_smi_map; |
| 4153 |
| 4154 // Move the weak map into the weak_cell register. |
| 4155 Register ic_map = weak_cell; |
| 4156 __ mov(ic_map, FieldOperand(weak_cell, WeakCell::kValueOffset)); |
| 4157 |
| 4158 // Receiver might not be a heap object. |
| 4159 __ JumpIfSmi(receiver, &compare_smi_map); |
| 4160 __ cmp(ic_map, FieldOperand(receiver, 0)); |
| 4161 __ j(not_equal, miss); |
| 4162 Register handler = weak_cell; |
| 4163 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size, |
| 4164 FixedArray::kHeaderSize + kPointerSize)); |
| 4165 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4166 __ jmp(handler); |
| 4167 |
| 4168 // In microbenchmarks, it made sense to unroll this code so that the call to |
| 4169 // the handler is duplicated for a HeapObject receiver and a Smi receiver. |
| 4170 __ bind(&compare_smi_map); |
| 4171 __ CompareRoot(ic_map, Heap::kHeapNumberMapRootIndex); |
| 4172 __ j(not_equal, miss); |
| 4173 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size, |
| 4174 FixedArray::kHeaderSize + kPointerSize)); |
| 4175 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4176 __ jmp(handler); |
| 4177 } |
| 4178 |
| 4179 |
| 4180 void VectorRawLoadStub::Generate(MacroAssembler* masm) { |
| 4181 GenerateImpl(masm, false); |
| 4182 } |
| 4183 |
| 4184 |
| 4185 void VectorRawLoadStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4186 GenerateImpl(masm, true); |
| 4187 } |
| 4188 |
| 4189 |
| 4190 void VectorRawLoadStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4191 Register receiver = VectorLoadICDescriptor::ReceiverRegister(); // edx |
| 4192 Register name = VectorLoadICDescriptor::NameRegister(); // ecx |
| 4193 Register vector = VectorLoadICDescriptor::VectorRegister(); // ebx |
| 4194 Register slot = VectorLoadICDescriptor::SlotRegister(); // eax |
| 4195 Register scratch = edi; |
| 4196 __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
| 4197 FixedArray::kHeaderSize)); |
| 4198 |
| 4199 // Is it a weak cell? |
| 4200 Label try_array; |
| 4201 Label not_array, smi_key, key_okay, miss; |
| 4202 __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex); |
| 4203 __ j(not_equal, &try_array); |
| 4204 HandleMonomorphicCase(masm, receiver, name, vector, slot, scratch, &miss); |
| 4205 |
| 4206 // Is it a fixed array? |
| 4207 __ bind(&try_array); |
| 4208 __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex); |
| 4209 __ j(not_equal, ¬_array); |
| 4210 HandleArrayCases(masm, receiver, name, vector, slot, scratch, true, &miss); |
| 4211 |
| 4212 __ bind(¬_array); |
| 4213 __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex); |
| 4214 __ j(not_equal, &miss); |
| 4215 __ push(slot); |
| 4216 __ push(vector); |
| 4217 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 4218 Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 4219 masm->isolate()->stub_cache()->GenerateProbe( |
| 4220 masm, Code::LOAD_IC, code_flags, false, receiver, name, vector, scratch); |
| 4221 __ pop(vector); |
| 4222 __ pop(slot); |
| 4223 |
| 4224 __ bind(&miss); |
| 4225 LoadIC::GenerateMiss(masm); |
| 4226 } |
| 4227 |
| 4228 |
| 4229 void VectorRawKeyedLoadStub::Generate(MacroAssembler* masm) { |
| 4230 GenerateImpl(masm, false); |
| 4231 } |
| 4232 |
| 4233 |
| 4234 void VectorRawKeyedLoadStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4235 GenerateImpl(masm, true); |
| 4236 } |
| 4237 |
| 4238 |
| 4239 void VectorRawKeyedLoadStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4240 Register receiver = VectorLoadICDescriptor::ReceiverRegister(); // edx |
| 4241 Register key = VectorLoadICDescriptor::NameRegister(); // ecx |
| 4242 Register vector = VectorLoadICDescriptor::VectorRegister(); // ebx |
| 4243 Register slot = VectorLoadICDescriptor::SlotRegister(); // eax |
| 4244 Register feedback = edi; |
| 4245 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size, |
| 4246 FixedArray::kHeaderSize)); |
| 4247 // Is it a weak cell? |
| 4248 Label try_array; |
| 4249 Label not_array, smi_key, key_okay, miss; |
| 4250 __ CompareRoot(FieldOperand(feedback, 0), Heap::kWeakCellMapRootIndex); |
| 4251 __ j(not_equal, &try_array); |
| 4252 __ JumpIfNotSmi(key, &miss); |
| 4253 HandleMonomorphicCase(masm, receiver, key, vector, slot, feedback, &miss); |
| 4254 |
| 4255 __ bind(&try_array); |
| 4256 // Is it a fixed array? |
| 4257 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex); |
| 4258 __ j(not_equal, ¬_array); |
| 4259 // We have a polymorphic element handler. |
| 4260 __ JumpIfNotSmi(key, &miss); |
| 4261 |
| 4262 Label polymorphic, try_poly_name; |
| 4263 __ bind(&polymorphic); |
| 4264 HandleArrayCases(masm, receiver, key, vector, slot, feedback, true, &miss); |
| 4265 |
| 4266 __ bind(¬_array); |
| 4267 // Is it generic? |
| 4268 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex); |
| 4269 __ j(not_equal, &try_poly_name); |
| 4270 Handle<Code> megamorphic_stub = |
| 4271 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate()); |
| 4272 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4273 |
| 4274 __ bind(&try_poly_name); |
| 4275 // We might have a name in feedback, and a fixed array in the next slot. |
| 4276 __ cmp(key, feedback); |
| 4277 __ j(not_equal, &miss); |
| 4278 // If the name comparison succeeded, we know we have a fixed array with |
| 4279 // at least one map/handler pair. |
| 4280 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size, |
| 4281 FixedArray::kHeaderSize + kPointerSize)); |
| 4282 HandleArrayCases(masm, receiver, key, vector, slot, feedback, false, &miss); |
| 4283 |
| 4284 __ bind(&miss); |
| 4285 KeyedLoadIC::GenerateMiss(masm); |
| 4286 } |
| 4287 |
| 4288 |
4067 void CallICTrampolineStub::Generate(MacroAssembler* masm) { | 4289 void CallICTrampolineStub::Generate(MacroAssembler* masm) { |
4068 EmitLoadTypeFeedbackVector(masm, ebx); | 4290 EmitLoadTypeFeedbackVector(masm, ebx); |
4069 CallICStub stub(isolate(), state()); | 4291 CallICStub stub(isolate(), state()); |
4070 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); | 4292 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
4071 } | 4293 } |
4072 | 4294 |
4073 | 4295 |
4074 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) { | 4296 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) { |
4075 EmitLoadTypeFeedbackVector(masm, ebx); | 4297 EmitLoadTypeFeedbackVector(masm, ebx); |
4076 CallIC_ArrayStub stub(isolate(), state()); | 4298 CallIC_ArrayStub stub(isolate(), state()); |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4837 ApiParameterOperand(2), kStackSpace, nullptr, | 5059 ApiParameterOperand(2), kStackSpace, nullptr, |
4838 Operand(ebp, 7 * kPointerSize), NULL); | 5060 Operand(ebp, 7 * kPointerSize), NULL); |
4839 } | 5061 } |
4840 | 5062 |
4841 | 5063 |
4842 #undef __ | 5064 #undef __ |
4843 | 5065 |
4844 } } // namespace v8::internal | 5066 } } // namespace v8::internal |
4845 | 5067 |
4846 #endif // V8_TARGET_ARCH_X87 | 5068 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |