1 // Copyright 2012 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.
9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h"
11 #include "src/code-stubs.h"
12 #include "src/codegen.h"
13 #include "src/ic/handler-compiler.h"
14 #include "src/ic/ic.h"
15 #include "src/ic/stub-cache.h"
16 #include "src/isolate.h"
17 #include "src/jsregexp.h"
18 #include "src/regexp-macro-assembler.h"
19 #include "src/runtime/runtime.h"
25 static void InitializeArrayConstructorDescriptor(
26 Isolate* isolate, CodeStubDescriptor* descriptor,
27 int constant_stack_parameter_count) {
29 // eax -- number of arguments
31 // ebx -- allocation site with elements kind
32 Address deopt_handler = Runtime::FunctionForId(
33 Runtime::kArrayConstructor)->entry;
35 if (constant_stack_parameter_count == 0) {
36 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
37 JS_FUNCTION_STUB_MODE);
39 descriptor->Initialize(eax, deopt_handler, constant_stack_parameter_count,
40 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
45 static void InitializeInternalArrayConstructorDescriptor(
46 Isolate* isolate, CodeStubDescriptor* descriptor,
47 int constant_stack_parameter_count) {
49 // eax -- number of arguments
50 // edi -- constructor function
51 Address deopt_handler = Runtime::FunctionForId(
52 Runtime::kInternalArrayConstructor)->entry;
54 if (constant_stack_parameter_count == 0) {
55 descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
56 JS_FUNCTION_STUB_MODE);
58 descriptor->Initialize(eax, deopt_handler, constant_stack_parameter_count,
59 JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
64 void ArrayNoArgumentConstructorStub::InitializeDescriptor(
65 CodeStubDescriptor* descriptor) {
66 InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
70 void ArraySingleArgumentConstructorStub::InitializeDescriptor(
71 CodeStubDescriptor* descriptor) {
72 InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
76 void ArrayNArgumentsConstructorStub::InitializeDescriptor(
77 CodeStubDescriptor* descriptor) {
78 InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
82 void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
83 CodeStubDescriptor* descriptor) {
84 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
88 void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
89 CodeStubDescriptor* descriptor) {
90 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
94 void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
95 CodeStubDescriptor* descriptor) {
96 InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
100 #define __ ACCESS_MASM(masm)
103 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
104 ExternalReference miss) {
105 // Update the static counter each time a new code stub is generated.
106 isolate()->counters()->code_stubs()->Increment();
108 CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
109 int param_count = descriptor.GetRegisterParameterCount();
111 // Call the runtime system in a fresh internal frame.
112 FrameScope scope(masm, StackFrame::INTERNAL);
113 DCHECK(param_count == 0 ||
114 eax.is(descriptor.GetRegisterParameter(param_count - 1)));
116 for (int i = 0; i < param_count; ++i) {
117 __ push(descriptor.GetRegisterParameter(i));
119 __ CallExternalReference(miss, param_count);
126 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
127 // We don't allow a GC during a store buffer overflow so there is no need to
128 // store the registers in any particular way, but we do have to store and
131 if (save_doubles()) {
132 // Save FPU stat in m108byte.
133 __ sub(esp, Immediate(108));
134 __ fnsave(Operand(esp, 0));
136 const int argument_count = 1;
138 AllowExternalCallThatCantCauseGC scope(masm);
139 __ PrepareCallCFunction(argument_count, ecx);
140 __ mov(Operand(esp, 0 * kPointerSize),
141 Immediate(ExternalReference::isolate_address(isolate())));
143 ExternalReference::store_buffer_overflow_function(isolate()),
145 if (save_doubles()) {
146 // Restore FPU stat in m108byte.
147 __ frstor(Operand(esp, 0));
148 __ add(esp, Immediate(108));
155 class FloatingPointHelper : public AllStatic {
162 // Code pattern for loading a floating point value. Input value must
163 // be either a smi or a heap number object (fp value). Requirements:
164 // operand in register number. Returns operand as floating point number
166 static void LoadFloatOperand(MacroAssembler* masm, Register number);
168 // Test if operands are smi or number objects (fp). Requirements:
169 // operand_1 in eax, operand_2 in edx; falls through on float
170 // operands, jumps to the non_float label otherwise.
171 static void CheckFloatOperands(MacroAssembler* masm,
177 void DoubleToIStub::Generate(MacroAssembler* masm) {
178 Register input_reg = this->source();
179 Register final_result_reg = this->destination();
180 DCHECK(is_truncating());
182 Label check_negative, process_64_bits, done, done_no_stash;
184 int double_offset = offset();
186 // Account for return address and saved regs if input is esp.
187 if (input_reg.is(esp)) double_offset += 3 * kPointerSize;
189 MemOperand mantissa_operand(MemOperand(input_reg, double_offset));
190 MemOperand exponent_operand(MemOperand(input_reg,
191 double_offset + kDoubleSize / 2));
195 Register scratch_candidates[3] = { ebx, edx, edi };
196 for (int i = 0; i < 3; i++) {
197 scratch1 = scratch_candidates[i];
198 if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break;
201 // Since we must use ecx for shifts below, use some other register (eax)
202 // to calculate the result if ecx is the requested return register.
203 Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg;
204 // Save ecx if it isn't the return register and therefore volatile, or if it
205 // is the return register, then save the temp register we use in its stead for
207 Register save_reg = final_result_reg.is(ecx) ? eax : ecx;
211 bool stash_exponent_copy = !input_reg.is(esp);
212 __ mov(scratch1, mantissa_operand);
213 __ mov(ecx, exponent_operand);
214 if (stash_exponent_copy) __ push(ecx);
216 __ and_(ecx, HeapNumber::kExponentMask);
217 __ shr(ecx, HeapNumber::kExponentShift);
218 __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias));
219 __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits));
220 __ j(below, &process_64_bits);
222 // Result is entirely in lower 32-bits of mantissa
223 int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize;
224 __ sub(ecx, Immediate(delta));
225 __ xor_(result_reg, result_reg);
226 __ cmp(ecx, Immediate(31));
229 __ jmp(&check_negative);
231 __ bind(&process_64_bits);
232 // Result must be extracted from shifted 32-bit mantissa
233 __ sub(ecx, Immediate(delta));
235 if (stash_exponent_copy) {
236 __ mov(result_reg, MemOperand(esp, 0));
238 __ mov(result_reg, exponent_operand);
241 Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32)));
243 Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32)));
244 __ shrd(result_reg, scratch1);
245 __ shr_cl(result_reg);
246 __ test(ecx, Immediate(32));
249 __ j(equal, &skip_mov, Label::kNear);
250 __ mov(scratch1, result_reg);
254 // If the double was negative, negate the integer result.
255 __ bind(&check_negative);
256 __ mov(result_reg, scratch1);
258 if (stash_exponent_copy) {
259 __ cmp(MemOperand(esp, 0), Immediate(0));
261 __ cmp(exponent_operand, Immediate(0));
265 __ j(less_equal, &skip_mov, Label::kNear);
266 __ mov(result_reg, scratch1);
272 if (stash_exponent_copy) {
273 __ add(esp, Immediate(kDoubleSize / 2));
275 __ bind(&done_no_stash);
276 if (!final_result_reg.is(result_reg)) {
277 DCHECK(final_result_reg.is(ecx));
278 __ mov(final_result_reg, result_reg);
286 void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm,
288 Label load_smi, done;
290 __ JumpIfSmi(number, &load_smi, Label::kNear);
291 __ fld_d(FieldOperand(number, HeapNumber::kValueOffset));
292 __ jmp(&done, Label::kNear);
297 __ fild_s(Operand(esp, 0));
304 void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm,
307 Label test_other, done;
308 // Test if both operands are floats or smi -> scratch=k_is_float;
309 // Otherwise scratch = k_not_float.
310 __ JumpIfSmi(edx, &test_other, Label::kNear);
311 __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset));
312 Factory* factory = masm->isolate()->factory();
313 __ cmp(scratch, factory->heap_number_map());
314 __ j(not_equal, non_float); // argument in edx is not a number -> NaN
316 __ bind(&test_other);
317 __ JumpIfSmi(eax, &done, Label::kNear);
318 __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset));
319 __ cmp(scratch, factory->heap_number_map());
320 __ j(not_equal, non_float); // argument in eax is not a number -> NaN
322 // Fall-through: Both operands are numbers.
327 void MathPowStub::Generate(MacroAssembler* masm) {
333 void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
335 Register receiver = LoadDescriptor::ReceiverRegister();
336 // With careful management, we won't have to save slot and vector on
337 // the stack. Simply handle the possibly missing case first.
338 // TODO(mvstanton): this code can be more efficient.
339 __ cmp(FieldOperand(receiver, JSFunction::kPrototypeOrInitialMapOffset),
340 Immediate(isolate()->factory()->the_hole_value()));
342 __ TryGetFunctionPrototype(receiver, eax, ebx, &miss);
346 PropertyAccessCompiler::TailCallBuiltin(
347 masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
351 void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
352 // Return address is on the stack.
355 Register receiver = LoadDescriptor::ReceiverRegister();
356 Register key = LoadDescriptor::NameRegister();
357 Register scratch = eax;
358 DCHECK(!scratch.is(receiver) && !scratch.is(key));
360 // Check that the key is an array index, that is Uint32.
361 __ test(key, Immediate(kSmiTagMask | kSmiSignMask));
362 __ j(not_zero, &slow);
364 // Everything is fine, call runtime.
366 __ push(receiver); // receiver
368 __ push(scratch); // return address
370 // Perform tail call to the entry.
371 ExternalReference ref = ExternalReference(
372 IC_Utility(IC::kLoadElementWithInterceptor), masm->isolate());
373 __ TailCallExternalReference(ref, 2, 1);
376 PropertyAccessCompiler::TailCallBuiltin(
377 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
381 void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
382 // Return address is on the stack.
385 Register receiver = LoadDescriptor::ReceiverRegister();
386 Register index = LoadDescriptor::NameRegister();
387 Register scratch = edi;
388 DCHECK(!scratch.is(receiver) && !scratch.is(index));
389 Register result = eax;
390 DCHECK(!result.is(scratch));
391 DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) &&
392 result.is(LoadDescriptor::SlotRegister()));
394 // StringCharAtGenerator doesn't use the result register until it's passed
395 // the different miss possibilities. If it did, we would have a conflict
396 // when FLAG_vector_ics is true.
398 StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
399 &miss, // When not a string.
400 &miss, // When not a number.
401 &miss, // When index out of range.
402 STRING_INDEX_IS_ARRAY_INDEX,
404 char_at_generator.GenerateFast(masm);
407 StubRuntimeCallHelper call_helper;
408 char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper);
411 PropertyAccessCompiler::TailCallBuiltin(
412 masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
416 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
417 // The key is in edx and the parameter count is in eax.
418 DCHECK(edx.is(ArgumentsAccessReadDescriptor::index()));
419 DCHECK(eax.is(ArgumentsAccessReadDescriptor::parameter_count()));
421 // The displacement is used for skipping the frame pointer on the
422 // stack. It is the offset of the last parameter (if any) relative
423 // to the frame pointer.
424 static const int kDisplacement = 1 * kPointerSize;
426 // Check that the key is a smi.
428 __ JumpIfNotSmi(edx, &slow, Label::kNear);
430 // Check if the calling frame is an arguments adaptor frame.
432 __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
433 __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset));
434 __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
435 __ j(equal, &adaptor, Label::kNear);
437 // Check index against formal parameters count limit passed in
438 // through register eax. Use unsigned comparison to get negative
441 __ j(above_equal, &slow, Label::kNear);
443 // Read the argument from the stack and return it.
444 STATIC_ASSERT(kSmiTagSize == 1);
445 STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these.
446 __ lea(ebx, Operand(ebp, eax, times_2, 0));
448 __ mov(eax, Operand(ebx, edx, times_2, kDisplacement));
451 // Arguments adaptor case: Check index against actual arguments
452 // limit found in the arguments adaptor frame. Use unsigned
453 // comparison to get negative check for free.
455 __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset));
457 __ j(above_equal, &slow, Label::kNear);
459 // Read the argument from the stack and return it.
460 STATIC_ASSERT(kSmiTagSize == 1);
461 STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these.
462 __ lea(ebx, Operand(ebx, ecx, times_2, 0));
464 __ mov(eax, Operand(ebx, edx, times_2, kDisplacement));
467 // Slow-case: Handle non-smi or out-of-bounds access to arguments
468 // by calling the runtime system.
470 __ pop(ebx); // Return address.
473 __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
477 void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
478 // esp[0] : return address
479 // esp[4] : number of parameters
480 // esp[8] : receiver displacement
481 // esp[12] : function
483 // Check if the calling frame is an arguments adaptor frame.
485 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
486 __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
487 __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
488 __ j(not_equal, &runtime, Label::kNear);
490 // Patch the arguments.length and the parameters pointer.
491 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
492 __ mov(Operand(esp, 1 * kPointerSize), ecx);
493 __ lea(edx, Operand(edx, ecx, times_2,
494 StandardFrameConstants::kCallerSPOffset));
495 __ mov(Operand(esp, 2 * kPointerSize), edx);
498 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
502 void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
503 // esp[0] : return address
504 // esp[4] : number of parameters (tagged)
505 // esp[8] : receiver displacement
506 // esp[12] : function
508 // ebx = parameter count (tagged)
509 __ mov(ebx, Operand(esp, 1 * kPointerSize));
511 // Check if the calling frame is an arguments adaptor frame.
512 // TODO(rossberg): Factor out some of the bits that are shared with the other
513 // Generate* functions.
515 Label adaptor_frame, try_allocate;
516 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
517 __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
518 __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
519 __ j(equal, &adaptor_frame, Label::kNear);
521 // No adaptor, parameter count = argument count.
523 __ jmp(&try_allocate, Label::kNear);
525 // We have an adaptor frame. Patch the parameters pointer.
526 __ bind(&adaptor_frame);
527 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
528 __ lea(edx, Operand(edx, ecx, times_2,
529 StandardFrameConstants::kCallerSPOffset));
530 __ mov(Operand(esp, 2 * kPointerSize), edx);
532 // ebx = parameter count (tagged)
533 // ecx = argument count (smi-tagged)
534 // esp[4] = parameter count (tagged)
535 // esp[8] = address of receiver argument
536 // Compute the mapped parameter count = min(ebx, ecx) in ebx.
538 __ j(less_equal, &try_allocate, Label::kNear);
541 __ bind(&try_allocate);
543 // Save mapped parameter count.
546 // Compute the sizes of backing store, parameter map, and arguments object.
547 // 1. Parameter map, has 2 extra words containing context and backing store.
548 const int kParameterMapHeaderSize =
549 FixedArray::kHeaderSize + 2 * kPointerSize;
550 Label no_parameter_map;
552 __ j(zero, &no_parameter_map, Label::kNear);
553 __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize));
554 __ bind(&no_parameter_map);
557 __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize));
559 // 3. Arguments object.
560 __ add(ebx, Immediate(Heap::kSloppyArgumentsObjectSize));
562 // Do the allocation of all three objects in one go.
563 __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT);
565 // eax = address of new object(s) (tagged)
566 // ecx = argument count (smi-tagged)
567 // esp[0] = mapped parameter count (tagged)
568 // esp[8] = parameter count (tagged)
569 // esp[12] = address of receiver argument
570 // Get the arguments map from the current native context into edi.
571 Label has_mapped_parameters, instantiate;
572 __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
573 __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset));
574 __ mov(ebx, Operand(esp, 0 * kPointerSize));
576 __ j(not_zero, &has_mapped_parameters, Label::kNear);
579 Operand(edi, Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX)));
580 __ jmp(&instantiate, Label::kNear);
582 __ bind(&has_mapped_parameters);
583 __ mov(edi, Operand(edi, Context::SlotOffset(
584 Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX)));
585 __ bind(&instantiate);
587 // eax = address of new object (tagged)
588 // ebx = mapped parameter count (tagged)
589 // ecx = argument count (smi-tagged)
590 // edi = address of arguments map (tagged)
591 // esp[0] = mapped parameter count (tagged)
592 // esp[8] = parameter count (tagged)
593 // esp[12] = address of receiver argument
594 // Copy the JS object part.
595 __ mov(FieldOperand(eax, JSObject::kMapOffset), edi);
596 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset),
597 masm->isolate()->factory()->empty_fixed_array());
598 __ mov(FieldOperand(eax, JSObject::kElementsOffset),
599 masm->isolate()->factory()->empty_fixed_array());
601 // Set up the callee in-object property.
602 STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
603 __ mov(edx, Operand(esp, 4 * kPointerSize));
604 __ AssertNotSmi(edx);
605 __ mov(FieldOperand(eax, JSObject::kHeaderSize +
606 Heap::kArgumentsCalleeIndex * kPointerSize),
609 // Use the length (smi tagged) and set that as an in-object property too.
611 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
612 __ mov(FieldOperand(eax, JSObject::kHeaderSize +
613 Heap::kArgumentsLengthIndex * kPointerSize),
616 // Set up the elements pointer in the allocated arguments object.
617 // If we allocated a parameter map, edi will point there, otherwise to the
619 __ lea(edi, Operand(eax, Heap::kSloppyArgumentsObjectSize));
620 __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi);
622 // eax = address of new object (tagged)
623 // ebx = mapped parameter count (tagged)
624 // ecx = argument count (tagged)
625 // edi = address of parameter map or backing store (tagged)
626 // esp[0] = mapped parameter count (tagged)
627 // esp[8] = parameter count (tagged)
628 // esp[12] = address of receiver argument
632 // Initialize parameter map. If there are no mapped arguments, we're done.
633 Label skip_parameter_map;
635 __ j(zero, &skip_parameter_map);
637 __ mov(FieldOperand(edi, FixedArray::kMapOffset),
638 Immediate(isolate()->factory()->sloppy_arguments_elements_map()));
639 __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2))));
640 __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax);
641 __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi);
642 __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize));
643 __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax);
645 // Copy the parameter slots and the holes in the arguments.
646 // We need to fill in mapped_parameter_count slots. They index the context,
647 // where parameters are stored in reverse order, at
648 // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
649 // The mapped parameter thus need to get indices
650 // MIN_CONTEXT_SLOTS+parameter_count-1 ..
651 // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
652 // We loop from right to left.
653 Label parameters_loop, parameters_test;
655 __ mov(eax, Operand(esp, 2 * kPointerSize));
656 __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
657 __ add(ebx, Operand(esp, 4 * kPointerSize));
659 __ mov(ecx, isolate()->factory()->the_hole_value());
661 __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize));
662 // eax = loop variable (tagged)
663 // ebx = mapping index (tagged)
664 // ecx = the hole value
665 // edx = address of parameter map (tagged)
666 // edi = address of backing store (tagged)
667 // esp[0] = argument count (tagged)
668 // esp[4] = address of new object (tagged)
669 // esp[8] = mapped parameter count (tagged)
670 // esp[16] = parameter count (tagged)
671 // esp[20] = address of receiver argument
672 __ jmp(¶meters_test, Label::kNear);
674 __ bind(¶meters_loop);
675 __ sub(eax, Immediate(Smi::FromInt(1)));
676 __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx);
677 __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx);
678 __ add(ebx, Immediate(Smi::FromInt(1)));
679 __ bind(¶meters_test);
681 __ j(not_zero, ¶meters_loop, Label::kNear);
684 __ bind(&skip_parameter_map);
686 // ecx = argument count (tagged)
687 // edi = address of backing store (tagged)
688 // esp[0] = address of new object (tagged)
689 // esp[4] = mapped parameter count (tagged)
690 // esp[12] = parameter count (tagged)
691 // esp[16] = address of receiver argument
692 // Copy arguments header and remaining slots (if there are any).
693 __ mov(FieldOperand(edi, FixedArray::kMapOffset),
694 Immediate(isolate()->factory()->fixed_array_map()));
695 __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx);
697 Label arguments_loop, arguments_test;
698 __ mov(ebx, Operand(esp, 1 * kPointerSize));
699 __ mov(edx, Operand(esp, 4 * kPointerSize));
700 __ sub(edx, ebx); // Is there a smarter way to do negative scaling?
702 __ jmp(&arguments_test, Label::kNear);
704 __ bind(&arguments_loop);
705 __ sub(edx, Immediate(kPointerSize));
706 __ mov(eax, Operand(edx, 0));
707 __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax);
708 __ add(ebx, Immediate(Smi::FromInt(1)));
710 __ bind(&arguments_test);
712 __ j(less, &arguments_loop, Label::kNear);
715 __ pop(eax); // Address of arguments object.
716 __ pop(ebx); // Parameter count.
718 // Return and remove the on-stack parameters.
719 __ ret(3 * kPointerSize);
721 // Do the runtime call to allocate the arguments object.
723 __ pop(eax); // Remove saved parameter count.
724 __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count.
725 __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
729 void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
730 // esp[0] : return address
731 // esp[4] : number of parameters
732 // esp[8] : receiver displacement
733 // esp[12] : function
735 // Check if the calling frame is an arguments adaptor frame.
736 Label adaptor_frame, try_allocate, runtime;
737 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
738 __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
739 __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
740 __ j(equal, &adaptor_frame, Label::kNear);
742 // Get the length from the frame.
743 __ mov(ecx, Operand(esp, 1 * kPointerSize));
744 __ jmp(&try_allocate, Label::kNear);
746 // Patch the arguments.length and the parameters pointer.
747 __ bind(&adaptor_frame);
748 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
750 __ lea(edx, Operand(edx, ecx, times_2,
751 StandardFrameConstants::kCallerSPOffset));
752 __ mov(Operand(esp, 1 * kPointerSize), ecx);
753 __ mov(Operand(esp, 2 * kPointerSize), edx);
755 // Try the new space allocation. Start out with computing the size of
756 // the arguments object and the elements array.
757 Label add_arguments_object;
758 __ bind(&try_allocate);
760 __ j(zero, &add_arguments_object, Label::kNear);
761 __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize));
762 __ bind(&add_arguments_object);
763 __ add(ecx, Immediate(Heap::kStrictArgumentsObjectSize));
765 // Do the allocation of both objects in one go.
766 __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT);
768 // Get the arguments map from the current native context.
769 __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
770 __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset));
771 const int offset = Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX);
772 __ mov(edi, Operand(edi, offset));
774 __ mov(FieldOperand(eax, JSObject::kMapOffset), edi);
775 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset),
776 masm->isolate()->factory()->empty_fixed_array());
777 __ mov(FieldOperand(eax, JSObject::kElementsOffset),
778 masm->isolate()->factory()->empty_fixed_array());
780 // Get the length (smi tagged) and set that as an in-object property too.
781 STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
782 __ mov(ecx, Operand(esp, 1 * kPointerSize));
784 __ mov(FieldOperand(eax, JSObject::kHeaderSize +
785 Heap::kArgumentsLengthIndex * kPointerSize),
788 // If there are no actual arguments, we're done.
791 __ j(zero, &done, Label::kNear);
793 // Get the parameters pointer from the stack.
794 __ mov(edx, Operand(esp, 2 * kPointerSize));
796 // Set up the elements pointer in the allocated arguments object and
797 // initialize the header in the elements fixed array.
798 __ lea(edi, Operand(eax, Heap::kStrictArgumentsObjectSize));
799 __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi);
800 __ mov(FieldOperand(edi, FixedArray::kMapOffset),
801 Immediate(isolate()->factory()->fixed_array_map()));
803 __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx);
804 // Untag the length for the loop below.
807 // Copy the fixed array slots.
810 __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver.
811 __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx);
812 __ add(edi, Immediate(kPointerSize));
813 __ sub(edx, Immediate(kPointerSize));
815 __ j(not_zero, &loop);
817 // Return and remove the on-stack parameters.
819 __ ret(3 * kPointerSize);
821 // Do the runtime call to allocate the arguments object.
823 __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
827 void RestParamAccessStub::GenerateNew(MacroAssembler* masm) {
828 // esp[0] : return address
829 // esp[4] : language mode
830 // esp[8] : index of rest parameter
831 // esp[12] : number of parameters
832 // esp[16] : receiver displacement
834 // Check if the calling frame is an arguments adaptor frame.
836 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
837 __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
838 __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
839 __ j(not_equal, &runtime);
841 // Patch the arguments.length and the parameters pointer.
842 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
843 __ mov(Operand(esp, 3 * kPointerSize), ecx);
844 __ lea(edx, Operand(edx, ecx, times_2,
845 StandardFrameConstants::kCallerSPOffset));
846 __ mov(Operand(esp, 4 * kPointerSize), edx);
849 __ TailCallRuntime(Runtime::kNewRestParam, 4, 1);
853 void RegExpExecStub::Generate(MacroAssembler* masm) {
854 // Just jump directly to runtime if native RegExp is not selected at compile
855 // time or if regexp entry in generated code is turned off runtime switch or
857 #ifdef V8_INTERPRETED_REGEXP
858 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
859 #else // V8_INTERPRETED_REGEXP
861 // Stack frame on entry.
862 // esp[0]: return address
863 // esp[4]: last_match_info (expected JSArray)
864 // esp[8]: previous index
865 // esp[12]: subject string
866 // esp[16]: JSRegExp object
868 static const int kLastMatchInfoOffset = 1 * kPointerSize;
869 static const int kPreviousIndexOffset = 2 * kPointerSize;
870 static const int kSubjectOffset = 3 * kPointerSize;
871 static const int kJSRegExpOffset = 4 * kPointerSize;
874 Factory* factory = isolate()->factory();
876 // Ensure that a RegExp stack is allocated.
877 ExternalReference address_of_regexp_stack_memory_address =
878 ExternalReference::address_of_regexp_stack_memory_address(isolate());
879 ExternalReference address_of_regexp_stack_memory_size =
880 ExternalReference::address_of_regexp_stack_memory_size(isolate());
881 __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size));
883 __ j(zero, &runtime);
885 // Check that the first argument is a JSRegExp object.
886 __ mov(eax, Operand(esp, kJSRegExpOffset));
887 STATIC_ASSERT(kSmiTag == 0);
888 __ JumpIfSmi(eax, &runtime);
889 __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx);
890 __ j(not_equal, &runtime);
892 // Check that the RegExp has been compiled (data contains a fixed array).
893 __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset));
894 if (FLAG_debug_code) {
895 __ test(ecx, Immediate(kSmiTagMask));
896 __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected);
897 __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx);
898 __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected);
901 // ecx: RegExp data (FixedArray)
902 // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
903 __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset));
904 __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP)));
905 __ j(not_equal, &runtime);
907 // ecx: RegExp data (FixedArray)
908 // Check that the number of captures fit in the static offsets vector buffer.
909 __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset));
910 // Check (number_of_captures + 1) * 2 <= offsets vector size
911 // Or number_of_captures * 2 <= offsets vector size - 2
912 // Multiplying by 2 comes for free since edx is smi-tagged.
913 STATIC_ASSERT(kSmiTag == 0);
914 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
915 STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
916 __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2);
917 __ j(above, &runtime);
919 // Reset offset for possibly sliced string.
920 __ Move(edi, Immediate(0));
921 __ mov(eax, Operand(esp, kSubjectOffset));
922 __ JumpIfSmi(eax, &runtime);
923 __ mov(edx, eax); // Make a copy of the original subject string.
924 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
925 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
927 // eax: subject string
928 // edx: subject string
929 // ebx: subject string instance type
930 // ecx: RegExp data (FixedArray)
931 // Handle subject string according to its encoding and representation:
932 // (1) Sequential two byte? If yes, go to (9).
933 // (2) Sequential one byte? If yes, go to (6).
934 // (3) Anything but sequential or cons? If yes, go to (7).
935 // (4) Cons string. If the string is flat, replace subject with first string.
936 // Otherwise bailout.
937 // (5a) Is subject sequential two byte? If yes, go to (9).
938 // (5b) Is subject external? If yes, go to (8).
939 // (6) One byte sequential. Load regexp code for one byte.
943 // Deferred code at the end of the stub:
944 // (7) Not a long external string? If yes, go to (10).
945 // (8) External string. Make it, offset-wise, look like a sequential string.
946 // (8a) Is the external string one byte? If yes, go to (6).
947 // (9) Two byte sequential. Load regexp code for one byte. Go to (E).
948 // (10) Short external string or not a string? If yes, bail out to runtime.
949 // (11) Sliced string. Replace subject with parent. Go to (5a).
951 Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */,
952 external_string /* 8 */, check_underlying /* 5a */,
953 not_seq_nor_cons /* 7 */, check_code /* E */,
954 not_long_external /* 10 */;
956 // (1) Sequential two byte? If yes, go to (9).
957 __ and_(ebx, kIsNotStringMask |
958 kStringRepresentationMask |
959 kStringEncodingMask |
960 kShortExternalStringMask);
961 STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0);
962 __ j(zero, &seq_two_byte_string); // Go to (9).
964 // (2) Sequential one byte? If yes, go to (6).
965 // Any other sequential string must be one byte.
966 __ and_(ebx, Immediate(kIsNotStringMask |
967 kStringRepresentationMask |
968 kShortExternalStringMask));
969 __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6).
971 // (3) Anything but sequential or cons? If yes, go to (7).
972 // We check whether the subject string is a cons, since sequential strings
973 // have already been covered.
974 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
975 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
976 STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
977 STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
978 __ cmp(ebx, Immediate(kExternalStringTag));
979 __ j(greater_equal, ¬_seq_nor_cons); // Go to (7).
981 // (4) Cons string. Check that it's flat.
982 // Replace subject with first string and reload instance type.
983 __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string());
984 __ j(not_equal, &runtime);
985 __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset));
986 __ bind(&check_underlying);
987 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
988 __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
990 // (5a) Is subject sequential two byte? If yes, go to (9).
991 __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask);
992 STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0);
993 __ j(zero, &seq_two_byte_string); // Go to (9).
994 // (5b) Is subject external? If yes, go to (8).
995 __ test_b(ebx, kStringRepresentationMask);
996 // The underlying external string is never a short external string.
997 STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
998 STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
999 __ j(not_zero, &external_string); // Go to (8).
1001 // eax: sequential subject string (or look-alike, external string)
1002 // edx: original subject string
1003 // ecx: RegExp data (FixedArray)
1004 // (6) One byte sequential. Load regexp code for one byte.
1005 __ bind(&seq_one_byte_string);
1006 // Load previous index and check range before edx is overwritten. We have
1007 // to use edx instead of eax here because it might have been only made to
1008 // look like a sequential string when it actually is an external string.
1009 __ mov(ebx, Operand(esp, kPreviousIndexOffset));
1010 __ JumpIfNotSmi(ebx, &runtime);
1011 __ cmp(ebx, FieldOperand(edx, String::kLengthOffset));
1012 __ j(above_equal, &runtime);
1013 __ mov(edx, FieldOperand(ecx, JSRegExp::kDataOneByteCodeOffset));
1014 __ Move(ecx, Immediate(1)); // Type is one byte.
1016 // (E) Carry on. String handling is done.
1017 __ bind(&check_code);
1018 // edx: irregexp code
1019 // Check that the irregexp code has been generated for the actual string
1020 // encoding. If it has, the field contains a code object otherwise it contains
1021 // a smi (code flushing support).
1022 __ JumpIfSmi(edx, &runtime);
1024 // eax: subject string
1025 // ebx: previous index (smi)
1027 // ecx: encoding of subject string (1 if one_byte, 0 if two_byte);
1028 // All checks done. Now push arguments for native regexp code.
1029 Counters* counters = isolate()->counters();
1030 __ IncrementCounter(counters->regexp_entry_native(), 1);
1032 // Isolates: note we add an additional parameter here (isolate pointer).
1033 static const int kRegExpExecuteArguments = 9;
1034 __ EnterApiExitFrame(kRegExpExecuteArguments);
1036 // Argument 9: Pass current isolate address.
1037 __ mov(Operand(esp, 8 * kPointerSize),
1038 Immediate(ExternalReference::isolate_address(isolate())));
1040 // Argument 8: Indicate that this is a direct call from JavaScript.
1041 __ mov(Operand(esp, 7 * kPointerSize), Immediate(1));
1043 // Argument 7: Start (high end) of backtracking stack memory area.
1044 __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address));
1045 __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size));
1046 __ mov(Operand(esp, 6 * kPointerSize), esi);
1048 // Argument 6: Set the number of capture registers to zero to force global
1049 // regexps to behave as non-global. This does not affect non-global regexps.
1050 __ mov(Operand(esp, 5 * kPointerSize), Immediate(0));
1052 // Argument 5: static offsets vector buffer.
1053 __ mov(Operand(esp, 4 * kPointerSize),
1054 Immediate(ExternalReference::address_of_static_offsets_vector(
1057 // Argument 2: Previous index.
1059 __ mov(Operand(esp, 1 * kPointerSize), ebx);
1061 // Argument 1: Original subject string.
1062 // The original subject is in the previous stack frame. Therefore we have to
1063 // use ebp, which points exactly to one pointer size below the previous esp.
1064 // (Because creating a new stack frame pushes the previous ebp onto the stack
1065 // and thereby moves up esp by one kPointerSize.)
1066 __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize));
1067 __ mov(Operand(esp, 0 * kPointerSize), esi);
1069 // esi: original subject string
1070 // eax: underlying subject string
1071 // ebx: previous index
1072 // ecx: encoding of subject string (1 if one_byte 0 if two_byte);
1074 // Argument 4: End of string data
1075 // Argument 3: Start of string data
1076 // Prepare start and end index of the input.
1077 // Load the length from the original sliced string if that is the case.
1078 __ mov(esi, FieldOperand(esi, String::kLengthOffset));
1079 __ add(esi, edi); // Calculate input end wrt offset.
1081 __ add(ebx, edi); // Calculate input start wrt offset.
1083 // ebx: start index of the input string
1084 // esi: end index of the input string
1085 Label setup_two_byte, setup_rest;
1087 __ j(zero, &setup_two_byte, Label::kNear);
1089 __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize));
1090 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4.
1091 __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize));
1092 __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3.
1093 __ jmp(&setup_rest, Label::kNear);
1095 __ bind(&setup_two_byte);
1096 STATIC_ASSERT(kSmiTag == 0);
1097 STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2).
1098 __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize));
1099 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4.
1100 __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize));
1101 __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3.
1103 __ bind(&setup_rest);
1105 // Locate the code entry and call it.
1106 __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag));
1109 // Drop arguments and come back to JS mode.
1110 __ LeaveApiExitFrame(true);
1112 // Check the result.
1115 // We expect exactly one result since we force the called regexp to behave
1117 __ j(equal, &success);
1119 __ cmp(eax, NativeRegExpMacroAssembler::FAILURE);
1120 __ j(equal, &failure);
1121 __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION);
1122 // If not exception it can only be retry. Handle that in the runtime system.
1123 __ j(not_equal, &runtime);
1124 // Result must now be exception. If there is no pending exception already a
1125 // stack overflow (on the backtrack stack) was detected in RegExp code but
1126 // haven't created the exception yet. Handle that in the runtime system.
1127 // TODO(592): Rerunning the RegExp to get the stack overflow exception.
1128 ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
1130 __ mov(edx, Immediate(isolate()->factory()->the_hole_value()));
1131 __ mov(eax, Operand::StaticVariable(pending_exception));
1133 __ j(equal, &runtime);
1135 // For exception, throw the exception again.
1136 __ TailCallRuntime(Runtime::kRegExpExecReThrow, 4, 1);
1139 // For failure to match, return null.
1140 __ mov(eax, factory->null_value());
1141 __ ret(4 * kPointerSize);
1143 // Load RegExp data.
1145 __ mov(eax, Operand(esp, kJSRegExpOffset));
1146 __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset));
1147 __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset));
1148 // Calculate number of capture registers (number_of_captures + 1) * 2.
1149 STATIC_ASSERT(kSmiTag == 0);
1150 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
1151 __ add(edx, Immediate(2)); // edx was a smi.
1153 // edx: Number of capture registers
1154 // Load last_match_info which is still known to be a fast case JSArray.
1155 // Check that the fourth object is a JSArray object.
1156 __ mov(eax, Operand(esp, kLastMatchInfoOffset));
1157 __ JumpIfSmi(eax, &runtime);
1158 __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx);
1159 __ j(not_equal, &runtime);
1160 // Check that the JSArray is in fast case.
1161 __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset));
1162 __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset));
1163 __ cmp(eax, factory->fixed_array_map());
1164 __ j(not_equal, &runtime);
1165 // Check that the last match info has space for the capture registers and the
1166 // additional information.
1167 __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset));
1169 __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead));
1171 __ j(greater, &runtime);
1173 // ebx: last_match_info backing store (FixedArray)
1174 // edx: number of capture registers
1175 // Store the capture count.
1176 __ SmiTag(edx); // Number of capture registers to smi.
1177 __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx);
1178 __ SmiUntag(edx); // Number of capture registers back from smi.
1179 // Store last subject and last input.
1180 __ mov(eax, Operand(esp, kSubjectOffset));
1182 __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax);
1183 __ RecordWriteField(ebx, RegExpImpl::kLastSubjectOffset, eax, edi,
1186 __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax);
1187 __ RecordWriteField(ebx, RegExpImpl::kLastInputOffset, eax, edi,
1190 // Get the static offsets vector filled by the native regexp code.
1191 ExternalReference address_of_static_offsets_vector =
1192 ExternalReference::address_of_static_offsets_vector(isolate());
1193 __ mov(ecx, Immediate(address_of_static_offsets_vector));
1195 // ebx: last_match_info backing store (FixedArray)
1196 // ecx: offsets vector
1197 // edx: number of capture registers
1198 Label next_capture, done;
1199 // Capture register counter starts from number of capture registers and
1200 // counts down until wraping after zero.
1201 __ bind(&next_capture);
1202 __ sub(edx, Immediate(1));
1203 __ j(negative, &done, Label::kNear);
1204 // Read the value from the static offsets vector buffer.
1205 __ mov(edi, Operand(ecx, edx, times_int_size, 0));
1207 // Store the smi value in the last match info.
1208 __ mov(FieldOperand(ebx,
1211 RegExpImpl::kFirstCaptureOffset),
1213 __ jmp(&next_capture);
1216 // Return last match info.
1217 __ mov(eax, Operand(esp, kLastMatchInfoOffset));
1218 __ ret(4 * kPointerSize);
1220 // Do the runtime call to execute the regexp.
1222 __ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
1224 // Deferred code for string handling.
1225 // (7) Not a long external string? If yes, go to (10).
1226 __ bind(¬_seq_nor_cons);
1227 // Compare flags are still set from (3).
1228 __ j(greater, ¬_long_external, Label::kNear); // Go to (10).
1230 // (8) External string. Short external strings have been ruled out.
1231 __ bind(&external_string);
1232 // Reload instance type.
1233 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
1234 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
1235 if (FLAG_debug_code) {
1236 // Assert that we do not have a cons or slice (indirect strings) here.
1237 // Sequential strings have already been ruled out.
1238 __ test_b(ebx, kIsIndirectStringMask);
1239 __ Assert(zero, kExternalStringExpectedButNotFound);
1241 __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset));
1242 // Move the pointer so that offset-wise, it looks like a sequential string.
1243 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
1244 __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
1245 STATIC_ASSERT(kTwoByteStringTag == 0);
1246 // (8a) Is the external string one byte? If yes, go to (6).
1247 __ test_b(ebx, kStringEncodingMask);
1248 __ j(not_zero, &seq_one_byte_string); // Goto (6).
1250 // eax: sequential subject string (or look-alike, external string)
1251 // edx: original subject string
1252 // ecx: RegExp data (FixedArray)
1253 // (9) Two byte sequential. Load regexp code for one byte. Go to (E).
1254 __ bind(&seq_two_byte_string);
1255 // Load previous index and check range before edx is overwritten. We have
1256 // to use edx instead of eax here because it might have been only made to
1257 // look like a sequential string when it actually is an external string.
1258 __ mov(ebx, Operand(esp, kPreviousIndexOffset));
1259 __ JumpIfNotSmi(ebx, &runtime);
1260 __ cmp(ebx, FieldOperand(edx, String::kLengthOffset));
1261 __ j(above_equal, &runtime);
1262 __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset));
1263 __ Move(ecx, Immediate(0)); // Type is two byte.
1264 __ jmp(&check_code); // Go to (E).
1266 // (10) Not a string or a short external string? If yes, bail out to runtime.
1267 __ bind(¬_long_external);
1268 // Catch non-string subject or short external string.
1269 STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
1270 __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag));
1271 __ j(not_zero, &runtime);
1273 // (11) Sliced string. Replace subject with parent. Go to (5a).
1274 // Load offset into edi and replace subject string with parent.
1275 __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset));
1276 __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset));
1277 __ jmp(&check_underlying); // Go to (5a).
1278 #endif // V8_INTERPRETED_REGEXP
1282 static int NegativeComparisonResult(Condition cc) {
1283 DCHECK(cc != equal);
1284 DCHECK((cc == less) || (cc == less_equal)
1285 || (cc == greater) || (cc == greater_equal));
1286 return (cc == greater || cc == greater_equal) ? LESS : GREATER;
1290 static void CheckInputType(MacroAssembler* masm, Register input,
1291 CompareICState::State expected, Label* fail) {
1293 if (expected == CompareICState::SMI) {
1294 __ JumpIfNotSmi(input, fail);
1295 } else if (expected == CompareICState::NUMBER) {
1296 __ JumpIfSmi(input, &ok);
1297 __ cmp(FieldOperand(input, HeapObject::kMapOffset),
1298 Immediate(masm->isolate()->factory()->heap_number_map()));
1299 __ j(not_equal, fail);
1301 // We could be strict about internalized/non-internalized here, but as long as
1302 // hydrogen doesn't care, the stub doesn't have to care either.
1307 static void BranchIfNotInternalizedString(MacroAssembler* masm,
1311 __ JumpIfSmi(object, label);
1312 __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset));
1313 __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
1314 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
1315 __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
1316 __ j(not_zero, label);
1320 void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
1321 Label runtime_call, check_unequal_objects;
1322 Condition cc = GetCondition();
1325 CheckInputType(masm, edx, left(), &miss);
1326 CheckInputType(masm, eax, right(), &miss);
1328 // Compare two smis.
1329 Label non_smi, smi_done;
1332 __ JumpIfNotSmi(ecx, &non_smi, Label::kNear);
1333 __ sub(edx, eax); // Return on the result of the subtraction.
1334 __ j(no_overflow, &smi_done, Label::kNear);
1335 __ not_(edx); // Correct sign in case of overflow. edx is never 0 here.
1341 // NOTICE! This code is only reached after a smi-fast-case check, so
1342 // it is certain that at least one operand isn't a smi.
1344 // Identical objects can be compared fast, but there are some tricky cases
1345 // for NaN and undefined.
1346 Label generic_heap_number_comparison;
1348 Label not_identical;
1350 __ j(not_equal, ¬_identical);
1353 // Check for undefined. undefined OP undefined is false even though
1354 // undefined == undefined.
1355 __ cmp(edx, isolate()->factory()->undefined_value());
1356 if (is_strong(strength())) {
1357 // In strong mode, this comparison must throw, so call the runtime.
1358 __ j(equal, &runtime_call, Label::kFar);
1360 Label check_for_nan;
1361 __ j(not_equal, &check_for_nan, Label::kNear);
1362 __ Move(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc))));
1364 __ bind(&check_for_nan);
1368 // Test for NaN. Compare heap numbers in a general way,
1369 // to handle NaNs correctly.
1370 __ cmp(FieldOperand(edx, HeapObject::kMapOffset),
1371 Immediate(isolate()->factory()->heap_number_map()));
1372 __ j(equal, &generic_heap_number_comparison, Label::kNear);
1374 __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset));
1375 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset));
1376 // Call runtime on identical JSObjects. Otherwise return equal.
1377 __ cmpb(ecx, static_cast<uint8_t>(FIRST_SPEC_OBJECT_TYPE));
1378 __ j(above_equal, &runtime_call, Label::kFar);
1379 // Call runtime on identical symbols since we need to throw a TypeError.
1380 __ cmpb(ecx, static_cast<uint8_t>(SYMBOL_TYPE));
1381 __ j(equal, &runtime_call, Label::kFar);
1382 // Call runtime on identical SIMD values since we must throw a TypeError.
1383 __ cmpb(ecx, static_cast<uint8_t>(FLOAT32X4_TYPE));
1384 __ j(equal, &runtime_call, Label::kFar);
1385 if (is_strong(strength())) {
1386 // We have already tested for smis and heap numbers, so if both
1387 // arguments are not strings we must proceed to the slow case.
1388 __ test(ecx, Immediate(kIsNotStringMask));
1389 __ j(not_zero, &runtime_call, Label::kFar);
1392 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
1396 __ bind(¬_identical);
1399 // Strict equality can quickly decide whether objects are equal.
1400 // Non-strict object equality is slower, so it is handled later in the stub.
1401 if (cc == equal && strict()) {
1402 Label slow; // Fallthrough label.
1404 // If we're doing a strict equality comparison, we don't have to do
1405 // type conversion, so we generate code to do fast comparison for objects
1406 // and oddballs. Non-smi numbers and strings still go through the usual
1408 // If either is a Smi (we know that not both are), then they can only
1409 // be equal if the other is a HeapNumber. If so, use the slow case.
1410 STATIC_ASSERT(kSmiTag == 0);
1411 DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0));
1412 __ mov(ecx, Immediate(kSmiTagMask));
1415 __ j(not_zero, ¬_smis, Label::kNear);
1416 // One operand is a smi.
1418 // Check whether the non-smi is a heap number.
1419 STATIC_ASSERT(kSmiTagMask == 1);
1420 // ecx still holds eax & kSmiTag, which is either zero or one.
1421 __ sub(ecx, Immediate(0x01));
1424 __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx.
1426 // if eax was smi, ebx is now edx, else eax.
1428 // Check if the non-smi operand is a heap number.
1429 __ cmp(FieldOperand(ebx, HeapObject::kMapOffset),
1430 Immediate(isolate()->factory()->heap_number_map()));
1431 // If heap number, handle it in the slow case.
1432 __ j(equal, &slow, Label::kNear);
1433 // Return non-equal (ebx is not zero)
1438 // If either operand is a JSObject or an oddball value, then they are not
1439 // equal since their pointers are different
1440 // There is no test for undetectability in strict equality.
1442 // Get the type of the first operand.
1443 // If the first object is a JS object, we have done pointer comparison.
1444 Label first_non_object;
1445 STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
1446 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
1447 __ j(below, &first_non_object, Label::kNear);
1449 // Return non-zero (eax is not zero)
1450 Label return_not_equal;
1451 STATIC_ASSERT(kHeapObjectTag != 0);
1452 __ bind(&return_not_equal);
1455 __ bind(&first_non_object);
1456 // Check for oddballs: true, false, null, undefined.
1457 __ CmpInstanceType(ecx, ODDBALL_TYPE);
1458 __ j(equal, &return_not_equal);
1460 __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx);
1461 __ j(above_equal, &return_not_equal);
1463 // Check for oddballs: true, false, null, undefined.
1464 __ CmpInstanceType(ecx, ODDBALL_TYPE);
1465 __ j(equal, &return_not_equal);
1467 // Fall through to the general case.
1471 // Generate the number comparison code.
1472 Label non_number_comparison;
1474 __ bind(&generic_heap_number_comparison);
1475 FloatingPointHelper::CheckFloatOperands(
1476 masm, &non_number_comparison, ebx);
1477 FloatingPointHelper::LoadFloatOperand(masm, eax);
1478 FloatingPointHelper::LoadFloatOperand(masm, edx);
1481 // Don't base result on EFLAGS when a NaN is involved.
1482 __ j(parity_even, &unordered, Label::kNear);
1484 Label below_label, above_label;
1485 // Return a result of -1, 0, or 1, based on EFLAGS.
1486 __ j(below, &below_label, Label::kNear);
1487 __ j(above, &above_label, Label::kNear);
1489 __ Move(eax, Immediate(0));
1492 __ bind(&below_label);
1493 __ mov(eax, Immediate(Smi::FromInt(-1)));
1496 __ bind(&above_label);
1497 __ mov(eax, Immediate(Smi::FromInt(1)));
1500 // If one of the numbers was NaN, then the result is always false.
1501 // The cc is never not-equal.
1502 __ bind(&unordered);
1503 DCHECK(cc != not_equal);
1504 if (cc == less || cc == less_equal) {
1505 __ mov(eax, Immediate(Smi::FromInt(1)));
1507 __ mov(eax, Immediate(Smi::FromInt(-1)));
1511 // The number comparison code did not provide a valid result.
1512 __ bind(&non_number_comparison);
1514 // Fast negative check for internalized-to-internalized equality.
1515 Label check_for_strings;
1517 BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx);
1518 BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx);
1520 // We've already checked for object identity, so if both operands
1521 // are internalized they aren't equal. Register eax already holds a
1522 // non-zero value, which indicates not equal, so just return.
1526 __ bind(&check_for_strings);
1528 __ JumpIfNotBothSequentialOneByteStrings(edx, eax, ecx, ebx,
1529 &check_unequal_objects);
1531 // Inline comparison of one-byte strings.
1533 StringHelper::GenerateFlatOneByteStringEquals(masm, edx, eax, ecx, ebx);
1535 StringHelper::GenerateCompareFlatOneByteStrings(masm, edx, eax, ecx, ebx,
1539 __ Abort(kUnexpectedFallThroughFromStringComparison);
1542 __ bind(&check_unequal_objects);
1543 if (cc == equal && !strict()) {
1544 // Non-strict equality. Objects are unequal if
1545 // they are both JSObjects and not undetectable,
1546 // and their pointers are different.
1547 Label return_unequal;
1548 // At most one is a smi, so we can test for smi by adding the two.
1549 // A smi plus a heap object has the low bit set, a heap object plus
1550 // a heap object has the low bit clear.
1551 STATIC_ASSERT(kSmiTag == 0);
1552 STATIC_ASSERT(kSmiTagMask == 1);
1553 __ lea(ecx, Operand(eax, edx, times_1, 0));
1554 __ test(ecx, Immediate(kSmiTagMask));
1555 __ j(not_zero, &runtime_call, Label::kNear);
1556 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
1557 __ j(below, &runtime_call, Label::kNear);
1558 __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx);
1559 __ j(below, &runtime_call, Label::kNear);
1560 // We do not bail out after this point. Both are JSObjects, and
1561 // they are equal if and only if both are undetectable.
1562 // The and of the undetectable flags is 1 if and only if they are equal.
1563 __ test_b(FieldOperand(ecx, Map::kBitFieldOffset),
1564 1 << Map::kIsUndetectable);
1565 __ j(zero, &return_unequal, Label::kNear);
1566 __ test_b(FieldOperand(ebx, Map::kBitFieldOffset),
1567 1 << Map::kIsUndetectable);
1568 __ j(zero, &return_unequal, Label::kNear);
1569 // The objects are both undetectable, so they both compare as the value
1570 // undefined, and are equal.
1571 __ Move(eax, Immediate(EQUAL));
1572 __ bind(&return_unequal);
1573 // Return non-equal by returning the non-zero object pointer in eax,
1574 // or return equal if we fell through to here.
1575 __ ret(0); // rax, rdx were pushed
1577 __ bind(&runtime_call);
1579 // Push arguments below the return address.
1584 // Figure out which native to call and setup the arguments.
1585 Builtins::JavaScript builtin;
1587 builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
1590 is_strong(strength()) ? Builtins::COMPARE_STRONG : Builtins::COMPARE;
1591 __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc))));
1594 // Restore return address on the stack.
1597 // Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
1598 // tagged as a small integer.
1599 __ InvokeBuiltin(builtin, JUMP_FUNCTION);
1606 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
1607 // eax : number of arguments to the construct function
1608 // ebx : Feedback vector
1609 // edx : slot in feedback vector (Smi)
1610 // edi : the function to call
1611 FrameScope scope(masm, StackFrame::INTERNAL);
1613 // Number-of-arguments register must be smi-tagged to call out.
1630 static void GenerateRecordCallTarget(MacroAssembler* masm) {
1631 // Cache the called function in a feedback vector slot. Cache states
1632 // are uninitialized, monomorphic (indicated by a JSFunction), and
1634 // eax : number of arguments to the construct function
1635 // ebx : Feedback vector
1636 // edx : slot in feedback vector (Smi)
1637 // edi : the function to call
1638 Isolate* isolate = masm->isolate();
1639 Label initialize, done, miss, megamorphic, not_array_function;
1641 // Load the cache state into ecx.
1642 __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size,
1643 FixedArray::kHeaderSize));
1645 // A monomorphic cache hit or an already megamorphic state: invoke the
1646 // function without changing the state.
1647 // We don't know if ecx is a WeakCell or a Symbol, but it's harmless to read
1648 // at this position in a symbol (see static asserts in
1649 // type-feedback-vector.h).
1650 Label check_allocation_site;
1651 __ cmp(edi, FieldOperand(ecx, WeakCell::kValueOffset));
1652 __ j(equal, &done, Label::kFar);
1653 __ CompareRoot(ecx, Heap::kmegamorphic_symbolRootIndex);
1654 __ j(equal, &done, Label::kFar);
1655 __ CompareRoot(FieldOperand(ecx, HeapObject::kMapOffset),
1656 Heap::kWeakCellMapRootIndex);
1657 __ j(not_equal, FLAG_pretenuring_call_new ? &miss : &check_allocation_site);
1659 // If the weak cell is cleared, we have a new chance to become monomorphic.
1660 __ JumpIfSmi(FieldOperand(ecx, WeakCell::kValueOffset), &initialize);
1661 __ jmp(&megamorphic);
1663 if (!FLAG_pretenuring_call_new) {
1664 __ bind(&check_allocation_site);
1665 // If we came here, we need to see if we are the array function.
1666 // If we didn't have a matching function, and we didn't find the megamorph
1667 // sentinel, then we have in the slot either some other function or an
1669 __ CompareRoot(FieldOperand(ecx, 0), Heap::kAllocationSiteMapRootIndex);
1670 __ j(not_equal, &miss);
1672 // Make sure the function is the Array() function
1673 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx);
1675 __ j(not_equal, &megamorphic);
1676 __ jmp(&done, Label::kFar);
1681 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
1683 __ CompareRoot(ecx, Heap::kuninitialized_symbolRootIndex);
1684 __ j(equal, &initialize);
1685 // MegamorphicSentinel is an immortal immovable object (undefined) so no
1686 // write-barrier is needed.
1687 __ bind(&megamorphic);
1689 FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize),
1690 Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate)));
1691 __ jmp(&done, Label::kFar);
1693 // An uninitialized cache is patched with the function or sentinel to
1694 // indicate the ElementsKind if function is the Array constructor.
1695 __ bind(&initialize);
1696 if (!FLAG_pretenuring_call_new) {
1697 // Make sure the function is the Array() function
1698 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx);
1700 __ j(not_equal, ¬_array_function);
1702 // The target function is the Array constructor,
1703 // Create an AllocationSite if we don't already have it, store it in the
1705 CreateAllocationSiteStub create_stub(isolate);
1706 CallStubInRecordCallTarget(masm, &create_stub);
1709 __ bind(¬_array_function);
1712 CreateWeakCellStub create_stub(isolate);
1713 CallStubInRecordCallTarget(masm, &create_stub);
1718 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
1719 // Do not transform the receiver for strict mode functions.
1720 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
1721 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kStrictModeByteOffset),
1722 1 << SharedFunctionInfo::kStrictModeBitWithinByte);
1723 __ j(not_equal, cont);
1725 // Do not transform the receiver for natives (shared already in ecx).
1726 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kNativeByteOffset),
1727 1 << SharedFunctionInfo::kNativeBitWithinByte);
1728 __ j(not_equal, cont);
1732 static void EmitSlowCase(Isolate* isolate,
1733 MacroAssembler* masm,
1735 Label* non_function) {
1736 // Check for function proxy.
1737 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE);
1738 __ j(not_equal, non_function);
1740 __ push(edi); // put proxy as additional argument under return address
1742 __ Move(eax, Immediate(argc + 1));
1743 __ Move(ebx, Immediate(0));
1744 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY);
1746 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline();
1747 __ jmp(adaptor, RelocInfo::CODE_TARGET);
1750 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
1751 // of the original receiver from the call site).
1752 __ bind(non_function);
1753 __ mov(Operand(esp, (argc + 1) * kPointerSize), edi);
1754 __ Move(eax, Immediate(argc));
1755 __ Move(ebx, Immediate(0));
1756 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION);
1757 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline();
1758 __ jmp(adaptor, RelocInfo::CODE_TARGET);
1762 static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
1763 // Wrap the receiver and patch it back onto the stack.
1764 { FrameScope frame_scope(masm, StackFrame::INTERNAL);
1767 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
1770 __ mov(Operand(esp, (argc + 1) * kPointerSize), eax);
1775 static void CallFunctionNoFeedback(MacroAssembler* masm,
1776 int argc, bool needs_checks,
1777 bool call_as_method) {
1778 // edi : the function to call
1779 Label slow, non_function, wrap, cont;
1782 // Check that the function really is a JavaScript function.
1783 __ JumpIfSmi(edi, &non_function);
1785 // Goto slow case if we do not have a function.
1786 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
1787 __ j(not_equal, &slow);
1790 // Fast-case: Just invoke the function.
1791 ParameterCount actual(argc);
1793 if (call_as_method) {
1795 EmitContinueIfStrictOrNative(masm, &cont);
1798 // Load the receiver from the stack.
1799 __ mov(eax, Operand(esp, (argc + 1) * kPointerSize));
1802 __ JumpIfSmi(eax, &wrap);
1804 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
1813 __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper());
1816 // Slow-case: Non-function called.
1818 // (non_function is bound in EmitSlowCase)
1819 EmitSlowCase(masm->isolate(), masm, argc, &non_function);
1822 if (call_as_method) {
1824 EmitWrapCase(masm, argc, &cont);
1829 void CallFunctionStub::Generate(MacroAssembler* masm) {
1830 CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
1834 void CallConstructStub::Generate(MacroAssembler* masm) {
1835 // eax : number of arguments
1836 // ebx : feedback vector
1837 // ecx : original constructor (for IsSuperConstructorCall)
1838 // edx : slot in feedback vector (Smi, for RecordCallTarget)
1839 // edi : constructor function
1840 Label slow, non_function_call;
1842 if (IsSuperConstructorCall()) {
1846 // Check that function is not a smi.
1847 __ JumpIfSmi(edi, &non_function_call);
1848 // Check that function is a JSFunction.
1849 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
1850 __ j(not_equal, &slow);
1852 if (RecordCallTarget()) {
1853 GenerateRecordCallTarget(masm);
1855 if (FLAG_pretenuring_call_new) {
1856 // Put the AllocationSite from the feedback vector into ebx.
1857 // By adding kPointerSize we encode that we know the AllocationSite
1858 // entry is at the feedback vector slot given by edx + 1.
1859 __ mov(ebx, FieldOperand(ebx, edx, times_half_pointer_size,
1860 FixedArray::kHeaderSize + kPointerSize));
1862 Label feedback_register_initialized;
1863 // Put the AllocationSite from the feedback vector into ebx, or undefined.
1864 __ mov(ebx, FieldOperand(ebx, edx, times_half_pointer_size,
1865 FixedArray::kHeaderSize));
1866 Handle<Map> allocation_site_map =
1867 isolate()->factory()->allocation_site_map();
1868 __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map));
1869 __ j(equal, &feedback_register_initialized);
1870 __ mov(ebx, isolate()->factory()->undefined_value());
1871 __ bind(&feedback_register_initialized);
1874 __ AssertUndefinedOrAllocationSite(ebx);
1877 if (IsSuperConstructorCall()) {
1880 // Pass original constructor to construct stub.
1884 // Jump to the function-specific construct stub.
1885 Register jmp_reg = ecx;
1886 __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
1887 __ mov(jmp_reg, FieldOperand(jmp_reg,
1888 SharedFunctionInfo::kConstructStubOffset));
1889 __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize));
1892 // edi: called object
1893 // eax: number of arguments
1895 // esp[0]: original receiver
1898 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE);
1899 __ j(not_equal, &non_function_call);
1900 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
1903 __ bind(&non_function_call);
1904 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
1906 if (IsSuperConstructorCall()) {
1909 // Set expected number of arguments to zero (not changing eax).
1910 __ Move(ebx, Immediate(0));
1911 Handle<Code> arguments_adaptor =
1912 isolate()->builtins()->ArgumentsAdaptorTrampoline();
1913 __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET);
1917 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
1918 __ mov(vector, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
1919 __ mov(vector, FieldOperand(vector, JSFunction::kSharedFunctionInfoOffset));
1920 __ mov(vector, FieldOperand(vector,
1921 SharedFunctionInfo::kFeedbackVectorOffset));
1925 void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
1930 int argc = arg_count();
1931 ParameterCount actual(argc);
1933 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx);
1935 __ j(not_equal, &miss);
1937 __ mov(eax, arg_count());
1938 __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size,
1939 FixedArray::kHeaderSize));
1941 // Verify that ecx contains an AllocationSite
1942 Factory* factory = masm->isolate()->factory();
1943 __ cmp(FieldOperand(ecx, HeapObject::kMapOffset),
1944 factory->allocation_site_map());
1945 __ j(not_equal, &miss);
1947 // Increment the call count for monomorphic function calls.
1948 __ add(FieldOperand(ebx, edx, times_half_pointer_size,
1949 FixedArray::kHeaderSize + kPointerSize),
1950 Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement)));
1954 ArrayConstructorStub stub(masm->isolate(), arg_count());
1955 __ TailCallStub(&stub);
1960 // The slow case, we need this no matter what to complete a call after a miss.
1961 CallFunctionNoFeedback(masm,
1971 void CallICStub::Generate(MacroAssembler* masm) {
1975 Isolate* isolate = masm->isolate();
1976 const int with_types_offset =
1977 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
1978 const int generic_offset =
1979 FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
1980 Label extra_checks_or_miss, slow_start;
1981 Label slow, non_function, wrap, cont;
1982 Label have_js_function;
1983 int argc = arg_count();
1984 ParameterCount actual(argc);
1986 // The checks. First, does edi match the recorded monomorphic target?
1987 __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size,
1988 FixedArray::kHeaderSize));
1990 // We don't know that we have a weak cell. We might have a private symbol
1991 // or an AllocationSite, but the memory is safe to examine.
1992 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to
1994 // WeakCell::kValueOffset - contains a JSFunction or Smi(0)
1995 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not
1996 // computed, meaning that it can't appear to be a pointer. If the low bit is
1997 // 0, then hash is computed, but the 0 bit prevents the field from appearing
1999 STATIC_ASSERT(WeakCell::kSize >= kPointerSize);
2000 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset ==
2001 WeakCell::kValueOffset &&
2002 WeakCell::kValueOffset == Symbol::kHashFieldSlot);
2004 __ cmp(edi, FieldOperand(ecx, WeakCell::kValueOffset));
2005 __ j(not_equal, &extra_checks_or_miss);
2007 // The compare above could have been a SMI/SMI comparison. Guard against this
2008 // convincing us that we have a monomorphic JSFunction.
2009 __ JumpIfSmi(edi, &extra_checks_or_miss);
2011 // Increment the call count for monomorphic function calls.
2012 __ add(FieldOperand(ebx, edx, times_half_pointer_size,
2013 FixedArray::kHeaderSize + kPointerSize),
2014 Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2016 __ bind(&have_js_function);
2017 if (CallAsMethod()) {
2018 EmitContinueIfStrictOrNative(masm, &cont);
2020 // Load the receiver from the stack.
2021 __ mov(eax, Operand(esp, (argc + 1) * kPointerSize));
2023 __ JumpIfSmi(eax, &wrap);
2025 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
2031 __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper());
2034 EmitSlowCase(isolate, masm, argc, &non_function);
2036 if (CallAsMethod()) {
2038 EmitWrapCase(masm, argc, &cont);
2041 __ bind(&extra_checks_or_miss);
2042 Label uninitialized, miss;
2044 __ cmp(ecx, Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate)));
2045 __ j(equal, &slow_start);
2047 // The following cases attempt to handle MISS cases without going to the
2049 if (FLAG_trace_ic) {
2053 __ cmp(ecx, Immediate(TypeFeedbackVector::UninitializedSentinel(isolate)));
2054 __ j(equal, &uninitialized);
2056 // We are going megamorphic. If the feedback is a JSFunction, it is fine
2057 // to handle it here. More complex cases are dealt with in the runtime.
2058 __ AssertNotSmi(ecx);
2059 __ CmpObjectType(ecx, JS_FUNCTION_TYPE, ecx);
2060 __ j(not_equal, &miss);
2062 FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize),
2063 Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate)));
2064 // We have to update statistics for runtime profiling.
2065 __ sub(FieldOperand(ebx, with_types_offset), Immediate(Smi::FromInt(1)));
2066 __ add(FieldOperand(ebx, generic_offset), Immediate(Smi::FromInt(1)));
2067 __ jmp(&slow_start);
2069 __ bind(&uninitialized);
2071 // We are going monomorphic, provided we actually have a JSFunction.
2072 __ JumpIfSmi(edi, &miss);
2074 // Goto miss case if we do not have a function.
2075 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
2076 __ j(not_equal, &miss);
2078 // Make sure the function is not the Array() function, which requires special
2079 // behavior on MISS.
2080 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx);
2085 __ add(FieldOperand(ebx, with_types_offset), Immediate(Smi::FromInt(1)));
2087 // Initialize the call counter.
2088 __ mov(FieldOperand(ebx, edx, times_half_pointer_size,
2089 FixedArray::kHeaderSize + kPointerSize),
2090 Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement)));
2092 // Store the function. Use a stub since we need a frame for allocation.
2097 FrameScope scope(masm, StackFrame::INTERNAL);
2098 CreateWeakCellStub create_stub(isolate);
2100 __ CallStub(&create_stub);
2104 __ jmp(&have_js_function);
2106 // We are here because tracing is on or we encountered a MISS case we can't
2112 __ bind(&slow_start);
2114 // Check that the function really is a JavaScript function.
2115 __ JumpIfSmi(edi, &non_function);
2117 // Goto slow case if we do not have a function.
2118 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
2119 __ j(not_equal, &slow);
2120 __ jmp(&have_js_function);
2127 void CallICStub::GenerateMiss(MacroAssembler* masm) {
2128 FrameScope scope(masm, StackFrame::INTERNAL);
2130 // Push the receiver and the function and feedback info.
2136 IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
2137 : IC::kCallIC_Customization_Miss;
2139 ExternalReference miss = ExternalReference(IC_Utility(id), masm->isolate());
2140 __ CallExternalReference(miss, 3);
2142 // Move result to edi and exit the internal frame.
2147 bool CEntryStub::NeedsImmovableCode() {
2152 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
2153 CEntryStub::GenerateAheadOfTime(isolate);
2154 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
2155 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
2156 // It is important that the store buffer overflow stubs are generated first.
2157 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
2158 CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
2159 CreateWeakCellStub::GenerateAheadOfTime(isolate);
2160 BinaryOpICStub::GenerateAheadOfTime(isolate);
2161 BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
2162 StoreFastElementStub::GenerateAheadOfTime(isolate);
2163 TypeofStub::GenerateAheadOfTime(isolate);
2167 void CodeStub::GenerateFPStubs(Isolate* isolate) {
2168 CEntryStub save_doubles(isolate, 1, kSaveFPRegs);
2169 // Stubs might already be in the snapshot, detect that and don't regenerate,
2170 // which would lead to code stub initialization state being messed up.
2171 Code* save_doubles_code;
2172 if (!save_doubles.FindCodeInCache(&save_doubles_code)) {
2173 save_doubles_code = *(save_doubles.GetCode());
2175 isolate->set_fp_stubs_generated(true);
2179 void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
2180 CEntryStub stub(isolate, 1, kDontSaveFPRegs);
2185 void CEntryStub::Generate(MacroAssembler* masm) {
2186 // eax: number of arguments including receiver
2187 // ebx: pointer to C function (C callee-saved)
2188 // ebp: frame pointer (restored after C call)
2189 // esp: stack pointer (restored after C call)
2190 // esi: current context (C callee-saved)
2191 // edi: JS function of the caller (C callee-saved)
2193 ProfileEntryHookStub::MaybeCallEntryHook(masm);
2195 // Enter the exit frame that transitions from JavaScript to C++.
2196 __ EnterExitFrame(save_doubles());
2198 // ebx: pointer to C function (C callee-saved)
2199 // ebp: frame pointer (restored after C call)
2200 // esp: stack pointer (restored after C call)
2201 // edi: number of arguments including receiver (C callee-saved)
2202 // esi: pointer to the first argument (C callee-saved)
2204 // Result returned in eax, or eax+edx if result size is 2.
2206 // Check stack alignment.
2207 if (FLAG_debug_code) {
2208 __ CheckStackAlignment();
2212 __ mov(Operand(esp, 0 * kPointerSize), edi); // argc.
2213 __ mov(Operand(esp, 1 * kPointerSize), esi); // argv.
2214 __ mov(Operand(esp, 2 * kPointerSize),
2215 Immediate(ExternalReference::isolate_address(isolate())));
2217 // Result is in eax or edx:eax - do not destroy these registers!
2219 // Check result for exception sentinel.
2220 Label exception_returned;
2221 __ cmp(eax, isolate()->factory()->exception());
2222 __ j(equal, &exception_returned);
2224 // Check that there is no pending exception, otherwise we
2225 // should have returned the exception sentinel.
2226 if (FLAG_debug_code) {
2228 __ mov(edx, Immediate(isolate()->factory()->the_hole_value()));
2230 ExternalReference pending_exception_address(
2231 Isolate::kPendingExceptionAddress, isolate());
2232 __ cmp(edx, Operand::StaticVariable(pending_exception_address));
2233 // Cannot use check here as it attempts to generate call into runtime.
2234 __ j(equal, &okay, Label::kNear);
2240 // Exit the JavaScript to C++ exit frame.
2241 __ LeaveExitFrame(save_doubles());
2244 // Handling of exception.
2245 __ bind(&exception_returned);
2247 ExternalReference pending_handler_context_address(
2248 Isolate::kPendingHandlerContextAddress, isolate());
2249 ExternalReference pending_handler_code_address(
2250 Isolate::kPendingHandlerCodeAddress, isolate());
2251 ExternalReference pending_handler_offset_address(
2252 Isolate::kPendingHandlerOffsetAddress, isolate());
2253 ExternalReference pending_handler_fp_address(
2254 Isolate::kPendingHandlerFPAddress, isolate());
2255 ExternalReference pending_handler_sp_address(
2256 Isolate::kPendingHandlerSPAddress, isolate());
2258 // Ask the runtime for help to determine the handler. This will set eax to
2259 // contain the current pending exception, don't clobber it.
2260 ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler,
2263 FrameScope scope(masm, StackFrame::MANUAL);
2264 __ PrepareCallCFunction(3, eax);
2265 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0)); // argc.
2266 __ mov(Operand(esp, 1 * kPointerSize), Immediate(0)); // argv.
2267 __ mov(Operand(esp, 2 * kPointerSize),
2268 Immediate(ExternalReference::isolate_address(isolate())));
2269 __ CallCFunction(find_handler, 3);
2272 // Retrieve the handler context, SP and FP.
2273 __ mov(esi, Operand::StaticVariable(pending_handler_context_address));
2274 __ mov(esp, Operand::StaticVariable(pending_handler_sp_address));
2275 __ mov(ebp, Operand::StaticVariable(pending_handler_fp_address));
2277 // If the handler is a JS frame, restore the context to the frame. Note that
2278 // the context will be set to (esi == 0) for non-JS frames.
2281 __ j(zero, &skip, Label::kNear);
2282 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi);
2285 // Compute the handler entry address and jump to it.
2286 __ mov(edi, Operand::StaticVariable(pending_handler_code_address));
2287 __ mov(edx, Operand::StaticVariable(pending_handler_offset_address));
2288 __ lea(edi, FieldOperand(edi, edx, times_1, Code::kHeaderSize));
2293 void JSEntryStub::Generate(MacroAssembler* masm) {
2294 Label invoke, handler_entry, exit;
2295 Label not_outermost_js, not_outermost_js_2;
2297 ProfileEntryHookStub::MaybeCallEntryHook(masm);
2303 // Push marker in two places.
2304 int marker = type();
2305 __ push(Immediate(Smi::FromInt(marker))); // context slot
2306 __ push(Immediate(Smi::FromInt(marker))); // function slot
2307 // Save callee-saved registers (C calling conventions).
2312 // Save copies of the top frame descriptor on the stack.
2313 ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate());
2314 __ push(Operand::StaticVariable(c_entry_fp));
2316 // If this is the outermost JS call, set js_entry_sp value.
2317 ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
2318 __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0));
2319 __ j(not_equal, ¬_outermost_js, Label::kNear);
2320 __ mov(Operand::StaticVariable(js_entry_sp), ebp);
2321 __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
2322 __ jmp(&invoke, Label::kNear);
2323 __ bind(¬_outermost_js);
2324 __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
2326 // Jump to a faked try block that does the invoke, with a faked catch
2327 // block that sets the pending exception.
2329 __ bind(&handler_entry);
2330 handler_offset_ = handler_entry.pos();
2331 // Caught exception: Store result (exception) in the pending exception
2332 // field in the JSEnv and return a failure sentinel.
2333 ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
2335 __ mov(Operand::StaticVariable(pending_exception), eax);
2336 __ mov(eax, Immediate(isolate()->factory()->exception()));
2339 // Invoke: Link this frame into the handler chain.
2341 __ PushStackHandler();
2343 // Clear any pending exceptions.
2344 __ mov(edx, Immediate(isolate()->factory()->the_hole_value()));
2345 __ mov(Operand::StaticVariable(pending_exception), edx);
2347 // Fake a receiver (NULL).
2348 __ push(Immediate(0)); // receiver
2350 // Invoke the function by calling through JS entry trampoline builtin and
2351 // pop the faked function when we return. Notice that we cannot store a
2352 // reference to the trampoline code directly in this stub, because the
2353 // builtin stubs may not have been generated yet.
2354 if (type() == StackFrame::ENTRY_CONSTRUCT) {
2355 ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
2357 __ mov(edx, Immediate(construct_entry));
2359 ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
2360 __ mov(edx, Immediate(entry));
2362 __ mov(edx, Operand(edx, 0)); // deref address
2363 __ lea(edx, FieldOperand(edx, Code::kHeaderSize));
2366 // Unlink this frame from the handler chain.
2367 __ PopStackHandler();
2370 // Check if the current stack frame is marked as the outermost JS frame.
2372 __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
2373 __ j(not_equal, ¬_outermost_js_2);
2374 __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0));
2375 __ bind(¬_outermost_js_2);
2377 // Restore the top frame descriptor from the stack.
2378 __ pop(Operand::StaticVariable(ExternalReference(
2379 Isolate::kCEntryFPAddress, isolate())));
2381 // Restore callee-saved registers (C calling conventions).
2385 __ add(esp, Immediate(2 * kPointerSize)); // remove markers
2387 // Restore frame pointer and return.
2393 // Generate stub code for instanceof.
2394 // This code can patch a call site inlined cache of the instance of check,
2395 // which looks like this.
2397 // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map>
2398 // 75 0a jne <some near label>
2399 // b8 XX XX XX XX mov eax, <the hole, patched to either true or false>
2401 // If call site patching is requested the stack will have the delta from the
2402 // return address to the cmp instruction just below the return address. This
2403 // also means that call site patching can only take place with arguments in
2404 // registers. TOS looks like this when call site patching is requested
2406 // esp[0] : return address
2407 // esp[4] : delta from return address to cmp instruction
2409 void InstanceofStub::Generate(MacroAssembler* masm) {
2410 // Call site inlining and patching implies arguments in registers.
2411 DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck());
2413 // Fixed register usage throughout the stub.
2414 Register object = eax; // Object (lhs).
2415 Register map = ebx; // Map of the object.
2416 Register function = edx; // Function (rhs).
2417 Register prototype = edi; // Prototype of the function.
2418 Register scratch = ecx;
2420 // Constants describing the call site code to patch.
2421 static const int kDeltaToCmpImmediate = 2;
2422 static const int kDeltaToMov = 8;
2423 static const int kDeltaToMovImmediate = 9;
2424 static const int8_t kCmpEdiOperandByte1 = bit_cast<int8_t, uint8_t>(0x3b);
2425 static const int8_t kCmpEdiOperandByte2 = bit_cast<int8_t, uint8_t>(0x3d);
2426 static const int8_t kMovEaxImmediateByte = bit_cast<int8_t, uint8_t>(0xb8);
2428 DCHECK_EQ(object.code(), InstanceofStub::left().code());
2429 DCHECK_EQ(function.code(), InstanceofStub::right().code());
2431 // Get the object and function - they are always both needed.
2432 Label slow, not_js_object;
2433 if (!HasArgsInRegisters()) {
2434 __ mov(object, Operand(esp, 2 * kPointerSize));
2435 __ mov(function, Operand(esp, 1 * kPointerSize));
2438 // Check that the left hand is a JS object.
2439 __ JumpIfSmi(object, ¬_js_object);
2440 __ IsObjectJSObjectType(object, map, scratch, ¬_js_object);
2442 // If there is a call site cache don't look in the global cache, but do the
2443 // real lookup and update the call site cache.
2444 if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
2445 // Look up the function and the map in the instanceof cache.
2447 __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex);
2448 __ j(not_equal, &miss, Label::kNear);
2449 __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex);
2450 __ j(not_equal, &miss, Label::kNear);
2451 __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex);
2452 __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
2456 // Get the prototype of the function.
2457 __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
2459 // Check that the function prototype is a JS object.
2460 __ JumpIfSmi(prototype, &slow);
2461 __ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
2463 // Update the global instanceof or call site inlined cache with the current
2464 // map and function. The cached answer will be set when it is known below.
2465 if (!HasCallSiteInlineCheck()) {
2466 __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex);
2467 __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex);
2469 // The constants for the code patching are based on no push instructions
2470 // at the call site.
2471 DCHECK(HasArgsInRegisters());
2472 // Get return address and delta to inlined map check.
2473 __ mov(scratch, Operand(esp, 0 * kPointerSize));
2474 __ sub(scratch, Operand(esp, 1 * kPointerSize));
2475 if (FLAG_debug_code) {
2476 __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1);
2477 __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1);
2478 __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2);
2479 __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2);
2481 __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate));
2482 __ mov(Operand(scratch, 0), map);
2484 // Scratch points at the cell payload. Calculate the start of the object.
2485 __ sub(scratch, Immediate(Cell::kValueOffset - 1));
2486 __ RecordWriteField(scratch, Cell::kValueOffset, map, function,
2487 kDontSaveFPRegs, OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
2491 // Loop through the prototype chain of the object looking for the function
2493 __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset));
2494 Label loop, is_instance, is_not_instance;
2496 __ cmp(scratch, prototype);
2497 __ j(equal, &is_instance, Label::kNear);
2498 Factory* factory = isolate()->factory();
2499 __ cmp(scratch, Immediate(factory->null_value()));
2500 __ j(equal, &is_not_instance, Label::kNear);
2501 __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
2502 __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset));
2505 __ bind(&is_instance);
2506 if (!HasCallSiteInlineCheck()) {
2507 __ mov(eax, Immediate(0));
2508 __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex);
2509 if (ReturnTrueFalseObject()) {
2510 __ mov(eax, factory->true_value());
2513 // Get return address and delta to inlined map check.
2514 __ mov(eax, factory->true_value());
2515 __ mov(scratch, Operand(esp, 0 * kPointerSize));
2516 __ sub(scratch, Operand(esp, 1 * kPointerSize));
2517 if (FLAG_debug_code) {
2518 __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte);
2519 __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov);
2521 __ mov(Operand(scratch, kDeltaToMovImmediate), eax);
2522 if (!ReturnTrueFalseObject()) {
2523 __ Move(eax, Immediate(0));
2526 __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
2528 __ bind(&is_not_instance);
2529 if (!HasCallSiteInlineCheck()) {
2530 __ mov(eax, Immediate(Smi::FromInt(1)));
2531 __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex);
2532 if (ReturnTrueFalseObject()) {
2533 __ mov(eax, factory->false_value());
2536 // Get return address and delta to inlined map check.
2537 __ mov(eax, factory->false_value());
2538 __ mov(scratch, Operand(esp, 0 * kPointerSize));
2539 __ sub(scratch, Operand(esp, 1 * kPointerSize));
2540 if (FLAG_debug_code) {
2541 __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte);
2542 __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov);
2544 __ mov(Operand(scratch, kDeltaToMovImmediate), eax);
2545 if (!ReturnTrueFalseObject()) {
2546 __ Move(eax, Immediate(Smi::FromInt(1)));
2549 __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
2551 Label object_not_null, object_not_null_or_smi;
2552 __ bind(¬_js_object);
2553 // Before null, smi and string value checks, check that the rhs is a function
2554 // as for a non-function rhs an exception needs to be thrown.
2555 __ JumpIfSmi(function, &slow, Label::kNear);
2556 __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch);
2557 __ j(not_equal, &slow, Label::kNear);
2559 // Null is not instance of anything.
2560 __ cmp(object, factory->null_value());
2561 __ j(not_equal, &object_not_null, Label::kNear);
2562 if (ReturnTrueFalseObject()) {
2563 __ mov(eax, factory->false_value());
2565 __ Move(eax, Immediate(Smi::FromInt(1)));
2567 __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
2569 __ bind(&object_not_null);
2570 // Smi values is not instance of anything.
2571 __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear);
2572 if (ReturnTrueFalseObject()) {
2573 __ mov(eax, factory->false_value());
2575 __ Move(eax, Immediate(Smi::FromInt(1)));
2577 __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
2579 __ bind(&object_not_null_or_smi);
2580 // String values is not instance of anything.
2581 Condition is_string = masm->IsObjectStringType(object, scratch, scratch);
2582 __ j(NegateCondition(is_string), &slow, Label::kNear);
2583 if (ReturnTrueFalseObject()) {
2584 __ mov(eax, factory->false_value());
2586 __ Move(eax, Immediate(Smi::FromInt(1)));
2588 __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
2590 // Slow-case: Go through the JavaScript implementation.
2592 if (!ReturnTrueFalseObject()) {
2593 // Tail call the builtin which returns 0 or 1.
2594 if (HasArgsInRegisters()) {
2595 // Push arguments below return address.
2601 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
2603 // Call the builtin and convert 0/1 to true/false.
2605 FrameScope scope(masm, StackFrame::INTERNAL);
2608 __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
2610 Label true_value, done;
2612 __ j(zero, &true_value, Label::kNear);
2613 __ mov(eax, factory->false_value());
2614 __ jmp(&done, Label::kNear);
2615 __ bind(&true_value);
2616 __ mov(eax, factory->true_value());
2618 __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
2623 // -------------------------------------------------------------------------
2624 // StringCharCodeAtGenerator
2626 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
2627 // If the receiver is a smi trigger the non-string case.
2628 if (check_mode_ == RECEIVER_IS_UNKNOWN) {
2629 __ JumpIfSmi(object_, receiver_not_string_);
2631 // Fetch the instance type of the receiver into result register.
2632 __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset));
2633 __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2634 // If the receiver is not a string trigger the non-string case.
2635 __ test(result_, Immediate(kIsNotStringMask));
2636 __ j(not_zero, receiver_not_string_);
2639 // If the index is non-smi trigger the non-smi case.
2640 __ JumpIfNotSmi(index_, &index_not_smi_);
2641 __ bind(&got_smi_index_);
2643 // Check for index out of range.
2644 __ cmp(index_, FieldOperand(object_, String::kLengthOffset));
2645 __ j(above_equal, index_out_of_range_);
2647 __ SmiUntag(index_);
2649 Factory* factory = masm->isolate()->factory();
2650 StringCharLoadGenerator::Generate(
2651 masm, factory, object_, index_, result_, &call_runtime_);
2658 void StringCharCodeAtGenerator::GenerateSlow(
2659 MacroAssembler* masm, EmbedMode embed_mode,
2660 const RuntimeCallHelper& call_helper) {
2661 __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
2663 // Index is not a smi.
2664 __ bind(&index_not_smi_);
2665 // If index is a heap number, try converting it to an integer.
2667 masm->isolate()->factory()->heap_number_map(),
2670 call_helper.BeforeCall(masm);
2671 if (embed_mode == PART_OF_IC_HANDLER) {
2672 __ push(LoadWithVectorDescriptor::VectorRegister());
2673 __ push(LoadDescriptor::SlotRegister());
2676 __ push(index_); // Consumed by runtime conversion function.
2677 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
2678 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
2680 DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
2681 // NumberToSmi discards numbers that are not exact integers.
2682 __ CallRuntime(Runtime::kNumberToSmi, 1);
2684 if (!index_.is(eax)) {
2685 // Save the conversion result before the pop instructions below
2686 // have a chance to overwrite it.
2687 __ mov(index_, eax);
2690 if (embed_mode == PART_OF_IC_HANDLER) {
2691 __ pop(LoadDescriptor::SlotRegister());
2692 __ pop(LoadWithVectorDescriptor::VectorRegister());
2694 // Reload the instance type.
2695 __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset));
2696 __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
2697 call_helper.AfterCall(masm);
2698 // If index is still not a smi, it must be out of range.
2699 STATIC_ASSERT(kSmiTag == 0);
2700 __ JumpIfNotSmi(index_, index_out_of_range_);
2701 // Otherwise, return to the fast path.
2702 __ jmp(&got_smi_index_);
2704 // Call runtime. We get here when the receiver is a string and the
2705 // index is a number, but the code of getting the actual character
2706 // is too complex (e.g., when the string needs to be flattened).
2707 __ bind(&call_runtime_);
2708 call_helper.BeforeCall(masm);
2712 __ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
2713 if (!result_.is(eax)) {
2714 __ mov(result_, eax);
2716 call_helper.AfterCall(masm);
2719 __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
2723 // -------------------------------------------------------------------------
2724 // StringCharFromCodeGenerator
2726 void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
2727 // Fast case of Heap::LookupSingleCharacterStringFromCode.
2728 STATIC_ASSERT(kSmiTag == 0);
2729 STATIC_ASSERT(kSmiShiftSize == 0);
2730 DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1));
2731 __ test(code_, Immediate(kSmiTagMask |
2732 ((~String::kMaxOneByteCharCodeU) << kSmiTagSize)));
2733 __ j(not_zero, &slow_case_);
2735 Factory* factory = masm->isolate()->factory();
2736 __ Move(result_, Immediate(factory->single_character_string_cache()));
2737 STATIC_ASSERT(kSmiTag == 0);
2738 STATIC_ASSERT(kSmiTagSize == 1);
2739 STATIC_ASSERT(kSmiShiftSize == 0);
2740 // At this point code register contains smi tagged one byte char code.
2741 __ mov(result_, FieldOperand(result_,
2742 code_, times_half_pointer_size,
2743 FixedArray::kHeaderSize));
2744 __ cmp(result_, factory->undefined_value());
2745 __ j(equal, &slow_case_);
2750 void StringCharFromCodeGenerator::GenerateSlow(
2751 MacroAssembler* masm,
2752 const RuntimeCallHelper& call_helper) {
2753 __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
2755 __ bind(&slow_case_);
2756 call_helper.BeforeCall(masm);
2758 __ CallRuntime(Runtime::kCharFromCode, 1);
2759 if (!result_.is(eax)) {
2760 __ mov(result_, eax);
2762 call_helper.AfterCall(masm);
2765 __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
2769 void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
2774 String::Encoding encoding) {
2775 DCHECK(!scratch.is(dest));
2776 DCHECK(!scratch.is(src));
2777 DCHECK(!scratch.is(count));
2779 // Nothing to do for zero characters.
2781 __ test(count, count);
2784 // Make count the number of bytes to copy.
2785 if (encoding == String::TWO_BYTE_ENCODING) {
2791 __ mov_b(scratch, Operand(src, 0));
2792 __ mov_b(Operand(dest, 0), scratch);
2796 __ j(not_zero, &loop);
2802 void SubStringStub::Generate(MacroAssembler* masm) {
2805 // Stack frame on entry.
2806 // esp[0]: return address
2811 // Make sure first argument is a string.
2812 __ mov(eax, Operand(esp, 3 * kPointerSize));
2813 STATIC_ASSERT(kSmiTag == 0);
2814 __ JumpIfSmi(eax, &runtime);
2815 Condition is_string = masm->IsObjectStringType(eax, ebx, ebx);
2816 __ j(NegateCondition(is_string), &runtime);
2819 // ebx: instance type
2821 // Calculate length of sub string using the smi values.
2822 __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index.
2823 __ JumpIfNotSmi(ecx, &runtime);
2824 __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index.
2825 __ JumpIfNotSmi(edx, &runtime);
2827 __ cmp(ecx, FieldOperand(eax, String::kLengthOffset));
2828 Label not_original_string;
2829 // Shorter than original string's length: an actual substring.
2830 __ j(below, ¬_original_string, Label::kNear);
2831 // Longer than original string's length or negative: unsafe arguments.
2832 __ j(above, &runtime);
2833 // Return original string.
2834 Counters* counters = isolate()->counters();
2835 __ IncrementCounter(counters->sub_string_native(), 1);
2836 __ ret(3 * kPointerSize);
2837 __ bind(¬_original_string);
2840 __ cmp(ecx, Immediate(Smi::FromInt(1)));
2841 __ j(equal, &single_char);
2844 // ebx: instance type
2845 // ecx: sub string length (smi)
2846 // edx: from index (smi)
2847 // Deal with different string types: update the index if necessary
2848 // and put the underlying string into edi.
2849 Label underlying_unpacked, sliced_string, seq_or_external_string;
2850 // If the string is not indirect, it can only be sequential or external.
2851 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
2852 STATIC_ASSERT(kIsIndirectStringMask != 0);
2853 __ test(ebx, Immediate(kIsIndirectStringMask));
2854 __ j(zero, &seq_or_external_string, Label::kNear);
2856 Factory* factory = isolate()->factory();
2857 __ test(ebx, Immediate(kSlicedNotConsMask));
2858 __ j(not_zero, &sliced_string, Label::kNear);
2859 // Cons string. Check whether it is flat, then fetch first part.
2860 // Flat cons strings have an empty second part.
2861 __ cmp(FieldOperand(eax, ConsString::kSecondOffset),
2862 factory->empty_string());
2863 __ j(not_equal, &runtime);
2864 __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset));
2865 // Update instance type.
2866 __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset));
2867 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
2868 __ jmp(&underlying_unpacked, Label::kNear);
2870 __ bind(&sliced_string);
2871 // Sliced string. Fetch parent and adjust start index by offset.
2872 __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset));
2873 __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset));
2874 // Update instance type.
2875 __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset));
2876 __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
2877 __ jmp(&underlying_unpacked, Label::kNear);
2879 __ bind(&seq_or_external_string);
2880 // Sequential or external string. Just move string to the expected register.
2883 __ bind(&underlying_unpacked);
2885 if (FLAG_string_slices) {
2887 // edi: underlying subject string
2888 // ebx: instance type of underlying subject string
2889 // edx: adjusted start index (smi)
2890 // ecx: length (smi)
2891 __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength)));
2892 // Short slice. Copy instead of slicing.
2893 __ j(less, ©_routine);
2894 // Allocate new sliced string. At this point we do not reload the instance
2895 // type including the string encoding because we simply rely on the info
2896 // provided by the original string. It does not matter if the original
2897 // string's encoding is wrong because we always have to recheck encoding of
2898 // the newly created string's parent anyways due to externalized strings.
2899 Label two_byte_slice, set_slice_header;
2900 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
2901 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
2902 __ test(ebx, Immediate(kStringEncodingMask));
2903 __ j(zero, &two_byte_slice, Label::kNear);
2904 __ AllocateOneByteSlicedString(eax, ebx, no_reg, &runtime);
2905 __ jmp(&set_slice_header, Label::kNear);
2906 __ bind(&two_byte_slice);
2907 __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime);
2908 __ bind(&set_slice_header);
2909 __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx);
2910 __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset),
2911 Immediate(String::kEmptyHashField));
2912 __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi);
2913 __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx);
2914 __ IncrementCounter(counters->sub_string_native(), 1);
2915 __ ret(3 * kPointerSize);
2917 __ bind(©_routine);
2920 // edi: underlying subject string
2921 // ebx: instance type of underlying subject string
2922 // edx: adjusted start index (smi)
2923 // ecx: length (smi)
2924 // The subject string can only be external or sequential string of either
2925 // encoding at this point.
2926 Label two_byte_sequential, runtime_drop_two, sequential_string;
2927 STATIC_ASSERT(kExternalStringTag != 0);
2928 STATIC_ASSERT(kSeqStringTag == 0);
2929 __ test_b(ebx, kExternalStringTag);
2930 __ j(zero, &sequential_string);
2932 // Handle external string.
2933 // Rule out short external strings.
2934 STATIC_ASSERT(kShortExternalStringTag != 0);
2935 __ test_b(ebx, kShortExternalStringMask);
2936 __ j(not_zero, &runtime);
2937 __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset));
2938 // Move the pointer so that offset-wise, it looks like a sequential string.
2939 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
2940 __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2942 __ bind(&sequential_string);
2943 // Stash away (adjusted) index and (underlying) string.
2947 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
2948 __ test_b(ebx, kStringEncodingMask);
2949 __ j(zero, &two_byte_sequential);
2951 // Sequential one byte string. Allocate the result.
2952 __ AllocateOneByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two);
2954 // eax: result string
2955 // ecx: result string length
2956 // Locate first character of result.
2958 __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag));
2959 // Load string argument and locate character of sub string start.
2963 __ lea(edx, FieldOperand(edx, ebx, times_1, SeqOneByteString::kHeaderSize));
2965 // eax: result string
2966 // ecx: result length
2967 // edi: first character of result
2968 // edx: character of sub string start
2969 StringHelper::GenerateCopyCharacters(
2970 masm, edi, edx, ecx, ebx, String::ONE_BYTE_ENCODING);
2971 __ IncrementCounter(counters->sub_string_native(), 1);
2972 __ ret(3 * kPointerSize);
2974 __ bind(&two_byte_sequential);
2975 // Sequential two-byte string. Allocate the result.
2976 __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two);
2978 // eax: result string
2979 // ecx: result string length
2980 // Locate first character of result.
2983 Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
2984 // Load string argument and locate character of sub string start.
2987 // As from is a smi it is 2 times the value which matches the size of a two
2989 STATIC_ASSERT(kSmiTag == 0);
2990 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
2991 __ lea(edx, FieldOperand(edx, ebx, times_1, SeqTwoByteString::kHeaderSize));
2993 // eax: result string
2994 // ecx: result length
2995 // edi: first character of result
2996 // edx: character of sub string start
2997 StringHelper::GenerateCopyCharacters(
2998 masm, edi, edx, ecx, ebx, String::TWO_BYTE_ENCODING);
2999 __ IncrementCounter(counters->sub_string_native(), 1);
3000 __ ret(3 * kPointerSize);
3002 // Drop pushed values on the stack before tail call.
3003 __ bind(&runtime_drop_two);
3006 // Just jump to runtime to create the sub string.
3008 __ TailCallRuntime(Runtime::kSubStringRT, 3, 1);
3010 __ bind(&single_char);
3012 // ebx: instance type
3013 // ecx: sub string length (smi)
3014 // edx: from index (smi)
3015 StringCharAtGenerator generator(eax, edx, ecx, eax, &runtime, &runtime,
3016 &runtime, STRING_INDEX_IS_NUMBER,
3017 RECEIVER_IS_STRING);
3018 generator.GenerateFast(masm);
3019 __ ret(3 * kPointerSize);
3020 generator.SkipSlow(masm, &runtime);
3024 void ToNumberStub::Generate(MacroAssembler* masm) {
3025 // The ToNumber stub takes one argument in eax.
3027 __ JumpIfNotSmi(eax, ¬_smi, Label::kNear);
3031 Label not_heap_number;
3032 __ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
3033 __ j(not_equal, ¬_heap_number, Label::kNear);
3035 __ bind(¬_heap_number);
3037 Label not_string, slow_string;
3038 __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
3041 __ j(above_equal, ¬_string, Label::kNear);
3042 // Check if string has a cached array index.
3043 __ test(FieldOperand(eax, String::kHashFieldOffset),
3044 Immediate(String::kContainsCachedArrayIndexMask));
3045 __ j(not_zero, &slow_string, Label::kNear);
3046 __ mov(eax, FieldOperand(eax, String::kHashFieldOffset));
3047 __ IndexFromHash(eax, eax);
3049 __ bind(&slow_string);
3050 __ pop(ecx); // Pop return address.
3051 __ push(eax); // Push argument.
3052 __ push(ecx); // Push return address.
3053 __ TailCallRuntime(Runtime::kStringToNumber, 1, 1);
3054 __ bind(¬_string);
3057 __ CmpInstanceType(edi, ODDBALL_TYPE);
3058 __ j(not_equal, ¬_oddball, Label::kNear);
3059 __ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset));
3061 __ bind(¬_oddball);
3063 __ pop(ecx); // Pop return address.
3064 __ push(eax); // Push argument.
3065 __ push(ecx); // Push return address.
3066 __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
3070 void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
3074 Register scratch2) {
3075 Register length = scratch1;
3078 Label strings_not_equal, check_zero_length;
3079 __ mov(length, FieldOperand(left, String::kLengthOffset));
3080 __ cmp(length, FieldOperand(right, String::kLengthOffset));
3081 __ j(equal, &check_zero_length, Label::kNear);
3082 __ bind(&strings_not_equal);
3083 __ Move(eax, Immediate(Smi::FromInt(NOT_EQUAL)));
3086 // Check if the length is zero.
3087 Label compare_chars;
3088 __ bind(&check_zero_length);
3089 STATIC_ASSERT(kSmiTag == 0);
3090 __ test(length, length);
3091 __ j(not_zero, &compare_chars, Label::kNear);
3092 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
3095 // Compare characters.
3096 __ bind(&compare_chars);
3097 GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2,
3098 &strings_not_equal, Label::kNear);
3100 // Characters are equal.
3101 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
3106 void StringHelper::GenerateCompareFlatOneByteStrings(
3107 MacroAssembler* masm, Register left, Register right, Register scratch1,
3108 Register scratch2, Register scratch3) {
3109 Counters* counters = masm->isolate()->counters();
3110 __ IncrementCounter(counters->string_compare_native(), 1);
3112 // Find minimum length.
3114 __ mov(scratch1, FieldOperand(left, String::kLengthOffset));
3115 __ mov(scratch3, scratch1);
3116 __ sub(scratch3, FieldOperand(right, String::kLengthOffset));
3118 Register length_delta = scratch3;
3120 __ j(less_equal, &left_shorter, Label::kNear);
3121 // Right string is shorter. Change scratch1 to be length of right string.
3122 __ sub(scratch1, length_delta);
3123 __ bind(&left_shorter);
3125 Register min_length = scratch1;
3127 // If either length is zero, just compare lengths.
3128 Label compare_lengths;
3129 __ test(min_length, min_length);
3130 __ j(zero, &compare_lengths, Label::kNear);
3132 // Compare characters.
3133 Label result_not_equal;
3134 GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2,
3135 &result_not_equal, Label::kNear);
3137 // Compare lengths - strings up to min-length are equal.
3138 __ bind(&compare_lengths);
3139 __ test(length_delta, length_delta);
3140 Label length_not_equal;
3141 __ j(not_zero, &length_not_equal, Label::kNear);
3144 STATIC_ASSERT(EQUAL == 0);
3145 STATIC_ASSERT(kSmiTag == 0);
3146 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
3149 Label result_greater;
3151 __ bind(&length_not_equal);
3152 __ j(greater, &result_greater, Label::kNear);
3153 __ jmp(&result_less, Label::kNear);
3154 __ bind(&result_not_equal);
3155 __ j(above, &result_greater, Label::kNear);
3156 __ bind(&result_less);
3159 __ Move(eax, Immediate(Smi::FromInt(LESS)));
3162 // Result is GREATER.
3163 __ bind(&result_greater);
3164 __ Move(eax, Immediate(Smi::FromInt(GREATER)));
3169 void StringHelper::GenerateOneByteCharsCompareLoop(
3170 MacroAssembler* masm, Register left, Register right, Register length,
3171 Register scratch, Label* chars_not_equal,
3172 Label::Distance chars_not_equal_near) {
3173 // Change index to run from -length to -1 by adding length to string
3174 // start. This means that loop ends when index reaches zero, which
3175 // doesn't need an additional compare.
3176 __ SmiUntag(length);
3178 FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize));
3180 FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize));
3182 Register index = length; // index = -length;
3187 __ mov_b(scratch, Operand(left, index, times_1, 0));
3188 __ cmpb(scratch, Operand(right, index, times_1, 0));
3189 __ j(not_equal, chars_not_equal, chars_not_equal_near);
3191 __ j(not_zero, &loop);
3195 void StringCompareStub::Generate(MacroAssembler* masm) {
3198 // Stack frame on entry.
3199 // esp[0]: return address
3200 // esp[4]: right string
3201 // esp[8]: left string
3203 __ mov(edx, Operand(esp, 2 * kPointerSize)); // left
3204 __ mov(eax, Operand(esp, 1 * kPointerSize)); // right
3208 __ j(not_equal, ¬_same, Label::kNear);
3209 STATIC_ASSERT(EQUAL == 0);
3210 STATIC_ASSERT(kSmiTag == 0);
3211 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
3212 __ IncrementCounter(isolate()->counters()->string_compare_native(), 1);
3213 __ ret(2 * kPointerSize);
3217 // Check that both objects are sequential one-byte strings.
3218 __ JumpIfNotBothSequentialOneByteStrings(edx, eax, ecx, ebx, &runtime);
3220 // Compare flat one-byte strings.
3221 // Drop arguments from the stack.
3223 __ add(esp, Immediate(2 * kPointerSize));
3225 StringHelper::GenerateCompareFlatOneByteStrings(masm, edx, eax, ecx, ebx,
3228 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
3229 // tagged as a small integer.
3231 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3235 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
3236 // ----------- S t a t e -------------
3239 // -- esp[0] : return address
3240 // -----------------------------------
3242 // Load ecx with the allocation site. We stick an undefined dummy value here
3243 // and replace it with the real allocation site later when we instantiate this
3244 // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
3245 __ mov(ecx, handle(isolate()->heap()->undefined_value()));
3247 // Make sure that we actually patched the allocation site.
3248 if (FLAG_debug_code) {
3249 __ test(ecx, Immediate(kSmiTagMask));
3250 __ Assert(not_equal, kExpectedAllocationSite);
3251 __ cmp(FieldOperand(ecx, HeapObject::kMapOffset),
3252 isolate()->factory()->allocation_site_map());
3253 __ Assert(equal, kExpectedAllocationSite);
3256 // Tail call into the stub that handles binary operations with allocation
3258 BinaryOpWithAllocationSiteStub stub(isolate(), state());
3259 __ TailCallStub(&stub);
3263 void CompareICStub::GenerateSmis(MacroAssembler* masm) {
3264 DCHECK(state() == CompareICState::SMI);
3268 __ JumpIfNotSmi(ecx, &miss, Label::kNear);
3270 if (GetCondition() == equal) {
3271 // For equality we do not care about the sign of the result.
3276 __ j(no_overflow, &done, Label::kNear);
3277 // Correct sign of result in case of overflow.
3289 void CompareICStub::GenerateNumbers(MacroAssembler* masm) {
3290 DCHECK(state() == CompareICState::NUMBER);
3292 Label generic_stub, check_left;
3293 Label unordered, maybe_undefined1, maybe_undefined2;
3296 if (left() == CompareICState::SMI) {
3297 __ JumpIfNotSmi(edx, &miss);
3299 if (right() == CompareICState::SMI) {
3300 __ JumpIfNotSmi(eax, &miss);
3303 // Inlining the double comparison and falling back to the general compare
3304 // stub if NaN is involved or SSE2 or CMOV is unsupported.
3305 __ JumpIfSmi(eax, &check_left, Label::kNear);
3306 __ cmp(FieldOperand(eax, HeapObject::kMapOffset),
3307 isolate()->factory()->heap_number_map());
3308 __ j(not_equal, &maybe_undefined1, Label::kNear);
3310 __ bind(&check_left);
3311 __ JumpIfSmi(edx, &generic_stub, Label::kNear);
3312 __ cmp(FieldOperand(edx, HeapObject::kMapOffset),
3313 isolate()->factory()->heap_number_map());
3314 __ j(not_equal, &maybe_undefined2, Label::kNear);
3316 __ bind(&unordered);
3317 __ bind(&generic_stub);
3318 CompareICStub stub(isolate(), op(), strength(), CompareICState::GENERIC,
3319 CompareICState::GENERIC, CompareICState::GENERIC);
3320 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
3322 __ bind(&maybe_undefined1);
3323 if (Token::IsOrderedRelationalCompareOp(op())) {
3324 __ cmp(eax, Immediate(isolate()->factory()->undefined_value()));
3325 __ j(not_equal, &miss);
3326 __ JumpIfSmi(edx, &unordered);
3327 __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx);
3328 __ j(not_equal, &maybe_undefined2, Label::kNear);
3332 __ bind(&maybe_undefined2);
3333 if (Token::IsOrderedRelationalCompareOp(op())) {
3334 __ cmp(edx, Immediate(isolate()->factory()->undefined_value()));
3335 __ j(equal, &unordered);
3343 void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) {
3344 DCHECK(state() == CompareICState::INTERNALIZED_STRING);
3345 DCHECK(GetCondition() == equal);
3347 // Registers containing left and right operands respectively.
3348 Register left = edx;
3349 Register right = eax;
3350 Register tmp1 = ecx;
3351 Register tmp2 = ebx;
3353 // Check that both operands are heap objects.
3356 STATIC_ASSERT(kSmiTag == 0);
3357 __ and_(tmp1, right);
3358 __ JumpIfSmi(tmp1, &miss, Label::kNear);
3360 // Check that both operands are internalized strings.
3361 __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3362 __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3363 __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3364 __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3365 STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
3367 __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
3368 __ j(not_zero, &miss, Label::kNear);
3370 // Internalized strings are compared by identity.
3372 __ cmp(left, right);
3373 // Make sure eax is non-zero. At this point input operands are
3374 // guaranteed to be non-zero.
3375 DCHECK(right.is(eax));
3376 __ j(not_equal, &done, Label::kNear);
3377 STATIC_ASSERT(EQUAL == 0);
3378 STATIC_ASSERT(kSmiTag == 0);
3379 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
3388 void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) {
3389 DCHECK(state() == CompareICState::UNIQUE_NAME);
3390 DCHECK(GetCondition() == equal);
3392 // Registers containing left and right operands respectively.
3393 Register left = edx;
3394 Register right = eax;
3395 Register tmp1 = ecx;
3396 Register tmp2 = ebx;
3398 // Check that both operands are heap objects.
3401 STATIC_ASSERT(kSmiTag == 0);
3402 __ and_(tmp1, right);
3403 __ JumpIfSmi(tmp1, &miss, Label::kNear);
3405 // Check that both operands are unique names. This leaves the instance
3406 // types loaded in tmp1 and tmp2.
3407 __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3408 __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3409 __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3410 __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3412 __ JumpIfNotUniqueNameInstanceType(tmp1, &miss, Label::kNear);
3413 __ JumpIfNotUniqueNameInstanceType(tmp2, &miss, Label::kNear);
3415 // Unique names are compared by identity.
3417 __ cmp(left, right);
3418 // Make sure eax is non-zero. At this point input operands are
3419 // guaranteed to be non-zero.
3420 DCHECK(right.is(eax));
3421 __ j(not_equal, &done, Label::kNear);
3422 STATIC_ASSERT(EQUAL == 0);
3423 STATIC_ASSERT(kSmiTag == 0);
3424 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
3433 void CompareICStub::GenerateStrings(MacroAssembler* masm) {
3434 DCHECK(state() == CompareICState::STRING);
3437 bool equality = Token::IsEqualityOp(op());
3439 // Registers containing left and right operands respectively.
3440 Register left = edx;
3441 Register right = eax;
3442 Register tmp1 = ecx;
3443 Register tmp2 = ebx;
3444 Register tmp3 = edi;
3446 // Check that both operands are heap objects.
3448 STATIC_ASSERT(kSmiTag == 0);
3449 __ and_(tmp1, right);
3450 __ JumpIfSmi(tmp1, &miss);
3452 // Check that both operands are strings. This leaves the instance
3453 // types loaded in tmp1 and tmp2.
3454 __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
3455 __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
3456 __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
3457 __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
3459 STATIC_ASSERT(kNotStringTag != 0);
3461 __ test(tmp3, Immediate(kIsNotStringMask));
3462 __ j(not_zero, &miss);
3464 // Fast check for identical strings.
3466 __ cmp(left, right);
3467 __ j(not_equal, ¬_same, Label::kNear);
3468 STATIC_ASSERT(EQUAL == 0);
3469 STATIC_ASSERT(kSmiTag == 0);
3470 __ Move(eax, Immediate(Smi::FromInt(EQUAL)));
3473 // Handle not identical strings.
3476 // Check that both strings are internalized. If they are, we're done
3477 // because we already know they are not identical. But in the case of
3478 // non-equality compare, we still need to determine the order. We
3479 // also know they are both strings.
3482 STATIC_ASSERT(kInternalizedTag == 0);
3484 __ test(tmp1, Immediate(kIsNotInternalizedMask));
3485 __ j(not_zero, &do_compare, Label::kNear);
3486 // Make sure eax is non-zero. At this point input operands are
3487 // guaranteed to be non-zero.
3488 DCHECK(right.is(eax));
3490 __ bind(&do_compare);
3493 // Check that both strings are sequential one-byte.
3495 __ JumpIfNotBothSequentialOneByteStrings(left, right, tmp1, tmp2, &runtime);
3497 // Compare flat one byte strings. Returns when done.
3499 StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1,
3502 StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1,
3506 // Handle more complex cases in runtime.
3508 __ pop(tmp1); // Return address.
3513 __ TailCallRuntime(Runtime::kStringEquals, 2, 1);
3515 __ TailCallRuntime(Runtime::kStringCompareRT, 2, 1);
3523 void CompareICStub::GenerateObjects(MacroAssembler* masm) {
3524 DCHECK(state() == CompareICState::OBJECT);
3528 __ JumpIfSmi(ecx, &miss, Label::kNear);
3530 __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx);
3531 __ j(not_equal, &miss, Label::kNear);
3532 __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx);
3533 __ j(not_equal, &miss, Label::kNear);
3535 DCHECK(GetCondition() == equal);
3544 void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) {
3546 Handle<WeakCell> cell = Map::WeakCellForMap(known_map_);
3549 __ JumpIfSmi(ecx, &miss, Label::kNear);
3551 __ GetWeakValue(edi, cell);
3552 __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset));
3553 __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset));
3555 __ j(not_equal, &miss, Label::kNear);
3557 __ j(not_equal, &miss, Label::kNear);
3567 void CompareICStub::GenerateMiss(MacroAssembler* masm) {
3569 // Call the runtime system in a fresh internal frame.
3570 ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss),
3572 FrameScope scope(masm, StackFrame::INTERNAL);
3573 __ push(edx); // Preserve edx and eax.
3575 __ push(edx); // And also use them as the arguments.
3577 __ push(Immediate(Smi::FromInt(op())));
3578 __ CallExternalReference(miss, 3);
3579 // Compute the entry point of the rewritten stub.
3580 __ lea(edi, FieldOperand(eax, Code::kHeaderSize));
3585 // Do a tail call to the rewritten stub.
3590 // Helper function used to check that the dictionary doesn't contain
3591 // the property. This function may return false negatives, so miss_label
3592 // must always call a backup property check that is complete.
3593 // This function is safe to call if the receiver has fast properties.
3594 // Name must be a unique name and receiver must be a heap object.
3595 void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
3598 Register properties,
3601 DCHECK(name->IsUniqueName());
3603 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3604 // not equal to the name and kProbes-th slot is not used (its name is the
3605 // undefined value), it guarantees the hash table doesn't contain the
3606 // property. It's true even if some slots represent deleted properties
3607 // (their names are the hole value).
3608 for (int i = 0; i < kInlinedProbes; i++) {
3609 // Compute the masked index: (hash + i + i * i) & mask.
3610 Register index = r0;
3611 // Capacity is smi 2^n.
3612 __ mov(index, FieldOperand(properties, kCapacityOffset));
3615 Immediate(Smi::FromInt(name->Hash() +
3616 NameDictionary::GetProbeOffset(i))));
3618 // Scale the index by multiplying by the entry size.
3619 DCHECK(NameDictionary::kEntrySize == 3);
3620 __ lea(index, Operand(index, index, times_2, 0)); // index *= 3.
3621 Register entity_name = r0;
3622 // Having undefined at this place means the name is not contained.
3623 DCHECK_EQ(kSmiTagSize, 1);
3624 __ mov(entity_name, Operand(properties, index, times_half_pointer_size,
3625 kElementsStartOffset - kHeapObjectTag));
3626 __ cmp(entity_name, masm->isolate()->factory()->undefined_value());
3629 // Stop if found the property.
3630 __ cmp(entity_name, Handle<Name>(name));
3634 // Check for the hole and skip.
3635 __ cmp(entity_name, masm->isolate()->factory()->the_hole_value());
3636 __ j(equal, &good, Label::kNear);
3638 // Check if the entry name is not a unique name.
3639 __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset));
3640 __ JumpIfNotUniqueNameInstanceType(
3641 FieldOperand(entity_name, Map::kInstanceTypeOffset), miss);
3645 NameDictionaryLookupStub stub(masm->isolate(), properties, r0, r0,
3647 __ push(Immediate(Handle<Object>(name)));
3648 __ push(Immediate(name->Hash()));
3651 __ j(not_zero, miss);
3656 // Probe the name dictionary in the |elements| register. Jump to the
3657 // |done| label if a property with the given name is found leaving the
3658 // index into the dictionary in |r0|. Jump to the |miss| label
3660 void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
3667 DCHECK(!elements.is(r0));
3668 DCHECK(!elements.is(r1));
3669 DCHECK(!name.is(r0));
3670 DCHECK(!name.is(r1));
3672 __ AssertName(name);
3674 __ mov(r1, FieldOperand(elements, kCapacityOffset));
3675 __ shr(r1, kSmiTagSize); // convert smi to int
3678 // Generate an unrolled loop that performs a few probes before
3679 // giving up. Measurements done on Gmail indicate that 2 probes
3680 // cover ~93% of loads from dictionaries.
3681 for (int i = 0; i < kInlinedProbes; i++) {
3682 // Compute the masked index: (hash + i + i * i) & mask.
3683 __ mov(r0, FieldOperand(name, Name::kHashFieldOffset));
3684 __ shr(r0, Name::kHashShift);
3686 __ add(r0, Immediate(NameDictionary::GetProbeOffset(i)));
3690 // Scale the index by multiplying by the entry size.
3691 DCHECK(NameDictionary::kEntrySize == 3);
3692 __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3
3694 // Check if the key is identical to the name.
3695 __ cmp(name, Operand(elements,
3698 kElementsStartOffset - kHeapObjectTag));
3702 NameDictionaryLookupStub stub(masm->isolate(), elements, r1, r0,
3705 __ mov(r0, FieldOperand(name, Name::kHashFieldOffset));
3706 __ shr(r0, Name::kHashShift);
3716 void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
3717 // This stub overrides SometimesSetsUpAFrame() to return false. That means
3718 // we cannot call anything that could cause a GC from this stub.
3719 // Stack frame on entry:
3720 // esp[0 * kPointerSize]: return address.
3721 // esp[1 * kPointerSize]: key's hash.
3722 // esp[2 * kPointerSize]: key.
3724 // dictionary_: NameDictionary to probe.
3725 // result_: used as scratch.
3726 // index_: will hold an index of entry if lookup is successful.
3727 // might alias with result_.
3729 // result_ is zero if lookup failed, non zero otherwise.
3731 Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
3733 Register scratch = result();
3735 __ mov(scratch, FieldOperand(dictionary(), kCapacityOffset));
3737 __ SmiUntag(scratch);
3740 // If names of slots in range from 1 to kProbes - 1 for the hash value are
3741 // not equal to the name and kProbes-th slot is not used (its name is the
3742 // undefined value), it guarantees the hash table doesn't contain the
3743 // property. It's true even if some slots represent deleted properties
3744 // (their names are the null value).
3745 for (int i = kInlinedProbes; i < kTotalProbes; i++) {
3746 // Compute the masked index: (hash + i + i * i) & mask.
3747 __ mov(scratch, Operand(esp, 2 * kPointerSize));
3749 __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i)));
3751 __ and_(scratch, Operand(esp, 0));
3753 // Scale the index by multiplying by the entry size.
3754 DCHECK(NameDictionary::kEntrySize == 3);
3755 __ lea(index(), Operand(scratch, scratch, times_2, 0)); // index *= 3.
3757 // Having undefined at this place means the name is not contained.
3758 DCHECK_EQ(kSmiTagSize, 1);
3759 __ mov(scratch, Operand(dictionary(), index(), times_pointer_size,
3760 kElementsStartOffset - kHeapObjectTag));
3761 __ cmp(scratch, isolate()->factory()->undefined_value());
3762 __ j(equal, ¬_in_dictionary);
3764 // Stop if found the property.
3765 __ cmp(scratch, Operand(esp, 3 * kPointerSize));
3766 __ j(equal, &in_dictionary);
3768 if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) {
3769 // If we hit a key that is not a unique name during negative
3770 // lookup we have to bailout as this key might be equal to the
3771 // key we are looking for.
3773 // Check if the entry name is not a unique name.
3774 __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
3775 __ JumpIfNotUniqueNameInstanceType(
3776 FieldOperand(scratch, Map::kInstanceTypeOffset),
3777 &maybe_in_dictionary);
3781 __ bind(&maybe_in_dictionary);
3782 // If we are doing negative lookup then probing failure should be
3783 // treated as a lookup success. For positive lookup probing failure
3784 // should be treated as lookup failure.
3785 if (mode() == POSITIVE_LOOKUP) {
3786 __ mov(result(), Immediate(0));
3788 __ ret(2 * kPointerSize);
3791 __ bind(&in_dictionary);
3792 __ mov(result(), Immediate(1));
3794 __ ret(2 * kPointerSize);
3796 __ bind(¬_in_dictionary);
3797 __ mov(result(), Immediate(0));
3799 __ ret(2 * kPointerSize);
3803 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
3805 StoreBufferOverflowStub stub(isolate, kDontSaveFPRegs);
3807 StoreBufferOverflowStub stub2(isolate, kSaveFPRegs);
3812 // Takes the input in 3 registers: address_ value_ and object_. A pointer to
3813 // the value has just been written into the object, now this stub makes sure
3814 // we keep the GC informed. The word in the object where the value has been
3815 // written is in the address register.
3816 void RecordWriteStub::Generate(MacroAssembler* masm) {
3817 Label skip_to_incremental_noncompacting;
3818 Label skip_to_incremental_compacting;
3820 // The first two instructions are generated with labels so as to get the
3821 // offset fixed up correctly by the bind(Label*) call. We patch it back and
3822 // forth between a compare instructions (a nop in this position) and the
3823 // real branch when we start and stop incremental heap marking.
3824 __ jmp(&skip_to_incremental_noncompacting, Label::kNear);
3825 __ jmp(&skip_to_incremental_compacting, Label::kFar);
3827 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3828 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3829 MacroAssembler::kReturnAtEnd);
3834 __ bind(&skip_to_incremental_noncompacting);
3835 GenerateIncremental(masm, INCREMENTAL);
3837 __ bind(&skip_to_incremental_compacting);
3838 GenerateIncremental(masm, INCREMENTAL_COMPACTION);
3840 // Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
3841 // Will be checked in IncrementalMarking::ActivateGeneratedStub.
3842 masm->set_byte_at(0, kTwoByteNopInstruction);
3843 masm->set_byte_at(2, kFiveByteNopInstruction);
3847 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
3850 if (remembered_set_action() == EMIT_REMEMBERED_SET) {
3851 Label dont_need_remembered_set;
3853 __ mov(regs_.scratch0(), Operand(regs_.address(), 0));
3854 __ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
3856 &dont_need_remembered_set);
3858 __ CheckPageFlag(regs_.object(),
3860 1 << MemoryChunk::SCAN_ON_SCAVENGE,
3862 &dont_need_remembered_set);
3864 // First notify the incremental marker if necessary, then update the
3866 CheckNeedsToInformIncrementalMarker(
3868 kUpdateRememberedSetOnNoNeedToInformIncrementalMarker,
3870 InformIncrementalMarker(masm);
3871 regs_.Restore(masm);
3872 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3873 MacroAssembler::kReturnAtEnd);
3875 __ bind(&dont_need_remembered_set);
3878 CheckNeedsToInformIncrementalMarker(
3880 kReturnOnNoNeedToInformIncrementalMarker,
3882 InformIncrementalMarker(masm);
3883 regs_.Restore(masm);
3888 void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
3889 regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode());
3890 int argument_count = 3;
3891 __ PrepareCallCFunction(argument_count, regs_.scratch0());
3892 __ mov(Operand(esp, 0 * kPointerSize), regs_.object());
3893 __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot.
3894 __ mov(Operand(esp, 2 * kPointerSize),
3895 Immediate(ExternalReference::isolate_address(isolate())));
3897 AllowExternalCallThatCantCauseGC scope(masm);
3899 ExternalReference::incremental_marking_record_write_function(isolate()),
3902 regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode());
3906 void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
3907 MacroAssembler* masm,
3908 OnNoNeedToInformIncrementalMarker on_no_need,
3910 Label object_is_black, need_incremental, need_incremental_pop_object;
3912 __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask));
3913 __ and_(regs_.scratch0(), regs_.object());
3914 __ mov(regs_.scratch1(),
3915 Operand(regs_.scratch0(),
3916 MemoryChunk::kWriteBarrierCounterOffset));
3917 __ sub(regs_.scratch1(), Immediate(1));
3918 __ mov(Operand(regs_.scratch0(),
3919 MemoryChunk::kWriteBarrierCounterOffset),
3921 __ j(negative, &need_incremental);
3923 // Let's look at the color of the object: If it is not black we don't have
3924 // to inform the incremental marker.
3925 __ JumpIfBlack(regs_.object(),
3931 regs_.Restore(masm);
3932 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
3933 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3934 MacroAssembler::kReturnAtEnd);
3939 __ bind(&object_is_black);
3941 // Get the value from the slot.
3942 __ mov(regs_.scratch0(), Operand(regs_.address(), 0));
3944 if (mode == INCREMENTAL_COMPACTION) {
3945 Label ensure_not_white;
3947 __ CheckPageFlag(regs_.scratch0(), // Contains value.
3948 regs_.scratch1(), // Scratch.
3949 MemoryChunk::kEvacuationCandidateMask,
3954 __ CheckPageFlag(regs_.object(),
3955 regs_.scratch1(), // Scratch.
3956 MemoryChunk::kSkipEvacuationSlotsRecordingMask,
3961 __ jmp(&need_incremental);
3963 __ bind(&ensure_not_white);
3966 // We need an extra register for this, so we push the object register
3968 __ push(regs_.object());
3969 __ EnsureNotWhite(regs_.scratch0(), // The value.
3970 regs_.scratch1(), // Scratch.
3971 regs_.object(), // Scratch.
3972 &need_incremental_pop_object,
3974 __ pop(regs_.object());
3976 regs_.Restore(masm);
3977 if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
3978 __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(),
3979 MacroAssembler::kReturnAtEnd);
3984 __ bind(&need_incremental_pop_object);
3985 __ pop(regs_.object());
3987 __ bind(&need_incremental);
3989 // Fall through when we need to inform the incremental marker.
3993 void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
3994 // ----------- S t a t e -------------
3995 // -- eax : element value to store
3996 // -- ecx : element index as smi
3997 // -- esp[0] : return address
3998 // -- esp[4] : array literal index in function
3999 // -- esp[8] : array literal
4000 // clobbers ebx, edx, edi
4001 // -----------------------------------
4004 Label double_elements;
4006 Label slow_elements;
4007 Label slow_elements_from_double;
4008 Label fast_elements;
4010 // Get array literal index, array literal and its map.
4011 __ mov(edx, Operand(esp, 1 * kPointerSize));
4012 __ mov(ebx, Operand(esp, 2 * kPointerSize));
4013 __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset));
4015 __ CheckFastElements(edi, &double_elements);
4017 // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements
4018 __ JumpIfSmi(eax, &smi_element);
4019 __ CheckFastSmiElements(edi, &fast_elements, Label::kNear);
4021 // Store into the array literal requires a elements transition. Call into
4024 __ bind(&slow_elements);
4025 __ pop(edi); // Pop return address and remember to put back later for tail
4030 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
4031 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset));
4033 __ push(edi); // Return return address so that tail call returns to right
4035 __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
4037 __ bind(&slow_elements_from_double);
4039 __ jmp(&slow_elements);
4041 // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
4042 __ bind(&fast_elements);
4043 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset));
4044 __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size,
4045 FixedArrayBase::kHeaderSize));
4046 __ mov(Operand(ecx, 0), eax);
4047 // Update the write barrier for the array store.
4048 __ RecordWrite(ebx, ecx, eax, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
4052 // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
4053 // and value is Smi.
4054 __ bind(&smi_element);
4055 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset));
4056 __ mov(FieldOperand(ebx, ecx, times_half_pointer_size,
4057 FixedArrayBase::kHeaderSize), eax);
4060 // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS.
4061 __ bind(&double_elements);
4064 __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset));
4065 __ StoreNumberToDoubleElements(eax,
4069 &slow_elements_from_double,
4076 void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
4077 CEntryStub ces(isolate(), 1, kSaveFPRegs);
4078 __ call(ces.GetCode(), RelocInfo::CODE_TARGET);
4079 int parameter_count_offset =
4080 StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
4081 __ mov(ebx, MemOperand(ebp, parameter_count_offset));
4082 masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
4084 int additional_offset =
4085 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0;
4086 __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset));
4087 __ jmp(ecx); // Return to IC Miss stub, continuation still on stack.
4091 void LoadICTrampolineStub::Generate(MacroAssembler* masm) {
4092 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4093 LoadICStub stub(isolate(), state());
4094 stub.GenerateForTrampoline(masm);
4098 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) {
4099 EmitLoadTypeFeedbackVector(masm, LoadWithVectorDescriptor::VectorRegister());
4100 KeyedLoadICStub stub(isolate(), state());
4101 stub.GenerateForTrampoline(masm);
4105 static void HandleArrayCases(MacroAssembler* masm, Register receiver,
4106 Register key, Register vector, Register slot,
4107 Register feedback, bool is_polymorphic,
4109 // feedback initially contains the feedback array
4110 Label next, next_loop, prepare_next;
4111 Label load_smi_map, compare_map;
4112 Label start_polymorphic;
4117 Register receiver_map = receiver;
4118 Register cached_map = vector;
4120 // Receiver might not be a heap object.
4121 __ JumpIfSmi(receiver, &load_smi_map);
4122 __ mov(receiver_map, FieldOperand(receiver, 0));
4123 __ bind(&compare_map);
4124 __ mov(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0)));
4126 // A named keyed load might have a 2 element array, all other cases can count
4127 // on an array with at least 2 {map, handler} pairs, so they can go right
4128 // into polymorphic array handling.
4129 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4130 __ j(not_equal, is_polymorphic ? &start_polymorphic : &next);
4132 // found, now call handler.
4133 Register handler = feedback;
4134 __ mov(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1)));
4137 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
4140 if (!is_polymorphic) {
4142 __ cmp(FieldOperand(feedback, FixedArray::kLengthOffset),
4143 Immediate(Smi::FromInt(2)));
4144 __ j(not_equal, &start_polymorphic);
4150 // Polymorphic, we have to loop from 2 to N
4151 __ bind(&start_polymorphic);
4153 Register counter = key;
4154 __ mov(counter, Immediate(Smi::FromInt(2)));
4155 __ bind(&next_loop);
4156 __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size,
4157 FixedArray::kHeaderSize));
4158 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset));
4159 __ j(not_equal, &prepare_next);
4160 __ mov(handler, FieldOperand(feedback, counter, times_half_pointer_size,
4161 FixedArray::kHeaderSize + kPointerSize));
4165 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
4168 __ bind(&prepare_next);
4169 __ add(counter, Immediate(Smi::FromInt(2)));
4170 __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset));
4171 __ j(less, &next_loop);
4173 // We exhausted our array of map handler pairs.
4179 __ bind(&load_smi_map);
4180 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex);
4181 __ jmp(&compare_map);
4185 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver,
4186 Register key, Register vector, Register slot,
4187 Register weak_cell, Label* miss) {
4188 // feedback initially contains the feedback array
4189 Label compare_smi_map;
4191 // Move the weak map into the weak_cell register.
4192 Register ic_map = weak_cell;
4193 __ mov(ic_map, FieldOperand(weak_cell, WeakCell::kValueOffset));
4195 // Receiver might not be a heap object.
4196 __ JumpIfSmi(receiver, &compare_smi_map);
4197 __ cmp(ic_map, FieldOperand(receiver, 0));
4198 __ j(not_equal, miss);
4199 Register handler = weak_cell;
4200 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size,
4201 FixedArray::kHeaderSize + kPointerSize));
4202 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
4205 // In microbenchmarks, it made sense to unroll this code so that the call to
4206 // the handler is duplicated for a HeapObject receiver and a Smi receiver.
4207 __ bind(&compare_smi_map);
4208 __ CompareRoot(ic_map, Heap::kHeapNumberMapRootIndex);
4209 __ j(not_equal, miss);
4210 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size,
4211 FixedArray::kHeaderSize + kPointerSize));
4212 __ lea(handler, FieldOperand(handler, Code::kHeaderSize));
4217 void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); }
4220 void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4221 GenerateImpl(masm, true);
4225 void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4226 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // edx
4227 Register name = LoadWithVectorDescriptor::NameRegister(); // ecx
4228 Register vector = LoadWithVectorDescriptor::VectorRegister(); // ebx
4229 Register slot = LoadWithVectorDescriptor::SlotRegister(); // eax
4230 Register scratch = edi;
4231 __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size,
4232 FixedArray::kHeaderSize));
4234 // Is it a weak cell?
4236 Label not_array, smi_key, key_okay, miss;
4237 __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex);
4238 __ j(not_equal, &try_array);
4239 HandleMonomorphicCase(masm, receiver, name, vector, slot, scratch, &miss);
4241 // Is it a fixed array?
4242 __ bind(&try_array);
4243 __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex);
4244 __ j(not_equal, ¬_array);
4245 HandleArrayCases(masm, receiver, name, vector, slot, scratch, true, &miss);
4247 __ bind(¬_array);
4248 __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex);
4249 __ j(not_equal, &miss);
4252 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags(
4253 Code::ComputeHandlerFlags(Code::LOAD_IC));
4254 masm->isolate()->stub_cache()->GenerateProbe(
4255 masm, Code::LOAD_IC, code_flags, false, receiver, name, vector, scratch);
4260 LoadIC::GenerateMiss(masm);
4264 void KeyedLoadICStub::Generate(MacroAssembler* masm) {
4265 GenerateImpl(masm, false);
4269 void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) {
4270 GenerateImpl(masm, true);
4274 void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4275 Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // edx
4276 Register key = LoadWithVectorDescriptor::NameRegister(); // ecx
4277 Register vector = LoadWithVectorDescriptor::VectorRegister(); // ebx
4278 Register slot = LoadWithVectorDescriptor::SlotRegister(); // eax
4279 Register feedback = edi;
4280 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size,
4281 FixedArray::kHeaderSize));
4282 // Is it a weak cell?
4284 Label not_array, smi_key, key_okay, miss;
4285 __ CompareRoot(FieldOperand(feedback, 0), Heap::kWeakCellMapRootIndex);
4286 __ j(not_equal, &try_array);
4287 HandleMonomorphicCase(masm, receiver, key, vector, slot, feedback, &miss);
4289 __ bind(&try_array);
4290 // Is it a fixed array?
4291 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex);
4292 __ j(not_equal, ¬_array);
4294 // We have a polymorphic element handler.
4295 Label polymorphic, try_poly_name;
4296 __ bind(&polymorphic);
4297 HandleArrayCases(masm, receiver, key, vector, slot, feedback, true, &miss);
4299 __ bind(¬_array);
4301 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex);
4302 __ j(not_equal, &try_poly_name);
4303 Handle<Code> megamorphic_stub =
4304 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState());
4305 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET);
4307 __ bind(&try_poly_name);
4308 // We might have a name in feedback, and a fixed array in the next slot.
4309 __ cmp(key, feedback);
4310 __ j(not_equal, &miss);
4311 // If the name comparison succeeded, we know we have a fixed array with
4312 // at least one map/handler pair.
4313 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size,
4314 FixedArray::kHeaderSize + kPointerSize));
4315 HandleArrayCases(masm, receiver, key, vector, slot, feedback, false, &miss);
4318 KeyedLoadIC::GenerateMiss(masm);
4322 void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4323 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4324 VectorStoreICStub stub(isolate(), state());
4325 stub.GenerateForTrampoline(masm);
4329 void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) {
4330 EmitLoadTypeFeedbackVector(masm, VectorStoreICDescriptor::VectorRegister());
4331 VectorKeyedStoreICStub stub(isolate(), state());
4332 stub.GenerateForTrampoline(masm);
4336 void VectorStoreICStub::Generate(MacroAssembler* masm) {
4337 GenerateImpl(masm, false);
4341 void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4342 GenerateImpl(masm, true);
4346 void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4349 // TODO(mvstanton): Implement.
4351 StoreIC::GenerateMiss(masm);
4355 void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) {
4356 GenerateImpl(masm, false);
4360 void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) {
4361 GenerateImpl(masm, true);
4365 void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) {
4368 // TODO(mvstanton): Implement.
4370 KeyedStoreIC::GenerateMiss(masm);
4374 void CallICTrampolineStub::Generate(MacroAssembler* masm) {
4375 EmitLoadTypeFeedbackVector(masm, ebx);
4376 CallICStub stub(isolate(), state());
4377 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
4381 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) {
4382 EmitLoadTypeFeedbackVector(masm, ebx);
4383 CallIC_ArrayStub stub(isolate(), state());
4384 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
4388 void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
4389 if (masm->isolate()->function_entry_hook() != NULL) {
4390 ProfileEntryHookStub stub(masm->isolate());
4391 masm->CallStub(&stub);
4396 void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
4397 // Save volatile registers.
4398 const int kNumSavedRegisters = 3;
4403 // Calculate and push the original stack pointer.
4404 __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize));
4407 // Retrieve our return address and use it to calculate the calling
4408 // function's address.
4409 __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize));
4410 __ sub(eax, Immediate(Assembler::kCallInstructionLength));
4413 // Call the entry hook.
4414 DCHECK(isolate()->function_entry_hook() != NULL);
4415 __ call(FUNCTION_ADDR(isolate()->function_entry_hook()),
4416 RelocInfo::RUNTIME_ENTRY);
4417 __ add(esp, Immediate(2 * kPointerSize));
4429 static void CreateArrayDispatch(MacroAssembler* masm,
4430 AllocationSiteOverrideMode mode) {
4431 if (mode == DISABLE_ALLOCATION_SITES) {
4432 T stub(masm->isolate(),
4433 GetInitialFastElementsKind(),
4435 __ TailCallStub(&stub);
4436 } else if (mode == DONT_OVERRIDE) {
4437 int last_index = GetSequenceIndexFromFastElementsKind(
4438 TERMINAL_FAST_ELEMENTS_KIND);
4439 for (int i = 0; i <= last_index; ++i) {
4441 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4443 __ j(not_equal, &next);
4444 T stub(masm->isolate(), kind);
4445 __ TailCallStub(&stub);
4449 // If we reached this point there is a problem.
4450 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4457 static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
4458 AllocationSiteOverrideMode mode) {
4459 // ebx - allocation site (if mode != DISABLE_ALLOCATION_SITES)
4460 // edx - kind (if mode != DISABLE_ALLOCATION_SITES)
4461 // eax - number of arguments
4462 // edi - constructor?
4463 // esp[0] - return address
4464 // esp[4] - last argument
4465 Label normal_sequence;
4466 if (mode == DONT_OVERRIDE) {
4467 DCHECK(FAST_SMI_ELEMENTS == 0);
4468 DCHECK(FAST_HOLEY_SMI_ELEMENTS == 1);
4469 DCHECK(FAST_ELEMENTS == 2);
4470 DCHECK(FAST_HOLEY_ELEMENTS == 3);
4471 DCHECK(FAST_DOUBLE_ELEMENTS == 4);
4472 DCHECK(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
4474 // is the low bit set? If so, we are holey and that is good.
4476 __ j(not_zero, &normal_sequence);
4479 // look at the first argument
4480 __ mov(ecx, Operand(esp, kPointerSize));
4482 __ j(zero, &normal_sequence);
4484 if (mode == DISABLE_ALLOCATION_SITES) {
4485 ElementsKind initial = GetInitialFastElementsKind();
4486 ElementsKind holey_initial = GetHoleyElementsKind(initial);
4488 ArraySingleArgumentConstructorStub stub_holey(masm->isolate(),
4490 DISABLE_ALLOCATION_SITES);
4491 __ TailCallStub(&stub_holey);
4493 __ bind(&normal_sequence);
4494 ArraySingleArgumentConstructorStub stub(masm->isolate(),
4496 DISABLE_ALLOCATION_SITES);
4497 __ TailCallStub(&stub);
4498 } else if (mode == DONT_OVERRIDE) {
4499 // We are going to create a holey array, but our kind is non-holey.
4500 // Fix kind and retry.
4503 if (FLAG_debug_code) {
4504 Handle<Map> allocation_site_map =
4505 masm->isolate()->factory()->allocation_site_map();
4506 __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map));
4507 __ Assert(equal, kExpectedAllocationSite);
4510 // Save the resulting elements kind in type info. We can't just store r3
4511 // in the AllocationSite::transition_info field because elements kind is
4512 // restricted to a portion of the field...upper bits need to be left alone.
4513 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4514 __ add(FieldOperand(ebx, AllocationSite::kTransitionInfoOffset),
4515 Immediate(Smi::FromInt(kFastElementsKindPackedToHoley)));
4517 __ bind(&normal_sequence);
4518 int last_index = GetSequenceIndexFromFastElementsKind(
4519 TERMINAL_FAST_ELEMENTS_KIND);
4520 for (int i = 0; i <= last_index; ++i) {
4522 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4524 __ j(not_equal, &next);
4525 ArraySingleArgumentConstructorStub stub(masm->isolate(), kind);
4526 __ TailCallStub(&stub);
4530 // If we reached this point there is a problem.
4531 __ Abort(kUnexpectedElementsKindInArrayConstructor);
4539 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
4540 int to_index = GetSequenceIndexFromFastElementsKind(
4541 TERMINAL_FAST_ELEMENTS_KIND);
4542 for (int i = 0; i <= to_index; ++i) {
4543 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
4544 T stub(isolate, kind);
4546 if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
4547 T stub1(isolate, kind, DISABLE_ALLOCATION_SITES);
4554 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
4555 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
4557 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
4559 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
4564 void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
4566 ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
4567 for (int i = 0; i < 2; i++) {
4568 // For internal arrays we only need a few things
4569 InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]);
4571 InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]);
4573 InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]);
4579 void ArrayConstructorStub::GenerateDispatchToArrayStub(
4580 MacroAssembler* masm,
4581 AllocationSiteOverrideMode mode) {
4582 if (argument_count() == ANY) {
4583 Label not_zero_case, not_one_case;
4585 __ j(not_zero, ¬_zero_case);
4586 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4588 __ bind(¬_zero_case);
4590 __ j(greater, ¬_one_case);
4591 CreateArrayDispatchOneArgument(masm, mode);
4593 __ bind(¬_one_case);
4594 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4595 } else if (argument_count() == NONE) {
4596 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
4597 } else if (argument_count() == ONE) {
4598 CreateArrayDispatchOneArgument(masm, mode);
4599 } else if (argument_count() == MORE_THAN_ONE) {
4600 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
4607 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
4608 // ----------- S t a t e -------------
4609 // -- eax : argc (only if argument_count() is ANY or MORE_THAN_ONE)
4610 // -- ebx : AllocationSite or undefined
4611 // -- edi : constructor
4612 // -- edx : Original constructor
4613 // -- esp[0] : return address
4614 // -- esp[4] : last argument
4615 // -----------------------------------
4616 if (FLAG_debug_code) {
4617 // The array construct code is only set for the global and natives
4618 // builtin Array functions which always have maps.
4620 // Initial map for the builtin Array function should be a map.
4621 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
4622 // Will both indicate a NULL and a Smi.
4623 __ test(ecx, Immediate(kSmiTagMask));
4624 __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction);
4625 __ CmpObjectType(ecx, MAP_TYPE, ecx);
4626 __ Assert(equal, kUnexpectedInitialMapForArrayFunction);
4628 // We should either have undefined in ebx or a valid AllocationSite
4629 __ AssertUndefinedOrAllocationSite(ebx);
4635 __ j(not_equal, &subclassing);
4638 // If the feedback vector is the undefined value call an array constructor
4639 // that doesn't use AllocationSites.
4640 __ cmp(ebx, isolate()->factory()->undefined_value());
4641 __ j(equal, &no_info);
4643 // Only look at the lower 16 bits of the transition info.
4644 __ mov(edx, FieldOperand(ebx, AllocationSite::kTransitionInfoOffset));
4646 STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
4647 __ and_(edx, Immediate(AllocationSite::ElementsKindBits::kMask));
4648 GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
4651 GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
4654 __ bind(&subclassing);
4655 __ pop(ecx); // return address.
4660 switch (argument_count()) {
4663 __ add(eax, Immediate(2));
4666 __ mov(eax, Immediate(2));
4669 __ mov(eax, Immediate(3));
4674 __ JumpToExternalReference(
4675 ExternalReference(Runtime::kArrayConstructorWithSubclassing, isolate()));
4679 void InternalArrayConstructorStub::GenerateCase(
4680 MacroAssembler* masm, ElementsKind kind) {
4681 Label not_zero_case, not_one_case;
4682 Label normal_sequence;
4685 __ j(not_zero, ¬_zero_case);
4686 InternalArrayNoArgumentConstructorStub stub0(isolate(), kind);
4687 __ TailCallStub(&stub0);
4689 __ bind(¬_zero_case);
4691 __ j(greater, ¬_one_case);
4693 if (IsFastPackedElementsKind(kind)) {
4694 // We might need to create a holey array
4695 // look at the first argument
4696 __ mov(ecx, Operand(esp, kPointerSize));
4698 __ j(zero, &normal_sequence);
4700 InternalArraySingleArgumentConstructorStub
4701 stub1_holey(isolate(), GetHoleyElementsKind(kind));
4702 __ TailCallStub(&stub1_holey);
4705 __ bind(&normal_sequence);
4706 InternalArraySingleArgumentConstructorStub stub1(isolate(), kind);
4707 __ TailCallStub(&stub1);
4709 __ bind(¬_one_case);
4710 InternalArrayNArgumentsConstructorStub stubN(isolate(), kind);
4711 __ TailCallStub(&stubN);
4715 void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
4716 // ----------- S t a t e -------------
4718 // -- edi : constructor
4719 // -- esp[0] : return address
4720 // -- esp[4] : last argument
4721 // -----------------------------------
4723 if (FLAG_debug_code) {
4724 // The array construct code is only set for the global and natives
4725 // builtin Array functions which always have maps.
4727 // Initial map for the builtin Array function should be a map.
4728 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
4729 // Will both indicate a NULL and a Smi.
4730 __ test(ecx, Immediate(kSmiTagMask));
4731 __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction);
4732 __ CmpObjectType(ecx, MAP_TYPE, ecx);
4733 __ Assert(equal, kUnexpectedInitialMapForArrayFunction);
4736 // Figure out the right elements kind
4737 __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
4739 // Load the map's "bit field 2" into |result|. We only need the first byte,
4740 // but the following masking takes care of that anyway.
4741 __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset));
4742 // Retrieve elements_kind from bit field 2.
4743 __ DecodeField<Map::ElementsKindBits>(ecx);
4745 if (FLAG_debug_code) {
4747 __ cmp(ecx, Immediate(FAST_ELEMENTS));
4749 __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS));
4751 kInvalidElementsKindForInternalArrayOrInternalPackedArray);
4755 Label fast_elements_case;
4756 __ cmp(ecx, Immediate(FAST_ELEMENTS));
4757 __ j(equal, &fast_elements_case);
4758 GenerateCase(masm, FAST_HOLEY_ELEMENTS);
4760 __ bind(&fast_elements_case);
4761 GenerateCase(masm, FAST_ELEMENTS);
4765 // Generates an Operand for saving parameters after PrepareCallApiFunction.
4766 static Operand ApiParameterOperand(int index) {
4767 return Operand(esp, index * kPointerSize);
4771 // Prepares stack to put arguments (aligns and so on). Reserves
4772 // space for return value if needed (assumes the return value is a handle).
4773 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1)
4774 // etc. Saves context (esi). If space was reserved for return value then
4775 // stores the pointer to the reserved slot into esi.
4776 static void PrepareCallApiFunction(MacroAssembler* masm, int argc) {
4777 __ EnterApiExitFrame(argc);
4778 if (__ emit_debug_code()) {
4779 __ mov(esi, Immediate(bit_cast<int32_t>(kZapValue)));
4784 // Calls an API function. Allocates HandleScope, extracts returned value
4785 // from handle and propagates exceptions. Clobbers ebx, edi and
4786 // caller-save registers. Restores context. On return removes
4787 // stack_space * kPointerSize (GCed).
4788 static void CallApiFunctionAndReturn(MacroAssembler* masm,
4789 Register function_address,
4790 ExternalReference thunk_ref,
4791 Operand thunk_last_arg, int stack_space,
4792 Operand* stack_space_operand,
4793 Operand return_value_operand,
4794 Operand* context_restore_operand) {
4795 Isolate* isolate = masm->isolate();
4797 ExternalReference next_address =
4798 ExternalReference::handle_scope_next_address(isolate);
4799 ExternalReference limit_address =
4800 ExternalReference::handle_scope_limit_address(isolate);
4801 ExternalReference level_address =
4802 ExternalReference::handle_scope_level_address(isolate);
4804 DCHECK(edx.is(function_address));
4805 // Allocate HandleScope in callee-save registers.
4806 __ mov(ebx, Operand::StaticVariable(next_address));
4807 __ mov(edi, Operand::StaticVariable(limit_address));
4808 __ add(Operand::StaticVariable(level_address), Immediate(1));
4810 if (FLAG_log_timer_events) {
4811 FrameScope frame(masm, StackFrame::MANUAL);
4812 __ PushSafepointRegisters();
4813 __ PrepareCallCFunction(1, eax);
4814 __ mov(Operand(esp, 0),
4815 Immediate(ExternalReference::isolate_address(isolate)));
4816 __ CallCFunction(ExternalReference::log_enter_external_function(isolate),
4818 __ PopSafepointRegisters();
4822 Label profiler_disabled;
4823 Label end_profiler_check;
4824 __ mov(eax, Immediate(ExternalReference::is_profiling_address(isolate)));
4825 __ cmpb(Operand(eax, 0), 0);
4826 __ j(zero, &profiler_disabled);
4828 // Additional parameter is the address of the actual getter function.
4829 __ mov(thunk_last_arg, function_address);
4830 // Call the api function.
4831 __ mov(eax, Immediate(thunk_ref));
4833 __ jmp(&end_profiler_check);
4835 __ bind(&profiler_disabled);
4836 // Call the api function.
4837 __ call(function_address);
4838 __ bind(&end_profiler_check);
4840 if (FLAG_log_timer_events) {
4841 FrameScope frame(masm, StackFrame::MANUAL);
4842 __ PushSafepointRegisters();
4843 __ PrepareCallCFunction(1, eax);
4844 __ mov(Operand(esp, 0),
4845 Immediate(ExternalReference::isolate_address(isolate)));
4846 __ CallCFunction(ExternalReference::log_leave_external_function(isolate),
4848 __ PopSafepointRegisters();
4852 // Load the value from ReturnValue
4853 __ mov(eax, return_value_operand);
4855 Label promote_scheduled_exception;
4856 Label delete_allocated_handles;
4857 Label leave_exit_frame;
4860 // No more valid handles (the result handle was the last one). Restore
4861 // previous handle scope.
4862 __ mov(Operand::StaticVariable(next_address), ebx);
4863 __ sub(Operand::StaticVariable(level_address), Immediate(1));
4864 __ Assert(above_equal, kInvalidHandleScopeLevel);
4865 __ cmp(edi, Operand::StaticVariable(limit_address));
4866 __ j(not_equal, &delete_allocated_handles);
4868 // Leave the API exit frame.
4869 __ bind(&leave_exit_frame);
4870 bool restore_context = context_restore_operand != NULL;
4871 if (restore_context) {
4872 __ mov(esi, *context_restore_operand);
4874 if (stack_space_operand != nullptr) {
4875 __ mov(ebx, *stack_space_operand);
4877 __ LeaveApiExitFrame(!restore_context);
4879 // Check if the function scheduled an exception.
4880 ExternalReference scheduled_exception_address =
4881 ExternalReference::scheduled_exception_address(isolate);
4882 __ cmp(Operand::StaticVariable(scheduled_exception_address),
4883 Immediate(isolate->factory()->the_hole_value()));
4884 __ j(not_equal, &promote_scheduled_exception);
4887 // Check if the function returned a valid JavaScript value.
4889 Register return_value = eax;
4892 __ JumpIfSmi(return_value, &ok, Label::kNear);
4893 __ mov(map, FieldOperand(return_value, HeapObject::kMapOffset));
4895 __ CmpInstanceType(map, LAST_NAME_TYPE);
4896 __ j(below_equal, &ok, Label::kNear);
4898 __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE);
4899 __ j(above_equal, &ok, Label::kNear);
4901 __ cmp(map, isolate->factory()->heap_number_map());
4902 __ j(equal, &ok, Label::kNear);
4904 __ cmp(return_value, isolate->factory()->undefined_value());
4905 __ j(equal, &ok, Label::kNear);
4907 __ cmp(return_value, isolate->factory()->true_value());
4908 __ j(equal, &ok, Label::kNear);
4910 __ cmp(return_value, isolate->factory()->false_value());
4911 __ j(equal, &ok, Label::kNear);
4913 __ cmp(return_value, isolate->factory()->null_value());
4914 __ j(equal, &ok, Label::kNear);
4916 __ Abort(kAPICallReturnedInvalidObject);
4921 if (stack_space_operand != nullptr) {
4922 DCHECK_EQ(0, stack_space);
4927 __ ret(stack_space * kPointerSize);
4930 // Re-throw by promoting a scheduled exception.
4931 __ bind(&promote_scheduled_exception);
4932 __ TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1);
4934 // HandleScope limit has changed. Delete allocated extensions.
4935 ExternalReference delete_extensions =
4936 ExternalReference::delete_handle_scope_extensions(isolate);
4937 __ bind(&delete_allocated_handles);
4938 __ mov(Operand::StaticVariable(limit_address), edi);
4940 __ mov(Operand(esp, 0),
4941 Immediate(ExternalReference::isolate_address(isolate)));
4942 __ mov(eax, Immediate(delete_extensions));
4945 __ jmp(&leave_exit_frame);
4949 static void CallApiFunctionStubHelper(MacroAssembler* masm,
4950 const ParameterCount& argc,
4951 bool return_first_arg,
4952 bool call_data_undefined) {
4953 // ----------- S t a t e -------------
4955 // -- ebx : call_data
4957 // -- edx : api_function_address
4959 // -- eax : number of arguments if argc is a register
4961 // -- esp[0] : return address
4962 // -- esp[4] : last argument
4964 // -- esp[argc * 4] : first argument
4965 // -- esp[(argc + 1) * 4] : receiver
4966 // -----------------------------------
4968 Register callee = edi;
4969 Register call_data = ebx;
4970 Register holder = ecx;
4971 Register api_function_address = edx;
4972 Register context = esi;
4973 Register return_address = eax;
4975 typedef FunctionCallbackArguments FCA;
4977 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
4978 STATIC_ASSERT(FCA::kCalleeIndex == 5);
4979 STATIC_ASSERT(FCA::kDataIndex == 4);
4980 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
4981 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
4982 STATIC_ASSERT(FCA::kIsolateIndex == 1);
4983 STATIC_ASSERT(FCA::kHolderIndex == 0);
4984 STATIC_ASSERT(FCA::kArgsLength == 7);
4986 DCHECK(argc.is_immediate() || eax.is(argc.reg()));
4988 if (argc.is_immediate()) {
4989 __ pop(return_address);
4993 // pop return address and save context
4994 __ xchg(context, Operand(esp, 0));
4995 return_address = context;
5004 Register scratch = call_data;
5005 if (!call_data_undefined) {
5007 __ push(Immediate(masm->isolate()->factory()->undefined_value()));
5008 // return value default
5009 __ push(Immediate(masm->isolate()->factory()->undefined_value()));
5013 // return value default
5017 __ push(Immediate(reinterpret_cast<int>(masm->isolate())));
5021 __ mov(scratch, esp);
5023 // push return address
5024 __ push(return_address);
5026 // load context from callee
5027 __ mov(context, FieldOperand(callee, JSFunction::kContextOffset));
5029 // API function gets reference to the v8::Arguments. If CPU profiler
5030 // is enabled wrapper function will be called and we need to pass
5031 // address of the callback as additional parameter, always allocate
5033 const int kApiArgc = 1 + 1;
5035 // Allocate the v8::Arguments structure in the arguments' space since
5036 // it's not controlled by GC.
5037 const int kApiStackSpace = 4;
5039 PrepareCallApiFunction(masm, kApiArgc + kApiStackSpace);
5041 // FunctionCallbackInfo::implicit_args_.
5042 __ mov(ApiParameterOperand(2), scratch);
5043 if (argc.is_immediate()) {
5045 Immediate((argc.immediate() + FCA::kArgsLength - 1) * kPointerSize));
5046 // FunctionCallbackInfo::values_.
5047 __ mov(ApiParameterOperand(3), scratch);
5048 // FunctionCallbackInfo::length_.
5049 __ Move(ApiParameterOperand(4), Immediate(argc.immediate()));
5050 // FunctionCallbackInfo::is_construct_call_.
5051 __ Move(ApiParameterOperand(5), Immediate(0));
5053 __ lea(scratch, Operand(scratch, argc.reg(), times_pointer_size,
5054 (FCA::kArgsLength - 1) * kPointerSize));
5055 // FunctionCallbackInfo::values_.
5056 __ mov(ApiParameterOperand(3), scratch);
5057 // FunctionCallbackInfo::length_.
5058 __ mov(ApiParameterOperand(4), argc.reg());
5059 // FunctionCallbackInfo::is_construct_call_.
5060 __ lea(argc.reg(), Operand(argc.reg(), times_pointer_size,
5061 (FCA::kArgsLength + 1) * kPointerSize));
5062 __ mov(ApiParameterOperand(5), argc.reg());
5065 // v8::InvocationCallback's argument.
5066 __ lea(scratch, ApiParameterOperand(2));
5067 __ mov(ApiParameterOperand(0), scratch);
5069 ExternalReference thunk_ref =
5070 ExternalReference::invoke_function_callback(masm->isolate());
5072 Operand context_restore_operand(ebp,
5073 (2 + FCA::kContextSaveIndex) * kPointerSize);
5074 // Stores return the first js argument
5075 int return_value_offset = 0;
5076 if (return_first_arg) {
5077 return_value_offset = 2 + FCA::kArgsLength;
5079 return_value_offset = 2 + FCA::kReturnValueOffset;
5081 Operand return_value_operand(ebp, return_value_offset * kPointerSize);
5082 int stack_space = 0;
5083 Operand is_construct_call_operand = ApiParameterOperand(5);
5084 Operand* stack_space_operand = &is_construct_call_operand;
5085 if (argc.is_immediate()) {
5086 stack_space = argc.immediate() + FCA::kArgsLength + 1;
5087 stack_space_operand = nullptr;
5089 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5090 ApiParameterOperand(1), stack_space,
5091 stack_space_operand, return_value_operand,
5092 &context_restore_operand);
5096 void CallApiFunctionStub::Generate(MacroAssembler* masm) {
5097 bool call_data_undefined = this->call_data_undefined();
5098 CallApiFunctionStubHelper(masm, ParameterCount(eax), false,
5099 call_data_undefined);
5103 void CallApiAccessorStub::Generate(MacroAssembler* masm) {
5104 bool is_store = this->is_store();
5105 int argc = this->argc();
5106 bool call_data_undefined = this->call_data_undefined();
5107 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store,
5108 call_data_undefined);
5112 void CallApiGetterStub::Generate(MacroAssembler* masm) {
5113 // ----------- S t a t e -------------
5114 // -- esp[0] : return address
5116 // -- esp[8 - kArgsLength*4] : PropertyCallbackArguments object
5118 // -- edx : api_function_address
5119 // -----------------------------------
5120 DCHECK(edx.is(ApiGetterDescriptor::function_address()));
5122 // array for v8::Arguments::values_, handler for name and pointer
5123 // to the values (it considered as smi in GC).
5124 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 2;
5125 // Allocate space for opional callback address parameter in case
5126 // CPU profiler is active.
5127 const int kApiArgc = 2 + 1;
5129 Register api_function_address = edx;
5130 Register scratch = ebx;
5132 // load address of name
5133 __ lea(scratch, Operand(esp, 1 * kPointerSize));
5135 PrepareCallApiFunction(masm, kApiArgc);
5136 __ mov(ApiParameterOperand(0), scratch); // name.
5137 __ add(scratch, Immediate(kPointerSize));
5138 __ mov(ApiParameterOperand(1), scratch); // arguments pointer.
5140 ExternalReference thunk_ref =
5141 ExternalReference::invoke_accessor_getter_callback(isolate());
5143 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref,
5144 ApiParameterOperand(2), kStackSpace, nullptr,
5145 Operand(ebp, 7 * kPointerSize), NULL);
5151 } // namespace internal
5154 #endif // V8_TARGET_ARCH_X87