Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/ic/x87/ic-compiler-x87.cc

Issue 504043002: X87: Move handler compilers to handler-compiler (Closed) Base URL: https://chromium.googlesource.com/external/v8.git@bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ic/x87/handler-compiler-x87.cc ('k') | src/x87/code-stubs-x87.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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 __ push(value_reg);
265 __ fild_s(Operand(esp, 0));
266 __ pop(value_reg);
267 __ SmiTag(value_reg);
268 __ jmp(&do_store);
269
270 __ bind(&heap_number);
271 __ CheckMap(value_reg, isolate()->factory()->heap_number_map(), miss_label,
272 DONT_DO_SMI_CHECK);
273 __ fld_d(FieldOperand(value_reg, HeapNumber::kValueOffset));
274
275 __ bind(&do_store);
276 __ fstp_d(FieldOperand(storage_reg, HeapNumber::kValueOffset));
277 }
278
279 // Stub never generated for objects that require access checks.
280 DCHECK(!transition->is_access_check_needed());
281
282 // Perform map transition for the receiver if necessary.
283 if (details.type() == FIELD &&
284 Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
285 // The properties must be extended before we can store the value.
286 // We jump to a runtime call that extends the properties array.
287 __ pop(scratch1); // Return address.
288 __ push(receiver_reg);
289 __ push(Immediate(transition));
290 __ push(value_reg);
291 __ push(scratch1);
292 __ TailCallExternalReference(
293 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
294 isolate()),
295 3, 1);
296 return;
297 }
298
299 // Update the map of the object.
300 __ mov(scratch1, Immediate(transition));
301 __ mov(FieldOperand(receiver_reg, HeapObject::kMapOffset), scratch1);
302
303 // Update the write barrier for the map field.
304 __ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
305 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
306
307 if (details.type() == CONSTANT) {
308 DCHECK(value_reg.is(eax));
309 __ ret(0);
310 return;
311 }
312
313 int index = transition->instance_descriptors()->GetFieldIndex(
314 transition->LastAdded());
315
316 // Adjust for the number of properties stored in the object. Even in the
317 // face of a transition we can use the old map here because the size of the
318 // object and the number of in-object properties is not going to change.
319 index -= transition->inobject_properties();
320
321 SmiCheck smi_check =
322 representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
323 // TODO(verwaest): Share this code as a code stub.
324 if (index < 0) {
325 // Set the property straight into the object.
326 int offset = transition->instance_size() + (index * kPointerSize);
327 if (representation.IsDouble()) {
328 __ mov(FieldOperand(receiver_reg, offset), storage_reg);
329 } else {
330 __ mov(FieldOperand(receiver_reg, offset), value_reg);
331 }
332
333 if (!representation.IsSmi()) {
334 // Update the write barrier for the array address.
335 if (!representation.IsDouble()) {
336 __ mov(storage_reg, value_reg);
337 }
338 __ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
339 EMIT_REMEMBERED_SET, smi_check);
340 }
341 } else {
342 // Write to the properties array.
343 int offset = index * kPointerSize + FixedArray::kHeaderSize;
344 // Get the properties array (optimistically).
345 __ mov(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset));
346 if (representation.IsDouble()) {
347 __ mov(FieldOperand(scratch1, offset), storage_reg);
348 } else {
349 __ mov(FieldOperand(scratch1, offset), value_reg);
350 }
351
352 if (!representation.IsSmi()) {
353 // Update the write barrier for the array address.
354 if (!representation.IsDouble()) {
355 __ mov(storage_reg, value_reg);
356 }
357 __ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
358 EMIT_REMEMBERED_SET, smi_check);
359 }
360 }
361
362 // Return the value (register eax).
363 DCHECK(value_reg.is(eax));
364 __ ret(0);
365 }
366
367
368 void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
369 Register value_reg,
370 Label* miss_label) {
371 DCHECK(lookup->representation().IsHeapObject());
372 __ JumpIfSmi(value_reg, miss_label);
373 HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
374 Label do_store;
375 while (true) {
376 __ CompareMap(value_reg, it.Current());
377 it.Advance();
378 if (it.Done()) {
379 __ j(not_equal, miss_label);
380 break;
381 }
382 __ j(equal, &do_store, Label::kNear);
383 }
384 __ bind(&do_store);
385
386 StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
387 lookup->representation());
388 GenerateTailCall(masm(), stub.GetCode());
389 }
390
391
392 Register PropertyHandlerCompiler::CheckPrototypes(
393 Register object_reg, Register holder_reg, Register scratch1,
394 Register scratch2, Handle<Name> name, Label* miss,
395 PrototypeCheckType check) {
396 Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
397
398 // Make sure there's no overlap between holder and object registers.
399 DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
400 DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
401 !scratch2.is(scratch1));
402
403 // Keep track of the current object in register reg.
404 Register reg = object_reg;
405 int depth = 0;
406
407 Handle<JSObject> current = Handle<JSObject>::null();
408 if (type()->IsConstant())
409 current = Handle<JSObject>::cast(type()->AsConstant()->Value());
410 Handle<JSObject> prototype = Handle<JSObject>::null();
411 Handle<Map> current_map = receiver_map;
412 Handle<Map> holder_map(holder()->map());
413 // Traverse the prototype chain and check the maps in the prototype chain for
414 // fast and global objects or do negative lookup for normal objects.
415 while (!current_map.is_identical_to(holder_map)) {
416 ++depth;
417
418 // Only global objects and objects that do not require access
419 // checks are allowed in stubs.
420 DCHECK(current_map->IsJSGlobalProxyMap() ||
421 !current_map->is_access_check_needed());
422
423 prototype = handle(JSObject::cast(current_map->prototype()));
424 if (current_map->is_dictionary_map() &&
425 !current_map->IsJSGlobalObjectMap()) {
426 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
427 if (!name->IsUniqueName()) {
428 DCHECK(name->IsString());
429 name = factory()->InternalizeString(Handle<String>::cast(name));
430 }
431 DCHECK(current.is_null() ||
432 current->property_dictionary()->FindEntry(name) ==
433 NameDictionary::kNotFound);
434
435 GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
436 scratch2);
437
438 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
439 reg = holder_reg; // From now on the object will be in holder_reg.
440 __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
441 } else {
442 bool in_new_space = heap()->InNewSpace(*prototype);
443 // Two possible reasons for loading the prototype from the map:
444 // (1) Can't store references to new space in code.
445 // (2) Handler is shared for all receivers with the same prototype
446 // map (but not necessarily the same prototype instance).
447 bool load_prototype_from_map = in_new_space || depth == 1;
448 if (depth != 1 || check == CHECK_ALL_MAPS) {
449 __ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
450 }
451
452 // Check access rights to the global object. This has to happen after
453 // the map check so that we know that the object is actually a global
454 // object.
455 // This allows us to install generated handlers for accesses to the
456 // global proxy (as opposed to using slow ICs). See corresponding code
457 // in LookupForRead().
458 if (current_map->IsJSGlobalProxyMap()) {
459 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
460 } else if (current_map->IsJSGlobalObjectMap()) {
461 GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
462 name, scratch2, miss);
463 }
464
465 if (load_prototype_from_map) {
466 // Save the map in scratch1 for later.
467 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
468 }
469
470 reg = holder_reg; // From now on the object will be in holder_reg.
471
472 if (load_prototype_from_map) {
473 __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
474 } else {
475 __ mov(reg, prototype);
476 }
477 }
478
479 // Go to the next object in the prototype chain.
480 current = prototype;
481 current_map = handle(current->map());
482 }
483
484 // Log the check depth.
485 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
486
487 if (depth != 0 || check == CHECK_ALL_MAPS) {
488 // Check the holder map.
489 __ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
490 }
491
492 // Perform security check for access to the global object.
493 DCHECK(current_map->IsJSGlobalProxyMap() ||
494 !current_map->is_access_check_needed());
495 if (current_map->IsJSGlobalProxyMap()) {
496 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
497 }
498
499 // Return the register containing the holder.
500 return reg;
501 }
502
503
504 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
505 if (!miss->is_unused()) {
506 Label success;
507 __ jmp(&success);
508 __ bind(miss);
509 TailCallBuiltin(masm(), MissBuiltin(kind()));
510 __ bind(&success);
511 }
512 }
513
514
515 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
516 if (!miss->is_unused()) {
517 Label success;
518 __ jmp(&success);
519 GenerateRestoreName(miss, name);
520 TailCallBuiltin(masm(), MissBuiltin(kind()));
521 __ bind(&success);
522 }
523 }
524
525
526 void NamedLoadHandlerCompiler::GenerateLoadCallback(
527 Register reg, Handle<ExecutableAccessorInfo> callback) {
528 // Insert additional parameters into the stack frame above return address.
529 DCHECK(!scratch3().is(reg));
530 __ pop(scratch3()); // Get return address to place it below.
531
532 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
533 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
534 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
535 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
536 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
537 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
538 __ push(receiver()); // receiver
539 // Push data from ExecutableAccessorInfo.
540 if (isolate()->heap()->InNewSpace(callback->data())) {
541 DCHECK(!scratch2().is(reg));
542 __ mov(scratch2(), Immediate(callback));
543 __ push(FieldOperand(scratch2(), ExecutableAccessorInfo::kDataOffset));
544 } else {
545 __ push(Immediate(Handle<Object>(callback->data(), isolate())));
546 }
547 __ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue
548 // ReturnValue default value
549 __ push(Immediate(isolate()->factory()->undefined_value()));
550 __ push(Immediate(reinterpret_cast<int>(isolate())));
551 __ push(reg); // holder
552
553 // Save a pointer to where we pushed the arguments. This will be
554 // passed as the const PropertyAccessorInfo& to the C++ callback.
555 __ push(esp);
556
557 __ push(name()); // name
558
559 __ push(scratch3()); // Restore return address.
560
561 // Abi for CallApiGetter
562 Register getter_address = edx;
563 Address function_address = v8::ToCData<Address>(callback->getter());
564 __ mov(getter_address, Immediate(function_address));
565
566 CallApiGetterStub stub(isolate());
567 __ TailCallStub(&stub);
568 }
569
570
571 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
572 // Return the constant value.
573 __ LoadObject(eax, value);
574 __ ret(0);
575 }
576
577
578 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
579 LookupIterator* it, Register holder_reg) {
580 DCHECK(holder()->HasNamedInterceptor());
581 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
582
583 // Compile the interceptor call, followed by inline code to load the
584 // property from further up the prototype chain if the call fails.
585 // Check that the maps haven't changed.
586 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
587
588 // Preserve the receiver register explicitly whenever it is different from the
589 // holder and it is needed should the interceptor return without any result.
590 // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
591 // case might cause a miss during the prototype check.
592 bool must_perform_prototype_check =
593 !holder().is_identical_to(it->GetHolder<JSObject>());
594 bool must_preserve_receiver_reg =
595 !receiver().is(holder_reg) &&
596 (it->property_kind() == LookupIterator::ACCESSOR ||
597 must_perform_prototype_check);
598
599 // Save necessary data before invoking an interceptor.
600 // Requires a frame to make GC aware of pushed pointers.
601 {
602 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
603
604 if (must_preserve_receiver_reg) {
605 __ push(receiver());
606 }
607 __ push(holder_reg);
608 __ push(this->name());
609
610 // Invoke an interceptor. Note: map checks from receiver to
611 // interceptor's holder has been compiled before (see a caller
612 // of this method.)
613 CompileCallLoadPropertyWithInterceptor(
614 masm(), receiver(), holder_reg, this->name(), holder(),
615 IC::kLoadPropertyWithInterceptorOnly);
616
617 // Check if interceptor provided a value for property. If it's
618 // the case, return immediately.
619 Label interceptor_failed;
620 __ cmp(eax, factory()->no_interceptor_result_sentinel());
621 __ j(equal, &interceptor_failed);
622 frame_scope.GenerateLeaveFrame();
623 __ ret(0);
624
625 // Clobber registers when generating debug-code to provoke errors.
626 __ bind(&interceptor_failed);
627 if (FLAG_debug_code) {
628 __ mov(receiver(), Immediate(BitCast<int32_t>(kZapValue)));
629 __ mov(holder_reg, Immediate(BitCast<int32_t>(kZapValue)));
630 __ mov(this->name(), Immediate(BitCast<int32_t>(kZapValue)));
631 }
632
633 __ pop(this->name());
634 __ pop(holder_reg);
635 if (must_preserve_receiver_reg) {
636 __ pop(receiver());
637 }
638
639 // Leave the internal frame.
640 }
641
642 GenerateLoadPostInterceptor(it, holder_reg);
643 }
644
645
646 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
647 DCHECK(holder()->HasNamedInterceptor());
648 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
649 // Call the runtime system to load the interceptor.
650 __ pop(scratch2()); // save old return address
651 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
652 holder());
653 __ push(scratch2()); // restore old return address
654
655 ExternalReference ref = ExternalReference(
656 IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
657 __ TailCallExternalReference(
658 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
659 }
660
661
662 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
663 Handle<JSObject> object, Handle<Name> name,
664 Handle<ExecutableAccessorInfo> callback) {
665 Register holder_reg = Frontend(receiver(), name);
666
667 __ pop(scratch1()); // remove the return address
668 __ push(receiver());
669 __ push(holder_reg);
670 __ Push(callback);
671 __ Push(name);
672 __ push(value());
673 __ push(scratch1()); // restore return address
674
675 // Do tail-call to the runtime system.
676 ExternalReference store_callback_property =
677 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
678 __ TailCallExternalReference(store_callback_property, 5, 1);
679
680 // Return the generated code.
681 return GetCode(kind(), Code::FAST, name);
682 }
683
684
685 #undef __
686 #define __ ACCESS_MASM(masm)
687
688
689 void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
690 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
691 Handle<JSFunction> setter) {
692 // ----------- S t a t e -------------
693 // -- esp[0] : return address
694 // -----------------------------------
695 {
696 FrameScope scope(masm, StackFrame::INTERNAL);
697
698 // Save value register, so we can restore it later.
699 __ push(value());
700
701 if (!setter.is_null()) {
702 // Call the JavaScript setter with receiver and value on the stack.
703 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
704 // Swap in the global receiver.
705 __ mov(receiver,
706 FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
707 }
708 __ push(receiver);
709 __ push(value());
710 ParameterCount actual(1);
711 ParameterCount expected(setter);
712 __ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
713 NullCallWrapper());
714 } else {
715 // If we generate a global code snippet for deoptimization only, remember
716 // the place to continue after deoptimization.
717 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
718 }
719
720 // We have to return the passed value, not the return value of the setter.
721 __ pop(eax);
722
723 // Restore context register.
724 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
725 }
726 __ ret(0);
727 }
728
729
730 #undef __
731 #define __ ACCESS_MASM(masm())
732
733
734 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
735 Handle<Name> name) {
736 __ pop(scratch1()); // remove the return address
737 __ push(receiver());
738 __ push(this->name());
739 __ push(value());
740 __ push(scratch1()); // restore return address
741
742 // Do tail-call to the runtime system.
743 ExternalReference store_ic_property = ExternalReference(
744 IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
745 __ TailCallExternalReference(store_ic_property, 3, 1);
746
747 // Return the generated code.
748 return GetCode(kind(), Code::FAST, name);
749 }
750
751
752 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
753 MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
754 MapHandleList* transitioned_maps) {
755 Label miss;
756 __ JumpIfSmi(receiver(), &miss, Label::kNear);
757 __ mov(scratch1(), FieldOperand(receiver(), HeapObject::kMapOffset));
758 for (int i = 0; i < receiver_maps->length(); ++i) {
759 __ cmp(scratch1(), receiver_maps->at(i));
760 if (transitioned_maps->at(i).is_null()) {
761 __ j(equal, handler_stubs->at(i));
762 } else {
763 Label next_map;
764 __ j(not_equal, &next_map, Label::kNear);
765 __ mov(transition_map(), Immediate(transitioned_maps->at(i)));
766 __ jmp(handler_stubs->at(i), RelocInfo::CODE_TARGET);
767 __ bind(&next_map);
768 }
769 }
770 __ bind(&miss);
771 TailCallBuiltin(masm(), MissBuiltin(kind()));
772
773 // Return the generated code.
774 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
775 }
776
777
778 Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
779
780
781 #undef __
782 #define __ ACCESS_MASM(masm)
783
784
785 void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
786 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
787 Handle<JSFunction> getter) {
788 {
789 FrameScope scope(masm, StackFrame::INTERNAL);
790
791 if (!getter.is_null()) {
792 // Call the JavaScript getter with the receiver on the stack.
793 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
794 // Swap in the global receiver.
795 __ mov(receiver,
796 FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
797 }
798 __ push(receiver);
799 ParameterCount actual(0);
800 ParameterCount expected(getter);
801 __ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
802 NullCallWrapper());
803 } else {
804 // If we generate a global code snippet for deoptimization only, remember
805 // the place to continue after deoptimization.
806 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
807 }
808
809 // Restore context register.
810 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
811 }
812 __ ret(0);
813 }
814
815
816 #undef __
817 #define __ ACCESS_MASM(masm())
818
819
820 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
821 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
822 Label miss;
823
824 FrontendHeader(receiver(), name, &miss);
825 // Get the value from the cell.
826 Register result = StoreIC::ValueRegister();
827 if (masm()->serializer_enabled()) {
828 __ mov(result, Immediate(cell));
829 __ mov(result, FieldOperand(result, PropertyCell::kValueOffset));
830 } else {
831 __ mov(result, Operand::ForCell(cell));
832 }
833
834 // Check for deleted property if property can actually be deleted.
835 if (is_configurable) {
836 __ cmp(result, factory()->the_hole_value());
837 __ j(equal, &miss);
838 } else if (FLAG_debug_code) {
839 __ cmp(result, factory()->the_hole_value());
840 __ Check(not_equal, kDontDeleteCellsCannotContainTheHole);
841 }
842
843 Counters* counters = isolate()->counters();
844 __ IncrementCounter(counters->named_load_global_stub(), 1);
845 // The code above already loads the result into the return register.
846 __ ret(0);
847
848 FrontendFooter(name, &miss);
849
850 // Return the generated code.
851 return GetCode(kind(), Code::NORMAL, name);
852 }
853
854
855 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types, 37 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
856 CodeHandleList* handlers, 38 CodeHandleList* handlers,
857 Handle<Name> name, 39 Handle<Name> name,
858 Code::StubType type, 40 Code::StubType type,
859 IcCheckType check) { 41 IcCheckType check) {
860 Label miss; 42 Label miss;
861 43
862 if (check == PROPERTY && 44 if (check == PROPERTY &&
863 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) { 45 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) {
864 // 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
900 __ bind(&miss); 82 __ bind(&miss);
901 TailCallBuiltin(masm(), MissBuiltin(kind())); 83 TailCallBuiltin(masm(), MissBuiltin(kind()));
902 84
903 // Return the generated code. 85 // Return the generated code.
904 InlineCacheState state = 86 InlineCacheState state =
905 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC; 87 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC;
906 return GetCode(kind(), type, name, state); 88 return GetCode(kind(), type, name, state);
907 } 89 }
908 90
909 91
910 #undef __ 92 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
911 #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()));
912 112
913 113 // Return the generated code.
914 void ElementHandlerCompiler::GenerateLoadDictionaryElement( 114 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
915 MacroAssembler* masm) {
916 // ----------- S t a t e -------------
917 // -- ecx : key
918 // -- edx : receiver
919 // -- esp[0] : return address
920 // -----------------------------------
921 DCHECK(edx.is(LoadIC::ReceiverRegister()));
922 DCHECK(ecx.is(LoadIC::NameRegister()));
923 Label slow, miss;
924
925 // This stub is meant to be tail-jumped to, the receiver must already
926 // have been verified by the caller to not be a smi.
927 __ JumpIfNotSmi(ecx, &miss);
928 __ mov(ebx, ecx);
929 __ SmiUntag(ebx);
930 __ mov(eax, FieldOperand(edx, JSObject::kElementsOffset));
931
932 // Push receiver on the stack to free up a register for the dictionary
933 // probing.
934 __ push(edx);
935 __ LoadFromNumberDictionary(&slow, eax, ecx, ebx, edx, edi, eax);
936 // Pop receiver before returning.
937 __ pop(edx);
938 __ ret(0);
939
940 __ bind(&slow);
941 __ pop(edx);
942
943 // ----------- S t a t e -------------
944 // -- ecx : key
945 // -- edx : receiver
946 // -- esp[0] : return address
947 // -----------------------------------
948 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
949
950 __ bind(&miss);
951 // ----------- S t a t e -------------
952 // -- ecx : key
953 // -- edx : receiver
954 // -- esp[0] : return address
955 // -----------------------------------
956 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
957 } 115 }
958 116
959 117
960 void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
961 StrictMode strict_mode) {
962 // Return address is on the stack.
963 DCHECK(!ebx.is(StoreIC::ReceiverRegister()) &&
964 !ebx.is(StoreIC::NameRegister()) && !ebx.is(StoreIC::ValueRegister()));
965 __ pop(ebx);
966 __ push(StoreIC::ReceiverRegister());
967 __ push(StoreIC::NameRegister());
968 __ push(StoreIC::ValueRegister());
969 __ push(Immediate(Smi::FromInt(strict_mode)));
970 __ push(ebx); // return address
971
972 // Do tail-call to runtime routine.
973 __ TailCallRuntime(Runtime::kSetProperty, 4, 1);
974 }
975
976
977 #undef __ 118 #undef __
978 } 119 }
979 } // namespace v8::internal 120 } // namespace v8::internal
980 121
981 #endif // V8_TARGET_ARCH_X87 122 #endif // V8_TARGET_ARCH_X87
OLDNEW
« no previous file with comments | « src/ic/x87/handler-compiler-x87.cc ('k') | src/x87/code-stubs-x87.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698