4283d39f22e6d27f4b1c05777d028bc3cc3ad66e
[platform/upstream/nodejs.git] / deps / v8 / src / ic / ppc / handler-compiler-ppc.cc
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
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #if V8_TARGET_ARCH_PPC
8
9 #include "src/ic/call-optimization.h"
10 #include "src/ic/handler-compiler.h"
11 #include "src/ic/ic.h"
12
13 namespace v8 {
14 namespace internal {
15
16 #define __ ACCESS_MASM(masm)
17
18
19 void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
20     MacroAssembler* masm, Handle<HeapType> type, Register receiver,
21     Register holder, int accessor_index, int expected_arguments,
22     Register scratch) {
23   // ----------- S t a t e -------------
24   //  -- r3    : receiver
25   //  -- r5    : name
26   //  -- lr    : return address
27   // -----------------------------------
28   {
29     FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
30
31     if (accessor_index >= 0) {
32       DCHECK(!holder.is(scratch));
33       DCHECK(!receiver.is(scratch));
34       // Call the JavaScript getter with the receiver on the stack.
35       if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
36         // Swap in the global receiver.
37         __ LoadP(scratch,
38                  FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
39         receiver = scratch;
40       }
41       __ push(receiver);
42       ParameterCount actual(0);
43       ParameterCount expected(expected_arguments);
44       __ LoadAccessor(r4, holder, accessor_index, ACCESSOR_GETTER);
45       __ InvokeFunction(r4, expected, actual, CALL_FUNCTION, NullCallWrapper());
46     } else {
47       // If we generate a global code snippet for deoptimization only, remember
48       // the place to continue after deoptimization.
49       masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
50     }
51
52     // Restore context register.
53     __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
54   }
55   __ Ret();
56 }
57
58
59 void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
60     MacroAssembler* masm, Handle<HeapType> type, Register receiver,
61     Register holder, int accessor_index, int expected_arguments,
62     Register scratch) {
63   // ----------- S t a t e -------------
64   //  -- lr    : return address
65   // -----------------------------------
66   {
67     FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
68
69     // Save value register, so we can restore it later.
70     __ push(value());
71
72     if (accessor_index >= 0) {
73       DCHECK(!holder.is(scratch));
74       DCHECK(!receiver.is(scratch));
75       DCHECK(!value().is(scratch));
76       // Call the JavaScript setter with receiver and value on the stack.
77       if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
78         // Swap in the global receiver.
79         __ LoadP(scratch,
80                  FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
81         receiver = scratch;
82       }
83       __ Push(receiver, value());
84       ParameterCount actual(1);
85       ParameterCount expected(expected_arguments);
86       __ LoadAccessor(r4, holder, accessor_index, ACCESSOR_SETTER);
87       __ InvokeFunction(r4, expected, actual, CALL_FUNCTION, NullCallWrapper());
88     } else {
89       // If we generate a global code snippet for deoptimization only, remember
90       // the place to continue after deoptimization.
91       masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
92     }
93
94     // We have to return the passed value, not the return value of the setter.
95     __ pop(r3);
96
97     // Restore context register.
98     __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
99   }
100   __ Ret();
101 }
102
103
104 void PropertyHandlerCompiler::PushVectorAndSlot(Register vector,
105                                                 Register slot) {
106   MacroAssembler* masm = this->masm();
107   __ Push(vector, slot);
108 }
109
110
111 void PropertyHandlerCompiler::PopVectorAndSlot(Register vector, Register slot) {
112   MacroAssembler* masm = this->masm();
113   __ Pop(vector, slot);
114 }
115
116
117 void PropertyHandlerCompiler::DiscardVectorAndSlot() {
118   MacroAssembler* masm = this->masm();
119   // Remove vector and slot.
120   __ addi(sp, sp, Operand(2 * kPointerSize));
121 }
122
123
124 void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
125     MacroAssembler* masm, Label* miss_label, Register receiver,
126     Handle<Name> name, Register scratch0, Register scratch1) {
127   DCHECK(name->IsUniqueName());
128   DCHECK(!receiver.is(scratch0));
129   Counters* counters = masm->isolate()->counters();
130   __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
131   __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
132
133   Label done;
134
135   const int kInterceptorOrAccessCheckNeededMask =
136       (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
137
138   // Bail out if the receiver has a named interceptor or requires access checks.
139   Register map = scratch1;
140   __ LoadP(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
141   __ lbz(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
142   __ andi(r0, scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
143   __ bne(miss_label, cr0);
144
145   // Check that receiver is a JSObject.
146   __ lbz(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
147   __ cmpi(scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
148   __ blt(miss_label);
149
150   // Load properties array.
151   Register properties = scratch0;
152   __ LoadP(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
153   // Check that the properties array is a dictionary.
154   __ LoadP(map, FieldMemOperand(properties, HeapObject::kMapOffset));
155   Register tmp = properties;
156   __ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
157   __ cmp(map, tmp);
158   __ bne(miss_label);
159
160   // Restore the temporarily used register.
161   __ LoadP(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
162
163
164   NameDictionaryLookupStub::GenerateNegativeLookup(
165       masm, miss_label, &done, receiver, properties, name, scratch1);
166   __ bind(&done);
167   __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
168 }
169
170
171 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
172     MacroAssembler* masm, int index, Register result, Label* miss) {
173   const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
174   __ LoadP(result, MemOperand(cp, offset));
175   __ LoadP(result, FieldMemOperand(result, GlobalObject::kNativeContextOffset));
176   __ LoadP(result, MemOperand(result, Context::SlotOffset(index)));
177   // Load its initial map. The global functions all have initial maps.
178   __ LoadP(result,
179            FieldMemOperand(result, JSFunction::kPrototypeOrInitialMapOffset));
180   // Load the prototype from the initial map.
181   __ LoadP(result, FieldMemOperand(result, Map::kPrototypeOffset));
182 }
183
184
185 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
186     MacroAssembler* masm, Register receiver, Register scratch1,
187     Register scratch2, Label* miss_label) {
188   __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
189   __ mr(r3, scratch1);
190   __ Ret();
191 }
192
193
194 // Generate code to check that a global property cell is empty. Create
195 // the property cell at compilation time if no cell exists for the
196 // property.
197 void PropertyHandlerCompiler::GenerateCheckPropertyCell(
198     MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
199     Register scratch, Label* miss) {
200   Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
201   DCHECK(cell->value()->IsTheHole());
202   Handle<WeakCell> weak_cell = masm->isolate()->factory()->NewWeakCell(cell);
203   __ LoadWeakValue(scratch, weak_cell, miss);
204   __ LoadP(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
205   __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
206   __ cmp(scratch, ip);
207   __ bne(miss);
208 }
209
210
211 static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
212                                      Register holder, Register name,
213                                      Handle<JSObject> holder_obj) {
214   STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
215   STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 1);
216   STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 2);
217   STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 3);
218   __ push(name);
219   __ push(receiver);
220   __ push(holder);
221 }
222
223
224 static void CompileCallLoadPropertyWithInterceptor(
225     MacroAssembler* masm, Register receiver, Register holder, Register name,
226     Handle<JSObject> holder_obj, IC::UtilityId id) {
227   PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
228   __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
229                            NamedLoadHandlerCompiler::kInterceptorArgsLength);
230 }
231
232
233 // Generate call to api function.
234 void PropertyHandlerCompiler::GenerateApiAccessorCall(
235     MacroAssembler* masm, const CallOptimization& optimization,
236     Handle<Map> receiver_map, Register receiver, Register scratch_in,
237     bool is_store, Register store_parameter, Register accessor_holder,
238     int accessor_index) {
239   DCHECK(!accessor_holder.is(scratch_in));
240   DCHECK(!receiver.is(scratch_in));
241   __ push(receiver);
242   // Write the arguments to stack frame.
243   if (is_store) {
244     DCHECK(!receiver.is(store_parameter));
245     DCHECK(!scratch_in.is(store_parameter));
246     __ push(store_parameter);
247   }
248   DCHECK(optimization.is_simple_api_call());
249
250   // Abi for CallApiFunctionStub.
251   Register callee = r3;
252   Register data = r7;
253   Register holder = r5;
254   Register api_function_address = r4;
255
256   // Put callee in place.
257   __ LoadAccessor(callee, accessor_holder, accessor_index,
258                   is_store ? ACCESSOR_SETTER : ACCESSOR_GETTER);
259
260   // Put holder in place.
261   CallOptimization::HolderLookup holder_lookup;
262   int holder_depth = 0;
263   optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup,
264                                           &holder_depth);
265   switch (holder_lookup) {
266     case CallOptimization::kHolderIsReceiver:
267       __ Move(holder, receiver);
268       break;
269     case CallOptimization::kHolderFound:
270       __ LoadP(holder, FieldMemOperand(receiver, HeapObject::kMapOffset));
271       __ LoadP(holder, FieldMemOperand(holder, Map::kPrototypeOffset));
272       for (int i = 1; i < holder_depth; i++) {
273         __ LoadP(holder, FieldMemOperand(holder, HeapObject::kMapOffset));
274         __ LoadP(holder, FieldMemOperand(holder, Map::kPrototypeOffset));
275       }
276       break;
277     case CallOptimization::kHolderNotFound:
278       UNREACHABLE();
279       break;
280   }
281
282   Isolate* isolate = masm->isolate();
283   Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
284   bool call_data_undefined = false;
285   // Put call data in place.
286   if (api_call_info->data()->IsUndefined()) {
287     call_data_undefined = true;
288     __ LoadRoot(data, Heap::kUndefinedValueRootIndex);
289   } else {
290     __ LoadP(data,
291              FieldMemOperand(callee, JSFunction::kSharedFunctionInfoOffset));
292     __ LoadP(data,
293              FieldMemOperand(data, SharedFunctionInfo::kFunctionDataOffset));
294     __ LoadP(data,
295              FieldMemOperand(data, FunctionTemplateInfo::kCallCodeOffset));
296     __ LoadP(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset));
297   }
298
299   // Put api_function_address in place.
300   Address function_address = v8::ToCData<Address>(api_call_info->callback());
301   ApiFunction fun(function_address);
302   ExternalReference::Type type = ExternalReference::DIRECT_API_CALL;
303   ExternalReference ref = ExternalReference(&fun, type, masm->isolate());
304   __ mov(api_function_address, Operand(ref));
305
306   // Jump to stub.
307   CallApiAccessorStub stub(isolate, is_store, call_data_undefined);
308   __ TailCallStub(&stub);
309 }
310
311
312 void NamedStoreHandlerCompiler::GenerateSlow(MacroAssembler* masm) {
313   // Push receiver, key and value for runtime call.
314   __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(),
315           StoreDescriptor::ValueRegister());
316
317   // The slow case calls into the runtime to complete the store without causing
318   // an IC miss that would otherwise cause a transition to the generic stub.
319   ExternalReference ref =
320       ExternalReference(IC_Utility(IC::kStoreIC_Slow), masm->isolate());
321   __ TailCallExternalReference(ref, 3, 1);
322 }
323
324
325 void ElementHandlerCompiler::GenerateStoreSlow(MacroAssembler* masm) {
326   // Push receiver, key and value for runtime call.
327   __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(),
328           StoreDescriptor::ValueRegister());
329
330   // The slow case calls into the runtime to complete the store without causing
331   // an IC miss that would otherwise cause a transition to the generic stub.
332   ExternalReference ref =
333       ExternalReference(IC_Utility(IC::kKeyedStoreIC_Slow), masm->isolate());
334   __ TailCallExternalReference(ref, 3, 1);
335 }
336
337
338 #undef __
339 #define __ ACCESS_MASM(masm())
340
341
342 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
343                                                     Handle<Name> name) {
344   if (!label->is_unused()) {
345     __ bind(label);
346     __ mov(this->name(), Operand(name));
347   }
348 }
349
350
351 void NamedStoreHandlerCompiler::GenerateRestoreName(Handle<Name> name) {
352   __ mov(this->name(), Operand(name));
353 }
354
355
356 void NamedStoreHandlerCompiler::GenerateRestoreMap(Handle<Map> transition,
357                                                    Register scratch,
358                                                    Label* miss) {
359   Handle<WeakCell> cell = Map::WeakCellForMap(transition);
360   Register map_reg = StoreTransitionDescriptor::MapRegister();
361   DCHECK(!map_reg.is(scratch));
362   __ LoadWeakValue(map_reg, cell, miss);
363   if (transition->CanBeDeprecated()) {
364     __ lwz(scratch, FieldMemOperand(map_reg, Map::kBitField3Offset));
365     __ DecodeField<Map::Deprecated>(r0, scratch, SetRC);
366     __ bne(miss, cr0);
367   }
368 }
369
370
371 void NamedStoreHandlerCompiler::GenerateConstantCheck(Register map_reg,
372                                                       int descriptor,
373                                                       Register value_reg,
374                                                       Register scratch,
375                                                       Label* miss_label) {
376   DCHECK(!map_reg.is(scratch));
377   DCHECK(!map_reg.is(value_reg));
378   DCHECK(!value_reg.is(scratch));
379   __ LoadInstanceDescriptors(map_reg, scratch);
380   __ LoadP(scratch, FieldMemOperand(
381                         scratch, DescriptorArray::GetValueOffset(descriptor)));
382   __ cmp(value_reg, scratch);
383   __ bne(miss_label);
384 }
385
386
387 void NamedStoreHandlerCompiler::GenerateFieldTypeChecks(HeapType* field_type,
388                                                         Register value_reg,
389                                                         Label* miss_label) {
390   Register map_reg = scratch1();
391   Register scratch = scratch2();
392   DCHECK(!value_reg.is(map_reg));
393   DCHECK(!value_reg.is(scratch));
394   __ JumpIfSmi(value_reg, miss_label);
395   HeapType::Iterator<Map> it = field_type->Classes();
396   if (!it.Done()) {
397     __ LoadP(map_reg, FieldMemOperand(value_reg, HeapObject::kMapOffset));
398     Label do_store;
399     while (true) {
400       __ CmpWeakValue(map_reg, Map::WeakCellForMap(it.Current()), scratch);
401       it.Advance();
402       if (it.Done()) {
403         __ bne(miss_label);
404         break;
405       }
406       __ beq(&do_store);
407     }
408     __ bind(&do_store);
409   }
410 }
411
412
413 Register PropertyHandlerCompiler::CheckPrototypes(
414     Register object_reg, Register holder_reg, Register scratch1,
415     Register scratch2, Handle<Name> name, Label* miss,
416     PrototypeCheckType check) {
417   Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
418
419   // Make sure there's no overlap between holder and object registers.
420   DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
421   DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
422          !scratch2.is(scratch1));
423
424   // Keep track of the current object in register reg.
425   Register reg = object_reg;
426   int depth = 0;
427
428   Handle<JSObject> current = Handle<JSObject>::null();
429   if (type()->IsConstant()) {
430     current = Handle<JSObject>::cast(type()->AsConstant()->Value());
431   }
432   Handle<JSObject> prototype = Handle<JSObject>::null();
433   Handle<Map> current_map = receiver_map;
434   Handle<Map> holder_map(holder()->map());
435   // Traverse the prototype chain and check the maps in the prototype chain for
436   // fast and global objects or do negative lookup for normal objects.
437   while (!current_map.is_identical_to(holder_map)) {
438     ++depth;
439
440     // Only global objects and objects that do not require access
441     // checks are allowed in stubs.
442     DCHECK(current_map->IsJSGlobalProxyMap() ||
443            !current_map->is_access_check_needed());
444
445     prototype = handle(JSObject::cast(current_map->prototype()));
446     if (current_map->is_dictionary_map() &&
447         !current_map->IsJSGlobalObjectMap()) {
448       DCHECK(!current_map->IsJSGlobalProxyMap());  // Proxy maps are fast.
449       if (!name->IsUniqueName()) {
450         DCHECK(name->IsString());
451         name = factory()->InternalizeString(Handle<String>::cast(name));
452       }
453       DCHECK(current.is_null() ||
454              current->property_dictionary()->FindEntry(name) ==
455                  NameDictionary::kNotFound);
456
457       GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
458                                        scratch2);
459
460       __ LoadP(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
461       reg = holder_reg;  // From now on the object will be in holder_reg.
462       __ LoadP(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
463     } else {
464       Register map_reg = scratch1;
465       __ LoadP(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
466       if (depth != 1 || check == CHECK_ALL_MAPS) {
467         Handle<WeakCell> cell = Map::WeakCellForMap(current_map);
468         __ CmpWeakValue(map_reg, cell, scratch2);
469         __ bne(miss);
470       }
471
472       // Check access rights to the global object.  This has to happen after
473       // the map check so that we know that the object is actually a global
474       // object.
475       // This allows us to install generated handlers for accesses to the
476       // global proxy (as opposed to using slow ICs). See corresponding code
477       // in LookupForRead().
478       if (current_map->IsJSGlobalProxyMap()) {
479         __ CheckAccessGlobalProxy(reg, scratch2, miss);
480       } else if (current_map->IsJSGlobalObjectMap()) {
481         GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
482                                   name, scratch2, miss);
483       }
484
485       reg = holder_reg;  // From now on the object will be in holder_reg.
486
487       __ LoadP(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
488     }
489
490     // Go to the next object in the prototype chain.
491     current = prototype;
492     current_map = handle(current->map());
493   }
494
495   // Log the check depth.
496   LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
497
498   if (depth != 0 || check == CHECK_ALL_MAPS) {
499     // Check the holder map.
500     __ LoadP(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
501     Handle<WeakCell> cell = Map::WeakCellForMap(current_map);
502     __ CmpWeakValue(scratch1, cell, scratch2);
503     __ bne(miss);
504   }
505
506   // Perform security check for access to the global object.
507   DCHECK(current_map->IsJSGlobalProxyMap() ||
508          !current_map->is_access_check_needed());
509   if (current_map->IsJSGlobalProxyMap()) {
510     __ CheckAccessGlobalProxy(reg, scratch1, miss);
511   }
512
513   // Return the register containing the holder.
514   return reg;
515 }
516
517
518 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
519   if (!miss->is_unused()) {
520     Label success;
521     __ b(&success);
522     __ bind(miss);
523     if (IC::ICUseVector(kind())) {
524       DCHECK(kind() == Code::LOAD_IC);
525       PopVectorAndSlot();
526     }
527     TailCallBuiltin(masm(), MissBuiltin(kind()));
528     __ bind(&success);
529   }
530 }
531
532
533 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
534   if (!miss->is_unused()) {
535     Label success;
536     __ b(&success);
537     GenerateRestoreName(miss, name);
538     TailCallBuiltin(masm(), MissBuiltin(kind()));
539     __ bind(&success);
540   }
541 }
542
543
544 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
545   // Return the constant value.
546   __ Move(r3, value);
547   __ Ret();
548 }
549
550
551 void NamedLoadHandlerCompiler::GenerateLoadCallback(
552     Register reg, Handle<ExecutableAccessorInfo> callback) {
553   // Build AccessorInfo::args_ list on the stack and push property name below
554   // the exit frame to make GC aware of them and store pointers to them.
555   STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
556   STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
557   STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
558   STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
559   STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
560   STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
561   STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
562   DCHECK(!scratch2().is(reg));
563   DCHECK(!scratch3().is(reg));
564   DCHECK(!scratch4().is(reg));
565   __ push(receiver());
566   // Push data from ExecutableAccessorInfo.
567   Handle<Object> data(callback->data(), isolate());
568   if (data->IsUndefined() || data->IsSmi()) {
569     __ Move(scratch3(), data);
570   } else {
571     Handle<WeakCell> cell =
572         isolate()->factory()->NewWeakCell(Handle<HeapObject>::cast(data));
573     // The callback is alive if this instruction is executed,
574     // so the weak cell is not cleared and points to data.
575     __ GetWeakValue(scratch3(), cell);
576   }
577   __ push(scratch3());
578   __ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex);
579   __ mr(scratch4(), scratch3());
580   __ Push(scratch3(), scratch4());
581   __ mov(scratch4(), Operand(ExternalReference::isolate_address(isolate())));
582   __ Push(scratch4(), reg);
583   __ push(name());
584
585   // Abi for CallApiGetter
586   Register getter_address_reg = ApiGetterDescriptor::function_address();
587
588   Address getter_address = v8::ToCData<Address>(callback->getter());
589   ApiFunction fun(getter_address);
590   ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
591   ExternalReference ref = ExternalReference(&fun, type, isolate());
592   __ mov(getter_address_reg, Operand(ref));
593
594   CallApiGetterStub stub(isolate());
595   __ TailCallStub(&stub);
596 }
597
598
599 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
600     LookupIterator* it, Register holder_reg) {
601   DCHECK(holder()->HasNamedInterceptor());
602   DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
603
604   // Compile the interceptor call, followed by inline code to load the
605   // property from further up the prototype chain if the call fails.
606   // Check that the maps haven't changed.
607   DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
608
609   // Preserve the receiver register explicitly whenever it is different from the
610   // holder and it is needed should the interceptor return without any result.
611   // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
612   // case might cause a miss during the prototype check.
613   bool must_perform_prototype_check =
614       !holder().is_identical_to(it->GetHolder<JSObject>());
615   bool must_preserve_receiver_reg =
616       !receiver().is(holder_reg) &&
617       (it->state() == LookupIterator::ACCESSOR || must_perform_prototype_check);
618
619   // Save necessary data before invoking an interceptor.
620   // Requires a frame to make GC aware of pushed pointers.
621   {
622     FrameAndConstantPoolScope frame_scope(masm(), StackFrame::INTERNAL);
623     if (must_preserve_receiver_reg) {
624       __ Push(receiver(), holder_reg, this->name());
625     } else {
626       __ Push(holder_reg, this->name());
627     }
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
631     // of this method.)
632     CompileCallLoadPropertyWithInterceptor(
633         masm(), receiver(), holder_reg, this->name(), holder(),
634         IC::kLoadPropertyWithInterceptorOnly);
635
636     // Check if interceptor provided a value for property.  If it's
637     // the case, return immediately.
638     Label interceptor_failed;
639     __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
640     __ cmp(r3, scratch1());
641     __ beq(&interceptor_failed);
642     frame_scope.GenerateLeaveFrame();
643     __ Ret();
644
645     __ bind(&interceptor_failed);
646     InterceptorVectorSlotPop(holder_reg);
647     __ pop(this->name());
648     __ pop(holder_reg);
649     if (must_preserve_receiver_reg) {
650       __ pop(receiver());
651     }
652     // Leave the internal frame.
653   }
654
655   GenerateLoadPostInterceptor(it, holder_reg);
656 }
657
658
659 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
660   // Call the runtime system to load the interceptor.
661   DCHECK(holder()->HasNamedInterceptor());
662   DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
663   PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
664                            holder());
665
666   ExternalReference ref = ExternalReference(
667       IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
668   __ TailCallExternalReference(
669       ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
670 }
671
672
673 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
674     Handle<JSObject> object, Handle<Name> name, int accessor_index) {
675   Register holder_reg = Frontend(name);
676
677   __ Push(receiver(), holder_reg);  // receiver
678   __ LoadSmiLiteral(ip, Smi::FromInt(accessor_index));
679   __ push(ip);
680   __ mov(ip, Operand(name));
681   __ Push(ip, value());
682
683   // Do tail-call to the runtime system.
684   ExternalReference store_callback_property =
685       ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
686   __ TailCallExternalReference(store_callback_property, 5, 1);
687
688   // Return the generated code.
689   return GetCode(kind(), Code::FAST, name);
690 }
691
692
693 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
694     Handle<Name> name) {
695   __ Push(receiver(), this->name(), value());
696
697   // Do tail-call to the runtime system.
698   ExternalReference store_ic_property = ExternalReference(
699       IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
700   __ TailCallExternalReference(store_ic_property, 3, 1);
701
702   // Return the generated code.
703   return GetCode(kind(), Code::FAST, name);
704 }
705
706
707 Register NamedStoreHandlerCompiler::value() {
708   return StoreDescriptor::ValueRegister();
709 }
710
711
712 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
713     Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
714   Label miss;
715   if (IC::ICUseVector(kind())) {
716     PushVectorAndSlot();
717   }
718   FrontendHeader(receiver(), name, &miss);
719
720   // Get the value from the cell.
721   Register result = StoreDescriptor::ValueRegister();
722   Handle<WeakCell> weak_cell = factory()->NewWeakCell(cell);
723   __ LoadWeakValue(result, weak_cell, &miss);
724   __ LoadP(result, FieldMemOperand(result, Cell::kValueOffset));
725
726   // Check for deleted property if property can actually be deleted.
727   if (is_configurable) {
728     __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
729     __ cmp(result, ip);
730     __ beq(&miss);
731   }
732
733   Counters* counters = isolate()->counters();
734   __ IncrementCounter(counters->named_load_global_stub(), 1, r4, r6);
735   if (IC::ICUseVector(kind())) {
736     DiscardVectorAndSlot();
737   }
738   __ Ret();
739
740   FrontendFooter(name, &miss);
741
742   // Return the generated code.
743   return GetCode(kind(), Code::NORMAL, name);
744 }
745
746
747 #undef __
748 }
749 }  // namespace v8::internal
750
751 #endif  // V8_TARGET_ARCH_ARM