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