Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: src/ic/arm64/ic-compiler-arm64.cc

Issue 497083002: Move handler compilers to handler-compiler (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix include Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ic/arm64/handler-compiler-arm64.cc ('k') | src/ic/handler-compiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #if V8_TARGET_ARCH_ARM64 7 #if V8_TARGET_ARCH_ARM64
8 8
9 #include "src/ic/call-optimization.h"
10 #include "src/ic/ic-compiler.h" 9 #include "src/ic/ic-compiler.h"
11 10
12 namespace v8 { 11 namespace v8 {
13 namespace internal { 12 namespace internal {
14 13
15 #define __ ACCESS_MASM(masm) 14 #define __ ACCESS_MASM(masm)
16 15
16 void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
17 StrictMode strict_mode) {
18 ASM_LOCATION("PropertyICCompiler::GenerateRuntimeSetProperty");
17 19
18 void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup( 20 __ Push(StoreIC::ReceiverRegister(), StoreIC::NameRegister(),
19 MacroAssembler* masm, Label* miss_label, Register receiver, 21 StoreIC::ValueRegister());
20 Handle<Name> name, Register scratch0, Register scratch1) {
21 DCHECK(!AreAliased(receiver, scratch0, scratch1));
22 DCHECK(name->IsUniqueName());
23 Counters* counters = masm->isolate()->counters();
24 __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
25 __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
26 22
27 Label done; 23 __ Mov(x10, Smi::FromInt(strict_mode));
24 __ Push(x10);
28 25
29 const int kInterceptorOrAccessCheckNeededMask = 26 // Do tail-call to runtime routine.
30 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded); 27 __ TailCallRuntime(Runtime::kSetProperty, 4, 1);
31
32 // Bail out if the receiver has a named interceptor or requires access checks.
33 Register map = scratch1;
34 __ Ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
35 __ Ldrb(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
36 __ Tst(scratch0, kInterceptorOrAccessCheckNeededMask);
37 __ B(ne, miss_label);
38
39 // Check that receiver is a JSObject.
40 __ Ldrb(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
41 __ Cmp(scratch0, FIRST_SPEC_OBJECT_TYPE);
42 __ B(lt, miss_label);
43
44 // Load properties array.
45 Register properties = scratch0;
46 __ Ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
47 // Check that the properties array is a dictionary.
48 __ Ldr(map, FieldMemOperand(properties, HeapObject::kMapOffset));
49 __ JumpIfNotRoot(map, Heap::kHashTableMapRootIndex, miss_label);
50
51 NameDictionaryLookupStub::GenerateNegativeLookup(
52 masm, miss_label, &done, receiver, properties, name, scratch1);
53 __ Bind(&done);
54 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
55 } 28 }
56 29
57 30
58 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
59 MacroAssembler* masm, int index, Register prototype, Label* miss) {
60 Isolate* isolate = masm->isolate();
61 // Get the global function with the given index.
62 Handle<JSFunction> function(
63 JSFunction::cast(isolate->native_context()->get(index)));
64
65 // Check we're still in the same context.
66 Register scratch = prototype;
67 __ Ldr(scratch, GlobalObjectMemOperand());
68 __ Ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
69 __ Ldr(scratch, ContextMemOperand(scratch, index));
70 __ Cmp(scratch, Operand(function));
71 __ B(ne, miss);
72
73 // Load its initial map. The global functions all have initial maps.
74 __ Mov(prototype, Operand(Handle<Map>(function->initial_map())));
75 // Load the prototype from the initial map.
76 __ Ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
77 }
78
79
80 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
81 MacroAssembler* masm, Register receiver, Register scratch1,
82 Register scratch2, Label* miss_label) {
83 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
84 // TryGetFunctionPrototype can't put the result directly in x0 because the
85 // 3 inputs registers can't alias and we call this function from
86 // LoadIC::GenerateFunctionPrototype, where receiver is x0. So we explicitly
87 // move the result in x0.
88 __ Mov(x0, scratch1);
89 __ Ret();
90 }
91
92
93 // Generate code to check that a global property cell is empty. Create
94 // the property cell at compilation time if no cell exists for the
95 // property.
96 void PropertyHandlerCompiler::GenerateCheckPropertyCell(
97 MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
98 Register scratch, Label* miss) {
99 Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
100 DCHECK(cell->value()->IsTheHole());
101 __ Mov(scratch, Operand(cell));
102 __ Ldr(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
103 __ JumpIfNotRoot(scratch, Heap::kTheHoleValueRootIndex, miss);
104 }
105
106
107 static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
108 Register holder, Register name,
109 Handle<JSObject> holder_obj) {
110 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
111 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
112 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
113 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
114 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
115
116 __ Push(name);
117 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
118 DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
119 Register scratch = name;
120 __ Mov(scratch, Operand(interceptor));
121 __ Push(scratch, receiver, holder);
122 }
123
124
125 static void CompileCallLoadPropertyWithInterceptor(
126 MacroAssembler* masm, Register receiver, Register holder, Register name,
127 Handle<JSObject> holder_obj, IC::UtilityId id) {
128 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
129
130 __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
131 NamedLoadHandlerCompiler::kInterceptorArgsLength);
132 }
133
134
135 // Generate call to api function.
136 void PropertyHandlerCompiler::GenerateFastApiCall(
137 MacroAssembler* masm, const CallOptimization& optimization,
138 Handle<Map> receiver_map, Register receiver, Register scratch,
139 bool is_store, int argc, Register* values) {
140 DCHECK(!AreAliased(receiver, scratch));
141
142 MacroAssembler::PushPopQueue queue(masm);
143 queue.Queue(receiver);
144 // Write the arguments to the stack frame.
145 for (int i = 0; i < argc; i++) {
146 Register arg = values[argc - 1 - i];
147 DCHECK(!AreAliased(receiver, scratch, arg));
148 queue.Queue(arg);
149 }
150 queue.PushQueued();
151
152 DCHECK(optimization.is_simple_api_call());
153
154 // Abi for CallApiFunctionStub.
155 Register callee = x0;
156 Register call_data = x4;
157 Register holder = x2;
158 Register api_function_address = x1;
159
160 // Put holder in place.
161 CallOptimization::HolderLookup holder_lookup;
162 Handle<JSObject> api_holder =
163 optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
164 switch (holder_lookup) {
165 case CallOptimization::kHolderIsReceiver:
166 __ Mov(holder, receiver);
167 break;
168 case CallOptimization::kHolderFound:
169 __ LoadObject(holder, api_holder);
170 break;
171 case CallOptimization::kHolderNotFound:
172 UNREACHABLE();
173 break;
174 }
175
176 Isolate* isolate = masm->isolate();
177 Handle<JSFunction> function = optimization.constant_function();
178 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
179 Handle<Object> call_data_obj(api_call_info->data(), isolate);
180
181 // Put callee in place.
182 __ LoadObject(callee, function);
183
184 bool call_data_undefined = false;
185 // Put call_data in place.
186 if (isolate->heap()->InNewSpace(*call_data_obj)) {
187 __ LoadObject(call_data, api_call_info);
188 __ Ldr(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset));
189 } else if (call_data_obj->IsUndefined()) {
190 call_data_undefined = true;
191 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
192 } else {
193 __ LoadObject(call_data, call_data_obj);
194 }
195
196 // Put api_function_address in place.
197 Address function_address = v8::ToCData<Address>(api_call_info->callback());
198 ApiFunction fun(function_address);
199 ExternalReference ref = ExternalReference(
200 &fun, ExternalReference::DIRECT_API_CALL, masm->isolate());
201 __ Mov(api_function_address, ref);
202
203 // Jump to stub.
204 CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
205 __ TailCallStub(&stub);
206 }
207
208
209 #undef __
210 #define __ ACCESS_MASM(masm())
211
212
213 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
214 Handle<Name> name) {
215 if (!label->is_unused()) {
216 __ Bind(label);
217 __ Mov(this->name(), Operand(name));
218 }
219 }
220
221
222 // Generate StoreTransition code, value is passed in x0 register.
223 // When leaving generated code after success, the receiver_reg and storage_reg
224 // may be clobbered. Upon branch to miss_label, the receiver and name registers
225 // have their original values.
226 void NamedStoreHandlerCompiler::GenerateStoreTransition(
227 Handle<Map> transition, Handle<Name> name, Register receiver_reg,
228 Register storage_reg, Register value_reg, Register scratch1,
229 Register scratch2, Register scratch3, Label* miss_label, Label* slow) {
230 Label exit;
231
232 DCHECK(!AreAliased(receiver_reg, storage_reg, value_reg, scratch1, scratch2,
233 scratch3));
234
235 // We don't need scratch3.
236 scratch3 = NoReg;
237
238 int descriptor = transition->LastAdded();
239 DescriptorArray* descriptors = transition->instance_descriptors();
240 PropertyDetails details = descriptors->GetDetails(descriptor);
241 Representation representation = details.representation();
242 DCHECK(!representation.IsNone());
243
244 if (details.type() == CONSTANT) {
245 Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
246 __ LoadObject(scratch1, constant);
247 __ Cmp(value_reg, scratch1);
248 __ B(ne, miss_label);
249 } else if (representation.IsSmi()) {
250 __ JumpIfNotSmi(value_reg, miss_label);
251 } else if (representation.IsHeapObject()) {
252 __ JumpIfSmi(value_reg, miss_label);
253 HeapType* field_type = descriptors->GetFieldType(descriptor);
254 HeapType::Iterator<Map> it = field_type->Classes();
255 if (!it.Done()) {
256 __ Ldr(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
257 Label do_store;
258 while (true) {
259 __ CompareMap(scratch1, it.Current());
260 it.Advance();
261 if (it.Done()) {
262 __ B(ne, miss_label);
263 break;
264 }
265 __ B(eq, &do_store);
266 }
267 __ Bind(&do_store);
268 }
269 } else if (representation.IsDouble()) {
270 UseScratchRegisterScope temps(masm());
271 DoubleRegister temp_double = temps.AcquireD();
272 __ SmiUntagToDouble(temp_double, value_reg, kSpeculativeUntag);
273
274 Label do_store;
275 __ JumpIfSmi(value_reg, &do_store);
276
277 __ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex, miss_label,
278 DONT_DO_SMI_CHECK);
279 __ Ldr(temp_double, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
280
281 __ Bind(&do_store);
282 __ AllocateHeapNumber(storage_reg, slow, scratch1, scratch2, temp_double,
283 NoReg, MUTABLE);
284 }
285
286 // Stub never generated for objects that require access checks.
287 DCHECK(!transition->is_access_check_needed());
288
289 // Perform map transition for the receiver if necessary.
290 if (details.type() == FIELD &&
291 Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
292 // The properties must be extended before we can store the value.
293 // We jump to a runtime call that extends the properties array.
294 __ Mov(scratch1, Operand(transition));
295 __ Push(receiver_reg, scratch1, value_reg);
296 __ TailCallExternalReference(
297 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
298 isolate()),
299 3, 1);
300 return;
301 }
302
303 // Update the map of the object.
304 __ Mov(scratch1, Operand(transition));
305 __ Str(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
306
307 // Update the write barrier for the map field.
308 __ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
309 kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET,
310 OMIT_SMI_CHECK);
311
312 if (details.type() == CONSTANT) {
313 DCHECK(value_reg.is(x0));
314 __ Ret();
315 return;
316 }
317
318 int index = transition->instance_descriptors()->GetFieldIndex(
319 transition->LastAdded());
320
321 // Adjust for the number of properties stored in the object. Even in the
322 // face of a transition we can use the old map here because the size of the
323 // object and the number of in-object properties is not going to change.
324 index -= transition->inobject_properties();
325
326 // TODO(verwaest): Share this code as a code stub.
327 SmiCheck smi_check =
328 representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
329 Register prop_reg = representation.IsDouble() ? storage_reg : value_reg;
330 if (index < 0) {
331 // Set the property straight into the object.
332 int offset = transition->instance_size() + (index * kPointerSize);
333 __ Str(prop_reg, FieldMemOperand(receiver_reg, offset));
334
335 if (!representation.IsSmi()) {
336 // Update the write barrier for the array address.
337 if (!representation.IsDouble()) {
338 __ Mov(storage_reg, value_reg);
339 }
340 __ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
341 kLRHasNotBeenSaved, kDontSaveFPRegs,
342 EMIT_REMEMBERED_SET, smi_check);
343 }
344 } else {
345 // Write to the properties array.
346 int offset = index * kPointerSize + FixedArray::kHeaderSize;
347 // Get the properties array
348 __ Ldr(scratch1,
349 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
350 __ Str(prop_reg, FieldMemOperand(scratch1, offset));
351
352 if (!representation.IsSmi()) {
353 // Update the write barrier for the array address.
354 if (!representation.IsDouble()) {
355 __ Mov(storage_reg, value_reg);
356 }
357 __ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
358 kLRHasNotBeenSaved, kDontSaveFPRegs,
359 EMIT_REMEMBERED_SET, smi_check);
360 }
361 }
362
363 __ Bind(&exit);
364 // Return the value (register x0).
365 DCHECK(value_reg.is(x0));
366 __ Ret();
367 }
368
369
370 void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
371 Register value_reg,
372 Label* miss_label) {
373 DCHECK(lookup->representation().IsHeapObject());
374 __ JumpIfSmi(value_reg, miss_label);
375 HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
376 __ Ldr(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset));
377 Label do_store;
378 while (true) {
379 __ CompareMap(scratch1(), it.Current());
380 it.Advance();
381 if (it.Done()) {
382 __ B(ne, miss_label);
383 break;
384 }
385 __ B(eq, &do_store);
386 }
387 __ Bind(&do_store);
388
389 StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
390 lookup->representation());
391 GenerateTailCall(masm(), stub.GetCode());
392 }
393
394
395 Register PropertyHandlerCompiler::CheckPrototypes(
396 Register object_reg, Register holder_reg, Register scratch1,
397 Register scratch2, Handle<Name> name, Label* miss,
398 PrototypeCheckType check) {
399 Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
400
401 // object_reg and holder_reg registers can alias.
402 DCHECK(!AreAliased(object_reg, scratch1, scratch2));
403 DCHECK(!AreAliased(holder_reg, scratch1, scratch2));
404
405 // Keep track of the current object in register reg.
406 Register reg = object_reg;
407 int depth = 0;
408
409 Handle<JSObject> current = Handle<JSObject>::null();
410 if (type()->IsConstant()) {
411 current = Handle<JSObject>::cast(type()->AsConstant()->Value());
412 }
413 Handle<JSObject> prototype = Handle<JSObject>::null();
414 Handle<Map> current_map = receiver_map;
415 Handle<Map> holder_map(holder()->map());
416 // Traverse the prototype chain and check the maps in the prototype chain for
417 // fast and global objects or do negative lookup for normal objects.
418 while (!current_map.is_identical_to(holder_map)) {
419 ++depth;
420
421 // Only global objects and objects that do not require access
422 // checks are allowed in stubs.
423 DCHECK(current_map->IsJSGlobalProxyMap() ||
424 !current_map->is_access_check_needed());
425
426 prototype = handle(JSObject::cast(current_map->prototype()));
427 if (current_map->is_dictionary_map() &&
428 !current_map->IsJSGlobalObjectMap()) {
429 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
430 if (!name->IsUniqueName()) {
431 DCHECK(name->IsString());
432 name = factory()->InternalizeString(Handle<String>::cast(name));
433 }
434 DCHECK(current.is_null() || (current->property_dictionary()->FindEntry(
435 name) == NameDictionary::kNotFound));
436
437 GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
438 scratch2);
439
440 __ Ldr(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
441 reg = holder_reg; // From now on the object will be in holder_reg.
442 __ Ldr(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
443 } else {
444 // Two possible reasons for loading the prototype from the map:
445 // (1) Can't store references to new space in code.
446 // (2) Handler is shared for all receivers with the same prototype
447 // map (but not necessarily the same prototype instance).
448 bool load_prototype_from_map =
449 heap()->InNewSpace(*prototype) || depth == 1;
450 Register map_reg = scratch1;
451 __ Ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
452
453 if (depth != 1 || check == CHECK_ALL_MAPS) {
454 __ CheckMap(map_reg, current_map, miss, DONT_DO_SMI_CHECK);
455 }
456
457 // Check access rights to the global object. This has to happen after
458 // the map check so that we know that the object is actually a global
459 // object.
460 // This allows us to install generated handlers for accesses to the
461 // global proxy (as opposed to using slow ICs). See corresponding code
462 // in LookupForRead().
463 if (current_map->IsJSGlobalProxyMap()) {
464 UseScratchRegisterScope temps(masm());
465 __ CheckAccessGlobalProxy(reg, scratch2, temps.AcquireX(), miss);
466 } else if (current_map->IsJSGlobalObjectMap()) {
467 GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
468 name, scratch2, miss);
469 }
470
471 reg = holder_reg; // From now on the object will be in holder_reg.
472
473 if (load_prototype_from_map) {
474 __ Ldr(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
475 } else {
476 __ Mov(reg, Operand(prototype));
477 }
478 }
479
480 // Go to the next object in the prototype chain.
481 current = prototype;
482 current_map = handle(current->map());
483 }
484
485 // Log the check depth.
486 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
487
488 // Check the holder map.
489 if (depth != 0 || check == CHECK_ALL_MAPS) {
490 // Check the holder map.
491 __ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK);
492 }
493
494 // Perform security check for access to the global object.
495 DCHECK(current_map->IsJSGlobalProxyMap() ||
496 !current_map->is_access_check_needed());
497 if (current_map->IsJSGlobalProxyMap()) {
498 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
499 }
500
501 // Return the register containing the holder.
502 return reg;
503 }
504
505
506 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
507 if (!miss->is_unused()) {
508 Label success;
509 __ B(&success);
510
511 __ Bind(miss);
512 TailCallBuiltin(masm(), MissBuiltin(kind()));
513
514 __ Bind(&success);
515 }
516 }
517
518
519 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
520 if (!miss->is_unused()) {
521 Label success;
522 __ B(&success);
523
524 GenerateRestoreName(miss, name);
525 TailCallBuiltin(masm(), MissBuiltin(kind()));
526
527 __ Bind(&success);
528 }
529 }
530
531
532 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
533 // Return the constant value.
534 __ LoadObject(x0, value);
535 __ Ret();
536 }
537
538
539 void NamedLoadHandlerCompiler::GenerateLoadCallback(
540 Register reg, Handle<ExecutableAccessorInfo> callback) {
541 DCHECK(!AreAliased(scratch2(), scratch3(), scratch4(), reg));
542
543 // Build ExecutableAccessorInfo::args_ list on the stack and push property
544 // name below the exit frame to make GC aware of them and store pointers to
545 // them.
546 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
547 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
548 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
549 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
550 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
551 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
552 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
553
554 __ Push(receiver());
555
556 if (heap()->InNewSpace(callback->data())) {
557 __ Mov(scratch3(), Operand(callback));
558 __ Ldr(scratch3(),
559 FieldMemOperand(scratch3(), ExecutableAccessorInfo::kDataOffset));
560 } else {
561 __ Mov(scratch3(), Operand(Handle<Object>(callback->data(), isolate())));
562 }
563 __ LoadRoot(scratch4(), Heap::kUndefinedValueRootIndex);
564 __ Mov(scratch2(), Operand(ExternalReference::isolate_address(isolate())));
565 __ Push(scratch3(), scratch4(), scratch4(), scratch2(), reg, name());
566
567 Register args_addr = scratch2();
568 __ Add(args_addr, __ StackPointer(), kPointerSize);
569
570 // Stack at this point:
571 // sp[40] callback data
572 // sp[32] undefined
573 // sp[24] undefined
574 // sp[16] isolate
575 // args_addr -> sp[8] reg
576 // sp[0] name
577
578 // Abi for CallApiGetter.
579 Register getter_address_reg = x2;
580
581 // Set up the call.
582 Address getter_address = v8::ToCData<Address>(callback->getter());
583 ApiFunction fun(getter_address);
584 ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
585 ExternalReference ref = ExternalReference(&fun, type, isolate());
586 __ Mov(getter_address_reg, ref);
587
588 CallApiGetterStub stub(isolate());
589 __ TailCallStub(&stub);
590 }
591
592
593 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
594 LookupIterator* it, Register holder_reg) {
595 DCHECK(!AreAliased(receiver(), this->name(), scratch1(), scratch2(),
596 scratch3()));
597 DCHECK(holder()->HasNamedInterceptor());
598 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
599
600 // Compile the interceptor call, followed by inline code to load the
601 // property from further up the prototype chain if the call fails.
602 // Check that the maps haven't changed.
603 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
604
605 // Preserve the receiver register explicitly whenever it is different from the
606 // holder and it is needed should the interceptor return without any result.
607 // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
608 // case might cause a miss during the prototype check.
609 bool must_perform_prototype_check =
610 !holder().is_identical_to(it->GetHolder<JSObject>());
611 bool must_preserve_receiver_reg =
612 !receiver().is(holder_reg) &&
613 (it->property_kind() == LookupIterator::ACCESSOR ||
614 must_perform_prototype_check);
615
616 // Save necessary data before invoking an interceptor.
617 // Requires a frame to make GC aware of pushed pointers.
618 {
619 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
620 if (must_preserve_receiver_reg) {
621 __ Push(receiver(), holder_reg, this->name());
622 } else {
623 __ Push(holder_reg, this->name());
624 }
625 // Invoke an interceptor. Note: map checks from receiver to
626 // interceptor's holder has been compiled before (see a caller
627 // of this method.)
628 CompileCallLoadPropertyWithInterceptor(
629 masm(), receiver(), holder_reg, this->name(), holder(),
630 IC::kLoadPropertyWithInterceptorOnly);
631
632 // Check if interceptor provided a value for property. If it's
633 // the case, return immediately.
634 Label interceptor_failed;
635 __ JumpIfRoot(x0, Heap::kNoInterceptorResultSentinelRootIndex,
636 &interceptor_failed);
637 frame_scope.GenerateLeaveFrame();
638 __ Ret();
639
640 __ Bind(&interceptor_failed);
641 if (must_preserve_receiver_reg) {
642 __ Pop(this->name(), holder_reg, receiver());
643 } else {
644 __ Pop(this->name(), holder_reg);
645 }
646 // Leave the internal frame.
647 }
648
649 GenerateLoadPostInterceptor(it, holder_reg);
650 }
651
652
653 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
654 // Call the runtime system to load the interceptor.
655 DCHECK(holder()->HasNamedInterceptor());
656 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
657 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
658 holder());
659
660 ExternalReference ref = ExternalReference(
661 IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
662 __ TailCallExternalReference(
663 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
664 }
665
666
667 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
668 Handle<JSObject> object, Handle<Name> name,
669 Handle<ExecutableAccessorInfo> callback) {
670 ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreCallback");
671 Register holder_reg = Frontend(receiver(), name);
672
673 // Stub never generated for non-global objects that require access checks.
674 DCHECK(holder()->IsJSGlobalProxy() || !holder()->IsAccessCheckNeeded());
675
676 // receiver() and holder_reg can alias.
677 DCHECK(!AreAliased(receiver(), scratch1(), scratch2(), value()));
678 DCHECK(!AreAliased(holder_reg, scratch1(), scratch2(), value()));
679 __ Mov(scratch1(), Operand(callback));
680 __ Mov(scratch2(), Operand(name));
681 __ Push(receiver(), holder_reg, scratch1(), scratch2(), 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 #undef __
694 #define __ ACCESS_MASM(masm)
695
696
697 void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
698 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
699 Handle<JSFunction> setter) {
700 // ----------- S t a t e -------------
701 // -- lr : return address
702 // -----------------------------------
703 Label miss;
704
705 {
706 FrameScope scope(masm, StackFrame::INTERNAL);
707
708 // Save value register, so we can restore it later.
709 __ Push(value());
710
711 if (!setter.is_null()) {
712 // Call the JavaScript setter with receiver and value on the stack.
713 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
714 // Swap in the global receiver.
715 __ Ldr(receiver,
716 FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
717 }
718 __ Push(receiver, value());
719 ParameterCount actual(1);
720 ParameterCount expected(setter);
721 __ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
722 NullCallWrapper());
723 } else {
724 // If we generate a global code snippet for deoptimization only, remember
725 // the place to continue after deoptimization.
726 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
727 }
728
729 // We have to return the passed value, not the return value of the setter.
730 __ Pop(x0);
731
732 // Restore context register.
733 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
734 }
735 __ Ret();
736 }
737
738
739 #undef __
740 #define __ ACCESS_MASM(masm())
741
742
743 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
744 Handle<Name> name) {
745 Label miss;
746
747 ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreInterceptor");
748
749 __ Push(receiver(), this->name(), value());
750
751 // Do tail-call to the runtime system.
752 ExternalReference store_ic_property = ExternalReference(
753 IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
754 __ TailCallExternalReference(store_ic_property, 3, 1);
755
756 // Return the generated code.
757 return GetCode(kind(), Code::FAST, name);
758 }
759
760
761 Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
762
763
764 #undef __
765 #define __ ACCESS_MASM(masm)
766
767 void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
768 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
769 Handle<JSFunction> getter) {
770 {
771 FrameScope scope(masm, StackFrame::INTERNAL);
772
773 if (!getter.is_null()) {
774 // Call the JavaScript getter with the receiver on the stack.
775 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
776 // Swap in the global receiver.
777 __ Ldr(receiver,
778 FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
779 }
780 __ Push(receiver);
781 ParameterCount actual(0);
782 ParameterCount expected(getter);
783 __ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
784 NullCallWrapper());
785 } else {
786 // If we generate a global code snippet for deoptimization only, remember
787 // the place to continue after deoptimization.
788 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
789 }
790
791 // Restore context register.
792 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
793 }
794 __ Ret();
795 }
796
797
798 #undef __ 31 #undef __
799 #define __ ACCESS_MASM(masm()) 32 #define __ ACCESS_MASM(masm())
800 33
801 34
802 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
803 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
804 Label miss;
805 FrontendHeader(receiver(), name, &miss);
806
807 // Get the value from the cell.
808 Register result = StoreIC::ValueRegister();
809 __ Mov(result, Operand(cell));
810 __ Ldr(result, FieldMemOperand(result, Cell::kValueOffset));
811
812 // Check for deleted property if property can actually be deleted.
813 if (is_configurable) {
814 __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &miss);
815 }
816
817 Counters* counters = isolate()->counters();
818 __ IncrementCounter(counters->named_load_global_stub(), 1, x1, x3);
819 __ Ret();
820
821 FrontendFooter(name, &miss);
822
823 // Return the generated code.
824 return GetCode(kind(), Code::NORMAL, name);
825 }
826
827
828 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types, 35 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
829 CodeHandleList* handlers, 36 CodeHandleList* handlers,
830 Handle<Name> name, 37 Handle<Name> name,
831 Code::StubType type, 38 Code::StubType type,
832 IcCheckType check) { 39 IcCheckType check) {
833 Label miss; 40 Label miss;
834 41
835 if (check == PROPERTY && 42 if (check == PROPERTY &&
836 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) { 43 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) {
837 // In case we are compiling an IC for dictionary loads and stores, just 44 // In case we are compiling an IC for dictionary loads and stores, just
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 } 115 }
909 116
910 __ Bind(&miss); 117 __ Bind(&miss);
911 TailCallBuiltin(masm(), MissBuiltin(kind())); 118 TailCallBuiltin(masm(), MissBuiltin(kind()));
912 119
913 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC); 120 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
914 } 121 }
915 122
916 123
917 #undef __ 124 #undef __
918 #define __ ACCESS_MASM(masm)
919
920 void ElementHandlerCompiler::GenerateLoadDictionaryElement(
921 MacroAssembler* masm) {
922 // The return address is in lr.
923 Label slow, miss;
924
925 Register result = x0;
926 Register key = LoadIC::NameRegister();
927 Register receiver = LoadIC::ReceiverRegister();
928 DCHECK(receiver.is(x1));
929 DCHECK(key.is(x2));
930
931 __ JumpIfNotSmi(key, &miss);
932 __ Ldr(x4, FieldMemOperand(receiver, JSObject::kElementsOffset));
933 __ LoadFromNumberDictionary(&slow, x4, key, result, x7, x3, x5, x6);
934 __ Ret();
935
936 __ Bind(&slow);
937 __ IncrementCounter(
938 masm->isolate()->counters()->keyed_load_external_array_slow(), 1, x4, x3);
939 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
940
941 // Miss case, call the runtime.
942 __ Bind(&miss);
943 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
944 }
945
946
947 void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
948 StrictMode strict_mode) {
949 ASM_LOCATION("PropertyICCompiler::GenerateRuntimeSetProperty");
950
951 __ Push(StoreIC::ReceiverRegister(), StoreIC::NameRegister(),
952 StoreIC::ValueRegister());
953
954 __ Mov(x10, Smi::FromInt(strict_mode));
955 __ Push(x10);
956
957 // Do tail-call to runtime routine.
958 __ TailCallRuntime(Runtime::kSetProperty, 4, 1);
959 }
960
961
962 #undef __
963 } 125 }
964 } // namespace v8::internal 126 } // namespace v8::internal
965 127
966 #endif // V8_TARGET_ARCH_ARM64 128 #endif // V8_TARGET_ARCH_ARM64
OLDNEW
« no previous file with comments | « src/ic/arm64/handler-compiler-arm64.cc ('k') | src/ic/handler-compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698