1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #if V8_TARGET_ARCH_ARM64
9 #include "src/bootstrapper.h"
10 #include "src/code-stubs.h"
11 #include "src/codegen.h"
12 #include "src/ic/handler-compiler.h"
13 #include "src/ic/ic.h"
14 #include "src/ic/stub-cache.h"
15 #include "src/isolate.h"
16 #include "src/jsregexp.h"
17 #include "src/regexp-macro-assembler.h"
18 #include "src/runtime/runtime.h"
24 static void InitializeArrayConstructorDescriptor(
25 Isolate* isolate, CodeStubDescriptor* descriptor,
26 int constant_stack_parameter_count) {
29 // x2: allocation site with elements kind
30 // x0: number of arguments to the constructor function
31 Address deopt_handler = Runtime::FunctionForId(
32 Runtime::kArrayConstructor)->entry;
34 if (constant_stack_parameter_count == 0) {
35 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
36 JS_FUNCTION_STUB_MODE);
38 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
39 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
44 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
45 CodeStubDescriptor* descriptor) {
46 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
50 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
51 CodeStubDescriptor* descriptor) {
52 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
56 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
57 CodeStubDescriptor* descriptor) {
58 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
62 static void InitializeInternalArrayConstructorDescriptor(
63 Isolate* isolate, CodeStubDescriptor* descriptor,
64 int constant_stack_parameter_count) {
65 Address deopt_handler = Runtime::FunctionForId(
66 Runtime::kInternalArrayConstructor)->entry;
68 if (constant_stack_parameter_count == 0) {
69 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
70 JS_FUNCTION_STUB_MODE);
72 descriptor->Initialize(x0, deopt_handler, constant_stack_parameter_count,
73 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
78 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
79 CodeStubDescriptor* descriptor) {
80 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
84 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
85 CodeStubDescriptor* descriptor) {
86 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
90 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
91 CodeStubDescriptor* descriptor) {
92 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
96 #define __ ACCESS_MASM(masm)
99 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
100 ExternalReference miss) {
101 // Update the static counter each time a new code stub is generated.
102 isolate()->counters()->code_stubs()->Increment();
104 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
105 int param_count = descriptor.GetRegisterParameterCount();
107 // Call the runtime system in a fresh internal frame.
108 FrameScope scope(masm, StackFrame::INTERNAL);
109 DCHECK((param_count == 0) ||
110 x0.Is(descriptor.GetRegisterParameter(param_count - 1)));
113 MacroAssembler::PushPopQueue queue(masm);
114 for (int i = 0; i < param_count; ++i) {
115 queue.Queue(descriptor.GetRegisterParameter(i));
119 __ CallExternalReference(miss, param_count);
126 void DoubleToIStub::Generate(MacroAssembler* masm) {
128 Register input = source();
129 Register result = destination();
130 DCHECK(is_truncating());
132 DCHECK(result.Is64Bits());
133 DCHECK(jssp.Is(masm->StackPointer()));
135 int double_offset = offset();
137 DoubleRegister double_scratch = d0; // only used if !skip_fastpath()
138 Register scratch1 = GetAllocatableRegisterThatIsNotOneOf(input, result);
140 GetAllocatableRegisterThatIsNotOneOf(input, result, scratch1);
142 __ Push(scratch1, scratch2);
143 // Account for saved regs if input is jssp.
144 if (input.is(jssp)) double_offset += 2 * kPointerSize;
146 if (!skip_fastpath()) {
147 __ Push(double_scratch);
148 if (input.is(jssp)) double_offset += 1 * kDoubleSize;
149 __ Ldr(double_scratch, MemOperand(input, double_offset));
150 // Try to convert with a FPU convert instruction. This handles all
151 // non-saturating cases.
152 __ TryConvertDoubleToInt64(result, double_scratch, &done);
153 __ Fmov(result, double_scratch);
155 __ Ldr(result, MemOperand(input, double_offset));
158 // If we reach here we need to manually convert the input to an int32.
160 // Extract the exponent.
161 Register exponent = scratch1;
162 __ Ubfx(exponent, result, HeapNumber::kMantissaBits,
163 HeapNumber::kExponentBits);
165 // It the exponent is >= 84 (kMantissaBits + 32), the result is always 0 since
166 // the mantissa gets shifted completely out of the int32_t result.
167 __ Cmp(exponent, HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 32);
168 __ CzeroX(result, ge);
171 // The Fcvtzs sequence handles all cases except where the conversion causes
172 // signed overflow in the int64_t target. Since we've already handled
173 // exponents >= 84, we can guarantee that 63 <= exponent < 84.
175 if (masm->emit_debug_code()) {
176 __ Cmp(exponent, HeapNumber::kExponentBias + 63);
177 // Exponents less than this should have been handled by the Fcvt case.
178 __ Check(ge, kUnexpectedValue);
181 // Isolate the mantissa bits, and set the implicit '1'.
182 Register mantissa = scratch2;
183 __ Ubfx(mantissa, result, 0, HeapNumber::kMantissaBits);
184 __ Orr(mantissa, mantissa, 1UL << HeapNumber::kMantissaBits);
186 // Negate the mantissa if necessary.
187 __ Tst(result, kXSignMask);
188 __ Cneg(mantissa, mantissa, ne);
190 // Shift the mantissa bits in the correct place. We know that we have to shift
191 // it left here, because exponent >= 63 >= kMantissaBits.
192 __ Sub(exponent, exponent,
193 HeapNumber::kExponentBias + HeapNumber::kMantissaBits);
194 __ Lsl(result, mantissa, exponent);
197 if (!skip_fastpath()) {
198 __ Pop(double_scratch);
200 __ Pop(scratch2, scratch1);
205 // See call site for description.
206 static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
207 Register right, Register scratch,
208 FPRegister double_scratch,
209 Label* slow, Condition cond,
211 DCHECK(!AreAliased(left, right, scratch));
212 Label not_identical, return_equal, heap_number;
213 Register result = x0;
216 __ B(ne, ¬_identical);
218 // Test for NaN. Sadly, we can't just compare to factory::nan_value(),
219 // so we do the second best thing - test it ourselves.
220 // They are both equal and they are not both Smis so both of them are not
221 // Smis. If it's not a heap number, then return equal.
222 Register right_type = scratch;
223 if ((cond == lt) || (cond == gt)) {
224 // Call runtime on identical JSObjects. Otherwise return equal.
225 __ JumpIfObjectType(right, right_type, right_type, FIRST_SPEC_OBJECT_TYPE,
227 // Call runtime on identical symbols since we need to throw a TypeError.
228 __ Cmp(right_type, SYMBOL_TYPE);
230 // Call runtime on identical SIMD values since we must throw a TypeError.
231 __ Cmp(right_type, FLOAT32X4_TYPE);
233 if (is_strong(strength)) {
234 // Call the runtime on anything that is converted in the semantics, since
235 // we need to throw a TypeError. Smis have already been ruled out.
236 __ Cmp(right_type, Operand(HEAP_NUMBER_TYPE));
237 __ B(eq, &return_equal);
238 __ Tst(right_type, Operand(kIsNotStringMask));
241 } else if (cond == eq) {
242 __ JumpIfHeapNumber(right, &heap_number);
244 __ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE,
246 // Comparing JS objects with <=, >= is complicated.
247 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
249 // Call runtime on identical symbols since we need to throw a TypeError.
250 __ Cmp(right_type, SYMBOL_TYPE);
252 // Call runtime on identical SIMD values since we must throw a TypeError.
253 __ Cmp(right_type, FLOAT32X4_TYPE);
255 if (is_strong(strength)) {
256 // Call the runtime on anything that is converted in the semantics,
257 // since we need to throw a TypeError. Smis and heap numbers have
258 // already been ruled out.
259 __ Tst(right_type, Operand(kIsNotStringMask));
262 // Normally here we fall through to return_equal, but undefined is
263 // special: (undefined == undefined) == true, but
264 // (undefined <= undefined) == false! See ECMAScript 11.8.5.
265 if ((cond == le) || (cond == ge)) {
266 __ Cmp(right_type, ODDBALL_TYPE);
267 __ B(ne, &return_equal);
268 __ JumpIfNotRoot(right, Heap::kUndefinedValueRootIndex, &return_equal);
270 // undefined <= undefined should fail.
271 __ Mov(result, GREATER);
273 // undefined >= undefined should fail.
274 __ Mov(result, LESS);
280 __ Bind(&return_equal);
282 __ Mov(result, GREATER); // Things aren't less than themselves.
283 } else if (cond == gt) {
284 __ Mov(result, LESS); // Things aren't greater than themselves.
286 __ Mov(result, EQUAL); // Things are <=, >=, ==, === themselves.
290 // Cases lt and gt have been handled earlier, and case ne is never seen, as
291 // it is handled in the parser (see Parser::ParseBinaryExpression). We are
292 // only concerned with cases ge, le and eq here.
293 if ((cond != lt) && (cond != gt)) {
294 DCHECK((cond == ge) || (cond == le) || (cond == eq));
295 __ Bind(&heap_number);
296 // Left and right are identical pointers to a heap number object. Return
297 // non-equal if the heap number is a NaN, and equal otherwise. Comparing
298 // the number to itself will set the overflow flag iff the number is NaN.
299 __ Ldr(double_scratch, FieldMemOperand(right, HeapNumber::kValueOffset));
300 __ Fcmp(double_scratch, double_scratch);
301 __ B(vc, &return_equal); // Not NaN, so treat as normal heap number.
304 __ Mov(result, GREATER);
306 __ Mov(result, LESS);
311 // No fall through here.
312 if (FLAG_debug_code) {
316 __ Bind(¬_identical);
320 // See call site for description.
321 static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
327 DCHECK(!AreAliased(left, right, left_type, right_type, scratch));
329 if (masm->emit_debug_code()) {
330 // We assume that the arguments are not identical.
332 __ Assert(ne, kExpectedNonIdenticalObjects);
335 // If either operand is a JS object or an oddball value, then they are not
336 // equal since their pointers are different.
337 // There is no test for undetectability in strict equality.
338 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
339 Label right_non_object;
341 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
342 __ B(lt, &right_non_object);
344 // Return non-zero - x0 already contains a non-zero pointer.
345 DCHECK(left.is(x0) || right.is(x0));
346 Label return_not_equal;
347 __ Bind(&return_not_equal);
350 __ Bind(&right_non_object);
352 // Check for oddballs: true, false, null, undefined.
353 __ Cmp(right_type, ODDBALL_TYPE);
355 // If right is not ODDBALL, test left. Otherwise, set eq condition.
356 __ Ccmp(left_type, ODDBALL_TYPE, ZFlag, ne);
358 // If right or left is not ODDBALL, test left >= FIRST_SPEC_OBJECT_TYPE.
359 // Otherwise, right or left is ODDBALL, so set a ge condition.
360 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NVFlag, ne);
362 __ B(ge, &return_not_equal);
364 // Internalized strings are unique, so they can only be equal if they are the
365 // same object. We have already tested that case, so if left and right are
366 // both internalized strings, they cannot be equal.
367 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
368 __ Orr(scratch, left_type, right_type);
369 __ TestAndBranchIfAllClear(
370 scratch, kIsNotStringMask | kIsNotInternalizedMask, &return_not_equal);
374 // See call site for description.
375 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
382 DCHECK(!AreAliased(left_d, right_d));
383 DCHECK((left.is(x0) && right.is(x1)) ||
384 (right.is(x0) && left.is(x1)));
385 Register result = x0;
387 Label right_is_smi, done;
388 __ JumpIfSmi(right, &right_is_smi);
390 // Left is the smi. Check whether right is a heap number.
392 // If right is not a number and left is a smi, then strict equality cannot
393 // succeed. Return non-equal.
394 Label is_heap_number;
395 __ JumpIfHeapNumber(right, &is_heap_number);
396 // Register right is a non-zero pointer, which is a valid NOT_EQUAL result.
397 if (!right.is(result)) {
398 __ Mov(result, NOT_EQUAL);
401 __ Bind(&is_heap_number);
403 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
405 __ JumpIfNotHeapNumber(right, slow);
408 // Left is the smi. Right is a heap number. Load right value into right_d, and
409 // convert left smi into double in left_d.
410 __ Ldr(right_d, FieldMemOperand(right, HeapNumber::kValueOffset));
411 __ SmiUntagToDouble(left_d, left);
414 __ Bind(&right_is_smi);
415 // Right is a smi. Check whether the non-smi left is a heap number.
417 // If left is not a number and right is a smi then strict equality cannot
418 // succeed. Return non-equal.
419 Label is_heap_number;
420 __ JumpIfHeapNumber(left, &is_heap_number);
421 // Register left is a non-zero pointer, which is a valid NOT_EQUAL result.
422 if (!left.is(result)) {
423 __ Mov(result, NOT_EQUAL);
426 __ Bind(&is_heap_number);
428 // Smi compared non-strictly with a non-smi, non-heap-number. Call the
430 __ JumpIfNotHeapNumber(left, slow);
433 // Right is the smi. Left is a heap number. Load left value into left_d, and
434 // convert right smi into double in right_d.
435 __ Ldr(left_d, FieldMemOperand(left, HeapNumber::kValueOffset));
436 __ SmiUntagToDouble(right_d, right);
438 // Fall through to both_loaded_as_doubles.
443 // Fast negative check for internalized-to-internalized equality.
444 // See call site for description.
445 static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
452 Label* possible_strings,
453 Label* not_both_strings) {
454 DCHECK(!AreAliased(left, right, left_map, right_map, left_type, right_type));
455 Register result = x0;
458 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
459 // TODO(all): reexamine this branch sequence for optimisation wrt branch
461 __ Tbnz(right_type, MaskToBit(kIsNotStringMask), &object_test);
462 __ Tbnz(right_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
463 __ Tbnz(left_type, MaskToBit(kIsNotStringMask), not_both_strings);
464 __ Tbnz(left_type, MaskToBit(kIsNotInternalizedMask), possible_strings);
466 // Both are internalized. We already checked that they weren't the same
467 // pointer, so they are not equal.
468 __ Mov(result, NOT_EQUAL);
471 __ Bind(&object_test);
473 __ Cmp(right_type, FIRST_SPEC_OBJECT_TYPE);
475 // If right >= FIRST_SPEC_OBJECT_TYPE, test left.
476 // Otherwise, right < FIRST_SPEC_OBJECT_TYPE, so set lt condition.
477 __ Ccmp(left_type, FIRST_SPEC_OBJECT_TYPE, NFlag, ge);
479 __ B(lt, not_both_strings);
481 // If both objects are undetectable, they are equal. Otherwise, they are not
482 // equal, since they are different objects and an object is not equal to
485 // Returning here, so we can corrupt right_type and left_type.
486 Register right_bitfield = right_type;
487 Register left_bitfield = left_type;
488 __ Ldrb(right_bitfield, FieldMemOperand(right_map, Map::kBitFieldOffset));
489 __ Ldrb(left_bitfield, FieldMemOperand(left_map, Map::kBitFieldOffset));
490 __ And(result, right_bitfield, left_bitfield);
491 __ And(result, result, 1 << Map::kIsUndetectable);
492 __ Eor(result, result, 1 << Map::kIsUndetectable);
497 static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
498 CompareICState::State expected,
501 if (expected == CompareICState::SMI) {
502 __ JumpIfNotSmi(input, fail);
503 } else if (expected == CompareICState::NUMBER) {
504 __ JumpIfSmi(input, &ok);
505 __ JumpIfNotHeapNumber(input, fail);
507 // We could be strict about internalized/non-internalized here, but as long as
508 // hydrogen doesn't care, the stub doesn't have to care either.
513 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
516 Register result = x0;
517 Condition cond = GetCondition();
520 CompareICStub_CheckInputType(masm, lhs, left(), &miss);
521 CompareICStub_CheckInputType(masm, rhs, right(), &miss);
523 Label slow; // Call builtin.
524 Label not_smis, both_loaded_as_doubles;
525 Label not_two_smis, smi_done;
526 __ JumpIfEitherNotSmi(lhs, rhs, ¬_two_smis);
528 __ Sub(result, lhs, Operand::UntagSmi(rhs));
531 __ Bind(¬_two_smis);
533 // NOTICE! This code is only reached after a smi-fast-case check, so it is
534 // certain that at least one operand isn't a smi.
536 // Handle the case where the objects are identical. Either returns the answer
537 // or goes to slow. Only falls through if the objects were not identical.
538 EmitIdenticalObjectComparison(masm, lhs, rhs, x10, d0, &slow, cond,
541 // If either is a smi (we know that at least one is not a smi), then they can
542 // only be strictly equal if the other is a HeapNumber.
543 __ JumpIfBothNotSmi(lhs, rhs, ¬_smis);
545 // Exactly one operand is a smi. EmitSmiNonsmiComparison generates code that
547 // 1) Return the answer.
548 // 2) Branch to the slow case.
549 // 3) Fall through to both_loaded_as_doubles.
550 // In case 3, we have found out that we were dealing with a number-number
551 // comparison. The double values of the numbers have been loaded, right into
552 // rhs_d, left into lhs_d.
553 FPRegister rhs_d = d0;
554 FPRegister lhs_d = d1;
555 EmitSmiNonsmiComparison(masm, lhs, rhs, lhs_d, rhs_d, &slow, strict());
557 __ Bind(&both_loaded_as_doubles);
558 // The arguments have been converted to doubles and stored in rhs_d and
561 __ Fcmp(lhs_d, rhs_d);
562 __ B(vs, &nan); // Overflow flag set if either is NaN.
563 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
564 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
565 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
569 // Left and/or right is a NaN. Load the result register with whatever makes
570 // the comparison fail, since comparisons with NaN always fail (except ne,
571 // which is filtered out at a higher level.)
573 if ((cond == lt) || (cond == le)) {
574 __ Mov(result, GREATER);
576 __ Mov(result, LESS);
581 // At this point we know we are dealing with two different objects, and
582 // neither of them is a smi. The objects are in rhs_ and lhs_.
584 // Load the maps and types of the objects.
585 Register rhs_map = x10;
586 Register rhs_type = x11;
587 Register lhs_map = x12;
588 Register lhs_type = x13;
589 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
590 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
591 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
592 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
595 // This emits a non-equal return sequence for some object types, or falls
596 // through if it was not lucky.
597 EmitStrictTwoHeapObjectCompare(masm, lhs, rhs, lhs_type, rhs_type, x14);
600 Label check_for_internalized_strings;
601 Label flat_string_check;
602 // Check for heap number comparison. Branch to earlier double comparison code
603 // if they are heap numbers, otherwise, branch to internalized string check.
604 __ Cmp(rhs_type, HEAP_NUMBER_TYPE);
605 __ B(ne, &check_for_internalized_strings);
606 __ Cmp(lhs_map, rhs_map);
608 // If maps aren't equal, lhs_ and rhs_ are not heap numbers. Branch to flat
610 __ B(ne, &flat_string_check);
612 // Both lhs_ and rhs_ are heap numbers. Load them and branch to the double
614 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
615 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
616 __ B(&both_loaded_as_doubles);
618 __ Bind(&check_for_internalized_strings);
619 // In the strict case, the EmitStrictTwoHeapObjectCompare already took care
620 // of internalized strings.
621 if ((cond == eq) && !strict()) {
622 // Returns an answer for two internalized strings or two detectable objects.
623 // Otherwise branches to the string case or not both strings case.
624 EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, lhs_map, rhs_map,
626 &flat_string_check, &slow);
629 // Check for both being sequential one-byte strings,
630 // and inline if that is the case.
631 __ Bind(&flat_string_check);
632 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x14,
635 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x10,
638 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
641 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
645 // Never fall through to here.
646 if (FLAG_debug_code) {
653 // Figure out which native to call and setup the arguments.
654 Builtins::JavaScript native;
656 native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
659 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
660 int ncr; // NaN compare result
661 if ((cond == lt) || (cond == le)) {
664 DCHECK((cond == gt) || (cond == ge)); // remaining cases
667 __ Mov(x10, Smi::FromInt(ncr));
671 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
672 // tagged as a small integer.
673 __ InvokeBuiltin(native, JUMP_FUNCTION);
680 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
681 CPURegList saved_regs = kCallerSaved;
682 CPURegList saved_fp_regs = kCallerSavedFP;
684 // We don't allow a GC during a store buffer overflow so there is no need to
685 // store the registers in any particular way, but we do have to store and
688 // We don't care if MacroAssembler scratch registers are corrupted.
689 saved_regs.Remove(*(masm->TmpList()));
690 saved_fp_regs.Remove(*(masm->FPTmpList()));
692 __ PushCPURegList(saved_regs);
693 if (save_doubles()) {
694 __ PushCPURegList(saved_fp_regs);
697 AllowExternalCallThatCantCauseGC scope(masm);
698 __ Mov(x0, ExternalReference::isolate_address(isolate()));
700 ExternalReference::store_buffer_overflow_function(isolate()), 1, 0);
702 if (save_doubles()) {
703 __ PopCPURegList(saved_fp_regs);
705 __ PopCPURegList(saved_regs);
710 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
712 StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs);
714 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
719 void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
720 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
721 UseScratchRegisterScope temps(masm);
722 Register saved_lr = temps.UnsafeAcquire(to_be_pushed_lr());
723 Register return_address = temps.AcquireX();
724 __ Mov(return_address, lr);
725 // Restore lr with the value it had before the call to this stub (the value
726 // which must be pushed).
727 __ Mov(lr, saved_lr);
728 __ PushSafepointRegisters();
729 __ Ret(return_address);
733 void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
734 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
735 UseScratchRegisterScope temps(masm);
736 Register return_address = temps.AcquireX();
737 // Preserve the return address (lr will be clobbered by the pop).
738 __ Mov(return_address, lr);
739 __ PopSafepointRegisters();
740 __ Ret(return_address);
744 void MathPowStub::Generate(MacroAssembler* masm) {
746 // jssp[0]: Exponent (as a tagged value).
747 // jssp[1]: Base (as a tagged value).
749 // The (tagged) result will be returned in x0, as a heap number.
751 Register result_tagged = x0;
752 Register base_tagged = x10;
753 Register exponent_tagged = MathPowTaggedDescriptor::exponent();
754 DCHECK(exponent_tagged.is(x11));
755 Register exponent_integer = MathPowIntegerDescriptor::exponent();
756 DCHECK(exponent_integer.is(x12));
757 Register scratch1 = x14;
758 Register scratch0 = x15;
759 Register saved_lr = x19;
760 FPRegister result_double = d0;
761 FPRegister base_double = d0;
762 FPRegister exponent_double = d1;
763 FPRegister base_double_copy = d2;
764 FPRegister scratch1_double = d6;
765 FPRegister scratch0_double = d7;
767 // A fast-path for integer exponents.
768 Label exponent_is_smi, exponent_is_integer;
769 // Bail out to runtime.
771 // Allocate a heap number for the result, and return it.
774 // Unpack the inputs.
775 if (exponent_type() == ON_STACK) {
777 Label unpack_exponent;
779 __ Pop(exponent_tagged, base_tagged);
781 __ JumpIfSmi(base_tagged, &base_is_smi);
782 __ JumpIfNotHeapNumber(base_tagged, &call_runtime);
783 // base_tagged is a heap number, so load its double value.
784 __ Ldr(base_double, FieldMemOperand(base_tagged, HeapNumber::kValueOffset));
785 __ B(&unpack_exponent);
786 __ Bind(&base_is_smi);
787 // base_tagged is a SMI, so untag it and convert it to a double.
788 __ SmiUntagToDouble(base_double, base_tagged);
790 __ Bind(&unpack_exponent);
791 // x10 base_tagged The tagged base (input).
792 // x11 exponent_tagged The tagged exponent (input).
793 // d1 base_double The base as a double.
794 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
795 __ JumpIfNotHeapNumber(exponent_tagged, &call_runtime);
796 // exponent_tagged is a heap number, so load its double value.
797 __ Ldr(exponent_double,
798 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
799 } else if (exponent_type() == TAGGED) {
800 __ JumpIfSmi(exponent_tagged, &exponent_is_smi);
801 __ Ldr(exponent_double,
802 FieldMemOperand(exponent_tagged, HeapNumber::kValueOffset));
805 // Handle double (heap number) exponents.
806 if (exponent_type() != INTEGER) {
807 // Detect integer exponents stored as doubles and handle those in the
808 // integer fast-path.
809 __ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
810 scratch0_double, &exponent_is_integer);
812 if (exponent_type() == ON_STACK) {
813 FPRegister half_double = d3;
814 FPRegister minus_half_double = d4;
815 // Detect square root case. Crankshaft detects constant +/-0.5 at compile
816 // time and uses DoMathPowHalf instead. We then skip this check for
817 // non-constant cases of +/-0.5 as these hardly occur.
819 __ Fmov(minus_half_double, -0.5);
820 __ Fmov(half_double, 0.5);
821 __ Fcmp(minus_half_double, exponent_double);
822 __ Fccmp(half_double, exponent_double, NZFlag, ne);
823 // Condition flags at this point:
824 // 0.5; nZCv // Identified by eq && pl
825 // -0.5: NZcv // Identified by eq && mi
826 // other: ?z?? // Identified by ne
827 __ B(ne, &call_runtime);
829 // The exponent is 0.5 or -0.5.
831 // Given that exponent is known to be either 0.5 or -0.5, the following
832 // special cases could apply (according to ECMA-262 15.8.2.13):
834 // base.isNaN(): The result is NaN.
835 // (base == +INFINITY) || (base == -INFINITY)
836 // exponent == 0.5: The result is +INFINITY.
837 // exponent == -0.5: The result is +0.
838 // (base == +0) || (base == -0)
839 // exponent == 0.5: The result is +0.
840 // exponent == -0.5: The result is +INFINITY.
841 // (base < 0) && base.isFinite(): The result is NaN.
843 // Fsqrt (and Fdiv for the -0.5 case) can handle all of those except
844 // where base is -INFINITY or -0.
846 // Add +0 to base. This has no effect other than turning -0 into +0.
847 __ Fadd(base_double, base_double, fp_zero);
848 // The operation -0+0 results in +0 in all cases except where the
849 // FPCR rounding mode is 'round towards minus infinity' (RM). The
850 // ARM64 simulator does not currently simulate FPCR (where the rounding
851 // mode is set), so test the operation with some debug code.
852 if (masm->emit_debug_code()) {
853 UseScratchRegisterScope temps(masm);
854 Register temp = temps.AcquireX();
855 __ Fneg(scratch0_double, fp_zero);
856 // Verify that we correctly generated +0.0 and -0.0.
857 // bits(+0.0) = 0x0000000000000000
858 // bits(-0.0) = 0x8000000000000000
859 __ Fmov(temp, fp_zero);
860 __ CheckRegisterIsClear(temp, kCouldNotGenerateZero);
861 __ Fmov(temp, scratch0_double);
862 __ Eor(temp, temp, kDSignMask);
863 __ CheckRegisterIsClear(temp, kCouldNotGenerateNegativeZero);
864 // Check that -0.0 + 0.0 == +0.0.
865 __ Fadd(scratch0_double, scratch0_double, fp_zero);
866 __ Fmov(temp, scratch0_double);
867 __ CheckRegisterIsClear(temp, kExpectedPositiveZero);
870 // If base is -INFINITY, make it +INFINITY.
871 // * Calculate base - base: All infinities will become NaNs since both
872 // -INFINITY+INFINITY and +INFINITY-INFINITY are NaN in ARM64.
873 // * If the result is NaN, calculate abs(base).
874 __ Fsub(scratch0_double, base_double, base_double);
875 __ Fcmp(scratch0_double, 0.0);
876 __ Fabs(scratch1_double, base_double);
877 __ Fcsel(base_double, scratch1_double, base_double, vs);
879 // Calculate the square root of base.
880 __ Fsqrt(result_double, base_double);
881 __ Fcmp(exponent_double, 0.0);
882 __ B(ge, &done); // Finish now for exponents of 0.5.
883 // Find the inverse for exponents of -0.5.
884 __ Fmov(scratch0_double, 1.0);
885 __ Fdiv(result_double, scratch0_double, result_double);
890 AllowExternalCallThatCantCauseGC scope(masm);
891 __ Mov(saved_lr, lr);
893 ExternalReference::power_double_double_function(isolate()),
895 __ Mov(lr, saved_lr);
899 // Handle SMI exponents.
900 __ Bind(&exponent_is_smi);
901 // x10 base_tagged The tagged base (input).
902 // x11 exponent_tagged The tagged exponent (input).
903 // d1 base_double The base as a double.
904 __ SmiUntag(exponent_integer, exponent_tagged);
907 __ Bind(&exponent_is_integer);
908 // x10 base_tagged The tagged base (input).
909 // x11 exponent_tagged The tagged exponent (input).
910 // x12 exponent_integer The exponent as an integer.
911 // d1 base_double The base as a double.
913 // Find abs(exponent). For negative exponents, we can find the inverse later.
914 Register exponent_abs = x13;
915 __ Cmp(exponent_integer, 0);
916 __ Cneg(exponent_abs, exponent_integer, mi);
917 // x13 exponent_abs The value of abs(exponent_integer).
919 // Repeatedly multiply to calculate the power.
921 // For each bit n (exponent_integer{n}) {
922 // if (exponent_integer{n}) {
926 // if (remaining bits in exponent_integer are all zero) {
930 Label power_loop, power_loop_entry, power_loop_exit;
931 __ Fmov(scratch1_double, base_double);
932 __ Fmov(base_double_copy, base_double);
933 __ Fmov(result_double, 1.0);
934 __ B(&power_loop_entry);
936 __ Bind(&power_loop);
937 __ Fmul(scratch1_double, scratch1_double, scratch1_double);
938 __ Lsr(exponent_abs, exponent_abs, 1);
939 __ Cbz(exponent_abs, &power_loop_exit);
941 __ Bind(&power_loop_entry);
942 __ Tbz(exponent_abs, 0, &power_loop);
943 __ Fmul(result_double, result_double, scratch1_double);
946 __ Bind(&power_loop_exit);
948 // If the exponent was positive, result_double holds the result.
949 __ Tbz(exponent_integer, kXSignBit, &done);
951 // The exponent was negative, so find the inverse.
952 __ Fmov(scratch0_double, 1.0);
953 __ Fdiv(result_double, scratch0_double, result_double);
954 // ECMA-262 only requires Math.pow to return an 'implementation-dependent
955 // approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
956 // to calculate the subnormal value 2^-1074. This method of calculating
957 // negative powers doesn't work because 2^1074 overflows to infinity. To
958 // catch this corner-case, we bail out if the result was 0. (This can only
959 // occur if the divisor is infinity or the base is zero.)
960 __ Fcmp(result_double, 0.0);
963 if (exponent_type() == ON_STACK) {
964 // Bail out to runtime code.
965 __ Bind(&call_runtime);
966 // Put the arguments back on the stack.
967 __ Push(base_tagged, exponent_tagged);
968 __ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
972 __ AllocateHeapNumber(result_tagged, &call_runtime, scratch0, scratch1,
974 DCHECK(result_tagged.is(x0));
976 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
979 AllowExternalCallThatCantCauseGC scope(masm);
980 __ Mov(saved_lr, lr);
981 __ Fmov(base_double, base_double_copy);
982 __ Scvtf(exponent_double, exponent_integer);
984 ExternalReference::power_double_double_function(isolate()),
986 __ Mov(lr, saved_lr);
989 isolate()->counters()->math_pow(), 1, scratch0, scratch1);
995 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
996 // It is important that the following stubs are generated in this order
997 // because pregenerated stubs can only call other pregenerated stubs.
998 // RecordWriteStub uses StoreBufferOverflowStub, which in turn uses
1000 CEntryStub::GenerateAheadOfTime(isolate);
1001 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
1002 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
1003 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
1004 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
1005 CreateWeakCellStub::GenerateAheadOfTime(isolate);
1006 BinaryOpICStub::GenerateAheadOfTime(isolate);
1007 StoreRegistersStateStub::GenerateAheadOfTime(isolate);
1008 RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
1009 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
1010 StoreFastElementStub::GenerateAheadOfTime(isolate);
1011 TypeofStub::GenerateAheadOfTime(isolate);
1015 void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1016 StoreRegistersStateStub stub(isolate);
1021 void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
1022 RestoreRegistersStateStub stub(isolate);
1027 void CodeStub::GenerateFPStubs(Isolate* isolate) {
1028 // Floating-point code doesn't get special handling in ARM64, so there's
1029 // nothing to do here.
1034 bool CEntryStub::NeedsImmovableCode() {
1035 // CEntryStub stores the return address on the stack before calling into
1036 // C++ code. In some cases, the VM accesses this address, but it is not used
1037 // when the C++ code returns to the stub because LR holds the return address
1038 // in AAPCS64. If the stub is moved (perhaps during a GC), we could end up
1039 // returning to dead code.
1040 // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't
1041 // find any comment to confirm this, and I don't hit any crashes whatever
1042 // this function returns. The anaylsis should be properly confirmed.
1047 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
1048 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
1050 CEntryStub stub_fp(isolate, 1, kSaveFPRegs);
1055 void CEntryStub::Generate(MacroAssembler* masm) {
1056 // The Abort mechanism relies on CallRuntime, which in turn relies on
1057 // CEntryStub, so until this stub has been generated, we have to use a
1058 // fall-back Abort mechanism.
1060 // Note that this stub must be generated before any use of Abort.
1061 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
1063 ASM_LOCATION("CEntryStub::Generate entry");
1064 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1066 // Register parameters:
1067 // x0: argc (including receiver, untagged)
1070 // The stack on entry holds the arguments and the receiver, with the receiver
1071 // at the highest address:
1073 // jssp]argc-1]: receiver
1074 // jssp[argc-2]: arg[argc-2]
1079 // The arguments are in reverse order, so that arg[argc-2] is actually the
1080 // first argument to the target function and arg[0] is the last.
1081 DCHECK(jssp.Is(__ StackPointer()));
1082 const Register& argc_input = x0;
1083 const Register& target_input = x1;
1085 // Calculate argv, argc and the target address, and store them in
1086 // callee-saved registers so we can retry the call without having to reload
1088 // TODO(jbramley): If the first call attempt succeeds in the common case (as
1089 // it should), then we might be better off putting these parameters directly
1090 // into their argument registers, rather than using callee-saved registers and
1091 // preserving them on the stack.
1092 const Register& argv = x21;
1093 const Register& argc = x22;
1094 const Register& target = x23;
1096 // Derive argv from the stack pointer so that it points to the first argument
1097 // (arg[argc-2]), or just below the receiver in case there are no arguments.
1098 // - Adjust for the arg[] array.
1099 Register temp_argv = x11;
1100 __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
1101 // - Adjust for the receiver.
1102 __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
1104 // Enter the exit frame. Reserve three slots to preserve x21-x23 callee-saved
1106 FrameScope scope(masm, StackFrame::MANUAL);
1107 __ EnterExitFrame(save_doubles(), x10, 3);
1108 DCHECK(csp.Is(__ StackPointer()));
1110 // Poke callee-saved registers into reserved space.
1111 __ Poke(argv, 1 * kPointerSize);
1112 __ Poke(argc, 2 * kPointerSize);
1113 __ Poke(target, 3 * kPointerSize);
1115 // We normally only keep tagged values in callee-saved registers, as they
1116 // could be pushed onto the stack by called stubs and functions, and on the
1117 // stack they can confuse the GC. However, we're only calling C functions
1118 // which can push arbitrary data onto the stack anyway, and so the GC won't
1119 // examine that part of the stack.
1120 __ Mov(argc, argc_input);
1121 __ Mov(target, target_input);
1122 __ Mov(argv, temp_argv);
1126 // x23 : call target
1128 // The stack (on entry) holds the arguments and the receiver, with the
1129 // receiver at the highest address:
1131 // argv[8]: receiver
1132 // argv -> argv[0]: arg[argc-2]
1134 // argv[...]: arg[1]
1135 // argv[...]: arg[0]
1137 // Immediately below (after) this is the exit frame, as constructed by
1139 // fp[8]: CallerPC (lr)
1140 // fp -> fp[0]: CallerFP (old fp)
1141 // fp[-8]: Space reserved for SPOffset.
1142 // fp[-16]: CodeObject()
1143 // csp[...]: Saved doubles, if saved_doubles is true.
1144 // csp[32]: Alignment padding, if necessary.
1145 // csp[24]: Preserved x23 (used for target).
1146 // csp[16]: Preserved x22 (used for argc).
1147 // csp[8]: Preserved x21 (used for argv).
1148 // csp -> csp[0]: Space reserved for the return address.
1150 // After a successful call, the exit frame, preserved registers (x21-x23) and
1151 // the arguments (including the receiver) are dropped or popped as
1152 // appropriate. The stub then returns.
1154 // After an unsuccessful call, the exit frame and suchlike are left
1155 // untouched, and the stub either throws an exception by jumping to one of
1156 // the exception_returned label.
1158 DCHECK(csp.Is(__ StackPointer()));
1160 // Prepare AAPCS64 arguments to pass to the builtin.
1163 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1165 Label return_location;
1166 __ Adr(x12, &return_location);
1169 if (__ emit_debug_code()) {
1170 // Verify that the slot below fp[kSPOffset]-8 points to the return location
1171 // (currently in x12).
1172 UseScratchRegisterScope temps(masm);
1173 Register temp = temps.AcquireX();
1174 __ Ldr(temp, MemOperand(fp, ExitFrameConstants::kSPOffset));
1175 __ Ldr(temp, MemOperand(temp, -static_cast<int64_t>(kXRegSize)));
1177 __ Check(eq, kReturnAddressNotFoundInFrame);
1180 // Call the builtin.
1182 __ Bind(&return_location);
1184 // x0 result The return code from the call.
1188 const Register& result = x0;
1190 // Check result for exception sentinel.
1191 Label exception_returned;
1192 __ CompareRoot(result, Heap::kExceptionRootIndex);
1193 __ B(eq, &exception_returned);
1195 // The call succeeded, so unwind the stack and return.
1197 // Restore callee-saved registers x21-x23.
1200 __ Peek(argv, 1 * kPointerSize);
1201 __ Peek(argc, 2 * kPointerSize);
1202 __ Peek(target, 3 * kPointerSize);
1204 __ LeaveExitFrame(save_doubles(), x10, true);
1205 DCHECK(jssp.Is(__ StackPointer()));
1206 // Pop or drop the remaining stack slots and return from the stub.
1207 // jssp[24]: Arguments array (of size argc), including receiver.
1208 // jssp[16]: Preserved x23 (used for target).
1209 // jssp[8]: Preserved x22 (used for argc).
1210 // jssp[0]: Preserved x21 (used for argv).
1212 __ AssertFPCRState();
1215 // The stack pointer is still csp if we aren't returning, and the frame
1216 // hasn't changed (except for the return address).
1217 __ SetStackPointer(csp);
1219 // Handling of exception.
1220 __ Bind(&exception_returned);
1222 ExternalReference pending_handler_context_address(
1223 Isolate::kPendingHandlerContextAddress, isolate());
1224 ExternalReference pending_handler_code_address(
1225 Isolate::kPendingHandlerCodeAddress, isolate());
1226 ExternalReference pending_handler_offset_address(
1227 Isolate::kPendingHandlerOffsetAddress, isolate());
1228 ExternalReference pending_handler_fp_address(
1229 Isolate::kPendingHandlerFPAddress, isolate());
1230 ExternalReference pending_handler_sp_address(
1231 Isolate::kPendingHandlerSPAddress, isolate());
1233 // Ask the runtime for help to determine the handler. This will set x0 to
1234 // contain the current pending exception, don't clobber it.
1235 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
1237 DCHECK(csp.Is(masm->StackPointer()));
1239 FrameScope scope(masm, StackFrame::MANUAL);
1240 __ Mov(x0, 0); // argc.
1241 __ Mov(x1, 0); // argv.
1242 __ Mov(x2, ExternalReference::isolate_address(isolate()));
1243 __ CallCFunction(find_handler, 3);
1246 // We didn't execute a return case, so the stack frame hasn't been updated
1247 // (except for the return address slot). However, we don't need to initialize
1248 // jssp because the throw method will immediately overwrite it when it
1249 // unwinds the stack.
1250 __ SetStackPointer(jssp);
1252 // Retrieve the handler context, SP and FP.
1253 __ Mov(cp, Operand(pending_handler_context_address));
1254 __ Ldr(cp, MemOperand(cp));
1255 __ Mov(jssp, Operand(pending_handler_sp_address));
1256 __ Ldr(jssp, MemOperand(jssp));
1257 __ Mov(fp, Operand(pending_handler_fp_address));
1258 __ Ldr(fp, MemOperand(fp));
1260 // If the handler is a JS frame, restore the context to the frame. Note that
1261 // the context will be set to (cp == 0) for non-JS frames.
1263 __ Cbz(cp, ¬_js_frame);
1264 __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1265 __ Bind(¬_js_frame);
1267 // Compute the handler entry address and jump to it.
1268 __ Mov(x10, Operand(pending_handler_code_address));
1269 __ Ldr(x10, MemOperand(x10));
1270 __ Mov(x11, Operand(pending_handler_offset_address));
1271 __ Ldr(x11, MemOperand(x11));
1272 __ Add(x10, x10, Code::kHeaderSize - kHeapObjectTag);
1273 __ Add(x10, x10, x11);
1278 // This is the entry point from C++. 5 arguments are provided in x0-x4.
1279 // See use of the CALL_GENERATED_CODE macro for example in src/execution.cc.
1288 void JSEntryStub::Generate(MacroAssembler* masm) {
1289 DCHECK(jssp.Is(__ StackPointer()));
1290 Register code_entry = x0;
1292 // Enable instruction instrumentation. This only works on the simulator, and
1293 // will have no effect on the model or real hardware.
1294 __ EnableInstrumentation();
1296 Label invoke, handler_entry, exit;
1298 // Push callee-saved registers and synchronize the system stack pointer (csp)
1299 // and the JavaScript stack pointer (jssp).
1301 // We must not write to jssp until after the PushCalleeSavedRegisters()
1302 // call, since jssp is itself a callee-saved register.
1303 __ SetStackPointer(csp);
1304 __ PushCalleeSavedRegisters();
1306 __ SetStackPointer(jssp);
1308 // Configure the FPCR. We don't restore it, so this is technically not allowed
1309 // according to AAPCS64. However, we only set default-NaN mode and this will
1310 // be harmless for most C code. Also, it works for ARM.
1313 ProfileEntryHookStub::MaybeCallEntryHook(masm);
1315 // Set up the reserved register for 0.0.
1316 __ Fmov(fp_zero, 0.0);
1318 // Build an entry frame (see layout below).
1319 int marker = type();
1320 int64_t bad_frame_pointer = -1L; // Bad frame pointer to fail if it is used.
1321 __ Mov(x13, bad_frame_pointer);
1322 __ Mov(x12, Smi::FromInt(marker));
1323 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1324 __ Ldr(x10, MemOperand(x11));
1326 __ Push(x13, xzr, x12, x10);
1328 __ Sub(fp, jssp, EntryFrameConstants::kCallerFPOffset);
1330 // Push the JS entry frame marker. Also set js_entry_sp if this is the
1331 // outermost JS call.
1332 Label non_outermost_js, done;
1333 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
1334 __ Mov(x10, ExternalReference(js_entry_sp));
1335 __ Ldr(x11, MemOperand(x10));
1336 __ Cbnz(x11, &non_outermost_js);
1337 __ Str(fp, MemOperand(x10));
1338 __ Mov(x12, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1341 __ Bind(&non_outermost_js);
1342 // We spare one instruction by pushing xzr since the marker is 0.
1343 DCHECK(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME) == NULL);
1347 // The frame set up looks like this:
1348 // jssp[0] : JS entry frame marker.
1349 // jssp[1] : C entry FP.
1350 // jssp[2] : stack frame marker.
1351 // jssp[3] : stack frmae marker.
1352 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1355 // Jump to a faked try block that does the invoke, with a faked catch
1356 // block that sets the pending exception.
1359 // Prevent the constant pool from being emitted between the record of the
1360 // handler_entry position and the first instruction of the sequence here.
1361 // There is no risk because Assembler::Emit() emits the instruction before
1362 // checking for constant pool emission, but we do not want to depend on
1365 Assembler::BlockPoolsScope block_pools(masm);
1366 __ bind(&handler_entry);
1367 handler_offset_ = handler_entry.pos();
1368 // Caught exception: Store result (exception) in the pending exception
1369 // field in the JSEnv and return a failure sentinel. Coming in here the
1370 // fp will be invalid because the PushTryHandler below sets it to 0 to
1371 // signal the existence of the JSEntry frame.
1372 __ Mov(x10, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1375 __ Str(code_entry, MemOperand(x10));
1376 __ LoadRoot(x0, Heap::kExceptionRootIndex);
1379 // Invoke: Link this frame into the handler chain.
1381 __ PushStackHandler();
1382 // If an exception not caught by another handler occurs, this handler
1383 // returns control to the code after the B(&invoke) above, which
1384 // restores all callee-saved registers (including cp and fp) to their
1385 // saved values before returning a failure to C.
1387 // Clear any pending exceptions.
1388 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
1389 __ Mov(x11, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
1391 __ Str(x10, MemOperand(x11));
1393 // Invoke the function by calling through the JS entry trampoline builtin.
1394 // Notice that we cannot store a reference to the trampoline code directly in
1395 // this stub, because runtime stubs are not traversed when doing GC.
1397 // Expected registers by Builtins::JSEntryTrampoline
1403 ExternalReference entry(type() == StackFrame::ENTRY_CONSTRUCT
1404 ? Builtins::kJSConstructEntryTrampoline
1405 : Builtins::kJSEntryTrampoline,
1409 // Call the JSEntryTrampoline.
1410 __ Ldr(x11, MemOperand(x10)); // Dereference the address.
1411 __ Add(x12, x11, Code::kHeaderSize - kHeapObjectTag);
1414 // Unlink this frame from the handler chain.
1415 __ PopStackHandler();
1419 // x0 holds the result.
1420 // The stack pointer points to the top of the entry frame pushed on entry from
1421 // C++ (at the beginning of this stub):
1422 // jssp[0] : JS entry frame marker.
1423 // jssp[1] : C entry FP.
1424 // jssp[2] : stack frame marker.
1425 // jssp[3] : stack frmae marker.
1426 // jssp[4] : bad frame pointer 0xfff...ff <- fp points here.
1428 // Check if the current stack frame is marked as the outermost JS frame.
1429 Label non_outermost_js_2;
1431 __ Cmp(x10, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
1432 __ B(ne, &non_outermost_js_2);
1433 __ Mov(x11, ExternalReference(js_entry_sp));
1434 __ Str(xzr, MemOperand(x11));
1435 __ Bind(&non_outermost_js_2);
1437 // Restore the top frame descriptors from the stack.
1439 __ Mov(x11, ExternalReference(Isolate::kCEntryFPAddress, isolate()));
1440 __ Str(x10, MemOperand(x11));
1442 // Reset the stack to the callee saved registers.
1443 __ Drop(-EntryFrameConstants::kCallerFPOffset, kByteSizeInBytes);
1444 // Restore the callee-saved registers and return.
1445 DCHECK(jssp.Is(__ StackPointer()));
1447 __ SetStackPointer(csp);
1448 __ PopCalleeSavedRegisters();
1449 // After this point, we must not modify jssp because it is a callee-saved
1450 // register which we have just restored.
1455 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
1457 Register receiver = LoadDescriptor::ReceiverRegister();
1458 // Ensure that the vector and slot registers won't be clobbered before
1459 // calling the miss handler.
1460 DCHECK(!AreAliased(x10, x11, LoadWithVectorDescriptor::VectorRegister(),
1461 LoadWithVectorDescriptor::SlotRegister()));
1463 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, x10,
1467 PropertyAccessCompiler::TailCallBuiltin(
1468 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
1472 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
1473 // Return address is in lr.
1476 Register receiver = LoadDescriptor::ReceiverRegister();
1477 Register index = LoadDescriptor::NameRegister();
1478 Register result = x0;
1479 Register scratch = x10;
1480 DCHECK(!scratch.is(receiver) && !scratch.is(index));
1481 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
1482 result.is(LoadWithVectorDescriptor::SlotRegister()));
1484 // StringCharAtGenerator doesn't use the result register until it's passed
1485 // the different miss possibilities. If it did, we would have a conflict
1486 // when FLAG_vector_ics is true.
1487 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
1488 &miss, // When not a string.
1489 &miss, // When not a number.
1490 &miss, // When index out of range.
1491 STRING_INDEX_IS_ARRAY_INDEX,
1492 RECEIVER_IS_STRING);
1493 char_at_generator.GenerateFast(masm);
1496 StubRuntimeCallHelper call_helper;
1497 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
1500 PropertyAccessCompiler::TailCallBuiltin(
1501 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
1505 void InstanceofStub::Generate(MacroAssembler* masm) {
1507 // jssp[0]: function.
1510 // Returns result in x0. Zero indicates instanceof, smi 1 indicates not
1513 Register result = x0;
1514 Register function = right();
1515 Register object = left();
1516 Register scratch1 = x6;
1517 Register scratch2 = x7;
1518 Register res_true = x8;
1519 Register res_false = x9;
1520 // Only used if there was an inline map check site. (See
1521 // LCodeGen::DoInstanceOfKnownGlobal().)
1522 Register map_check_site = x4;
1523 // Delta for the instructions generated between the inline map check and the
1524 // instruction setting the result.
1525 const int32_t kDeltaToLoadBoolResult = 4 * kInstructionSize;
1527 Label not_js_object, slow;
1529 if (!HasArgsInRegisters()) {
1530 __ Pop(function, object);
1533 if (ReturnTrueFalseObject()) {
1534 __ LoadTrueFalseRoots(res_true, res_false);
1536 // This is counter-intuitive, but correct.
1537 __ Mov(res_true, Smi::FromInt(0));
1538 __ Mov(res_false, Smi::FromInt(1));
1541 // Check that the left hand side is a JS object and load its map as a side
1544 __ JumpIfSmi(object, ¬_js_object);
1545 __ IsObjectJSObjectType(object, map, scratch2, ¬_js_object);
1547 // If there is a call site cache, don't look in the global cache, but do the
1548 // real lookup and update the call site cache.
1549 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
1551 __ JumpIfNotRoot(function, Heap::kInstanceofCacheFunctionRootIndex, &miss);
1552 __ JumpIfNotRoot(map, Heap::kInstanceofCacheMapRootIndex, &miss);
1553 __ LoadRoot(result, Heap::kInstanceofCacheAnswerRootIndex);
1558 // Get the prototype of the function.
1559 Register prototype = x13;
1560 __ TryGetFunctionPrototype(function, prototype, scratch2, &slow,
1561 MacroAssembler::kMissOnBoundFunction);
1563 // Check that the function prototype is a JS object.
1564 __ JumpIfSmi(prototype, &slow);
1565 __ IsObjectJSObjectType(prototype, scratch1, scratch2, &slow);
1567 // Update the global instanceof or call site inlined cache with the current
1568 // map and function. The cached answer will be set when it is known below.
1569 if (HasCallSiteInlineCheck()) {
1570 // Patch the (relocated) inlined map check.
1571 __ GetRelocatedValueLocation(map_check_site, scratch1);
1572 // We have a cell, so need another level of dereferencing.
1573 __ Ldr(scratch1, MemOperand(scratch1));
1574 __ Str(map, FieldMemOperand(scratch1, Cell::kValueOffset));
1577 // |scratch1| points at the beginning of the cell. Calculate the
1578 // field containing the map.
1579 __ Add(function, scratch1, Operand(Cell::kValueOffset - 1));
1580 __ RecordWriteField(scratch1, Cell::kValueOffset, x14, function,
1581 kLRHasNotBeenSaved, kDontSaveFPRegs,
1582 OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
1584 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
1585 __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
1588 Label return_true, return_result;
1589 Register smi_value = scratch1;
1591 // Loop through the prototype chain looking for the function prototype.
1592 Register chain_map = x1;
1593 Register chain_prototype = x14;
1594 Register null_value = x15;
1596 __ Ldr(chain_prototype, FieldMemOperand(map, Map::kPrototypeOffset));
1597 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
1598 // Speculatively set a result.
1599 __ Mov(result, res_false);
1600 if (!HasCallSiteInlineCheck() && ReturnTrueFalseObject()) {
1601 // Value to store in the cache cannot be an object.
1602 __ Mov(smi_value, Smi::FromInt(1));
1607 // If the chain prototype is the object prototype, return true.
1608 __ Cmp(chain_prototype, prototype);
1609 __ B(eq, &return_true);
1611 // If the chain prototype is null, we've reached the end of the chain, so
1613 __ Cmp(chain_prototype, null_value);
1614 __ B(eq, &return_result);
1616 // Otherwise, load the next prototype in the chain, and loop.
1617 __ Ldr(chain_map, FieldMemOperand(chain_prototype, HeapObject::kMapOffset));
1618 __ Ldr(chain_prototype, FieldMemOperand(chain_map, Map::kPrototypeOffset));
1622 // Return sequence when no arguments are on the stack.
1623 // We cannot fall through to here.
1624 __ Bind(&return_true);
1625 __ Mov(result, res_true);
1626 if (!HasCallSiteInlineCheck() && ReturnTrueFalseObject()) {
1627 // Value to store in the cache cannot be an object.
1628 __ Mov(smi_value, Smi::FromInt(0));
1630 __ Bind(&return_result);
1631 if (HasCallSiteInlineCheck()) {
1632 DCHECK(ReturnTrueFalseObject());
1633 __ Add(map_check_site, map_check_site, kDeltaToLoadBoolResult);
1634 __ GetRelocatedValueLocation(map_check_site, scratch2);
1635 __ Str(result, MemOperand(scratch2));
1637 Register cached_value = ReturnTrueFalseObject() ? smi_value : result;
1638 __ StoreRoot(cached_value, Heap::kInstanceofCacheAnswerRootIndex);
1642 Label object_not_null, object_not_null_or_smi;
1644 __ Bind(¬_js_object);
1645 Register object_type = x14;
1646 // x0 result result return register (uninit)
1647 // x10 function pointer to function
1648 // x11 object pointer to object
1649 // x14 object_type type of object (uninit)
1651 // Before null, smi and string checks, check that the rhs is a function.
1652 // For a non-function rhs, an exception must be thrown.
1653 __ JumpIfSmi(function, &slow);
1654 __ JumpIfNotObjectType(
1655 function, scratch1, object_type, JS_FUNCTION_TYPE, &slow);
1657 __ Mov(result, res_false);
1659 // Null is not instance of anything.
1660 __ Cmp(object, Operand(isolate()->factory()->null_value()));
1661 __ B(ne, &object_not_null);
1664 __ Bind(&object_not_null);
1665 // Smi values are not instances of anything.
1666 __ JumpIfNotSmi(object, &object_not_null_or_smi);
1669 __ Bind(&object_not_null_or_smi);
1670 // String values are not instances of anything.
1671 __ IsObjectJSStringType(object, scratch2, &slow);
1674 // Slow-case. Tail call builtin.
1677 FrameScope scope(masm, StackFrame::INTERNAL);
1678 // Arguments have either been passed into registers or have been previously
1679 // popped. We need to push them before calling builtin.
1680 __ Push(object, function);
1681 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
1683 if (ReturnTrueFalseObject()) {
1684 // Reload true/false because they were clobbered in the builtin call.
1685 __ LoadTrueFalseRoots(res_true, res_false);
1687 __ Csel(result, res_true, res_false, eq);
1693 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
1694 Register arg_count = ArgumentsAccessReadDescriptor::parameter_count();
1695 Register key = ArgumentsAccessReadDescriptor::index();
1696 DCHECK(arg_count.is(x0));
1699 // The displacement is the offset of the last parameter (if any) relative
1700 // to the frame pointer.
1701 static const int kDisplacement =
1702 StandardFrameConstants::kCallerSPOffset - kPointerSize;
1704 // Check that the key is a smi.
1706 __ JumpIfNotSmi(key, &slow);
1708 // Check if the calling frame is an arguments adaptor frame.
1709 Register local_fp = x11;
1710 Register caller_fp = x11;
1711 Register caller_ctx = x12;
1713 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1714 __ Ldr(caller_ctx, MemOperand(caller_fp,
1715 StandardFrameConstants::kContextOffset));
1716 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1717 __ Csel(local_fp, fp, caller_fp, ne);
1718 __ B(ne, &skip_adaptor);
1720 // Load the actual arguments limit found in the arguments adaptor frame.
1721 __ Ldr(arg_count, MemOperand(caller_fp,
1722 ArgumentsAdaptorFrameConstants::kLengthOffset));
1723 __ Bind(&skip_adaptor);
1725 // Check index against formal parameters count limit. Use unsigned comparison
1726 // to get negative check for free: branch if key < 0 or key >= arg_count.
1727 __ Cmp(key, arg_count);
1730 // Read the argument from the stack and return it.
1731 __ Sub(x10, arg_count, key);
1732 __ Add(x10, local_fp, Operand::UntagSmiAndScale(x10, kPointerSizeLog2));
1733 __ Ldr(x0, MemOperand(x10, kDisplacement));
1736 // Slow case: handle non-smi or out-of-bounds access to arguments by calling
1737 // the runtime system.
1740 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
1744 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
1745 // Stack layout on entry.
1746 // jssp[0]: number of parameters (tagged)
1747 // jssp[8]: address of receiver argument
1748 // jssp[16]: function
1750 // Check if the calling frame is an arguments adaptor frame.
1752 Register caller_fp = x10;
1753 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1754 // Load and untag the context.
1755 __ Ldr(w11, UntagSmiMemOperand(caller_fp,
1756 StandardFrameConstants::kContextOffset));
1757 __ Cmp(w11, StackFrame::ARGUMENTS_ADAPTOR);
1760 // Patch the arguments.length and parameters pointer in the current frame.
1761 __ Ldr(x11, MemOperand(caller_fp,
1762 ArgumentsAdaptorFrameConstants::kLengthOffset));
1763 __ Poke(x11, 0 * kXRegSize);
1764 __ Add(x10, caller_fp, Operand::UntagSmiAndScale(x11, kPointerSizeLog2));
1765 __ Add(x10, x10, StandardFrameConstants::kCallerSPOffset);
1766 __ Poke(x10, 1 * kXRegSize);
1769 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
1773 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
1774 // Stack layout on entry.
1775 // jssp[0]: number of parameters (tagged)
1776 // jssp[8]: address of receiver argument
1777 // jssp[16]: function
1779 // Returns pointer to result object in x0.
1781 // Note: arg_count_smi is an alias of param_count_smi.
1782 Register arg_count_smi = x3;
1783 Register param_count_smi = x3;
1784 Register param_count = x7;
1785 Register recv_arg = x14;
1786 Register function = x4;
1787 __ Pop(param_count_smi, recv_arg, function);
1788 __ SmiUntag(param_count, param_count_smi);
1790 // Check if the calling frame is an arguments adaptor frame.
1791 Register caller_fp = x11;
1792 Register caller_ctx = x12;
1794 Label adaptor_frame, try_allocate;
1795 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1796 __ Ldr(caller_ctx, MemOperand(caller_fp,
1797 StandardFrameConstants::kContextOffset));
1798 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1799 __ B(eq, &adaptor_frame);
1801 // No adaptor, parameter count = argument count.
1803 // x1 mapped_params number of mapped params, min(params, args) (uninit)
1804 // x2 arg_count number of function arguments (uninit)
1805 // x3 arg_count_smi number of function arguments (smi)
1806 // x4 function function pointer
1807 // x7 param_count number of function parameters
1808 // x11 caller_fp caller's frame pointer
1809 // x14 recv_arg pointer to receiver arguments
1811 Register arg_count = x2;
1812 __ Mov(arg_count, param_count);
1813 __ B(&try_allocate);
1815 // We have an adaptor frame. Patch the parameters pointer.
1816 __ Bind(&adaptor_frame);
1817 __ Ldr(arg_count_smi,
1818 MemOperand(caller_fp,
1819 ArgumentsAdaptorFrameConstants::kLengthOffset));
1820 __ SmiUntag(arg_count, arg_count_smi);
1821 __ Add(x10, caller_fp, Operand(arg_count, LSL, kPointerSizeLog2));
1822 __ Add(recv_arg, x10, StandardFrameConstants::kCallerSPOffset);
1824 // Compute the mapped parameter count = min(param_count, arg_count)
1825 Register mapped_params = x1;
1826 __ Cmp(param_count, arg_count);
1827 __ Csel(mapped_params, param_count, arg_count, lt);
1829 __ Bind(&try_allocate);
1831 // x0 alloc_obj pointer to allocated objects: param map, backing
1832 // store, arguments (uninit)
1833 // x1 mapped_params number of mapped parameters, min(params, args)
1834 // x2 arg_count number of function arguments
1835 // x3 arg_count_smi number of function arguments (smi)
1836 // x4 function function pointer
1837 // x7 param_count number of function parameters
1838 // x10 size size of objects to allocate (uninit)
1839 // x14 recv_arg pointer to receiver arguments
1841 // Compute the size of backing store, parameter map, and arguments object.
1842 // 1. Parameter map, has two extra words containing context and backing
1844 const int kParameterMapHeaderSize =
1845 FixedArray::kHeaderSize + 2 * kPointerSize;
1847 // Calculate the parameter map size, assuming it exists.
1848 Register size = x10;
1849 __ Mov(size, Operand(mapped_params, LSL, kPointerSizeLog2));
1850 __ Add(size, size, kParameterMapHeaderSize);
1852 // If there are no mapped parameters, set the running size total to zero.
1853 // Otherwise, use the parameter map size calculated earlier.
1854 __ Cmp(mapped_params, 0);
1855 __ CzeroX(size, eq);
1857 // 2. Add the size of the backing store and arguments object.
1858 __ Add(size, size, Operand(arg_count, LSL, kPointerSizeLog2));
1860 FixedArray::kHeaderSize + Heap::kSloppyArgumentsObjectSize);
1862 // Do the allocation of all three objects in one go. Assign this to x0, as it
1863 // will be returned to the caller.
1864 Register alloc_obj = x0;
1865 __ Allocate(size, alloc_obj, x11, x12, &runtime, TAG_OBJECT);
1867 // Get the arguments boilerplate from the current (global) context.
1869 // x0 alloc_obj pointer to allocated objects (param map, backing
1870 // store, arguments)
1871 // x1 mapped_params number of mapped parameters, min(params, args)
1872 // x2 arg_count number of function arguments
1873 // x3 arg_count_smi number of function arguments (smi)
1874 // x4 function function pointer
1875 // x7 param_count number of function parameters
1876 // x11 sloppy_args_map offset to args (or aliased args) map (uninit)
1877 // x14 recv_arg pointer to receiver arguments
1879 Register global_object = x10;
1880 Register global_ctx = x10;
1881 Register sloppy_args_map = x11;
1882 Register aliased_args_map = x10;
1883 __ Ldr(global_object, GlobalObjectMemOperand());
1884 __ Ldr(global_ctx, FieldMemOperand(global_object,
1885 GlobalObject::kNativeContextOffset));
1887 __ Ldr(sloppy_args_map,
1888 ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1891 ContextMemOperand(global_ctx, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX));
1892 __ Cmp(mapped_params, 0);
1893 __ CmovX(sloppy_args_map, aliased_args_map, ne);
1895 // Copy the JS object part.
1896 __ Str(sloppy_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
1897 __ LoadRoot(x10, Heap::kEmptyFixedArrayRootIndex);
1898 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
1899 __ Str(x10, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1901 // Set up the callee in-object property.
1902 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
1903 const int kCalleeOffset = JSObject::kHeaderSize +
1904 Heap::kArgumentsCalleeIndex * kPointerSize;
1905 __ AssertNotSmi(function);
1906 __ Str(function, FieldMemOperand(alloc_obj, kCalleeOffset));
1908 // Use the length and set that as an in-object property.
1909 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
1910 const int kLengthOffset = JSObject::kHeaderSize +
1911 Heap::kArgumentsLengthIndex * kPointerSize;
1912 __ Str(arg_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
1914 // Set up the elements pointer in the allocated arguments object.
1915 // If we allocated a parameter map, "elements" will point there, otherwise
1916 // it will point to the backing store.
1918 // x0 alloc_obj pointer to allocated objects (param map, backing
1919 // store, arguments)
1920 // x1 mapped_params number of mapped parameters, min(params, args)
1921 // x2 arg_count number of function arguments
1922 // x3 arg_count_smi number of function arguments (smi)
1923 // x4 function function pointer
1924 // x5 elements pointer to parameter map or backing store (uninit)
1925 // x6 backing_store pointer to backing store (uninit)
1926 // x7 param_count number of function parameters
1927 // x14 recv_arg pointer to receiver arguments
1929 Register elements = x5;
1930 __ Add(elements, alloc_obj, Heap::kSloppyArgumentsObjectSize);
1931 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
1933 // Initialize parameter map. If there are no mapped arguments, we're done.
1934 Label skip_parameter_map;
1935 __ Cmp(mapped_params, 0);
1936 // Set up backing store address, because it is needed later for filling in
1937 // the unmapped arguments.
1938 Register backing_store = x6;
1939 __ CmovX(backing_store, elements, eq);
1940 __ B(eq, &skip_parameter_map);
1942 __ LoadRoot(x10, Heap::kSloppyArgumentsElementsMapRootIndex);
1943 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
1944 __ Add(x10, mapped_params, 2);
1946 __ Str(x10, FieldMemOperand(elements, FixedArray::kLengthOffset));
1947 __ Str(cp, FieldMemOperand(elements,
1948 FixedArray::kHeaderSize + 0 * kPointerSize));
1949 __ Add(x10, elements, Operand(mapped_params, LSL, kPointerSizeLog2));
1950 __ Add(x10, x10, kParameterMapHeaderSize);
1951 __ Str(x10, FieldMemOperand(elements,
1952 FixedArray::kHeaderSize + 1 * kPointerSize));
1954 // Copy the parameter slots and the holes in the arguments.
1955 // We need to fill in mapped_parameter_count slots. Then index the context,
1956 // where parameters are stored in reverse order, at:
1958 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS + parameter_count - 1
1960 // The mapped parameter thus needs to get indices:
1962 // MIN_CONTEXT_SLOTS + parameter_count - 1 ..
1963 // MIN_CONTEXT_SLOTS + parameter_count - mapped_parameter_count
1965 // We loop from right to left.
1967 // x0 alloc_obj pointer to allocated objects (param map, backing
1968 // store, arguments)
1969 // x1 mapped_params number of mapped parameters, min(params, args)
1970 // x2 arg_count number of function arguments
1971 // x3 arg_count_smi number of function arguments (smi)
1972 // x4 function function pointer
1973 // x5 elements pointer to parameter map or backing store (uninit)
1974 // x6 backing_store pointer to backing store (uninit)
1975 // x7 param_count number of function parameters
1976 // x11 loop_count parameter loop counter (uninit)
1977 // x12 index parameter index (smi, uninit)
1978 // x13 the_hole hole value (uninit)
1979 // x14 recv_arg pointer to receiver arguments
1981 Register loop_count = x11;
1982 Register index = x12;
1983 Register the_hole = x13;
1984 Label parameters_loop, parameters_test;
1985 __ Mov(loop_count, mapped_params);
1986 __ Add(index, param_count, static_cast<int>(Context::MIN_CONTEXT_SLOTS));
1987 __ Sub(index, index, mapped_params);
1989 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
1990 __ Add(backing_store, elements, Operand(loop_count, LSL, kPointerSizeLog2));
1991 __ Add(backing_store, backing_store, kParameterMapHeaderSize);
1993 __ B(¶meters_test);
1995 __ Bind(¶meters_loop);
1996 __ Sub(loop_count, loop_count, 1);
1997 __ Mov(x10, Operand(loop_count, LSL, kPointerSizeLog2));
1998 __ Add(x10, x10, kParameterMapHeaderSize - kHeapObjectTag);
1999 __ Str(index, MemOperand(elements, x10));
2000 __ Sub(x10, x10, kParameterMapHeaderSize - FixedArray::kHeaderSize);
2001 __ Str(the_hole, MemOperand(backing_store, x10));
2002 __ Add(index, index, Smi::FromInt(1));
2003 __ Bind(¶meters_test);
2004 __ Cbnz(loop_count, ¶meters_loop);
2006 __ Bind(&skip_parameter_map);
2007 // Copy arguments header and remaining slots (if there are any.)
2008 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
2009 __ Str(x10, FieldMemOperand(backing_store, FixedArray::kMapOffset));
2010 __ Str(arg_count_smi, FieldMemOperand(backing_store,
2011 FixedArray::kLengthOffset));
2013 // x0 alloc_obj pointer to allocated objects (param map, backing
2014 // store, arguments)
2015 // x1 mapped_params number of mapped parameters, min(params, args)
2016 // x2 arg_count number of function arguments
2017 // x4 function function pointer
2018 // x3 arg_count_smi number of function arguments (smi)
2019 // x6 backing_store pointer to backing store (uninit)
2020 // x14 recv_arg pointer to receiver arguments
2022 Label arguments_loop, arguments_test;
2023 __ Mov(x10, mapped_params);
2024 __ Sub(recv_arg, recv_arg, Operand(x10, LSL, kPointerSizeLog2));
2025 __ B(&arguments_test);
2027 __ Bind(&arguments_loop);
2028 __ Sub(recv_arg, recv_arg, kPointerSize);
2029 __ Ldr(x11, MemOperand(recv_arg));
2030 __ Add(x12, backing_store, Operand(x10, LSL, kPointerSizeLog2));
2031 __ Str(x11, FieldMemOperand(x12, FixedArray::kHeaderSize));
2032 __ Add(x10, x10, 1);
2034 __ Bind(&arguments_test);
2035 __ Cmp(x10, arg_count);
2036 __ B(lt, &arguments_loop);
2040 // Do the runtime call to allocate the arguments object.
2042 __ Push(function, recv_arg, arg_count_smi);
2043 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
2047 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
2048 // Return address is in lr.
2051 Register receiver = LoadDescriptor::ReceiverRegister();
2052 Register key = LoadDescriptor::NameRegister();
2054 // Check that the key is an array index, that is Uint32.
2055 __ TestAndBranchIfAnySet(key, kSmiTagMask | kSmiSignMask, &slow);
2057 // Everything is fine, call runtime.
2058 __ Push(receiver, key);
2059 __ TailCallExternalReference(
2060 ExternalReference(IC_Utility(IC::kLoadElementWithInterceptor),
2065 PropertyAccessCompiler::TailCallBuiltin(
2066 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
2070 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
2071 // Stack layout on entry.
2072 // jssp[0]: number of parameters (tagged)
2073 // jssp[8]: address of receiver argument
2074 // jssp[16]: function
2076 // Returns pointer to result object in x0.
2078 // Get the stub arguments from the frame, and make an untagged copy of the
2080 Register param_count_smi = x1;
2081 Register params = x2;
2082 Register function = x3;
2083 Register param_count = x13;
2084 __ Pop(param_count_smi, params, function);
2085 __ SmiUntag(param_count, param_count_smi);
2087 // Test if arguments adaptor needed.
2088 Register caller_fp = x11;
2089 Register caller_ctx = x12;
2090 Label try_allocate, runtime;
2091 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2092 __ Ldr(caller_ctx, MemOperand(caller_fp,
2093 StandardFrameConstants::kContextOffset));
2094 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2095 __ B(ne, &try_allocate);
2097 // x1 param_count_smi number of parameters passed to function (smi)
2098 // x2 params pointer to parameters
2099 // x3 function function pointer
2100 // x11 caller_fp caller's frame pointer
2101 // x13 param_count number of parameters passed to function
2103 // Patch the argument length and parameters pointer.
2104 __ Ldr(param_count_smi,
2105 MemOperand(caller_fp,
2106 ArgumentsAdaptorFrameConstants::kLengthOffset));
2107 __ SmiUntag(param_count, param_count_smi);
2108 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2109 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2111 // Try the new space allocation. Start out with computing the size of the
2112 // arguments object and the elements array in words.
2113 Register size = x10;
2114 __ Bind(&try_allocate);
2115 __ Add(size, param_count, FixedArray::kHeaderSize / kPointerSize);
2116 __ Cmp(param_count, 0);
2117 __ CzeroX(size, eq);
2118 __ Add(size, size, Heap::kStrictArgumentsObjectSize / kPointerSize);
2120 // Do the allocation of both objects in one go. Assign this to x0, as it will
2121 // be returned to the caller.
2122 Register alloc_obj = x0;
2123 __ Allocate(size, alloc_obj, x11, x12, &runtime,
2124 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
2126 // Get the arguments boilerplate from the current (native) context.
2127 Register global_object = x10;
2128 Register global_ctx = x10;
2129 Register strict_args_map = x4;
2130 __ Ldr(global_object, GlobalObjectMemOperand());
2131 __ Ldr(global_ctx, FieldMemOperand(global_object,
2132 GlobalObject::kNativeContextOffset));
2133 __ Ldr(strict_args_map,
2134 ContextMemOperand(global_ctx, Context::STRICT_ARGUMENTS_MAP_INDEX));
2136 // x0 alloc_obj pointer to allocated objects: parameter array and
2138 // x1 param_count_smi number of parameters passed to function (smi)
2139 // x2 params pointer to parameters
2140 // x3 function function pointer
2141 // x4 strict_args_map offset to arguments map
2142 // x13 param_count number of parameters passed to function
2143 __ Str(strict_args_map, FieldMemOperand(alloc_obj, JSObject::kMapOffset));
2144 __ LoadRoot(x5, Heap::kEmptyFixedArrayRootIndex);
2145 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kPropertiesOffset));
2146 __ Str(x5, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2148 // Set the smi-tagged length as an in-object property.
2149 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
2150 const int kLengthOffset = JSObject::kHeaderSize +
2151 Heap::kArgumentsLengthIndex * kPointerSize;
2152 __ Str(param_count_smi, FieldMemOperand(alloc_obj, kLengthOffset));
2154 // If there are no actual arguments, we're done.
2156 __ Cbz(param_count, &done);
2158 // Set up the elements pointer in the allocated arguments object and
2159 // initialize the header in the elements fixed array.
2160 Register elements = x5;
2161 __ Add(elements, alloc_obj, Heap::kStrictArgumentsObjectSize);
2162 __ Str(elements, FieldMemOperand(alloc_obj, JSObject::kElementsOffset));
2163 __ LoadRoot(x10, Heap::kFixedArrayMapRootIndex);
2164 __ Str(x10, FieldMemOperand(elements, FixedArray::kMapOffset));
2165 __ Str(param_count_smi, FieldMemOperand(elements, FixedArray::kLengthOffset));
2167 // x0 alloc_obj pointer to allocated objects: parameter array and
2169 // x1 param_count_smi number of parameters passed to function (smi)
2170 // x2 params pointer to parameters
2171 // x3 function function pointer
2172 // x4 array pointer to array slot (uninit)
2173 // x5 elements pointer to elements array of alloc_obj
2174 // x13 param_count number of parameters passed to function
2176 // Copy the fixed array slots.
2178 Register array = x4;
2179 // Set up pointer to first array slot.
2180 __ Add(array, elements, FixedArray::kHeaderSize - kHeapObjectTag);
2183 // Pre-decrement the parameters pointer by kPointerSize on each iteration.
2184 // Pre-decrement in order to skip receiver.
2185 __ Ldr(x10, MemOperand(params, -kPointerSize, PreIndex));
2186 // Post-increment elements by kPointerSize on each iteration.
2187 __ Str(x10, MemOperand(array, kPointerSize, PostIndex));
2188 __ Sub(param_count, param_count, 1);
2189 __ Cbnz(param_count, &loop);
2191 // Return from stub.
2195 // Do the runtime call to allocate the arguments object.
2197 __ Push(function, params, param_count_smi);
2198 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
2202 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
2203 // Stack layout on entry.
2204 // jssp[0]: language mode (tagged)
2205 // jssp[8]: index of rest parameter (tagged)
2206 // jssp[16]: number of parameters (tagged)
2207 // jssp[24]: address of receiver argument
2209 // Returns pointer to result object in x0.
2211 // Get the stub arguments from the frame, and make an untagged copy of the
2213 Register language_mode_smi = x1;
2214 Register rest_index_smi = x2;
2215 Register param_count_smi = x3;
2216 Register params = x4;
2217 Register param_count = x13;
2218 __ Pop(language_mode_smi, rest_index_smi, param_count_smi, params);
2219 __ SmiUntag(param_count, param_count_smi);
2221 // Test if arguments adaptor needed.
2222 Register caller_fp = x11;
2223 Register caller_ctx = x12;
2225 __ Ldr(caller_fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2226 __ Ldr(caller_ctx, MemOperand(caller_fp,
2227 StandardFrameConstants::kContextOffset));
2228 __ Cmp(caller_ctx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
2231 // x1 language_mode_smi language mode
2232 // x2 rest_index_smi index of rest parameter
2233 // x3 param_count_smi number of parameters passed to function (smi)
2234 // x4 params pointer to parameters
2235 // x11 caller_fp caller's frame pointer
2236 // x13 param_count number of parameters passed to function
2238 // Patch the argument length and parameters pointer.
2239 __ Ldr(param_count_smi,
2240 MemOperand(caller_fp,
2241 ArgumentsAdaptorFrameConstants::kLengthOffset));
2242 __ SmiUntag(param_count, param_count_smi);
2243 __ Add(x10, caller_fp, Operand(param_count, LSL, kPointerSizeLog2));
2244 __ Add(params, x10, StandardFrameConstants::kCallerSPOffset);
2247 __ Push(params, param_count_smi, rest_index_smi, language_mode_smi);
2248 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
2252 void RegExpExecStub::Generate(MacroAssembler* masm) {
2253 #ifdef V8_INTERPRETED_REGEXP
2254 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2255 #else // V8_INTERPRETED_REGEXP
2257 // Stack frame on entry.
2258 // jssp[0]: last_match_info (expected JSArray)
2259 // jssp[8]: previous index
2260 // jssp[16]: subject string
2261 // jssp[24]: JSRegExp object
2264 // Use of registers for this function.
2266 // Variable registers:
2267 // x10-x13 used as scratch registers
2268 // w0 string_type type of subject string
2269 // x2 jsstring_length subject string length
2270 // x3 jsregexp_object JSRegExp object
2271 // w4 string_encoding Latin1 or UC16
2272 // w5 sliced_string_offset if the string is a SlicedString
2273 // offset to the underlying string
2274 // w6 string_representation groups attributes of the string:
2276 // - type of the string
2277 // - is a short external string
2278 Register string_type = w0;
2279 Register jsstring_length = x2;
2280 Register jsregexp_object = x3;
2281 Register string_encoding = w4;
2282 Register sliced_string_offset = w5;
2283 Register string_representation = w6;
2285 // These are in callee save registers and will be preserved by the call
2286 // to the native RegExp code, as this code is called using the normal
2287 // C calling convention. When calling directly from generated code the
2288 // native RegExp code will not do a GC and therefore the content of
2289 // these registers are safe to use after the call.
2291 // x19 subject subject string
2292 // x20 regexp_data RegExp data (FixedArray)
2293 // x21 last_match_info_elements info relative to the last match
2295 // x22 code_object generated regexp code
2296 Register subject = x19;
2297 Register regexp_data = x20;
2298 Register last_match_info_elements = x21;
2299 Register code_object = x22;
2302 // jssp[00]: last_match_info (JSArray)
2303 // jssp[08]: previous index
2304 // jssp[16]: subject string
2305 // jssp[24]: JSRegExp object
2307 const int kLastMatchInfoOffset = 0 * kPointerSize;
2308 const int kPreviousIndexOffset = 1 * kPointerSize;
2309 const int kSubjectOffset = 2 * kPointerSize;
2310 const int kJSRegExpOffset = 3 * kPointerSize;
2312 // Ensure that a RegExp stack is allocated.
2313 ExternalReference address_of_regexp_stack_memory_address =
2314 ExternalReference::address_of_regexp_stack_memory_address(isolate());
2315 ExternalReference address_of_regexp_stack_memory_size =
2316 ExternalReference::address_of_regexp_stack_memory_size(isolate());
2317 __ Mov(x10, address_of_regexp_stack_memory_size);
2318 __ Ldr(x10, MemOperand(x10));
2319 __ Cbz(x10, &runtime);
2321 // Check that the first argument is a JSRegExp object.
2322 DCHECK(jssp.Is(__ StackPointer()));
2323 __ Peek(jsregexp_object, kJSRegExpOffset);
2324 __ JumpIfSmi(jsregexp_object, &runtime);
2325 __ JumpIfNotObjectType(jsregexp_object, x10, x10, JS_REGEXP_TYPE, &runtime);
2327 // Check that the RegExp has been compiled (data contains a fixed array).
2328 __ Ldr(regexp_data, FieldMemOperand(jsregexp_object, JSRegExp::kDataOffset));
2329 if (FLAG_debug_code) {
2330 STATIC_ASSERT(kSmiTag == 0);
2331 __ Tst(regexp_data, kSmiTagMask);
2332 __ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2333 __ CompareObjectType(regexp_data, x10, x10, FIXED_ARRAY_TYPE);
2334 __ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
2337 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
2338 __ Ldr(x10, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
2339 __ Cmp(x10, Smi::FromInt(JSRegExp::IRREGEXP));
2342 // Check that the number of captures fit in the static offsets vector buffer.
2343 // We have always at least one capture for the whole match, plus additional
2344 // ones due to capturing parentheses. A capture takes 2 registers.
2345 // The number of capture registers then is (number_of_captures + 1) * 2.
2347 UntagSmiFieldMemOperand(regexp_data,
2348 JSRegExp::kIrregexpCaptureCountOffset));
2349 // Check (number_of_captures + 1) * 2 <= offsets vector size
2350 // number_of_captures * 2 <= offsets vector size - 2
2351 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
2352 __ Add(x10, x10, x10);
2353 __ Cmp(x10, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
2356 // Initialize offset for possibly sliced string.
2357 __ Mov(sliced_string_offset, 0);
2359 DCHECK(jssp.Is(__ StackPointer()));
2360 __ Peek(subject, kSubjectOffset);
2361 __ JumpIfSmi(subject, &runtime);
2363 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2364 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2366 __ Ldr(jsstring_length, FieldMemOperand(subject, String::kLengthOffset));
2368 // Handle subject string according to its encoding and representation:
2369 // (1) Sequential string? If yes, go to (5).
2370 // (2) Anything but sequential or cons? If yes, go to (6).
2371 // (3) Cons string. If the string is flat, replace subject with first string.
2372 // Otherwise bailout.
2373 // (4) Is subject external? If yes, go to (7).
2374 // (5) Sequential string. Load regexp code according to encoding.
2378 // Deferred code at the end of the stub:
2379 // (6) Not a long external string? If yes, go to (8).
2380 // (7) External string. Make it, offset-wise, look like a sequential string.
2382 // (8) Short external string or not a string? If yes, bail out to runtime.
2383 // (9) Sliced string. Replace subject with parent. Go to (4).
2385 Label check_underlying; // (4)
2386 Label seq_string; // (5)
2387 Label not_seq_nor_cons; // (6)
2388 Label external_string; // (7)
2389 Label not_long_external; // (8)
2391 // (1) Sequential string? If yes, go to (5).
2392 __ And(string_representation,
2395 kStringRepresentationMask |
2396 kShortExternalStringMask);
2397 // We depend on the fact that Strings of type
2398 // SeqString and not ShortExternalString are defined
2399 // by the following pattern:
2400 // string_type: 0XX0 XX00
2403 // | | is a SeqString
2404 // | is not a short external String
2406 STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
2407 STATIC_ASSERT(kShortExternalStringTag != 0);
2408 __ Cbz(string_representation, &seq_string); // Go to (5).
2410 // (2) Anything but sequential or cons? If yes, go to (6).
2411 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
2412 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
2413 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
2414 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
2415 __ Cmp(string_representation, kExternalStringTag);
2416 __ B(ge, ¬_seq_nor_cons); // Go to (6).
2418 // (3) Cons string. Check that it's flat.
2419 __ Ldr(x10, FieldMemOperand(subject, ConsString::kSecondOffset));
2420 __ JumpIfNotRoot(x10, Heap::kempty_stringRootIndex, &runtime);
2421 // Replace subject with first string.
2422 __ Ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
2424 // (4) Is subject external? If yes, go to (7).
2425 __ Bind(&check_underlying);
2426 // Reload the string type.
2427 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2428 __ Ldrb(string_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2429 STATIC_ASSERT(kSeqStringTag == 0);
2430 // The underlying external string is never a short external string.
2431 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
2432 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
2433 __ TestAndBranchIfAnySet(string_type.X(),
2434 kStringRepresentationMask,
2435 &external_string); // Go to (7).
2437 // (5) Sequential string. Load regexp code according to encoding.
2438 __ Bind(&seq_string);
2440 // Check that the third argument is a positive smi less than the subject
2441 // string length. A negative value will be greater (unsigned comparison).
2442 DCHECK(jssp.Is(__ StackPointer()));
2443 __ Peek(x10, kPreviousIndexOffset);
2444 __ JumpIfNotSmi(x10, &runtime);
2445 __ Cmp(jsstring_length, x10);
2448 // Argument 2 (x1): We need to load argument 2 (the previous index) into x1
2449 // before entering the exit frame.
2450 __ SmiUntag(x1, x10);
2452 // The third bit determines the string encoding in string_type.
2453 STATIC_ASSERT(kOneByteStringTag == 0x04);
2454 STATIC_ASSERT(kTwoByteStringTag == 0x00);
2455 STATIC_ASSERT(kStringEncodingMask == 0x04);
2457 // Find the code object based on the assumptions above.
2458 // kDataOneByteCodeOffset and kDataUC16CodeOffset are adjacent, adds an offset
2459 // of kPointerSize to reach the latter.
2460 DCHECK_EQ(JSRegExp::kDataOneByteCodeOffset + kPointerSize,
2461 JSRegExp::kDataUC16CodeOffset);
2462 __ Mov(x10, kPointerSize);
2463 // We will need the encoding later: Latin1 = 0x04
2465 __ Ands(string_encoding, string_type, kStringEncodingMask);
2467 __ Add(x10, regexp_data, x10);
2468 __ Ldr(code_object, FieldMemOperand(x10, JSRegExp::kDataOneByteCodeOffset));
2470 // (E) Carry on. String handling is done.
2472 // Check that the irregexp code has been generated for the actual string
2473 // encoding. If it has, the field contains a code object otherwise it contains
2474 // a smi (code flushing support).
2475 __ JumpIfSmi(code_object, &runtime);
2477 // All checks done. Now push arguments for native regexp code.
2478 __ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1,
2482 // Isolates: note we add an additional parameter here (isolate pointer).
2483 __ EnterExitFrame(false, x10, 1);
2484 DCHECK(csp.Is(__ StackPointer()));
2486 // We have 9 arguments to pass to the regexp code, therefore we have to pass
2487 // one on the stack and the rest as registers.
2489 // Note that the placement of the argument on the stack isn't standard
2491 // csp[0]: Space for the return address placed by DirectCEntryStub.
2492 // csp[8]: Argument 9, the current isolate address.
2494 __ Mov(x10, ExternalReference::isolate_address(isolate()));
2495 __ Poke(x10, kPointerSize);
2497 Register length = w11;
2498 Register previous_index_in_bytes = w12;
2499 Register start = x13;
2501 // Load start of the subject string.
2502 __ Add(start, subject, SeqString::kHeaderSize - kHeapObjectTag);
2503 // Load the length from the original subject string from the previous stack
2504 // frame. Therefore we have to use fp, which points exactly to two pointer
2505 // sizes below the previous sp. (Because creating a new stack frame pushes
2506 // the previous fp onto the stack and decrements sp by 2 * kPointerSize.)
2507 __ Ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
2508 __ Ldr(length, UntagSmiFieldMemOperand(subject, String::kLengthOffset));
2510 // Handle UC16 encoding, two bytes make one character.
2511 // string_encoding: if Latin1: 0x04
2513 STATIC_ASSERT(kStringEncodingMask == 0x04);
2514 __ Ubfx(string_encoding, string_encoding, 2, 1);
2515 __ Eor(string_encoding, string_encoding, 1);
2516 // string_encoding: if Latin1: 0
2519 // Convert string positions from characters to bytes.
2520 // Previous index is in x1.
2521 __ Lsl(previous_index_in_bytes, w1, string_encoding);
2522 __ Lsl(length, length, string_encoding);
2523 __ Lsl(sliced_string_offset, sliced_string_offset, string_encoding);
2525 // Argument 1 (x0): Subject string.
2526 __ Mov(x0, subject);
2528 // Argument 2 (x1): Previous index, already there.
2530 // Argument 3 (x2): Get the start of input.
2531 // Start of input = start of string + previous index + substring offset
2534 __ Add(w10, previous_index_in_bytes, sliced_string_offset);
2535 __ Add(x2, start, Operand(w10, UXTW));
2538 // End of input = start of input + (length of input - previous index)
2539 __ Sub(w10, length, previous_index_in_bytes);
2540 __ Add(x3, x2, Operand(w10, UXTW));
2542 // Argument 5 (x4): static offsets vector buffer.
2543 __ Mov(x4, ExternalReference::address_of_static_offsets_vector(isolate()));
2545 // Argument 6 (x5): Set the number of capture registers to zero to force
2546 // global regexps to behave as non-global. This stub is not used for global
2550 // Argument 7 (x6): Start (high end) of backtracking stack memory area.
2551 __ Mov(x10, address_of_regexp_stack_memory_address);
2552 __ Ldr(x10, MemOperand(x10));
2553 __ Mov(x11, address_of_regexp_stack_memory_size);
2554 __ Ldr(x11, MemOperand(x11));
2555 __ Add(x6, x10, x11);
2557 // Argument 8 (x7): Indicate that this is a direct call from JavaScript.
2560 // Locate the code entry and call it.
2561 __ Add(code_object, code_object, Code::kHeaderSize - kHeapObjectTag);
2562 DirectCEntryStub stub(isolate());
2563 stub.GenerateCall(masm, code_object);
2565 __ LeaveExitFrame(false, x10, true);
2567 // The generated regexp code returns an int32 in w0.
2568 Label failure, exception;
2569 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::FAILURE, eq, &failure);
2570 __ CompareAndBranch(w0,
2571 NativeRegExpMacroAssembler::EXCEPTION,
2574 __ CompareAndBranch(w0, NativeRegExpMacroAssembler::RETRY, eq, &runtime);
2576 // Success: process the result from the native regexp code.
2577 Register number_of_capture_registers = x12;
2579 // Calculate number of capture registers (number_of_captures + 1) * 2
2580 // and store it in the last match info.
2582 UntagSmiFieldMemOperand(regexp_data,
2583 JSRegExp::kIrregexpCaptureCountOffset));
2584 __ Add(x10, x10, x10);
2585 __ Add(number_of_capture_registers, x10, 2);
2587 // Check that the fourth object is a JSArray object.
2588 DCHECK(jssp.Is(__ StackPointer()));
2589 __ Peek(x10, kLastMatchInfoOffset);
2590 __ JumpIfSmi(x10, &runtime);
2591 __ JumpIfNotObjectType(x10, x11, x11, JS_ARRAY_TYPE, &runtime);
2593 // Check that the JSArray is the fast case.
2594 __ Ldr(last_match_info_elements,
2595 FieldMemOperand(x10, JSArray::kElementsOffset));
2597 FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
2598 __ JumpIfNotRoot(x10, Heap::kFixedArrayMapRootIndex, &runtime);
2600 // Check that the last match info has space for the capture registers and the
2601 // additional information (overhead).
2602 // (number_of_captures + 1) * 2 + overhead <= last match info size
2603 // (number_of_captures * 2) + 2 + overhead <= last match info size
2604 // number_of_capture_registers + overhead <= last match info size
2606 UntagSmiFieldMemOperand(last_match_info_elements,
2607 FixedArray::kLengthOffset));
2608 __ Add(x11, number_of_capture_registers, RegExpImpl::kLastMatchOverhead);
2612 // Store the capture count.
2613 __ SmiTag(x10, number_of_capture_registers);
2615 FieldMemOperand(last_match_info_elements,
2616 RegExpImpl::kLastCaptureCountOffset));
2617 // Store last subject and last input.
2619 FieldMemOperand(last_match_info_elements,
2620 RegExpImpl::kLastSubjectOffset));
2621 // Use x10 as the subject string in order to only need
2622 // one RecordWriteStub.
2623 __ Mov(x10, subject);
2624 __ RecordWriteField(last_match_info_elements,
2625 RegExpImpl::kLastSubjectOffset,
2631 FieldMemOperand(last_match_info_elements,
2632 RegExpImpl::kLastInputOffset));
2633 __ Mov(x10, subject);
2634 __ RecordWriteField(last_match_info_elements,
2635 RegExpImpl::kLastInputOffset,
2641 Register last_match_offsets = x13;
2642 Register offsets_vector_index = x14;
2643 Register current_offset = x15;
2645 // Get the static offsets vector filled by the native regexp code
2646 // and fill the last match info.
2647 ExternalReference address_of_static_offsets_vector =
2648 ExternalReference::address_of_static_offsets_vector(isolate());
2649 __ Mov(offsets_vector_index, address_of_static_offsets_vector);
2651 Label next_capture, done;
2652 // Capture register counter starts from number of capture registers and
2653 // iterates down to zero (inclusive).
2654 __ Add(last_match_offsets,
2655 last_match_info_elements,
2656 RegExpImpl::kFirstCaptureOffset - kHeapObjectTag);
2657 __ Bind(&next_capture);
2658 __ Subs(number_of_capture_registers, number_of_capture_registers, 2);
2660 // Read two 32 bit values from the static offsets vector buffer into
2662 __ Ldr(current_offset,
2663 MemOperand(offsets_vector_index, kWRegSize * 2, PostIndex));
2664 // Store the smi values in the last match info.
2665 __ SmiTag(x10, current_offset);
2666 // Clearing the 32 bottom bits gives us a Smi.
2667 STATIC_ASSERT(kSmiTag == 0);
2668 __ Bic(x11, current_offset, kSmiShiftMask);
2671 MemOperand(last_match_offsets, kXRegSize * 2, PostIndex));
2672 __ B(&next_capture);
2675 // Return last match info.
2676 __ Peek(x0, kLastMatchInfoOffset);
2677 // Drop the 4 arguments of the stub from the stack.
2681 __ Bind(&exception);
2682 Register exception_value = x0;
2683 // A stack overflow (on the backtrack stack) may have occured
2684 // in the RegExp code but no exception has been created yet.
2685 // If there is no pending exception, handle that in the runtime system.
2686 __ Mov(x10, Operand(isolate()->factory()->the_hole_value()));
2688 Operand(ExternalReference(Isolate::kPendingExceptionAddress,
2690 __ Ldr(exception_value, MemOperand(x11));
2691 __ Cmp(x10, exception_value);
2694 // For exception, throw the exception again.
2695 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
2698 __ Mov(x0, Operand(isolate()->factory()->null_value()));
2699 // Drop the 4 arguments of the stub from the stack.
2704 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
2706 // Deferred code for string handling.
2707 // (6) Not a long external string? If yes, go to (8).
2708 __ Bind(¬_seq_nor_cons);
2709 // Compare flags are still set.
2710 __ B(ne, ¬_long_external); // Go to (8).
2712 // (7) External string. Make it, offset-wise, look like a sequential string.
2713 __ Bind(&external_string);
2714 if (masm->emit_debug_code()) {
2715 // Assert that we do not have a cons or slice (indirect strings) here.
2716 // Sequential strings have already been ruled out.
2717 __ Ldr(x10, FieldMemOperand(subject, HeapObject::kMapOffset));
2718 __ Ldrb(x10, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2719 __ Tst(x10, kIsIndirectStringMask);
2720 __ Check(eq, kExternalStringExpectedButNotFound);
2721 __ And(x10, x10, kStringRepresentationMask);
2723 __ Check(ne, kExternalStringExpectedButNotFound);
2726 FieldMemOperand(subject, ExternalString::kResourceDataOffset));
2727 // Move the pointer so that offset-wise, it looks like a sequential string.
2728 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2729 __ Sub(subject, subject, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2730 __ B(&seq_string); // Go to (5).
2732 // (8) If this is a short external string or not a string, bail out to
2734 __ Bind(¬_long_external);
2735 STATIC_ASSERT(kShortExternalStringTag != 0);
2736 __ TestAndBranchIfAnySet(string_representation,
2737 kShortExternalStringMask | kIsNotStringMask,
2740 // (9) Sliced string. Replace subject with parent.
2741 __ Ldr(sliced_string_offset,
2742 UntagSmiFieldMemOperand(subject, SlicedString::kOffsetOffset));
2743 __ Ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2744 __ B(&check_underlying); // Go to (4).
2749 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub,
2750 Register argc, Register function,
2751 Register feedback_vector,
2753 FrameScope scope(masm, StackFrame::INTERNAL);
2755 // Number-of-arguments register must be smi-tagged to call out.
2757 __ Push(argc, function, feedback_vector, index);
2759 DCHECK(feedback_vector.Is(x2) && index.Is(x3));
2762 __ Pop(index, feedback_vector, function, argc);
2767 static void GenerateRecordCallTarget(MacroAssembler* masm, Register argc,
2769 Register feedback_vector, Register index,
2770 Register scratch1, Register scratch2,
2771 Register scratch3) {
2772 ASM_LOCATION("GenerateRecordCallTarget");
2773 DCHECK(!AreAliased(scratch1, scratch2, scratch3, argc, function,
2774 feedback_vector, index));
2775 // Cache the called function in a feedback vector slot. Cache states are
2776 // uninitialized, monomorphic (indicated by a JSFunction), and megamorphic.
2777 // argc : number of arguments to the construct function
2778 // function : the function to call
2779 // feedback_vector : the feedback vector
2780 // index : slot in feedback vector (smi)
2781 Label initialize, done, miss, megamorphic, not_array_function;
2783 DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
2784 masm->isolate()->heap()->megamorphic_symbol());
2785 DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
2786 masm->isolate()->heap()->uninitialized_symbol());
2788 // Load the cache state.
2789 Register feedback = scratch1;
2790 Register feedback_map = scratch2;
2791 Register feedback_value = scratch3;
2792 __ Add(feedback, feedback_vector,
2793 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2794 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
2796 // A monomorphic cache hit or an already megamorphic state: invoke the
2797 // function without changing the state.
2798 // We don't know if feedback value is a WeakCell or a Symbol, but it's
2799 // harmless to read at this position in a symbol (see static asserts in
2800 // type-feedback-vector.h).
2801 Label check_allocation_site;
2802 __ Ldr(feedback_value, FieldMemOperand(feedback, WeakCell::kValueOffset));
2803 __ Cmp(function, feedback_value);
2805 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
2807 __ Ldr(feedback_map, FieldMemOperand(feedback, HeapObject::kMapOffset));
2808 __ CompareRoot(feedback_map, Heap::kWeakCellMapRootIndex);
2809 __ B(ne, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
2811 // If the weak cell is cleared, we have a new chance to become monomorphic.
2812 __ JumpIfSmi(feedback_value, &initialize);
2815 if (!FLAG_pretenuring_call_new) {
2816 __ bind(&check_allocation_site);
2817 // If we came here, we need to see if we are the array function.
2818 // If we didn't have a matching function, and we didn't find the megamorph
2819 // sentinel, then we have in the slot either some other function or an
2821 __ JumpIfNotRoot(feedback_map, Heap::kAllocationSiteMapRootIndex, &miss);
2823 // Make sure the function is the Array() function
2824 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2825 __ Cmp(function, scratch1);
2826 __ B(ne, &megamorphic);
2832 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
2834 __ JumpIfRoot(scratch1, Heap::kuninitialized_symbolRootIndex, &initialize);
2835 // MegamorphicSentinel is an immortal immovable object (undefined) so no
2836 // write-barrier is needed.
2837 __ Bind(&megamorphic);
2838 __ Add(scratch1, feedback_vector,
2839 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
2840 __ LoadRoot(scratch2, Heap::kmegamorphic_symbolRootIndex);
2841 __ Str(scratch2, FieldMemOperand(scratch1, FixedArray::kHeaderSize));
2844 // An uninitialized cache is patched with the function or sentinel to
2845 // indicate the ElementsKind if function is the Array constructor.
2846 __ Bind(&initialize);
2848 if (!FLAG_pretenuring_call_new) {
2849 // Make sure the function is the Array() function
2850 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch1);
2851 __ Cmp(function, scratch1);
2852 __ B(ne, ¬_array_function);
2854 // The target function is the Array constructor,
2855 // Create an AllocationSite if we don't already have it, store it in the
2857 CreateAllocationSiteStub create_stub(masm->isolate());
2858 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2859 feedback_vector, index);
2862 __ Bind(¬_array_function);
2865 CreateWeakCellStub create_stub(masm->isolate());
2866 CallStubInRecordCallTarget(masm, &create_stub, argc, function,
2867 feedback_vector, index);
2872 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
2873 // Do not transform the receiver for strict mode functions.
2874 __ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
2875 __ Ldr(w4, FieldMemOperand(x3, SharedFunctionInfo::kCompilerHintsOffset));
2876 __ Tbnz(w4, SharedFunctionInfo::kStrictModeFunction, cont);
2878 // Do not transform the receiver for native (Compilerhints already in x3).
2879 __ Tbnz(w4, SharedFunctionInfo::kNative, cont);
2883 static void EmitSlowCase(MacroAssembler* masm,
2887 Label* non_function) {
2888 // Check for function proxy.
2889 // x10 : function type.
2890 __ CompareAndBranch(type, JS_FUNCTION_PROXY_TYPE, ne, non_function);
2891 __ Push(function); // put proxy as additional argument
2892 __ Mov(x0, argc + 1);
2894 __ GetBuiltinFunction(x1, Builtins::CALL_FUNCTION_PROXY);
2896 Handle<Code> adaptor =
2897 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
2898 __ Jump(adaptor, RelocInfo::CODE_TARGET);
2901 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
2902 // of the original receiver from the call site).
2903 __ Bind(non_function);
2904 __ Poke(function, argc * kXRegSize);
2905 __ Mov(x0, argc); // Set up the number of arguments.
2907 __ GetBuiltinFunction(function, Builtins::CALL_NON_FUNCTION);
2908 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
2909 RelocInfo::CODE_TARGET);
2913 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
2914 // Wrap the receiver and patch it back onto the stack.
2915 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
2917 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
2920 __ Poke(x0, argc * kPointerSize);
2925 static void CallFunctionNoFeedback(MacroAssembler* masm,
2926 int argc, bool needs_checks,
2927 bool call_as_method) {
2928 // x1 function the function to call
2929 Register function = x1;
2931 Label slow, non_function, wrap, cont;
2933 // TODO(jbramley): This function has a lot of unnamed registers. Name them,
2934 // and tidy things up a bit.
2937 // Check that the function is really a JavaScript function.
2938 __ JumpIfSmi(function, &non_function);
2940 // Goto slow case if we do not have a function.
2941 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
2944 // Fast-case: Invoke the function now.
2945 // x1 function pushed function
2946 ParameterCount actual(argc);
2948 if (call_as_method) {
2950 EmitContinueIfStrictOrNative(masm, &cont);
2953 // Compute the receiver in sloppy mode.
2954 __ Peek(x3, argc * kPointerSize);
2957 __ JumpIfSmi(x3, &wrap);
2958 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
2966 __ InvokeFunction(function,
2971 // Slow-case: Non-function called.
2973 EmitSlowCase(masm, argc, function, type, &non_function);
2976 if (call_as_method) {
2978 EmitWrapCase(masm, argc, &cont);
2983 void CallFunctionStub::Generate(MacroAssembler* masm) {
2984 ASM_LOCATION("CallFunctionStub::Generate");
2985 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
2989 void CallConstructStub::Generate(MacroAssembler* masm) {
2990 ASM_LOCATION("CallConstructStub::Generate");
2991 // x0 : number of arguments
2992 // x1 : the function to call
2993 // x2 : feedback vector
2994 // x3 : slot in feedback vector (Smi, for RecordCallTarget)
2995 // x4 : original constructor (for IsSuperConstructorCall)
2996 Register function = x1;
2997 Label slow, non_function_call;
2999 // Check that the function is not a smi.
3000 __ JumpIfSmi(function, &non_function_call);
3001 // Check that the function is a JSFunction.
3002 Register object_type = x10;
3003 __ JumpIfNotObjectType(function, object_type, object_type, JS_FUNCTION_TYPE,
3006 if (RecordCallTarget()) {
3007 if (IsSuperConstructorCall()) {
3010 // TODO(mstarzinger): Consider tweaking target recording to avoid push/pop.
3011 GenerateRecordCallTarget(masm, x0, function, x2, x3, x4, x5, x11);
3012 if (IsSuperConstructorCall()) {
3016 __ Add(x5, x2, Operand::UntagSmiAndScale(x3, kPointerSizeLog2));
3017 if (FLAG_pretenuring_call_new) {
3018 // Put the AllocationSite from the feedback vector into x2.
3019 // By adding kPointerSize we encode that we know the AllocationSite
3020 // entry is at the feedback vector slot given by x3 + 1.
3021 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize + kPointerSize));
3023 Label feedback_register_initialized;
3024 // Put the AllocationSite from the feedback vector into x2, or undefined.
3025 __ Ldr(x2, FieldMemOperand(x5, FixedArray::kHeaderSize));
3026 __ Ldr(x5, FieldMemOperand(x2, AllocationSite::kMapOffset));
3027 __ JumpIfRoot(x5, Heap::kAllocationSiteMapRootIndex,
3028 &feedback_register_initialized);
3029 __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
3030 __ bind(&feedback_register_initialized);
3033 __ AssertUndefinedOrAllocationSite(x2, x5);
3036 if (IsSuperConstructorCall()) {
3039 __ Mov(x3, function);
3042 // Jump to the function-specific construct stub.
3043 Register jump_reg = x4;
3044 Register shared_func_info = jump_reg;
3045 Register cons_stub = jump_reg;
3046 Register cons_stub_code = jump_reg;
3047 __ Ldr(shared_func_info,
3048 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
3050 FieldMemOperand(shared_func_info,
3051 SharedFunctionInfo::kConstructStubOffset));
3052 __ Add(cons_stub_code, cons_stub, Code::kHeaderSize - kHeapObjectTag);
3053 __ Br(cons_stub_code);
3057 __ Cmp(object_type, JS_FUNCTION_PROXY_TYPE);
3058 __ B(ne, &non_function_call);
3059 __ GetBuiltinFunction(x1, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
3062 __ Bind(&non_function_call);
3063 __ GetBuiltinFunction(x1, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
3066 // Set expected number of arguments to zero (not changing x0).
3068 __ Jump(isolate()->builtins()->ArgumentsAdaptorTrampoline(),
3069 RelocInfo::CODE_TARGET);
3073 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
3074 __ Ldr(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
3075 __ Ldr(vector, FieldMemOperand(vector,
3076 JSFunction::kSharedFunctionInfoOffset));
3077 __ Ldr(vector, FieldMemOperand(vector,
3078 SharedFunctionInfo::kFeedbackVectorOffset));
3082 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
3087 Register function = x1;
3088 Register feedback_vector = x2;
3089 Register index = x3;
3090 Register scratch = x4;
3092 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, scratch);
3093 __ Cmp(function, scratch);
3096 __ Mov(x0, Operand(arg_count()));
3098 __ Add(scratch, feedback_vector,
3099 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3100 __ Ldr(scratch, FieldMemOperand(scratch, FixedArray::kHeaderSize));
3102 // Verify that scratch contains an AllocationSite
3104 __ Ldr(map, FieldMemOperand(scratch, HeapObject::kMapOffset));
3105 __ JumpIfNotRoot(map, Heap::kAllocationSiteMapRootIndex, &miss);
3107 // Increment the call count for monomorphic function calls.
3108 __ Add(feedback_vector, feedback_vector,
3109 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3110 __ Add(feedback_vector, feedback_vector,
3111 Operand(FixedArray::kHeaderSize + kPointerSize));
3112 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
3113 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3114 __ Str(index, FieldMemOperand(feedback_vector, 0));
3116 Register allocation_site = feedback_vector;
3117 Register original_constructor = index;
3118 __ Mov(allocation_site, scratch);
3119 __ Mov(original_constructor, function);
3120 ArrayConstructorStub stub(masm->isolate(), arg_count());
3121 __ TailCallStub(&stub);
3126 // The slow case, we need this no matter what to complete a call after a miss.
3127 CallFunctionNoFeedback(masm,
3136 void CallICStub::Generate(MacroAssembler* masm) {
3137 ASM_LOCATION("CallICStub");
3140 // x3 - slot id (Smi)
3142 const int with_types_offset =
3143 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
3144 const int generic_offset =
3145 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
3146 Label extra_checks_or_miss, slow_start;
3147 Label slow, non_function, wrap, cont;
3148 Label have_js_function;
3149 int argc = arg_count();
3150 ParameterCount actual(argc);
3152 Register function = x1;
3153 Register feedback_vector = x2;
3154 Register index = x3;
3157 // The checks. First, does x1 match the recorded monomorphic target?
3158 __ Add(x4, feedback_vector,
3159 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3160 __ Ldr(x4, FieldMemOperand(x4, FixedArray::kHeaderSize));
3162 // We don't know that we have a weak cell. We might have a private symbol
3163 // or an AllocationSite, but the memory is safe to examine.
3164 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
3166 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
3167 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
3168 // computed, meaning that it can't appear to be a pointer. If the low bit is
3169 // 0, then hash is computed, but the 0 bit prevents the field from appearing
3171 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
3172 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
3173 WeakCell::kValueOffset &&
3174 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
3176 __ Ldr(x5, FieldMemOperand(x4, WeakCell::kValueOffset));
3177 __ Cmp(x5, function);
3178 __ B(ne, &extra_checks_or_miss);
3180 // The compare above could have been a SMI/SMI comparison. Guard against this
3181 // convincing us that we have a monomorphic JSFunction.
3182 __ JumpIfSmi(function, &extra_checks_or_miss);
3184 // Increment the call count for monomorphic function calls.
3185 __ Add(feedback_vector, feedback_vector,
3186 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3187 __ Add(feedback_vector, feedback_vector,
3188 Operand(FixedArray::kHeaderSize + kPointerSize));
3189 __ Ldr(index, FieldMemOperand(feedback_vector, 0));
3190 __ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
3191 __ Str(index, FieldMemOperand(feedback_vector, 0));
3193 __ bind(&have_js_function);
3194 if (CallAsMethod()) {
3195 EmitContinueIfStrictOrNative(masm, &cont);
3197 // Compute the receiver in sloppy mode.
3198 __ Peek(x3, argc * kPointerSize);
3200 __ JumpIfSmi(x3, &wrap);
3201 __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
3206 __ InvokeFunction(function,
3212 EmitSlowCase(masm, argc, function, type, &non_function);
3214 if (CallAsMethod()) {
3216 EmitWrapCase(masm, argc, &cont);
3219 __ bind(&extra_checks_or_miss);
3220 Label uninitialized, miss;
3222 __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &slow_start);
3224 // The following cases attempt to handle MISS cases without going to the
3226 if (FLAG_trace_ic) {
3230 __ JumpIfRoot(x4, Heap::kuninitialized_symbolRootIndex, &miss);
3232 // We are going megamorphic. If the feedback is a JSFunction, it is fine
3233 // to handle it here. More complex cases are dealt with in the runtime.
3234 __ AssertNotSmi(x4);
3235 __ JumpIfNotObjectType(x4, x5, x5, JS_FUNCTION_TYPE, &miss);
3236 __ Add(x4, feedback_vector,
3237 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3238 __ LoadRoot(x5, Heap::kmegamorphic_symbolRootIndex);
3239 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize));
3240 // We have to update statistics for runtime profiling.
3241 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3242 __ Subs(x4, x4, Operand(Smi::FromInt(1)));
3243 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3244 __ Ldr(x4, FieldMemOperand(feedback_vector, generic_offset));
3245 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3246 __ Str(x4, FieldMemOperand(feedback_vector, generic_offset));
3249 __ bind(&uninitialized);
3251 // We are going monomorphic, provided we actually have a JSFunction.
3252 __ JumpIfSmi(function, &miss);
3254 // Goto miss case if we do not have a function.
3255 __ JumpIfNotObjectType(function, x5, x5, JS_FUNCTION_TYPE, &miss);
3257 // Make sure the function is not the Array() function, which requires special
3258 // behavior on MISS.
3259 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, x5);
3260 __ Cmp(function, x5);
3264 __ Ldr(x4, FieldMemOperand(feedback_vector, with_types_offset));
3265 __ Adds(x4, x4, Operand(Smi::FromInt(1)));
3266 __ Str(x4, FieldMemOperand(feedback_vector, with_types_offset));
3268 // Initialize the call counter.
3269 __ Mov(x5, Smi::FromInt(CallICNexus::kCallCountIncrement));
3270 __ Adds(x4, feedback_vector,
3271 Operand::UntagSmiAndScale(index, kPointerSizeLog2));
3272 __ Str(x5, FieldMemOperand(x4, FixedArray::kHeaderSize + kPointerSize));
3274 // Store the function. Use a stub since we need a frame for allocation.
3279 FrameScope scope(masm, StackFrame::INTERNAL);
3280 CreateWeakCellStub create_stub(masm->isolate());
3282 __ CallStub(&create_stub);
3286 __ B(&have_js_function);
3288 // We are here because tracing is on or we encountered a MISS case we can't
3294 __ bind(&slow_start);
3296 // Check that the function is really a JavaScript function.
3297 __ JumpIfSmi(function, &non_function);
3299 // Goto slow case if we do not have a function.
3300 __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
3301 __ B(&have_js_function);
3305 void CallICStub::GenerateMiss(MacroAssembler* masm) {
3306 ASM_LOCATION("CallICStub[Miss]");
3308 FrameScope scope(masm, StackFrame::INTERNAL);
3310 // Push the receiver and the function and feedback info.
3311 __ Push(x1, x2, x3);
3314 IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
3315 : IC::kCallIC_Customization_Miss;
3317 ExternalReference miss = ExternalReference(IC_Utility(id), masm->isolate());
3318 __ CallExternalReference(miss, 3);
3320 // Move result to edi and exit the internal frame.
3325 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
3326 // If the receiver is a smi trigger the non-string case.
3327 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
3328 __ JumpIfSmi(object_, receiver_not_string_);
3330 // Fetch the instance type of the receiver into result register.
3331 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3332 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3334 // If the receiver is not a string trigger the non-string case.
3335 __ TestAndBranchIfAnySet(result_, kIsNotStringMask, receiver_not_string_);
3338 // If the index is non-smi trigger the non-smi case.
3339 __ JumpIfNotSmi(index_, &index_not_smi_);
3341 __ Bind(&got_smi_index_);
3342 // Check for index out of range.
3343 __ Ldrsw(result_, UntagSmiFieldMemOperand(object_, String::kLengthOffset));
3344 __ Cmp(result_, Operand::UntagSmi(index_));
3345 __ B(ls, index_out_of_range_);
3347 __ SmiUntag(index_);
3349 StringCharLoadGenerator::Generate(masm,
3359 void StringCharCodeAtGenerator::GenerateSlow(
3360 MacroAssembler* masm, EmbedMode embed_mode,
3361 const RuntimeCallHelper& call_helper) {
3362 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
3364 __ Bind(&index_not_smi_);
3365 // If index is a heap number, try converting it to an integer.
3366 __ JumpIfNotHeapNumber(index_, index_not_number_);
3367 call_helper.BeforeCall(masm);
3368 if (embed_mode == PART_OF_IC_HANDLER) {
3369 __ Push(LoadWithVectorDescriptor::VectorRegister(),
3370 LoadWithVectorDescriptor::SlotRegister(), object_, index_);
3372 // Save object_ on the stack and pass index_ as argument for runtime call.
3373 __ Push(object_, index_);
3375 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
3376 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
3378 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
3379 // NumberToSmi discards numbers that are not exact integers.
3380 __ CallRuntime(Runtime::kNumberToSmi, 1);
3382 // Save the conversion result before the pop instructions below
3383 // have a chance to overwrite it.
3385 if (embed_mode == PART_OF_IC_HANDLER) {
3386 __ Pop(object_, LoadWithVectorDescriptor::SlotRegister(),
3387 LoadWithVectorDescriptor::VectorRegister());
3391 // Reload the instance type.
3392 __ Ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
3393 __ Ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
3394 call_helper.AfterCall(masm);
3396 // If index is still not a smi, it must be out of range.
3397 __ JumpIfNotSmi(index_, index_out_of_range_);
3398 // Otherwise, return to the fast path.
3399 __ B(&got_smi_index_);
3401 // Call runtime. We get here when the receiver is a string and the
3402 // index is a number, but the code of getting the actual character
3403 // is too complex (e.g., when the string needs to be flattened).
3404 __ Bind(&call_runtime_);
3405 call_helper.BeforeCall(masm);
3407 __ Push(object_, index_);
3408 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
3409 __ Mov(result_, x0);
3410 call_helper.AfterCall(masm);
3413 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
3417 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
3418 __ JumpIfNotSmi(code_, &slow_case_);
3419 __ Cmp(code_, Smi::FromInt(String::kMaxOneByteCharCode));
3420 __ B(hi, &slow_case_);
3422 __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
3423 // At this point code register contains smi tagged one-byte char code.
3424 __ Add(result_, result_, Operand::UntagSmiAndScale(code_, kPointerSizeLog2));
3425 __ Ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
3426 __ JumpIfRoot(result_, Heap::kUndefinedValueRootIndex, &slow_case_);
3431 void StringCharFromCodeGenerator::GenerateSlow(
3432 MacroAssembler* masm,
3433 const RuntimeCallHelper& call_helper) {
3434 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
3436 __ Bind(&slow_case_);
3437 call_helper.BeforeCall(masm);
3439 __ CallRuntime(Runtime::kCharFromCode, 1);
3440 __ Mov(result_, x0);
3441 call_helper.AfterCall(masm);
3444 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
3448 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3449 // Inputs are in x0 (lhs) and x1 (rhs).
3450 DCHECK(state() == CompareICState::SMI);
3451 ASM_LOCATION("CompareICStub[Smis]");
3453 // Bail out (to 'miss') unless both x0 and x1 are smis.
3454 __ JumpIfEitherNotSmi(x0, x1, &miss);
3456 if (GetCondition() == eq) {
3457 // For equality we do not care about the sign of the result.
3460 // Untag before subtracting to avoid handling overflow.
3462 __ Sub(x0, x1, Operand::UntagSmi(x0));
3471 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3472 DCHECK(state() == CompareICState::NUMBER);
3473 ASM_LOCATION("CompareICStub[HeapNumbers]");
3475 Label unordered, maybe_undefined1, maybe_undefined2;
3476 Label miss, handle_lhs, values_in_d_regs;
3477 Label untag_rhs, untag_lhs;
3479 Register result = x0;
3482 FPRegister rhs_d = d0;
3483 FPRegister lhs_d = d1;
3485 if (left() == CompareICState::SMI) {
3486 __ JumpIfNotSmi(lhs, &miss);
3488 if (right() == CompareICState::SMI) {
3489 __ JumpIfNotSmi(rhs, &miss);
3492 __ SmiUntagToDouble(rhs_d, rhs, kSpeculativeUntag);
3493 __ SmiUntagToDouble(lhs_d, lhs, kSpeculativeUntag);
3495 // Load rhs if it's a heap number.
3496 __ JumpIfSmi(rhs, &handle_lhs);
3497 __ JumpIfNotHeapNumber(rhs, &maybe_undefined1);
3498 __ Ldr(rhs_d, FieldMemOperand(rhs, HeapNumber::kValueOffset));
3500 // Load lhs if it's a heap number.
3501 __ Bind(&handle_lhs);
3502 __ JumpIfSmi(lhs, &values_in_d_regs);
3503 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3504 __ Ldr(lhs_d, FieldMemOperand(lhs, HeapNumber::kValueOffset));
3506 __ Bind(&values_in_d_regs);
3507 __ Fcmp(lhs_d, rhs_d);
3508 __ B(vs, &unordered); // Overflow flag set if either is NaN.
3509 STATIC_ASSERT((LESS == -1) && (EQUAL == 0) && (GREATER == 1));
3510 __ Cset(result, gt); // gt => 1, otherwise (lt, eq) => 0 (EQUAL).
3511 __ Csinv(result, result, xzr, ge); // lt => -1, gt => 1, eq => 0.
3514 __ Bind(&unordered);
3515 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3516 CompareICState::GENERIC, CompareICState::GENERIC);
3517 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
3519 __ Bind(&maybe_undefined1);
3520 if (Token::IsOrderedRelationalCompareOp(op())) {
3521 __ JumpIfNotRoot(rhs, Heap::kUndefinedValueRootIndex, &miss);
3522 __ JumpIfSmi(lhs, &unordered);
3523 __ JumpIfNotHeapNumber(lhs, &maybe_undefined2);
3527 __ Bind(&maybe_undefined2);
3528 if (Token::IsOrderedRelationalCompareOp(op())) {
3529 __ JumpIfRoot(lhs, Heap::kUndefinedValueRootIndex, &unordered);
3537 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3538 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3539 ASM_LOCATION("CompareICStub[InternalizedStrings]");
3542 Register result = x0;
3546 // Check that both operands are heap objects.
3547 __ JumpIfEitherSmi(lhs, rhs, &miss);
3549 // Check that both operands are internalized strings.
3550 Register rhs_map = x10;
3551 Register lhs_map = x11;
3552 Register rhs_type = x10;
3553 Register lhs_type = x11;
3554 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3555 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3556 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3557 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3559 STATIC_ASSERT((kInternalizedTag == 0) && (kStringTag == 0));
3560 __ Orr(x12, lhs_type, rhs_type);
3561 __ TestAndBranchIfAnySet(
3562 x12, kIsNotStringMask | kIsNotInternalizedMask, &miss);
3564 // Internalized strings are compared by identity.
3565 STATIC_ASSERT(EQUAL == 0);
3567 __ Cset(result, ne);
3575 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3576 DCHECK(state() == CompareICState::UNIQUE_NAME);
3577 ASM_LOCATION("CompareICStub[UniqueNames]");
3578 DCHECK(GetCondition() == eq);
3581 Register result = x0;
3585 Register lhs_instance_type = w2;
3586 Register rhs_instance_type = w3;
3588 // Check that both operands are heap objects.
3589 __ JumpIfEitherSmi(lhs, rhs, &miss);
3591 // Check that both operands are unique names. This leaves the instance
3592 // types loaded in tmp1 and tmp2.
3593 __ Ldr(x10, FieldMemOperand(lhs, HeapObject::kMapOffset));
3594 __ Ldr(x11, FieldMemOperand(rhs, HeapObject::kMapOffset));
3595 __ Ldrb(lhs_instance_type, FieldMemOperand(x10, Map::kInstanceTypeOffset));
3596 __ Ldrb(rhs_instance_type, FieldMemOperand(x11, Map::kInstanceTypeOffset));
3598 // To avoid a miss, each instance type should be either SYMBOL_TYPE or it
3599 // should have kInternalizedTag set.
3600 __ JumpIfNotUniqueNameInstanceType(lhs_instance_type, &miss);
3601 __ JumpIfNotUniqueNameInstanceType(rhs_instance_type, &miss);
3603 // Unique names are compared by identity.
3604 STATIC_ASSERT(EQUAL == 0);
3606 __ Cset(result, ne);
3614 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3615 DCHECK(state() == CompareICState::STRING);
3616 ASM_LOCATION("CompareICStub[Strings]");
3620 bool equality = Token::IsEqualityOp(op());
3622 Register result = x0;
3626 // Check that both operands are heap objects.
3627 __ JumpIfEitherSmi(rhs, lhs, &miss);
3629 // Check that both operands are strings.
3630 Register rhs_map = x10;
3631 Register lhs_map = x11;
3632 Register rhs_type = x10;
3633 Register lhs_type = x11;
3634 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3635 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3636 __ Ldrb(lhs_type, FieldMemOperand(lhs_map, Map::kInstanceTypeOffset));
3637 __ Ldrb(rhs_type, FieldMemOperand(rhs_map, Map::kInstanceTypeOffset));
3638 STATIC_ASSERT(kNotStringTag != 0);
3639 __ Orr(x12, lhs_type, rhs_type);
3640 __ Tbnz(x12, MaskToBit(kIsNotStringMask), &miss);
3642 // Fast check for identical strings.
3645 __ B(ne, ¬_equal);
3646 __ Mov(result, EQUAL);
3649 __ Bind(¬_equal);
3650 // Handle not identical strings
3652 // Check that both strings are internalized strings. If they are, we're done
3653 // because we already know they are not identical. We know they are both
3656 DCHECK(GetCondition() == eq);
3657 STATIC_ASSERT(kInternalizedTag == 0);
3658 Label not_internalized_strings;
3659 __ Orr(x12, lhs_type, rhs_type);
3660 __ TestAndBranchIfAnySet(
3661 x12, kIsNotInternalizedMask, ¬_internalized_strings);
3662 // Result is in rhs (x0), and not EQUAL, as rhs is not a smi.
3664 __ Bind(¬_internalized_strings);
3667 // Check that both strings are sequential one-byte.
3669 __ JumpIfBothInstanceTypesAreNotSequentialOneByte(lhs_type, rhs_type, x12,
3672 // Compare flat one-byte strings. Returns when done.
3674 StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, x10, x11,
3677 StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, x10, x11,
3681 // Handle more complex cases in runtime.
3685 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3687 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3695 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3696 DCHECK(state() == CompareICState::OBJECT);
3697 ASM_LOCATION("CompareICStub[Objects]");
3701 Register result = x0;
3705 __ JumpIfEitherSmi(rhs, lhs, &miss);
3707 __ JumpIfNotObjectType(rhs, x10, x10, JS_OBJECT_TYPE, &miss);
3708 __ JumpIfNotObjectType(lhs, x10, x10, JS_OBJECT_TYPE, &miss);
3710 DCHECK(GetCondition() == eq);
3711 __ Sub(result, rhs, lhs);
3719 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3720 ASM_LOCATION("CompareICStub[KnownObjects]");
3723 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3725 Register result = x0;
3729 __ JumpIfEitherSmi(rhs, lhs, &miss);
3731 Register rhs_map = x10;
3732 Register lhs_map = x11;
3734 __ GetWeakValue(map, cell);
3735 __ Ldr(rhs_map, FieldMemOperand(rhs, HeapObject::kMapOffset));
3736 __ Ldr(lhs_map, FieldMemOperand(lhs, HeapObject::kMapOffset));
3737 __ Cmp(rhs_map, map);
3739 __ Cmp(lhs_map, map);
3742 __ Sub(result, rhs, lhs);
3750 // This method handles the case where a compare stub had the wrong
3751 // implementation. It calls a miss handler, which re-writes the stub. All other
3752 // CompareICStub::Generate* methods should fall back into this one if their
3753 // operands were not the expected types.
3754 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3755 ASM_LOCATION("CompareICStub[Miss]");
3757 Register stub_entry = x11;
3759 ExternalReference miss =
3760 ExternalReference(IC_Utility(IC::kCompareIC_Miss), isolate());
3762 FrameScope scope(masm, StackFrame::INTERNAL);
3765 Register right = x0;
3766 // Preserve some caller-saved registers.
3767 __ Push(x1, x0, lr);
3768 // Push the arguments.
3769 __ Mov(op, Smi::FromInt(this->op()));
3770 __ Push(left, right, op);
3772 // Call the miss handler. This also pops the arguments.
3773 __ CallExternalReference(miss, 3);
3775 // Compute the entry point of the rewritten stub.
3776 __ Add(stub_entry, x0, Code::kHeaderSize - kHeapObjectTag);
3777 // Restore caller-saved registers.
3781 // Tail-call to the new stub.
3782 __ Jump(stub_entry);
3786 void SubStringStub::Generate(MacroAssembler* masm) {
3787 ASM_LOCATION("SubStringStub::Generate");
3790 // Stack frame on entry.
3791 // lr: return address
3792 // jssp[0]: substring "to" offset
3793 // jssp[8]: substring "from" offset
3794 // jssp[16]: pointer to string object
3796 // This stub is called from the native-call %_SubString(...), so
3797 // nothing can be assumed about the arguments. It is tested that:
3798 // "string" is a sequential string,
3799 // both "from" and "to" are smis, and
3800 // 0 <= from <= to <= string.length (in debug mode.)
3801 // If any of these assumptions fail, we call the runtime system.
3803 static const int kToOffset = 0 * kPointerSize;
3804 static const int kFromOffset = 1 * kPointerSize;
3805 static const int kStringOffset = 2 * kPointerSize;
3808 Register from = x15;
3809 Register input_string = x10;
3810 Register input_length = x11;
3811 Register input_type = x12;
3812 Register result_string = x0;
3813 Register result_length = x1;
3816 __ Peek(to, kToOffset);
3817 __ Peek(from, kFromOffset);
3819 // Check that both from and to are smis. If not, jump to runtime.
3820 __ JumpIfEitherNotSmi(from, to, &runtime);
3824 // Calculate difference between from and to. If to < from, branch to runtime.
3825 __ Subs(result_length, to, from);
3828 // Check from is positive.
3829 __ Tbnz(from, kWSignBit, &runtime);
3831 // Make sure first argument is a string.
3832 __ Peek(input_string, kStringOffset);
3833 __ JumpIfSmi(input_string, &runtime);
3834 __ IsObjectJSStringType(input_string, input_type, &runtime);
3837 __ Cmp(result_length, 1);
3838 __ B(eq, &single_char);
3840 // Short-cut for the case of trivial substring.
3842 __ Ldrsw(input_length,
3843 UntagSmiFieldMemOperand(input_string, String::kLengthOffset));
3845 __ Cmp(result_length, input_length);
3846 __ CmovX(x0, input_string, eq);
3847 // Return original string.
3848 __ B(eq, &return_x0);
3850 // Longer than original string's length or negative: unsafe arguments.
3853 // Shorter than original string's length: an actual substring.
3855 // x0 to substring end character offset
3856 // x1 result_length length of substring result
3857 // x10 input_string pointer to input string object
3858 // x10 unpacked_string pointer to unpacked string object
3859 // x11 input_length length of input string
3860 // x12 input_type instance type of input string
3861 // x15 from substring start character offset
3863 // Deal with different string types: update the index if necessary and put
3864 // the underlying string into register unpacked_string.
3865 Label underlying_unpacked, sliced_string, seq_or_external_string;
3866 Label update_instance_type;
3867 // If the string is not indirect, it can only be sequential or external.
3868 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
3869 STATIC_ASSERT(kIsIndirectStringMask != 0);
3871 // Test for string types, and branch/fall through to appropriate unpacking
3873 __ Tst(input_type, kIsIndirectStringMask);
3874 __ B(eq, &seq_or_external_string);
3875 __ Tst(input_type, kSlicedNotConsMask);
3876 __ B(ne, &sliced_string);
3878 Register unpacked_string = input_string;
3880 // Cons string. Check whether it is flat, then fetch first part.
3881 __ Ldr(temp, FieldMemOperand(input_string, ConsString::kSecondOffset));
3882 __ JumpIfNotRoot(temp, Heap::kempty_stringRootIndex, &runtime);
3883 __ Ldr(unpacked_string,
3884 FieldMemOperand(input_string, ConsString::kFirstOffset));
3885 __ B(&update_instance_type);
3887 __ Bind(&sliced_string);
3888 // Sliced string. Fetch parent and correct start index by offset.
3890 UntagSmiFieldMemOperand(input_string, SlicedString::kOffsetOffset));
3891 __ Add(from, from, temp);
3892 __ Ldr(unpacked_string,
3893 FieldMemOperand(input_string, SlicedString::kParentOffset));
3895 __ Bind(&update_instance_type);
3896 __ Ldr(temp, FieldMemOperand(unpacked_string, HeapObject::kMapOffset));
3897 __ Ldrb(input_type, FieldMemOperand(temp, Map::kInstanceTypeOffset));
3898 // Now control must go to &underlying_unpacked. Since the no code is generated
3899 // before then we fall through instead of generating a useless branch.
3901 __ Bind(&seq_or_external_string);
3902 // Sequential or external string. Registers unpacked_string and input_string
3903 // alias, so there's nothing to do here.
3904 // Note that if code is added here, the above code must be updated.
3906 // x0 result_string pointer to result string object (uninit)
3907 // x1 result_length length of substring result
3908 // x10 unpacked_string pointer to unpacked string object
3909 // x11 input_length length of input string
3910 // x12 input_type instance type of input string
3911 // x15 from substring start character offset
3912 __ Bind(&underlying_unpacked);
3914 if (FLAG_string_slices) {
3916 __ Cmp(result_length, SlicedString::kMinLength);
3917 // Short slice. Copy instead of slicing.
3918 __ B(lt, ©_routine);
3919 // Allocate new sliced string. At this point we do not reload the instance
3920 // type including the string encoding because we simply rely on the info
3921 // provided by the original string. It does not matter if the original
3922 // string's encoding is wrong because we always have to recheck encoding of
3923 // the newly created string's parent anyway due to externalized strings.
3924 Label two_byte_slice, set_slice_header;
3925 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
3926 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
3927 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_slice);
3928 __ AllocateOneByteSlicedString(result_string, result_length, x3, x4,
3930 __ B(&set_slice_header);
3932 __ Bind(&two_byte_slice);
3933 __ AllocateTwoByteSlicedString(result_string, result_length, x3, x4,
3936 __ Bind(&set_slice_header);
3938 __ Str(from, FieldMemOperand(result_string, SlicedString::kOffsetOffset));
3939 __ Str(unpacked_string,
3940 FieldMemOperand(result_string, SlicedString::kParentOffset));
3943 __ Bind(©_routine);
3946 // x0 result_string pointer to result string object (uninit)
3947 // x1 result_length length of substring result
3948 // x10 unpacked_string pointer to unpacked string object
3949 // x11 input_length length of input string
3950 // x12 input_type instance type of input string
3951 // x13 unpacked_char0 pointer to first char of unpacked string (uninit)
3952 // x13 substring_char0 pointer to first char of substring (uninit)
3953 // x14 result_char0 pointer to first char of result (uninit)
3954 // x15 from substring start character offset
3955 Register unpacked_char0 = x13;
3956 Register substring_char0 = x13;
3957 Register result_char0 = x14;
3958 Label two_byte_sequential, sequential_string, allocate_result;
3959 STATIC_ASSERT(kExternalStringTag != 0);
3960 STATIC_ASSERT(kSeqStringTag == 0);
3962 __ Tst(input_type, kExternalStringTag);
3963 __ B(eq, &sequential_string);
3965 __ Tst(input_type, kShortExternalStringTag);
3967 __ Ldr(unpacked_char0,
3968 FieldMemOperand(unpacked_string, ExternalString::kResourceDataOffset));
3969 // unpacked_char0 points to the first character of the underlying string.
3970 __ B(&allocate_result);
3972 __ Bind(&sequential_string);
3973 // Locate first character of underlying subject string.
3974 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
3975 __ Add(unpacked_char0, unpacked_string,
3976 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3978 __ Bind(&allocate_result);
3979 // Sequential one-byte string. Allocate the result.
3980 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
3981 __ Tbz(input_type, MaskToBit(kStringEncodingMask), &two_byte_sequential);
3983 // Allocate and copy the resulting one-byte string.
3984 __ AllocateOneByteString(result_string, result_length, x3, x4, x5, &runtime);
3986 // Locate first character of substring to copy.
3987 __ Add(substring_char0, unpacked_char0, from);
3989 // Locate first character of result.
3990 __ Add(result_char0, result_string,
3991 SeqOneByteString::kHeaderSize - kHeapObjectTag);
3993 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
3994 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
3997 // Allocate and copy the resulting two-byte string.
3998 __ Bind(&two_byte_sequential);
3999 __ AllocateTwoByteString(result_string, result_length, x3, x4, x5, &runtime);
4001 // Locate first character of substring to copy.
4002 __ Add(substring_char0, unpacked_char0, Operand(from, LSL, 1));
4004 // Locate first character of result.
4005 __ Add(result_char0, result_string,
4006 SeqTwoByteString::kHeaderSize - kHeapObjectTag);
4008 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
4009 __ Add(result_length, result_length, result_length);
4010 __ CopyBytes(result_char0, substring_char0, result_length, x3, kCopyLong);
4012 __ Bind(&return_x0);
4013 Counters* counters = isolate()->counters();
4014 __ IncrementCounter(counters->sub_string_native(), 1, x3, x4);
4019 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
4021 __ bind(&single_char);
4022 // x1: result_length
4023 // x10: input_string
4025 // x15: from (untagged)
4027 StringCharAtGenerator generator(input_string, from, result_length, x0,
4028 &runtime, &runtime, &runtime,
4029 STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING);
4030 generator.GenerateFast(masm);
4033 generator.SkipSlow(masm, &runtime);
4037 void ToNumberStub::Generate(MacroAssembler* masm) {
4038 // The ToNumber stub takes one argument in x0.
4040 __ JumpIfNotSmi(x0, ¬_smi);
4044 Label not_heap_number;
4045 __ Ldr(x1, FieldMemOperand(x0, HeapObject::kMapOffset));
4046 __ Ldrb(x1, FieldMemOperand(x1, Map::kInstanceTypeOffset));
4048 // x1: instance type
4049 __ Cmp(x1, HEAP_NUMBER_TYPE);
4050 __ B(ne, ¬_heap_number);
4052 __ Bind(¬_heap_number);
4054 Label not_string, slow_string;
4055 __ Cmp(x1, FIRST_NONSTRING_TYPE);
4056 __ B(hs, ¬_string);
4057 // Check if string has a cached array index.
4058 __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset));
4059 __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask));
4060 __ B(ne, &slow_string);
4061 __ IndexFromHash(x2, x0);
4063 __ Bind(&slow_string);
4064 __ Push(x0); // Push argument.
4065 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
4066 __ Bind(¬_string);
4069 __ Cmp(x1, ODDBALL_TYPE);
4070 __ B(ne, ¬_oddball);
4071 __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset));
4073 __ Bind(¬_oddball);
4075 __ Push(x0); // Push argument.
4076 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
4080 void StringHelper::GenerateFlatOneByteStringEquals(
4081 MacroAssembler* masm, Register left, Register right, Register scratch1,
4082 Register scratch2, Register scratch3) {
4083 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3));
4084 Register result = x0;
4085 Register left_length = scratch1;
4086 Register right_length = scratch2;
4088 // Compare lengths. If lengths differ, strings can't be equal. Lengths are
4089 // smis, and don't need to be untagged.
4090 Label strings_not_equal, check_zero_length;
4091 __ Ldr(left_length, FieldMemOperand(left, String::kLengthOffset));
4092 __ Ldr(right_length, FieldMemOperand(right, String::kLengthOffset));
4093 __ Cmp(left_length, right_length);
4094 __ B(eq, &check_zero_length);
4096 __ Bind(&strings_not_equal);
4097 __ Mov(result, Smi::FromInt(NOT_EQUAL));
4100 // Check if the length is zero. If so, the strings must be equal (and empty.)
4101 Label compare_chars;
4102 __ Bind(&check_zero_length);
4103 STATIC_ASSERT(kSmiTag == 0);
4104 __ Cbnz(left_length, &compare_chars);
4105 __ Mov(result, Smi::FromInt(EQUAL));
4108 // Compare characters. Falls through if all characters are equal.
4109 __ Bind(&compare_chars);
4110 GenerateOneByteCharsCompareLoop(masm, left, right, left_length, scratch2,
4111 scratch3, &strings_not_equal);
4113 // Characters in strings are equal.
4114 __ Mov(result, Smi::FromInt(EQUAL));
4119 void StringHelper::GenerateCompareFlatOneByteStrings(
4120 MacroAssembler* masm, Register left, Register right, Register scratch1,
4121 Register scratch2, Register scratch3, Register scratch4) {
4122 DCHECK(!AreAliased(left, right, scratch1, scratch2, scratch3, scratch4));
4123 Label result_not_equal, compare_lengths;
4125 // Find minimum length and length difference.
4126 Register length_delta = scratch3;
4127 __ Ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
4128 __ Ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
4129 __ Subs(length_delta, scratch1, scratch2);
4131 Register min_length = scratch1;
4132 __ Csel(min_length, scratch2, scratch1, gt);
4133 __ Cbz(min_length, &compare_lengths);
4136 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
4137 scratch4, &result_not_equal);
4139 // Compare lengths - strings up to min-length are equal.
4140 __ Bind(&compare_lengths);
4142 DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
4144 // Use length_delta as result if it's zero.
4145 Register result = x0;
4146 __ Subs(result, length_delta, 0);
4148 __ Bind(&result_not_equal);
4149 Register greater = x10;
4150 Register less = x11;
4151 __ Mov(greater, Smi::FromInt(GREATER));
4152 __ Mov(less, Smi::FromInt(LESS));
4153 __ CmovX(result, greater, gt);
4154 __ CmovX(result, less, lt);
4159 void StringHelper::GenerateOneByteCharsCompareLoop(
4160 MacroAssembler* masm, Register left, Register right, Register length,
4161 Register scratch1, Register scratch2, Label* chars_not_equal) {
4162 DCHECK(!AreAliased(left, right, length, scratch1, scratch2));
4164 // Change index to run from -length to -1 by adding length to string
4165 // start. This means that loop ends when index reaches zero, which
4166 // doesn't need an additional compare.
4167 __ SmiUntag(length);
4168 __ Add(scratch1, length, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4169 __ Add(left, left, scratch1);
4170 __ Add(right, right, scratch1);
4172 Register index = length;
4173 __ Neg(index, length); // index = -length;
4178 __ Ldrb(scratch1, MemOperand(left, index));
4179 __ Ldrb(scratch2, MemOperand(right, index));
4180 __ Cmp(scratch1, scratch2);
4181 __ B(ne, chars_not_equal);
4182 __ Add(index, index, 1);
4183 __ Cbnz(index, &loop);
4187 void StringCompareStub::Generate(MacroAssembler* masm) {
4190 Counters* counters = isolate()->counters();
4192 // Stack frame on entry.
4193 // sp[0]: right string
4194 // sp[8]: left string
4195 Register right = x10;
4196 Register left = x11;
4197 Register result = x0;
4198 __ Pop(right, left);
4201 __ Subs(result, right, left);
4202 __ B(ne, ¬_same);
4203 STATIC_ASSERT(EQUAL == 0);
4204 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4209 // Check that both objects are sequential one-byte strings.
4210 __ JumpIfEitherIsNotSequentialOneByteStrings(left, right, x12, x13, &runtime);
4212 // Compare flat one-byte strings natively. Remove arguments from stack first,
4213 // as this function will generate a return.
4214 __ IncrementCounter(counters->string_compare_native(), 1, x3, x4);
4215 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, x12, x13,
4220 // Push arguments back on to the stack.
4221 // sp[0] = right string
4222 // sp[8] = left string.
4223 __ Push(left, right);
4225 // Call the runtime.
4226 // Returns -1 (less), 0 (equal), or 1 (greater) tagged as a small integer.
4227 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
4231 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4232 // ----------- S t a t e -------------
4235 // -- lr : return address
4236 // -----------------------------------
4238 // Load x2 with the allocation site. We stick an undefined dummy value here
4239 // and replace it with the real allocation site later when we instantiate this
4240 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
4241 __ LoadObject(x2, handle(isolate()->heap()->undefined_value()));
4243 // Make sure that we actually patched the allocation site.
4244 if (FLAG_debug_code) {
4245 __ AssertNotSmi(x2, kExpectedAllocationSite);
4246 __ Ldr(x10, FieldMemOperand(x2, HeapObject::kMapOffset));
4247 __ AssertRegisterIsRoot(x10, Heap::kAllocationSiteMapRootIndex,
4248 kExpectedAllocationSite);
4251 // Tail call into the stub that handles binary operations with allocation
4253 BinaryOpWithAllocationSiteStub stub(isolate(), state());
4254 __ TailCallStub(&stub);
4258 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
4259 // We need some extra registers for this stub, they have been allocated
4260 // but we need to save them before using them.
4263 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4264 Label dont_need_remembered_set;
4266 Register val = regs_.scratch0();
4267 __ Ldr(val, MemOperand(regs_.address()));
4268 __ JumpIfNotInNewSpace(val, &dont_need_remembered_set);
4270 __ CheckPageFlagSet(regs_.object(), val, 1 << MemoryChunk::SCAN_ON_SCAVENGE,
4271 &dont_need_remembered_set);
4273 // First notify the incremental marker if necessary, then update the
4275 CheckNeedsToInformIncrementalMarker(
4276 masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
4277 InformIncrementalMarker(masm);
4278 regs_.Restore(masm); // Restore the extra scratch registers we used.
4280 __ RememberedSetHelper(object(), address(),
4281 value(), // scratch1
4282 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4284 __ Bind(&dont_need_remembered_set);
4287 CheckNeedsToInformIncrementalMarker(
4288 masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
4289 InformIncrementalMarker(masm);
4290 regs_.Restore(masm); // Restore the extra scratch registers we used.
4295 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
4296 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
4298 x0.Is(regs_.address()) ? regs_.scratch0() : regs_.address();
4299 DCHECK(!address.Is(regs_.object()));
4300 DCHECK(!address.Is(x0));
4301 __ Mov(address, regs_.address());
4302 __ Mov(x0, regs_.object());
4303 __ Mov(x1, address);
4304 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4306 AllowExternalCallThatCantCauseGC scope(masm);
4307 ExternalReference function =
4308 ExternalReference::incremental_marking_record_write_function(
4310 __ CallCFunction(function, 3, 0);
4312 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
4316 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
4317 MacroAssembler* masm,
4318 OnNoNeedToInformIncrementalMarker on_no_need,
4321 Label need_incremental;
4322 Label need_incremental_pop_scratch;
4324 Register mem_chunk = regs_.scratch0();
4325 Register counter = regs_.scratch1();
4326 __ Bic(mem_chunk, regs_.object(), Page::kPageAlignmentMask);
4328 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4329 __ Subs(counter, counter, 1);
4331 MemOperand(mem_chunk, MemoryChunk::kWriteBarrierCounterOffset));
4332 __ B(mi, &need_incremental);
4334 // If the object is not black we don't have to inform the incremental marker.
4335 __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
4337 regs_.Restore(masm); // Restore the extra scratch registers we used.
4338 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4339 __ RememberedSetHelper(object(), address(),
4340 value(), // scratch1
4341 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4347 // Get the value from the slot.
4348 Register val = regs_.scratch0();
4349 __ Ldr(val, MemOperand(regs_.address()));
4351 if (mode == INCREMENTAL_COMPACTION) {
4352 Label ensure_not_white;
4354 __ CheckPageFlagClear(val, regs_.scratch1(),
4355 MemoryChunk::kEvacuationCandidateMask,
4358 __ CheckPageFlagClear(regs_.object(),
4360 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
4363 __ Bind(&ensure_not_white);
4366 // We need extra registers for this, so we push the object and the address
4367 // register temporarily.
4368 __ Push(regs_.address(), regs_.object());
4369 __ EnsureNotWhite(val,
4370 regs_.scratch1(), // Scratch.
4371 regs_.object(), // Scratch.
4372 regs_.address(), // Scratch.
4373 regs_.scratch2(), // Scratch.
4374 &need_incremental_pop_scratch);
4375 __ Pop(regs_.object(), regs_.address());
4377 regs_.Restore(masm); // Restore the extra scratch registers we used.
4378 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
4379 __ RememberedSetHelper(object(), address(),
4380 value(), // scratch1
4381 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4386 __ Bind(&need_incremental_pop_scratch);
4387 __ Pop(regs_.object(), regs_.address());
4389 __ Bind(&need_incremental);
4390 // Fall through when we need to inform the incremental marker.
4394 void RecordWriteStub::Generate(MacroAssembler* masm) {
4395 Label skip_to_incremental_noncompacting;
4396 Label skip_to_incremental_compacting;
4398 // We patch these two first instructions back and forth between a nop and
4399 // real branch when we start and stop incremental heap marking.
4400 // Initially the stub is expected to be in STORE_BUFFER_ONLY mode, so 2 nops
4402 // See RecordWriteStub::Patch for details.
4404 InstructionAccurateScope scope(masm, 2);
4405 __ adr(xzr, &skip_to_incremental_noncompacting);
4406 __ adr(xzr, &skip_to_incremental_compacting);
4409 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
4410 __ RememberedSetHelper(object(), address(),
4411 value(), // scratch1
4412 save_fp_regs_mode(), MacroAssembler::kReturnAtEnd);
4416 __ Bind(&skip_to_incremental_noncompacting);
4417 GenerateIncremental(masm, INCREMENTAL);
4419 __ Bind(&skip_to_incremental_compacting);
4420 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
4424 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
4425 // x0 value element value to store
4426 // x3 index_smi element index as smi
4427 // sp[0] array_index_smi array literal index in function as smi
4428 // sp[1] array array literal
4430 Register value = x0;
4431 Register index_smi = x3;
4433 Register array = x1;
4434 Register array_map = x2;
4435 Register array_index_smi = x4;
4436 __ PeekPair(array_index_smi, array, 0);
4437 __ Ldr(array_map, FieldMemOperand(array, JSObject::kMapOffset));
4439 Label double_elements, smi_element, fast_elements, slow_elements;
4440 Register bitfield2 = x10;
4441 __ Ldrb(bitfield2, FieldMemOperand(array_map, Map::kBitField2Offset));
4443 // Jump if array's ElementsKind is not FAST*_SMI_ELEMENTS, FAST_ELEMENTS or
4444 // FAST_HOLEY_ELEMENTS.
4445 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
4446 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
4447 STATIC_ASSERT(FAST_ELEMENTS == 2);
4448 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
4449 __ Cmp(bitfield2, Map::kMaximumBitField2FastHoleyElementValue);
4450 __ B(hi, &double_elements);
4452 __ JumpIfSmi(value, &smi_element);
4454 // Jump if array's ElementsKind is not FAST_ELEMENTS or FAST_HOLEY_ELEMENTS.
4455 __ Tbnz(bitfield2, MaskToBit(FAST_ELEMENTS << Map::ElementsKindBits::kShift),
4458 // Store into the array literal requires an elements transition. Call into
4460 __ Bind(&slow_elements);
4461 __ Push(array, index_smi, value);
4462 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4463 __ Ldr(x11, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
4464 __ Push(x11, array_index_smi);
4465 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4467 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4468 __ Bind(&fast_elements);
4469 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4470 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4471 __ Add(x11, x11, FixedArray::kHeaderSize - kHeapObjectTag);
4472 __ Str(value, MemOperand(x11));
4473 // Update the write barrier for the array store.
4474 __ RecordWrite(x10, x11, value, kLRHasNotBeenSaved, kDontSaveFPRegs,
4475 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4478 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4479 // and value is Smi.
4480 __ Bind(&smi_element);
4481 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4482 __ Add(x11, x10, Operand::UntagSmiAndScale(index_smi, kPointerSizeLog2));
4483 __ Str(value, FieldMemOperand(x11, FixedArray::kHeaderSize));
4486 __ Bind(&double_elements);
4487 __ Ldr(x10, FieldMemOperand(array, JSObject::kElementsOffset));
4488 __ StoreNumberToDoubleElements(value, index_smi, x10, x11, d0,
4494 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4495 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4496 __ Call(ces.GetCode(), RelocInfo::CODE_TARGET);
4497 int parameter_count_offset =
4498 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4499 __ Ldr(x1, MemOperand(fp, parameter_count_offset));
4500 if (function_mode() == JS_FUNCTION_STUB_MODE) {
4503 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4505 // Return to IC Miss stub, continuation still on stack.
4510 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4511 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4512 LoadICStub stub(isolate(), state());
4513 stub.GenerateForTrampoline(masm);
4517 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4518 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4519 KeyedLoadICStub stub(isolate(), state());
4520 stub.GenerateForTrampoline(masm);
4524 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4525 EmitLoadTypeFeedbackVector(masm, x2);
4526 CallICStub stub(isolate(), state());
4527 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4531 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4532 EmitLoadTypeFeedbackVector(masm, x2);
4533 CallIC_ArrayStub stub(isolate(), state());
4534 __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
4538 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4541 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4542 GenerateImpl(masm, true);
4546 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4547 Register key, Register vector, Register slot,
4548 Register feedback, Register receiver_map,
4549 Register scratch1, Register scratch2,
4550 bool is_polymorphic, Label* miss) {
4551 // feedback initially contains the feedback array
4552 Label next_loop, prepare_next;
4553 Label load_smi_map, compare_map;
4554 Label start_polymorphic;
4556 Register cached_map = scratch1;
4559 FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4560 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4561 __ Cmp(receiver_map, cached_map);
4562 __ B(ne, &start_polymorphic);
4563 // found, now call handler.
4564 Register handler = feedback;
4565 __ Ldr(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4566 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4569 Register length = scratch2;
4570 __ Bind(&start_polymorphic);
4571 __ Ldr(length, FieldMemOperand(feedback, FixedArray::kLengthOffset));
4572 if (!is_polymorphic) {
4573 __ Cmp(length, Operand(Smi::FromInt(2)));
4577 Register too_far = length;
4578 Register pointer_reg = feedback;
4580 // +-----+------+------+-----+-----+ ... ----+
4581 // | map | len | wm0 | h0 | wm1 | hN |
4582 // +-----+------+------+-----+-----+ ... ----+
4586 // pointer_reg too_far
4587 // aka feedback scratch2
4588 // also need receiver_map
4589 // use cached_map (scratch1) to look in the weak map values.
4590 __ Add(too_far, feedback,
4591 Operand::UntagSmiAndScale(length, kPointerSizeLog2));
4592 __ Add(too_far, too_far, FixedArray::kHeaderSize - kHeapObjectTag);
4593 __ Add(pointer_reg, feedback,
4594 FixedArray::OffsetOfElementAt(2) - kHeapObjectTag);
4596 __ Bind(&next_loop);
4597 __ Ldr(cached_map, MemOperand(pointer_reg));
4598 __ Ldr(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset));
4599 __ Cmp(receiver_map, cached_map);
4600 __ B(ne, &prepare_next);
4601 __ Ldr(handler, MemOperand(pointer_reg, kPointerSize));
4602 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4605 __ Bind(&prepare_next);
4606 __ Add(pointer_reg, pointer_reg, kPointerSize * 2);
4607 __ Cmp(pointer_reg, too_far);
4608 __ B(lt, &next_loop);
4610 // We exhausted our array of map handler pairs.
4615 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4616 Register receiver_map, Register feedback,
4617 Register vector, Register slot,
4618 Register scratch, Label* compare_map,
4619 Label* load_smi_map, Label* try_array) {
4620 __ JumpIfSmi(receiver, load_smi_map);
4621 __ Ldr(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset));
4622 __ bind(compare_map);
4623 Register cached_map = scratch;
4624 // Move the weak map into the weak_cell register.
4625 __ Ldr(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset));
4626 __ Cmp(cached_map, receiver_map);
4627 __ B(ne, try_array);
4629 Register handler = feedback;
4630 __ Add(handler, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4632 FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize));
4633 __ Add(handler, handler, Code::kHeaderSize - kHeapObjectTag);
4638 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4639 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4640 Register name = LoadWithVectorDescriptor::NameRegister(); // x2
4641 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4642 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4643 Register feedback = x4;
4644 Register receiver_map = x5;
4645 Register scratch1 = x6;
4647 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4648 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4650 // Try to quickly handle the monomorphic case without knowing for sure
4651 // if we have a weak cell in feedback. We do know it's safe to look
4652 // at WeakCell::kValueOffset.
4653 Label try_array, load_smi_map, compare_map;
4654 Label not_array, miss;
4655 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4656 scratch1, &compare_map, &load_smi_map, &try_array);
4658 // Is it a fixed array?
4659 __ Bind(&try_array);
4660 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4661 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4662 HandleArrayCases(masm, receiver, name, vector, slot, feedback, receiver_map,
4663 scratch1, x7, true, &miss);
4665 __ Bind(¬_array);
4666 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex, &miss);
4667 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4668 Code::ComputeHandlerFlags(Code::LOAD_IC));
4669 masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags,
4670 false, receiver, name, feedback,
4671 receiver_map, scratch1, x7);
4674 LoadIC::GenerateMiss(masm);
4676 __ Bind(&load_smi_map);
4677 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4678 __ jmp(&compare_map);
4682 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4683 GenerateImpl(masm, false);
4687 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4688 GenerateImpl(masm, true);
4692 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4693 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // x1
4694 Register key = LoadWithVectorDescriptor::NameRegister(); // x2
4695 Register vector = LoadWithVectorDescriptor::VectorRegister(); // x3
4696 Register slot = LoadWithVectorDescriptor::SlotRegister(); // x0
4697 Register feedback = x4;
4698 Register receiver_map = x5;
4699 Register scratch1 = x6;
4701 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4702 __ Ldr(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize));
4704 // Try to quickly handle the monomorphic case without knowing for sure
4705 // if we have a weak cell in feedback. We do know it's safe to look
4706 // at WeakCell::kValueOffset.
4707 Label try_array, load_smi_map, compare_map;
4708 Label not_array, miss;
4709 HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot,
4710 scratch1, &compare_map, &load_smi_map, &try_array);
4712 __ Bind(&try_array);
4713 // Is it a fixed array?
4714 __ Ldr(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset));
4715 __ JumpIfNotRoot(scratch1, Heap::kFixedArrayMapRootIndex, ¬_array);
4717 // We have a polymorphic element handler.
4718 Label polymorphic, try_poly_name;
4719 __ Bind(&polymorphic);
4720 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4721 scratch1, x7, true, &miss);
4723 __ Bind(¬_array);
4725 __ JumpIfNotRoot(feedback, Heap::kmegamorphic_symbolRootIndex,
4727 Handle<Code> megamorphic_stub =
4728 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4729 __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET);
4731 __ Bind(&try_poly_name);
4732 // We might have a name in feedback, and a fixed array in the next slot.
4733 __ Cmp(key, feedback);
4735 // If the name comparison succeeded, we know we have a fixed array with
4736 // at least one map/handler pair.
4737 __ Add(feedback, vector, Operand::UntagSmiAndScale(slot, kPointerSizeLog2));
4739 FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize));
4740 HandleArrayCases(masm, receiver, key, vector, slot, feedback, receiver_map,
4741 scratch1, x7, false, &miss);
4744 KeyedLoadIC::GenerateMiss(masm);
4746 __ Bind(&load_smi_map);
4747 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4748 __ jmp(&compare_map);
4752 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4753 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4754 VectorStoreICStub stub(isolate(), state());
4755 stub.GenerateForTrampoline(masm);
4759 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4760 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4761 VectorKeyedStoreICStub stub(isolate(), state());
4762 stub.GenerateForTrampoline(masm);
4766 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4767 GenerateImpl(masm, false);
4771 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4772 GenerateImpl(masm, true);
4776 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4779 // TODO(mvstanton): Implement.
4781 StoreIC::GenerateMiss(masm);
4785 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4786 GenerateImpl(masm, false);
4790 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4791 GenerateImpl(masm, true);
4795 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4798 // TODO(mvstanton): Implement.
4800 KeyedStoreIC::GenerateMiss(masm);
4804 // The entry hook is a "BumpSystemStackPointer" instruction (sub), followed by
4805 // a "Push lr" instruction, followed by a call.
4806 static const unsigned int kProfileEntryHookCallSize =
4807 Assembler::kCallSizeWithRelocation + (2 * kInstructionSize);
4810 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4811 if (masm->isolate()->function_entry_hook() != NULL) {
4812 ProfileEntryHookStub stub(masm->isolate());
4813 Assembler::BlockConstPoolScope no_const_pools(masm);
4814 DontEmitDebugCodeScope no_debug_code(masm);
4815 Label entry_hook_call_start;
4816 __ Bind(&entry_hook_call_start);
4819 DCHECK(masm->SizeOfCodeGeneratedSince(&entry_hook_call_start) ==
4820 kProfileEntryHookCallSize);
4827 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4828 MacroAssembler::NoUseRealAbortsScope no_use_real_aborts(masm);
4830 // Save all kCallerSaved registers (including lr), since this can be called
4832 // TODO(jbramley): What about FP registers?
4833 __ PushCPURegList(kCallerSaved);
4834 DCHECK(kCallerSaved.IncludesAliasOf(lr));
4835 const int kNumSavedRegs = kCallerSaved.Count();
4837 // Compute the function's address as the first argument.
4838 __ Sub(x0, lr, kProfileEntryHookCallSize);
4840 #if V8_HOST_ARCH_ARM64
4841 uintptr_t entry_hook =
4842 reinterpret_cast<uintptr_t>(isolate()->function_entry_hook());
4843 __ Mov(x10, entry_hook);
4845 // Under the simulator we need to indirect the entry hook through a trampoline
4846 // function at a known address.
4847 ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline));
4848 __ Mov(x10, Operand(ExternalReference(&dispatcher,
4849 ExternalReference::BUILTIN_CALL,
4851 // It additionally takes an isolate as a third parameter
4852 __ Mov(x2, ExternalReference::isolate_address(isolate()));
4855 // The caller's return address is above the saved temporaries.
4856 // Grab its location for the second argument to the hook.
4857 __ Add(x1, __ StackPointer(), kNumSavedRegs * kPointerSize);
4860 // Create a dummy frame, as CallCFunction requires this.
4861 FrameScope frame(masm, StackFrame::MANUAL);
4862 __ CallCFunction(x10, 2, 0);
4865 __ PopCPURegList(kCallerSaved);
4870 void DirectCEntryStub::Generate(MacroAssembler* masm) {
4871 // When calling into C++ code the stack pointer must be csp.
4872 // Therefore this code must use csp for peek/poke operations when the
4873 // stub is generated. When the stub is called
4874 // (via DirectCEntryStub::GenerateCall), the caller must setup an ExitFrame
4875 // and configure the stack pointer *before* doing the call.
4876 const Register old_stack_pointer = __ StackPointer();
4877 __ SetStackPointer(csp);
4879 // Put return address on the stack (accessible to GC through exit frame pc).
4881 // Call the C++ function.
4883 // Return to calling code.
4885 __ AssertFPCRState();
4888 __ SetStackPointer(old_stack_pointer);
4891 void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
4893 // Make sure the caller configured the stack pointer (see comment in
4894 // DirectCEntryStub::Generate).
4895 DCHECK(csp.Is(__ StackPointer()));
4898 reinterpret_cast<intptr_t>(GetCode().location());
4899 __ Mov(lr, Operand(code, RelocInfo::CODE_TARGET));
4900 __ Mov(x10, target);
4901 // Branch to the stub.
4906 // Probe the name dictionary in the 'elements' register.
4907 // Jump to the 'done' label if a property with the given name is found.
4908 // Jump to the 'miss' label otherwise.
4910 // If lookup was successful 'scratch2' will be equal to elements + 4 * index.
4911 // 'elements' and 'name' registers are preserved on miss.
4912 void NameDictionaryLookupStub::GeneratePositiveLookup(
4913 MacroAssembler* masm,
4919 Register scratch2) {
4920 DCHECK(!AreAliased(elements, name, scratch1, scratch2));
4922 // Assert that name contains a string.
4923 __ AssertName(name);
4925 // Compute the capacity mask.
4926 __ Ldrsw(scratch1, UntagSmiFieldMemOperand(elements, kCapacityOffset));
4927 __ Sub(scratch1, scratch1, 1);
4929 // Generate an unrolled loop that performs a few probes before giving up.
4930 for (int i = 0; i < kInlinedProbes; i++) {
4931 // Compute the masked index: (hash + i + i * i) & mask.
4932 __ Ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
4934 // Add the probe offset (i + i * i) left shifted to avoid right shifting
4935 // the hash in a separate instruction. The value hash + i + i * i is right
4936 // shifted in the following and instruction.
4937 DCHECK(NameDictionary::GetProbeOffset(i) <
4938 1 << (32 - Name::kHashFieldOffset));
4939 __ Add(scratch2, scratch2, Operand(
4940 NameDictionary::GetProbeOffset(i) << Name::kHashShift));
4942 __ And(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
4944 // Scale the index by multiplying by the element size.
4945 DCHECK(NameDictionary::kEntrySize == 3);
4946 __ Add(scratch2, scratch2, Operand(scratch2, LSL, 1));
4948 // Check if the key is identical to the name.
4949 UseScratchRegisterScope temps(masm);
4950 Register scratch3 = temps.AcquireX();
4951 __ Add(scratch2, elements, Operand(scratch2, LSL, kPointerSizeLog2));
4952 __ Ldr(scratch3, FieldMemOperand(scratch2, kElementsStartOffset));
4953 __ Cmp(name, scratch3);
4957 // The inlined probes didn't find the entry.
4958 // Call the complete stub to scan the whole dictionary.
4960 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
4961 spill_list.Combine(lr);
4962 spill_list.Remove(scratch1);
4963 spill_list.Remove(scratch2);
4965 __ PushCPURegList(spill_list);
4968 DCHECK(!elements.is(x1));
4970 __ Mov(x0, elements);
4972 __ Mov(x0, elements);
4977 NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP);
4979 __ Cbz(x0, ¬_found);
4980 __ Mov(scratch2, x2); // Move entry index into scratch2.
4981 __ PopCPURegList(spill_list);
4984 __ Bind(¬_found);
4985 __ PopCPURegList(spill_list);
4990 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
4994 Register properties,
4996 Register scratch0) {
4997 DCHECK(!AreAliased(receiver, properties, scratch0));
4998 DCHECK(name->IsUniqueName());
4999 // If names of slots in range from 1 to kProbes - 1 for the hash value are
5000 // not equal to the name and kProbes-th slot is not used (its name is the
5001 // undefined value), it guarantees the hash table doesn't contain the
5002 // property. It's true even if some slots represent deleted properties
5003 // (their names are the hole value).
5004 for (int i = 0; i < kInlinedProbes; i++) {
5005 // scratch0 points to properties hash.
5006 // Compute the masked index: (hash + i + i * i) & mask.
5007 Register index = scratch0;
5008 // Capacity is smi 2^n.
5009 __ Ldrsw(index, UntagSmiFieldMemOperand(properties, kCapacityOffset));
5010 __ Sub(index, index, 1);
5011 __ And(index, index, name->Hash() + NameDictionary::GetProbeOffset(i));
5013 // Scale the index by multiplying by the entry size.
5014 DCHECK(NameDictionary::kEntrySize == 3);
5015 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5017 Register entity_name = scratch0;
5018 // Having undefined at this place means the name is not contained.
5019 Register tmp = index;
5020 __ Add(tmp, properties, Operand(index, LSL, kPointerSizeLog2));
5021 __ Ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
5023 __ JumpIfRoot(entity_name, Heap::kUndefinedValueRootIndex, done);
5025 // Stop if found the property.
5026 __ Cmp(entity_name, Operand(name));
5030 __ JumpIfRoot(entity_name, Heap::kTheHoleValueRootIndex, &good);
5032 // Check if the entry name is not a unique name.
5033 __ Ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
5034 __ Ldrb(entity_name,
5035 FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
5036 __ JumpIfNotUniqueNameInstanceType(entity_name, miss);
5040 CPURegList spill_list(CPURegister::kRegister, kXRegSizeInBits, 0, 6);
5041 spill_list.Combine(lr);
5042 spill_list.Remove(scratch0); // Scratch registers don't need to be preserved.
5044 __ PushCPURegList(spill_list);
5046 __ Ldr(x0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
5047 __ Mov(x1, Operand(name));
5048 NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP);
5050 // Move stub return value to scratch0. Note that scratch0 is not included in
5051 // spill_list and won't be clobbered by PopCPURegList.
5052 __ Mov(scratch0, x0);
5053 __ PopCPURegList(spill_list);
5055 __ Cbz(scratch0, done);
5060 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
5061 // This stub overrides SometimesSetsUpAFrame() to return false. That means
5062 // we cannot call anything that could cause a GC from this stub.
5064 // Arguments are in x0 and x1:
5065 // x0: property dictionary.
5066 // x1: the name of the property we are looking for.
5068 // Return value is in x0 and is zero if lookup failed, non zero otherwise.
5069 // If the lookup is successful, x2 will contains the index of the entry.
5071 Register result = x0;
5072 Register dictionary = x0;
5074 Register index = x2;
5077 Register undefined = x5;
5078 Register entry_key = x6;
5080 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
5082 __ Ldrsw(mask, UntagSmiFieldMemOperand(dictionary, kCapacityOffset));
5083 __ Sub(mask, mask, 1);
5085 __ Ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
5086 __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
5088 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
5089 // Compute the masked index: (hash + i + i * i) & mask.
5090 // Capacity is smi 2^n.
5092 // Add the probe offset (i + i * i) left shifted to avoid right shifting
5093 // the hash in a separate instruction. The value hash + i + i * i is right
5094 // shifted in the following and instruction.
5095 DCHECK(NameDictionary::GetProbeOffset(i) <
5096 1 << (32 - Name::kHashFieldOffset));
5098 NameDictionary::GetProbeOffset(i) << Name::kHashShift);
5100 __ Mov(index, hash);
5102 __ And(index, mask, Operand(index, LSR, Name::kHashShift));
5104 // Scale the index by multiplying by the entry size.
5105 DCHECK(NameDictionary::kEntrySize == 3);
5106 __ Add(index, index, Operand(index, LSL, 1)); // index *= 3.
5108 __ Add(index, dictionary, Operand(index, LSL, kPointerSizeLog2));
5109 __ Ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
5111 // Having undefined at this place means the name is not contained.
5112 __ Cmp(entry_key, undefined);
5113 __ B(eq, ¬_in_dictionary);
5115 // Stop if found the property.
5116 __ Cmp(entry_key, key);
5117 __ B(eq, &in_dictionary);
5119 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
5120 // Check if the entry name is not a unique name.
5121 __ Ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
5122 __ Ldrb(entry_key, FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
5123 __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary);
5127 __ Bind(&maybe_in_dictionary);
5128 // If we are doing negative lookup then probing failure should be
5129 // treated as a lookup success. For positive lookup, probing failure
5130 // should be treated as lookup failure.
5131 if (mode() == POSITIVE_LOOKUP) {
5136 __ Bind(&in_dictionary);
5140 __ Bind(¬_in_dictionary);
5147 static void CreateArrayDispatch(MacroAssembler* masm,
5148 AllocationSiteOverrideMode mode) {
5149 ASM_LOCATION("CreateArrayDispatch");
5150 if (mode == DISABLE_ALLOCATION_SITES) {
5151 T stub(masm->isolate(), GetInitialFastElementsKind(), mode);
5152 __ TailCallStub(&stub);
5154 } else if (mode == DONT_OVERRIDE) {
5157 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5158 for (int i = 0; i <= last_index; ++i) {
5160 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5161 // TODO(jbramley): Is this the best way to handle this? Can we make the
5162 // tail calls conditional, rather than hopping over each one?
5163 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5164 T stub(masm->isolate(), candidate_kind);
5165 __ TailCallStub(&stub);
5169 // If we reached this point there is a problem.
5170 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5178 // TODO(jbramley): If this needs to be a special case, make it a proper template
5179 // specialization, and not a separate function.
5180 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
5181 AllocationSiteOverrideMode mode) {
5182 ASM_LOCATION("CreateArrayDispatchOneArgument");
5184 // x1 - constructor?
5185 // x2 - allocation site (if mode != DISABLE_ALLOCATION_SITES)
5186 // x3 - kind (if mode != DISABLE_ALLOCATION_SITES)
5187 // sp[0] - last argument
5189 Register allocation_site = x2;
5192 Label normal_sequence;
5193 if (mode == DONT_OVERRIDE) {
5194 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
5195 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
5196 STATIC_ASSERT(FAST_ELEMENTS == 2);
5197 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
5198 STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4);
5199 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
5201 // Is the low bit set? If so, the array is holey.
5202 __ Tbnz(kind, 0, &normal_sequence);
5205 // Look at the last argument.
5206 // TODO(jbramley): What does a 0 argument represent?
5208 __ Cbz(x10, &normal_sequence);
5210 if (mode == DISABLE_ALLOCATION_SITES) {
5211 ElementsKind initial = GetInitialFastElementsKind();
5212 ElementsKind holey_initial = GetHoleyElementsKind(initial);
5214 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
5216 DISABLE_ALLOCATION_SITES);
5217 __ TailCallStub(&stub_holey);
5219 __ Bind(&normal_sequence);
5220 ArraySingleArgumentConstructorStub stub(masm->isolate(),
5222 DISABLE_ALLOCATION_SITES);
5223 __ TailCallStub(&stub);
5224 } else if (mode == DONT_OVERRIDE) {
5225 // We are going to create a holey array, but our kind is non-holey.
5226 // Fix kind and retry (only if we have an allocation site in the slot).
5227 __ Orr(kind, kind, 1);
5229 if (FLAG_debug_code) {
5230 __ Ldr(x10, FieldMemOperand(allocation_site, 0));
5231 __ JumpIfNotRoot(x10, Heap::kAllocationSiteMapRootIndex,
5233 __ Assert(eq, kExpectedAllocationSite);
5236 // Save the resulting elements kind in type info. We can't just store 'kind'
5237 // in the AllocationSite::transition_info field because elements kind is
5238 // restricted to a portion of the field; upper bits need to be left alone.
5239 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
5240 __ Ldr(x11, FieldMemOperand(allocation_site,
5241 AllocationSite::kTransitionInfoOffset));
5242 __ Add(x11, x11, Smi::FromInt(kFastElementsKindPackedToHoley));
5243 __ Str(x11, FieldMemOperand(allocation_site,
5244 AllocationSite::kTransitionInfoOffset));
5246 __ Bind(&normal_sequence);
5248 GetSequenceIndexFromFastElementsKind(TERMINAL_FAST_ELEMENTS_KIND);
5249 for (int i = 0; i <= last_index; ++i) {
5251 ElementsKind candidate_kind = GetFastElementsKindFromSequenceIndex(i);
5252 __ CompareAndBranch(kind, candidate_kind, ne, &next);
5253 ArraySingleArgumentConstructorStub stub(masm->isolate(), candidate_kind);
5254 __ TailCallStub(&stub);
5258 // If we reached this point there is a problem.
5259 __ Abort(kUnexpectedElementsKindInArrayConstructor);
5267 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
5268 int to_index = GetSequenceIndexFromFastElementsKind(
5269 TERMINAL_FAST_ELEMENTS_KIND);
5270 for (int i = 0; i <= to_index; ++i) {
5271 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
5272 T stub(isolate, kind);
5274 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
5275 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
5282 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
5283 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
5285 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
5287 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
5292 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
5294 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
5295 for (int i = 0; i < 2; i++) {
5296 // For internal arrays we only need a few things
5297 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
5299 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
5301 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
5307 void ArrayConstructorStub::GenerateDispatchToArrayStub(
5308 MacroAssembler* masm,
5309 AllocationSiteOverrideMode mode) {
5311 if (argument_count() == ANY) {
5312 Label zero_case, n_case;
5313 __ Cbz(argc, &zero_case);
5318 CreateArrayDispatchOneArgument(masm, mode);
5320 __ Bind(&zero_case);
5322 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5326 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5328 } else if (argument_count() == NONE) {
5329 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
5330 } else if (argument_count() == ONE) {
5331 CreateArrayDispatchOneArgument(masm, mode);
5332 } else if (argument_count() == MORE_THAN_ONE) {
5333 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
5340 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
5341 ASM_LOCATION("ArrayConstructorStub::Generate");
5342 // ----------- S t a t e -------------
5343 // -- x0 : argc (only if argument_count() is ANY or MORE_THAN_ONE)
5344 // -- x1 : constructor
5345 // -- x2 : AllocationSite or undefined
5346 // -- x3 : original constructor
5347 // -- sp[0] : last argument
5348 // -----------------------------------
5349 Register constructor = x1;
5350 Register allocation_site = x2;
5351 Register original_constructor = x3;
5353 if (FLAG_debug_code) {
5354 // The array construct code is only set for the global and natives
5355 // builtin Array functions which always have maps.
5357 Label unexpected_map, map_ok;
5358 // Initial map for the builtin Array function should be a map.
5359 __ Ldr(x10, FieldMemOperand(constructor,
5360 JSFunction::kPrototypeOrInitialMapOffset));
5361 // Will both indicate a NULL and a Smi.
5362 __ JumpIfSmi(x10, &unexpected_map);
5363 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5364 __ Bind(&unexpected_map);
5365 __ Abort(kUnexpectedInitialMapForArrayFunction);
5368 // We should either have undefined in the allocation_site register or a
5369 // valid AllocationSite.
5370 __ AssertUndefinedOrAllocationSite(allocation_site, x10);
5374 __ Cmp(original_constructor, constructor);
5375 __ B(ne, &subclassing);
5379 // Get the elements kind and case on that.
5380 __ JumpIfRoot(allocation_site, Heap::kUndefinedValueRootIndex, &no_info);
5383 UntagSmiFieldMemOperand(allocation_site,
5384 AllocationSite::kTransitionInfoOffset));
5385 __ And(kind, kind, AllocationSite::ElementsKindBits::kMask);
5386 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
5389 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
5391 // Subclassing support.
5392 __ Bind(&subclassing);
5393 __ Push(constructor, original_constructor);
5395 switch (argument_count()) {
5398 __ add(x0, x0, Operand(2));
5401 __ Mov(x0, Operand(2));
5404 __ Mov(x0, Operand(3));
5407 __ JumpToExternalReference(
5408 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
5412 void InternalArrayConstructorStub::GenerateCase(
5413 MacroAssembler* masm, ElementsKind kind) {
5414 Label zero_case, n_case;
5417 __ Cbz(argc, &zero_case);
5418 __ CompareAndBranch(argc, 1, ne, &n_case);
5421 if (IsFastPackedElementsKind(kind)) {
5424 // We might need to create a holey array; look at the first argument.
5426 __ Cbz(x10, &packed_case);
5428 InternalArraySingleArgumentConstructorStub
5429 stub1_holey(isolate(), GetHoleyElementsKind(kind));
5430 __ TailCallStub(&stub1_holey);
5432 __ Bind(&packed_case);
5434 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
5435 __ TailCallStub(&stub1);
5437 __ Bind(&zero_case);
5439 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
5440 __ TailCallStub(&stub0);
5444 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
5445 __ TailCallStub(&stubN);
5449 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
5450 // ----------- S t a t e -------------
5452 // -- x1 : constructor
5453 // -- sp[0] : return address
5454 // -- sp[4] : last argument
5455 // -----------------------------------
5457 Register constructor = x1;
5459 if (FLAG_debug_code) {
5460 // The array construct code is only set for the global and natives
5461 // builtin Array functions which always have maps.
5463 Label unexpected_map, map_ok;
5464 // Initial map for the builtin Array function should be a map.
5465 __ Ldr(x10, FieldMemOperand(constructor,
5466 JSFunction::kPrototypeOrInitialMapOffset));
5467 // Will both indicate a NULL and a Smi.
5468 __ JumpIfSmi(x10, &unexpected_map);
5469 __ JumpIfObjectType(x10, x10, x11, MAP_TYPE, &map_ok);
5470 __ Bind(&unexpected_map);
5471 __ Abort(kUnexpectedInitialMapForArrayFunction);
5476 // Figure out the right elements kind
5477 __ Ldr(x10, FieldMemOperand(constructor,
5478 JSFunction::kPrototypeOrInitialMapOffset));
5480 // Retrieve elements_kind from map.
5481 __ LoadElementsKindFromMap(kind, x10);
5483 if (FLAG_debug_code) {
5485 __ Cmp(x3, FAST_ELEMENTS);
5486 __ Ccmp(x3, FAST_HOLEY_ELEMENTS, ZFlag, ne);
5487 __ Assert(eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray);
5490 Label fast_elements_case;
5491 __ CompareAndBranch(kind, FAST_ELEMENTS, eq, &fast_elements_case);
5492 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
5494 __ Bind(&fast_elements_case);
5495 GenerateCase(masm, FAST_ELEMENTS);
5499 // The number of register that CallApiFunctionAndReturn will need to save on
5500 // the stack. The space for these registers need to be allocated in the
5501 // ExitFrame before calling CallApiFunctionAndReturn.
5502 static const int kCallApiFunctionSpillSpace = 4;
5505 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) {
5506 return static_cast<int>(ref0.address() - ref1.address());
5510 // Calls an API function. Allocates HandleScope, extracts returned value
5511 // from handle and propagates exceptions.
5512 // 'stack_space' is the space to be unwound on exit (includes the call JS
5513 // arguments space and the additional space allocated for the fast call).
5514 // 'spill_offset' is the offset from the stack pointer where
5515 // CallApiFunctionAndReturn can spill registers.
5516 static void CallApiFunctionAndReturn(
5517 MacroAssembler* masm, Register function_address,
5518 ExternalReference thunk_ref, int stack_space,
5519 MemOperand* stack_space_operand, int spill_offset,
5520 MemOperand return_value_operand, MemOperand* context_restore_operand) {
5521 ASM_LOCATION("CallApiFunctionAndReturn");
5522 Isolate* isolate = masm->isolate();
5523 ExternalReference next_address =
5524 ExternalReference::handle_scope_next_address(isolate);
5525 const int kNextOffset = 0;
5526 const int kLimitOffset = AddressOffset(
5527 ExternalReference::handle_scope_limit_address(isolate), next_address);
5528 const int kLevelOffset = AddressOffset(
5529 ExternalReference::handle_scope_level_address(isolate), next_address);
5531 DCHECK(function_address.is(x1) || function_address.is(x2));
5533 Label profiler_disabled;
5534 Label end_profiler_check;
5535 __ Mov(x10, ExternalReference::is_profiling_address(isolate));
5536 __ Ldrb(w10, MemOperand(x10));
5537 __ Cbz(w10, &profiler_disabled);
5538 __ Mov(x3, thunk_ref);
5539 __ B(&end_profiler_check);
5541 __ Bind(&profiler_disabled);
5542 __ Mov(x3, function_address);
5543 __ Bind(&end_profiler_check);
5545 // Save the callee-save registers we are going to use.
5546 // TODO(all): Is this necessary? ARM doesn't do it.
5547 STATIC_ASSERT(kCallApiFunctionSpillSpace == 4);
5548 __ Poke(x19, (spill_offset + 0) * kXRegSize);
5549 __ Poke(x20, (spill_offset + 1) * kXRegSize);
5550 __ Poke(x21, (spill_offset + 2) * kXRegSize);
5551 __ Poke(x22, (spill_offset + 3) * kXRegSize);
5553 // Allocate HandleScope in callee-save registers.
5554 // We will need to restore the HandleScope after the call to the API function,
5555 // by allocating it in callee-save registers they will be preserved by C code.
5556 Register handle_scope_base = x22;
5557 Register next_address_reg = x19;
5558 Register limit_reg = x20;
5559 Register level_reg = w21;
5561 __ Mov(handle_scope_base, next_address);
5562 __ Ldr(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5563 __ Ldr(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5564 __ Ldr(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5565 __ Add(level_reg, level_reg, 1);
5566 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5568 if (FLAG_log_timer_events) {
5569 FrameScope frame(masm, StackFrame::MANUAL);
5570 __ PushSafepointRegisters();
5571 __ Mov(x0, ExternalReference::isolate_address(isolate));
5572 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
5574 __ PopSafepointRegisters();
5577 // Native call returns to the DirectCEntry stub which redirects to the
5578 // return address pushed on stack (could have moved after GC).
5579 // DirectCEntry stub itself is generated early and never moves.
5580 DirectCEntryStub stub(isolate);
5581 stub.GenerateCall(masm, x3);
5583 if (FLAG_log_timer_events) {
5584 FrameScope frame(masm, StackFrame::MANUAL);
5585 __ PushSafepointRegisters();
5586 __ Mov(x0, ExternalReference::isolate_address(isolate));
5587 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
5589 __ PopSafepointRegisters();
5592 Label promote_scheduled_exception;
5593 Label delete_allocated_handles;
5594 Label leave_exit_frame;
5595 Label return_value_loaded;
5597 // Load value from ReturnValue.
5598 __ Ldr(x0, return_value_operand);
5599 __ Bind(&return_value_loaded);
5600 // No more valid handles (the result handle was the last one). Restore
5601 // previous handle scope.
5602 __ Str(next_address_reg, MemOperand(handle_scope_base, kNextOffset));
5603 if (__ emit_debug_code()) {
5604 __ Ldr(w1, MemOperand(handle_scope_base, kLevelOffset));
5605 __ Cmp(w1, level_reg);
5606 __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall);
5608 __ Sub(level_reg, level_reg, 1);
5609 __ Str(level_reg, MemOperand(handle_scope_base, kLevelOffset));
5610 __ Ldr(x1, MemOperand(handle_scope_base, kLimitOffset));
5611 __ Cmp(limit_reg, x1);
5612 __ B(ne, &delete_allocated_handles);
5614 // Leave the API exit frame.
5615 __ Bind(&leave_exit_frame);
5616 // Restore callee-saved registers.
5617 __ Peek(x19, (spill_offset + 0) * kXRegSize);
5618 __ Peek(x20, (spill_offset + 1) * kXRegSize);
5619 __ Peek(x21, (spill_offset + 2) * kXRegSize);
5620 __ Peek(x22, (spill_offset + 3) * kXRegSize);
5622 bool restore_context = context_restore_operand != NULL;
5623 if (restore_context) {
5624 __ Ldr(cp, *context_restore_operand);
5627 if (stack_space_operand != NULL) {
5628 __ Ldr(w2, *stack_space_operand);
5631 __ LeaveExitFrame(false, x1, !restore_context);
5633 // Check if the function scheduled an exception.
5634 __ Mov(x5, ExternalReference::scheduled_exception_address(isolate));
5635 __ Ldr(x5, MemOperand(x5));
5636 __ JumpIfNotRoot(x5, Heap::kTheHoleValueRootIndex,
5637 &promote_scheduled_exception);
5639 if (stack_space_operand != NULL) {
5642 __ Drop(stack_space);
5646 // Re-throw by promoting a scheduled exception.
5647 __ Bind(&promote_scheduled_exception);
5648 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
5650 // HandleScope limit has changed. Delete allocated extensions.
5651 __ Bind(&delete_allocated_handles);
5652 __ Str(limit_reg, MemOperand(handle_scope_base, kLimitOffset));
5653 // Save the return value in a callee-save register.
5654 Register saved_result = x19;
5655 __ Mov(saved_result, x0);
5656 __ Mov(x0, ExternalReference::isolate_address(isolate));
5657 __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate),
5659 __ Mov(x0, saved_result);
5660 __ B(&leave_exit_frame);
5664 static void CallApiFunctionStubHelper(MacroAssembler* masm,
5665 const ParameterCount& argc,
5666 bool return_first_arg,
5667 bool call_data_undefined) {
5668 // ----------- S t a t e -------------
5670 // -- x4 : call_data
5672 // -- x1 : api_function_address
5673 // -- x3 : number of arguments if argc is a register
5676 // -- sp[0] : last argument
5678 // -- sp[(argc - 1) * 8] : first argument
5679 // -- sp[argc * 8] : receiver
5680 // -----------------------------------
5682 Register callee = x0;
5683 Register call_data = x4;
5684 Register holder = x2;
5685 Register api_function_address = x1;
5686 Register context = cp;
5688 typedef FunctionCallbackArguments FCA;
5690 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
5691 STATIC_ASSERT(FCA::kCalleeIndex == 5);
5692 STATIC_ASSERT(FCA::kDataIndex == 4);
5693 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
5694 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
5695 STATIC_ASSERT(FCA::kIsolateIndex == 1);
5696 STATIC_ASSERT(FCA::kHolderIndex == 0);
5697 STATIC_ASSERT(FCA::kArgsLength == 7);
5699 DCHECK(argc.is_immediate() || x3.is(argc.reg()));
5701 // FunctionCallbackArguments: context, callee and call data.
5702 __ Push(context, callee, call_data);
5704 // Load context from callee
5705 __ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
5707 if (!call_data_undefined) {
5708 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
5710 Register isolate_reg = x5;
5711 __ Mov(isolate_reg, ExternalReference::isolate_address(masm->isolate()));
5713 // FunctionCallbackArguments:
5714 // return value, return value default, isolate, holder.
5715 __ Push(call_data, call_data, isolate_reg, holder);
5717 // Prepare arguments.
5719 __ Mov(args, masm->StackPointer());
5721 // Allocate the v8::Arguments structure in the arguments' space, since it's
5722 // not controlled by GC.
5723 const int kApiStackSpace = 4;
5725 // Allocate space for CallApiFunctionAndReturn can store some scratch
5726 // registeres on the stack.
5727 const int kCallApiFunctionSpillSpace = 4;
5729 FrameScope frame_scope(masm, StackFrame::MANUAL);
5730 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5732 DCHECK(!AreAliased(x0, api_function_address));
5733 // x0 = FunctionCallbackInfo&
5734 // Arguments is after the return address.
5735 __ Add(x0, masm->StackPointer(), 1 * kPointerSize);
5736 if (argc.is_immediate()) {
5737 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5739 Operand((FCA::kArgsLength - 1 + argc.immediate()) * kPointerSize));
5740 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5741 // FunctionCallbackInfo::length_ = argc and
5742 // FunctionCallbackInfo::is_construct_call = 0
5743 __ Mov(x10, argc.immediate());
5744 __ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize));
5746 // FunctionCallbackInfo::implicit_args_ and FunctionCallbackInfo::values_
5747 __ Add(x10, args, Operand(argc.reg(), LSL, kPointerSizeLog2));
5748 __ Add(x10, x10, (FCA::kArgsLength - 1) * kPointerSize);
5749 __ Stp(args, x10, MemOperand(x0, 0 * kPointerSize));
5750 // FunctionCallbackInfo::length_ = argc and
5751 // FunctionCallbackInfo::is_construct_call
5752 __ Add(x10, argc.reg(), FCA::kArgsLength + 1);
5753 __ Mov(x10, Operand(x10, LSL, kPointerSizeLog2));
5754 __ Stp(argc.reg(), x10, MemOperand(x0, 2 * kPointerSize));
5757 ExternalReference thunk_ref =
5758 ExternalReference::invoke_function_callback(masm->isolate());
5760 AllowExternalCallThatCantCauseGC scope(masm);
5761 MemOperand context_restore_operand(
5762 fp, (2 + FCA::kContextSaveIndex) * kPointerSize);
5763 // Stores return the first js argument
5764 int return_value_offset = 0;
5765 if (return_first_arg) {
5766 return_value_offset = 2 + FCA::kArgsLength;
5768 return_value_offset = 2 + FCA::kReturnValueOffset;
5770 MemOperand return_value_operand(fp, return_value_offset * kPointerSize);
5771 int stack_space = 0;
5772 MemOperand is_construct_call_operand =
5773 MemOperand(masm->StackPointer(), 4 * kPointerSize);
5774 MemOperand* stack_space_operand = &is_construct_call_operand;
5775 if (argc.is_immediate()) {
5776 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5777 stack_space_operand = NULL;
5780 const int spill_offset = 1 + kApiStackSpace;
5781 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space,
5782 stack_space_operand, spill_offset,
5783 return_value_operand, &context_restore_operand);
5787 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5788 bool call_data_undefined = this->call_data_undefined();
5789 CallApiFunctionStubHelper(masm, ParameterCount(x3), false,
5790 call_data_undefined);
5794 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5795 bool is_store = this->is_store();
5796 int argc = this->argc();
5797 bool call_data_undefined = this->call_data_undefined();
5798 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5799 call_data_undefined);
5803 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5804 // ----------- S t a t e -------------
5806 // -- sp[8 - kArgsLength*8] : PropertyCallbackArguments object
5808 // -- x2 : api_function_address
5809 // -----------------------------------
5811 Register api_function_address = ApiGetterDescriptor::function_address();
5812 DCHECK(api_function_address.is(x2));
5814 __ Mov(x0, masm->StackPointer()); // x0 = Handle<Name>
5815 __ Add(x1, x0, 1 * kPointerSize); // x1 = PCA
5817 const int kApiStackSpace = 1;
5819 // Allocate space for CallApiFunctionAndReturn can store some scratch
5820 // registeres on the stack.
5821 const int kCallApiFunctionSpillSpace = 4;
5823 FrameScope frame_scope(masm, StackFrame::MANUAL);
5824 __ EnterExitFrame(false, x10, kApiStackSpace + kCallApiFunctionSpillSpace);
5826 // Create PropertyAccessorInfo instance on the stack above the exit frame with
5827 // x1 (internal::Object** args_) as the data.
5828 __ Poke(x1, 1 * kPointerSize);
5829 __ Add(x1, masm->StackPointer(), 1 * kPointerSize); // x1 = AccessorInfo&
5831 const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
5833 ExternalReference thunk_ref =
5834 ExternalReference::invoke_accessor_getter_callback(isolate());
5836 const int spill_offset = 1 + kApiStackSpace;
5837 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5838 kStackUnwindSpace, NULL, spill_offset,
5839 MemOperand(fp, 6 * kPointerSize), NULL);
5845 } // namespace internal
5848 #endif // V8_TARGET_ARCH_ARM64