blob: 2ef657e2cac133e61aef5764e8bf77770f0c7aa3 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 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
34namespace v8 { namespace internal {
35
36#define __ masm->
37
38
39static void ProbeTable(MacroAssembler* masm,
40 Code::Flags flags,
41 StubCache::Table table,
42 Register name,
43 Register offset) {
44 ExternalReference key_offset(SCTableReference::keyReference(table));
45 ExternalReference value_offset(SCTableReference::valueReference(table));
46
47 Label miss;
48
49 // Save the offset on the stack.
50 __ push(offset);
51
52 // Check that the key in the entry matches the name.
53 __ mov(ip, Operand(key_offset));
54 __ ldr(ip, MemOperand(ip, offset, LSL, 1));
55 __ cmp(name, Operand(ip));
56 __ b(ne, &miss);
57
58 // Get the code entry from the cache.
59 __ mov(ip, Operand(value_offset));
60 __ ldr(offset, MemOperand(ip, offset, LSL, 1));
61
62 // Check that the flags match what we're looking for.
63 __ ldr(offset, FieldMemOperand(offset, Code::kFlagsOffset));
64 __ and_(offset, offset, Operand(~Code::kFlagsTypeMask));
65 __ cmp(offset, Operand(flags));
66 __ b(ne, &miss);
67
68 // Restore offset and re-load code entry from cache.
69 __ pop(offset);
70 __ mov(ip, Operand(value_offset));
71 __ ldr(offset, MemOperand(ip, offset, LSL, 1));
72
73 // Jump to the first instruction in the code stub.
74 __ add(offset, offset, Operand(Code::kHeaderSize - kHeapObjectTag));
75 __ Jump(offset);
76
77 // Miss: Restore offset and fall through.
78 __ bind(&miss);
79 __ pop(offset);
80}
81
82
83void StubCache::GenerateProbe(MacroAssembler* masm,
84 Code::Flags flags,
85 Register receiver,
86 Register name,
87 Register scratch) {
88 Label miss;
89
90 // Make sure that code is valid. The shifting code relies on the
91 // entry size being 8.
92 ASSERT(sizeof(Entry) == 8);
93
94 // Make sure the flags does not name a specific type.
95 ASSERT(Code::ExtractTypeFromFlags(flags) == 0);
96
97 // Make sure that there are no register conflicts.
98 ASSERT(!scratch.is(receiver));
99 ASSERT(!scratch.is(name));
100
101 // Check that the receiver isn't a smi.
102 __ tst(receiver, Operand(kSmiTagMask));
103 __ b(eq, &miss);
104
105 // Get the map of the receiver and compute the hash.
ager@chromium.org7c537e22008-10-16 08:43:32 +0000106 __ ldr(scratch, FieldMemOperand(name, String::kLengthOffset));
107 __ ldr(ip, FieldMemOperand(receiver, HeapObject::kMapOffset));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000108 __ add(scratch, scratch, Operand(ip));
109 __ eor(scratch, scratch, Operand(flags));
110 __ and_(scratch,
111 scratch,
112 Operand((kPrimaryTableSize - 1) << kHeapObjectTagSize));
113
114 // Probe the primary table.
115 ProbeTable(masm, flags, kPrimary, name, scratch);
116
117 // Primary miss: Compute hash for secondary probe.
118 __ sub(scratch, scratch, Operand(name));
119 __ add(scratch, scratch, Operand(flags));
120 __ and_(scratch,
121 scratch,
122 Operand((kSecondaryTableSize - 1) << kHeapObjectTagSize));
123
124 // Probe the secondary table.
125 ProbeTable(masm, flags, kSecondary, name, scratch);
126
127 // Cache miss: Fall-through and let caller handle the miss by
128 // entering the runtime system.
129 __ bind(&miss);
130}
131
132
133void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm,
134 int index,
135 Register prototype) {
136 // Load the global or builtins object from the current context.
137 __ ldr(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
138 // Load the global context from the global or builtins object.
139 __ ldr(prototype,
140 FieldMemOperand(prototype, GlobalObject::kGlobalContextOffset));
141 // Load the function from the global context.
142 __ ldr(prototype, MemOperand(prototype, Context::SlotOffset(index)));
143 // Load the initial map. The global functions all have initial maps.
144 __ ldr(prototype,
145 FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset));
146 // Load the prototype from the initial map.
147 __ ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
148}
149
150
ager@chromium.org7c537e22008-10-16 08:43:32 +0000151// Load a fast property out of a holder object (src). In-object properties
152// are loaded directly otherwise the property is loaded from the properties
153// fixed array.
154void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm,
155 Register dst, Register src,
156 JSObject* holder, int index) {
157 // Adjust for the number of properties stored in the holder.
158 index -= holder->map()->inobject_properties();
159 if (index < 0) {
160 // Get the property straight out of the holder.
161 int offset = holder->map()->instance_size() + (index * kPointerSize);
162 __ ldr(dst, FieldMemOperand(src, offset));
163 } else {
164 // Calculate the offset into the properties array.
165 int offset = index * kPointerSize + Array::kHeaderSize;
166 __ ldr(dst, FieldMemOperand(src, JSObject::kPropertiesOffset));
167 __ ldr(dst, FieldMemOperand(dst, offset));
168 }
169}
170
171
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000172#undef __
173
174#define __ masm()->
175
176
177Object* StubCompiler::CompileLazyCompile(Code::Flags flags) {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000178 // ----------- S t a t e -------------
179 // -- r1: function
180 // -- lr: return address
181 // -----------------------------------
182
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000183 HandleScope scope;
184
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000185 // Enter an internal frame.
186 __ EnterInternalFrame();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000187
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000188 // Preserve the function.
189 __ push(r1);
190
191 // Push the function on the stack as the argument to the runtime function.
192 __ push(r1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000193 __ CallRuntime(Runtime::kLazyCompile, 1);
194
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000195 // Calculate the entry point.
196 __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000197
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000198 // Restore saved function.
199 __ pop(r1);
200
201 // Tear down temporary frame.
ager@chromium.org236ad962008-09-25 09:45:57 +0000202 __ LeaveInternalFrame();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000203
204 // Do a tail-call of the compiled function.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000205 __ Jump(r2);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000206
207 return GetCodeWithFlags(flags);
208}
209
210
211Object* CallStubCompiler::CompileCallField(Object* object,
212 JSObject* holder,
213 int index) {
214 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000215 // -- lr: return address
216 // -----------------------------------
217
218 HandleScope scope;
219 Label miss;
220
mads.s.ager31e71382008-08-13 09:32:07 +0000221 const int argc = arguments().immediate();
222
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000223 // Get the receiver of the function from the stack into r0.
224 __ ldr(r0, MemOperand(sp, argc * kPointerSize));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000225 // Check that the receiver isn't a smi.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000226 __ tst(r0, Operand(kSmiTagMask));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000227 __ b(eq, &miss);
228
229 // Do the right check and compute the holder register.
230 Register reg =
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000231 __ CheckMaps(JSObject::cast(object), r0, holder, r3, r2, &miss);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000232 GenerateFastPropertyLoad(masm(), r1, reg, holder, index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000233
234 // Check that the function really is a function.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000235 __ tst(r1, Operand(kSmiTagMask));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000236 __ b(eq, &miss);
237 // Get the map.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000238 __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000239 __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset));
240 __ cmp(r2, Operand(JS_FUNCTION_TYPE));
241 __ b(ne, &miss);
242
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000243 // Patch the receiver on the stack with the global proxy if
244 // necessary.
245 if (object->IsGlobalObject()) {
246 __ ldr(r3, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset));
247 __ str(r3, MemOperand(sp, argc * kPointerSize));
248 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000249
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000250 // Invoke the function.
251 __ InvokeFunction(r1, arguments(), JUMP_FUNCTION);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000252
253 // Handle call cache miss.
254 __ bind(&miss);
255 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000256 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000257
258 // Return the generated code.
259 return GetCode(FIELD);
260}
261
262
263Object* CallStubCompiler::CompileCallConstant(Object* object,
264 JSObject* holder,
265 JSFunction* function,
266 CheckType check) {
267 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000268 // -- lr: return address
269 // -----------------------------------
270
271 HandleScope scope;
272 Label miss;
273
mads.s.ager31e71382008-08-13 09:32:07 +0000274 // Get the receiver from the stack
275 const int argc = arguments().immediate();
276 __ ldr(r1, MemOperand(sp, argc * kPointerSize));
277
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000278 // Check that the receiver isn't a smi.
279 if (check != NUMBER_CHECK) {
280 __ tst(r1, Operand(kSmiTagMask));
281 __ b(eq, &miss);
282 }
283
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000284 // Make sure that it's okay not to patch the on stack receiver
285 // unless we're doing a receiver map check.
286 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
287
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000288 switch (check) {
289 case RECEIVER_MAP_CHECK:
290 // Check that the maps haven't changed.
291 __ CheckMaps(JSObject::cast(object), r1, holder, r3, r2, &miss);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000292
293 // Patch the receiver on the stack with the global proxy if
294 // necessary.
295 if (object->IsGlobalObject()) {
296 __ ldr(r3, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset));
297 __ str(r3, MemOperand(sp, argc * kPointerSize));
298 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000299 break;
300
301 case STRING_CHECK:
302 // Check that the object is a two-byte string or a symbol.
303 __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset));
304 __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset));
305 __ cmp(r2, Operand(FIRST_NONSTRING_TYPE));
306 __ b(hs, &miss);
307 // Check that the maps starting from the prototype haven't changed.
308 GenerateLoadGlobalFunctionPrototype(masm(),
309 Context::STRING_FUNCTION_INDEX,
310 r2);
311 __ CheckMaps(JSObject::cast(object->GetPrototype()),
312 r2, holder, r3, r1, &miss);
313 break;
314
315 case NUMBER_CHECK: {
316 Label fast;
317 // Check that the object is a smi or a heap number.
318 __ tst(r1, Operand(kSmiTagMask));
319 __ b(eq, &fast);
320 __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset));
321 __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset));
322 __ cmp(r2, Operand(HEAP_NUMBER_TYPE));
323 __ b(ne, &miss);
324 __ bind(&fast);
325 // Check that the maps starting from the prototype haven't changed.
326 GenerateLoadGlobalFunctionPrototype(masm(),
327 Context::NUMBER_FUNCTION_INDEX,
328 r2);
329 __ CheckMaps(JSObject::cast(object->GetPrototype()),
330 r2, holder, r3, r1, &miss);
331 break;
332 }
333
334 case BOOLEAN_CHECK: {
335 Label fast;
336 // Check that the object is a boolean.
337 __ cmp(r1, Operand(Factory::true_value()));
338 __ b(eq, &fast);
339 __ cmp(r1, Operand(Factory::false_value()));
340 __ b(ne, &miss);
341 __ bind(&fast);
342 // Check that the maps starting from the prototype haven't changed.
343 GenerateLoadGlobalFunctionPrototype(masm(),
344 Context::BOOLEAN_FUNCTION_INDEX,
345 r2);
346 __ CheckMaps(JSObject::cast(object->GetPrototype()),
347 r2, holder, r3, r1, &miss);
348 break;
349 }
350
351 case JSARRAY_HAS_FAST_ELEMENTS_CHECK:
352 __ CheckMaps(JSObject::cast(object), r1, holder, r3, r2, &miss);
353 // Make sure object->elements()->map() != Heap::hash_table_map()
354 // Get the elements array of the object.
355 __ ldr(r3, FieldMemOperand(r1, JSObject::kElementsOffset));
356 // Check that the object is in fast mode (not dictionary).
357 __ ldr(r2, FieldMemOperand(r3, HeapObject::kMapOffset));
358 __ cmp(r2, Operand(Factory::hash_table_map()));
359 __ b(eq, &miss);
360 break;
361
362 default:
363 UNREACHABLE();
364 }
365
366 // Get the function and setup the context.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000367 __ mov(r1, Operand(Handle<JSFunction>(function)));
368 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000369
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000370 // Jump to the cached code (tail call).
371 Handle<Code> code(function->code());
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000372 ParameterCount expected(function->shared()->formal_parameter_count());
ager@chromium.org236ad962008-09-25 09:45:57 +0000373 __ InvokeCode(code, expected, arguments(),
374 RelocInfo::CODE_TARGET, JUMP_FUNCTION);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000375
376 // Handle call cache miss.
377 __ bind(&miss);
378 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000379 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000380
381 // Return the generated code.
382 return GetCode(CONSTANT_FUNCTION);
383}
384
385
386Object* CallStubCompiler::CompileCallInterceptor(Object* object,
387 JSObject* holder,
388 String* name) {
389 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000390 // -- lr: return address
391 // -----------------------------------
392
393 HandleScope scope;
394 Label miss;
395
396 // TODO(1224669): Implement.
397
398 // Handle call cache miss.
399 __ bind(&miss);
400 Handle<Code> ic = ComputeCallMiss(arguments().immediate());
ager@chromium.org236ad962008-09-25 09:45:57 +0000401 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000402
403 // Return the generated code.
404 return GetCode(INTERCEPTOR);
405}
406
407
408Object* StoreStubCompiler::CompileStoreField(JSObject* object,
409 int index,
410 Map* transition,
411 String* name) {
412 // ----------- S t a t e -------------
413 // -- r0 : value
414 // -- r2 : name
415 // -- lr : return address
416 // -- [sp] : receiver
417 // -----------------------------------
418
419 HandleScope scope;
420 Label miss, exit;
421
422 // Get the receiver from the stack.
423 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
424
425 // Check that the receiver isn't a smi.
426 __ tst(r3, Operand(kSmiTagMask));
427 __ b(eq, &miss);
428
429 // Check that the map of the receiver hasn't changed.
430 __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset));
431 __ cmp(r1, Operand(Handle<Map>(object->map())));
432 __ b(ne, &miss);
433
434 // Perform global security token check if needed.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000435 if (object->IsJSGlobalProxy()) {
436 __ CheckAccessGlobalProxy(r3, r1, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000437 }
438
439 // Stub never generated for non-global objects that require access
440 // checks.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000441 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000442
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000443 // Perform map transition for the receiver if necessary.
kasperl@chromium.org1accd572008-10-07 10:57:21 +0000444 if ((transition != NULL) && (object->map()->unused_property_fields() == 0)) {
445 // The properties must be extended before we can store the value.
446 // We jump to a runtime call that extends the propeties array.
447 __ mov(r2, Operand(Handle<Map>(transition)));
448 // Please note, if we implement keyed store for arm we need
449 // to call the Builtins::KeyedStoreIC_ExtendStorage.
450 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_ExtendStorage));
451 __ Jump(ic, RelocInfo::CODE_TARGET);
452 } else {
ager@chromium.org7c537e22008-10-16 08:43:32 +0000453 // Adjust for the number of properties stored in the object. Even in the
454 // face of a transition we can use the old map here because the size of the
455 // object and the number of in-object properties is not going to change.
456 index -= object->map()->inobject_properties();
457
458 if (index >= 0) {
459 // Get the properties array
460 __ ldr(r1, FieldMemOperand(r3, JSObject::kPropertiesOffset));
461 }
kasperl@chromium.org1accd572008-10-07 10:57:21 +0000462
463 if (transition != NULL) {
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000464 // Update the map of the object; no write barrier updating is
465 // needed because the map is never in new space.
466 __ mov(ip, Operand(Handle<Map>(transition)));
467 __ str(ip, FieldMemOperand(r3, HeapObject::kMapOffset));
468 }
kasperl@chromium.org1accd572008-10-07 10:57:21 +0000469
ager@chromium.org7c537e22008-10-16 08:43:32 +0000470 if (index < 0) {
471 // Set the property straight into the object.
472 int offset = object->map()->instance_size() + (index * kPointerSize);
473 __ str(r0, FieldMemOperand(r3, offset));
kasperl@chromium.org1accd572008-10-07 10:57:21 +0000474
ager@chromium.org7c537e22008-10-16 08:43:32 +0000475 // Skip updating write barrier if storing a smi.
476 __ tst(r0, Operand(kSmiTagMask));
477 __ b(eq, &exit);
kasperl@chromium.org1accd572008-10-07 10:57:21 +0000478
ager@chromium.org7c537e22008-10-16 08:43:32 +0000479 // Update the write barrier for the array address.
480 __ mov(r1, Operand(offset));
481 __ RecordWrite(r3, r1, r2);
482 } else {
483 // Write to the properties array.
484 int offset = index * kPointerSize + Array::kHeaderSize;
485 __ str(r0, FieldMemOperand(r1, offset));
486
487 // Skip updating write barrier if storing a smi.
488 __ tst(r0, Operand(kSmiTagMask));
489 __ b(eq, &exit);
490
491 // Update the write barrier for the array address.
492 __ mov(r3, Operand(offset));
493 __ RecordWrite(r1, r3, r2); // OK to clobber r2, since we return
494 }
kasperl@chromium.org1accd572008-10-07 10:57:21 +0000495
496 // Return the value (register r0).
497 __ bind(&exit);
498 __ Ret();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000499 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000500 // Handle store cache miss.
501 __ bind(&miss);
502 __ mov(r2, Operand(Handle<String>(name))); // restore name
503 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000504 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000505
506 // Return the generated code.
507 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION);
508}
509
510
511Object* StoreStubCompiler::CompileStoreCallback(JSObject* object,
512 AccessorInfo* callback,
513 String* name) {
514 // ----------- S t a t e -------------
515 // -- r0 : value
516 // -- r2 : name
517 // -- lr : return address
518 // -- [sp] : receiver
519 // -----------------------------------
520
521 HandleScope scope;
522 Label miss;
523
524 // Get the object from the stack.
525 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
526
527 // Check that the object isn't a smi.
528 __ tst(r3, Operand(kSmiTagMask));
529 __ b(eq, &miss);
530
531 // Check that the map of the object hasn't changed.
532 __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset));
533 __ cmp(r1, Operand(Handle<Map>(object->map())));
534 __ b(ne, &miss);
535
536 // Perform global security token check if needed.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000537 if (object->IsJSGlobalProxy()) {
538 __ CheckAccessGlobalProxy(r3, r1, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000539 }
540
541 // Stub never generated for non-global objects that require access
542 // checks.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000543 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000544
545 __ ldr(ip, MemOperand(sp)); // receiver
546 __ push(ip);
547 __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback info
548 __ push(ip);
549 __ push(r2); // name
550 __ push(r0); // value
551
mads.s.ager31e71382008-08-13 09:32:07 +0000552 // Do tail-call to the runtime system.
553 ExternalReference store_callback_property =
554 ExternalReference(IC_Utility(IC::kStoreCallbackProperty));
555 __ TailCallRuntime(store_callback_property, 4);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000556
557 // Handle store cache miss.
558 __ bind(&miss);
559 __ mov(r2, Operand(Handle<String>(name))); // restore name
560 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000561 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000562
563 // Return the generated code.
564 return GetCode(CALLBACKS);
565}
566
567
568Object* StoreStubCompiler::CompileStoreInterceptor(JSObject* receiver,
569 String* name) {
570 // ----------- S t a t e -------------
571 // -- r0 : value
572 // -- r2 : name
573 // -- lr : return address
574 // -- [sp] : receiver
575 // -----------------------------------
576
577 HandleScope scope;
578 Label miss;
579
580 // Get the object from the stack.
581 __ ldr(r3, MemOperand(sp, 0 * kPointerSize));
582
583 // Check that the object isn't a smi.
584 __ tst(r3, Operand(kSmiTagMask));
585 __ b(eq, &miss);
586
587 // Check that the map of the object hasn't changed.
588 __ ldr(r1, FieldMemOperand(r3, HeapObject::kMapOffset));
589 __ cmp(r1, Operand(Handle<Map>(receiver->map())));
590 __ b(ne, &miss);
591
592 // Perform global security token check if needed.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000593 if (receiver->IsJSGlobalProxy()) {
594 __ CheckAccessGlobalProxy(r3, r1, &miss);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000595 }
596
597 // Stub never generated for non-global objects that require access
598 // checks.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000599 ASSERT(receiver->IsJSGlobalProxy() || !receiver->IsAccessCheckNeeded());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000600
601 __ ldr(ip, MemOperand(sp)); // receiver
602 __ push(ip);
603 __ push(r2); // name
604 __ push(r0); // value
605
mads.s.ager31e71382008-08-13 09:32:07 +0000606 // Do tail-call to the runtime system.
607 ExternalReference store_ic_property =
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000608 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty));
mads.s.ager31e71382008-08-13 09:32:07 +0000609 __ TailCallRuntime(store_ic_property, 3);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000610
611 // Handle store cache miss.
612 __ bind(&miss);
613 __ mov(r2, Operand(Handle<String>(name))); // restore name
614 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000615 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000616
617 // Return the generated code.
618 return GetCode(INTERCEPTOR);
619}
620
621
622Object* LoadStubCompiler::CompileLoadField(JSObject* object,
623 JSObject* holder,
624 int index) {
625 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000626 // -- r2 : name
627 // -- lr : return address
628 // -- [sp] : receiver
629 // -----------------------------------
630
631 HandleScope scope;
632 Label miss;
633
mads.s.ager31e71382008-08-13 09:32:07 +0000634 __ ldr(r0, MemOperand(sp, 0));
635
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000636 // Check that the receiver isn't a smi.
637 __ tst(r0, Operand(kSmiTagMask));
638 __ b(eq, &miss);
639
640 // Check that the maps haven't changed.
641 Register reg = __ CheckMaps(object, r0, holder, r3, r1, &miss);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000642 GenerateFastPropertyLoad(masm(), r0, reg, holder, index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000643 __ Ret();
644
645 // Handle load cache miss.
646 __ bind(&miss);
647 __ ldr(r0, MemOperand(sp)); // restore receiver
648 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000649 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000650
651 // Return the generated code.
652 return GetCode(FIELD);
653}
654
655
656Object* LoadStubCompiler::CompileLoadCallback(JSObject* object,
657 JSObject* holder,
658 AccessorInfo* callback) {
659 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000660 // -- r2 : name
661 // -- lr : return address
662 // -- [sp] : receiver
663 // -----------------------------------
664
665 HandleScope scope;
666 Label miss;
667
mads.s.ager31e71382008-08-13 09:32:07 +0000668 __ ldr(r0, MemOperand(sp, 0));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000669 // Check that the receiver isn't a smi.
670 __ tst(r0, Operand(kSmiTagMask));
671 __ b(eq, &miss);
672
673 // Check that the maps haven't changed.
674 Register reg = __ CheckMaps(object, r0, holder, r3, r1, &miss);
675
676 // Push the arguments on the JS stack of the caller.
677 __ push(r0); // receiver
678 __ mov(ip, Operand(Handle<AccessorInfo>(callback))); // callback data
679 __ push(ip);
680 __ push(r2); // name
681 __ push(reg); // holder
682
mads.s.ager31e71382008-08-13 09:32:07 +0000683 // Do tail-call to the runtime system.
684 ExternalReference load_callback_property =
685 ExternalReference(IC_Utility(IC::kLoadCallbackProperty));
686 __ TailCallRuntime(load_callback_property, 4);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000687
688 // Handle load cache miss.
689 __ bind(&miss);
690 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000691 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000692
693 // Return the generated code.
694 return GetCode(CALLBACKS);
695}
696
697
698Object* LoadStubCompiler::CompileLoadConstant(JSObject* object,
699 JSObject* holder,
700 Object* value) {
701 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000702 // -- r2 : name
703 // -- lr : return address
704 // -- [sp] : receiver
705 // -----------------------------------
706
707 HandleScope scope;
708 Label miss;
709
mads.s.ager31e71382008-08-13 09:32:07 +0000710 __ ldr(r0, MemOperand(sp, 0));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000711 // Check that the receiver isn't a smi.
712 __ tst(r0, Operand(kSmiTagMask));
713 __ b(eq, &miss);
714
715 // Check that the maps haven't changed.
716 Register reg = __ CheckMaps(object, r0, holder, r3, r1, &miss);
717
718 // Return the constant value.
719 __ mov(r0, Operand(Handle<Object>(value)));
720 __ Ret();
721
722 // Handle load cache miss.
723 __ bind(&miss);
724 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000725 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000726
727 // Return the generated code.
728 return GetCode(CONSTANT_FUNCTION);
729}
730
731
732Object* LoadStubCompiler::CompileLoadInterceptor(JSObject* object,
733 JSObject* holder,
734 String* name) {
735 // ----------- S t a t e -------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000736 // -- r2 : name
737 // -- lr : return address
738 // -- [sp] : receiver
739 // -----------------------------------
740
741 HandleScope scope;
742 Label miss;
743
mads.s.ager31e71382008-08-13 09:32:07 +0000744 __ ldr(r0, MemOperand(sp, 0));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000745 // Check that the receiver isn't a smi.
746 __ tst(r0, Operand(kSmiTagMask));
747 __ b(eq, &miss);
748
749 // Check that the maps haven't changed.
750 Register reg = __ CheckMaps(object, r0, holder, r3, r1, &miss);
751
752 // Push the arguments on the JS stack of the caller.
753 __ push(r0); // receiver
754 __ push(reg); // holder
755 __ push(r2); // name
756
mads.s.ager31e71382008-08-13 09:32:07 +0000757 // Do tail-call to the runtime system.
758 ExternalReference load_ic_property =
759 ExternalReference(IC_Utility(IC::kLoadInterceptorProperty));
760 __ TailCallRuntime(load_ic_property, 3);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000761
762 // Handle load cache miss.
763 __ bind(&miss);
764 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Miss));
ager@chromium.org236ad962008-09-25 09:45:57 +0000765 __ Jump(ic, RelocInfo::CODE_TARGET);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000766
767 // Return the generated code.
768 return GetCode(INTERCEPTOR);
769}
770
771
772// TODO(1224671): IC stubs for keyed loads have not been implemented
773// for ARM.
774Object* KeyedLoadStubCompiler::CompileLoadField(String* name,
775 JSObject* receiver,
776 JSObject* holder,
777 int index) {
778 UNIMPLEMENTED();
779 return Heap::undefined_value();
780}
781
782
783Object* KeyedLoadStubCompiler::CompileLoadCallback(String* name,
784 JSObject* receiver,
785 JSObject* holder,
786 AccessorInfo* callback) {
787 UNIMPLEMENTED();
788 return Heap::undefined_value();
789}
790
791
792Object* KeyedLoadStubCompiler::CompileLoadConstant(String* name,
793 JSObject* receiver,
794 JSObject* holder,
795 Object* value) {
796 UNIMPLEMENTED();
797 return Heap::undefined_value();
798}
799
800
801Object* KeyedLoadStubCompiler::CompileLoadInterceptor(JSObject* receiver,
802 JSObject* holder,
803 String* name) {
804 UNIMPLEMENTED();
805 return Heap::undefined_value();
806}
807
808
809Object* KeyedLoadStubCompiler::CompileLoadArrayLength(String* name) {
810 UNIMPLEMENTED();
811 return Heap::undefined_value();
812}
813
814
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000815Object* KeyedLoadStubCompiler::CompileLoadStringLength(String* name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000816 UNIMPLEMENTED();
817 return Heap::undefined_value();
818}
819
820
821Object* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) {
822 UNIMPLEMENTED();
823 return Heap::undefined_value();
824}
825
826
827Object* KeyedStoreStubCompiler::CompileStoreField(JSObject* object,
828 int index,
829 Map* transition,
830 String* name) {
831 UNIMPLEMENTED();
832 return Heap::undefined_value();
833}
834
835
836
837#undef __
838
839} } // namespace v8::internal