blob: 745b541e54311b28624ca3ac6d684ef27630b33e [file] [log] [blame]
kasperl@chromium.org71affb52009-05-26 05:44:31 +00001// Copyright 2006-2009 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
30#include "ic-inl.h"
31#include "codegen-inl.h"
32#include "stub-cache.h"
33
kasperl@chromium.org71affb52009-05-26 05:44:31 +000034namespace v8 {
35namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036
ager@chromium.org65dad4b2009-04-23 08:48:43 +000037#define __ ACCESS_MASM(masm)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000038
39
40static void ProbeTable(MacroAssembler* masm,
41 Code::Flags flags,
42 StubCache::Table table,
43 Register name,
44 Register offset) {
45 ExternalReference key_offset(SCTableReference::keyReference(table));
46 ExternalReference value_offset(SCTableReference::valueReference(table));
47
48 Label miss;
49
50 // Save the offset on the stack.
51 __ push(offset);
52
53 // Check that the key in the entry matches the name.
54 __ mov(ip, Operand(key_offset));
55 __ ldr(ip, MemOperand(ip, offset, LSL, 1));
56 __ cmp(name, Operand(ip));
57 __ b(ne, &miss);
58
59 // Get the code entry from the cache.
60 __ mov(ip, Operand(value_offset));
61 __ ldr(offset, MemOperand(ip, offset, LSL, 1));
62
63 // Check that the flags match what we're looking for.
64 __ ldr(offset, FieldMemOperand(offset, Code::kFlagsOffset));
kasperl@chromium.org71affb52009-05-26 05:44:31 +000065 __ and_(offset, offset, Operand(~Code::kFlagsNotUsedInLookup));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000066 __ cmp(offset, Operand(flags));
67 __ b(ne, &miss);
68
69 // Restore offset and re-load code entry from cache.
70 __ pop(offset);
71 __ mov(ip, Operand(value_offset));
72 __ ldr(offset, MemOperand(ip, offset, LSL, 1));
73
74 // Jump to the first instruction in the code stub.
75 __ add(offset, offset, Operand(Code::kHeaderSize - kHeapObjectTag));
76 __ Jump(offset);
77
78 // Miss: Restore offset and fall through.
79 __ bind(&miss);
80 __ pop(offset);
81}
82
83
84void StubCache::GenerateProbe(MacroAssembler* masm,
85 Code::Flags flags,
86 Register receiver,
87 Register name,
kasperl@chromium.org86f77b72009-07-06 08:21:57 +000088 Register scratch,
89 Register extra) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000090 Label miss;
91
92 // Make sure that code is valid. The shifting code relies on the
93 // entry size being 8.
94 ASSERT(sizeof(Entry) == 8);
95
96 // Make sure the flags does not name a specific type.
97 ASSERT(Code::ExtractTypeFromFlags(flags) == 0);
98
99 // Make sure that there are no register conflicts.
100 ASSERT(!scratch.is(receiver));
101 ASSERT(!scratch.is(name));
102
103 // Check that the receiver isn't a smi.
104 __ tst(receiver, Operand(kSmiTagMask));
105 __ b(eq, &miss);
106
107 // Get the map of the receiver and compute the hash.
ager@chromium.org7c537e22008-10-16 08:43:32 +0000108 __ ldr(scratch, FieldMemOperand(name, String::kLengthOffset));
109 __ ldr(ip, FieldMemOperand(receiver, HeapObject::kMapOffset));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000110 __ add(scratch, scratch, Operand(ip));
111 __ eor(scratch, scratch, Operand(flags));
112 __ and_(scratch,
113 scratch,
114 Operand((kPrimaryTableSize - 1) << kHeapObjectTagSize));
115
116 // Probe the primary table.
117 ProbeTable(masm, flags, kPrimary, name, scratch);
118
119 // Primary miss: Compute hash for secondary probe.
120 __ sub(scratch, scratch, Operand(name));
121 __ add(scratch, scratch, Operand(flags));
122 __ and_(scratch,
123 scratch,
124 Operand((kSecondaryTableSize - 1) << kHeapObjectTagSize));
125
126 // Probe the secondary table.
127 ProbeTable(masm, flags, kSecondary, name, scratch);
128
129 // Cache miss: Fall-through and let caller handle the miss by
130 // entering the runtime system.
131 __ bind(&miss);
132}
133
134
135void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm,
136 int index,
137 Register prototype) {
138 // Load the global or builtins object from the current context.
139 __ ldr(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
140 // Load the global context from the global or builtins object.
141 __ ldr(prototype,
142 FieldMemOperand(prototype, GlobalObject::kGlobalContextOffset));
143 // Load the function from the global context.
144 __ ldr(prototype, MemOperand(prototype, Context::SlotOffset(index)));
145 // Load the initial map. The global functions all have initial maps.
146 __ ldr(prototype,
147 FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset));
148 // Load the prototype from the initial map.
149 __ ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
150}
151
152
ager@chromium.org7c537e22008-10-16 08:43:32 +0000153// Load a fast property out of a holder object (src). In-object properties
154// are loaded directly otherwise the property is loaded from the properties
155// fixed array.
156void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm,
157 Register dst, Register src,
158 JSObject* holder, int index) {
159 // Adjust for the number of properties stored in the holder.
160 index -= holder->map()->inobject_properties();
161 if (index < 0) {
162 // Get the property straight out of the holder.
163 int offset = holder->map()->instance_size() + (index * kPointerSize);
164 __ ldr(dst, FieldMemOperand(src, offset));
165 } else {
166 // Calculate the offset into the properties array.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000167 int offset = index * kPointerSize + FixedArray::kHeaderSize;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000168 __ ldr(dst, FieldMemOperand(src, JSObject::kPropertiesOffset));
169 __ ldr(dst, FieldMemOperand(dst, offset));
170 }
171}
172
173
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000174void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm,
175 Register receiver,
176 Register scratch,
177 Label* miss_label) {
178 // Check that the receiver isn't a smi.
179 __ tst(receiver, Operand(kSmiTagMask));
180 __ b(eq, miss_label);
181
182 // Check that the object is a JS array.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000183 __ CompareObjectType(receiver, scratch, scratch, JS_ARRAY_TYPE);
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000184 __ b(ne, miss_label);
185
186 // Load length directly from the JS array.
187 __ ldr(r0, FieldMemOperand(receiver, JSArray::kLengthOffset));
188 __ Ret();
189}
190
191
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000192// Generate code to check if an object is a string. If the object is
193// a string, the map's instance type is left in the scratch1 register.
194static void GenerateStringCheck(MacroAssembler* masm,
195 Register receiver,
196 Register scratch1,
197 Register scratch2,
198 Label* smi,
199 Label* non_string_object) {
200 // Check that the receiver isn't a smi.
201 __ tst(receiver, Operand(kSmiTagMask));
202 __ b(eq, smi);
203
204 // Check that the object is a string.
205 __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
206 __ ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
207 __ and_(scratch2, scratch1, Operand(kIsNotStringMask));
208 // The cast is to resolve the overload for the argument of 0x0.
209 __ cmp(scratch2, Operand(static_cast<int32_t>(kStringTag)));
210 __ b(ne, non_string_object);
211}
212
213
ager@chromium.org32912102009-01-16 10:38:43 +0000214// Generate code to load the length from a string object and return the length.
215// If the receiver object is not a string or a wrapped string object the
216// execution continues at the miss label. The register containing the
217// receiver is potentially clobbered.
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000218void StubCompiler::GenerateLoadStringLength2(MacroAssembler* masm,
219 Register receiver,
220 Register scratch1,
221 Register scratch2,
222 Label* miss) {
ager@chromium.org32912102009-01-16 10:38:43 +0000223 Label check_string, check_wrapper;
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000224
ager@chromium.org32912102009-01-16 10:38:43 +0000225 __ bind(&check_string);
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000226 // Check if the object is a string leaving the instance type in the
227 // scratch1 register.
228 GenerateStringCheck(masm, receiver, scratch1, scratch2,
229 miss, &check_wrapper);
230
231 // Load length directly from the string.
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000232 __ and_(scratch1, scratch1, Operand(kStringSizeMask));
233 __ add(scratch1, scratch1, Operand(String::kHashShift));
234 __ ldr(r0, FieldMemOperand(receiver, String::kLengthOffset));
235 __ mov(r0, Operand(r0, LSR, scratch1));
236 __ mov(r0, Operand(r0, LSL, kSmiTagSize));
237 __ Ret();
238
239 // Check if the object is a JSValue wrapper.
240 __ bind(&check_wrapper);
241 __ cmp(scratch1, Operand(JS_VALUE_TYPE));
242 __ b(ne, miss);
243
ager@chromium.org32912102009-01-16 10:38:43 +0000244 // Unwrap the value in place and check if the wrapped value is a string.
245 __ ldr(receiver, FieldMemOperand(receiver, JSValue::kValueOffset));
246 __ b(&check_string);
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000247}
248
249
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000250void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm,
251 Register receiver,
252 Register scratch1,
253 Register scratch2,
254 Label* miss_label) {
255 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
256 __ mov(r0, scratch1);
257 __ Ret();
258}
259
260
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000261// Generate StoreField code, value is passed in r0 register.
262// After executing generated code, the receiver_reg and name_reg
263// may be clobbered.
264void StubCompiler::GenerateStoreField(MacroAssembler* masm,
265 Builtins::Name storage_extend,
266 JSObject* object,
267 int index,
268 Map* transition,
269 Register receiver_reg,
270 Register name_reg,
271 Register scratch,
272 Label* miss_label) {
273 // r0 : value
274 Label exit;
275
276 // Check that the receiver isn't a smi.
277 __ tst(receiver_reg, Operand(kSmiTagMask));
278 __ b(eq, miss_label);
279
280 // Check that the map of the receiver hasn't changed.
281 __ ldr(scratch, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
282 __ cmp(scratch, Operand(Handle<Map>(object->map())));
283 __ b(ne, miss_label);
284
285 // Perform global security token check if needed.
286 if (object->IsJSGlobalProxy()) {
287 __ CheckAccessGlobalProxy(receiver_reg, scratch, miss_label);
288 }
289
290 // Stub never generated for non-global objects that require access
291 // checks.
292 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
293
294 // Perform map transition for the receiver if necessary.
295 if ((transition != NULL) && (object->map()->unused_property_fields() == 0)) {
296 // The properties must be extended before we can store the value.
ager@chromium.org32912102009-01-16 10:38:43 +0000297 // We jump to a runtime call that extends the properties array.
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000298 __ mov(r2, Operand(Handle<Map>(transition)));
299 // Please note, if we implement keyed store for arm we need
300 // to call the Builtins::KeyedStoreIC_ExtendStorage.
301 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_ExtendStorage));
302 __ Jump(ic, RelocInfo::CODE_TARGET);
303 return;
304 }
305
306 if (transition != NULL) {
307 // Update the map of the object; no write barrier updating is
308 // needed because the map is never in new space.
309 __ mov(ip, Operand(Handle<Map>(transition)));
310 __ str(ip, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
311 }
312
313 // Adjust for the number of properties stored in the object. Even in the
314 // face of a transition we can use the old map here because the size of the
315 // object and the number of in-object properties is not going to change.
316 index -= object->map()->inobject_properties();
317
318 if (index < 0) {
319 // Set the property straight into the object.
320 int offset = object->map()->instance_size() + (index * kPointerSize);
321 __ str(r0, FieldMemOperand(receiver_reg, offset));
322
323 // Skip updating write barrier if storing a smi.
324 __ tst(r0, Operand(kSmiTagMask));
325 __ b(eq, &exit);
326
327 // Update the write barrier for the array address.
328 // Pass the value being stored in the now unused name_reg.
329 __ mov(name_reg, Operand(offset));
330 __ RecordWrite(receiver_reg, name_reg, scratch);
331 } else {
332 // Write to the properties array.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000333 int offset = index * kPointerSize + FixedArray::kHeaderSize;
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000334 // Get the properties array
335 __ ldr(scratch, FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
336 __ str(r0, FieldMemOperand(scratch, offset));
337
338 // Skip updating write barrier if storing a smi.
339 __ tst(r0, Operand(kSmiTagMask));
340 __ b(eq, &exit);
341
342 // Update the write barrier for the array address.
343 // Ok to clobber receiver_reg and name_reg, since we return.
344 __ mov(name_reg, Operand(offset));
345 __ RecordWrite(scratch, name_reg, receiver_reg);
346 }
347
348 // Return the value (register r0).
349 __ bind(&exit);
350 __ Ret();
351}
352
353
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000354void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) {
355 ASSERT(kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC);
356 Code* code = NULL;
357 if (kind == Code::LOAD_IC) {
358 code = Builtins::builtin(Builtins::LoadIC_Miss);
359 } else {
360 code = Builtins::builtin(Builtins::KeyedLoadIC_Miss);
361 }
362
363 Handle<Code> ic(code);
364 __ Jump(ic, RelocInfo::CODE_TARGET);
365}
366
367
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000368#undef __
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000369#define __ ACCESS_MASM(masm())
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000370
371
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000372Register StubCompiler::CheckPrototypes(JSObject* object,
373 Register object_reg,
374 JSObject* holder,
375 Register holder_reg,
376 Register scratch,
377 String* name,
378 Label* miss) {
379 // Check that the maps haven't changed.
380 Register result =
381 masm()->CheckMaps(object, object_reg, holder, holder_reg, scratch, miss);
382
383 // If we've skipped any global objects, it's not enough to verify
384 // that their maps haven't changed.
385 while (object != holder) {
386 if (object->IsGlobalObject()) {
387 GlobalObject* global = GlobalObject::cast(object);
388 Object* probe = global->EnsurePropertyCell(name);
389 if (probe->IsFailure()) {
390 set_failure(Failure::cast(probe));
391 return result;
392 }
393 JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(probe);
394 ASSERT(cell->value()->IsTheHole());
395 __ mov(scratch, Operand(Handle<Object>(cell)));
396 __ ldr(scratch,
397 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000398 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
399 __ cmp(scratch, ip);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000400 __ b(ne, miss);
401 }
402 object = JSObject::cast(object->GetPrototype());
403 }
404
405 // Return the register containin the holder.
406 return result;
407}
408
409
410void StubCompiler::GenerateLoadField(JSObject* object,
411 JSObject* holder,
412 Register receiver,
413 Register scratch1,
414 Register scratch2,
415 int index,
416 String* name,
417 Label* miss) {
418 // Check that the receiver isn't a smi.
419 __ tst(receiver, Operand(kSmiTagMask));
420 __ b(eq, miss);
421
422 // Check that the maps haven't changed.
423 Register reg =
424 CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss);
425 GenerateFastPropertyLoad(masm(), r0, reg, holder, index);
426 __ Ret();
427}
428
429
430void StubCompiler::GenerateLoadConstant(JSObject* object,
431 JSObject* holder,
432 Register receiver,
433 Register scratch1,
434 Register scratch2,
435 Object* value,
436 String* name,
437 Label* miss) {
438 // Check that the receiver isn't a smi.
439 __ tst(receiver, Operand(kSmiTagMask));
440 __ b(eq, miss);
441
442 // Check that the maps haven't changed.
443 Register reg =
444 CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss);
445
446 // Return the constant value.
447 __ mov(r0, Operand(Handle<Object>(value)));
448 __ Ret();
449}
450
451
452void StubCompiler::GenerateLoadCallback(JSObject* object,
453 JSObject* holder,
454 Register receiver,
455 Register name_reg,
456 Register scratch1,
457 Register scratch2,
458 AccessorInfo* callback,
459 String* name,
460 Label* miss) {
461 // Check that the receiver isn't a smi.
462 __ tst(receiver, Operand(kSmiTagMask));
463 __ b(eq, miss);
464
465 // Check that the maps haven't changed.
466 Register reg =
467 CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss);
468
469 // Push the arguments on the JS stack of the caller.
470 __ push(receiver); // receiver
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000471 __ push(reg); // holder
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000472 __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback data
473 __ push(ip);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000474 __ ldr(reg, FieldMemOperand(ip, AccessorInfo::kDataOffset));
475 __ push(reg);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000476 __ push(name_reg); // name
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000477
478 // Do tail-call to the runtime system.
479 ExternalReference load_callback_property =
480 ExternalReference(IC_Utility(IC::kLoadCallbackProperty));
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000481 __ TailCallRuntime(load_callback_property, 5);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000482}
483
484
485void StubCompiler::GenerateLoadInterceptor(JSObject* object,
486 JSObject* holder,
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000487 LookupResult* lookup,
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000488 Register receiver,
489 Register name_reg,
490 Register scratch1,
491 Register scratch2,
492 String* name,
493 Label* miss) {
494 // Check that the receiver isn't a smi.
495 __ tst(receiver, Operand(kSmiTagMask));
496 __ b(eq, miss);
497
498 // Check that the maps haven't changed.
499 Register reg =
500 CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss);
501
502 // Push the arguments on the JS stack of the caller.
503 __ push(receiver); // receiver
504 __ push(reg); // holder
505 __ push(name_reg); // name
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000506
507 InterceptorInfo* interceptor = holder->GetNamedInterceptor();
508 ASSERT(!Heap::InNewSpace(interceptor));
509 __ mov(scratch1, Operand(Handle<Object>(interceptor)));
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000510 __ push(scratch1);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000511 __ ldr(scratch2, FieldMemOperand(scratch1, InterceptorInfo::kDataOffset));
512 __ push(scratch2);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000513
514 // Do tail-call to the runtime system.
515 ExternalReference load_ic_property =
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000516 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorForLoad));
517 __ TailCallRuntime(load_ic_property, 5);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000518}
519
520
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000521Object* StubCompiler::CompileLazyCompile(Code::Flags flags) {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000522 // ----------- S t a t e -------------
523 // -- r1: function
524 // -- lr: return address
525 // -----------------------------------
526
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000527 // Enter an internal frame.
528 __ EnterInternalFrame();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000529
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000530 // Preserve the function.
531 __ push(r1);
532
533 // Push the function on the stack as the argument to the runtime function.
534 __ push(r1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000535 __ CallRuntime(Runtime::kLazyCompile, 1);
536
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000537 // Calculate the entry point.
538 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000539
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000540 // Restore saved function.
541 __ pop(r1);
542
543 // Tear down temporary frame.
ager@chromium.org236ad962008-09-25 09:45:57 +0000544 __ LeaveInternalFrame();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000545
546 // Do a tail-call of the compiled function.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000547 __ Jump(r2);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000548
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000549 return GetCodeWithFlags(flags, "LazyCompileStub");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000550}
551
552
553Object* CallStubCompiler::CompileCallField(Object* object,
554 JSObject* holder,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000555 int index,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000556 String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000557 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000558 // -- lr: return address
559 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000560 Label miss;
561
mads.s.ager31e71382008-08-13 09:32:07 +0000562 const int argc = arguments().immediate();
563
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000564 // Get the receiver of the function from the stack into r0.
565 __ ldr(r0, MemOperand(sp, argc * kPointerSize));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000566 // Check that the receiver isn't a smi.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000567 __ tst(r0, Operand(kSmiTagMask));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000568 __ b(eq, &miss);
569
570 // Do the right check and compute the holder register.
571 Register reg =
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000572 CheckPrototypes(JSObject::cast(object), r0, holder, r3, r2, name, &miss);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000573 GenerateFastPropertyLoad(masm(), r1, reg, holder, index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000574
575 // Check that the function really is a function.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000576 __ tst(r1, Operand(kSmiTagMask));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000577 __ b(eq, &miss);
578 // Get the map.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000579 __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000580 __ b(ne, &miss);
581
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000582 // Patch the receiver on the stack with the global proxy if
583 // necessary.
584 if (object->IsGlobalObject()) {
585 __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset));
586 __ str(r3, MemOperand(sp, argc * kPointerSize));
587 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000588
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000589 // Invoke the function.
590 __ InvokeFunction(r1, arguments(), JUMP_FUNCTION);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000591
592 // Handle call cache miss.
593 __ bind(&miss);
594 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000595 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000596
597 // Return the generated code.
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000598 return GetCode(FIELD, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000599}
600
601
602Object* CallStubCompiler::CompileCallConstant(Object* object,
603 JSObject* holder,
604 JSFunction* function,
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000605 String* name,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000606 CheckType check) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000607 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000608 // -- lr: return address
609 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000610 Label miss;
611
mads.s.ager31e71382008-08-13 09:32:07 +0000612 // Get the receiver from the stack
613 const int argc = arguments().immediate();
614 __ ldr(r1, MemOperand(sp, argc * kPointerSize));
615
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000616 // Check that the receiver isn't a smi.
617 if (check != NUMBER_CHECK) {
618 __ tst(r1, Operand(kSmiTagMask));
619 __ b(eq, &miss);
620 }
621
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000622 // Make sure that it's okay not to patch the on stack receiver
623 // unless we're doing a receiver map check.
624 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
625
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000626 switch (check) {
627 case RECEIVER_MAP_CHECK:
628 // Check that the maps haven't changed.
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000629 CheckPrototypes(JSObject::cast(object), r1, holder, r3, r2, name, &miss);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000630
631 // Patch the receiver on the stack with the global proxy if
632 // necessary.
633 if (object->IsGlobalObject()) {
634 __ ldr(r3, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset));
635 __ str(r3, MemOperand(sp, argc * kPointerSize));
636 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000637 break;
638
639 case STRING_CHECK:
640 // Check that the object is a two-byte string or a symbol.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000641 __ CompareObjectType(r1, r2, r2, FIRST_NONSTRING_TYPE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000642 __ b(hs, &miss);
643 // Check that the maps starting from the prototype haven't changed.
644 GenerateLoadGlobalFunctionPrototype(masm(),
645 Context::STRING_FUNCTION_INDEX,
646 r2);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000647 CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3,
648 r1, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000649 break;
650
651 case NUMBER_CHECK: {
652 Label fast;
653 // Check that the object is a smi or a heap number.
654 __ tst(r1, Operand(kSmiTagMask));
655 __ b(eq, &fast);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000656 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000657 __ b(ne, &miss);
658 __ bind(&fast);
659 // Check that the maps starting from the prototype haven't changed.
660 GenerateLoadGlobalFunctionPrototype(masm(),
661 Context::NUMBER_FUNCTION_INDEX,
662 r2);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000663 CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3,
664 r1, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000665 break;
666 }
667
668 case BOOLEAN_CHECK: {
669 Label fast;
670 // Check that the object is a boolean.
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000671 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
672 __ cmp(r1, ip);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000673 __ b(eq, &fast);
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000674 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
675 __ cmp(r1, ip);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000676 __ b(ne, &miss);
677 __ bind(&fast);
678 // Check that the maps starting from the prototype haven't changed.
679 GenerateLoadGlobalFunctionPrototype(masm(),
680 Context::BOOLEAN_FUNCTION_INDEX,
681 r2);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000682 CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3,
683 r1, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000684 break;
685 }
686
687 case JSARRAY_HAS_FAST_ELEMENTS_CHECK:
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000688 CheckPrototypes(JSObject::cast(object), r1, holder, r3, r2, name, &miss);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000689 // Make sure object->HasFastElements().
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000690 // Get the elements array of the object.
691 __ ldr(r3, FieldMemOperand(r1, JSObject::kElementsOffset));
692 // Check that the object is in fast mode (not dictionary).
693 __ ldr(r2, FieldMemOperand(r3, HeapObject::kMapOffset));
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000694 __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex);
695 __ cmp(r2, ip);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000696 __ b(ne, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000697 break;
698
699 default:
700 UNREACHABLE();
701 }
702
703 // Get the function and setup the context.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000704 __ mov(r1, Operand(Handle<JSFunction>(function)));
705 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000706
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000707 // Jump to the cached code (tail call).
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000708 ASSERT(function->is_compiled());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000709 Handle<Code> code(function->code());
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000710 ParameterCount expected(function->shared()->formal_parameter_count());
ager@chromium.org236ad962008-09-25 09:45:57 +0000711 __ InvokeCode(code, expected, arguments(),
712 RelocInfo::CODE_TARGET, JUMP_FUNCTION);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000713
714 // Handle call cache miss.
715 __ bind(&miss);
716 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000717 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000718
719 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000720 String* function_name = NULL;
721 if (function->shared()->name()->IsString()) {
722 function_name = String::cast(function->shared()->name());
723 }
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000724 return GetCode(CONSTANT_FUNCTION, function_name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000725}
726
727
728Object* CallStubCompiler::CompileCallInterceptor(Object* object,
729 JSObject* holder,
730 String* name) {
731 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000732 // -- lr: return address
733 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000734 Label miss;
735
736 // TODO(1224669): Implement.
737
738 // Handle call cache miss.
739 __ bind(&miss);
740 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000741 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000742
743 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000744 return GetCode(INTERCEPTOR, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000745}
746
747
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000748Object* CallStubCompiler::CompileCallGlobal(JSObject* object,
749 GlobalObject* holder,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000750 JSGlobalPropertyCell* cell,
751 JSFunction* function,
752 String* name) {
753 // ----------- S t a t e -------------
754 // -- lr: return address
755 // -----------------------------------
756 Label miss;
757
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000758 // Get the number of arguments.
759 const int argc = arguments().immediate();
760
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000761 // Get the receiver from the stack.
762 __ ldr(r0, MemOperand(sp, argc * kPointerSize));
763
764 // If the object is the holder then we know that it's a global
765 // object which can only happen for contextual calls. In this case,
766 // the receiver cannot be a smi.
767 if (object != holder) {
768 __ tst(r0, Operand(kSmiTagMask));
769 __ b(eq, &miss);
770 }
771
772 // Check that the maps haven't changed.
773 CheckPrototypes(object, r0, holder, r3, r2, name, &miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000774
775 // Get the value from the cell.
776 __ mov(r3, Operand(Handle<JSGlobalPropertyCell>(cell)));
777 __ ldr(r1, FieldMemOperand(r3, JSGlobalPropertyCell::kValueOffset));
778
779 // Check that the cell contains the same function.
780 __ cmp(r1, Operand(Handle<JSFunction>(function)));
781 __ b(ne, &miss);
782
783 // Patch the receiver on the stack with the global proxy if
784 // necessary.
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000785 if (object->IsGlobalObject()) {
786 __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset));
787 __ str(r3, MemOperand(sp, argc * kPointerSize));
788 }
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000789
790 // Setup the context (function already in r1).
791 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
792
793 // Jump to the cached code (tail call).
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000794 __ IncrementCounter(&Counters::call_global_inline, 1, r2, r3);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000795 ASSERT(function->is_compiled());
796 Handle<Code> code(function->code());
797 ParameterCount expected(function->shared()->formal_parameter_count());
798 __ InvokeCode(code, expected, arguments(),
799 RelocInfo::CODE_TARGET, JUMP_FUNCTION);
800
801 // Handle call cache miss.
802 __ bind(&miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000803 __ IncrementCounter(&Counters::call_global_inline_miss, 1, r1, r3);
804 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
805 __ Jump(ic, RelocInfo::CODE_TARGET);
806
807 // Return the generated code.
808 return GetCode(NORMAL, name);
809}
810
811
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000812Object* StoreStubCompiler::CompileStoreField(JSObject* object,
813 int index,
814 Map* transition,
815 String* name) {
816 // ----------- S t a t e -------------
817 // -- r0 : value
818 // -- r2 : name
819 // -- lr : return address
820 // -- [sp] : receiver
821 // -----------------------------------
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000822 Label miss;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000823
824 // Get the receiver from the stack.
825 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
826
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000827 // name register might be clobbered.
828 GenerateStoreField(masm(),
829 Builtins::StoreIC_ExtendStorage,
830 object,
831 index,
832 transition,
833 r3, r2, r1,
834 &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000835 __ bind(&miss);
836 __ mov(r2, Operand(Handle<String>(name))); // restore name
837 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000838 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000839
840 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000841 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000842}
843
844
845Object* StoreStubCompiler::CompileStoreCallback(JSObject* object,
846 AccessorInfo* callback,
847 String* name) {
848 // ----------- S t a t e -------------
849 // -- r0 : value
850 // -- r2 : name
851 // -- lr : return address
852 // -- [sp] : receiver
853 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000854 Label miss;
855
856 // Get the object from the stack.
857 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
858
859 // Check that the object isn't a smi.
860 __ tst(r3, Operand(kSmiTagMask));
861 __ b(eq, &miss);
862
863 // Check that the map of the object hasn't changed.
864 __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset));
865 __ cmp(r1, Operand(Handle<Map>(object->map())));
866 __ b(ne, &miss);
867
868 // Perform global security token check if needed.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000869 if (object->IsJSGlobalProxy()) {
870 __ CheckAccessGlobalProxy(r3, r1, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000871 }
872
873 // Stub never generated for non-global objects that require access
874 // checks.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000875 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000876
877 __ ldr(ip, MemOperand(sp)); // receiver
878 __ push(ip);
879 __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback info
880 __ push(ip);
881 __ push(r2); // name
882 __ push(r0); // value
883
mads.s.ager31e71382008-08-13 09:32:07 +0000884 // Do tail-call to the runtime system.
885 ExternalReference store_callback_property =
886 ExternalReference(IC_Utility(IC::kStoreCallbackProperty));
887 __ TailCallRuntime(store_callback_property, 4);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000888
889 // Handle store cache miss.
890 __ bind(&miss);
891 __ mov(r2, Operand(Handle<String>(name))); // restore name
892 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000893 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000894
895 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000896 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000897}
898
899
900Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver,
901 String* name) {
902 // ----------- S t a t e -------------
903 // -- r0 : value
904 // -- r2 : name
905 // -- lr : return address
906 // -- [sp] : receiver
907 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000908 Label miss;
909
910 // Get the object from the stack.
911 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
912
913 // Check that the object isn't a smi.
914 __ tst(r3, Operand(kSmiTagMask));
915 __ b(eq, &miss);
916
917 // Check that the map of the object hasn't changed.
918 __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset));
919 __ cmp(r1, Operand(Handle<Map>(receiver->map())));
920 __ b(ne, &miss);
921
922 // Perform global security token check if needed.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000923 if (receiver->IsJSGlobalProxy()) {
924 __ CheckAccessGlobalProxy(r3, r1, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000925 }
926
927 // Stub never generated for non-global objects that require access
928 // checks.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000929 ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000930
931 __ ldr(ip, MemOperand(sp)); // receiver
932 __ push(ip);
933 __ push(r2); // name
934 __ push(r0); // value
935
mads.s.ager31e71382008-08-13 09:32:07 +0000936 // Do tail-call to the runtime system.
937 ExternalReference store_ic_property =
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000938 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty));
mads.s.ager31e71382008-08-13 09:32:07 +0000939 __ TailCallRuntime(store_ic_property, 3);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000940
941 // Handle store cache miss.
942 __ bind(&miss);
943 __ mov(r2, Operand(Handle<String>(name))); // restore name
944 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000945 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000946
947 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000948 return GetCode(INTERCEPTOR, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000949}
950
951
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000952Object* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object,
953 JSGlobalPropertyCell* cell,
954 String* name) {
955 // ----------- S t a t e -------------
956 // -- r0 : value
957 // -- r2 : name
958 // -- lr : return address
959 // -- [sp] : receiver
960 // -----------------------------------
961 Label miss;
962
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000963 // Check that the map of the global has not changed.
964 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
965 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
966 __ cmp(r3, Operand(Handle<Map>(object->map())));
967 __ b(ne, &miss);
968
969 // Store the value in the cell.
970 __ mov(r2, Operand(Handle<JSGlobalPropertyCell>(cell)));
971 __ str(r0, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset));
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000972
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000973 __ IncrementCounter(&Counters::named_store_global_inline, 1, r1, r3);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000974 __ Ret();
975
976 // Handle store cache miss.
977 __ bind(&miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000978 __ IncrementCounter(&Counters::named_store_global_inline_miss, 1, r1, r3);
979 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
980 __ Jump(ic, RelocInfo::CODE_TARGET);
981
982 // Return the generated code.
983 return GetCode(NORMAL, name);
984}
985
986
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000987Object* LoadStubCompiler::CompileLoadField(JSObject* object,
988 JSObject* holder,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000989 int index,
990 String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000991 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000992 // -- r2 : name
993 // -- lr : return address
994 // -- [sp] : receiver
995 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000996 Label miss;
997
mads.s.ager31e71382008-08-13 09:32:07 +0000998 __ ldr(r0, MemOperand(sp, 0));
999
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001000 GenerateLoadField(object, holder, r0, r3, r1, index, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001001 __ bind(&miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001002 GenerateLoadMiss(masm(), Code::LOAD_IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001003
1004 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001005 return GetCode(FIELD, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001006}
1007
1008
1009Object* LoadStubCompiler::CompileLoadCallback(JSObject* object,
1010 JSObject* holder,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001011 AccessorInfo* callback,
1012 String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001013 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001014 // -- r2 : name
1015 // -- lr : return address
1016 // -- [sp] : receiver
1017 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001018 Label miss;
1019
mads.s.ager31e71382008-08-13 09:32:07 +00001020 __ ldr(r0, MemOperand(sp, 0));
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001021 GenerateLoadCallback(object, holder, r0, r2, r3, r1, callback, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001022 __ bind(&miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001023 GenerateLoadMiss(masm(), Code::LOAD_IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001024
1025 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001026 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001027}
1028
1029
1030Object* LoadStubCompiler::CompileLoadConstant(JSObject* object,
1031 JSObject* holder,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001032 Object* value,
1033 String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001034 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001035 // -- r2 : name
1036 // -- lr : return address
1037 // -- [sp] : receiver
1038 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001039 Label miss;
1040
mads.s.ager31e71382008-08-13 09:32:07 +00001041 __ ldr(r0, MemOperand(sp, 0));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001042
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001043 GenerateLoadConstant(object, holder, r0, r3, r1, value, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001044 __ bind(&miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001045 GenerateLoadMiss(masm(), Code::LOAD_IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001046
1047 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001048 return GetCode(CONSTANT_FUNCTION, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001049}
1050
1051
1052Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* object,
1053 JSObject* holder,
1054 String* name) {
1055 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001056 // -- r2 : name
1057 // -- lr : return address
1058 // -- [sp] : receiver
1059 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001060 Label miss;
1061
mads.s.ager31e71382008-08-13 09:32:07 +00001062 __ ldr(r0, MemOperand(sp, 0));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001063
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001064 LookupResult lookup;
1065 holder->LocalLookupRealNamedProperty(name, &lookup);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001066 GenerateLoadInterceptor(object,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001067 holder,
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001068 &lookup,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001069 r0,
1070 r2,
1071 r3,
1072 r1,
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001073 name,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001074 &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001075 __ bind(&miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001076 GenerateLoadMiss(masm(), Code::LOAD_IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001077
1078 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001079 return GetCode(INTERCEPTOR, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001080}
1081
1082
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001083Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object,
1084 GlobalObject* holder,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001085 JSGlobalPropertyCell* cell,
1086 String* name,
1087 bool is_dont_delete) {
1088 // ----------- S t a t e -------------
1089 // -- r2 : name
1090 // -- lr : return address
1091 // -- [sp] : receiver
1092 // -----------------------------------
1093 Label miss;
1094
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001095 // Get the receiver from the stack.
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001096 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001097
1098 // If the object is the holder then we know that it's a global
1099 // object which can only happen for contextual calls. In this case,
1100 // the receiver cannot be a smi.
1101 if (object != holder) {
1102 __ tst(r1, Operand(kSmiTagMask));
1103 __ b(eq, &miss);
1104 }
1105
1106 // Check that the map of the global has not changed.
1107 CheckPrototypes(object, r1, holder, r3, r0, name, &miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001108
1109 // Get the value from the cell.
1110 __ mov(r3, Operand(Handle<JSGlobalPropertyCell>(cell)));
1111 __ ldr(r0, FieldMemOperand(r3, JSGlobalPropertyCell::kValueOffset));
1112
1113 // Check for deleted property if property can actually be deleted.
1114 if (!is_dont_delete) {
ager@chromium.orgab99eea2009-08-25 07:05:41 +00001115 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
1116 __ cmp(r0, ip);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001117 __ b(eq, &miss);
1118 }
1119
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001120 __ IncrementCounter(&Counters::named_load_global_inline, 1, r1, r3);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001121 __ Ret();
1122
1123 __ bind(&miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001124 __ IncrementCounter(&Counters::named_load_global_inline_miss, 1, r1, r3);
1125 GenerateLoadMiss(masm(), Code::LOAD_IC);
1126
1127 // Return the generated code.
1128 return GetCode(NORMAL, name);
1129}
1130
1131
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001132Object* KeyedLoadStubCompiler::CompileLoadField(String* name,
1133 JSObject* receiver,
1134 JSObject* holder,
1135 int index) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001136 // ----------- S t a t e -------------
1137 // -- lr : return address
1138 // -- sp[0] : key
1139 // -- sp[4] : receiver
1140 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001141 Label miss;
1142
1143 __ ldr(r2, MemOperand(sp, 0));
1144 __ ldr(r0, MemOperand(sp, kPointerSize));
1145
1146 __ cmp(r2, Operand(Handle<String>(name)));
1147 __ b(ne, &miss);
1148
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001149 GenerateLoadField(receiver, holder, r0, r3, r1, index, name, &miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001150 __ bind(&miss);
1151 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1152
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001153 return GetCode(FIELD, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001154}
1155
1156
1157Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name,
1158 JSObject* receiver,
1159 JSObject* holder,
1160 AccessorInfo* callback) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001161 // ----------- S t a t e -------------
1162 // -- lr : return address
1163 // -- sp[0] : key
1164 // -- sp[4] : receiver
1165 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001166 Label miss;
1167
1168 __ ldr(r2, MemOperand(sp, 0));
1169 __ ldr(r0, MemOperand(sp, kPointerSize));
1170
1171 __ cmp(r2, Operand(Handle<String>(name)));
1172 __ b(ne, &miss);
1173
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001174 GenerateLoadCallback(receiver, holder, r0, r2, r3, r1, callback, name, &miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001175 __ bind(&miss);
1176 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1177
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001178 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001179}
1180
1181
1182Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name,
1183 JSObject* receiver,
1184 JSObject* holder,
1185 Object* value) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001186 // ----------- S t a t e -------------
1187 // -- lr : return address
1188 // -- sp[0] : key
1189 // -- sp[4] : receiver
1190 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001191 Label miss;
1192
1193 // Check the key is the cached one
1194 __ ldr(r2, MemOperand(sp, 0));
1195 __ ldr(r0, MemOperand(sp, kPointerSize));
1196
1197 __ cmp(r2, Operand(Handle<String>(name)));
1198 __ b(ne, &miss);
1199
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001200 GenerateLoadConstant(receiver, holder, r0, r3, r1, value, name, &miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001201 __ bind(&miss);
1202 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1203
1204 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001205 return GetCode(CONSTANT_FUNCTION, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001206}
1207
1208
1209Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver,
1210 JSObject* holder,
1211 String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001212 // ----------- S t a t e -------------
1213 // -- lr : return address
1214 // -- sp[0] : key
1215 // -- sp[4] : receiver
1216 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001217 Label miss;
1218
1219 // Check the key is the cached one
1220 __ ldr(r2, MemOperand(sp, 0));
1221 __ ldr(r0, MemOperand(sp, kPointerSize));
1222
1223 __ cmp(r2, Operand(Handle<String>(name)));
1224 __ b(ne, &miss);
1225
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001226 LookupResult lookup;
1227 holder->LocalLookupRealNamedProperty(name, &lookup);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001228 GenerateLoadInterceptor(receiver,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001229 holder,
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001230 &lookup,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001231 r0,
1232 r2,
1233 r3,
1234 r1,
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001235 name,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001236 &miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001237 __ bind(&miss);
1238 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1239
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001240 return GetCode(INTERCEPTOR, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001241}
1242
1243
1244Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001245 // ----------- S t a t e -------------
1246 // -- lr : return address
1247 // -- sp[0] : key
1248 // -- sp[4] : receiver
1249 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001250 Label miss;
1251
1252 // Check the key is the cached one
1253 __ ldr(r2, MemOperand(sp, 0));
1254 __ ldr(r0, MemOperand(sp, kPointerSize));
1255
1256 __ cmp(r2, Operand(Handle<String>(name)));
1257 __ b(ne, &miss);
1258
1259 GenerateLoadArrayLength(masm(), r0, r3, &miss);
1260 __ bind(&miss);
1261 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1262
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001263 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001264}
1265
1266
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00001267Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001268 // ----------- S t a t e -------------
1269 // -- lr : return address
1270 // -- sp[0] : key
1271 // -- sp[4] : receiver
1272 // -----------------------------------
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001273 Label miss;
1274 __ IncrementCounter(&Counters::keyed_load_string_length, 1, r1, r3);
1275
1276 __ ldr(r2, MemOperand(sp));
1277 __ ldr(r0, MemOperand(sp, kPointerSize)); // receiver
1278
1279 __ cmp(r2, Operand(Handle<String>(name)));
1280 __ b(ne, &miss);
1281
1282 GenerateLoadStringLength2(masm(), r0, r1, r3, &miss);
1283 __ bind(&miss);
1284 __ DecrementCounter(&Counters::keyed_load_string_length, 1, r1, r3);
1285
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001286 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1287
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001288 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001289}
1290
1291
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001292// TODO(1224671): implement the fast case.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001293Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001294 // ----------- S t a t e -------------
1295 // -- lr : return address
1296 // -- sp[0] : key
1297 // -- sp[4] : receiver
1298 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001299 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1300
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001301 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001302}
1303
1304
1305Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object,
1306 int index,
1307 Map* transition,
1308 String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001309 // ----------- S t a t e -------------
1310 // -- r0 : value
1311 // -- r2 : name
1312 // -- lr : return address
1313 // -- [sp] : receiver
1314 // -----------------------------------
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001315 Label miss;
1316
1317 __ IncrementCounter(&Counters::keyed_store_field, 1, r1, r3);
1318
1319 // Check that the name has not changed.
1320 __ cmp(r2, Operand(Handle<String>(name)));
1321 __ b(ne, &miss);
1322
1323 // Load receiver from the stack.
1324 __ ldr(r3, MemOperand(sp));
1325 // r1 is used as scratch register, r3 and r2 might be clobbered.
1326 GenerateStoreField(masm(),
1327 Builtins::StoreIC_ExtendStorage,
1328 object,
1329 index,
1330 transition,
1331 r3, r2, r1,
1332 &miss);
1333 __ bind(&miss);
1334
1335 __ DecrementCounter(&Counters::keyed_store_field, 1, r1, r3);
1336 __ mov(r2, Operand(Handle<String>(name))); // restore name register.
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001337 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss));
1338 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001339
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001340 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001341 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001342}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001343
1344
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001345Object* ConstructStubCompiler::CompileConstructStub(
1346 SharedFunctionInfo* shared) {
1347 // Not implemented yet - just jump to generic stub.
1348 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric);
1349 Handle<Code> generic_construct_stub(code);
1350 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
1351
1352 // Return the generated code.
1353 return GetCode();
1354}
1355
1356
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001357#undef __
1358
1359} } // namespace v8::internal