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