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();
434 Handle<JSObject> prototype = Handle<JSObject>::null();
435 Handle<Map> current_map = receiver_map;
436 Handle<Map> holder_map(holder()->map());
437 // Traverse the prototype chain and check the maps in the prototype chain for
438 // fast and global objects or do negative lookup for normal objects.
439 while (!current_map.is_identical_to(holder_map)) {
442 // Only global objects and objects that do not require access
443 // checks are allowed in stubs.
444 DCHECK(current_map->IsJSGlobalProxyMap() ||
445 !current_map->is_access_check_needed());
447 prototype = handle(JSObject::cast(current_map->prototype()));
448 if (current_map->is_dictionary_map() &&
449 !current_map->IsJSGlobalObjectMap()) {
450 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
451 if (!name->IsUniqueName()) {
452 DCHECK(name->IsString());
453 name = factory()->InternalizeString(Handle<String>::cast(name));
455 DCHECK(current.is_null() ||
456 current->property_dictionary()->FindEntry(name) ==
457 NameDictionary::kNotFound);
459 GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
462 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
463 reg = holder_reg; // From now on the object will be in holder_reg.
464 __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
466 Register map_reg = scratch1;
467 __ mov(map_reg, FieldOperand(reg, HeapObject::kMapOffset));
468 if (depth != 1 || check == CHECK_ALL_MAPS) {
469 Handle<WeakCell> cell = Map::WeakCellForMap(current_map);
470 __ CmpWeakValue(map_reg, cell, scratch2);
471 __ j(not_equal, miss);
474 // Check access rights to the global object. This has to happen after
475 // the map check so that we know that the object is actually a global
477 // This allows us to install generated handlers for accesses to the
478 // global proxy (as opposed to using slow ICs). See corresponding code
479 // in LookupForRead().
480 if (current_map->IsJSGlobalProxyMap()) {
481 __ CheckAccessGlobalProxy(reg, map_reg, scratch2, miss);
483 __ mov(map_reg, FieldOperand(reg, HeapObject::kMapOffset));
484 } else if (current_map->IsJSGlobalObjectMap()) {
485 GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
486 name, scratch2, 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 // Log the check depth.
498 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
500 if (depth != 0 || check == CHECK_ALL_MAPS) {
501 // Check the holder map.
502 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
503 Handle<WeakCell> cell = Map::WeakCellForMap(current_map);
504 __ CmpWeakValue(scratch1, cell, scratch2);
505 __ j(not_equal, miss);
508 // Perform security check for access to the global object.
509 DCHECK(current_map->IsJSGlobalProxyMap() ||
510 !current_map->is_access_check_needed());
511 if (current_map->IsJSGlobalProxyMap()) {
512 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
515 // Return the register containing the holder.
520 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
521 if (!miss->is_unused()) {
525 if (IC::ICUseVector(kind())) {
526 DCHECK(kind() == Code::LOAD_IC);
529 TailCallBuiltin(masm(), MissBuiltin(kind()));
535 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
536 if (!miss->is_unused()) {
539 GenerateRestoreName(miss, name);
540 TailCallBuiltin(masm(), MissBuiltin(kind()));
546 void NamedLoadHandlerCompiler::GenerateLoadCallback(
547 Register reg, Handle<ExecutableAccessorInfo> callback) {
548 // Insert additional parameters into the stack frame above return address.
549 DCHECK(!scratch3().is(reg));
550 __ pop(scratch3()); // Get return address to place it below.
552 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
553 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
554 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
555 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
556 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
557 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
558 __ push(receiver()); // receiver
559 // Push data from ExecutableAccessorInfo.
560 Handle<Object> data(callback->data(), isolate());
561 if (data->IsUndefined() || data->IsSmi()) {
562 __ push(Immediate(data));
564 DCHECK(!scratch2().is(reg));
565 Handle<WeakCell> cell =
566 isolate()->factory()->NewWeakCell(Handle<HeapObject>::cast(data));
567 // The callback is alive if this instruction is executed,
568 // so the weak cell is not cleared and points to data.
569 __ GetWeakValue(scratch2(), cell);
572 __ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue
573 // ReturnValue default value
574 __ push(Immediate(isolate()->factory()->undefined_value()));
575 __ push(Immediate(reinterpret_cast<int>(isolate())));
576 __ push(reg); // holder
578 // Save a pointer to where we pushed the arguments. This will be
579 // passed as the const PropertyAccessorInfo& to the C++ callback.
582 __ push(name()); // name
584 __ push(scratch3()); // Restore return address.
586 // Abi for CallApiGetter
587 Register getter_address = ApiGetterDescriptor::function_address();
588 Address function_address = v8::ToCData<Address>(callback->getter());
589 __ mov(getter_address, Immediate(function_address));
591 CallApiGetterStub stub(isolate());
592 __ TailCallStub(&stub);
596 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
597 // Return the constant value.
598 __ LoadObject(eax, value);
603 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
604 LookupIterator* it, Register holder_reg) {
605 DCHECK(holder()->HasNamedInterceptor());
606 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
608 // Compile the interceptor call, followed by inline code to load the
609 // property from further up the prototype chain if the call fails.
610 // Check that the maps haven't changed.
611 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
613 // Preserve the receiver register explicitly whenever it is different from the
614 // holder and it is needed should the interceptor return without any result.
615 // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
616 // case might cause a miss during the prototype check.
617 bool must_perform_prototype_check =
618 !holder().is_identical_to(it->GetHolder<JSObject>());
619 bool must_preserve_receiver_reg =
620 !receiver().is(holder_reg) &&
621 (it->state() == LookupIterator::ACCESSOR || must_perform_prototype_check);
623 // Save necessary data before invoking an interceptor.
624 // Requires a frame to make GC aware of pushed pointers.
626 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
628 if (must_preserve_receiver_reg) {
632 __ push(this->name());
633 InterceptorVectorSlotPush(holder_reg);
634 // Invoke an interceptor. Note: map checks from receiver to
635 // interceptor's holder has been compiled before (see a caller
637 CompileCallLoadPropertyWithInterceptor(
638 masm(), receiver(), holder_reg, this->name(), holder(),
639 IC::kLoadPropertyWithInterceptorOnly);
641 // Check if interceptor provided a value for property. If it's
642 // the case, return immediately.
643 Label interceptor_failed;
644 __ cmp(eax, factory()->no_interceptor_result_sentinel());
645 __ j(equal, &interceptor_failed);
646 frame_scope.GenerateLeaveFrame();
649 // Clobber registers when generating debug-code to provoke errors.
650 __ bind(&interceptor_failed);
651 if (FLAG_debug_code) {
652 __ mov(receiver(), Immediate(bit_cast<int32_t>(kZapValue)));
653 __ mov(holder_reg, Immediate(bit_cast<int32_t>(kZapValue)));
654 __ mov(this->name(), Immediate(bit_cast<int32_t>(kZapValue)));
657 InterceptorVectorSlotPop(holder_reg);
658 __ pop(this->name());
660 if (must_preserve_receiver_reg) {
664 // Leave the internal frame.
667 GenerateLoadPostInterceptor(it, holder_reg);
671 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
672 DCHECK(holder()->HasNamedInterceptor());
673 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
674 // Call the runtime system to load the interceptor.
675 __ pop(scratch2()); // save old return address
676 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
678 __ push(scratch2()); // restore old return address
680 ExternalReference ref = ExternalReference(
681 IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
682 __ TailCallExternalReference(
683 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
687 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
688 Handle<JSObject> object, Handle<Name> name,
689 Handle<ExecutableAccessorInfo> callback) {
690 Register holder_reg = Frontend(name);
692 __ pop(scratch1()); // remove the return address
695 // If the callback cannot leak, then push the callback directly,
696 // otherwise wrap it in a weak cell.
697 if (callback->data()->IsUndefined() || callback->data()->IsSmi()) {
700 Handle<WeakCell> cell = isolate()->factory()->NewWeakCell(callback);
705 __ push(scratch1()); // restore return address
707 // Do tail-call to the runtime system.
708 ExternalReference store_callback_property =
709 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
710 __ TailCallExternalReference(store_callback_property, 5, 1);
712 // Return the generated code.
713 return GetCode(kind(), Code::FAST, name);
717 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
719 __ pop(scratch1()); // remove the return address
721 __ push(this->name());
723 __ push(scratch1()); // restore return address
725 // Do tail-call to the runtime system.
726 ExternalReference store_ic_property = ExternalReference(
727 IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
728 __ TailCallExternalReference(store_ic_property, 3, 1);
730 // Return the generated code.
731 return GetCode(kind(), Code::FAST, name);
735 Register NamedStoreHandlerCompiler::value() {
736 return StoreDescriptor::ValueRegister();
740 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
741 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
743 if (IC::ICUseVector(kind())) {
746 FrontendHeader(receiver(), name, &miss);
747 // Get the value from the cell.
748 Register result = StoreDescriptor::ValueRegister();
749 Handle<WeakCell> weak_cell = factory()->NewWeakCell(cell);
750 __ LoadWeakValue(result, weak_cell, &miss);
751 __ mov(result, FieldOperand(result, PropertyCell::kValueOffset));
753 // Check for deleted property if property can actually be deleted.
754 if (is_configurable) {
755 __ cmp(result, factory()->the_hole_value());
757 } else if (FLAG_debug_code) {
758 __ cmp(result, factory()->the_hole_value());
759 __ Check(not_equal, kDontDeleteCellsCannotContainTheHole);
762 Counters* counters = isolate()->counters();
763 __ IncrementCounter(counters->named_load_global_stub(), 1);
764 // The code above already loads the result into the return register.
765 if (IC::ICUseVector(kind())) {
766 DiscardVectorAndSlot();
770 FrontendFooter(name, &miss);
772 // Return the generated code.
773 return GetCode(kind(), Code::NORMAL, name);
779 } // namespace v8::internal
781 #endif // V8_TARGET_ARCH_X87