1 // Copyright 2013 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.
7 #if V8_TARGET_ARCH_ARM64
9 #include "src/codegen.h"
10 #include "src/ic-inl.h"
11 #include "src/stub-cache.h"
17 #define __ ACCESS_MASM(masm)
20 void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
21 MacroAssembler* masm, Label* miss_label, Register receiver,
22 Handle<Name> name, Register scratch0, Register scratch1) {
23 DCHECK(!AreAliased(receiver, scratch0, scratch1));
24 DCHECK(name->IsUniqueName());
25 Counters* counters = masm->isolate()->counters();
26 __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
27 __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
31 const int kInterceptorOrAccessCheckNeededMask =
32 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
34 // Bail out if the receiver has a named interceptor or requires access checks.
35 Register map = scratch1;
36 __ Ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
37 __ Ldrb(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
38 __ Tst(scratch0, kInterceptorOrAccessCheckNeededMask);
41 // Check that receiver is a JSObject.
42 __ Ldrb(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
43 __ Cmp(scratch0, FIRST_SPEC_OBJECT_TYPE);
46 // Load properties array.
47 Register properties = scratch0;
48 __ Ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
49 // Check that the properties array is a dictionary.
50 __ Ldr(map, FieldMemOperand(properties, HeapObject::kMapOffset));
51 __ JumpIfNotRoot(map, Heap::kHashTableMapRootIndex, miss_label);
53 NameDictionaryLookupStub::GenerateNegativeLookup(masm,
61 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
65 // Probe primary or secondary table.
66 // If the entry is found in the cache, the generated code jump to the first
67 // instruction of the stub in the cache.
68 // If there is a miss the code fall trough.
70 // 'receiver', 'name' and 'offset' registers are preserved on miss.
71 static void ProbeTable(Isolate* isolate,
74 StubCache::Table table,
81 // Some code below relies on the fact that the Entry struct contains
82 // 3 pointers (name, code, map).
83 STATIC_ASSERT(sizeof(StubCache::Entry) == (3 * kPointerSize));
85 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
86 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
87 ExternalReference map_offset(isolate->stub_cache()->map_reference(table));
89 uintptr_t key_off_addr = reinterpret_cast<uintptr_t>(key_offset.address());
90 uintptr_t value_off_addr =
91 reinterpret_cast<uintptr_t>(value_offset.address());
92 uintptr_t map_off_addr = reinterpret_cast<uintptr_t>(map_offset.address());
96 DCHECK(!AreAliased(name, offset, scratch, scratch2, scratch3));
98 // Multiply by 3 because there are 3 fields per entry.
99 __ Add(scratch3, offset, Operand(offset, LSL, 1));
101 // Calculate the base address of the entry.
102 __ Mov(scratch, key_offset);
103 __ Add(scratch, scratch, Operand(scratch3, LSL, kPointerSizeLog2));
105 // Check that the key in the entry matches the name.
106 __ Ldr(scratch2, MemOperand(scratch));
107 __ Cmp(name, scratch2);
110 // Check the map matches.
111 __ Ldr(scratch2, MemOperand(scratch, map_off_addr - key_off_addr));
112 __ Ldr(scratch3, FieldMemOperand(receiver, HeapObject::kMapOffset));
113 __ Cmp(scratch2, scratch3);
116 // Get the code entry from the cache.
117 __ Ldr(scratch, MemOperand(scratch, value_off_addr - key_off_addr));
119 // Check that the flags match what we're looking for.
120 __ Ldr(scratch2.W(), FieldMemOperand(scratch, Code::kFlagsOffset));
121 __ Bic(scratch2.W(), scratch2.W(), Code::kFlagsNotUsedInLookup);
122 __ Cmp(scratch2.W(), flags);
126 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
128 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
133 // Jump to the first instruction in the code stub.
134 __ Add(scratch, scratch, Code::kHeaderSize - kHeapObjectTag);
137 // Miss: fall through.
142 void StubCache::GenerateProbe(MacroAssembler* masm,
150 Isolate* isolate = masm->isolate();
153 // Make sure the flags does not name a specific type.
154 DCHECK(Code::ExtractTypeFromFlags(flags) == 0);
156 // Make sure that there are no register conflicts.
157 DCHECK(!AreAliased(receiver, name, scratch, extra, extra2, extra3));
159 // Make sure extra and extra2 registers are valid.
160 DCHECK(!extra.is(no_reg));
161 DCHECK(!extra2.is(no_reg));
162 DCHECK(!extra3.is(no_reg));
164 Counters* counters = masm->isolate()->counters();
165 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1,
168 // Check that the receiver isn't a smi.
169 __ JumpIfSmi(receiver, &miss);
171 // Compute the hash for primary table.
172 __ Ldr(scratch, FieldMemOperand(name, Name::kHashFieldOffset));
173 __ Ldr(extra, FieldMemOperand(receiver, HeapObject::kMapOffset));
174 __ Add(scratch, scratch, extra);
175 __ Eor(scratch, scratch, flags);
176 // We shift out the last two bits because they are not part of the hash.
177 __ Ubfx(scratch, scratch, kCacheIndexShift,
178 CountTrailingZeros(kPrimaryTableSize, 64));
180 // Probe the primary table.
181 ProbeTable(isolate, masm, flags, kPrimary, receiver, name,
182 scratch, extra, extra2, extra3);
184 // Primary miss: Compute hash for secondary table.
185 __ Sub(scratch, scratch, Operand(name, LSR, kCacheIndexShift));
186 __ Add(scratch, scratch, flags >> kCacheIndexShift);
187 __ And(scratch, scratch, kSecondaryTableSize - 1);
189 // Probe the secondary table.
190 ProbeTable(isolate, masm, flags, kSecondary, receiver, name,
191 scratch, extra, extra2, extra3);
193 // Cache miss: Fall-through and let caller handle the miss by
194 // entering the runtime system.
196 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1,
201 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
202 MacroAssembler* masm, int index, Register prototype, Label* miss) {
203 Isolate* isolate = masm->isolate();
204 // Get the global function with the given index.
205 Handle<JSFunction> function(
206 JSFunction::cast(isolate->native_context()->get(index)));
208 // Check we're still in the same context.
209 Register scratch = prototype;
210 __ Ldr(scratch, GlobalObjectMemOperand());
211 __ Ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
212 __ Ldr(scratch, ContextMemOperand(scratch, index));
213 __ Cmp(scratch, Operand(function));
216 // Load its initial map. The global functions all have initial maps.
217 __ Mov(prototype, Operand(Handle<Map>(function->initial_map())));
218 // Load the prototype from the initial map.
219 __ Ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
223 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
224 MacroAssembler* masm, Register receiver, Register scratch1,
225 Register scratch2, Label* miss_label) {
226 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
227 // TryGetFunctionPrototype can't put the result directly in x0 because the
228 // 3 inputs registers can't alias and we call this function from
229 // LoadIC::GenerateFunctionPrototype, where receiver is x0. So we explicitly
230 // move the result in x0.
231 __ Mov(x0, scratch1);
236 // Generate code to check that a global property cell is empty. Create
237 // the property cell at compilation time if no cell exists for the
239 void PropertyHandlerCompiler::GenerateCheckPropertyCell(
240 MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
241 Register scratch, Label* miss) {
242 Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
243 DCHECK(cell->value()->IsTheHole());
244 __ Mov(scratch, Operand(cell));
245 __ Ldr(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
246 __ JumpIfNotRoot(scratch, Heap::kTheHoleValueRootIndex, miss);
250 static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
251 Register holder, Register name,
252 Handle<JSObject> holder_obj) {
253 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
254 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
255 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
256 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
257 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
260 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
261 DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
262 Register scratch = name;
263 __ Mov(scratch, Operand(interceptor));
264 __ Push(scratch, receiver, holder);
268 static void CompileCallLoadPropertyWithInterceptor(
269 MacroAssembler* masm, Register receiver, Register holder, Register name,
270 Handle<JSObject> holder_obj, IC::UtilityId id) {
271 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
273 __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
274 NamedLoadHandlerCompiler::kInterceptorArgsLength);
278 // Generate call to api function.
279 void PropertyHandlerCompiler::GenerateFastApiCall(
280 MacroAssembler* masm, const CallOptimization& optimization,
281 Handle<Map> receiver_map, Register receiver, Register scratch,
282 bool is_store, int argc, Register* values) {
283 DCHECK(!AreAliased(receiver, scratch));
285 MacroAssembler::PushPopQueue queue(masm);
286 queue.Queue(receiver);
287 // Write the arguments to the stack frame.
288 for (int i = 0; i < argc; i++) {
289 Register arg = values[argc - 1 - i];
290 DCHECK(!AreAliased(receiver, scratch, arg));
295 DCHECK(optimization.is_simple_api_call());
297 // Abi for CallApiFunctionStub.
298 Register callee = x0;
299 Register call_data = x4;
300 Register holder = x2;
301 Register api_function_address = x1;
303 // Put holder in place.
304 CallOptimization::HolderLookup holder_lookup;
305 Handle<JSObject> api_holder =
306 optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
307 switch (holder_lookup) {
308 case CallOptimization::kHolderIsReceiver:
309 __ Mov(holder, receiver);
311 case CallOptimization::kHolderFound:
312 __ LoadObject(holder, api_holder);
314 case CallOptimization::kHolderNotFound:
319 Isolate* isolate = masm->isolate();
320 Handle<JSFunction> function = optimization.constant_function();
321 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
322 Handle<Object> call_data_obj(api_call_info->data(), isolate);
324 // Put callee in place.
325 __ LoadObject(callee, function);
327 bool call_data_undefined = false;
328 // Put call_data in place.
329 if (isolate->heap()->InNewSpace(*call_data_obj)) {
330 __ LoadObject(call_data, api_call_info);
331 __ Ldr(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset));
332 } else if (call_data_obj->IsUndefined()) {
333 call_data_undefined = true;
334 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
336 __ LoadObject(call_data, call_data_obj);
339 // Put api_function_address in place.
340 Address function_address = v8::ToCData<Address>(api_call_info->callback());
341 ApiFunction fun(function_address);
342 ExternalReference ref = ExternalReference(
343 &fun, ExternalReference::DIRECT_API_CALL, masm->isolate());
344 __ Mov(api_function_address, ref);
347 CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
348 __ TailCallStub(&stub);
352 void PropertyAccessCompiler::GenerateTailCall(MacroAssembler* masm,
354 __ Jump(code, RelocInfo::CODE_TARGET);
359 #define __ ACCESS_MASM(masm())
362 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
364 if (!label->is_unused()) {
366 __ Mov(this->name(), Operand(name));
371 // Generate StoreTransition code, value is passed in x0 register.
372 // When leaving generated code after success, the receiver_reg and storage_reg
373 // may be clobbered. Upon branch to miss_label, the receiver and name registers
374 // have their original values.
375 void NamedStoreHandlerCompiler::GenerateStoreTransition(
376 Handle<Map> transition, Handle<Name> name, Register receiver_reg,
377 Register storage_reg, Register value_reg, Register scratch1,
378 Register scratch2, Register scratch3, Label* miss_label, Label* slow) {
381 DCHECK(!AreAliased(receiver_reg, storage_reg, value_reg,
382 scratch1, scratch2, scratch3));
384 // We don't need scratch3.
387 int descriptor = transition->LastAdded();
388 DescriptorArray* descriptors = transition->instance_descriptors();
389 PropertyDetails details = descriptors->GetDetails(descriptor);
390 Representation representation = details.representation();
391 DCHECK(!representation.IsNone());
393 if (details.type() == CONSTANT) {
394 Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
395 __ LoadObject(scratch1, constant);
396 __ Cmp(value_reg, scratch1);
397 __ B(ne, miss_label);
398 } else if (representation.IsSmi()) {
399 __ JumpIfNotSmi(value_reg, miss_label);
400 } else if (representation.IsHeapObject()) {
401 __ JumpIfSmi(value_reg, miss_label);
402 HeapType* field_type = descriptors->GetFieldType(descriptor);
403 HeapType::Iterator<Map> it = field_type->Classes();
405 __ Ldr(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
408 __ CompareMap(scratch1, it.Current());
411 __ B(ne, miss_label);
418 } else if (representation.IsDouble()) {
419 UseScratchRegisterScope temps(masm());
420 DoubleRegister temp_double = temps.AcquireD();
421 __ SmiUntagToDouble(temp_double, value_reg, kSpeculativeUntag);
424 __ JumpIfSmi(value_reg, &do_store);
426 __ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex,
427 miss_label, DONT_DO_SMI_CHECK);
428 __ Ldr(temp_double, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
431 __ AllocateHeapNumber(storage_reg, slow, scratch1, scratch2, temp_double,
435 // Stub never generated for objects that require access checks.
436 DCHECK(!transition->is_access_check_needed());
438 // Perform map transition for the receiver if necessary.
439 if (details.type() == FIELD &&
440 Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
441 // The properties must be extended before we can store the value.
442 // We jump to a runtime call that extends the properties array.
443 __ Mov(scratch1, Operand(transition));
444 __ Push(receiver_reg, scratch1, value_reg);
445 __ TailCallExternalReference(
446 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
452 // Update the map of the object.
453 __ Mov(scratch1, Operand(transition));
454 __ Str(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
456 // Update the write barrier for the map field.
457 __ RecordWriteField(receiver_reg,
458 HeapObject::kMapOffset,
466 if (details.type() == CONSTANT) {
467 DCHECK(value_reg.is(x0));
472 int index = transition->instance_descriptors()->GetFieldIndex(
473 transition->LastAdded());
475 // Adjust for the number of properties stored in the object. Even in the
476 // face of a transition we can use the old map here because the size of the
477 // object and the number of in-object properties is not going to change.
478 index -= transition->inobject_properties();
480 // TODO(verwaest): Share this code as a code stub.
481 SmiCheck smi_check = representation.IsTagged()
482 ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
483 Register prop_reg = representation.IsDouble() ? storage_reg : value_reg;
485 // Set the property straight into the object.
486 int offset = transition->instance_size() + (index * kPointerSize);
487 __ Str(prop_reg, FieldMemOperand(receiver_reg, offset));
489 if (!representation.IsSmi()) {
490 // Update the write barrier for the array address.
491 if (!representation.IsDouble()) {
492 __ Mov(storage_reg, value_reg);
494 __ RecordWriteField(receiver_reg,
504 // Write to the properties array.
505 int offset = index * kPointerSize + FixedArray::kHeaderSize;
506 // Get the properties array
508 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
509 __ Str(prop_reg, FieldMemOperand(scratch1, offset));
511 if (!representation.IsSmi()) {
512 // Update the write barrier for the array address.
513 if (!representation.IsDouble()) {
514 __ Mov(storage_reg, value_reg);
516 __ RecordWriteField(scratch1,
528 // Return the value (register x0).
529 DCHECK(value_reg.is(x0));
534 void NamedStoreHandlerCompiler::GenerateStoreField(LookupResult* lookup,
537 DCHECK(lookup->representation().IsHeapObject());
538 __ JumpIfSmi(value_reg, miss_label);
539 HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
540 __ Ldr(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset));
543 __ CompareMap(scratch1(), it.Current());
546 __ B(ne, miss_label);
553 StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
554 lookup->representation());
555 GenerateTailCall(masm(), stub.GetCode());
559 Register PropertyHandlerCompiler::CheckPrototypes(
560 Register object_reg, Register holder_reg, Register scratch1,
561 Register scratch2, Handle<Name> name, Label* miss,
562 PrototypeCheckType check) {
563 Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
565 // object_reg and holder_reg registers can alias.
566 DCHECK(!AreAliased(object_reg, scratch1, scratch2));
567 DCHECK(!AreAliased(holder_reg, scratch1, scratch2));
569 // Keep track of the current object in register reg.
570 Register reg = object_reg;
573 Handle<JSObject> current = Handle<JSObject>::null();
574 if (type()->IsConstant()) {
575 current = Handle<JSObject>::cast(type()->AsConstant()->Value());
577 Handle<JSObject> prototype = Handle<JSObject>::null();
578 Handle<Map> current_map = receiver_map;
579 Handle<Map> holder_map(holder()->map());
580 // Traverse the prototype chain and check the maps in the prototype chain for
581 // fast and global objects or do negative lookup for normal objects.
582 while (!current_map.is_identical_to(holder_map)) {
585 // Only global objects and objects that do not require access
586 // checks are allowed in stubs.
587 DCHECK(current_map->IsJSGlobalProxyMap() ||
588 !current_map->is_access_check_needed());
590 prototype = handle(JSObject::cast(current_map->prototype()));
591 if (current_map->is_dictionary_map() &&
592 !current_map->IsJSGlobalObjectMap()) {
593 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
594 if (!name->IsUniqueName()) {
595 DCHECK(name->IsString());
596 name = factory()->InternalizeString(Handle<String>::cast(name));
598 DCHECK(current.is_null() ||
599 (current->property_dictionary()->FindEntry(name) ==
600 NameDictionary::kNotFound));
602 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
605 __ Ldr(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
606 reg = holder_reg; // From now on the object will be in holder_reg.
607 __ Ldr(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
609 // Two possible reasons for loading the prototype from the map:
610 // (1) Can't store references to new space in code.
611 // (2) Handler is shared for all receivers with the same prototype
612 // map (but not necessarily the same prototype instance).
613 bool load_prototype_from_map =
614 heap()->InNewSpace(*prototype) || depth == 1;
615 Register map_reg = scratch1;
616 __ Ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
618 if (depth != 1 || check == CHECK_ALL_MAPS) {
619 __ CheckMap(map_reg, current_map, miss, DONT_DO_SMI_CHECK);
622 // Check access rights to the global object. This has to happen after
623 // the map check so that we know that the object is actually a global
625 // This allows us to install generated handlers for accesses to the
626 // global proxy (as opposed to using slow ICs). See corresponding code
627 // in LookupForRead().
628 if (current_map->IsJSGlobalProxyMap()) {
629 UseScratchRegisterScope temps(masm());
630 __ CheckAccessGlobalProxy(reg, scratch2, temps.AcquireX(), miss);
631 } else if (current_map->IsJSGlobalObjectMap()) {
632 GenerateCheckPropertyCell(
633 masm(), Handle<JSGlobalObject>::cast(current), name,
637 reg = holder_reg; // From now on the object will be in holder_reg.
639 if (load_prototype_from_map) {
640 __ Ldr(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
642 __ Mov(reg, Operand(prototype));
646 // Go to the next object in the prototype chain.
648 current_map = handle(current->map());
651 // Log the check depth.
652 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
654 // Check the holder map.
655 if (depth != 0 || check == CHECK_ALL_MAPS) {
656 // Check the holder map.
657 __ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK);
660 // Perform security check for access to the global object.
661 DCHECK(current_map->IsJSGlobalProxyMap() ||
662 !current_map->is_access_check_needed());
663 if (current_map->IsJSGlobalProxyMap()) {
664 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
667 // Return the register containing the holder.
672 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
673 if (!miss->is_unused()) {
678 TailCallBuiltin(masm(), MissBuiltin(kind()));
685 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
686 if (!miss->is_unused()) {
690 GenerateRestoreName(miss, name);
691 TailCallBuiltin(masm(), MissBuiltin(kind()));
698 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
699 // Return the constant value.
700 __ LoadObject(x0, value);
705 void NamedLoadHandlerCompiler::GenerateLoadCallback(
706 Register reg, Handle<ExecutableAccessorInfo> callback) {
707 DCHECK(!AreAliased(scratch2(), scratch3(), scratch4(), reg));
709 // Build ExecutableAccessorInfo::args_ list on the stack and push property
710 // name below the exit frame to make GC aware of them and store pointers to
712 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
713 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
714 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
715 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
716 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
717 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
718 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
722 if (heap()->InNewSpace(callback->data())) {
723 __ Mov(scratch3(), Operand(callback));
724 __ Ldr(scratch3(), FieldMemOperand(scratch3(),
725 ExecutableAccessorInfo::kDataOffset));
727 __ Mov(scratch3(), Operand(Handle<Object>(callback->data(), isolate())));
729 __ LoadRoot(scratch4(), Heap::kUndefinedValueRootIndex);
730 __ Mov(scratch2(), Operand(ExternalReference::isolate_address(isolate())));
731 __ Push(scratch3(), scratch4(), scratch4(), scratch2(), reg, name());
733 Register args_addr = scratch2();
734 __ Add(args_addr, __ StackPointer(), kPointerSize);
736 // Stack at this point:
737 // sp[40] callback data
741 // args_addr -> sp[8] reg
744 // Abi for CallApiGetter.
745 Register getter_address_reg = x2;
748 Address getter_address = v8::ToCData<Address>(callback->getter());
749 ApiFunction fun(getter_address);
750 ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
751 ExternalReference ref = ExternalReference(&fun, type, isolate());
752 __ Mov(getter_address_reg, ref);
754 CallApiGetterStub stub(isolate());
755 __ TailCallStub(&stub);
759 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg,
760 LookupResult* lookup,
762 DCHECK(!AreAliased(receiver(), this->name(),
763 scratch1(), scratch2(), scratch3()));
764 DCHECK(holder()->HasNamedInterceptor());
765 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
767 // So far the most popular follow ups for interceptor loads are FIELD
768 // and CALLBACKS, so inline only them, other cases may be added later.
769 bool compile_followup_inline = false;
770 if (lookup->IsFound() && lookup->IsCacheable()) {
771 if (lookup->IsField()) {
772 compile_followup_inline = true;
773 } else if (lookup->type() == CALLBACKS &&
774 lookup->GetCallbackObject()->IsExecutableAccessorInfo()) {
775 Handle<ExecutableAccessorInfo> callback(
776 ExecutableAccessorInfo::cast(lookup->GetCallbackObject()));
777 compile_followup_inline =
778 callback->getter() != NULL &&
779 ExecutableAccessorInfo::IsCompatibleReceiverType(isolate(), callback,
784 if (compile_followup_inline) {
785 // Compile the interceptor call, followed by inline code to load the
786 // property from further up the prototype chain if the call fails.
787 // Check that the maps haven't changed.
788 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
790 // Preserve the receiver register explicitly whenever it is different from
791 // the holder and it is needed should the interceptor return without any
792 // result. The CALLBACKS case needs the receiver to be passed into C++ code,
793 // the FIELD case might cause a miss during the prototype check.
794 bool must_perfrom_prototype_check = *holder() != lookup->holder();
795 bool must_preserve_receiver_reg = !receiver().Is(holder_reg) &&
796 (lookup->type() == CALLBACKS || must_perfrom_prototype_check);
798 // Save necessary data before invoking an interceptor.
799 // Requires a frame to make GC aware of pushed pointers.
801 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
802 if (must_preserve_receiver_reg) {
803 __ Push(receiver(), holder_reg, this->name());
805 __ Push(holder_reg, this->name());
807 // Invoke an interceptor. Note: map checks from receiver to
808 // interceptor's holder has been compiled before (see a caller
810 CompileCallLoadPropertyWithInterceptor(
811 masm(), receiver(), holder_reg, this->name(), holder(),
812 IC::kLoadPropertyWithInterceptorOnly);
814 // Check if interceptor provided a value for property. If it's
815 // the case, return immediately.
816 Label interceptor_failed;
818 Heap::kNoInterceptorResultSentinelRootIndex,
819 &interceptor_failed);
820 frame_scope.GenerateLeaveFrame();
823 __ Bind(&interceptor_failed);
824 if (must_preserve_receiver_reg) {
825 __ Pop(this->name(), holder_reg, receiver());
827 __ Pop(this->name(), holder_reg);
829 // Leave the internal frame.
831 GenerateLoadPostInterceptor(holder_reg, name, lookup);
832 } else { // !compile_followup_inline
833 // Call the runtime system to load the interceptor.
834 // Check that the maps haven't changed.
835 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
838 ExternalReference ref =
839 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptor),
841 __ TailCallExternalReference(
842 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
847 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
848 Handle<JSObject> object, Handle<Name> name,
849 Handle<ExecutableAccessorInfo> callback) {
850 ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreCallback");
851 Register holder_reg = Frontend(receiver(), name);
853 // Stub never generated for non-global objects that require access checks.
854 DCHECK(holder()->IsJSGlobalProxy() || !holder()->IsAccessCheckNeeded());
856 // receiver() and holder_reg can alias.
857 DCHECK(!AreAliased(receiver(), scratch1(), scratch2(), value()));
858 DCHECK(!AreAliased(holder_reg, scratch1(), scratch2(), value()));
859 __ Mov(scratch1(), Operand(callback));
860 __ Mov(scratch2(), Operand(name));
861 __ Push(receiver(), holder_reg, scratch1(), scratch2(), value());
863 // Do tail-call to the runtime system.
864 ExternalReference store_callback_property =
865 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
866 __ TailCallExternalReference(store_callback_property, 5, 1);
868 // Return the generated code.
869 return GetCode(kind(), Code::FAST, name);
874 #define __ ACCESS_MASM(masm)
877 void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
878 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
879 Handle<JSFunction> setter) {
880 // ----------- S t a t e -------------
881 // -- lr : return address
882 // -----------------------------------
886 FrameScope scope(masm, StackFrame::INTERNAL);
888 // Save value register, so we can restore it later.
891 if (!setter.is_null()) {
892 // Call the JavaScript setter with receiver and value on the stack.
893 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
894 // Swap in the global receiver.
896 FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
898 __ Push(receiver, value());
899 ParameterCount actual(1);
900 ParameterCount expected(setter);
901 __ InvokeFunction(setter, expected, actual,
902 CALL_FUNCTION, NullCallWrapper());
904 // If we generate a global code snippet for deoptimization only, remember
905 // the place to continue after deoptimization.
906 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
909 // We have to return the passed value, not the return value of the setter.
912 // Restore context register.
913 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
920 #define __ ACCESS_MASM(masm())
923 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
927 ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreInterceptor");
929 __ Push(receiver(), this->name(), value());
931 // Do tail-call to the runtime system.
932 ExternalReference store_ic_property = ExternalReference(
933 IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
934 __ TailCallExternalReference(store_ic_property, 3, 1);
936 // Return the generated code.
937 return GetCode(kind(), Code::FAST, name);
941 // TODO(all): The so-called scratch registers are significant in some cases. For
942 // example, PropertyAccessCompiler::keyed_store_calling_convention()[3] (x3) is
944 // used for KeyedStoreCompiler::transition_map(). We should verify which
945 // registers are actually scratch registers, and which are important. For now,
946 // we use the same assignments as ARM to remain on the safe side.
948 Register* PropertyAccessCompiler::load_calling_convention() {
949 // receiver, name, scratch1, scratch2, scratch3, scratch4.
950 Register receiver = LoadIC::ReceiverRegister();
951 Register name = LoadIC::NameRegister();
952 static Register registers[] = { receiver, name, x3, x0, x4, x5 };
957 Register* PropertyAccessCompiler::store_calling_convention() {
958 // receiver, value, scratch1, scratch2, scratch3.
959 Register receiver = StoreIC::ReceiverRegister();
960 Register name = StoreIC::NameRegister();
961 DCHECK(x3.is(KeyedStoreIC::MapRegister()));
962 static Register registers[] = { receiver, name, x3, x4, x5 };
967 Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
971 #define __ ACCESS_MASM(masm)
973 void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
974 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
975 Handle<JSFunction> getter) {
977 FrameScope scope(masm, StackFrame::INTERNAL);
979 if (!getter.is_null()) {
980 // Call the JavaScript getter with the receiver on the stack.
981 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
982 // Swap in the global receiver.
984 FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
987 ParameterCount actual(0);
988 ParameterCount expected(getter);
989 __ InvokeFunction(getter, expected, actual,
990 CALL_FUNCTION, NullCallWrapper());
992 // If we generate a global code snippet for deoptimization only, remember
993 // the place to continue after deoptimization.
994 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
997 // Restore context register.
998 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1005 #define __ ACCESS_MASM(masm())
1008 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
1009 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
1011 FrontendHeader(receiver(), name, &miss);
1013 // Get the value from the cell.
1014 Register result = StoreIC::ValueRegister();
1015 __ Mov(result, Operand(cell));
1016 __ Ldr(result, FieldMemOperand(result, Cell::kValueOffset));
1018 // Check for deleted property if property can actually be deleted.
1019 if (is_configurable) {
1020 __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &miss);
1023 Counters* counters = isolate()->counters();
1024 __ IncrementCounter(counters->named_load_global_stub(), 1, x1, x3);
1027 FrontendFooter(name, &miss);
1029 // Return the generated code.
1030 return GetCode(kind(), Code::NORMAL, name);
1034 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
1035 CodeHandleList* handlers,
1037 Code::StubType type,
1038 IcCheckType check) {
1041 if (check == PROPERTY &&
1042 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) {
1043 // In case we are compiling an IC for dictionary loads and stores, just
1044 // check whether the name is unique.
1045 if (name.is_identical_to(isolate()->factory()->normal_ic_symbol())) {
1046 __ JumpIfNotUniqueName(this->name(), &miss);
1048 __ CompareAndBranch(this->name(), Operand(name), ne, &miss);
1053 Label* smi_target = IncludesNumberType(types) ? &number_case : &miss;
1054 __ JumpIfSmi(receiver(), smi_target);
1056 // Polymorphic keyed stores may use the map register
1057 Register map_reg = scratch1();
1058 DCHECK(kind() != Code::KEYED_STORE_IC ||
1059 map_reg.is(KeyedStoreIC::MapRegister()));
1060 __ Ldr(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
1061 int receiver_count = types->length();
1062 int number_of_handled_maps = 0;
1063 for (int current = 0; current < receiver_count; ++current) {
1064 Handle<HeapType> type = types->at(current);
1065 Handle<Map> map = IC::TypeToMap(*type, isolate());
1066 if (!map->is_deprecated()) {
1067 number_of_handled_maps++;
1069 __ Cmp(map_reg, Operand(map));
1070 __ B(ne, &try_next);
1071 if (type->Is(HeapType::Number())) {
1072 DCHECK(!number_case.is_unused());
1073 __ Bind(&number_case);
1075 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET);
1079 DCHECK(number_of_handled_maps != 0);
1082 TailCallBuiltin(masm(), MissBuiltin(kind()));
1084 // Return the generated code.
1085 InlineCacheState state =
1086 (number_of_handled_maps > 1) ? POLYMORPHIC : MONOMORPHIC;
1087 return GetCode(kind(), type, name, state);
1091 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
1092 MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
1093 MapHandleList* transitioned_maps) {
1096 ASM_LOCATION("PropertyICCompiler::CompileStorePolymorphic");
1098 __ JumpIfSmi(receiver(), &miss);
1100 int receiver_count = receiver_maps->length();
1101 __ Ldr(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
1102 for (int i = 0; i < receiver_count; i++) {
1103 __ Cmp(scratch1(), Operand(receiver_maps->at(i)));
1107 if (!transitioned_maps->at(i).is_null()) {
1108 // This argument is used by the handler stub. For example, see
1109 // ElementsTransitionGenerator::GenerateMapChangeElementsTransition.
1110 __ Mov(transition_map(), Operand(transitioned_maps->at(i)));
1112 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
1117 TailCallBuiltin(masm(), MissBuiltin(kind()));
1119 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
1124 #define __ ACCESS_MASM(masm)
1126 void ElementHandlerCompiler::GenerateLoadDictionaryElement(
1127 MacroAssembler* masm) {
1128 // The return address is in lr.
1131 Register result = x0;
1132 Register key = LoadIC::NameRegister();
1133 Register receiver = LoadIC::ReceiverRegister();
1134 DCHECK(receiver.is(x1));
1137 __ JumpIfNotSmi(key, &miss);
1138 __ Ldr(x4, FieldMemOperand(receiver, JSObject::kElementsOffset));
1139 __ LoadFromNumberDictionary(&slow, x4, key, result, x7, x3, x5, x6);
1143 __ IncrementCounter(
1144 masm->isolate()->counters()->keyed_load_external_array_slow(), 1, x4, x3);
1145 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
1147 // Miss case, call the runtime.
1149 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
1153 } } // namespace v8::internal
1155 #endif // V8_TARGET_ARCH_ARM64