blob: 393db59e49df4d6e6d658d0c0a547a5eb707f10b [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));
398 __ cmp(scratch, Operand(Factory::the_hole_value()));
399 __ b(ne, miss);
400 }
401 object = JSObject::cast(object->GetPrototype());
402 }
403
404 // Return the register containin the holder.
405 return result;
406}
407
408
409void StubCompiler::GenerateLoadField(JSObject* object,
410 JSObject* holder,
411 Register receiver,
412 Register scratch1,
413 Register scratch2,
414 int index,
415 String* name,
416 Label* miss) {
417 // Check that the receiver isn't a smi.
418 __ tst(receiver, Operand(kSmiTagMask));
419 __ b(eq, miss);
420
421 // Check that the maps haven't changed.
422 Register reg =
423 CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss);
424 GenerateFastPropertyLoad(masm(), r0, reg, holder, index);
425 __ Ret();
426}
427
428
429void StubCompiler::GenerateLoadConstant(JSObject* object,
430 JSObject* holder,
431 Register receiver,
432 Register scratch1,
433 Register scratch2,
434 Object* value,
435 String* name,
436 Label* miss) {
437 // Check that the receiver isn't a smi.
438 __ tst(receiver, Operand(kSmiTagMask));
439 __ b(eq, miss);
440
441 // Check that the maps haven't changed.
442 Register reg =
443 CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss);
444
445 // Return the constant value.
446 __ mov(r0, Operand(Handle<Object>(value)));
447 __ Ret();
448}
449
450
451void StubCompiler::GenerateLoadCallback(JSObject* object,
452 JSObject* holder,
453 Register receiver,
454 Register name_reg,
455 Register scratch1,
456 Register scratch2,
457 AccessorInfo* callback,
458 String* name,
459 Label* miss) {
460 // Check that the receiver isn't a smi.
461 __ tst(receiver, Operand(kSmiTagMask));
462 __ b(eq, miss);
463
464 // Check that the maps haven't changed.
465 Register reg =
466 CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss);
467
468 // Push the arguments on the JS stack of the caller.
469 __ push(receiver); // receiver
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000470 __ push(reg); // holder
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000471 __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback data
472 __ push(ip);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000473 __ ldr(reg, FieldMemOperand(ip, AccessorInfo::kDataOffset));
474 __ push(reg);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000475 __ push(name_reg); // name
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000476
477 // Do tail-call to the runtime system.
478 ExternalReference load_callback_property =
479 ExternalReference(IC_Utility(IC::kLoadCallbackProperty));
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000480 __ TailCallRuntime(load_callback_property, 5);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000481}
482
483
484void StubCompiler::GenerateLoadInterceptor(JSObject* object,
485 JSObject* holder,
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000486 LookupResult* lookup,
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000487 Register receiver,
488 Register name_reg,
489 Register scratch1,
490 Register scratch2,
491 String* name,
492 Label* miss) {
493 // Check that the receiver isn't a smi.
494 __ tst(receiver, Operand(kSmiTagMask));
495 __ b(eq, miss);
496
497 // Check that the maps haven't changed.
498 Register reg =
499 CheckPrototypes(object, receiver, holder, scratch1, scratch2, name, miss);
500
501 // Push the arguments on the JS stack of the caller.
502 __ push(receiver); // receiver
503 __ push(reg); // holder
504 __ push(name_reg); // name
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000505
506 InterceptorInfo* interceptor = holder->GetNamedInterceptor();
507 ASSERT(!Heap::InNewSpace(interceptor));
508 __ mov(scratch1, Operand(Handle<Object>(interceptor)));
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000509 __ push(scratch1);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000510 __ ldr(scratch2, FieldMemOperand(scratch1, InterceptorInfo::kDataOffset));
511 __ push(scratch2);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000512
513 // Do tail-call to the runtime system.
514 ExternalReference load_ic_property =
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000515 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorForLoad));
516 __ TailCallRuntime(load_ic_property, 5);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000517}
518
519
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000520Object* StubCompiler::CompileLazyCompile(Code::Flags flags) {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000521 // ----------- S t a t e -------------
522 // -- r1: function
523 // -- lr: return address
524 // -----------------------------------
525
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000526 // Enter an internal frame.
527 __ EnterInternalFrame();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000528
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000529 // Preserve the function.
530 __ push(r1);
531
532 // Push the function on the stack as the argument to the runtime function.
533 __ push(r1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000534 __ CallRuntime(Runtime::kLazyCompile, 1);
535
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000536 // Calculate the entry point.
537 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000538
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000539 // Restore saved function.
540 __ pop(r1);
541
542 // Tear down temporary frame.
ager@chromium.org236ad962008-09-25 09:45:57 +0000543 __ LeaveInternalFrame();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000544
545 // Do a tail-call of the compiled function.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000546 __ Jump(r2);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000547
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000548 return GetCodeWithFlags(flags, "LazyCompileStub");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000549}
550
551
552Object* CallStubCompiler::CompileCallField(Object* object,
553 JSObject* holder,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000554 int index,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000555 String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000556 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000557 // -- lr: return address
558 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000559 Label miss;
560
mads.s.ager31e71382008-08-13 09:32:07 +0000561 const int argc = arguments().immediate();
562
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000563 // Get the receiver of the function from the stack into r0.
564 __ ldr(r0, MemOperand(sp, argc * kPointerSize));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000565 // Check that the receiver isn't a smi.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000566 __ tst(r0, Operand(kSmiTagMask));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000567 __ b(eq, &miss);
568
569 // Do the right check and compute the holder register.
570 Register reg =
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000571 CheckPrototypes(JSObject::cast(object), r0, holder, r3, r2, name, &miss);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000572 GenerateFastPropertyLoad(masm(), r1, reg, holder, index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000573
574 // Check that the function really is a function.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000575 __ tst(r1, Operand(kSmiTagMask));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000576 __ b(eq, &miss);
577 // Get the map.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000578 __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000579 __ b(ne, &miss);
580
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000581 // Patch the receiver on the stack with the global proxy if
582 // necessary.
583 if (object->IsGlobalObject()) {
584 __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset));
585 __ str(r3, MemOperand(sp, argc * kPointerSize));
586 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000587
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000588 // Invoke the function.
589 __ InvokeFunction(r1, arguments(), JUMP_FUNCTION);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000590
591 // Handle call cache miss.
592 __ bind(&miss);
593 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000594 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000595
596 // Return the generated code.
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000597 return GetCode(FIELD, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000598}
599
600
601Object* CallStubCompiler::CompileCallConstant(Object* object,
602 JSObject* holder,
603 JSFunction* function,
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000604 String* name,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000605 CheckType check) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000606 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000607 // -- lr: return address
608 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000609 Label miss;
610
mads.s.ager31e71382008-08-13 09:32:07 +0000611 // Get the receiver from the stack
612 const int argc = arguments().immediate();
613 __ ldr(r1, MemOperand(sp, argc * kPointerSize));
614
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000615 // Check that the receiver isn't a smi.
616 if (check != NUMBER_CHECK) {
617 __ tst(r1, Operand(kSmiTagMask));
618 __ b(eq, &miss);
619 }
620
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000621 // Make sure that it's okay not to patch the on stack receiver
622 // unless we're doing a receiver map check.
623 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
624
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000625 switch (check) {
626 case RECEIVER_MAP_CHECK:
627 // Check that the maps haven't changed.
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000628 CheckPrototypes(JSObject::cast(object), r1, holder, r3, r2, name, &miss);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000629
630 // Patch the receiver on the stack with the global proxy if
631 // necessary.
632 if (object->IsGlobalObject()) {
633 __ ldr(r3, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset));
634 __ str(r3, MemOperand(sp, argc * kPointerSize));
635 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000636 break;
637
638 case STRING_CHECK:
639 // Check that the object is a two-byte string or a symbol.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000640 __ CompareObjectType(r1, r2, r2, FIRST_NONSTRING_TYPE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000641 __ b(hs, &miss);
642 // Check that the maps starting from the prototype haven't changed.
643 GenerateLoadGlobalFunctionPrototype(masm(),
644 Context::STRING_FUNCTION_INDEX,
645 r2);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000646 CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3,
647 r1, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000648 break;
649
650 case NUMBER_CHECK: {
651 Label fast;
652 // Check that the object is a smi or a heap number.
653 __ tst(r1, Operand(kSmiTagMask));
654 __ b(eq, &fast);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000655 __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000656 __ b(ne, &miss);
657 __ bind(&fast);
658 // Check that the maps starting from the prototype haven't changed.
659 GenerateLoadGlobalFunctionPrototype(masm(),
660 Context::NUMBER_FUNCTION_INDEX,
661 r2);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000662 CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3,
663 r1, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000664 break;
665 }
666
667 case BOOLEAN_CHECK: {
668 Label fast;
669 // Check that the object is a boolean.
670 __ cmp(r1, Operand(Factory::true_value()));
671 __ b(eq, &fast);
672 __ cmp(r1, Operand(Factory::false_value()));
673 __ b(ne, &miss);
674 __ bind(&fast);
675 // Check that the maps starting from the prototype haven't changed.
676 GenerateLoadGlobalFunctionPrototype(masm(),
677 Context::BOOLEAN_FUNCTION_INDEX,
678 r2);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000679 CheckPrototypes(JSObject::cast(object->GetPrototype()), r2, holder, r3,
680 r1, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000681 break;
682 }
683
684 case JSARRAY_HAS_FAST_ELEMENTS_CHECK:
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000685 CheckPrototypes(JSObject::cast(object), r1, holder, r3, r2, name, &miss);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000686 // Make sure object->HasFastElements().
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000687 // Get the elements array of the object.
688 __ ldr(r3, FieldMemOperand(r1, JSObject::kElementsOffset));
689 // Check that the object is in fast mode (not dictionary).
690 __ ldr(r2, FieldMemOperand(r3, HeapObject::kMapOffset));
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000691 __ cmp(r2, Operand(Factory::fixed_array_map()));
692 __ b(ne, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000693 break;
694
695 default:
696 UNREACHABLE();
697 }
698
699 // Get the function and setup the context.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000700 __ mov(r1, Operand(Handle<JSFunction>(function)));
701 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000702
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000703 // Jump to the cached code (tail call).
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000704 ASSERT(function->is_compiled());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000705 Handle<Code> code(function->code());
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000706 ParameterCount expected(function->shared()->formal_parameter_count());
ager@chromium.org236ad962008-09-25 09:45:57 +0000707 __ InvokeCode(code, expected, arguments(),
708 RelocInfo::CODE_TARGET, JUMP_FUNCTION);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000709
710 // Handle call cache miss.
711 __ bind(&miss);
712 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000713 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000714
715 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000716 String* function_name = NULL;
717 if (function->shared()->name()->IsString()) {
718 function_name = String::cast(function->shared()->name());
719 }
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000720 return GetCode(CONSTANT_FUNCTION, function_name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000721}
722
723
724Object* CallStubCompiler::CompileCallInterceptor(Object* object,
725 JSObject* holder,
726 String* name) {
727 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000728 // -- lr: return address
729 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000730 Label miss;
731
732 // TODO(1224669): Implement.
733
734 // Handle call cache miss.
735 __ bind(&miss);
736 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000737 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000738
739 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000740 return GetCode(INTERCEPTOR, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000741}
742
743
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000744Object* CallStubCompiler::CompileCallGlobal(JSObject* object,
745 GlobalObject* holder,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000746 JSGlobalPropertyCell* cell,
747 JSFunction* function,
748 String* name) {
749 // ----------- S t a t e -------------
750 // -- lr: return address
751 // -----------------------------------
752 Label miss;
753
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000754 // Get the number of arguments.
755 const int argc = arguments().immediate();
756
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000757 // Get the receiver from the stack.
758 __ ldr(r0, MemOperand(sp, argc * kPointerSize));
759
760 // If the object is the holder then we know that it's a global
761 // object which can only happen for contextual calls. In this case,
762 // the receiver cannot be a smi.
763 if (object != holder) {
764 __ tst(r0, Operand(kSmiTagMask));
765 __ b(eq, &miss);
766 }
767
768 // Check that the maps haven't changed.
769 CheckPrototypes(object, r0, holder, r3, r2, name, &miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000770
771 // Get the value from the cell.
772 __ mov(r3, Operand(Handle<JSGlobalPropertyCell>(cell)));
773 __ ldr(r1, FieldMemOperand(r3, JSGlobalPropertyCell::kValueOffset));
774
775 // Check that the cell contains the same function.
776 __ cmp(r1, Operand(Handle<JSFunction>(function)));
777 __ b(ne, &miss);
778
779 // Patch the receiver on the stack with the global proxy if
780 // necessary.
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000781 if (object->IsGlobalObject()) {
782 __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset));
783 __ str(r3, MemOperand(sp, argc * kPointerSize));
784 }
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000785
786 // Setup the context (function already in r1).
787 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
788
789 // Jump to the cached code (tail call).
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000790 __ IncrementCounter(&Counters::call_global_inline, 1, r1, r3);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000791 ASSERT(function->is_compiled());
792 Handle<Code> code(function->code());
793 ParameterCount expected(function->shared()->formal_parameter_count());
794 __ InvokeCode(code, expected, arguments(),
795 RelocInfo::CODE_TARGET, JUMP_FUNCTION);
796
797 // Handle call cache miss.
798 __ bind(&miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000799 __ IncrementCounter(&Counters::call_global_inline_miss, 1, r1, r3);
800 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
801 __ Jump(ic, RelocInfo::CODE_TARGET);
802
803 // Return the generated code.
804 return GetCode(NORMAL, name);
805}
806
807
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000808Object* StoreStubCompiler::CompileStoreField(JSObject* object,
809 int index,
810 Map* transition,
811 String* name) {
812 // ----------- S t a t e -------------
813 // -- r0 : value
814 // -- r2 : name
815 // -- lr : return address
816 // -- [sp] : receiver
817 // -----------------------------------
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000818 Label miss;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000819
820 // Get the receiver from the stack.
821 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
822
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000823 // name register might be clobbered.
824 GenerateStoreField(masm(),
825 Builtins::StoreIC_ExtendStorage,
826 object,
827 index,
828 transition,
829 r3, r2, r1,
830 &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000831 __ bind(&miss);
832 __ mov(r2, Operand(Handle<String>(name))); // restore name
833 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000834 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000835
836 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000837 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000838}
839
840
841Object* StoreStubCompiler::CompileStoreCallback(JSObject* object,
842 AccessorInfo* callback,
843 String* name) {
844 // ----------- S t a t e -------------
845 // -- r0 : value
846 // -- r2 : name
847 // -- lr : return address
848 // -- [sp] : receiver
849 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000850 Label miss;
851
852 // Get the object from the stack.
853 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
854
855 // Check that the object isn't a smi.
856 __ tst(r3, Operand(kSmiTagMask));
857 __ b(eq, &miss);
858
859 // Check that the map of the object hasn't changed.
860 __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset));
861 __ cmp(r1, Operand(Handle<Map>(object->map())));
862 __ b(ne, &miss);
863
864 // Perform global security token check if needed.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000865 if (object->IsJSGlobalProxy()) {
866 __ CheckAccessGlobalProxy(r3, r1, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000867 }
868
869 // Stub never generated for non-global objects that require access
870 // checks.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000871 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000872
873 __ ldr(ip, MemOperand(sp)); // receiver
874 __ push(ip);
875 __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback info
876 __ push(ip);
877 __ push(r2); // name
878 __ push(r0); // value
879
mads.s.ager31e71382008-08-13 09:32:07 +0000880 // Do tail-call to the runtime system.
881 ExternalReference store_callback_property =
882 ExternalReference(IC_Utility(IC::kStoreCallbackProperty));
883 __ TailCallRuntime(store_callback_property, 4);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000884
885 // Handle store cache miss.
886 __ bind(&miss);
887 __ mov(r2, Operand(Handle<String>(name))); // restore name
888 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000889 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000890
891 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000892 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000893}
894
895
896Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver,
897 String* name) {
898 // ----------- S t a t e -------------
899 // -- r0 : value
900 // -- r2 : name
901 // -- lr : return address
902 // -- [sp] : receiver
903 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000904 Label miss;
905
906 // Get the object from the stack.
907 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
908
909 // Check that the object isn't a smi.
910 __ tst(r3, Operand(kSmiTagMask));
911 __ b(eq, &miss);
912
913 // Check that the map of the object hasn't changed.
914 __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset));
915 __ cmp(r1, Operand(Handle<Map>(receiver->map())));
916 __ b(ne, &miss);
917
918 // Perform global security token check if needed.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000919 if (receiver->IsJSGlobalProxy()) {
920 __ CheckAccessGlobalProxy(r3, r1, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000921 }
922
923 // Stub never generated for non-global objects that require access
924 // checks.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000925 ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000926
927 __ ldr(ip, MemOperand(sp)); // receiver
928 __ push(ip);
929 __ push(r2); // name
930 __ push(r0); // value
931
mads.s.ager31e71382008-08-13 09:32:07 +0000932 // Do tail-call to the runtime system.
933 ExternalReference store_ic_property =
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000934 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty));
mads.s.ager31e71382008-08-13 09:32:07 +0000935 __ TailCallRuntime(store_ic_property, 3);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000936
937 // Handle store cache miss.
938 __ bind(&miss);
939 __ mov(r2, Operand(Handle<String>(name))); // restore name
940 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000941 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000942
943 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000944 return GetCode(INTERCEPTOR, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000945}
946
947
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000948Object* StoreStubCompiler::CompileStoreGlobal(GlobalObject* object,
949 JSGlobalPropertyCell* cell,
950 String* name) {
951 // ----------- S t a t e -------------
952 // -- r0 : value
953 // -- r2 : name
954 // -- lr : return address
955 // -- [sp] : receiver
956 // -----------------------------------
957 Label miss;
958
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000959 // Check that the map of the global has not changed.
960 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
961 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
962 __ cmp(r3, Operand(Handle<Map>(object->map())));
963 __ b(ne, &miss);
964
965 // Store the value in the cell.
966 __ mov(r2, Operand(Handle<JSGlobalPropertyCell>(cell)));
967 __ str(r0, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset));
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000968
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000969 __ IncrementCounter(&Counters::named_store_global_inline, 1, r1, r3);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000970 __ Ret();
971
972 // Handle store cache miss.
973 __ bind(&miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000974 __ IncrementCounter(&Counters::named_store_global_inline_miss, 1, r1, r3);
975 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
976 __ Jump(ic, RelocInfo::CODE_TARGET);
977
978 // Return the generated code.
979 return GetCode(NORMAL, name);
980}
981
982
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000983Object* LoadStubCompiler::CompileLoadField(JSObject* object,
984 JSObject* holder,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000985 int index,
986 String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000987 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000988 // -- r2 : name
989 // -- lr : return address
990 // -- [sp] : receiver
991 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000992 Label miss;
993
mads.s.ager31e71382008-08-13 09:32:07 +0000994 __ ldr(r0, MemOperand(sp, 0));
995
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000996 GenerateLoadField(object, holder, r0, r3, r1, index, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000997 __ bind(&miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000998 GenerateLoadMiss(masm(), Code::LOAD_IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000999
1000 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001001 return GetCode(FIELD, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001002}
1003
1004
1005Object* LoadStubCompiler::CompileLoadCallback(JSObject* object,
1006 JSObject* holder,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001007 AccessorInfo* callback,
1008 String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001009 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001010 // -- r2 : name
1011 // -- lr : return address
1012 // -- [sp] : receiver
1013 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001014 Label miss;
1015
mads.s.ager31e71382008-08-13 09:32:07 +00001016 __ ldr(r0, MemOperand(sp, 0));
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001017 GenerateLoadCallback(object, holder, r0, r2, r3, r1, callback, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001018 __ bind(&miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001019 GenerateLoadMiss(masm(), Code::LOAD_IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001020
1021 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001022 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001023}
1024
1025
1026Object* LoadStubCompiler::CompileLoadConstant(JSObject* object,
1027 JSObject* holder,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001028 Object* value,
1029 String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001030 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001031 // -- r2 : name
1032 // -- lr : return address
1033 // -- [sp] : receiver
1034 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001035 Label miss;
1036
mads.s.ager31e71382008-08-13 09:32:07 +00001037 __ ldr(r0, MemOperand(sp, 0));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001038
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001039 GenerateLoadConstant(object, holder, r0, r3, r1, value, name, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001040 __ bind(&miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001041 GenerateLoadMiss(masm(), Code::LOAD_IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001042
1043 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001044 return GetCode(CONSTANT_FUNCTION, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001045}
1046
1047
1048Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* object,
1049 JSObject* holder,
1050 String* name) {
1051 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001052 // -- r2 : name
1053 // -- lr : return address
1054 // -- [sp] : receiver
1055 // -----------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001056 Label miss;
1057
mads.s.ager31e71382008-08-13 09:32:07 +00001058 __ ldr(r0, MemOperand(sp, 0));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001059
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001060 LookupResult lookup;
1061 holder->LocalLookupRealNamedProperty(name, &lookup);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001062 GenerateLoadInterceptor(object,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001063 holder,
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001064 &lookup,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001065 r0,
1066 r2,
1067 r3,
1068 r1,
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001069 name,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001070 &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001071 __ bind(&miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001072 GenerateLoadMiss(masm(), Code::LOAD_IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001073
1074 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001075 return GetCode(INTERCEPTOR, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001076}
1077
1078
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001079Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object,
1080 GlobalObject* holder,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001081 JSGlobalPropertyCell* cell,
1082 String* name,
1083 bool is_dont_delete) {
1084 // ----------- S t a t e -------------
1085 // -- r2 : name
1086 // -- lr : return address
1087 // -- [sp] : receiver
1088 // -----------------------------------
1089 Label miss;
1090
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001091 // Get the receiver from the stack.
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001092 __ ldr(r1, MemOperand(sp, 0 * kPointerSize));
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001093
1094 // If the object is the holder then we know that it's a global
1095 // object which can only happen for contextual calls. In this case,
1096 // the receiver cannot be a smi.
1097 if (object != holder) {
1098 __ tst(r1, Operand(kSmiTagMask));
1099 __ b(eq, &miss);
1100 }
1101
1102 // Check that the map of the global has not changed.
1103 CheckPrototypes(object, r1, holder, r3, r0, name, &miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001104
1105 // Get the value from the cell.
1106 __ mov(r3, Operand(Handle<JSGlobalPropertyCell>(cell)));
1107 __ ldr(r0, FieldMemOperand(r3, JSGlobalPropertyCell::kValueOffset));
1108
1109 // Check for deleted property if property can actually be deleted.
1110 if (!is_dont_delete) {
1111 __ cmp(r0, Operand(Factory::the_hole_value()));
1112 __ b(eq, &miss);
1113 }
1114
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001115 __ IncrementCounter(&Counters::named_load_global_inline, 1, r1, r3);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001116 __ Ret();
1117
1118 __ bind(&miss);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001119 __ IncrementCounter(&Counters::named_load_global_inline_miss, 1, r1, r3);
1120 GenerateLoadMiss(masm(), Code::LOAD_IC);
1121
1122 // Return the generated code.
1123 return GetCode(NORMAL, name);
1124}
1125
1126
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001127Object* KeyedLoadStubCompiler::CompileLoadField(String* name,
1128 JSObject* receiver,
1129 JSObject* holder,
1130 int index) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001131 // ----------- S t a t e -------------
1132 // -- lr : return address
1133 // -- sp[0] : key
1134 // -- sp[4] : receiver
1135 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001136 Label miss;
1137
1138 __ ldr(r2, MemOperand(sp, 0));
1139 __ ldr(r0, MemOperand(sp, kPointerSize));
1140
1141 __ cmp(r2, Operand(Handle<String>(name)));
1142 __ b(ne, &miss);
1143
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001144 GenerateLoadField(receiver, holder, r0, r3, r1, index, name, &miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001145 __ bind(&miss);
1146 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1147
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001148 return GetCode(FIELD, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001149}
1150
1151
1152Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name,
1153 JSObject* receiver,
1154 JSObject* holder,
1155 AccessorInfo* callback) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001156 // ----------- S t a t e -------------
1157 // -- lr : return address
1158 // -- sp[0] : key
1159 // -- sp[4] : receiver
1160 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001161 Label miss;
1162
1163 __ ldr(r2, MemOperand(sp, 0));
1164 __ ldr(r0, MemOperand(sp, kPointerSize));
1165
1166 __ cmp(r2, Operand(Handle<String>(name)));
1167 __ b(ne, &miss);
1168
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001169 GenerateLoadCallback(receiver, holder, r0, r2, r3, r1, callback, name, &miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001170 __ bind(&miss);
1171 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1172
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001173 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001174}
1175
1176
1177Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name,
1178 JSObject* receiver,
1179 JSObject* holder,
1180 Object* value) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001181 // ----------- S t a t e -------------
1182 // -- lr : return address
1183 // -- sp[0] : key
1184 // -- sp[4] : receiver
1185 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001186 Label miss;
1187
1188 // Check the key is the cached one
1189 __ ldr(r2, MemOperand(sp, 0));
1190 __ ldr(r0, MemOperand(sp, kPointerSize));
1191
1192 __ cmp(r2, Operand(Handle<String>(name)));
1193 __ b(ne, &miss);
1194
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001195 GenerateLoadConstant(receiver, holder, r0, r3, r1, value, name, &miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001196 __ bind(&miss);
1197 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1198
1199 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001200 return GetCode(CONSTANT_FUNCTION, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001201}
1202
1203
1204Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver,
1205 JSObject* holder,
1206 String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001207 // ----------- S t a t e -------------
1208 // -- lr : return address
1209 // -- sp[0] : key
1210 // -- sp[4] : receiver
1211 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001212 Label miss;
1213
1214 // Check the key is the cached one
1215 __ ldr(r2, MemOperand(sp, 0));
1216 __ ldr(r0, MemOperand(sp, kPointerSize));
1217
1218 __ cmp(r2, Operand(Handle<String>(name)));
1219 __ b(ne, &miss);
1220
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001221 LookupResult lookup;
1222 holder->LocalLookupRealNamedProperty(name, &lookup);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001223 GenerateLoadInterceptor(receiver,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001224 holder,
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001225 &lookup,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001226 r0,
1227 r2,
1228 r3,
1229 r1,
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001230 name,
ager@chromium.orge2902be2009-06-08 12:21:35 +00001231 &miss);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001232 __ bind(&miss);
1233 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1234
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001235 return GetCode(INTERCEPTOR, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001236}
1237
1238
1239Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001240 // ----------- S t a t e -------------
1241 // -- lr : return address
1242 // -- sp[0] : key
1243 // -- sp[4] : receiver
1244 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001245 Label miss;
1246
1247 // Check the key is the cached one
1248 __ ldr(r2, MemOperand(sp, 0));
1249 __ ldr(r0, MemOperand(sp, kPointerSize));
1250
1251 __ cmp(r2, Operand(Handle<String>(name)));
1252 __ b(ne, &miss);
1253
1254 GenerateLoadArrayLength(masm(), r0, r3, &miss);
1255 __ bind(&miss);
1256 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1257
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001258 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001259}
1260
1261
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00001262Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001263 // ----------- S t a t e -------------
1264 // -- lr : return address
1265 // -- sp[0] : key
1266 // -- sp[4] : receiver
1267 // -----------------------------------
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001268 Label miss;
1269 __ IncrementCounter(&Counters::keyed_load_string_length, 1, r1, r3);
1270
1271 __ ldr(r2, MemOperand(sp));
1272 __ ldr(r0, MemOperand(sp, kPointerSize)); // receiver
1273
1274 __ cmp(r2, Operand(Handle<String>(name)));
1275 __ b(ne, &miss);
1276
1277 GenerateLoadStringLength2(masm(), r0, r1, r3, &miss);
1278 __ bind(&miss);
1279 __ DecrementCounter(&Counters::keyed_load_string_length, 1, r1, r3);
1280
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001281 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1282
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001283 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001284}
1285
1286
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001287// TODO(1224671): implement the fast case.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001288Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001289 // ----------- S t a t e -------------
1290 // -- lr : return address
1291 // -- sp[0] : key
1292 // -- sp[4] : receiver
1293 // -----------------------------------
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001294 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC);
1295
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001296 return GetCode(CALLBACKS, name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001297}
1298
1299
1300Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object,
1301 int index,
1302 Map* transition,
1303 String* name) {
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001304 // ----------- S t a t e -------------
1305 // -- r0 : value
1306 // -- r2 : name
1307 // -- lr : return address
1308 // -- [sp] : receiver
1309 // -----------------------------------
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001310 Label miss;
1311
1312 __ IncrementCounter(&Counters::keyed_store_field, 1, r1, r3);
1313
1314 // Check that the name has not changed.
1315 __ cmp(r2, Operand(Handle<String>(name)));
1316 __ b(ne, &miss);
1317
1318 // Load receiver from the stack.
1319 __ ldr(r3, MemOperand(sp));
1320 // r1 is used as scratch register, r3 and r2 might be clobbered.
1321 GenerateStoreField(masm(),
1322 Builtins::StoreIC_ExtendStorage,
1323 object,
1324 index,
1325 transition,
1326 r3, r2, r1,
1327 &miss);
1328 __ bind(&miss);
1329
1330 __ DecrementCounter(&Counters::keyed_store_field, 1, r1, r3);
1331 __ mov(r2, Operand(Handle<String>(name))); // restore name register.
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001332 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss));
1333 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001334
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001335 // Return the generated code.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001336 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name);
ager@chromium.org3bf7b912008-11-17 09:09:45 +00001337}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001338
1339
1340#undef __
1341
1342} } // namespace v8::internal