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
3 // found in the LICENSE file.
9 #include "src/ic/call-optimization.h"
10 #include "src/ic/handler-compiler.h"
11 #include "src/ic/ic.h"
16 #define __ ACCESS_MASM(masm)
19 void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
20 MacroAssembler* masm, Handle<Map> map, Register receiver, Register holder,
21 int accessor_index, int expected_arguments, Register scratch) {
23 FrameScope scope(masm, StackFrame::INTERNAL);
25 if (accessor_index >= 0) {
26 DCHECK(!holder.is(scratch));
27 DCHECK(!receiver.is(scratch));
28 // Call the JavaScript getter with the receiver on the stack.
29 if (map->IsJSGlobalObjectMap()) {
30 // Swap in the global receiver.
32 FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
36 ParameterCount actual(0);
37 ParameterCount expected(expected_arguments);
38 __ LoadAccessor(edi, holder, accessor_index, ACCESSOR_GETTER);
39 __ InvokeFunction(edi, expected, actual, CALL_FUNCTION,
42 // If we generate a global code snippet for deoptimization only, remember
43 // the place to continue after deoptimization.
44 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
47 // Restore context register.
48 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
54 void PropertyHandlerCompiler::PushVectorAndSlot(Register vector,
56 MacroAssembler* masm = this->masm();
62 void PropertyHandlerCompiler::PopVectorAndSlot(Register vector, Register slot) {
63 MacroAssembler* masm = this->masm();
69 void PropertyHandlerCompiler::DiscardVectorAndSlot() {
70 MacroAssembler* masm = this->masm();
71 // Remove vector and slot.
72 __ add(esp, Immediate(2 * kPointerSize));
76 void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
77 MacroAssembler* masm, Label* miss_label, Register receiver,
78 Handle<Name> name, Register scratch0, Register scratch1) {
79 DCHECK(name->IsUniqueName());
80 DCHECK(!receiver.is(scratch0));
81 Counters* counters = masm->isolate()->counters();
82 __ IncrementCounter(counters->negative_lookups(), 1);
83 __ IncrementCounter(counters->negative_lookups_miss(), 1);
85 __ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
87 const int kInterceptorOrAccessCheckNeededMask =
88 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
90 // Bail out if the receiver has a named interceptor or requires access checks.
91 __ test_b(FieldOperand(scratch0, Map::kBitFieldOffset),
92 kInterceptorOrAccessCheckNeededMask);
93 __ j(not_zero, miss_label);
95 // Check that receiver is a JSObject.
96 __ CmpInstanceType(scratch0, FIRST_SPEC_OBJECT_TYPE);
97 __ j(below, miss_label);
99 // Load properties array.
100 Register properties = scratch0;
101 __ mov(properties, FieldOperand(receiver, JSObject::kPropertiesOffset));
103 // Check that the properties array is a dictionary.
104 __ cmp(FieldOperand(properties, HeapObject::kMapOffset),
105 Immediate(masm->isolate()->factory()->hash_table_map()));
106 __ j(not_equal, miss_label);
109 NameDictionaryLookupStub::GenerateNegativeLookup(masm, miss_label, &done,
110 properties, name, scratch1);
112 __ DecrementCounter(counters->negative_lookups_miss(), 1);
116 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
117 MacroAssembler* masm, int index, Register result, Label* miss) {
118 const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
119 __ mov(result, Operand(esi, offset));
120 __ mov(result, FieldOperand(result, GlobalObject::kNativeContextOffset));
121 __ mov(result, Operand(result, Context::SlotOffset(index)));
122 // Load its initial map. The global functions all have initial maps.
124 FieldOperand(result, JSFunction::kPrototypeOrInitialMapOffset));
125 // Load the prototype from the initial map.
126 __ mov(result, FieldOperand(result, Map::kPrototypeOffset));
130 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
131 MacroAssembler* masm, Register receiver, Register scratch1,
132 Register scratch2, Label* miss_label) {
133 DCHECK(!FLAG_vector_ics);
134 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
135 __ mov(eax, scratch1);
140 // Generate call to api function.
141 // This function uses push() to generate smaller, faster code than
142 // the version above. It is an optimization that should will be removed
143 // when api call ICs are generated in hydrogen.
144 void PropertyHandlerCompiler::GenerateApiAccessorCall(
145 MacroAssembler* masm, const CallOptimization& optimization,
146 Handle<Map> receiver_map, Register receiver, Register scratch,
147 bool is_store, Register store_parameter, Register accessor_holder,
148 int accessor_index) {
149 DCHECK(!accessor_holder.is(scratch));
150 // Copy return value.
154 // Write the arguments to stack frame.
156 DCHECK(!receiver.is(store_parameter));
157 DCHECK(!scratch.is(store_parameter));
158 __ push(store_parameter);
161 // Stack now matches JSFunction abi.
162 DCHECK(optimization.is_simple_api_call());
164 // Abi for CallApiFunctionStub.
165 Register callee = edi;
167 Register holder = ecx;
168 Register api_function_address = edx;
171 // Put callee in place.
172 __ LoadAccessor(callee, accessor_holder, accessor_index,
173 is_store ? ACCESSOR_SETTER : ACCESSOR_GETTER);
175 // Put holder in place.
176 CallOptimization::HolderLookup holder_lookup;
177 int holder_depth = 0;
178 optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup,
180 switch (holder_lookup) {
181 case CallOptimization::kHolderIsReceiver:
182 __ Move(holder, receiver);
184 case CallOptimization::kHolderFound:
185 __ mov(holder, FieldOperand(receiver, HeapObject::kMapOffset));
186 __ mov(holder, FieldOperand(holder, Map::kPrototypeOffset));
187 for (int i = 1; i < holder_depth; i++) {
188 __ mov(holder, FieldOperand(holder, HeapObject::kMapOffset));
189 __ mov(holder, FieldOperand(holder, Map::kPrototypeOffset));
192 case CallOptimization::kHolderNotFound:
197 Isolate* isolate = masm->isolate();
198 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
199 bool call_data_undefined = false;
200 // Put call data in place.
201 if (api_call_info->data()->IsUndefined()) {
202 call_data_undefined = true;
203 __ mov(data, Immediate(isolate->factory()->undefined_value()));
205 __ mov(data, FieldOperand(callee, JSFunction::kSharedFunctionInfoOffset));
206 __ mov(data, FieldOperand(data, SharedFunctionInfo::kFunctionDataOffset));
207 __ mov(data, FieldOperand(data, FunctionTemplateInfo::kCallCodeOffset));
208 __ mov(data, FieldOperand(data, CallHandlerInfo::kDataOffset));
211 // Put api_function_address in place.
212 Address function_address = v8::ToCData<Address>(api_call_info->callback());
213 __ mov(api_function_address, Immediate(function_address));
216 CallApiAccessorStub stub(isolate, is_store, call_data_undefined);
217 __ TailCallStub(&stub);
221 // Generate code to check that a global property cell is empty. Create
222 // the property cell at compilation time if no cell exists for the
224 void PropertyHandlerCompiler::GenerateCheckPropertyCell(
225 MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
226 Register scratch, Label* miss) {
227 Handle<PropertyCell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
228 DCHECK(cell->value()->IsTheHole());
229 Factory* factory = masm->isolate()->factory();
230 Handle<WeakCell> weak_cell = factory->NewWeakCell(cell);
231 __ LoadWeakValue(scratch, weak_cell, miss);
232 __ cmp(FieldOperand(scratch, PropertyCell::kValueOffset),
233 Immediate(factory->the_hole_value()));
234 __ j(not_equal, miss);
238 void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
239 MacroAssembler* masm, Handle<Map> map, Register receiver, Register holder,
240 int accessor_index, int expected_arguments, Register scratch) {
241 // ----------- S t a t e -------------
242 // -- esp[0] : return address
243 // -----------------------------------
245 FrameScope scope(masm, StackFrame::INTERNAL);
247 // Save value register, so we can restore it later.
250 if (accessor_index >= 0) {
251 DCHECK(!holder.is(scratch));
252 DCHECK(!receiver.is(scratch));
253 DCHECK(!value().is(scratch));
254 // Call the JavaScript setter with receiver and value on the stack.
255 if (map->IsJSGlobalObjectMap()) {
257 FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
262 ParameterCount actual(1);
263 ParameterCount expected(expected_arguments);
264 __ LoadAccessor(edi, holder, accessor_index, ACCESSOR_SETTER);
265 __ InvokeFunction(edi, expected, actual, CALL_FUNCTION,
268 // If we generate a global code snippet for deoptimization only, remember
269 // the place to continue after deoptimization.
270 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
273 // We have to return the passed value, not the return value of the setter.
276 // Restore context register.
277 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
283 static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
284 Register holder, Register name,
285 Handle<JSObject> holder_obj) {
286 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
287 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 1);
288 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 2);
289 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 3);
296 static void CompileCallLoadPropertyWithInterceptor(
297 MacroAssembler* masm, Register receiver, Register holder, Register name,
298 Handle<JSObject> holder_obj, IC::UtilityId id) {
299 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
300 __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
301 NamedLoadHandlerCompiler::kInterceptorArgsLength);
305 static void StoreIC_PushArgs(MacroAssembler* masm) {
306 Register receiver = StoreDescriptor::ReceiverRegister();
307 Register name = StoreDescriptor::NameRegister();
308 Register value = StoreDescriptor::ValueRegister();
310 DCHECK(!ebx.is(receiver) && !ebx.is(name) && !ebx.is(value));
320 void NamedStoreHandlerCompiler::GenerateSlow(MacroAssembler* masm) {
321 // Return address is on the stack.
322 StoreIC_PushArgs(masm);
324 // Do tail-call to runtime routine.
325 ExternalReference ref(IC_Utility(IC::kStoreIC_Slow), masm->isolate());
326 __ TailCallExternalReference(ref, 3, 1);
330 void ElementHandlerCompiler::GenerateStoreSlow(MacroAssembler* masm) {
331 // Return address is on the stack.
332 StoreIC_PushArgs(masm);
334 // Do tail-call to runtime routine.
335 ExternalReference ref(IC_Utility(IC::kKeyedStoreIC_Slow), masm->isolate());
336 __ TailCallExternalReference(ref, 3, 1);
341 #define __ ACCESS_MASM(masm())
344 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
346 if (!label->is_unused()) {
348 __ mov(this->name(), Immediate(name));
353 void NamedStoreHandlerCompiler::GenerateRestoreName(Handle<Name> name) {
354 __ mov(this->name(), Immediate(name));
358 void NamedStoreHandlerCompiler::GenerateRestoreMap(Handle<Map> transition,
361 Handle<WeakCell> cell = Map::WeakCellForMap(transition);
362 Register map_reg = StoreTransitionDescriptor::MapRegister();
363 DCHECK(!map_reg.is(scratch));
364 __ LoadWeakValue(map_reg, cell, miss);
365 if (transition->CanBeDeprecated()) {
366 __ mov(scratch, FieldOperand(map_reg, Map::kBitField3Offset));
367 __ and_(scratch, Immediate(Map::Deprecated::kMask));
368 __ j(not_zero, miss);
373 void NamedStoreHandlerCompiler::GenerateConstantCheck(Register map_reg,
378 DCHECK(!map_reg.is(scratch));
379 DCHECK(!map_reg.is(value_reg));
380 DCHECK(!value_reg.is(scratch));
381 __ LoadInstanceDescriptors(map_reg, scratch);
383 FieldOperand(scratch, DescriptorArray::GetValueOffset(descriptor)));
384 __ cmp(value_reg, scratch);
385 __ j(not_equal, miss_label);
389 void NamedStoreHandlerCompiler::GenerateFieldTypeChecks(HeapType* field_type,
392 Register map_reg = scratch1();
393 Register scratch = scratch2();
394 DCHECK(!value_reg.is(map_reg));
395 DCHECK(!value_reg.is(scratch));
396 __ JumpIfSmi(value_reg, miss_label);
397 HeapType::Iterator<Map> it = field_type->Classes();
400 __ mov(map_reg, FieldOperand(value_reg, HeapObject::kMapOffset));
402 __ CmpWeakValue(map_reg, Map::WeakCellForMap(it.Current()), scratch);
405 __ j(not_equal, miss_label);
408 __ j(equal, &do_store, Label::kNear);
415 Register PropertyHandlerCompiler::CheckPrototypes(
416 Register object_reg, Register holder_reg, Register scratch1,
417 Register scratch2, Handle<Name> name, Label* miss,
418 PrototypeCheckType check) {
419 Handle<Map> receiver_map = map();
421 // Make sure there's no overlap between holder and object registers.
422 DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
423 DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
424 !scratch2.is(scratch1));
426 // Keep track of the current object in register reg.
427 Register reg = object_reg;
430 Handle<JSObject> current = Handle<JSObject>::null();
431 if (receiver_map->IsJSGlobalObjectMap()) {
432 current = isolate()->global_object();
435 // Check access rights to the global object. This has to happen after
436 // the map check so that we know that the object is actually a global
438 // This allows us to install generated handlers for accesses to the
439 // global proxy (as opposed to using slow ICs). See corresponding code
440 // in LookupForRead().
441 if (receiver_map->IsJSGlobalProxyMap()) {
442 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
445 Handle<JSObject> prototype = Handle<JSObject>::null();
446 Handle<Map> current_map = receiver_map;
447 Handle<Map> holder_map(holder()->map());
448 // Traverse the prototype chain and check the maps in the prototype chain for
449 // fast and global objects or do negative lookup for normal objects.
450 while (!current_map.is_identical_to(holder_map)) {
453 // Only global objects and objects that do not require access
454 // checks are allowed in stubs.
455 DCHECK(current_map->IsJSGlobalProxyMap() ||
456 !current_map->is_access_check_needed());
458 prototype = handle(JSObject::cast(current_map->prototype()));
459 if (current_map->is_dictionary_map() &&
460 !current_map->IsJSGlobalObjectMap()) {
461 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
462 if (!name->IsUniqueName()) {
463 DCHECK(name->IsString());
464 name = factory()->InternalizeString(Handle<String>::cast(name));
466 DCHECK(current.is_null() ||
467 current->property_dictionary()->FindEntry(name) ==
468 NameDictionary::kNotFound);
470 GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
473 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
474 reg = holder_reg; // From now on the object will be in holder_reg.
475 __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
477 Register map_reg = scratch1;
478 __ mov(map_reg, FieldOperand(reg, HeapObject::kMapOffset));
479 if (current_map->IsJSGlobalObjectMap()) {
480 GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
481 name, scratch2, miss);
482 } else if (depth != 1 || check == CHECK_ALL_MAPS) {
483 Handle<WeakCell> cell = Map::WeakCellForMap(current_map);
484 __ CmpWeakValue(map_reg, cell, scratch2);
485 __ j(not_equal, miss);
488 reg = holder_reg; // From now on the object will be in holder_reg.
489 __ mov(reg, FieldOperand(map_reg, Map::kPrototypeOffset));
492 // Go to the next object in the prototype chain.
494 current_map = handle(current->map());
497 DCHECK(!current_map->IsJSGlobalProxyMap());
499 // Log the check depth.
500 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
502 if (depth != 0 || check == CHECK_ALL_MAPS) {
503 // Check the holder map.
504 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
505 Handle<WeakCell> cell = Map::WeakCellForMap(current_map);
506 __ CmpWeakValue(scratch1, cell, scratch2);
507 __ j(not_equal, miss);
510 // Return the register containing the holder.
515 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
516 if (!miss->is_unused()) {
520 if (IC::ICUseVector(kind())) {
521 DCHECK(kind() == Code::LOAD_IC);
524 TailCallBuiltin(masm(), MissBuiltin(kind()));
530 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
531 if (!miss->is_unused()) {
534 GenerateRestoreName(miss, name);
535 TailCallBuiltin(masm(), MissBuiltin(kind()));
541 void NamedLoadHandlerCompiler::GenerateLoadCallback(
542 Register reg, Handle<ExecutableAccessorInfo> callback) {
543 // Insert additional parameters into the stack frame above return address.
544 DCHECK(!scratch3().is(reg));
545 __ pop(scratch3()); // Get return address to place it below.
547 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
548 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
549 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
550 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
551 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
552 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
553 __ push(receiver()); // receiver
554 // Push data from ExecutableAccessorInfo.
555 Handle<Object> data(callback->data(), isolate());
556 if (data->IsUndefined() || data->IsSmi()) {
557 __ push(Immediate(data));
559 DCHECK(!scratch2().is(reg));
560 Handle<WeakCell> cell =
561 isolate()->factory()->NewWeakCell(Handle<HeapObject>::cast(data));
562 // The callback is alive if this instruction is executed,
563 // so the weak cell is not cleared and points to data.
564 __ GetWeakValue(scratch2(), cell);
567 __ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue
568 // ReturnValue default value
569 __ push(Immediate(isolate()->factory()->undefined_value()));
570 __ push(Immediate(reinterpret_cast<int>(isolate())));
571 __ push(reg); // holder
573 // Save a pointer to where we pushed the arguments. This will be
574 // passed as the const PropertyAccessorInfo& to the C++ callback.
577 __ push(name()); // name
579 __ push(scratch3()); // Restore return address.
581 // Abi for CallApiGetter
582 Register getter_address = ApiGetterDescriptor::function_address();
583 Address function_address = v8::ToCData<Address>(callback->getter());
584 __ mov(getter_address, Immediate(function_address));
586 CallApiGetterStub stub(isolate());
587 __ TailCallStub(&stub);
591 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
592 // Return the constant value.
593 __ LoadObject(eax, value);
598 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
599 LookupIterator* it, Register holder_reg) {
600 DCHECK(holder()->HasNamedInterceptor());
601 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
603 // Compile the interceptor call, followed by inline code to load the
604 // property from further up the prototype chain if the call fails.
605 // Check that the maps haven't changed.
606 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
608 // Preserve the receiver register explicitly whenever it is different from the
609 // holder and it is needed should the interceptor return without any result.
610 // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
611 // case might cause a miss during the prototype check.
612 bool must_perform_prototype_check =
613 !holder().is_identical_to(it->GetHolder<JSObject>());
614 bool must_preserve_receiver_reg =
615 !receiver().is(holder_reg) &&
616 (it->state() == LookupIterator::ACCESSOR || must_perform_prototype_check);
618 // Save necessary data before invoking an interceptor.
619 // Requires a frame to make GC aware of pushed pointers.
621 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
623 if (must_preserve_receiver_reg) {
627 __ push(this->name());
628 InterceptorVectorSlotPush(holder_reg);
629 // Invoke an interceptor. Note: map checks from receiver to
630 // interceptor's holder has been compiled before (see a caller
632 CompileCallLoadPropertyWithInterceptor(
633 masm(), receiver(), holder_reg, this->name(), holder(),
634 IC::kLoadPropertyWithInterceptorOnly);
636 // Check if interceptor provided a value for property. If it's
637 // the case, return immediately.
638 Label interceptor_failed;
639 __ cmp(eax, factory()->no_interceptor_result_sentinel());
640 __ j(equal, &interceptor_failed);
641 frame_scope.GenerateLeaveFrame();
644 // Clobber registers when generating debug-code to provoke errors.
645 __ bind(&interceptor_failed);
646 if (FLAG_debug_code) {
647 __ mov(receiver(), Immediate(bit_cast<int32_t>(kZapValue)));
648 __ mov(holder_reg, Immediate(bit_cast<int32_t>(kZapValue)));
649 __ mov(this->name(), Immediate(bit_cast<int32_t>(kZapValue)));
652 InterceptorVectorSlotPop(holder_reg);
653 __ pop(this->name());
655 if (must_preserve_receiver_reg) {
659 // Leave the internal frame.
662 GenerateLoadPostInterceptor(it, holder_reg);
666 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
667 DCHECK(holder()->HasNamedInterceptor());
668 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
669 // Call the runtime system to load the interceptor.
670 __ pop(scratch2()); // save old return address
671 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
673 __ push(scratch2()); // restore old return address
675 ExternalReference ref = ExternalReference(
676 IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
677 __ TailCallExternalReference(
678 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
682 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
683 Handle<JSObject> object, Handle<Name> name,
684 Handle<ExecutableAccessorInfo> callback) {
685 Register holder_reg = Frontend(name);
687 __ pop(scratch1()); // remove the return address
690 // If the callback cannot leak, then push the callback directly,
691 // otherwise wrap it in a weak cell.
692 if (callback->data()->IsUndefined() || callback->data()->IsSmi()) {
695 Handle<WeakCell> cell = isolate()->factory()->NewWeakCell(callback);
700 __ push(scratch1()); // restore return address
702 // Do tail-call to the runtime system.
703 ExternalReference store_callback_property =
704 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
705 __ TailCallExternalReference(store_callback_property, 5, 1);
707 // Return the generated code.
708 return GetCode(kind(), Code::FAST, name);
712 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
714 __ pop(scratch1()); // remove the return address
716 __ push(this->name());
718 __ push(scratch1()); // restore return address
720 // Do tail-call to the runtime system.
721 ExternalReference store_ic_property = ExternalReference(
722 IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
723 __ TailCallExternalReference(store_ic_property, 3, 1);
725 // Return the generated code.
726 return GetCode(kind(), Code::FAST, name);
730 Register NamedStoreHandlerCompiler::value() {
731 return StoreDescriptor::ValueRegister();
735 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
736 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
738 if (IC::ICUseVector(kind())) {
741 FrontendHeader(receiver(), name, &miss);
742 // Get the value from the cell.
743 Register result = StoreDescriptor::ValueRegister();
744 Handle<WeakCell> weak_cell = factory()->NewWeakCell(cell);
745 __ LoadWeakValue(result, weak_cell, &miss);
746 __ mov(result, FieldOperand(result, PropertyCell::kValueOffset));
748 // Check for deleted property if property can actually be deleted.
749 if (is_configurable) {
750 __ cmp(result, factory()->the_hole_value());
752 } else if (FLAG_debug_code) {
753 __ cmp(result, factory()->the_hole_value());
754 __ Check(not_equal, kDontDeleteCellsCannotContainTheHole);
757 Counters* counters = isolate()->counters();
758 __ IncrementCounter(counters->named_load_global_stub(), 1);
759 // The code above already loads the result into the return register.
760 if (IC::ICUseVector(kind())) {
761 DiscardVectorAndSlot();
765 FrontendFooter(name, &miss);
767 // Return the generated code.
768 return GetCode(kind(), Code::NORMAL, name);
774 } // namespace v8::internal
776 #endif // V8_TARGET_ARCH_X87