blob: 7e7a3f77e6fe4948e441d4a73490fea612e2a262 [file] [log] [blame]
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001// Copyright 2012 the V8 project authors. All rights reserved.
ager@chromium.org5c838252010-02-19 08:53:10 +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
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +000030#if defined(V8_TARGET_ARCH_MIPS)
31
ager@chromium.org5c838252010-02-19 08:53:10 +000032#include "ic-inl.h"
karlklose@chromium.org83a47282011-05-11 11:54:09 +000033#include "codegen.h"
ager@chromium.org5c838252010-02-19 08:53:10 +000034#include "stub-cache.h"
35
36namespace v8 {
37namespace internal {
38
39#define __ ACCESS_MASM(masm)
40
41
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000042static void ProbeTable(Isolate* isolate,
43 MacroAssembler* masm,
44 Code::Flags flags,
45 StubCache::Table table,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000046 Register receiver,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000047 Register name,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000048 // Number of the cache entry, not scaled.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000049 Register offset,
50 Register scratch,
fschneider@chromium.org35814e52012-03-01 15:43:35 +000051 Register scratch2,
52 Register offset_scratch) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000053 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
54 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
fschneider@chromium.org35814e52012-03-01 15:43:35 +000055 ExternalReference map_offset(isolate->stub_cache()->map_reference(table));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000056
57 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address());
58 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address());
fschneider@chromium.org35814e52012-03-01 15:43:35 +000059 uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000060
61 // Check the relative positions of the address fields.
62 ASSERT(value_off_addr > key_off_addr);
63 ASSERT((value_off_addr - key_off_addr) % 4 == 0);
64 ASSERT((value_off_addr - key_off_addr) < (256 * 4));
fschneider@chromium.org35814e52012-03-01 15:43:35 +000065 ASSERT(map_off_addr > key_off_addr);
66 ASSERT((map_off_addr - key_off_addr) % 4 == 0);
67 ASSERT((map_off_addr - key_off_addr) < (256 * 4));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000068
69 Label miss;
fschneider@chromium.org35814e52012-03-01 15:43:35 +000070 Register base_addr = scratch;
71 scratch = no_reg;
72
73 // Multiply by 3 because there are 3 fields per entry (name, code, map).
74 __ sll(offset_scratch, offset, 1);
75 __ Addu(offset_scratch, offset_scratch, offset);
76
77 // Calculate the base address of the entry.
78 __ li(base_addr, Operand(key_offset));
79 __ sll(at, offset_scratch, kPointerSizeLog2);
80 __ Addu(base_addr, base_addr, at);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000081
82 // Check that the key in the entry matches the name.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000083 __ lw(at, MemOperand(base_addr, 0));
84 __ Branch(&miss, ne, name, Operand(at));
85
86 // Check the map matches.
87 __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr));
88 __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset));
89 __ Branch(&miss, ne, at, Operand(scratch2));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000090
91 // Get the code entry from the cache.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000092 Register code = scratch2;
93 scratch2 = no_reg;
94 __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000095
96 // Check that the flags match what we're looking for.
fschneider@chromium.org35814e52012-03-01 15:43:35 +000097 Register flags_reg = base_addr;
98 base_addr = no_reg;
99 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset));
100 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup));
101 __ Branch(&miss, ne, flags_reg, Operand(flags));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000102
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000103#ifdef DEBUG
104 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
105 __ jmp(&miss);
106 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
107 __ jmp(&miss);
108 }
109#endif
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000110
111 // Jump to the first instruction in the code stub.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000112 __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag));
113 __ Jump(at);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000114
115 // Miss: fall through.
116 __ bind(&miss);
117}
118
119
120// Helper function used to check that the dictionary doesn't contain
121// the property. This function may return false negatives, so miss_label
122// must always call a backup property check that is complete.
123// This function is safe to call if the receiver has fast properties.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000124// Name must be unique and receiver must be a heap object.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000125static void GenerateDictionaryNegativeLookup(MacroAssembler* masm,
126 Label* miss_label,
127 Register receiver,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000128 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000129 Register scratch0,
130 Register scratch1) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000131 ASSERT(name->IsUniqueName());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000132 Counters* counters = masm->isolate()->counters();
133 __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
134 __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
135
136 Label done;
137
138 const int kInterceptorOrAccessCheckNeededMask =
139 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
140
141 // Bail out if the receiver has a named interceptor or requires access checks.
142 Register map = scratch1;
143 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
144 __ lbu(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
145 __ And(scratch0, scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
146 __ Branch(miss_label, ne, scratch0, Operand(zero_reg));
147
148 // Check that receiver is a JSObject.
149 __ lbu(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
150 __ Branch(miss_label, lt, scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
151
152 // Load properties array.
153 Register properties = scratch0;
154 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
155 // Check that the properties array is a dictionary.
156 __ lw(map, FieldMemOperand(properties, HeapObject::kMapOffset));
157 Register tmp = properties;
158 __ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
159 __ Branch(miss_label, ne, map, Operand(tmp));
160
161 // Restore the temporarily used register.
162 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
163
164
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000165 NameDictionaryLookupStub::GenerateNegativeLookup(masm,
166 miss_label,
167 &done,
168 receiver,
169 properties,
170 name,
171 scratch1);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000172 __ bind(&done);
173 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
174}
175
176
ager@chromium.org5c838252010-02-19 08:53:10 +0000177void StubCache::GenerateProbe(MacroAssembler* masm,
178 Code::Flags flags,
179 Register receiver,
180 Register name,
181 Register scratch,
fschneider@chromium.orge03fb642010-11-01 12:34:09 +0000182 Register extra,
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000183 Register extra2,
184 Register extra3) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000185 Isolate* isolate = masm->isolate();
186 Label miss;
187
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000188 // Make sure that code is valid. The multiplying code relies on the
189 // entry size being 12.
190 ASSERT(sizeof(Entry) == 12);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000191
192 // Make sure the flags does not name a specific type.
193 ASSERT(Code::ExtractTypeFromFlags(flags) == 0);
194
195 // Make sure that there are no register conflicts.
196 ASSERT(!scratch.is(receiver));
197 ASSERT(!scratch.is(name));
198 ASSERT(!extra.is(receiver));
199 ASSERT(!extra.is(name));
200 ASSERT(!extra.is(scratch));
201 ASSERT(!extra2.is(receiver));
202 ASSERT(!extra2.is(name));
203 ASSERT(!extra2.is(scratch));
204 ASSERT(!extra2.is(extra));
205
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000206 // Check register validity.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000207 ASSERT(!scratch.is(no_reg));
208 ASSERT(!extra.is(no_reg));
209 ASSERT(!extra2.is(no_reg));
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000210 ASSERT(!extra3.is(no_reg));
211
212 Counters* counters = masm->isolate()->counters();
213 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1,
214 extra2, extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000215
216 // Check that the receiver isn't a smi.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000217 __ JumpIfSmi(receiver, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000218
219 // Get the map of the receiver and compute the hash.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000220 __ lw(scratch, FieldMemOperand(name, Name::kHashFieldOffset));
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000221 __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset));
222 __ Addu(scratch, scratch, at);
223 uint32_t mask = kPrimaryTableSize - 1;
224 // We shift out the last two bits because they are not part of the hash and
225 // they are always 01 for maps.
226 __ srl(scratch, scratch, kHeapObjectTagSize);
227 __ Xor(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask));
228 __ And(scratch, scratch, Operand(mask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000229
230 // Probe the primary table.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000231 ProbeTable(isolate,
232 masm,
233 flags,
234 kPrimary,
235 receiver,
236 name,
237 scratch,
238 extra,
239 extra2,
240 extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000241
242 // Primary miss: Compute hash for secondary probe.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000243 __ srl(at, name, kHeapObjectTagSize);
244 __ Subu(scratch, scratch, at);
245 uint32_t mask2 = kSecondaryTableSize - 1;
246 __ Addu(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask2));
247 __ And(scratch, scratch, Operand(mask2));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000248
249 // Probe the secondary table.
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000250 ProbeTable(isolate,
251 masm,
252 flags,
253 kSecondary,
254 receiver,
255 name,
256 scratch,
257 extra,
258 extra2,
259 extra3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000260
261 // Cache miss: Fall-through and let caller handle the miss by
262 // entering the runtime system.
263 __ bind(&miss);
fschneider@chromium.org35814e52012-03-01 15:43:35 +0000264 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1,
265 extra2, extra3);
ager@chromium.org5c838252010-02-19 08:53:10 +0000266}
267
268
269void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm,
270 int index,
271 Register prototype) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000272 // Load the global or builtins object from the current context.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000273 __ lw(prototype,
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000274 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
275 // Load the native context from the global or builtins object.
276 __ lw(prototype,
277 FieldMemOperand(prototype, GlobalObject::kNativeContextOffset));
278 // Load the function from the native context.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000279 __ lw(prototype, MemOperand(prototype, Context::SlotOffset(index)));
280 // Load the initial map. The global functions all have initial maps.
281 __ lw(prototype,
282 FieldMemOperand(prototype, JSFunction::kPrototypeOrInitialMapOffset));
283 // Load the prototype from the initial map.
284 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000285}
286
287
lrn@chromium.org7516f052011-03-30 08:52:27 +0000288void StubCompiler::GenerateDirectLoadGlobalFunctionPrototype(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000289 MacroAssembler* masm,
290 int index,
291 Register prototype,
292 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000293 Isolate* isolate = masm->isolate();
294 // Check we're still in the same context.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000295 __ lw(prototype,
296 MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000297 ASSERT(!prototype.is(at));
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000298 __ li(at, isolate->global_object());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000299 __ Branch(miss, ne, prototype, Operand(at));
300 // Get the global function with the given index.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000301 Handle<JSFunction> function(
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000302 JSFunction::cast(isolate->native_context()->get(index)));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000303 // Load its initial map. The global functions all have initial maps.
304 __ li(prototype, Handle<Map>(function->initial_map()));
305 // Load the prototype from the initial map.
306 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000307}
308
309
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000310void StubCompiler::GenerateFastPropertyLoad(MacroAssembler* masm,
311 Register dst,
312 Register src,
313 bool inobject,
314 int index,
315 Representation representation) {
316 ASSERT(!FLAG_track_double_fields || !representation.IsDouble());
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000317 int offset = index * kPointerSize;
318 if (!inobject) {
319 // Calculate the offset into the properties array.
320 offset = offset + FixedArray::kHeaderSize;
321 __ lw(dst, FieldMemOperand(src, JSObject::kPropertiesOffset));
322 src = dst;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000323 }
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000324 __ lw(dst, FieldMemOperand(src, offset));
ager@chromium.org5c838252010-02-19 08:53:10 +0000325}
326
327
328void StubCompiler::GenerateLoadArrayLength(MacroAssembler* masm,
329 Register receiver,
330 Register scratch,
331 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000332 // Check that the receiver isn't a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000333 __ JumpIfSmi(receiver, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000334
335 // Check that the object is a JS array.
336 __ GetObjectType(receiver, scratch, scratch);
337 __ Branch(miss_label, ne, scratch, Operand(JS_ARRAY_TYPE));
338
339 // Load length directly from the JS array.
340 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
341 __ Ret();
342}
343
344
345// Generate code to check if an object is a string. If the object is a
346// heap object, its map's instance type is left in the scratch1 register.
347// If this is not needed, scratch1 and scratch2 may be the same register.
348static void GenerateStringCheck(MacroAssembler* masm,
349 Register receiver,
350 Register scratch1,
351 Register scratch2,
352 Label* smi,
353 Label* non_string_object) {
354 // Check that the receiver isn't a smi.
355 __ JumpIfSmi(receiver, smi, t0);
356
357 // Check that the object is a string.
358 __ lw(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
359 __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
360 __ And(scratch2, scratch1, Operand(kIsNotStringMask));
361 // The cast is to resolve the overload for the argument of 0x0.
362 __ Branch(non_string_object,
363 ne,
364 scratch2,
365 Operand(static_cast<int32_t>(kStringTag)));
ager@chromium.org5c838252010-02-19 08:53:10 +0000366}
367
368
lrn@chromium.org7516f052011-03-30 08:52:27 +0000369// Generate code to load the length from a string object and return the length.
370// If the receiver object is not a string or a wrapped string object the
371// execution continues at the miss label. The register containing the
372// receiver is potentially clobbered.
373void StubCompiler::GenerateLoadStringLength(MacroAssembler* masm,
374 Register receiver,
375 Register scratch1,
376 Register scratch2,
377 Label* miss,
378 bool support_wrappers) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000379 Label check_wrapper;
380
381 // Check if the object is a string leaving the instance type in the
382 // scratch1 register.
383 GenerateStringCheck(masm, receiver, scratch1, scratch2, miss,
384 support_wrappers ? &check_wrapper : miss);
385
386 // Load length directly from the string.
387 __ lw(v0, FieldMemOperand(receiver, String::kLengthOffset));
388 __ Ret();
389
390 if (support_wrappers) {
391 // Check if the object is a JSValue wrapper.
392 __ bind(&check_wrapper);
393 __ Branch(miss, ne, scratch1, Operand(JS_VALUE_TYPE));
394
395 // Unwrap the value and check if the wrapped value is a string.
396 __ lw(scratch1, FieldMemOperand(receiver, JSValue::kValueOffset));
397 GenerateStringCheck(masm, scratch1, scratch2, scratch2, miss, miss);
398 __ lw(v0, FieldMemOperand(scratch1, String::kLengthOffset));
399 __ Ret();
400 }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000401}
402
403
ager@chromium.org5c838252010-02-19 08:53:10 +0000404void StubCompiler::GenerateLoadFunctionPrototype(MacroAssembler* masm,
405 Register receiver,
406 Register scratch1,
407 Register scratch2,
408 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000409 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
410 __ mov(v0, scratch1);
411 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000412}
413
414
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000415// Generate code to check that a global property cell is empty. Create
416// the property cell at compilation time if no cell exists for the
417// property.
418static void GenerateCheckPropertyCell(MacroAssembler* masm,
419 Handle<GlobalObject> global,
420 Handle<Name> name,
421 Register scratch,
422 Label* miss) {
423 Handle<JSGlobalPropertyCell> cell =
424 GlobalObject::EnsurePropertyCell(global, name);
425 ASSERT(cell->value()->IsTheHole());
426 __ li(scratch, Operand(cell));
427 __ lw(scratch,
428 FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
429 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
430 __ Branch(miss, ne, scratch, Operand(at));
431}
432
433
434// Generate StoreTransition code, value is passed in a0 register.
ager@chromium.org5c838252010-02-19 08:53:10 +0000435// After executing generated code, the receiver_reg and name_reg
436// may be clobbered.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000437void StubCompiler::GenerateStoreTransition(MacroAssembler* masm,
438 Handle<JSObject> object,
439 LookupResult* lookup,
440 Handle<Map> transition,
441 Handle<Name> name,
442 Register receiver_reg,
443 Register name_reg,
444 Register value_reg,
445 Register scratch1,
446 Register scratch2,
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000447 Register scratch3,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000448 Label* miss_label,
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000449 Label* miss_restore_name,
450 Label* slow) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000451 // a0 : value.
452 Label exit;
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000453
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000454 // Check that the map of the object hasn't changed.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000455 __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000456 DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000457
458 // Perform global security token check if needed.
459 if (object->IsJSGlobalProxy()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000460 __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label);
461 }
462
danno@chromium.orgf005df62013-04-30 16:36:45 +0000463 int descriptor = transition->LastAdded();
464 DescriptorArray* descriptors = transition->instance_descriptors();
465 PropertyDetails details = descriptors->GetDetails(descriptor);
466 Representation representation = details.representation();
467 ASSERT(!representation.IsNone());
468
469 // Ensure no transitions to deprecated maps are followed.
470 __ CheckMapDeprecated(transition, scratch1, miss_label);
471
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000472 // Check that we are allowed to write this.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000473 if (object->GetPrototype()->IsJSObject()) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000474 JSObject* holder;
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000475 // holder == object indicates that no property was found.
476 if (lookup->holder() != *object) {
477 holder = lookup->holder();
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000478 } else {
479 // Find the top object.
480 holder = *object;
481 do {
482 holder = JSObject::cast(holder->GetPrototype());
483 } while (holder->GetPrototype()->IsJSObject());
484 }
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000485 Register holder_reg = CheckPrototypes(
486 object, receiver_reg, Handle<JSObject>(holder), name_reg,
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000487 scratch1, scratch2, name, miss_restore_name, SKIP_RECEIVER);
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000488 // If no property was found, and the holder (the last object in the
489 // prototype chain) is in slow mode, we need to do a negative lookup on the
490 // holder.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000491 if (lookup->holder() == *object) {
492 if (holder->IsJSGlobalObject()) {
493 GenerateCheckPropertyCell(
494 masm,
495 Handle<GlobalObject>(GlobalObject::cast(holder)),
496 name,
497 scratch1,
498 miss_restore_name);
499 } else if (!holder->HasFastProperties() && !holder->IsJSGlobalProxy()) {
500 GenerateDictionaryNegativeLookup(
501 masm, miss_restore_name, holder_reg, name, scratch1, scratch2);
502 }
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000503 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000504 }
505
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000506 Register storage_reg = name_reg;
507
508 if (FLAG_track_fields && representation.IsSmi()) {
509 __ JumpIfNotSmi(value_reg, miss_restore_name);
ulan@chromium.org906e2fb2013-05-14 08:14:38 +0000510 } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) {
511 __ JumpIfSmi(value_reg, miss_restore_name);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000512 } else if (FLAG_track_double_fields && representation.IsDouble()) {
513 Label do_store, heap_number;
514 __ LoadRoot(scratch3, Heap::kHeapNumberMapRootIndex);
515 __ AllocateHeapNumber(storage_reg, scratch1, scratch2, scratch3, slow);
516
517 __ JumpIfNotSmi(value_reg, &heap_number);
518 __ SmiUntag(scratch1, value_reg);
519 __ mtc1(scratch1, f6);
520 __ cvt_d_w(f4, f6);
521 __ jmp(&do_store);
522
523 __ bind(&heap_number);
524 __ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex,
525 miss_restore_name, DONT_DO_SMI_CHECK);
526 __ ldc1(f4, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
527
528 __ bind(&do_store);
529 __ sdc1(f4, FieldMemOperand(storage_reg, HeapNumber::kValueOffset));
530 }
531
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000532 // Stub never generated for non-global objects that require access
533 // checks.
534 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
535
536 // Perform map transition for the receiver if necessary.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000537 if (object->map()->unused_property_fields() == 0) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000538 // The properties must be extended before we can store the value.
539 // We jump to a runtime call that extends the properties array.
540 __ push(receiver_reg);
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +0000541 __ li(a2, Operand(transition));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000542 __ Push(a2, a0);
543 __ TailCallExternalReference(
544 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
545 masm->isolate()),
546 3, 1);
547 return;
548 }
549
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000550 // Update the map of the object.
551 __ li(scratch1, Operand(transition));
552 __ sw(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
verwaest@chromium.org37141392012-05-31 13:27:02 +0000553
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000554 // Update the write barrier for the map field and pass the now unused
555 // name_reg as scratch register.
556 __ RecordWriteField(receiver_reg,
557 HeapObject::kMapOffset,
558 scratch1,
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000559 scratch2,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000560 kRAHasNotBeenSaved,
561 kDontSaveFPRegs,
562 OMIT_REMEMBERED_SET,
563 OMIT_SMI_CHECK);
564
565 int index = transition->instance_descriptors()->GetFieldIndex(
566 transition->LastAdded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000567
568 // Adjust for the number of properties stored in the object. Even in the
569 // face of a transition we can use the old map here because the size of the
570 // object and the number of in-object properties is not going to change.
571 index -= object->map()->inobject_properties();
572
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000573 // TODO(verwaest): Share this code as a code stub.
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000574 SmiCheck smi_check = representation.IsTagged()
575 ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000576 if (index < 0) {
577 // Set the property straight into the object.
578 int offset = object->map()->instance_size() + (index * kPointerSize);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000579 if (FLAG_track_double_fields && representation.IsDouble()) {
580 __ sw(storage_reg, FieldMemOperand(receiver_reg, offset));
581 } else {
582 __ sw(value_reg, FieldMemOperand(receiver_reg, offset));
583 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000584
danno@chromium.orgf005df62013-04-30 16:36:45 +0000585 if (!FLAG_track_fields || !representation.IsSmi()) {
586 // Skip updating write barrier if storing a smi.
587 __ JumpIfSmi(value_reg, &exit);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000588
danno@chromium.orgf005df62013-04-30 16:36:45 +0000589 // Update the write barrier for the array address.
590 // Pass the now unused name_reg as a scratch register.
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000591 if (!FLAG_track_double_fields || !representation.IsDouble()) {
592 __ mov(name_reg, value_reg);
593 } else {
594 ASSERT(storage_reg.is(name_reg));
595 }
danno@chromium.orgf005df62013-04-30 16:36:45 +0000596 __ RecordWriteField(receiver_reg,
597 offset,
598 name_reg,
599 scratch1,
600 kRAHasNotBeenSaved,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000601 kDontSaveFPRegs,
602 EMIT_REMEMBERED_SET,
603 smi_check);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000604 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000605 } else {
606 // Write to the properties array.
607 int offset = index * kPointerSize + FixedArray::kHeaderSize;
608 // Get the properties array
609 __ lw(scratch1,
610 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000611 if (FLAG_track_double_fields && representation.IsDouble()) {
612 __ sw(storage_reg, FieldMemOperand(scratch1, offset));
613 } else {
614 __ sw(value_reg, FieldMemOperand(scratch1, offset));
615 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000616
danno@chromium.orgf005df62013-04-30 16:36:45 +0000617 if (!FLAG_track_fields || !representation.IsSmi()) {
618 // Skip updating write barrier if storing a smi.
619 __ JumpIfSmi(value_reg, &exit);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000620
danno@chromium.orgf005df62013-04-30 16:36:45 +0000621 // Update the write barrier for the array address.
622 // Ok to clobber receiver_reg and name_reg, since we return.
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000623 if (!FLAG_track_double_fields || !representation.IsDouble()) {
624 __ mov(name_reg, value_reg);
625 } else {
626 ASSERT(storage_reg.is(name_reg));
627 }
danno@chromium.orgf005df62013-04-30 16:36:45 +0000628 __ RecordWriteField(scratch1,
629 offset,
630 name_reg,
631 receiver_reg,
632 kRAHasNotBeenSaved,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000633 kDontSaveFPRegs,
634 EMIT_REMEMBERED_SET,
635 smi_check);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000636 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000637 }
638
639 // Return the value (register v0).
640 ASSERT(value_reg.is(a0));
641 __ bind(&exit);
642 __ mov(v0, a0);
643 __ Ret();
644}
645
646
647// Generate StoreField code, value is passed in a0 register.
648// When leaving generated code after success, the receiver_reg and name_reg
649// may be clobbered. Upon branch to miss_label, the receiver and name
650// registers have their original values.
651void StubCompiler::GenerateStoreField(MacroAssembler* masm,
652 Handle<JSObject> object,
653 LookupResult* lookup,
654 Register receiver_reg,
655 Register name_reg,
656 Register value_reg,
657 Register scratch1,
658 Register scratch2,
659 Label* miss_label) {
660 // a0 : value
661 Label exit;
662
663 // Check that the map of the object hasn't changed.
664 __ CheckMap(receiver_reg, scratch1, Handle<Map>(object->map()), miss_label,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000665 DO_SMI_CHECK);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000666
667 // Perform global security token check if needed.
668 if (object->IsJSGlobalProxy()) {
669 __ CheckAccessGlobalProxy(receiver_reg, scratch1, miss_label);
670 }
671
672 // Stub never generated for non-global objects that require access
673 // checks.
674 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
675
676 int index = lookup->GetFieldIndex().field_index();
677
678 // Adjust for the number of properties stored in the object. Even in the
679 // face of a transition we can use the old map here because the size of the
680 // object and the number of in-object properties is not going to change.
681 index -= object->map()->inobject_properties();
682
danno@chromium.orgf005df62013-04-30 16:36:45 +0000683 Representation representation = lookup->representation();
684 ASSERT(!representation.IsNone());
685 if (FLAG_track_fields && representation.IsSmi()) {
686 __ JumpIfNotSmi(value_reg, miss_label);
ulan@chromium.org906e2fb2013-05-14 08:14:38 +0000687 } else if (FLAG_track_heap_object_fields && representation.IsHeapObject()) {
688 __ JumpIfSmi(value_reg, miss_label);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000689 } else if (FLAG_track_double_fields && representation.IsDouble()) {
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000690 // Load the double storage.
691 if (index < 0) {
692 int offset = object->map()->instance_size() + (index * kPointerSize);
693 __ lw(scratch1, FieldMemOperand(receiver_reg, offset));
694 } else {
695 __ lw(scratch1,
696 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
697 int offset = index * kPointerSize + FixedArray::kHeaderSize;
698 __ lw(scratch1, FieldMemOperand(scratch1, offset));
699 }
700
701 // Store the value into the storage.
702 Label do_store, heap_number;
703 __ JumpIfNotSmi(value_reg, &heap_number);
704 __ SmiUntag(scratch2, value_reg);
705 __ mtc1(scratch2, f6);
706 __ cvt_d_w(f4, f6);
707 __ jmp(&do_store);
708
709 __ bind(&heap_number);
710 __ CheckMap(value_reg, scratch2, Heap::kHeapNumberMapRootIndex,
danno@chromium.orgf005df62013-04-30 16:36:45 +0000711 miss_label, DONT_DO_SMI_CHECK);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000712 __ ldc1(f4, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
713
danno@chromium.orgf005df62013-04-30 16:36:45 +0000714 __ bind(&do_store);
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000715 __ sdc1(f4, FieldMemOperand(scratch1, HeapNumber::kValueOffset));
716 // Return the value (register v0).
717 ASSERT(value_reg.is(a0));
718 __ mov(v0, a0);
719 __ Ret();
720 return;
danno@chromium.orgf005df62013-04-30 16:36:45 +0000721 }
722
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000723 // TODO(verwaest): Share this code as a code stub.
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000724 SmiCheck smi_check = representation.IsTagged()
725 ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000726 if (index < 0) {
727 // Set the property straight into the object.
728 int offset = object->map()->instance_size() + (index * kPointerSize);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000729 __ sw(value_reg, FieldMemOperand(receiver_reg, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000730
danno@chromium.orgf005df62013-04-30 16:36:45 +0000731 if (!FLAG_track_fields || !representation.IsSmi()) {
732 // Skip updating write barrier if storing a smi.
733 __ JumpIfSmi(value_reg, &exit);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000734
danno@chromium.orgf005df62013-04-30 16:36:45 +0000735 // Update the write barrier for the array address.
736 // Pass the now unused name_reg as a scratch register.
737 __ mov(name_reg, value_reg);
738 __ RecordWriteField(receiver_reg,
739 offset,
740 name_reg,
741 scratch1,
742 kRAHasNotBeenSaved,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000743 kDontSaveFPRegs,
744 EMIT_REMEMBERED_SET,
745 smi_check);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000746 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000747 } else {
748 // Write to the properties array.
749 int offset = index * kPointerSize + FixedArray::kHeaderSize;
750 // Get the properties array.
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000751 __ lw(scratch1,
752 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000753 __ sw(value_reg, FieldMemOperand(scratch1, offset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000754
danno@chromium.orgf005df62013-04-30 16:36:45 +0000755 if (!FLAG_track_fields || !representation.IsSmi()) {
756 // Skip updating write barrier if storing a smi.
757 __ JumpIfSmi(value_reg, &exit);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000758
danno@chromium.orgf005df62013-04-30 16:36:45 +0000759 // Update the write barrier for the array address.
760 // Ok to clobber receiver_reg and name_reg, since we return.
761 __ mov(name_reg, value_reg);
762 __ RecordWriteField(scratch1,
763 offset,
764 name_reg,
765 receiver_reg,
766 kRAHasNotBeenSaved,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +0000767 kDontSaveFPRegs,
768 EMIT_REMEMBERED_SET,
769 smi_check);
danno@chromium.orgf005df62013-04-30 16:36:45 +0000770 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000771 }
772
773 // Return the value (register v0).
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000774 ASSERT(value_reg.is(a0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000775 __ bind(&exit);
776 __ mov(v0, a0);
777 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +0000778}
779
780
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +0000781void BaseStoreStubCompiler::GenerateRestoreName(MacroAssembler* masm,
782 Label* label,
783 Handle<Name> name) {
784 if (!label->is_unused()) {
785 __ bind(label);
786 __ li(this->name(), Operand(name));
787 }
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +0000788}
789
790
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000791static void GenerateCallFunction(MacroAssembler* masm,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000792 Handle<Object> object,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000793 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000794 Label* miss,
795 Code::ExtraICState extra_ic_state) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000796 // ----------- S t a t e -------------
797 // -- a0: receiver
798 // -- a1: function to call
799 // -----------------------------------
800 // Check that the function really is a function.
801 __ JumpIfSmi(a1, miss);
802 __ GetObjectType(a1, a3, a3);
803 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
804
805 // Patch the receiver on the stack with the global proxy if
806 // necessary.
807 if (object->IsGlobalObject()) {
808 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
809 __ sw(a3, MemOperand(sp, arguments.immediate() * kPointerSize));
810 }
811
812 // Invoke the function.
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000813 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state)
814 ? CALL_AS_FUNCTION
815 : CALL_AS_METHOD;
816 __ InvokeFunction(a1, arguments, JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000817}
818
819
820static void PushInterceptorArguments(MacroAssembler* masm,
821 Register receiver,
822 Register holder,
823 Register name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000824 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000825 __ push(name);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000826 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
827 ASSERT(!masm->isolate()->heap()->InNewSpace(*interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000828 Register scratch = name;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000829 __ li(scratch, Operand(interceptor));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000830 __ Push(scratch, receiver, holder);
831 __ lw(scratch, FieldMemOperand(scratch, InterceptorInfo::kDataOffset));
832 __ push(scratch);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +0000833 __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000834 __ push(scratch);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000835}
836
837
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000838static void CompileCallLoadPropertyWithInterceptor(
839 MacroAssembler* masm,
840 Register receiver,
841 Register holder,
842 Register name,
843 Handle<JSObject> holder_obj) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000844 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
845
846 ExternalReference ref =
847 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly),
848 masm->isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000849 __ PrepareCEntryArgs(6);
ulan@chromium.org6ff65142012-03-21 09:52:17 +0000850 __ PrepareCEntryFunction(ref);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000851
852 CEntryStub stub(1);
853 __ CallStub(&stub);
854}
855
856
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000857static const int kFastApiCallArguments = FunctionCallbackArguments::kArgsLength;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000858
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000859// Reserves space for the extra arguments to API function in the
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000860// caller's frame.
861//
862// These arguments are set by CheckPrototypes and GenerateFastApiDirectCall.
863static void ReserveSpaceForFastApiCall(MacroAssembler* masm,
864 Register scratch) {
865 ASSERT(Smi::FromInt(0) == 0);
866 for (int i = 0; i < kFastApiCallArguments; i++) {
867 __ push(zero_reg);
868 }
869}
870
871
872// Undoes the effects of ReserveSpaceForFastApiCall.
873static void FreeSpaceForFastApiCall(MacroAssembler* masm) {
874 __ Drop(kFastApiCallArguments);
875}
876
877
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000878static void GenerateFastApiDirectCall(MacroAssembler* masm,
879 const CallOptimization& optimization,
880 int argc) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000881 // ----------- S t a t e -------------
882 // -- sp[0] : holder (set by CheckPrototypes)
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000883 // -- sp[4] : callee JS function
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000884 // -- sp[8] : call data
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000885 // -- sp[12] : isolate
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000886 // -- sp[16] : ReturnValue
887 // -- sp[20] : last JS argument
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000888 // -- ...
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000889 // -- sp[(argc + 4) * 4] : first JS argument
890 // -- sp[(argc + 5) * 4] : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000891 // -----------------------------------
892 // Get the function and setup the context.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000893 Handle<JSFunction> function = optimization.constant_function();
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000894 __ LoadHeapObject(t1, function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000895 __ lw(cp, FieldMemOperand(t1, JSFunction::kContextOffset));
896
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000897 // Pass the additional arguments.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000898 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000899 Handle<Object> call_data(api_call_info->data(), masm->isolate());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000900 if (masm->isolate()->heap()->InNewSpace(*call_data)) {
901 __ li(a0, api_call_info);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000902 __ lw(t2, FieldMemOperand(a0, CallHandlerInfo::kDataOffset));
903 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000904 __ li(t2, call_data);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000905 }
906
ulan@chromium.org32d7dba2013-04-24 10:59:06 +0000907 __ li(t3, Operand(ExternalReference::isolate_address(masm->isolate())));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000908 // Store JS function, call data, isolate and ReturnValue.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000909 __ sw(t1, MemOperand(sp, 1 * kPointerSize));
910 __ sw(t2, MemOperand(sp, 2 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000911 __ sw(t3, MemOperand(sp, 3 * kPointerSize));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000912 __ LoadRoot(t1, Heap::kUndefinedValueRootIndex);
913 __ sw(t1, MemOperand(sp, 4 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000914
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000915 // Prepare arguments.
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000916 __ Addu(a2, sp, Operand(4 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000917
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000918 // Allocate the v8::Arguments structure in the arguments' space since
919 // it's not controlled by GC.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000920 const int kApiStackSpace = 4;
921
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000922 FrameScope frame_scope(masm, StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000923 __ EnterExitFrame(false, kApiStackSpace);
924
925 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
926 // struct from the function (which is currently the case). This means we pass
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +0000927 // the first argument in a1 instead of a0, if returns_handle is true.
928 // CallApiFunctionAndReturn will set up a0.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000929
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000930 Address function_address = v8::ToCData<Address>(api_call_info->callback());
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000931 bool returns_handle =
932 !CallbackTable::ReturnsVoid(masm->isolate(), function_address);
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +0000933
934 Register first_arg = returns_handle ? a1 : a0;
935
936 // first_arg = v8::Arguments&
937 // Arguments is built at sp + 1 (sp is a reserved spot for ra).
938 __ Addu(first_arg, sp, kPointerSize);
939
940 // v8::Arguments::implicit_args_
941 __ sw(a2, MemOperand(first_arg, 0 * kPointerSize));
942 // v8::Arguments::values_
943 __ Addu(t0, a2, Operand(argc * kPointerSize));
944 __ sw(t0, MemOperand(first_arg, 1 * kPointerSize));
945 // v8::Arguments::length_ = argc
946 __ li(t0, Operand(argc));
947 __ sw(t0, MemOperand(first_arg, 2 * kPointerSize));
948 // v8::Arguments::is_construct_call = 0
949 __ sw(zero_reg, MemOperand(first_arg, 3 * kPointerSize));
950
951 const int kStackUnwindSpace = argc + kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000952 ApiFunction fun(function_address);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000953 ExternalReference::Type type =
954 returns_handle ?
955 ExternalReference::DIRECT_API_CALL :
956 ExternalReference::DIRECT_API_CALL_NEW;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000957 ExternalReference ref =
958 ExternalReference(&fun,
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000959 type,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000960 masm->isolate());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000961 AllowExternalCallThatCantCauseGC scope(masm);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000962 __ CallApiFunctionAndReturn(ref,
963 kStackUnwindSpace,
964 returns_handle,
965 kFastApiCallArguments + 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000966}
967
lrn@chromium.org7516f052011-03-30 08:52:27 +0000968class CallInterceptorCompiler BASE_EMBEDDED {
969 public:
970 CallInterceptorCompiler(StubCompiler* stub_compiler,
971 const ParameterCount& arguments,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000972 Register name,
973 Code::ExtraICState extra_ic_state)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000974 : stub_compiler_(stub_compiler),
975 arguments_(arguments),
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000976 name_(name),
977 extra_ic_state_(extra_ic_state) {}
lrn@chromium.org7516f052011-03-30 08:52:27 +0000978
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000979 void Compile(MacroAssembler* masm,
980 Handle<JSObject> object,
981 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000982 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000983 LookupResult* lookup,
984 Register receiver,
985 Register scratch1,
986 Register scratch2,
987 Register scratch3,
988 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000989 ASSERT(holder->HasNamedInterceptor());
990 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined());
991
992 // Check that the receiver isn't a smi.
993 __ JumpIfSmi(receiver, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000994 CallOptimization optimization(lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000995 if (optimization.is_constant_call()) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000996 CompileCacheable(masm, object, receiver, scratch1, scratch2, scratch3,
997 holder, lookup, name, optimization, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000998 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000999 CompileRegular(masm, object, receiver, scratch1, scratch2, scratch3,
1000 name, holder, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001001 }
1002 }
1003
1004 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001005 void CompileCacheable(MacroAssembler* masm,
1006 Handle<JSObject> object,
1007 Register receiver,
1008 Register scratch1,
1009 Register scratch2,
1010 Register scratch3,
1011 Handle<JSObject> interceptor_holder,
1012 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001013 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001014 const CallOptimization& optimization,
1015 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001016 ASSERT(optimization.is_constant_call());
1017 ASSERT(!lookup->holder()->IsGlobalObject());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001018 Counters* counters = masm->isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001019 int depth1 = kInvalidProtoDepth;
1020 int depth2 = kInvalidProtoDepth;
1021 bool can_do_fast_api_call = false;
1022 if (optimization.is_simple_api_call() &&
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001023 !lookup->holder()->IsGlobalObject()) {
1024 depth1 = optimization.GetPrototypeDepthOfExpectedType(
1025 object, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001026 if (depth1 == kInvalidProtoDepth) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001027 depth2 = optimization.GetPrototypeDepthOfExpectedType(
1028 interceptor_holder, Handle<JSObject>(lookup->holder()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001029 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001030 can_do_fast_api_call =
1031 depth1 != kInvalidProtoDepth || depth2 != kInvalidProtoDepth;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001032 }
1033
1034 __ IncrementCounter(counters->call_const_interceptor(), 1,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001035 scratch1, scratch2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001036
1037 if (can_do_fast_api_call) {
1038 __ IncrementCounter(counters->call_const_interceptor_fast_api(), 1,
1039 scratch1, scratch2);
1040 ReserveSpaceForFastApiCall(masm, scratch1);
1041 }
1042
1043 // Check that the maps from receiver to interceptor's holder
1044 // haven't changed and thus we can invoke interceptor.
1045 Label miss_cleanup;
1046 Label* miss = can_do_fast_api_call ? &miss_cleanup : miss_label;
1047 Register holder =
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001048 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
1049 scratch1, scratch2, scratch3,
1050 name, depth1, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001051
1052 // Invoke an interceptor and if it provides a value,
1053 // branch to |regular_invoke|.
1054 Label regular_invoke;
1055 LoadWithInterceptor(masm, receiver, holder, interceptor_holder, scratch2,
1056 &regular_invoke);
1057
1058 // Interceptor returned nothing for this property. Try to use cached
1059 // constant function.
1060
1061 // Check that the maps from interceptor's holder to constant function's
1062 // holder haven't changed and thus we can use cached constant function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001063 if (*interceptor_holder != lookup->holder()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001064 stub_compiler_->CheckPrototypes(interceptor_holder, receiver,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001065 Handle<JSObject>(lookup->holder()),
1066 scratch1, scratch2, scratch3,
1067 name, depth2, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001068 } else {
1069 // CheckPrototypes has a side effect of fetching a 'holder'
1070 // for API (object which is instanceof for the signature). It's
1071 // safe to omit it here, as if present, it should be fetched
1072 // by the previous CheckPrototypes.
1073 ASSERT(depth2 == kInvalidProtoDepth);
1074 }
1075
1076 // Invoke function.
1077 if (can_do_fast_api_call) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001078 GenerateFastApiDirectCall(masm, optimization, arguments_.immediate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001079 } else {
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001080 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_)
1081 ? CALL_AS_FUNCTION
1082 : CALL_AS_METHOD;
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001083 Handle<JSFunction> function = optimization.constant_function();
1084 ParameterCount expected(function);
1085 __ InvokeFunction(function, expected, arguments_,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001086 JUMP_FUNCTION, NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001087 }
1088
1089 // Deferred code for fast API call case---clean preallocated space.
1090 if (can_do_fast_api_call) {
1091 __ bind(&miss_cleanup);
1092 FreeSpaceForFastApiCall(masm);
1093 __ Branch(miss_label);
1094 }
1095
1096 // Invoke a regular function.
1097 __ bind(&regular_invoke);
1098 if (can_do_fast_api_call) {
1099 FreeSpaceForFastApiCall(masm);
1100 }
lrn@chromium.org7516f052011-03-30 08:52:27 +00001101 }
1102
1103 void CompileRegular(MacroAssembler* masm,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001104 Handle<JSObject> object,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001105 Register receiver,
1106 Register scratch1,
1107 Register scratch2,
1108 Register scratch3,
ulan@chromium.org6e196bf2013-03-13 09:38:22 +00001109 Handle<Name> name,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001110 Handle<JSObject> interceptor_holder,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001111 Label* miss_label) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001112 Register holder =
1113 stub_compiler_->CheckPrototypes(object, receiver, interceptor_holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001114 scratch1, scratch2, scratch3,
1115 name, miss_label);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001116
1117 // Call a runtime function to load the interceptor property.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001118 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001119 // Save the name_ register across the call.
1120 __ push(name_);
1121
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001122 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001123
1124 __ CallExternalReference(
1125 ExternalReference(
1126 IC_Utility(IC::kLoadPropertyWithInterceptorForCall),
1127 masm->isolate()),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001128 6);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001129 // Restore the name_ register.
1130 __ pop(name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001131 // Leave the internal frame.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001132 }
1133
1134 void LoadWithInterceptor(MacroAssembler* masm,
1135 Register receiver,
1136 Register holder,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001137 Handle<JSObject> holder_obj,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001138 Register scratch,
1139 Label* interceptor_succeeded) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001140 {
1141 FrameScope scope(masm, StackFrame::INTERNAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001142
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001143 __ Push(holder, name_);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001144 CompileCallLoadPropertyWithInterceptor(masm,
1145 receiver,
1146 holder,
1147 name_,
1148 holder_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001149 __ pop(name_); // Restore the name.
1150 __ pop(receiver); // Restore the holder.
1151 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001152 // If interceptor returns no-result sentinel, call the constant function.
1153 __ LoadRoot(scratch, Heap::kNoInterceptorResultSentinelRootIndex);
1154 __ Branch(interceptor_succeeded, ne, v0, Operand(scratch));
lrn@chromium.org7516f052011-03-30 08:52:27 +00001155 }
1156
1157 StubCompiler* stub_compiler_;
1158 const ParameterCount& arguments_;
1159 Register name_;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001160 Code::ExtraICState extra_ic_state_;
lrn@chromium.org7516f052011-03-30 08:52:27 +00001161};
1162
1163
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001164// Calls GenerateCheckPropertyCell for each global object in the prototype chain
1165// from object to (but not including) holder.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001166static void GenerateCheckPropertyCells(MacroAssembler* masm,
1167 Handle<JSObject> object,
1168 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001169 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001170 Register scratch,
1171 Label* miss) {
1172 Handle<JSObject> current = object;
1173 while (!current.is_identical_to(holder)) {
1174 if (current->IsGlobalObject()) {
1175 GenerateCheckPropertyCell(masm,
1176 Handle<GlobalObject>::cast(current),
1177 name,
1178 scratch,
1179 miss);
1180 }
1181 current = Handle<JSObject>(JSObject::cast(current->GetPrototype()));
1182 }
1183}
1184
1185
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001186// Convert and store int passed in register ival to IEEE 754 single precision
1187// floating point value at memory location (dst + 4 * wordoffset)
1188// If FPU is available use it for conversion.
1189static void StoreIntAsFloat(MacroAssembler* masm,
1190 Register dst,
1191 Register wordoffset,
1192 Register ival,
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00001193 Register scratch1) {
1194 __ mtc1(ival, f0);
1195 __ cvt_s_w(f0, f0);
1196 __ sll(scratch1, wordoffset, 2);
1197 __ addu(scratch1, dst, scratch1);
1198 __ swc1(f0, MemOperand(scratch1, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001199}
1200
1201
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001202void StubCompiler::GenerateTailCall(MacroAssembler* masm, Handle<Code> code) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001203 __ Jump(code, RelocInfo::CODE_TARGET);
1204}
1205
1206
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001207#undef __
1208#define __ ACCESS_MASM(masm())
1209
1210
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001211Register StubCompiler::CheckPrototypes(Handle<JSObject> object,
1212 Register object_reg,
1213 Handle<JSObject> holder,
1214 Register holder_reg,
1215 Register scratch1,
1216 Register scratch2,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001217 Handle<Name> name,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001218 int save_at_depth,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001219 Label* miss,
1220 PrototypeCheckType check) {
1221 Handle<JSObject> first = object;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001222 // Make sure there's no overlap between holder and object registers.
1223 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
1224 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
1225 && !scratch2.is(scratch1));
1226
1227 // Keep track of the current object in register reg.
1228 Register reg = object_reg;
1229 int depth = 0;
1230
1231 if (save_at_depth == depth) {
1232 __ sw(reg, MemOperand(sp));
1233 }
1234
1235 // Check the maps in the prototype chain.
1236 // Traverse the prototype chain from the object and do map checks.
1237 Handle<JSObject> current = object;
1238 while (!current.is_identical_to(holder)) {
1239 ++depth;
1240
1241 // Only global objects and objects that do not require access
1242 // checks are allowed in stubs.
1243 ASSERT(current->IsJSGlobalProxy() || !current->IsAccessCheckNeeded());
1244
1245 Handle<JSObject> prototype(JSObject::cast(current->GetPrototype()));
1246 if (!current->HasFastProperties() &&
1247 !current->IsJSGlobalObject() &&
1248 !current->IsJSGlobalProxy()) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001249 if (!name->IsUniqueName()) {
1250 ASSERT(name->IsString());
1251 name = factory()->InternalizeString(Handle<String>::cast(name));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001252 }
1253 ASSERT(current->property_dictionary()->FindEntry(*name) ==
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001254 NameDictionary::kNotFound);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001255
1256 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
1257 scratch1, scratch2);
1258
1259 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
1260 reg = holder_reg; // From now on the object will be in holder_reg.
1261 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
1262 } else {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001263 Register map_reg = scratch1;
1264 if (!current.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1265 Handle<Map> current_map(current->map());
1266 // CheckMap implicitly loads the map of |reg| into |map_reg|.
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001267 __ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001268 } else {
1269 __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
1270 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001271 // Check access rights to the global object. This has to happen after
1272 // the map check so that we know that the object is actually a global
1273 // object.
1274 if (current->IsJSGlobalProxy()) {
1275 __ CheckAccessGlobalProxy(reg, scratch2, miss);
1276 }
1277 reg = holder_reg; // From now on the object will be in holder_reg.
1278
1279 if (heap()->InNewSpace(*prototype)) {
1280 // The prototype is in new space; we cannot store a reference to it
1281 // in the code. Load it from the map.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001282 __ lw(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001283 } else {
1284 // The prototype is in old space; load it directly.
1285 __ li(reg, Operand(prototype));
1286 }
1287 }
1288
1289 if (save_at_depth == depth) {
1290 __ sw(reg, MemOperand(sp));
1291 }
1292
1293 // Go to the next object in the prototype chain.
1294 current = prototype;
1295 }
1296
1297 // Log the check depth.
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001298 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001299
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001300 if (!holder.is_identical_to(first) || check == CHECK_ALL_MAPS) {
1301 // Check the holder map.
1302 __ CheckMap(reg, scratch1, Handle<Map>(holder->map()), miss,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001303 DONT_DO_SMI_CHECK);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001304 }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001305
1306 // Perform security check for access to the global object.
1307 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
1308 if (holder->IsJSGlobalProxy()) {
1309 __ CheckAccessGlobalProxy(reg, scratch1, miss);
1310 }
1311
1312 // If we've skipped any global objects, it's not enough to verify that
1313 // their maps haven't changed. We also need to check that the property
1314 // cell for the property is still empty.
1315 GenerateCheckPropertyCells(masm(), object, holder, name, scratch1, miss);
1316
1317 // Return the register containing the holder.
1318 return reg;
1319}
1320
1321
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001322void BaseLoadStubCompiler::HandlerFrontendFooter(Label* success,
1323 Label* miss) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001324 if (!miss->is_unused()) {
1325 __ Branch(success);
1326 __ bind(miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00001327 TailCallBuiltin(masm(), MissBuiltin(kind()));
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001328 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001329}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001330
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001331
1332Register BaseLoadStubCompiler::CallbackHandlerFrontend(
1333 Handle<JSObject> object,
1334 Register object_reg,
1335 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001336 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001337 Label* success,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001338 Handle<ExecutableAccessorInfo> callback) {
1339 Label miss;
1340
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001341 Register reg = HandlerFrontendHeader(object, object_reg, holder, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001342
1343 if (!holder->HasFastProperties() && !holder->IsJSGlobalObject()) {
1344 ASSERT(!reg.is(scratch2()));
1345 ASSERT(!reg.is(scratch3()));
1346 ASSERT(!reg.is(scratch4()));
1347
1348 // Load the properties dictionary.
1349 Register dictionary = scratch4();
1350 __ lw(dictionary, FieldMemOperand(reg, JSObject::kPropertiesOffset));
1351
1352 // Probe the dictionary.
1353 Label probe_done;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001354 NameDictionaryLookupStub::GeneratePositiveLookup(masm(),
1355 &miss,
1356 &probe_done,
1357 dictionary,
1358 this->name(),
1359 scratch2(),
1360 scratch3());
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001361 __ bind(&probe_done);
1362
1363 // If probing finds an entry in the dictionary, scratch3 contains the
1364 // pointer into the dictionary. Check that the value is the callback.
1365 Register pointer = scratch3();
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001366 const int kElementsStartOffset = NameDictionary::kHeaderSize +
1367 NameDictionary::kElementsStartIndex * kPointerSize;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001368 const int kValueOffset = kElementsStartOffset + kPointerSize;
1369 __ lw(scratch2(), FieldMemOperand(pointer, kValueOffset));
1370 __ Branch(&miss, ne, scratch2(), Operand(callback));
1371 }
1372
1373 HandlerFrontendFooter(success, &miss);
1374 return reg;
1375}
1376
1377
1378void BaseLoadStubCompiler::NonexistentHandlerFrontend(
1379 Handle<JSObject> object,
1380 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001381 Handle<Name> name,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001382 Label* success,
1383 Handle<GlobalObject> global) {
1384 Label miss;
1385
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00001386 HandlerFrontendHeader(object, receiver(), last, name, &miss);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001387
1388 // If the last object in the prototype chain is a global object,
1389 // check that the global property cell is empty.
1390 if (!global.is_null()) {
1391 GenerateCheckPropertyCell(masm(), global, name, scratch2(), &miss);
1392 }
1393
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001394 HandlerFrontendFooter(success, &miss);
1395}
1396
1397
1398void BaseLoadStubCompiler::GenerateLoadField(Register reg,
1399 Handle<JSObject> holder,
ulan@chromium.org57ff8812013-05-10 08:16:55 +00001400 PropertyIndex field,
1401 Representation representation) {
1402 if (!reg.is(receiver())) __ mov(receiver(), reg);
1403 if (kind() == Code::LOAD_IC) {
1404 LoadFieldStub stub(field.is_inobject(holder),
1405 field.translate(holder),
1406 representation);
1407 GenerateTailCall(masm(), stub.GetCode(isolate()));
1408 } else {
1409 KeyedLoadFieldStub stub(field.is_inobject(holder),
1410 field.translate(holder),
1411 representation);
1412 GenerateTailCall(masm(), stub.GetCode(isolate()));
1413 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001414}
1415
1416
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001417void BaseLoadStubCompiler::GenerateLoadConstant(Handle<JSFunction> value) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001418 // Return the constant value.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001419 __ LoadHeapObject(v0, value);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001420 __ Ret();
ager@chromium.org5c838252010-02-19 08:53:10 +00001421}
1422
1423
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001424void BaseLoadStubCompiler::GenerateLoadCallback(
1425 Register reg,
1426 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001427 // Build AccessorInfo::args_ list on the stack and push property name below
1428 // the exit frame to make GC aware of them and store pointers to them.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001429 __ push(receiver());
1430 __ mov(scratch2(), sp); // scratch2 = AccessorInfo::args_
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001431 if (heap()->InNewSpace(callback->data())) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001432 __ li(scratch3(), callback);
1433 __ lw(scratch3(), FieldMemOperand(scratch3(),
1434 ExecutableAccessorInfo::kDataOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001435 } else {
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001436 __ li(scratch3(), Handle<Object>(callback->data(), isolate()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001437 }
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001438 __ Subu(sp, sp, 5 * kPointerSize);
1439 __ sw(reg, MemOperand(sp, 4 * kPointerSize));
1440 __ sw(scratch3(), MemOperand(sp, 3 * kPointerSize));
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001441 __ li(scratch3(),
1442 Operand(ExternalReference::isolate_address(isolate())));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001443 __ LoadRoot(scratch4(), Heap::kUndefinedValueRootIndex);
1444 __ sw(scratch3(), MemOperand(sp, 2 * kPointerSize));
1445 __ sw(scratch4(), MemOperand(sp, 1 * kPointerSize));
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001446 __ sw(name(), MemOperand(sp, 0 * kPointerSize));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001447
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001448 Address getter_address = v8::ToCData<Address>(callback->getter());
1449 bool returns_handle =
1450 !CallbackTable::ReturnsVoid(isolate(), getter_address);
1451
1452 Register first_arg = returns_handle ? a1 : a0;
1453 Register second_arg = returns_handle ? a2 : a1;
1454
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001455 __ mov(a2, scratch2()); // Saved in case scratch2 == a1.
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001456 __ mov(first_arg, sp); // (first argument - see note below) = Handle<Name>
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001457
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001458 // NOTE: the O32 abi requires a0 to hold a special pointer when returning a
1459 // struct from the function (which is currently the case). This means we pass
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001460 // the arguments in a1-a2 instead of a0-a1, if returns_handle is true.
1461 // CallApiFunctionAndReturn will set up a0.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001462
1463 const int kApiStackSpace = 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001464 FrameScope frame_scope(masm(), StackFrame::MANUAL);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001465 __ EnterExitFrame(false, kApiStackSpace);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001466
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001467 // Create AccessorInfo instance on the stack above the exit frame with
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001468 // scratch2 (internal::Object** args_) as the data.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001469 __ sw(a2, MemOperand(sp, kPointerSize));
svenpanne@chromium.org53ad1752013-05-27 12:20:38 +00001470 // (second argument - see note above) = AccessorInfo&
1471 __ Addu(second_arg, sp, kPointerSize);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001472
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001473 const int kStackUnwindSpace = kFastApiCallArguments + 1;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001474 ApiFunction fun(getter_address);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001475 ExternalReference::Type type =
1476 returns_handle ?
1477 ExternalReference::DIRECT_GETTER_CALL :
1478 ExternalReference::DIRECT_GETTER_CALL_NEW;
1479
1480 ExternalReference ref = ExternalReference(&fun, type, isolate());
1481 __ CallApiFunctionAndReturn(ref,
1482 kStackUnwindSpace,
1483 returns_handle,
1484 3);
ager@chromium.org5c838252010-02-19 08:53:10 +00001485}
1486
1487
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001488void BaseLoadStubCompiler::GenerateLoadInterceptor(
1489 Register holder_reg,
1490 Handle<JSObject> object,
1491 Handle<JSObject> interceptor_holder,
1492 LookupResult* lookup,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001493 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001494 ASSERT(interceptor_holder->HasNamedInterceptor());
1495 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined());
1496
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001497 // So far the most popular follow ups for interceptor loads are FIELD
1498 // and CALLBACKS, so inline only them, other cases may be added
1499 // later.
1500 bool compile_followup_inline = false;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001501 if (lookup->IsFound() && lookup->IsCacheable()) {
yangguo@chromium.orgde0db002012-06-22 13:44:28 +00001502 if (lookup->IsField()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001503 compile_followup_inline = true;
1504 } else if (lookup->type() == CALLBACKS &&
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00001505 lookup->GetCallbackObject()->IsExecutableAccessorInfo()) {
1506 ExecutableAccessorInfo* callback =
1507 ExecutableAccessorInfo::cast(lookup->GetCallbackObject());
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001508 compile_followup_inline = callback->getter() != NULL &&
1509 callback->IsCompatibleReceiver(*object);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001510 }
1511 }
1512
1513 if (compile_followup_inline) {
1514 // Compile the interceptor call, followed by inline code to load the
1515 // property from further up the prototype chain if the call fails.
1516 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001517 ASSERT(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001518
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001519 // Preserve the receiver register explicitly whenever it is different from
1520 // the holder and it is needed should the interceptor return without any
1521 // result. The CALLBACKS case needs the receiver to be passed into C++ code,
1522 // the FIELD case might cause a miss during the prototype check.
1523 bool must_perfrom_prototype_check = *interceptor_holder != lookup->holder();
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001524 bool must_preserve_receiver_reg = !receiver().is(holder_reg) &&
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001525 (lookup->type() == CALLBACKS || must_perfrom_prototype_check);
1526
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001527 // Save necessary data before invoking an interceptor.
1528 // Requires a frame to make GC aware of pushed pointers.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001529 {
1530 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001531 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001532 __ Push(receiver(), holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001533 } else {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001534 __ Push(holder_reg, this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001535 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001536 // Invoke an interceptor. Note: map checks from receiver to
1537 // interceptor's holder has been compiled before (see a caller
1538 // of this method).
1539 CompileCallLoadPropertyWithInterceptor(masm(),
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001540 receiver(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001541 holder_reg,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001542 this->name(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001543 interceptor_holder);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001544 // Check if interceptor provided a value for property. If it's
1545 // the case, return immediately.
1546 Label interceptor_failed;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001547 __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
1548 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1()));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001549 frame_scope.GenerateLeaveFrame();
1550 __ Ret();
1551
1552 __ bind(&interceptor_failed);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001553 __ pop(this->name());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001554 __ pop(holder_reg);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00001555 if (must_preserve_receiver_reg) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001556 __ pop(receiver());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001557 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001558 // Leave the internal frame.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001559 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001560 GenerateLoadPostInterceptor(holder_reg, interceptor_holder, name, lookup);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001561 } else { // !compile_followup_inline
1562 // Call the runtime system to load the interceptor.
1563 // Check that the maps haven't changed.
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001564 PushInterceptorArguments(masm(), receiver(), holder_reg,
1565 this->name(), interceptor_holder);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001566
1567 ExternalReference ref = ExternalReference(
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001568 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad), isolate());
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00001569 __ TailCallExternalReference(ref, 6, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001570 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001571}
1572
1573
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001574void CallStubCompiler::GenerateNameCheck(Handle<Name> name, Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001575 if (kind_ == Code::KEYED_CALL_IC) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001576 __ Branch(miss, ne, a2, Operand(name));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001577 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001578}
1579
1580
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001581void CallStubCompiler::GenerateGlobalReceiverCheck(Handle<JSObject> object,
1582 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001583 Handle<Name> name,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001584 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001585 ASSERT(holder->IsGlobalObject());
1586
1587 // Get the number of arguments.
1588 const int argc = arguments().immediate();
1589
1590 // Get the receiver from the stack.
1591 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1592
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001593 // Check that the maps haven't changed.
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001594 __ JumpIfSmi(a0, miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001595 CheckPrototypes(object, a0, holder, a3, a1, t0, name, miss);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001596}
1597
1598
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001599void CallStubCompiler::GenerateLoadFunctionFromCell(
1600 Handle<JSGlobalPropertyCell> cell,
1601 Handle<JSFunction> function,
1602 Label* miss) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001603 // Get the value from the cell.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001604 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001605 __ lw(a1, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
1606
1607 // Check that the cell contains the same function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001608 if (heap()->InNewSpace(*function)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001609 // We can't embed a pointer to a function in new space so we have
1610 // to verify that the shared function info is unchanged. This has
1611 // the nice side effect that multiple closures based on the same
1612 // function can all use this call IC. Before we load through the
1613 // function, we have to verify that it still is a function.
1614 __ JumpIfSmi(a1, miss);
1615 __ GetObjectType(a1, a3, a3);
1616 __ Branch(miss, ne, a3, Operand(JS_FUNCTION_TYPE));
1617
1618 // Check the shared function info. Make sure it hasn't changed.
1619 __ li(a3, Handle<SharedFunctionInfo>(function->shared()));
1620 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1621 __ Branch(miss, ne, t0, Operand(a3));
1622 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001623 __ Branch(miss, ne, a1, Operand(function));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001624 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001625}
1626
1627
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001628void CallStubCompiler::GenerateMissBranch() {
1629 Handle<Code> code =
danno@chromium.org40cb8782011-05-25 07:58:50 +00001630 isolate()->stub_cache()->ComputeCallMiss(arguments().immediate(),
1631 kind_,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001632 extra_state_);
1633 __ Jump(code, RelocInfo::CODE_TARGET);
1634}
1635
1636
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001637Handle<Code> CallStubCompiler::CompileCallField(Handle<JSObject> object,
1638 Handle<JSObject> holder,
yangguo@chromium.orgfb377212012-11-16 14:43:43 +00001639 PropertyIndex index,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001640 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001641 // ----------- S t a t e -------------
1642 // -- a2 : name
1643 // -- ra : return address
1644 // -----------------------------------
1645 Label miss;
1646
1647 GenerateNameCheck(name, &miss);
1648
1649 const int argc = arguments().immediate();
1650
1651 // Get the receiver of the function from the stack into a0.
1652 __ lw(a0, MemOperand(sp, argc * kPointerSize));
1653 // Check that the receiver isn't a smi.
1654 __ JumpIfSmi(a0, &miss, t0);
1655
1656 // Do the right check and compute the holder register.
1657 Register reg = CheckPrototypes(object, a0, holder, a1, a3, t0, name, &miss);
ulan@chromium.org57ff8812013-05-10 08:16:55 +00001658 GenerateFastPropertyLoad(masm(), a1, reg, index.is_inobject(holder),
1659 index.translate(holder), Representation::Tagged());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001660
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001661 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001662
1663 // Handle call cache miss.
1664 __ bind(&miss);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001665 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001666
1667 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00001668 return GetCode(Code::FIELD, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00001669}
1670
1671
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001672Handle<Code> CallStubCompiler::CompileArrayPushCall(
1673 Handle<Object> object,
1674 Handle<JSObject> holder,
1675 Handle<JSGlobalPropertyCell> cell,
1676 Handle<JSFunction> function,
1677 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001678 // ----------- S t a t e -------------
1679 // -- a2 : name
1680 // -- ra : return address
1681 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1682 // -- ...
1683 // -- sp[argc * 4] : receiver
1684 // -----------------------------------
1685
1686 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001687 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001688
1689 Label miss;
1690
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001691 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001692
1693 Register receiver = a1;
1694
1695 // Get the receiver from the stack.
1696 const int argc = arguments().immediate();
1697 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
1698
1699 // Check that the receiver isn't a smi.
1700 __ JumpIfSmi(receiver, &miss);
1701
1702 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001703 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, a3, v0, t0,
1704 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001705
1706 if (argc == 0) {
1707 // Nothing to do, just return the length.
1708 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1709 __ Drop(argc + 1);
1710 __ Ret();
1711 } else {
1712 Label call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001713 if (argc == 1) { // Otherwise fall through to call the builtin.
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001714 Label attempt_to_grow_elements, with_write_barrier, check_double;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001715
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001716 Register elements = t2;
1717 Register end_elements = t1;
1718 // Get the elements array of the object.
1719 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1720
1721 // Check that the elements are in fast mode and writable.
1722 __ CheckMap(elements,
1723 v0,
1724 Heap::kFixedArrayMapRootIndex,
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001725 &check_double,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001726 DONT_DO_SMI_CHECK);
1727
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001728 // Get the array's length into v0 and calculate new length.
1729 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1730 STATIC_ASSERT(kSmiTagSize == 1);
1731 STATIC_ASSERT(kSmiTag == 0);
1732 __ Addu(v0, v0, Operand(Smi::FromInt(argc)));
1733
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001734 // Get the elements' length.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001735 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1736
1737 // Check if we could survive without allocation.
1738 __ Branch(&attempt_to_grow_elements, gt, v0, Operand(t0));
1739
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001740 // Check if value is a smi.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001741 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1742 __ JumpIfNotSmi(t0, &with_write_barrier);
1743
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001744 // Save new length.
1745 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1746
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001747 // Store the value.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001748 // We may need a register containing the address end_elements below,
1749 // so write back the value in end_elements.
1750 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1751 __ Addu(end_elements, elements, end_elements);
1752 const int kEndElementsOffset =
1753 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001754 __ Addu(end_elements, end_elements, kEndElementsOffset);
1755 __ sw(t0, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001756
1757 // Check for a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001758 __ Drop(argc + 1);
1759 __ Ret();
1760
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001761 __ bind(&check_double);
1762
1763 // Check that the elements are in fast mode and writable.
1764 __ CheckMap(elements,
1765 a0,
1766 Heap::kFixedDoubleArrayMapRootIndex,
1767 &call_builtin,
1768 DONT_DO_SMI_CHECK);
1769
1770 // Get the array's length into r0 and calculate new length.
1771 __ lw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1772 STATIC_ASSERT(kSmiTagSize == 1);
1773 STATIC_ASSERT(kSmiTag == 0);
1774 __ Addu(a0, a0, Operand(Smi::FromInt(argc)));
1775
1776 // Get the elements' length.
1777 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1778
1779 // Check if we could survive without allocation.
1780 __ Branch(&call_builtin, gt, a0, Operand(t0));
1781
1782 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize));
1783 __ StoreNumberToDoubleElements(
1784 t0, a0, elements, a3, t1, a2, t5,
1785 &call_builtin, argc * kDoubleSize);
1786
1787 // Save new length.
1788 __ sw(a0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1789
1790 // Check for a smi.
1791 __ Drop(argc + 1);
1792 __ Ret();
1793
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001794 __ bind(&with_write_barrier);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001795
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001796 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1797
1798 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1799 Label fast_object, not_fast_object;
1800 __ CheckFastObjectElements(a3, t3, &not_fast_object);
1801 __ jmp(&fast_object);
1802 // In case of fast smi-only, convert to fast object, otherwise bail out.
1803 __ bind(&not_fast_object);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001804 __ CheckFastSmiElements(a3, t3, &call_builtin);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001805
1806 __ lw(t3, FieldMemOperand(t0, HeapObject::kMapOffset));
1807 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
1808 __ Branch(&call_builtin, eq, t3, Operand(at));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001809 // edx: receiver
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001810 // a3: map
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001811 Label try_holey_map;
1812 __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001813 FAST_ELEMENTS,
1814 a3,
1815 t3,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001816 &try_holey_map);
1817 __ mov(a2, receiver);
1818 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001819 GenerateMapChangeElementsTransition(masm(),
1820 DONT_TRACK_ALLOCATION_SITE,
1821 NULL);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001822 __ jmp(&fast_object);
1823
1824 __ bind(&try_holey_map);
1825 __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS,
1826 FAST_HOLEY_ELEMENTS,
1827 a3,
1828 t3,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001829 &call_builtin);
1830 __ mov(a2, receiver);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001831 ElementsTransitionGenerator::
yangguo@chromium.org28381b42013-01-21 14:39:38 +00001832 GenerateMapChangeElementsTransition(masm(),
1833 DONT_TRACK_ALLOCATION_SITE,
1834 NULL);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001835 __ bind(&fast_object);
1836 } else {
1837 __ CheckFastObjectElements(a3, a3, &call_builtin);
1838 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001839
1840 // Save new length.
1841 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1842
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001843 // Store the value.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001844 // We may need a register containing the address end_elements below,
1845 // so write back the value in end_elements.
1846 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1847 __ Addu(end_elements, elements, end_elements);
1848 __ Addu(end_elements, end_elements, kEndElementsOffset);
1849 __ sw(t0, MemOperand(end_elements));
1850
1851 __ RecordWrite(elements,
1852 end_elements,
1853 t0,
1854 kRAHasNotBeenSaved,
1855 kDontSaveFPRegs,
1856 EMIT_REMEMBERED_SET,
1857 OMIT_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001858 __ Drop(argc + 1);
1859 __ Ret();
1860
1861 __ bind(&attempt_to_grow_elements);
1862 // v0: array's length + 1.
1863 // t0: elements' length.
1864
1865 if (!FLAG_inline_new) {
1866 __ Branch(&call_builtin);
1867 }
1868
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001869 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize));
1870 // Growing elements that are SMI-only requires special handling in case
1871 // the new element is non-Smi. For now, delegate to the builtin.
1872 Label no_fast_elements_check;
1873 __ JumpIfSmi(a2, &no_fast_elements_check);
1874 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1875 __ CheckFastObjectElements(t3, t3, &call_builtin);
1876 __ bind(&no_fast_elements_check);
1877
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001878 ExternalReference new_space_allocation_top =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001879 ExternalReference::new_space_allocation_top_address(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001880 ExternalReference new_space_allocation_limit =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001881 ExternalReference::new_space_allocation_limit_address(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001882
1883 const int kAllocationDelta = 4;
1884 // Load top and check if it is the end of elements.
1885 __ sll(end_elements, v0, kPointerSizeLog2 - kSmiTagSize);
1886 __ Addu(end_elements, elements, end_elements);
1887 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset));
1888 __ li(t3, Operand(new_space_allocation_top));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001889 __ lw(a3, MemOperand(t3));
1890 __ Branch(&call_builtin, ne, end_elements, Operand(a3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001891
1892 __ li(t5, Operand(new_space_allocation_limit));
1893 __ lw(t5, MemOperand(t5));
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001894 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize));
1895 __ Branch(&call_builtin, hi, a3, Operand(t5));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001896
1897 // We fit and could grow elements.
1898 // Update new_space_allocation_top.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001899 __ sw(a3, MemOperand(t3));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001900 // Push the argument.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001901 __ sw(a2, MemOperand(end_elements));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001902 // Fill the rest with holes.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001903 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001904 for (int i = 1; i < kAllocationDelta; i++) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00001905 __ sw(a3, MemOperand(end_elements, i * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001906 }
1907
1908 // Update elements' and array's sizes.
1909 __ sw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1910 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta)));
1911 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset));
1912
1913 // Elements are in new space, so write barrier is not required.
1914 __ Drop(argc + 1);
1915 __ Ret();
1916 }
1917 __ bind(&call_builtin);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00001918 __ TailCallExternalReference(
1919 ExternalReference(Builtins::c_ArrayPush, isolate()), argc + 1, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001920 }
1921
1922 // Handle call cache miss.
1923 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001924 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001925
1926 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001927 return GetCode(function);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001928}
1929
1930
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001931Handle<Code> CallStubCompiler::CompileArrayPopCall(
1932 Handle<Object> object,
1933 Handle<JSObject> holder,
1934 Handle<JSGlobalPropertyCell> cell,
1935 Handle<JSFunction> function,
1936 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001937 // ----------- S t a t e -------------
1938 // -- a2 : name
1939 // -- ra : return address
1940 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
1941 // -- ...
1942 // -- sp[argc * 4] : receiver
1943 // -----------------------------------
1944
1945 // If object is not an array, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001946 if (!object->IsJSArray() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001947
1948 Label miss, return_undefined, call_builtin;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001949 Register receiver = a1;
1950 Register elements = a3;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001951 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001952
1953 // Get the receiver from the stack.
1954 const int argc = arguments().immediate();
1955 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001956 // Check that the receiver isn't a smi.
1957 __ JumpIfSmi(receiver, &miss);
1958
1959 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001960 CheckPrototypes(Handle<JSObject>::cast(object), receiver, holder, elements,
1961 t0, v0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001962
1963 // Get the elements array of the object.
1964 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1965
1966 // Check that the elements are in fast mode and writable.
danno@chromium.org40cb8782011-05-25 07:58:50 +00001967 __ CheckMap(elements,
1968 v0,
1969 Heap::kFixedArrayMapRootIndex,
1970 &call_builtin,
1971 DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001972
1973 // Get the array's length into t0 and calculate new length.
1974 __ lw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1975 __ Subu(t0, t0, Operand(Smi::FromInt(1)));
1976 __ Branch(&return_undefined, lt, t0, Operand(zero_reg));
1977
1978 // Get the last element.
1979 __ LoadRoot(t2, Heap::kTheHoleValueRootIndex);
1980 STATIC_ASSERT(kSmiTagSize == 1);
1981 STATIC_ASSERT(kSmiTag == 0);
1982 // We can't address the last element in one operation. Compute the more
1983 // expensive shift first, and use an offset later on.
1984 __ sll(t1, t0, kPointerSizeLog2 - kSmiTagSize);
1985 __ Addu(elements, elements, t1);
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001986 __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001987 __ Branch(&call_builtin, eq, v0, Operand(t2));
1988
1989 // Set the array's length.
1990 __ sw(t0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1991
1992 // Fill with the hole.
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00001993 __ sw(t2, FieldMemOperand(elements, FixedArray::kHeaderSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001994 __ Drop(argc + 1);
1995 __ Ret();
1996
1997 __ bind(&return_undefined);
1998 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
1999 __ Drop(argc + 1);
2000 __ Ret();
2001
2002 __ bind(&call_builtin);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002003 __ TailCallExternalReference(
2004 ExternalReference(Builtins::c_ArrayPop, isolate()), argc + 1, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002005
2006 // Handle call cache miss.
2007 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002008 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002009
2010 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002011 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002012}
2013
2014
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002015Handle<Code> CallStubCompiler::CompileStringCharCodeAtCall(
2016 Handle<Object> object,
2017 Handle<JSObject> holder,
2018 Handle<JSGlobalPropertyCell> cell,
2019 Handle<JSFunction> function,
2020 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002021 // ----------- S t a t e -------------
2022 // -- a2 : function name
2023 // -- ra : return address
2024 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2025 // -- ...
2026 // -- sp[argc * 4] : receiver
2027 // -----------------------------------
2028
2029 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002030 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002031
2032 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002033 Label miss;
2034 Label name_miss;
2035 Label index_out_of_range;
2036
2037 Label* index_out_of_range_label = &index_out_of_range;
2038
danno@chromium.org40cb8782011-05-25 07:58:50 +00002039 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002040 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00002041 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002042 index_out_of_range_label = &miss;
2043 }
2044
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002045 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002046
2047 // Check that the maps starting from the prototype haven't changed.
2048 GenerateDirectLoadGlobalFunctionPrototype(masm(),
2049 Context::STRING_FUNCTION_INDEX,
2050 v0,
2051 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002052 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002053 CheckPrototypes(
2054 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2055 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002056
2057 Register receiver = a1;
2058 Register index = t1;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002059 Register result = v0;
2060 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
2061 if (argc > 0) {
2062 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
2063 } else {
2064 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
2065 }
2066
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002067 StringCharCodeAtGenerator generator(receiver,
2068 index,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002069 result,
2070 &miss, // When not a string.
2071 &miss, // When not a number.
2072 index_out_of_range_label,
2073 STRING_INDEX_IS_NUMBER);
2074 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002075 __ Drop(argc + 1);
2076 __ Ret();
2077
2078 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002079 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002080
2081 if (index_out_of_range.is_linked()) {
2082 __ bind(&index_out_of_range);
2083 __ LoadRoot(v0, Heap::kNanValueRootIndex);
2084 __ Drop(argc + 1);
2085 __ Ret();
2086 }
2087
2088 __ bind(&miss);
2089 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002090 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002091 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002092 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002093
2094 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002095 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002096}
2097
2098
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002099Handle<Code> CallStubCompiler::CompileStringCharAtCall(
2100 Handle<Object> object,
2101 Handle<JSObject> holder,
2102 Handle<JSGlobalPropertyCell> cell,
2103 Handle<JSFunction> function,
2104 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002105 // ----------- S t a t e -------------
2106 // -- a2 : function name
2107 // -- ra : return address
2108 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2109 // -- ...
2110 // -- sp[argc * 4] : receiver
2111 // -----------------------------------
2112
2113 // If object is not a string, bail out to regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002114 if (!object->IsString() || !cell.is_null()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002115
2116 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002117 Label miss;
2118 Label name_miss;
2119 Label index_out_of_range;
2120 Label* index_out_of_range_label = &index_out_of_range;
danno@chromium.org40cb8782011-05-25 07:58:50 +00002121 if (kind_ == Code::CALL_IC &&
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002122 (CallICBase::StringStubState::decode(extra_state_) ==
danno@chromium.org40cb8782011-05-25 07:58:50 +00002123 DEFAULT_STRING_STUB)) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002124 index_out_of_range_label = &miss;
2125 }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002126 GenerateNameCheck(name, &name_miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002127
2128 // Check that the maps starting from the prototype haven't changed.
2129 GenerateDirectLoadGlobalFunctionPrototype(masm(),
2130 Context::STRING_FUNCTION_INDEX,
2131 v0,
2132 &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002133 ASSERT(!object.is_identical_to(holder));
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002134 CheckPrototypes(
2135 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2136 v0, holder, a1, a3, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002137
2138 Register receiver = v0;
2139 Register index = t1;
danno@chromium.orgc612e022011-11-10 11:38:15 +00002140 Register scratch = a3;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002141 Register result = v0;
2142 __ lw(receiver, MemOperand(sp, argc * kPointerSize));
2143 if (argc > 0) {
2144 __ lw(index, MemOperand(sp, (argc - 1) * kPointerSize));
2145 } else {
2146 __ LoadRoot(index, Heap::kUndefinedValueRootIndex);
2147 }
2148
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002149 StringCharAtGenerator generator(receiver,
2150 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +00002151 scratch,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002152 result,
2153 &miss, // When not a string.
2154 &miss, // When not a number.
2155 index_out_of_range_label,
2156 STRING_INDEX_IS_NUMBER);
2157 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002158 __ Drop(argc + 1);
2159 __ Ret();
2160
2161 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002162 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002163
2164 if (index_out_of_range.is_linked()) {
2165 __ bind(&index_out_of_range);
ulan@chromium.org750145a2013-03-07 15:14:13 +00002166 __ LoadRoot(v0, Heap::kempty_stringRootIndex);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002167 __ Drop(argc + 1);
2168 __ Ret();
2169 }
2170
2171 __ bind(&miss);
2172 // Restore function name in a2.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002173 __ li(a2, name);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002174 __ bind(&name_miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002175 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002176
2177 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002178 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002179}
2180
2181
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002182Handle<Code> CallStubCompiler::CompileStringFromCharCodeCall(
2183 Handle<Object> object,
2184 Handle<JSObject> holder,
2185 Handle<JSGlobalPropertyCell> cell,
2186 Handle<JSFunction> function,
2187 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002188 // ----------- S t a t e -------------
2189 // -- a2 : function name
2190 // -- ra : return address
2191 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2192 // -- ...
2193 // -- sp[argc * 4] : receiver
2194 // -----------------------------------
2195
2196 const int argc = arguments().immediate();
2197
2198 // If the object is not a JSObject or we got an unexpected number of
2199 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002200 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002201
2202 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002203 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002204
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002205 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002206 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
2207
2208 STATIC_ASSERT(kSmiTag == 0);
2209 __ JumpIfSmi(a1, &miss);
2210
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002211 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2212 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002213 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002214 ASSERT(cell->value() == *function);
2215 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2216 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002217 GenerateLoadFunctionFromCell(cell, function, &miss);
2218 }
2219
2220 // Load the char code argument.
2221 Register code = a1;
2222 __ lw(code, MemOperand(sp, 0 * kPointerSize));
2223
2224 // Check the code is a smi.
2225 Label slow;
2226 STATIC_ASSERT(kSmiTag == 0);
2227 __ JumpIfNotSmi(code, &slow);
2228
2229 // Convert the smi code to uint16.
2230 __ And(code, code, Operand(Smi::FromInt(0xffff)));
2231
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002232 StringCharFromCodeGenerator generator(code, v0);
2233 generator.GenerateFast(masm());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002234 __ Drop(argc + 1);
2235 __ Ret();
2236
2237 StubRuntimeCallHelper call_helper;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002238 generator.GenerateSlow(masm(), call_helper);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002239
2240 // Tail call the full function. We do not have to patch the receiver
2241 // because the function makes no use of it.
2242 __ bind(&slow);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002243 ParameterCount expected(function);
2244 __ InvokeFunction(function, expected, arguments(),
2245 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002246
2247 __ bind(&miss);
2248 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002249 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002250
2251 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002252 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002253}
2254
2255
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002256Handle<Code> CallStubCompiler::CompileMathFloorCall(
2257 Handle<Object> object,
2258 Handle<JSObject> holder,
2259 Handle<JSGlobalPropertyCell> cell,
2260 Handle<JSFunction> function,
2261 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002262 // ----------- S t a t e -------------
2263 // -- a2 : function name
2264 // -- ra : return address
2265 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2266 // -- ...
2267 // -- sp[argc * 4] : receiver
2268 // -----------------------------------
2269
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002270
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002271 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002272 // If the object is not a JSObject or we got an unexpected number of
2273 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002274 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002275
2276 Label miss, slow;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002277 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002278
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002279 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002280 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002281 STATIC_ASSERT(kSmiTag == 0);
2282 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002283 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2284 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002285 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002286 ASSERT(cell->value() == *function);
2287 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2288 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002289 GenerateLoadFunctionFromCell(cell, function, &miss);
2290 }
2291
2292 // Load the (only) argument into v0.
2293 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2294
2295 // If the argument is a smi, just return.
2296 STATIC_ASSERT(kSmiTag == 0);
2297 __ And(t0, v0, Operand(kSmiTagMask));
2298 __ Drop(argc + 1, eq, t0, Operand(zero_reg));
2299 __ Ret(eq, t0, Operand(zero_reg));
2300
danno@chromium.org40cb8782011-05-25 07:58:50 +00002301 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002302
2303 Label wont_fit_smi, no_fpu_error, restore_fcsr_and_return;
2304
2305 // If fpu is enabled, we use the floor instruction.
2306
2307 // Load the HeapNumber value.
2308 __ ldc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset));
2309
2310 // Backup FCSR.
2311 __ cfc1(a3, FCSR);
2312 // Clearing FCSR clears the exception mask with no side-effects.
2313 __ ctc1(zero_reg, FCSR);
2314 // Convert the argument to an integer.
2315 __ floor_w_d(f0, f0);
2316
2317 // Start checking for special cases.
2318 // Get the argument exponent and clear the sign bit.
2319 __ lw(t1, FieldMemOperand(v0, HeapNumber::kValueOffset + kPointerSize));
2320 __ And(t2, t1, Operand(~HeapNumber::kSignMask));
2321 __ srl(t2, t2, HeapNumber::kMantissaBitsInTopWord);
2322
2323 // Retrieve FCSR and check for fpu errors.
2324 __ cfc1(t5, FCSR);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00002325 __ And(t5, t5, Operand(kFCSRExceptionFlagMask));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002326 __ Branch(&no_fpu_error, eq, t5, Operand(zero_reg));
2327
2328 // Check for NaN, Infinity, and -Infinity.
2329 // They are invariant through a Math.Floor call, so just
2330 // return the original argument.
2331 __ Subu(t3, t2, Operand(HeapNumber::kExponentMask
2332 >> HeapNumber::kMantissaBitsInTopWord));
2333 __ Branch(&restore_fcsr_and_return, eq, t3, Operand(zero_reg));
2334 // We had an overflow or underflow in the conversion. Check if we
2335 // have a big exponent.
2336 // If greater or equal, the argument is already round and in v0.
2337 __ Branch(&restore_fcsr_and_return, ge, t3,
2338 Operand(HeapNumber::kMantissaBits));
2339 __ Branch(&wont_fit_smi);
2340
2341 __ bind(&no_fpu_error);
2342 // Move the result back to v0.
2343 __ mfc1(v0, f0);
2344 // Check if the result fits into a smi.
2345 __ Addu(a1, v0, Operand(0x40000000));
2346 __ Branch(&wont_fit_smi, lt, a1, Operand(zero_reg));
2347 // Tag the result.
2348 STATIC_ASSERT(kSmiTag == 0);
2349 __ sll(v0, v0, kSmiTagSize);
2350
2351 // Check for -0.
2352 __ Branch(&restore_fcsr_and_return, ne, v0, Operand(zero_reg));
2353 // t1 already holds the HeapNumber exponent.
2354 __ And(t0, t1, Operand(HeapNumber::kSignMask));
2355 // If our HeapNumber is negative it was -0, so load its address and return.
2356 // Else v0 is loaded with 0, so we can also just return.
2357 __ Branch(&restore_fcsr_and_return, eq, t0, Operand(zero_reg));
2358 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2359
2360 __ bind(&restore_fcsr_and_return);
2361 // Restore FCSR and return.
2362 __ ctc1(a3, FCSR);
2363
2364 __ Drop(argc + 1);
2365 __ Ret();
2366
2367 __ bind(&wont_fit_smi);
2368 // Restore FCSR and fall to slow case.
2369 __ ctc1(a3, FCSR);
2370
2371 __ bind(&slow);
2372 // Tail call the full function. We do not have to patch the receiver
2373 // because the function makes no use of it.
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002374 ParameterCount expected(function);
2375 __ InvokeFunction(function, expected, arguments(),
2376 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002377
2378 __ bind(&miss);
2379 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002380 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002381
2382 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002383 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002384}
2385
2386
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002387Handle<Code> CallStubCompiler::CompileMathAbsCall(
2388 Handle<Object> object,
2389 Handle<JSObject> holder,
2390 Handle<JSGlobalPropertyCell> cell,
2391 Handle<JSFunction> function,
2392 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002393 // ----------- S t a t e -------------
2394 // -- a2 : function name
2395 // -- ra : return address
2396 // -- sp[(argc - n - 1) * 4] : arg[n] (zero-based)
2397 // -- ...
2398 // -- sp[argc * 4] : receiver
2399 // -----------------------------------
2400
2401 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002402 // If the object is not a JSObject or we got an unexpected number of
2403 // arguments, bail out to the regular call.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002404 if (!object->IsJSObject() || argc != 1) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002405
2406 Label miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002407
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002408 GenerateNameCheck(name, &miss);
2409 if (cell.is_null()) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002410 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002411 STATIC_ASSERT(kSmiTag == 0);
2412 __ JumpIfSmi(a1, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002413 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, v0, a3, t0,
2414 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002415 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002416 ASSERT(cell->value() == *function);
2417 GenerateGlobalReceiverCheck(Handle<JSObject>::cast(object), holder, name,
2418 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002419 GenerateLoadFunctionFromCell(cell, function, &miss);
2420 }
2421
2422 // Load the (only) argument into v0.
2423 __ lw(v0, MemOperand(sp, 0 * kPointerSize));
2424
2425 // Check if the argument is a smi.
2426 Label not_smi;
2427 STATIC_ASSERT(kSmiTag == 0);
2428 __ JumpIfNotSmi(v0, &not_smi);
2429
2430 // Do bitwise not or do nothing depending on the sign of the
2431 // argument.
2432 __ sra(t0, v0, kBitsPerInt - 1);
2433 __ Xor(a1, v0, t0);
2434
2435 // Add 1 or do nothing depending on the sign of the argument.
2436 __ Subu(v0, a1, t0);
2437
2438 // If the result is still negative, go to the slow case.
2439 // This only happens for the most negative smi.
2440 Label slow;
2441 __ Branch(&slow, lt, v0, Operand(zero_reg));
2442
2443 // Smi case done.
2444 __ Drop(argc + 1);
2445 __ Ret();
2446
2447 // Check if the argument is a heap number and load its exponent and
2448 // sign.
2449 __ bind(&not_smi);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002450 __ CheckMap(v0, a1, Heap::kHeapNumberMapRootIndex, &slow, DONT_DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002451 __ lw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2452
2453 // Check the sign of the argument. If the argument is positive,
2454 // just return it.
2455 Label negative_sign;
2456 __ And(t0, a1, Operand(HeapNumber::kSignMask));
2457 __ Branch(&negative_sign, ne, t0, Operand(zero_reg));
2458 __ Drop(argc + 1);
2459 __ Ret();
2460
2461 // If the argument is negative, clear the sign, and return a new
2462 // number.
2463 __ bind(&negative_sign);
2464 __ Xor(a1, a1, Operand(HeapNumber::kSignMask));
2465 __ lw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2466 __ LoadRoot(t2, Heap::kHeapNumberMapRootIndex);
2467 __ AllocateHeapNumber(v0, t0, t1, t2, &slow);
2468 __ sw(a1, FieldMemOperand(v0, HeapNumber::kExponentOffset));
2469 __ sw(a3, FieldMemOperand(v0, HeapNumber::kMantissaOffset));
2470 __ Drop(argc + 1);
2471 __ Ret();
2472
2473 // Tail call the full function. We do not have to patch the receiver
2474 // because the function makes no use of it.
2475 __ bind(&slow);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002476 ParameterCount expected(function);
2477 __ InvokeFunction(function, expected, arguments(),
2478 JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002479
2480 __ bind(&miss);
2481 // a2: function name.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002482 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002483
2484 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002485 return cell.is_null() ? GetCode(function) : GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002486}
2487
2488
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002489Handle<Code> CallStubCompiler::CompileFastApiCall(
lrn@chromium.org7516f052011-03-30 08:52:27 +00002490 const CallOptimization& optimization,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002491 Handle<Object> object,
2492 Handle<JSObject> holder,
2493 Handle<JSGlobalPropertyCell> cell,
2494 Handle<JSFunction> function,
2495 Handle<String> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002496
danno@chromium.org40cb8782011-05-25 07:58:50 +00002497 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002498
2499 ASSERT(optimization.is_simple_api_call());
2500 // Bail out if object is a global object as we don't want to
2501 // repatch it to global receiver.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002502 if (object->IsGlobalObject()) return Handle<Code>::null();
2503 if (!cell.is_null()) return Handle<Code>::null();
2504 if (!object->IsJSObject()) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002505 int depth = optimization.GetPrototypeDepthOfExpectedType(
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002506 Handle<JSObject>::cast(object), holder);
2507 if (depth == kInvalidProtoDepth) return Handle<Code>::null();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002508
2509 Label miss, miss_before_stack_reserved;
2510
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002511 GenerateNameCheck(name, &miss_before_stack_reserved);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002512
2513 // Get the receiver from the stack.
2514 const int argc = arguments().immediate();
2515 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2516
2517 // Check that the receiver isn't a smi.
2518 __ JumpIfSmi(a1, &miss_before_stack_reserved);
2519
2520 __ IncrementCounter(counters->call_const(), 1, a0, a3);
2521 __ IncrementCounter(counters->call_const_fast_api(), 1, a0, a3);
2522
2523 ReserveSpaceForFastApiCall(masm(), a0);
2524
2525 // Check that the maps haven't changed and find a Holder as a side effect.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002526 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0, name,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002527 depth, &miss);
2528
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002529 GenerateFastApiDirectCall(masm(), optimization, argc);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002530
2531 __ bind(&miss);
2532 FreeSpaceForFastApiCall(masm());
2533
2534 __ bind(&miss_before_stack_reserved);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002535 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002536
2537 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002538 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002539}
2540
2541
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002542void CallStubCompiler::CompileHandlerFrontend(Handle<Object> object,
2543 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002544 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002545 CheckType check,
2546 Label* success) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002547 // ----------- S t a t e -------------
2548 // -- a2 : name
2549 // -- ra : return address
2550 // -----------------------------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002551 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002552 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002553
2554 // Get the receiver from the stack.
2555 const int argc = arguments().immediate();
2556 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2557
2558 // Check that the receiver isn't a smi.
2559 if (check != NUMBER_CHECK) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002560 __ JumpIfSmi(a1, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002561 }
2562
2563 // Make sure that it's okay not to patch the on stack receiver
2564 // unless we're doing a receiver map check.
2565 ASSERT(!object->IsGlobalObject() || check == RECEIVER_MAP_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002566 switch (check) {
2567 case RECEIVER_MAP_CHECK:
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002568 __ IncrementCounter(isolate()->counters()->call_const(), 1, a0, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002569
2570 // Check that the maps haven't changed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002571 CheckPrototypes(Handle<JSObject>::cast(object), a1, holder, a0, a3, t0,
2572 name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002573
2574 // Patch the receiver on the stack with the global proxy if
2575 // necessary.
2576 if (object->IsGlobalObject()) {
2577 __ lw(a3, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2578 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2579 }
2580 break;
2581
2582 case STRING_CHECK:
ulan@chromium.org750145a2013-03-07 15:14:13 +00002583 // Check that the object is a string.
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002584 __ GetObjectType(a1, a3, a3);
2585 __ Branch(&miss, Ugreater_equal, a3, Operand(FIRST_NONSTRING_TYPE));
2586 // Check that the maps starting from the prototype haven't changed.
2587 GenerateDirectLoadGlobalFunctionPrototype(
2588 masm(), Context::STRING_FUNCTION_INDEX, a0, &miss);
2589 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002590 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002591 a0, holder, a3, a1, t0, name, &miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002592 break;
2593
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002594 case SYMBOL_CHECK:
2595 // Check that the object is a symbol.
2596 __ GetObjectType(a1, a1, a3);
2597 __ Branch(&miss, ne, a3, Operand(SYMBOL_TYPE));
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00002598 // Check that the maps starting from the prototype haven't changed.
2599 GenerateDirectLoadGlobalFunctionPrototype(
2600 masm(), Context::SYMBOL_FUNCTION_INDEX, a0, &miss);
2601 CheckPrototypes(
2602 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
2603 a0, holder, a3, a1, t0, name, &miss);
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002604 break;
2605
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002606 case NUMBER_CHECK: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002607 Label fast;
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002608 // Check that the object is a smi or a heap number.
2609 __ JumpIfSmi(a1, &fast);
2610 __ GetObjectType(a1, a0, a0);
2611 __ Branch(&miss, ne, a0, Operand(HEAP_NUMBER_TYPE));
2612 __ bind(&fast);
2613 // Check that the maps starting from the prototype haven't changed.
2614 GenerateDirectLoadGlobalFunctionPrototype(
2615 masm(), Context::NUMBER_FUNCTION_INDEX, a0, &miss);
2616 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002617 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002618 a0, holder, a3, a1, t0, name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002619 break;
2620 }
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002621 case BOOLEAN_CHECK: {
2622 Label fast;
2623 // Check that the object is a boolean.
2624 __ LoadRoot(t0, Heap::kTrueValueRootIndex);
2625 __ Branch(&fast, eq, a1, Operand(t0));
2626 __ LoadRoot(t0, Heap::kFalseValueRootIndex);
2627 __ Branch(&miss, ne, a1, Operand(t0));
2628 __ bind(&fast);
2629 // Check that the maps starting from the prototype haven't changed.
2630 GenerateDirectLoadGlobalFunctionPrototype(
2631 masm(), Context::BOOLEAN_FUNCTION_INDEX, a0, &miss);
2632 CheckPrototypes(
hpayer@chromium.org8432c912013-02-28 15:55:26 +00002633 Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate()))),
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002634 a0, holder, a3, a1, t0, name, &miss);
2635 break;
2636 }
2637 }
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002638
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002639 __ jmp(success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002640
2641 // Handle call cache miss.
2642 __ bind(&miss);
2643
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002644 GenerateMissBranch();
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002645}
2646
2647
2648void CallStubCompiler::CompileHandlerBackend(Handle<JSFunction> function) {
2649 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
2650 ? CALL_AS_FUNCTION
2651 : CALL_AS_METHOD;
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002652 ParameterCount expected(function);
2653 __ InvokeFunction(function, expected, arguments(),
2654 JUMP_FUNCTION, NullCallWrapper(), call_kind);
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002655}
2656
2657
2658Handle<Code> CallStubCompiler::CompileCallConstant(
2659 Handle<Object> object,
2660 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002661 Handle<Name> name,
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002662 CheckType check,
2663 Handle<JSFunction> function) {
2664 if (HasCustomCallGenerator(function)) {
2665 Handle<Code> code = CompileCustomCall(object, holder,
2666 Handle<JSGlobalPropertyCell>::null(),
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002667 function, Handle<String>::cast(name));
mmassi@chromium.org2f0efde2013-02-06 14:12:58 +00002668 // A null handle means bail out to the regular compiler code below.
2669 if (!code.is_null()) return code;
2670 }
2671
2672 Label success;
2673
2674 CompileHandlerFrontend(object, holder, name, check, &success);
2675 __ bind(&success);
2676 CompileHandlerBackend(function);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002677
2678 // Return the generated code.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002679 return GetCode(function);
ager@chromium.org5c838252010-02-19 08:53:10 +00002680}
2681
2682
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002683Handle<Code> CallStubCompiler::CompileCallInterceptor(Handle<JSObject> object,
2684 Handle<JSObject> holder,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002685 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002686 // ----------- S t a t e -------------
2687 // -- a2 : name
2688 // -- ra : return address
2689 // -----------------------------------
2690
2691 Label miss;
2692
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002693 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002694
2695 // Get the number of arguments.
2696 const int argc = arguments().immediate();
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002697 LookupResult lookup(isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002698 LookupPostInterceptor(holder, name, &lookup);
2699
2700 // Get the receiver from the stack.
2701 __ lw(a1, MemOperand(sp, argc * kPointerSize));
2702
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002703 CallInterceptorCompiler compiler(this, arguments(), a2, extra_state_);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002704 compiler.Compile(masm(), object, holder, name, &lookup, a1, a3, t0, a0,
2705 &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002706
2707 // Move returned value, the function to call, to a1.
2708 __ mov(a1, v0);
2709 // Restore receiver.
2710 __ lw(a0, MemOperand(sp, argc * kPointerSize));
2711
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002712 GenerateCallFunction(masm(), object, arguments(), &miss, extra_state_);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002713
2714 // Handle call cache miss.
2715 __ bind(&miss);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002716 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002717
2718 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002719 return GetCode(Code::INTERCEPTOR, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002720}
2721
2722
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002723Handle<Code> CallStubCompiler::CompileCallGlobal(
2724 Handle<JSObject> object,
2725 Handle<GlobalObject> holder,
2726 Handle<JSGlobalPropertyCell> cell,
2727 Handle<JSFunction> function,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002728 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002729 // ----------- S t a t e -------------
2730 // -- a2 : name
2731 // -- ra : return address
2732 // -----------------------------------
2733
2734 if (HasCustomCallGenerator(function)) {
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002735 Handle<Code> code = CompileCustomCall(
2736 object, holder, cell, function, Handle<String>::cast(name));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002737 // A null handle means bail out to the regular compiler code below.
2738 if (!code.is_null()) return code;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002739 }
2740
2741 Label miss;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002742 GenerateNameCheck(name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002743
2744 // Get the number of arguments.
2745 const int argc = arguments().immediate();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002746 GenerateGlobalReceiverCheck(object, holder, name, &miss);
2747 GenerateLoadFunctionFromCell(cell, function, &miss);
2748
2749 // Patch the receiver on the stack with the global proxy if
2750 // necessary.
2751 if (object->IsGlobalObject()) {
2752 __ lw(a3, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset));
2753 __ sw(a3, MemOperand(sp, argc * kPointerSize));
2754 }
2755
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002756 // Set up the context (function already in r1).
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002757 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2758
2759 // Jump to the cached code (tail call).
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002760 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002761 __ IncrementCounter(counters->call_global_inline(), 1, a3, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002762 ParameterCount expected(function->shared()->formal_parameter_count());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002763 CallKind call_kind = CallICBase::Contextual::decode(extra_state_)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002764 ? CALL_AS_FUNCTION
2765 : CALL_AS_METHOD;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002766 // We call indirectly through the code field in the function to
2767 // allow recompilation to take effect without changing any of the
2768 // call sites.
2769 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2770 __ InvokeCode(a3, expected, arguments(), JUMP_FUNCTION,
2771 NullCallWrapper(), call_kind);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002772
2773 // Handle call cache miss.
2774 __ bind(&miss);
2775 __ IncrementCounter(counters->call_global_inline_miss(), 1, a1, a3);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002776 GenerateMissBranch();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002777
2778 // Return the generated code.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002779 return GetCode(Code::NORMAL, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002780}
2781
2782
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002783Handle<Code> StoreStubCompiler::CompileStoreCallback(
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002784 Handle<Name> name,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002785 Handle<JSObject> object,
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002786 Handle<JSObject> holder,
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00002787 Handle<ExecutableAccessorInfo> callback) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002788 Label miss;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002789 // Check that the maps haven't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002790 __ JumpIfSmi(receiver(), &miss);
2791 CheckPrototypes(object, receiver(), holder,
2792 scratch1(), scratch2(), scratch3(), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002793
2794 // Stub never generated for non-global objects that require access
2795 // checks.
yangguo@chromium.org355cfd12012-08-29 15:32:24 +00002796 ASSERT(holder->IsJSGlobalProxy() || !holder->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002797
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002798 __ push(receiver()); // Receiver.
2799 __ li(at, Operand(callback)); // Callback info.
2800 __ Push(at, this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002801
2802 // Do tail-call to the runtime system.
2803 ExternalReference store_callback_property =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002804 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002805 __ TailCallExternalReference(store_callback_property, 4, 1);
2806
2807 // Handle store cache miss.
2808 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002809 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002810
2811 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002812 return GetICCode(kind(), Code::CALLBACKS, name);
ager@chromium.org5c838252010-02-19 08:53:10 +00002813}
2814
2815
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00002816#undef __
2817#define __ ACCESS_MASM(masm)
2818
2819
2820void StoreStubCompiler::GenerateStoreViaSetter(
2821 MacroAssembler* masm,
2822 Handle<JSFunction> setter) {
2823 // ----------- S t a t e -------------
2824 // -- a0 : value
2825 // -- a1 : receiver
2826 // -- a2 : name
2827 // -- ra : return address
2828 // -----------------------------------
2829 {
2830 FrameScope scope(masm, StackFrame::INTERNAL);
2831
2832 // Save value register, so we can restore it later.
2833 __ push(a0);
2834
2835 if (!setter.is_null()) {
2836 // Call the JavaScript setter with receiver and value on the stack.
2837 __ push(a1);
2838 __ push(a0);
2839 ParameterCount actual(1);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002840 ParameterCount expected(setter);
2841 __ InvokeFunction(setter, expected, actual,
2842 CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00002843 } else {
2844 // If we generate a global code snippet for deoptimization only, remember
2845 // the place to continue after deoptimization.
2846 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
2847 }
2848
2849 // We have to return the passed value, not the return value of the setter.
2850 __ pop(v0);
2851
2852 // Restore context register.
2853 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2854 }
2855 __ Ret();
2856}
2857
2858
2859#undef __
2860#define __ ACCESS_MASM(masm())
2861
2862
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002863Handle<Code> StoreStubCompiler::CompileStoreInterceptor(
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002864 Handle<JSObject> object,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002865 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002866 Label miss;
2867
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002868 // Check that the map of the object hasn't changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002869 __ CheckMap(receiver(), scratch1(), Handle<Map>(object->map()), &miss,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00002870 DO_SMI_CHECK);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002871
2872 // Perform global security token check if needed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002873 if (object->IsJSGlobalProxy()) {
2874 __ CheckAccessGlobalProxy(receiver(), scratch1(), &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002875 }
2876
2877 // Stub is never generated for non-global objects that require access
2878 // checks.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002879 ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002880
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002881 __ Push(receiver(), this->name(), value());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002882
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002883 __ li(scratch1(), Operand(Smi::FromInt(strict_mode())));
2884 __ push(scratch1()); // strict mode
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002885
2886 // Do tail-call to the runtime system.
2887 ExternalReference store_ic_property =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002888 ExternalReference(IC_Utility(IC::kStoreInterceptorProperty), isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002889 __ TailCallExternalReference(store_ic_property, 4, 1);
2890
2891 // Handle store cache miss.
2892 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002893 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002894
2895 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002896 return GetICCode(kind(), Code::INTERCEPTOR, name);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00002897}
2898
2899
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00002900Handle<Code> StoreStubCompiler::CompileStoreGlobal(
2901 Handle<GlobalObject> object,
2902 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002903 Handle<Name> name) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002904 Label miss;
2905
2906 // Check that the map of the global has not changed.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002907 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
2908 __ Branch(&miss, ne, scratch1(), Operand(Handle<Map>(object->map())));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002909
2910 // Check that the value in the cell is not the hole. If it is, this
2911 // cell could have been deleted and reintroducing the global needs
2912 // to update the property details in the property dictionary of the
2913 // global object. We bail out to the runtime system to do that.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002914 __ li(scratch1(), Operand(cell));
2915 __ LoadRoot(scratch2(), Heap::kTheHoleValueRootIndex);
2916 __ lw(scratch3(),
2917 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
2918 __ Branch(&miss, eq, scratch3(), Operand(scratch2()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002919
2920 // Store the value in the cell.
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002921 __ sw(value(),
2922 FieldMemOperand(scratch1(), JSGlobalPropertyCell::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002923 __ mov(v0, a0); // Stored value must be returned in v0.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002924 // Cells are always rescanned, so no write barrier here.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00002925
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00002926 Counters* counters = isolate()->counters();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002927 __ IncrementCounter(
2928 counters->named_store_global_inline(), 1, scratch1(), scratch2());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002929 __ Ret();
2930
2931 // Handle store cache miss.
2932 __ bind(&miss);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00002933 __ IncrementCounter(
2934 counters->named_store_global_inline_miss(), 1, scratch1(), scratch2());
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002935 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002936
2937 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002938 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002939}
2940
2941
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002942Handle<Code> LoadStubCompiler::CompileLoadNonexistent(
2943 Handle<JSObject> object,
2944 Handle<JSObject> last,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002945 Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002946 Handle<GlobalObject> global) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002947 Label success;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002948
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002949 NonexistentHandlerFrontend(object, last, name, &success, global);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002950
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00002951 __ bind(&success);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002952 // Return undefined if maps of the full prototype chain is still the same.
2953 __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2954 __ Ret();
2955
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002956 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002957 return GetCode(kind(), Code::NONEXISTENT, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00002958}
2959
2960
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002961Register* LoadStubCompiler::registers() {
2962 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2963 static Register registers[] = { a0, a2, a3, a1, t0, t1 };
2964 return registers;
lrn@chromium.org7516f052011-03-30 08:52:27 +00002965}
2966
2967
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002968Register* KeyedLoadStubCompiler::registers() {
2969 // receiver, name, scratch1, scratch2, scratch3, scratch4.
2970 static Register registers[] = { a1, a0, a2, a3, t0, t1 };
2971 return registers;
2972}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00002973
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002974
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002975Register* StoreStubCompiler::registers() {
2976 // receiver, name, value, scratch1, scratch2, scratch3.
2977 static Register registers[] = { a1, a2, a0, a3, t0, t1 };
2978 return registers;
2979}
2980
2981
2982Register* KeyedStoreStubCompiler::registers() {
2983 // receiver, name, value, scratch1, scratch2, scratch3.
2984 static Register registers[] = { a2, a1, a0, a3, t0, t1 };
2985 return registers;
2986}
2987
2988
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00002989void KeyedLoadStubCompiler::GenerateNameCheck(Handle<Name> name,
danno@chromium.org94b0d6f2013-02-04 13:33:20 +00002990 Register name_reg,
2991 Label* miss) {
2992 __ Branch(miss, ne, name_reg, Operand(name));
lrn@chromium.org7516f052011-03-30 08:52:27 +00002993}
2994
2995
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00002996void KeyedStoreStubCompiler::GenerateNameCheck(Handle<Name> name,
2997 Register name_reg,
2998 Label* miss) {
2999 __ Branch(miss, ne, name_reg, Operand(name));
3000}
3001
3002
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00003003#undef __
3004#define __ ACCESS_MASM(masm)
3005
3006
3007void LoadStubCompiler::GenerateLoadViaGetter(MacroAssembler* masm,
3008 Handle<JSFunction> getter) {
3009 // ----------- S t a t e -------------
3010 // -- a0 : receiver
3011 // -- a2 : name
3012 // -- ra : return address
3013 // -----------------------------------
3014 {
3015 FrameScope scope(masm, StackFrame::INTERNAL);
3016
3017 if (!getter.is_null()) {
3018 // Call the JavaScript getter with the receiver on the stack.
3019 __ push(a0);
3020 ParameterCount actual(0);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003021 ParameterCount expected(getter);
3022 __ InvokeFunction(getter, expected, actual,
3023 CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD);
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00003024 } else {
3025 // If we generate a global code snippet for deoptimization only, remember
3026 // the place to continue after deoptimization.
3027 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
3028 }
3029
3030 // Restore context register.
3031 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3032 }
3033 __ Ret();
3034}
3035
3036
3037#undef __
3038#define __ ACCESS_MASM(masm())
3039
3040
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003041Handle<Code> LoadStubCompiler::CompileLoadGlobal(
3042 Handle<JSObject> object,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003043 Handle<GlobalObject> global,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003044 Handle<JSGlobalPropertyCell> cell,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003045 Handle<Name> name,
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003046 bool is_dont_delete) {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003047 Label success, miss;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003048
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003049 __ CheckMap(
3050 receiver(), scratch1(), Handle<Map>(object->map()), &miss, DO_SMI_CHECK);
3051 HandlerFrontendHeader(
3052 object, receiver(), Handle<JSObject>::cast(global), name, &miss);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003053
3054 // Get the value from the cell.
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003055 __ li(a3, Operand(cell));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003056 __ lw(t0, FieldMemOperand(a3, JSGlobalPropertyCell::kValueOffset));
3057
3058 // Check for deleted property if property can actually be deleted.
3059 if (!is_dont_delete) {
3060 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
3061 __ Branch(&miss, eq, t0, Operand(at));
3062 }
3063
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003064 HandlerFrontendFooter(&success, &miss);
3065 __ bind(&success);
3066
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003067 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003068 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003069 __ mov(v0, t0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003070 __ Ret();
3071
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003072 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003073 return GetICCode(kind(), Code::NORMAL, name);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003074}
3075
3076
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00003077Handle<Code> BaseLoadStubCompiler::CompilePolymorphicIC(
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003078 MapHandleList* receiver_maps,
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003079 CodeHandleList* handlers,
3080 Handle<Name> name,
3081 Code::StubType type,
3082 IcCheckType check) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003083 Label miss;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003084
3085 if (check == PROPERTY) {
3086 GenerateNameCheck(name, this->name(), &miss);
3087 }
3088
3089 __ JumpIfSmi(receiver(), &miss);
3090 Register map_reg = scratch1();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003091
danno@chromium.org40cb8782011-05-25 07:58:50 +00003092 int receiver_count = receiver_maps->length();
danno@chromium.orgf005df62013-04-30 16:36:45 +00003093 int number_of_handled_maps = 0;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003094 __ lw(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003095 for (int current = 0; current < receiver_count; ++current) {
danno@chromium.orgf005df62013-04-30 16:36:45 +00003096 Handle<Map> map = receiver_maps->at(current);
3097 if (!map->is_deprecated()) {
3098 number_of_handled_maps++;
3099 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET,
3100 eq, map_reg, Operand(receiver_maps->at(current)));
3101 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003102 }
danno@chromium.orgf005df62013-04-30 16:36:45 +00003103 ASSERT(number_of_handled_maps != 0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003104
3105 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003106 TailCallBuiltin(masm(), MissBuiltin(kind()));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003107
3108 // Return the generated code.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003109 InlineCacheState state =
danno@chromium.orgf005df62013-04-30 16:36:45 +00003110 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC;
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003111 return GetICCode(kind(), type, name, state);
lrn@chromium.org7516f052011-03-30 08:52:27 +00003112}
3113
3114
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003115Handle<Code> KeyedStoreStubCompiler::CompileStorePolymorphic(
3116 MapHandleList* receiver_maps,
3117 CodeHandleList* handler_stubs,
3118 MapHandleList* transitioned_maps) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003119 Label miss;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003120 __ JumpIfSmi(receiver(), &miss);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003121
3122 int receiver_count = receiver_maps->length();
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003123 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003124 for (int i = 0; i < receiver_count; ++i) {
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003125 if (transitioned_maps->at(i).is_null()) {
3126 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003127 scratch1(), Operand(receiver_maps->at(i)));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003128 } else {
3129 Label next_map;
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003130 __ Branch(&next_map, ne, scratch1(), Operand(receiver_maps->at(i)));
3131 __ li(transition_map(), Operand(transitioned_maps->at(i)));
erik.corry@gmail.com6e28b562011-10-27 14:20:17 +00003132 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003133 __ bind(&next_map);
3134 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003135 }
3136
3137 __ bind(&miss);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003138 TailCallBuiltin(masm(), MissBuiltin(kind()));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003139
3140 // Return the generated code.
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003141 return GetICCode(
3142 kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003143}
3144
3145
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003146Handle<Code> ConstructStubCompiler::CompileConstructStub(
3147 Handle<JSFunction> function) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003148 // a0 : argc
3149 // a1 : constructor
3150 // ra : return address
3151 // [sp] : last argument
3152 Label generic_stub_call;
3153
3154 // Use t7 for holding undefined which is used in several places below.
3155 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex);
3156
3157#ifdef ENABLE_DEBUGGER_SUPPORT
3158 // Check to see whether there are any break points in the function code. If
3159 // there are jump to the generic constructor stub which calls the actual
3160 // code for the function thereby hitting the break points.
3161 __ lw(t5, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
3162 __ lw(a2, FieldMemOperand(t5, SharedFunctionInfo::kDebugInfoOffset));
3163 __ Branch(&generic_stub_call, ne, a2, Operand(t7));
3164#endif
3165
3166 // Load the initial map and verify that it is in fact a map.
3167 // a1: constructor function
3168 // t7: undefined
3169 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003170 __ JumpIfSmi(a2, &generic_stub_call);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003171 __ GetObjectType(a2, a3, t0);
3172 __ Branch(&generic_stub_call, ne, t0, Operand(MAP_TYPE));
3173
3174#ifdef DEBUG
3175 // Cannot construct functions this way.
3176 // a0: argc
3177 // a1: constructor function
3178 // a2: initial map
3179 // t7: undefined
3180 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset));
3181 __ Check(ne, "Function constructed by construct stub.",
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003182 a3, Operand(JS_FUNCTION_TYPE));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003183#endif
3184
3185 // Now allocate the JSObject in new space.
3186 // a0: argc
3187 // a1: constructor function
3188 // a2: initial map
3189 // t7: undefined
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003190 ASSERT(function->has_initial_map());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003191 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +00003192#ifdef DEBUG
3193 int instance_size = function->initial_map()->instance_size();
3194 __ Check(eq, "Instance size of initial map changed.",
3195 a3, Operand(instance_size >> kPointerSizeLog2));
3196#endif
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +00003197 __ Allocate(a3, t4, t5, t6, &generic_stub_call, SIZE_IN_WORDS);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003198
3199 // Allocated the JSObject, now initialize the fields. Map is set to initial
3200 // map and properties and elements are set to empty fixed array.
3201 // a0: argc
3202 // a1: constructor function
3203 // a2: initial map
3204 // a3: object size (in words)
3205 // t4: JSObject (not tagged)
3206 // t7: undefined
3207 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
3208 __ mov(t5, t4);
3209 __ sw(a2, MemOperand(t5, JSObject::kMapOffset));
3210 __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset));
3211 __ sw(t6, MemOperand(t5, JSObject::kElementsOffset));
3212 __ Addu(t5, t5, Operand(3 * kPointerSize));
3213 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset);
3214 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset);
3215 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset);
3216
3217
3218 // Calculate the location of the first argument. The stack contains only the
3219 // argc arguments.
3220 __ sll(a1, a0, kPointerSizeLog2);
3221 __ Addu(a1, a1, sp);
3222
3223 // Fill all the in-object properties with undefined.
3224 // a0: argc
3225 // a1: first argument
3226 // a3: object size (in words)
3227 // t4: JSObject (not tagged)
3228 // t5: First in-object property of JSObject (not tagged)
3229 // t7: undefined
3230 // Fill the initialized properties with a constant value or a passed argument
3231 // depending on the this.x = ...; assignment in the function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003232 Handle<SharedFunctionInfo> shared(function->shared());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003233 for (int i = 0; i < shared->this_property_assignments_count(); i++) {
3234 if (shared->IsThisPropertyAssignmentArgument(i)) {
3235 Label not_passed, next;
3236 // Check if the argument assigned to the property is actually passed.
3237 int arg_number = shared->GetThisPropertyAssignmentArgument(i);
3238 __ Branch(&not_passed, less_equal, a0, Operand(arg_number));
3239 // Argument passed - find it on the stack.
3240 __ lw(a2, MemOperand(a1, (arg_number + 1) * -kPointerSize));
3241 __ sw(a2, MemOperand(t5));
3242 __ Addu(t5, t5, kPointerSize);
3243 __ jmp(&next);
3244 __ bind(&not_passed);
3245 // Set the property to undefined.
3246 __ sw(t7, MemOperand(t5));
3247 __ Addu(t5, t5, Operand(kPointerSize));
3248 __ bind(&next);
3249 } else {
3250 // Set the property to the constant value.
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003251 Handle<Object> constant(
3252 shared->GetThisPropertyAssignmentConstant(i), isolate());
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003253 __ li(a2, Operand(constant));
3254 __ sw(a2, MemOperand(t5));
3255 __ Addu(t5, t5, kPointerSize);
3256 }
3257 }
3258
3259 // Fill the unused in-object property fields with undefined.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003260 for (int i = shared->this_property_assignments_count();
3261 i < function->initial_map()->inobject_properties();
3262 i++) {
3263 __ sw(t7, MemOperand(t5));
3264 __ Addu(t5, t5, kPointerSize);
3265 }
3266
3267 // a0: argc
3268 // t4: JSObject (not tagged)
3269 // Move argc to a1 and the JSObject to return to v0 and tag it.
3270 __ mov(a1, a0);
3271 __ mov(v0, t4);
3272 __ Or(v0, v0, Operand(kHeapObjectTag));
3273
3274 // v0: JSObject
3275 // a1: argc
3276 // Remove caller arguments and receiver from the stack and return.
3277 __ sll(t0, a1, kPointerSizeLog2);
3278 __ Addu(sp, sp, t0);
3279 __ Addu(sp, sp, Operand(kPointerSize));
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003280 Counters* counters = isolate()->counters();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003281 __ IncrementCounter(counters->constructed_objects(), 1, a1, a2);
3282 __ IncrementCounter(counters->constructed_objects_stub(), 1, a1, a2);
3283 __ Ret();
3284
3285 // Jump to the generic stub in case the specialized code cannot handle the
3286 // construction.
3287 __ bind(&generic_stub_call);
3288 Handle<Code> generic_construct_stub =
ulan@chromium.org32d7dba2013-04-24 10:59:06 +00003289 isolate()->builtins()->JSConstructStubGeneric();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003290 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
3291
3292 // Return the generated code.
3293 return GetCode();
3294}
3295
3296
danno@chromium.org40cb8782011-05-25 07:58:50 +00003297#undef __
3298#define __ ACCESS_MASM(masm)
3299
3300
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003301void KeyedLoadStubCompiler::GenerateLoadDictionaryElement(
3302 MacroAssembler* masm) {
3303 // ---------- S t a t e --------------
3304 // -- ra : return address
3305 // -- a0 : key
3306 // -- a1 : receiver
3307 // -----------------------------------
3308 Label slow, miss_force_generic;
3309
3310 Register key = a0;
3311 Register receiver = a1;
3312
3313 __ JumpIfNotSmi(key, &miss_force_generic);
3314 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
3315 __ sra(a2, a0, kSmiTagSize);
3316 __ LoadFromNumberDictionary(&slow, t0, a0, v0, a2, a3, t1);
3317 __ Ret();
3318
3319 // Slow case, key and receiver still in a0 and a1.
3320 __ bind(&slow);
3321 __ IncrementCounter(
3322 masm->isolate()->counters()->keyed_load_external_array_slow(),
3323 1, a2, a3);
3324 // Entry registers are intact.
3325 // ---------- S t a t e --------------
3326 // -- ra : return address
3327 // -- a0 : key
3328 // -- a1 : receiver
3329 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003330 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003331
3332 // Miss case, call the runtime.
3333 __ bind(&miss_force_generic);
3334
3335 // ---------- S t a t e --------------
3336 // -- ra : return address
3337 // -- a0 : key
3338 // -- a1 : receiver
3339 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003340 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_MissForceGeneric);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003341}
3342
3343
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003344static void GenerateSmiKeyCheck(MacroAssembler* masm,
3345 Register key,
3346 Register scratch0,
3347 Register scratch1,
3348 FPURegister double_scratch0,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003349 FPURegister double_scratch1,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003350 Label* fail) {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003351 Label key_ok;
3352 // Check for smi or a smi inside a heap number. We convert the heap
3353 // number and check if the conversion is exact and fits into the smi
3354 // range.
3355 __ JumpIfSmi(key, &key_ok);
3356 __ CheckMap(key,
3357 scratch0,
3358 Heap::kHeapNumberMapRootIndex,
3359 fail,
3360 DONT_DO_SMI_CHECK);
3361 __ ldc1(double_scratch0, FieldMemOperand(key, HeapNumber::kValueOffset));
3362 __ EmitFPUTruncate(kRoundToZero,
3363 scratch0,
3364 double_scratch0,
3365 at,
3366 double_scratch1,
3367 scratch1,
3368 kCheckForInexactConversion);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003369
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003370 __ Branch(fail, ne, scratch1, Operand(zero_reg));
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003371
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003372 __ SmiTagCheckOverflow(key, scratch0, scratch1);
3373 __ BranchOnOverflow(fail, scratch1);
3374 __ bind(&key_ok);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003375}
3376
3377
danno@chromium.org40cb8782011-05-25 07:58:50 +00003378void KeyedStoreStubCompiler::GenerateStoreExternalArray(
3379 MacroAssembler* masm,
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003380 ElementsKind elements_kind) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003381 // ---------- S t a t e --------------
3382 // -- a0 : value
3383 // -- a1 : key
3384 // -- a2 : receiver
3385 // -- ra : return address
3386 // -----------------------------------
3387
danno@chromium.org40cb8782011-05-25 07:58:50 +00003388 Label slow, check_heap_number, miss_force_generic;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003389
3390 // Register usage.
3391 Register value = a0;
3392 Register key = a1;
3393 Register receiver = a2;
3394 // a3 mostly holds the elements array or the destination external array.
3395
danno@chromium.org40cb8782011-05-25 07:58:50 +00003396 // This stub is meant to be tail-jumped to, the receiver must already
3397 // have been verified by the caller to not be a smi.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003398
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003399 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003400 GenerateSmiKeyCheck(masm, key, t0, t1, f2, f4, &miss_force_generic);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003401
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003402 __ lw(a3, FieldMemOperand(receiver, JSObject::kElementsOffset));
3403
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003404 // Check that the index is in range.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003405 __ lw(t1, FieldMemOperand(a3, ExternalArray::kLengthOffset));
3406 // Unsigned comparison catches both negative and too-large values.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003407 __ Branch(&miss_force_generic, Ugreater_equal, key, Operand(t1));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003408
3409 // Handle both smis and HeapNumbers in the fast path. Go to the
3410 // runtime for all other kinds of values.
3411 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003412
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003413 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003414 // Double to pixel conversion is only implemented in the runtime for now.
3415 __ JumpIfNotSmi(value, &slow);
3416 } else {
3417 __ JumpIfNotSmi(value, &check_heap_number);
3418 }
3419 __ SmiUntag(t1, value);
3420 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3421
3422 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003423 // t1: value (integer).
3424
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00003425 switch (elements_kind) {
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003426 case EXTERNAL_PIXEL_ELEMENTS: {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003427 // Clamp the value to [0..255].
3428 // v0 is used as a scratch register here.
3429 Label done;
3430 __ li(v0, Operand(255));
3431 // Normal branch: nop in delay slot.
3432 __ Branch(&done, gt, t1, Operand(v0));
3433 // Use delay slot in this branch.
3434 __ Branch(USE_DELAY_SLOT, &done, lt, t1, Operand(zero_reg));
3435 __ mov(v0, zero_reg); // In delay slot.
3436 __ mov(v0, t1); // Value is in range 0..255.
3437 __ bind(&done);
3438 __ mov(t1, v0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003439
3440 __ srl(t8, key, 1);
3441 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003442 __ sb(t1, MemOperand(t8, 0));
3443 }
3444 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003445 case EXTERNAL_BYTE_ELEMENTS:
3446 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003447 __ srl(t8, key, 1);
3448 __ addu(t8, a3, t8);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003449 __ sb(t1, MemOperand(t8, 0));
3450 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003451 case EXTERNAL_SHORT_ELEMENTS:
3452 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003453 __ addu(t8, a3, key);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003454 __ sh(t1, MemOperand(t8, 0));
3455 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003456 case EXTERNAL_INT_ELEMENTS:
3457 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003458 __ sll(t8, key, 1);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003459 __ addu(t8, a3, t8);
3460 __ sw(t1, MemOperand(t8, 0));
3461 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003462 case EXTERNAL_FLOAT_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003463 // Perform int-to-float conversion and store to memory.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003464 __ SmiUntag(t0, key);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003465 StoreIntAsFloat(masm, a3, t0, t1, t2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003466 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003467 case EXTERNAL_DOUBLE_ELEMENTS:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003468 __ sll(t8, key, 2);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003469 __ addu(a3, a3, t8);
3470 // a3: effective address of the double element
3471 FloatingPointHelper::Destination destination;
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003472 destination = FloatingPointHelper::kFPURegisters;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003473 FloatingPointHelper::ConvertIntToDouble(
danno@chromium.org40cb8782011-05-25 07:58:50 +00003474 masm, t1, destination,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003475 f0, t2, t3, // These are: double_dst, dst_mantissa, dst_exponent.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003476 t0, f2); // These are: scratch2, single_scratch.
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003477 __ sdc1(f0, MemOperand(a3, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003478 break;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003479 case FAST_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003480 case FAST_SMI_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003481 case FAST_DOUBLE_ELEMENTS:
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003482 case FAST_HOLEY_ELEMENTS:
3483 case FAST_HOLEY_SMI_ELEMENTS:
3484 case FAST_HOLEY_DOUBLE_ELEMENTS:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003485 case DICTIONARY_ELEMENTS:
3486 case NON_STRICT_ARGUMENTS_ELEMENTS:
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003487 UNREACHABLE();
3488 break;
3489 }
3490
3491 // Entry registers are intact, a0 holds the value which is the return value.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003492 __ mov(v0, a0);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003493 __ Ret();
3494
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00003495 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) {
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003496 // a3: external array.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003497 __ bind(&check_heap_number);
3498 __ GetObjectType(value, t1, t2);
3499 __ Branch(&slow, ne, t2, Operand(HEAP_NUMBER_TYPE));
3500
3501 __ lw(a3, FieldMemOperand(a3, ExternalArray::kExternalPointerOffset));
3502
3503 // a3: base pointer of external storage.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003504
3505 // The WebGL specification leaves the behavior of storing NaN and
3506 // +/-Infinity into integer arrays basically undefined. For more
3507 // reproducible behavior, convert these to zero.
3508
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003509
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003510 __ ldc1(f0, FieldMemOperand(a0, HeapNumber::kValueOffset));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003511
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003512 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) {
3513 __ cvt_s_d(f0, f0);
3514 __ sll(t8, key, 1);
3515 __ addu(t8, a3, t8);
3516 __ swc1(f0, MemOperand(t8, 0));
3517 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) {
3518 __ sll(t8, key, 2);
3519 __ addu(t8, a3, t8);
3520 __ sdc1(f0, MemOperand(t8, 0));
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003521 } else {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003522 __ EmitECMATruncate(t3, f0, f2, t2, t1, t5);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003523
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003524 switch (elements_kind) {
3525 case EXTERNAL_BYTE_ELEMENTS:
3526 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
3527 __ srl(t8, key, 1);
3528 __ addu(t8, a3, t8);
3529 __ sb(t3, MemOperand(t8, 0));
3530 break;
3531 case EXTERNAL_SHORT_ELEMENTS:
3532 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
3533 __ addu(t8, a3, key);
3534 __ sh(t3, MemOperand(t8, 0));
3535 break;
3536 case EXTERNAL_INT_ELEMENTS:
3537 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
3538 __ sll(t8, key, 1);
3539 __ addu(t8, a3, t8);
3540 __ sw(t3, MemOperand(t8, 0));
3541 break;
3542 case EXTERNAL_PIXEL_ELEMENTS:
3543 case EXTERNAL_FLOAT_ELEMENTS:
3544 case EXTERNAL_DOUBLE_ELEMENTS:
3545 case FAST_ELEMENTS:
3546 case FAST_SMI_ELEMENTS:
3547 case FAST_DOUBLE_ELEMENTS:
3548 case FAST_HOLEY_ELEMENTS:
3549 case FAST_HOLEY_SMI_ELEMENTS:
3550 case FAST_HOLEY_DOUBLE_ELEMENTS:
3551 case DICTIONARY_ELEMENTS:
3552 case NON_STRICT_ARGUMENTS_ELEMENTS:
3553 UNREACHABLE();
3554 break;
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003555 }
3556 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +00003557
3558 // Entry registers are intact, a0 holds the value
3559 // which is the return value.
3560 __ mov(v0, a0);
3561 __ Ret();
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003562 }
3563
danno@chromium.org40cb8782011-05-25 07:58:50 +00003564 // Slow case, key and receiver still in a0 and a1.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003565 __ bind(&slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003566 __ IncrementCounter(
3567 masm->isolate()->counters()->keyed_load_external_array_slow(),
3568 1, a2, a3);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003569 // Entry registers are intact.
3570 // ---------- S t a t e --------------
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003571 // -- ra : return address
danno@chromium.org40cb8782011-05-25 07:58:50 +00003572 // -- a0 : key
3573 // -- a1 : receiver
3574 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003575 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003576
3577 // Miss case, call the runtime.
3578 __ bind(&miss_force_generic);
3579
3580 // ---------- S t a t e --------------
3581 // -- ra : return address
3582 // -- a0 : key
3583 // -- a1 : receiver
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003584 // -----------------------------------
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003585 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003586}
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003587
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00003588
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003589void KeyedStoreStubCompiler::GenerateStoreFastElement(
3590 MacroAssembler* masm,
3591 bool is_js_array,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003592 ElementsKind elements_kind,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003593 KeyedAccessStoreMode store_mode) {
danno@chromium.org40cb8782011-05-25 07:58:50 +00003594 // ----------- S t a t e -------------
3595 // -- a0 : value
3596 // -- a1 : key
3597 // -- a2 : receiver
3598 // -- ra : return address
3599 // -- a3 : scratch
3600 // -- a4 : scratch (elements)
3601 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003602 Label miss_force_generic, transition_elements_kind, grow, slow;
3603 Label finish_store, check_capacity;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003604
3605 Register value_reg = a0;
3606 Register key_reg = a1;
3607 Register receiver_reg = a2;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003608 Register scratch = t0;
3609 Register elements_reg = a3;
3610 Register length_reg = t1;
3611 Register scratch2 = t2;
danno@chromium.org40cb8782011-05-25 07:58:50 +00003612
3613 // This stub is meant to be tail-jumped to, the receiver must already
3614 // have been verified by the caller to not be a smi.
3615
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003616 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003617 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003618
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003619 if (IsFastSmiElementsKind(elements_kind)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003620 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
3621 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003622
3623 // Check that the key is within bounds.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003624 __ lw(elements_reg,
3625 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
danno@chromium.org40cb8782011-05-25 07:58:50 +00003626 if (is_js_array) {
3627 __ lw(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3628 } else {
3629 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3630 }
3631 // Compare smis.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003632 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003633 __ Branch(&grow, hs, key_reg, Operand(scratch));
3634 } else {
3635 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch));
3636 }
3637
3638 // Make sure elements is a fast element array, not 'cow'.
3639 __ CheckMap(elements_reg,
3640 scratch,
3641 Heap::kFixedArrayMapRootIndex,
3642 &miss_force_generic,
3643 DONT_DO_SMI_CHECK);
3644
3645 __ bind(&finish_store);
danno@chromium.org40cb8782011-05-25 07:58:50 +00003646
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003647 if (IsFastSmiElementsKind(elements_kind)) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003648 __ Addu(scratch,
3649 elements_reg,
3650 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3651 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3652 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3653 __ Addu(scratch, scratch, scratch2);
3654 __ sw(value_reg, MemOperand(scratch));
3655 } else {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00003656 ASSERT(IsFastObjectElementsKind(elements_kind));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003657 __ Addu(scratch,
3658 elements_reg,
3659 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3660 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
3661 __ sll(scratch2, key_reg, kPointerSizeLog2 - kSmiTagSize);
3662 __ Addu(scratch, scratch, scratch2);
3663 __ sw(value_reg, MemOperand(scratch));
3664 __ mov(receiver_reg, value_reg);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003665 __ RecordWrite(elements_reg, // Object.
3666 scratch, // Address.
3667 receiver_reg, // Value.
3668 kRAHasNotBeenSaved,
3669 kDontSaveFPRegs);
3670 }
danno@chromium.org40cb8782011-05-25 07:58:50 +00003671 // value_reg (a0) is preserved.
3672 // Done.
3673 __ Ret();
3674
3675 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003676 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003677
3678 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003679 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003680
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003681 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003682 // Grow the array by a single element if possible.
3683 __ bind(&grow);
3684
3685 // Make sure the array is only growing by a single element, anything else
3686 // must be handled by the runtime.
3687 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch));
3688
3689 // Check for the empty array, and preallocate a small backing store if
3690 // possible.
3691 __ lw(length_reg,
3692 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3693 __ lw(elements_reg,
3694 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3695 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3696 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3697
3698 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003699 __ Allocate(size, elements_reg, scratch, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003700
3701 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
3702 __ sw(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3703 __ li(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3704 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3705 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
3706 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
3707 __ sw(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
3708 }
3709
3710 // Store the element at index zero.
3711 __ sw(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
3712
3713 // Install the new backing store in the JSArray.
3714 __ sw(elements_reg,
3715 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3716 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3717 scratch, kRAHasNotBeenSaved, kDontSaveFPRegs,
3718 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3719
3720 // Increment the length of the array.
3721 __ li(length_reg, Operand(Smi::FromInt(1)));
3722 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3723 __ Ret();
3724
3725 __ bind(&check_capacity);
3726 // Check for cow elements, in general they are not handled by this stub
3727 __ CheckMap(elements_reg,
3728 scratch,
3729 Heap::kFixedCOWArrayMapRootIndex,
3730 &miss_force_generic,
3731 DONT_DO_SMI_CHECK);
3732
3733 __ lw(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3734 __ Branch(&slow, hs, length_reg, Operand(scratch));
3735
3736 // Grow the array and finish the store.
3737 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3738 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3739 __ jmp(&finish_store);
3740
3741 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003742 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003743 }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +00003744}
3745
3746
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003747void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
3748 MacroAssembler* masm,
yangguo@chromium.org56454712012-02-16 15:33:53 +00003749 bool is_js_array,
ulan@chromium.org750145a2013-03-07 15:14:13 +00003750 KeyedAccessStoreMode store_mode) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003751 // ----------- S t a t e -------------
3752 // -- a0 : value
3753 // -- a1 : key
3754 // -- a2 : receiver
3755 // -- ra : return address
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003756 // -- a3 : scratch (elements backing store)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003757 // -- t0 : scratch (elements_reg)
3758 // -- t1 : scratch (mantissa_reg)
3759 // -- t2 : scratch (exponent_reg)
3760 // -- t3 : scratch4
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003761 // -- t4 : scratch
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003762 // -----------------------------------
yangguo@chromium.org56454712012-02-16 15:33:53 +00003763 Label miss_force_generic, transition_elements_kind, grow, slow;
3764 Label finish_store, check_capacity;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003765
3766 Register value_reg = a0;
3767 Register key_reg = a1;
3768 Register receiver_reg = a2;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003769 Register elements_reg = a3;
3770 Register scratch1 = t0;
3771 Register scratch2 = t1;
3772 Register scratch3 = t2;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003773 Register scratch4 = t3;
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003774 Register scratch5 = t4;
yangguo@chromium.org56454712012-02-16 15:33:53 +00003775 Register length_reg = t3;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003776
3777 // This stub is meant to be tail-jumped to, the receiver must already
3778 // have been verified by the caller to not be a smi.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00003779
3780 // Check that the key is a smi or a heap number convertible to a smi.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003781 GenerateSmiKeyCheck(masm, key_reg, t0, t1, f2, f4, &miss_force_generic);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003782
3783 __ lw(elements_reg,
3784 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3785
3786 // Check that the key is within bounds.
3787 if (is_js_array) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003788 __ lw(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003789 } else {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003790 __ lw(scratch1,
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003791 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
3792 }
3793 // Compare smis, unsigned compare catches both negative and out-of-bound
3794 // indexes.
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003795 if (IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003796 __ Branch(&grow, hs, key_reg, Operand(scratch1));
3797 } else {
3798 __ Branch(&miss_force_generic, hs, key_reg, Operand(scratch1));
3799 }
3800
3801 __ bind(&finish_store);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003802
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003803 __ StoreNumberToDoubleElements(value_reg,
3804 key_reg,
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00003805 // All registers after this are overwritten.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003806 elements_reg,
3807 scratch1,
3808 scratch2,
3809 scratch3,
3810 scratch4,
3811 &transition_elements_kind);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003812
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00003813 __ Ret(USE_DELAY_SLOT);
3814 __ mov(v0, value_reg); // In delay slot.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00003815
3816 // Handle store cache miss, replacing the ic with the generic stub.
3817 __ bind(&miss_force_generic);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003818 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003819
3820 __ bind(&transition_elements_kind);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003821 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003822
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00003823 if (is_js_array && IsGrowStoreMode(store_mode)) {
yangguo@chromium.org56454712012-02-16 15:33:53 +00003824 // Grow the array by a single element if possible.
3825 __ bind(&grow);
3826
3827 // Make sure the array is only growing by a single element, anything else
3828 // must be handled by the runtime.
3829 __ Branch(&miss_force_generic, ne, key_reg, Operand(scratch1));
3830
3831 // Transition on values that can't be stored in a FixedDoubleArray.
3832 Label value_is_smi;
3833 __ JumpIfSmi(value_reg, &value_is_smi);
3834 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
3835 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
3836 __ Branch(&transition_elements_kind, ne, scratch1, Operand(at));
3837 __ bind(&value_is_smi);
3838
3839 // Check for the empty array, and preallocate a small backing store if
3840 // possible.
3841 __ lw(length_reg,
3842 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3843 __ lw(elements_reg,
3844 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3845 __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex);
3846 __ Branch(&check_capacity, ne, elements_reg, Operand(at));
3847
3848 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +00003849 __ Allocate(size, elements_reg, scratch1, scratch2, &slow, TAG_OBJECT);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003850
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003851 // Initialize the new FixedDoubleArray.
yangguo@chromium.org56454712012-02-16 15:33:53 +00003852 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
3853 __ sw(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
3854 __ li(scratch1, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
3855 __ sw(scratch1,
3856 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3857
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003858 __ mov(scratch1, elements_reg);
3859 __ StoreNumberToDoubleElements(value_reg,
3860 key_reg,
3861 // All registers after this are overwritten.
3862 scratch1,
3863 scratch2,
3864 scratch3,
3865 scratch4,
3866 scratch5,
3867 &transition_elements_kind);
3868
3869 __ li(scratch1, Operand(kHoleNanLower32));
3870 __ li(scratch2, Operand(kHoleNanUpper32));
3871 for (int i = 1; i < JSArray::kPreallocatedArrayElements; i++) {
3872 int offset = FixedDoubleArray::OffsetOfElementAt(i);
3873 __ sw(scratch1, FieldMemOperand(elements_reg, offset));
3874 __ sw(scratch2, FieldMemOperand(elements_reg, offset + kPointerSize));
3875 }
3876
yangguo@chromium.org56454712012-02-16 15:33:53 +00003877 // Install the new backing store in the JSArray.
3878 __ sw(elements_reg,
3879 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
3880 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
3881 scratch1, kRAHasNotBeenSaved, kDontSaveFPRegs,
3882 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
3883
3884 // Increment the length of the array.
3885 __ li(length_reg, Operand(Smi::FromInt(1)));
3886 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
danno@chromium.org00379b82012-05-04 09:16:29 +00003887 __ lw(elements_reg,
3888 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +00003889 __ Ret();
yangguo@chromium.org56454712012-02-16 15:33:53 +00003890
3891 __ bind(&check_capacity);
3892 // Make sure that the backing store can hold additional elements.
3893 __ lw(scratch1,
3894 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
3895 __ Branch(&slow, hs, length_reg, Operand(scratch1));
3896
3897 // Grow the array and finish the store.
3898 __ Addu(length_reg, length_reg, Operand(Smi::FromInt(1)));
3899 __ sw(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
3900 __ jmp(&finish_store);
3901
3902 __ bind(&slow);
svenpanne@chromium.org2bda5432013-03-15 12:39:50 +00003903 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow);
yangguo@chromium.org56454712012-02-16 15:33:53 +00003904 }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00003905}
3906
3907
ager@chromium.org5c838252010-02-19 08:53:10 +00003908#undef __
3909
3910} } // namespace v8::internal
3911
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00003912#endif // V8_TARGET_ARCH_MIPS