OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
8 | 8 |
9 #include "src/ic/call-optimization.h" | |
10 #include "src/ic/ic-compiler.h" | 9 #include "src/ic/ic-compiler.h" |
11 | 10 |
12 namespace v8 { | 11 namespace v8 { |
13 namespace internal { | 12 namespace internal { |
14 | 13 |
15 #define __ ACCESS_MASM(masm) | 14 #define __ ACCESS_MASM(masm) |
16 | 15 |
17 void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup( | |
18 MacroAssembler* masm, Label* miss_label, Register receiver, | |
19 Handle<Name> name, Register scratch0, Register scratch1) { | |
20 DCHECK(name->IsUniqueName()); | |
21 DCHECK(!receiver.is(scratch0)); | |
22 Counters* counters = masm->isolate()->counters(); | |
23 __ IncrementCounter(counters->negative_lookups(), 1); | |
24 __ IncrementCounter(counters->negative_lookups_miss(), 1); | |
25 | 16 |
26 __ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset)); | 17 void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 18 StrictMode strict_mode) { |
| 19 // Return address is on the stack. |
| 20 DCHECK(!ebx.is(StoreIC::ReceiverRegister()) && |
| 21 !ebx.is(StoreIC::NameRegister()) && !ebx.is(StoreIC::ValueRegister())); |
| 22 __ pop(ebx); |
| 23 __ push(StoreIC::ReceiverRegister()); |
| 24 __ push(StoreIC::NameRegister()); |
| 25 __ push(StoreIC::ValueRegister()); |
| 26 __ push(Immediate(Smi::FromInt(strict_mode))); |
| 27 __ push(ebx); // return address |
27 | 28 |
28 const int kInterceptorOrAccessCheckNeededMask = | 29 // Do tail-call to runtime routine. |
29 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded); | 30 __ TailCallRuntime(Runtime::kSetProperty, 4, 1); |
30 | |
31 // Bail out if the receiver has a named interceptor or requires access checks. | |
32 __ test_b(FieldOperand(scratch0, Map::kBitFieldOffset), | |
33 kInterceptorOrAccessCheckNeededMask); | |
34 __ j(not_zero, miss_label); | |
35 | |
36 // Check that receiver is a JSObject. | |
37 __ CmpInstanceType(scratch0, FIRST_SPEC_OBJECT_TYPE); | |
38 __ j(below, miss_label); | |
39 | |
40 // Load properties array. | |
41 Register properties = scratch0; | |
42 __ mov(properties, FieldOperand(receiver, JSObject::kPropertiesOffset)); | |
43 | |
44 // Check that the properties array is a dictionary. | |
45 __ cmp(FieldOperand(properties, HeapObject::kMapOffset), | |
46 Immediate(masm->isolate()->factory()->hash_table_map())); | |
47 __ j(not_equal, miss_label); | |
48 | |
49 Label done; | |
50 NameDictionaryLookupStub::GenerateNegativeLookup(masm, miss_label, &done, | |
51 properties, name, scratch1); | |
52 __ bind(&done); | |
53 __ DecrementCounter(counters->negative_lookups_miss(), 1); | |
54 } | |
55 | |
56 | |
57 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype( | |
58 MacroAssembler* masm, int index, Register prototype, Label* miss) { | |
59 // Get the global function with the given index. | |
60 Handle<JSFunction> function( | |
61 JSFunction::cast(masm->isolate()->native_context()->get(index))); | |
62 // Check we're still in the same context. | |
63 Register scratch = prototype; | |
64 const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX); | |
65 __ mov(scratch, Operand(esi, offset)); | |
66 __ mov(scratch, FieldOperand(scratch, GlobalObject::kNativeContextOffset)); | |
67 __ cmp(Operand(scratch, Context::SlotOffset(index)), function); | |
68 __ j(not_equal, miss); | |
69 | |
70 // Load its initial map. The global functions all have initial maps. | |
71 __ Move(prototype, Immediate(Handle<Map>(function->initial_map()))); | |
72 // Load the prototype from the initial map. | |
73 __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset)); | |
74 } | |
75 | |
76 | |
77 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype( | |
78 MacroAssembler* masm, Register receiver, Register scratch1, | |
79 Register scratch2, Label* miss_label) { | |
80 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); | |
81 __ mov(eax, scratch1); | |
82 __ ret(0); | |
83 } | |
84 | |
85 | |
86 static void PushInterceptorArguments(MacroAssembler* masm, Register receiver, | |
87 Register holder, Register name, | |
88 Handle<JSObject> holder_obj) { | |
89 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0); | |
90 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1); | |
91 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2); | |
92 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3); | |
93 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4); | |
94 __ push(name); | |
95 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor()); | |
96 DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor)); | |
97 Register scratch = name; | |
98 __ mov(scratch, Immediate(interceptor)); | |
99 __ push(scratch); | |
100 __ push(receiver); | |
101 __ push(holder); | |
102 } | |
103 | |
104 | |
105 static void CompileCallLoadPropertyWithInterceptor( | |
106 MacroAssembler* masm, Register receiver, Register holder, Register name, | |
107 Handle<JSObject> holder_obj, IC::UtilityId id) { | |
108 PushInterceptorArguments(masm, receiver, holder, name, holder_obj); | |
109 __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()), | |
110 NamedLoadHandlerCompiler::kInterceptorArgsLength); | |
111 } | |
112 | |
113 | |
114 // Generate call to api function. | |
115 // This function uses push() to generate smaller, faster code than | |
116 // the version above. It is an optimization that should will be removed | |
117 // when api call ICs are generated in hydrogen. | |
118 void PropertyHandlerCompiler::GenerateFastApiCall( | |
119 MacroAssembler* masm, const CallOptimization& optimization, | |
120 Handle<Map> receiver_map, Register receiver, Register scratch_in, | |
121 bool is_store, int argc, Register* values) { | |
122 // Copy return value. | |
123 __ pop(scratch_in); | |
124 // receiver | |
125 __ push(receiver); | |
126 // Write the arguments to stack frame. | |
127 for (int i = 0; i < argc; i++) { | |
128 Register arg = values[argc - 1 - i]; | |
129 DCHECK(!receiver.is(arg)); | |
130 DCHECK(!scratch_in.is(arg)); | |
131 __ push(arg); | |
132 } | |
133 __ push(scratch_in); | |
134 // Stack now matches JSFunction abi. | |
135 DCHECK(optimization.is_simple_api_call()); | |
136 | |
137 // Abi for CallApiFunctionStub. | |
138 Register callee = eax; | |
139 Register call_data = ebx; | |
140 Register holder = ecx; | |
141 Register api_function_address = edx; | |
142 Register scratch = edi; // scratch_in is no longer valid. | |
143 | |
144 // Put holder in place. | |
145 CallOptimization::HolderLookup holder_lookup; | |
146 Handle<JSObject> api_holder = | |
147 optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup); | |
148 switch (holder_lookup) { | |
149 case CallOptimization::kHolderIsReceiver: | |
150 __ Move(holder, receiver); | |
151 break; | |
152 case CallOptimization::kHolderFound: | |
153 __ LoadHeapObject(holder, api_holder); | |
154 break; | |
155 case CallOptimization::kHolderNotFound: | |
156 UNREACHABLE(); | |
157 break; | |
158 } | |
159 | |
160 Isolate* isolate = masm->isolate(); | |
161 Handle<JSFunction> function = optimization.constant_function(); | |
162 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); | |
163 Handle<Object> call_data_obj(api_call_info->data(), isolate); | |
164 | |
165 // Put callee in place. | |
166 __ LoadHeapObject(callee, function); | |
167 | |
168 bool call_data_undefined = false; | |
169 // Put call_data in place. | |
170 if (isolate->heap()->InNewSpace(*call_data_obj)) { | |
171 __ mov(scratch, api_call_info); | |
172 __ mov(call_data, FieldOperand(scratch, CallHandlerInfo::kDataOffset)); | |
173 } else if (call_data_obj->IsUndefined()) { | |
174 call_data_undefined = true; | |
175 __ mov(call_data, Immediate(isolate->factory()->undefined_value())); | |
176 } else { | |
177 __ mov(call_data, call_data_obj); | |
178 } | |
179 | |
180 // Put api_function_address in place. | |
181 Address function_address = v8::ToCData<Address>(api_call_info->callback()); | |
182 __ mov(api_function_address, Immediate(function_address)); | |
183 | |
184 // Jump to stub. | |
185 CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc); | |
186 __ TailCallStub(&stub); | |
187 } | |
188 | |
189 | |
190 // Generate code to check that a global property cell is empty. Create | |
191 // the property cell at compilation time if no cell exists for the | |
192 // property. | |
193 void PropertyHandlerCompiler::GenerateCheckPropertyCell( | |
194 MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name, | |
195 Register scratch, Label* miss) { | |
196 Handle<PropertyCell> cell = JSGlobalObject::EnsurePropertyCell(global, name); | |
197 DCHECK(cell->value()->IsTheHole()); | |
198 Handle<Oddball> the_hole = masm->isolate()->factory()->the_hole_value(); | |
199 if (masm->serializer_enabled()) { | |
200 __ mov(scratch, Immediate(cell)); | |
201 __ cmp(FieldOperand(scratch, PropertyCell::kValueOffset), | |
202 Immediate(the_hole)); | |
203 } else { | |
204 __ cmp(Operand::ForCell(cell), Immediate(the_hole)); | |
205 } | |
206 __ j(not_equal, miss); | |
207 } | 31 } |
208 | 32 |
209 | 33 |
210 #undef __ | 34 #undef __ |
211 #define __ ACCESS_MASM(masm()) | 35 #define __ ACCESS_MASM(masm()) |
212 | 36 |
213 | |
214 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label, | |
215 Handle<Name> name) { | |
216 if (!label->is_unused()) { | |
217 __ bind(label); | |
218 __ mov(this->name(), Immediate(name)); | |
219 } | |
220 } | |
221 | |
222 | |
223 // Receiver_reg is preserved on jumps to miss_label, but may be destroyed if | |
224 // store is successful. | |
225 void NamedStoreHandlerCompiler::GenerateStoreTransition( | |
226 Handle<Map> transition, Handle<Name> name, Register receiver_reg, | |
227 Register storage_reg, Register value_reg, Register scratch1, | |
228 Register scratch2, Register unused, Label* miss_label, Label* slow) { | |
229 int descriptor = transition->LastAdded(); | |
230 DescriptorArray* descriptors = transition->instance_descriptors(); | |
231 PropertyDetails details = descriptors->GetDetails(descriptor); | |
232 Representation representation = details.representation(); | |
233 DCHECK(!representation.IsNone()); | |
234 | |
235 if (details.type() == CONSTANT) { | |
236 Handle<Object> constant(descriptors->GetValue(descriptor), isolate()); | |
237 __ CmpObject(value_reg, constant); | |
238 __ j(not_equal, miss_label); | |
239 } else if (representation.IsSmi()) { | |
240 __ JumpIfNotSmi(value_reg, miss_label); | |
241 } else if (representation.IsHeapObject()) { | |
242 __ JumpIfSmi(value_reg, miss_label); | |
243 HeapType* field_type = descriptors->GetFieldType(descriptor); | |
244 HeapType::Iterator<Map> it = field_type->Classes(); | |
245 if (!it.Done()) { | |
246 Label do_store; | |
247 while (true) { | |
248 __ CompareMap(value_reg, it.Current()); | |
249 it.Advance(); | |
250 if (it.Done()) { | |
251 __ j(not_equal, miss_label); | |
252 break; | |
253 } | |
254 __ j(equal, &do_store, Label::kNear); | |
255 } | |
256 __ bind(&do_store); | |
257 } | |
258 } else if (representation.IsDouble()) { | |
259 Label do_store, heap_number; | |
260 __ AllocateHeapNumber(storage_reg, scratch1, scratch2, slow, MUTABLE); | |
261 | |
262 __ JumpIfNotSmi(value_reg, &heap_number); | |
263 __ SmiUntag(value_reg); | |
264 __ Cvtsi2sd(xmm0, value_reg); | |
265 __ SmiTag(value_reg); | |
266 __ jmp(&do_store); | |
267 | |
268 __ bind(&heap_number); | |
269 __ CheckMap(value_reg, isolate()->factory()->heap_number_map(), miss_label, | |
270 DONT_DO_SMI_CHECK); | |
271 __ movsd(xmm0, FieldOperand(value_reg, HeapNumber::kValueOffset)); | |
272 | |
273 __ bind(&do_store); | |
274 __ movsd(FieldOperand(storage_reg, HeapNumber::kValueOffset), xmm0); | |
275 } | |
276 | |
277 // Stub never generated for objects that require access checks. | |
278 DCHECK(!transition->is_access_check_needed()); | |
279 | |
280 // Perform map transition for the receiver if necessary. | |
281 if (details.type() == FIELD && | |
282 Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) { | |
283 // The properties must be extended before we can store the value. | |
284 // We jump to a runtime call that extends the properties array. | |
285 __ pop(scratch1); // Return address. | |
286 __ push(receiver_reg); | |
287 __ push(Immediate(transition)); | |
288 __ push(value_reg); | |
289 __ push(scratch1); | |
290 __ TailCallExternalReference( | |
291 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage), | |
292 isolate()), | |
293 3, 1); | |
294 return; | |
295 } | |
296 | |
297 // Update the map of the object. | |
298 __ mov(scratch1, Immediate(transition)); | |
299 __ mov(FieldOperand(receiver_reg, HeapObject::kMapOffset), scratch1); | |
300 | |
301 // Update the write barrier for the map field. | |
302 __ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2, | |
303 kDontSaveFPRegs, OMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | |
304 | |
305 if (details.type() == CONSTANT) { | |
306 DCHECK(value_reg.is(eax)); | |
307 __ ret(0); | |
308 return; | |
309 } | |
310 | |
311 int index = transition->instance_descriptors()->GetFieldIndex( | |
312 transition->LastAdded()); | |
313 | |
314 // Adjust for the number of properties stored in the object. Even in the | |
315 // face of a transition we can use the old map here because the size of the | |
316 // object and the number of in-object properties is not going to change. | |
317 index -= transition->inobject_properties(); | |
318 | |
319 SmiCheck smi_check = | |
320 representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK; | |
321 // TODO(verwaest): Share this code as a code stub. | |
322 if (index < 0) { | |
323 // Set the property straight into the object. | |
324 int offset = transition->instance_size() + (index * kPointerSize); | |
325 if (representation.IsDouble()) { | |
326 __ mov(FieldOperand(receiver_reg, offset), storage_reg); | |
327 } else { | |
328 __ mov(FieldOperand(receiver_reg, offset), value_reg); | |
329 } | |
330 | |
331 if (!representation.IsSmi()) { | |
332 // Update the write barrier for the array address. | |
333 if (!representation.IsDouble()) { | |
334 __ mov(storage_reg, value_reg); | |
335 } | |
336 __ RecordWriteField(receiver_reg, offset, storage_reg, scratch1, | |
337 kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check); | |
338 } | |
339 } else { | |
340 // Write to the properties array. | |
341 int offset = index * kPointerSize + FixedArray::kHeaderSize; | |
342 // Get the properties array (optimistically). | |
343 __ mov(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset)); | |
344 if (representation.IsDouble()) { | |
345 __ mov(FieldOperand(scratch1, offset), storage_reg); | |
346 } else { | |
347 __ mov(FieldOperand(scratch1, offset), value_reg); | |
348 } | |
349 | |
350 if (!representation.IsSmi()) { | |
351 // Update the write barrier for the array address. | |
352 if (!representation.IsDouble()) { | |
353 __ mov(storage_reg, value_reg); | |
354 } | |
355 __ RecordWriteField(scratch1, offset, storage_reg, receiver_reg, | |
356 kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check); | |
357 } | |
358 } | |
359 | |
360 // Return the value (register eax). | |
361 DCHECK(value_reg.is(eax)); | |
362 __ ret(0); | |
363 } | |
364 | |
365 | |
366 void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup, | |
367 Register value_reg, | |
368 Label* miss_label) { | |
369 DCHECK(lookup->representation().IsHeapObject()); | |
370 __ JumpIfSmi(value_reg, miss_label); | |
371 HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes(); | |
372 Label do_store; | |
373 while (true) { | |
374 __ CompareMap(value_reg, it.Current()); | |
375 it.Advance(); | |
376 if (it.Done()) { | |
377 __ j(not_equal, miss_label); | |
378 break; | |
379 } | |
380 __ j(equal, &do_store, Label::kNear); | |
381 } | |
382 __ bind(&do_store); | |
383 | |
384 StoreFieldStub stub(isolate(), lookup->GetFieldIndex(), | |
385 lookup->representation()); | |
386 GenerateTailCall(masm(), stub.GetCode()); | |
387 } | |
388 | |
389 | |
390 Register PropertyHandlerCompiler::CheckPrototypes( | |
391 Register object_reg, Register holder_reg, Register scratch1, | |
392 Register scratch2, Handle<Name> name, Label* miss, | |
393 PrototypeCheckType check) { | |
394 Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate())); | |
395 | |
396 // Make sure there's no overlap between holder and object registers. | |
397 DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg)); | |
398 DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) && | |
399 !scratch2.is(scratch1)); | |
400 | |
401 // Keep track of the current object in register reg. | |
402 Register reg = object_reg; | |
403 int depth = 0; | |
404 | |
405 Handle<JSObject> current = Handle<JSObject>::null(); | |
406 if (type()->IsConstant()) | |
407 current = Handle<JSObject>::cast(type()->AsConstant()->Value()); | |
408 Handle<JSObject> prototype = Handle<JSObject>::null(); | |
409 Handle<Map> current_map = receiver_map; | |
410 Handle<Map> holder_map(holder()->map()); | |
411 // Traverse the prototype chain and check the maps in the prototype chain for | |
412 // fast and global objects or do negative lookup for normal objects. | |
413 while (!current_map.is_identical_to(holder_map)) { | |
414 ++depth; | |
415 | |
416 // Only global objects and objects that do not require access | |
417 // checks are allowed in stubs. | |
418 DCHECK(current_map->IsJSGlobalProxyMap() || | |
419 !current_map->is_access_check_needed()); | |
420 | |
421 prototype = handle(JSObject::cast(current_map->prototype())); | |
422 if (current_map->is_dictionary_map() && | |
423 !current_map->IsJSGlobalObjectMap()) { | |
424 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast. | |
425 if (!name->IsUniqueName()) { | |
426 DCHECK(name->IsString()); | |
427 name = factory()->InternalizeString(Handle<String>::cast(name)); | |
428 } | |
429 DCHECK(current.is_null() || | |
430 current->property_dictionary()->FindEntry(name) == | |
431 NameDictionary::kNotFound); | |
432 | |
433 GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1, | |
434 scratch2); | |
435 | |
436 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); | |
437 reg = holder_reg; // From now on the object will be in holder_reg. | |
438 __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset)); | |
439 } else { | |
440 bool in_new_space = heap()->InNewSpace(*prototype); | |
441 // Two possible reasons for loading the prototype from the map: | |
442 // (1) Can't store references to new space in code. | |
443 // (2) Handler is shared for all receivers with the same prototype | |
444 // map (but not necessarily the same prototype instance). | |
445 bool load_prototype_from_map = in_new_space || depth == 1; | |
446 if (depth != 1 || check == CHECK_ALL_MAPS) { | |
447 __ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK); | |
448 } | |
449 | |
450 // Check access rights to the global object. This has to happen after | |
451 // the map check so that we know that the object is actually a global | |
452 // object. | |
453 // This allows us to install generated handlers for accesses to the | |
454 // global proxy (as opposed to using slow ICs). See corresponding code | |
455 // in LookupForRead(). | |
456 if (current_map->IsJSGlobalProxyMap()) { | |
457 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss); | |
458 } else if (current_map->IsJSGlobalObjectMap()) { | |
459 GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current), | |
460 name, scratch2, miss); | |
461 } | |
462 | |
463 if (load_prototype_from_map) { | |
464 // Save the map in scratch1 for later. | |
465 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); | |
466 } | |
467 | |
468 reg = holder_reg; // From now on the object will be in holder_reg. | |
469 | |
470 if (load_prototype_from_map) { | |
471 __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset)); | |
472 } else { | |
473 __ mov(reg, prototype); | |
474 } | |
475 } | |
476 | |
477 // Go to the next object in the prototype chain. | |
478 current = prototype; | |
479 current_map = handle(current->map()); | |
480 } | |
481 | |
482 // Log the check depth. | |
483 LOG(isolate(), IntEvent("check-maps-depth", depth + 1)); | |
484 | |
485 if (depth != 0 || check == CHECK_ALL_MAPS) { | |
486 // Check the holder map. | |
487 __ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK); | |
488 } | |
489 | |
490 // Perform security check for access to the global object. | |
491 DCHECK(current_map->IsJSGlobalProxyMap() || | |
492 !current_map->is_access_check_needed()); | |
493 if (current_map->IsJSGlobalProxyMap()) { | |
494 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss); | |
495 } | |
496 | |
497 // Return the register containing the holder. | |
498 return reg; | |
499 } | |
500 | |
501 | |
502 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) { | |
503 if (!miss->is_unused()) { | |
504 Label success; | |
505 __ jmp(&success); | |
506 __ bind(miss); | |
507 TailCallBuiltin(masm(), MissBuiltin(kind())); | |
508 __ bind(&success); | |
509 } | |
510 } | |
511 | |
512 | |
513 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) { | |
514 if (!miss->is_unused()) { | |
515 Label success; | |
516 __ jmp(&success); | |
517 GenerateRestoreName(miss, name); | |
518 TailCallBuiltin(masm(), MissBuiltin(kind())); | |
519 __ bind(&success); | |
520 } | |
521 } | |
522 | |
523 | |
524 void NamedLoadHandlerCompiler::GenerateLoadCallback( | |
525 Register reg, Handle<ExecutableAccessorInfo> callback) { | |
526 // Insert additional parameters into the stack frame above return address. | |
527 DCHECK(!scratch3().is(reg)); | |
528 __ pop(scratch3()); // Get return address to place it below. | |
529 | |
530 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0); | |
531 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1); | |
532 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2); | |
533 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3); | |
534 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4); | |
535 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5); | |
536 __ push(receiver()); // receiver | |
537 // Push data from ExecutableAccessorInfo. | |
538 if (isolate()->heap()->InNewSpace(callback->data())) { | |
539 DCHECK(!scratch2().is(reg)); | |
540 __ mov(scratch2(), Immediate(callback)); | |
541 __ push(FieldOperand(scratch2(), ExecutableAccessorInfo::kDataOffset)); | |
542 } else { | |
543 __ push(Immediate(Handle<Object>(callback->data(), isolate()))); | |
544 } | |
545 __ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue | |
546 // ReturnValue default value | |
547 __ push(Immediate(isolate()->factory()->undefined_value())); | |
548 __ push(Immediate(reinterpret_cast<int>(isolate()))); | |
549 __ push(reg); // holder | |
550 | |
551 // Save a pointer to where we pushed the arguments. This will be | |
552 // passed as the const PropertyAccessorInfo& to the C++ callback. | |
553 __ push(esp); | |
554 | |
555 __ push(name()); // name | |
556 | |
557 __ push(scratch3()); // Restore return address. | |
558 | |
559 // Abi for CallApiGetter | |
560 Register getter_address = edx; | |
561 Address function_address = v8::ToCData<Address>(callback->getter()); | |
562 __ mov(getter_address, Immediate(function_address)); | |
563 | |
564 CallApiGetterStub stub(isolate()); | |
565 __ TailCallStub(&stub); | |
566 } | |
567 | |
568 | |
569 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) { | |
570 // Return the constant value. | |
571 __ LoadObject(eax, value); | |
572 __ ret(0); | |
573 } | |
574 | |
575 | |
576 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup( | |
577 LookupIterator* it, Register holder_reg) { | |
578 DCHECK(holder()->HasNamedInterceptor()); | |
579 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined()); | |
580 | |
581 // Compile the interceptor call, followed by inline code to load the | |
582 // property from further up the prototype chain if the call fails. | |
583 // Check that the maps haven't changed. | |
584 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1())); | |
585 | |
586 // Preserve the receiver register explicitly whenever it is different from the | |
587 // holder and it is needed should the interceptor return without any result. | |
588 // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD | |
589 // case might cause a miss during the prototype check. | |
590 bool must_perform_prototype_check = | |
591 !holder().is_identical_to(it->GetHolder<JSObject>()); | |
592 bool must_preserve_receiver_reg = | |
593 !receiver().is(holder_reg) && | |
594 (it->property_kind() == LookupIterator::ACCESSOR || | |
595 must_perform_prototype_check); | |
596 | |
597 // Save necessary data before invoking an interceptor. | |
598 // Requires a frame to make GC aware of pushed pointers. | |
599 { | |
600 FrameScope frame_scope(masm(), StackFrame::INTERNAL); | |
601 | |
602 if (must_preserve_receiver_reg) { | |
603 __ push(receiver()); | |
604 } | |
605 __ push(holder_reg); | |
606 __ push(this->name()); | |
607 | |
608 // Invoke an interceptor. Note: map checks from receiver to | |
609 // interceptor's holder has been compiled before (see a caller | |
610 // of this method.) | |
611 CompileCallLoadPropertyWithInterceptor( | |
612 masm(), receiver(), holder_reg, this->name(), holder(), | |
613 IC::kLoadPropertyWithInterceptorOnly); | |
614 | |
615 // Check if interceptor provided a value for property. If it's | |
616 // the case, return immediately. | |
617 Label interceptor_failed; | |
618 __ cmp(eax, factory()->no_interceptor_result_sentinel()); | |
619 __ j(equal, &interceptor_failed); | |
620 frame_scope.GenerateLeaveFrame(); | |
621 __ ret(0); | |
622 | |
623 // Clobber registers when generating debug-code to provoke errors. | |
624 __ bind(&interceptor_failed); | |
625 if (FLAG_debug_code) { | |
626 __ mov(receiver(), Immediate(BitCast<int32_t>(kZapValue))); | |
627 __ mov(holder_reg, Immediate(BitCast<int32_t>(kZapValue))); | |
628 __ mov(this->name(), Immediate(BitCast<int32_t>(kZapValue))); | |
629 } | |
630 | |
631 __ pop(this->name()); | |
632 __ pop(holder_reg); | |
633 if (must_preserve_receiver_reg) { | |
634 __ pop(receiver()); | |
635 } | |
636 | |
637 // Leave the internal frame. | |
638 } | |
639 | |
640 GenerateLoadPostInterceptor(it, holder_reg); | |
641 } | |
642 | |
643 | |
644 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) { | |
645 DCHECK(holder()->HasNamedInterceptor()); | |
646 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined()); | |
647 // Call the runtime system to load the interceptor. | |
648 __ pop(scratch2()); // save old return address | |
649 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(), | |
650 holder()); | |
651 __ push(scratch2()); // restore old return address | |
652 | |
653 ExternalReference ref = ExternalReference( | |
654 IC_Utility(IC::kLoadPropertyWithInterceptor), isolate()); | |
655 __ TailCallExternalReference( | |
656 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1); | |
657 } | |
658 | |
659 | |
660 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback( | |
661 Handle<JSObject> object, Handle<Name> name, | |
662 Handle<ExecutableAccessorInfo> callback) { | |
663 Register holder_reg = Frontend(receiver(), name); | |
664 | |
665 __ pop(scratch1()); // remove the return address | |
666 __ push(receiver()); | |
667 __ push(holder_reg); | |
668 __ Push(callback); | |
669 __ Push(name); | |
670 __ push(value()); | |
671 __ push(scratch1()); // restore return address | |
672 | |
673 // Do tail-call to the runtime system. | |
674 ExternalReference store_callback_property = | |
675 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate()); | |
676 __ TailCallExternalReference(store_callback_property, 5, 1); | |
677 | |
678 // Return the generated code. | |
679 return GetCode(kind(), Code::FAST, name); | |
680 } | |
681 | |
682 | |
683 #undef __ | |
684 #define __ ACCESS_MASM(masm) | |
685 | |
686 | |
687 void NamedStoreHandlerCompiler::GenerateStoreViaSetter( | |
688 MacroAssembler* masm, Handle<HeapType> type, Register receiver, | |
689 Handle<JSFunction> setter) { | |
690 // ----------- S t a t e ------------- | |
691 // -- esp[0] : return address | |
692 // ----------------------------------- | |
693 { | |
694 FrameScope scope(masm, StackFrame::INTERNAL); | |
695 | |
696 // Save value register, so we can restore it later. | |
697 __ push(value()); | |
698 | |
699 if (!setter.is_null()) { | |
700 // Call the JavaScript setter with receiver and value on the stack. | |
701 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) { | |
702 // Swap in the global receiver. | |
703 __ mov(receiver, | |
704 FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset)); | |
705 } | |
706 __ push(receiver); | |
707 __ push(value()); | |
708 ParameterCount actual(1); | |
709 ParameterCount expected(setter); | |
710 __ InvokeFunction(setter, expected, actual, CALL_FUNCTION, | |
711 NullCallWrapper()); | |
712 } else { | |
713 // If we generate a global code snippet for deoptimization only, remember | |
714 // the place to continue after deoptimization. | |
715 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset()); | |
716 } | |
717 | |
718 // We have to return the passed value, not the return value of the setter. | |
719 __ pop(eax); | |
720 | |
721 // Restore context register. | |
722 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
723 } | |
724 __ ret(0); | |
725 } | |
726 | |
727 | |
728 #undef __ | |
729 #define __ ACCESS_MASM(masm()) | |
730 | |
731 | |
732 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor( | |
733 Handle<Name> name) { | |
734 __ pop(scratch1()); // remove the return address | |
735 __ push(receiver()); | |
736 __ push(this->name()); | |
737 __ push(value()); | |
738 __ push(scratch1()); // restore return address | |
739 | |
740 // Do tail-call to the runtime system. | |
741 ExternalReference store_ic_property = ExternalReference( | |
742 IC_Utility(IC::kStorePropertyWithInterceptor), isolate()); | |
743 __ TailCallExternalReference(store_ic_property, 3, 1); | |
744 | |
745 // Return the generated code. | |
746 return GetCode(kind(), Code::FAST, name); | |
747 } | |
748 | |
749 | |
750 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic( | |
751 MapHandleList* receiver_maps, CodeHandleList* handler_stubs, | |
752 MapHandleList* transitioned_maps) { | |
753 Label miss; | |
754 __ JumpIfSmi(receiver(), &miss, Label::kNear); | |
755 __ mov(scratch1(), FieldOperand(receiver(), HeapObject::kMapOffset)); | |
756 for (int i = 0; i < receiver_maps->length(); ++i) { | |
757 __ cmp(scratch1(), receiver_maps->at(i)); | |
758 if (transitioned_maps->at(i).is_null()) { | |
759 __ j(equal, handler_stubs->at(i)); | |
760 } else { | |
761 Label next_map; | |
762 __ j(not_equal, &next_map, Label::kNear); | |
763 __ mov(transition_map(), Immediate(transitioned_maps->at(i))); | |
764 __ jmp(handler_stubs->at(i), RelocInfo::CODE_TARGET); | |
765 __ bind(&next_map); | |
766 } | |
767 } | |
768 __ bind(&miss); | |
769 TailCallBuiltin(masm(), MissBuiltin(kind())); | |
770 | |
771 // Return the generated code. | |
772 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC); | |
773 } | |
774 | |
775 | |
776 Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); } | |
777 | |
778 | |
779 #undef __ | |
780 #define __ ACCESS_MASM(masm) | |
781 | |
782 | |
783 void NamedLoadHandlerCompiler::GenerateLoadViaGetter( | |
784 MacroAssembler* masm, Handle<HeapType> type, Register receiver, | |
785 Handle<JSFunction> getter) { | |
786 { | |
787 FrameScope scope(masm, StackFrame::INTERNAL); | |
788 | |
789 if (!getter.is_null()) { | |
790 // Call the JavaScript getter with the receiver on the stack. | |
791 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) { | |
792 // Swap in the global receiver. | |
793 __ mov(receiver, | |
794 FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset)); | |
795 } | |
796 __ push(receiver); | |
797 ParameterCount actual(0); | |
798 ParameterCount expected(getter); | |
799 __ InvokeFunction(getter, expected, actual, CALL_FUNCTION, | |
800 NullCallWrapper()); | |
801 } else { | |
802 // If we generate a global code snippet for deoptimization only, remember | |
803 // the place to continue after deoptimization. | |
804 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset()); | |
805 } | |
806 | |
807 // Restore context register. | |
808 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
809 } | |
810 __ ret(0); | |
811 } | |
812 | |
813 | |
814 #undef __ | |
815 #define __ ACCESS_MASM(masm()) | |
816 | |
817 | |
818 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal( | |
819 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) { | |
820 Label miss; | |
821 | |
822 FrontendHeader(receiver(), name, &miss); | |
823 // Get the value from the cell. | |
824 Register result = StoreIC::ValueRegister(); | |
825 if (masm()->serializer_enabled()) { | |
826 __ mov(result, Immediate(cell)); | |
827 __ mov(result, FieldOperand(result, PropertyCell::kValueOffset)); | |
828 } else { | |
829 __ mov(result, Operand::ForCell(cell)); | |
830 } | |
831 | |
832 // Check for deleted property if property can actually be deleted. | |
833 if (is_configurable) { | |
834 __ cmp(result, factory()->the_hole_value()); | |
835 __ j(equal, &miss); | |
836 } else if (FLAG_debug_code) { | |
837 __ cmp(result, factory()->the_hole_value()); | |
838 __ Check(not_equal, kDontDeleteCellsCannotContainTheHole); | |
839 } | |
840 | |
841 Counters* counters = isolate()->counters(); | |
842 __ IncrementCounter(counters->named_load_global_stub(), 1); | |
843 // The code above already loads the result into the return register. | |
844 __ ret(0); | |
845 | |
846 FrontendFooter(name, &miss); | |
847 | |
848 // Return the generated code. | |
849 return GetCode(kind(), Code::NORMAL, name); | |
850 } | |
851 | |
852 | |
853 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types, | 37 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types, |
854 CodeHandleList* handlers, | 38 CodeHandleList* handlers, |
855 Handle<Name> name, | 39 Handle<Name> name, |
856 Code::StubType type, | 40 Code::StubType type, |
857 IcCheckType check) { | 41 IcCheckType check) { |
858 Label miss; | 42 Label miss; |
859 | 43 |
860 if (check == PROPERTY && | 44 if (check == PROPERTY && |
861 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) { | 45 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) { |
862 // In case we are compiling an IC for dictionary loads and stores, just | 46 // In case we are compiling an IC for dictionary loads and stores, just |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 __ bind(&miss); | 82 __ bind(&miss); |
899 TailCallBuiltin(masm(), MissBuiltin(kind())); | 83 TailCallBuiltin(masm(), MissBuiltin(kind())); |
900 | 84 |
901 // Return the generated code. | 85 // Return the generated code. |
902 InlineCacheState state = | 86 InlineCacheState state = |
903 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC; | 87 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC; |
904 return GetCode(kind(), type, name, state); | 88 return GetCode(kind(), type, name, state); |
905 } | 89 } |
906 | 90 |
907 | 91 |
908 #undef __ | 92 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic( |
909 #define __ ACCESS_MASM(masm) | 93 MapHandleList* receiver_maps, CodeHandleList* handler_stubs, |
| 94 MapHandleList* transitioned_maps) { |
| 95 Label miss; |
| 96 __ JumpIfSmi(receiver(), &miss, Label::kNear); |
| 97 __ mov(scratch1(), FieldOperand(receiver(), HeapObject::kMapOffset)); |
| 98 for (int i = 0; i < receiver_maps->length(); ++i) { |
| 99 __ cmp(scratch1(), receiver_maps->at(i)); |
| 100 if (transitioned_maps->at(i).is_null()) { |
| 101 __ j(equal, handler_stubs->at(i)); |
| 102 } else { |
| 103 Label next_map; |
| 104 __ j(not_equal, &next_map, Label::kNear); |
| 105 __ mov(transition_map(), Immediate(transitioned_maps->at(i))); |
| 106 __ jmp(handler_stubs->at(i), RelocInfo::CODE_TARGET); |
| 107 __ bind(&next_map); |
| 108 } |
| 109 } |
| 110 __ bind(&miss); |
| 111 TailCallBuiltin(masm(), MissBuiltin(kind())); |
910 | 112 |
911 | 113 // Return the generated code. |
912 void ElementHandlerCompiler::GenerateLoadDictionaryElement( | 114 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC); |
913 MacroAssembler* masm) { | |
914 // ----------- S t a t e ------------- | |
915 // -- ecx : key | |
916 // -- edx : receiver | |
917 // -- esp[0] : return address | |
918 // ----------------------------------- | |
919 DCHECK(edx.is(LoadIC::ReceiverRegister())); | |
920 DCHECK(ecx.is(LoadIC::NameRegister())); | |
921 Label slow, miss; | |
922 | |
923 // This stub is meant to be tail-jumped to, the receiver must already | |
924 // have been verified by the caller to not be a smi. | |
925 __ JumpIfNotSmi(ecx, &miss); | |
926 __ mov(ebx, ecx); | |
927 __ SmiUntag(ebx); | |
928 __ mov(eax, FieldOperand(edx, JSObject::kElementsOffset)); | |
929 | |
930 // Push receiver on the stack to free up a register for the dictionary | |
931 // probing. | |
932 __ push(edx); | |
933 __ LoadFromNumberDictionary(&slow, eax, ecx, ebx, edx, edi, eax); | |
934 // Pop receiver before returning. | |
935 __ pop(edx); | |
936 __ ret(0); | |
937 | |
938 __ bind(&slow); | |
939 __ pop(edx); | |
940 | |
941 // ----------- S t a t e ------------- | |
942 // -- ecx : key | |
943 // -- edx : receiver | |
944 // -- esp[0] : return address | |
945 // ----------------------------------- | |
946 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow); | |
947 | |
948 __ bind(&miss); | |
949 // ----------- S t a t e ------------- | |
950 // -- ecx : key | |
951 // -- edx : receiver | |
952 // -- esp[0] : return address | |
953 // ----------------------------------- | |
954 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); | |
955 } | 115 } |
956 | 116 |
957 | 117 |
958 void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm, | |
959 StrictMode strict_mode) { | |
960 // Return address is on the stack. | |
961 DCHECK(!ebx.is(StoreIC::ReceiverRegister()) && | |
962 !ebx.is(StoreIC::NameRegister()) && !ebx.is(StoreIC::ValueRegister())); | |
963 __ pop(ebx); | |
964 __ push(StoreIC::ReceiverRegister()); | |
965 __ push(StoreIC::NameRegister()); | |
966 __ push(StoreIC::ValueRegister()); | |
967 __ push(Immediate(Smi::FromInt(strict_mode))); | |
968 __ push(ebx); // return address | |
969 | |
970 // Do tail-call to runtime routine. | |
971 __ TailCallRuntime(Runtime::kSetProperty, 4, 1); | |
972 } | |
973 | |
974 | |
975 #undef __ | 118 #undef __ |
976 } | 119 } |
977 } // namespace v8::internal | 120 } // namespace v8::internal |
978 | 121 |
979 #endif // V8_TARGET_ARCH_IA32 | 122 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |