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/codegen.h"
10 #include "src/deoptimizer.h"
11 #include "src/full-codegen.h"
12 #include "src/stub-cache.h"
18 #define __ ACCESS_MASM(masm)
21 void Builtins::Generate_Adaptor(MacroAssembler* masm,
23 BuiltinExtraArguments extra_args) {
24 // ----------- S t a t e -------------
25 // -- eax : number of arguments excluding receiver
26 // -- edi : called function (only guaranteed when
27 // extra_args requires it)
29 // -- esp[0] : return address
30 // -- esp[4] : last argument
32 // -- esp[4 * argc] : first argument (argc == eax)
33 // -- esp[4 * (argc +1)] : receiver
34 // -----------------------------------
36 // Insert extra arguments.
37 int num_extra_args = 0;
38 if (extra_args == NEEDS_CALLED_FUNCTION) {
40 Register scratch = ebx;
41 __ pop(scratch); // Save return address.
43 __ push(scratch); // Restore return address.
45 DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
48 // JumpToExternalReference expects eax to contain the number of arguments
49 // including the receiver and the extra arguments.
50 __ add(eax, Immediate(num_extra_args + 1));
51 __ JumpToExternalReference(ExternalReference(id, masm->isolate()));
55 static void CallRuntimePassFunction(
56 MacroAssembler* masm, Runtime::FunctionId function_id) {
57 FrameScope scope(masm, StackFrame::INTERNAL);
58 // Push a copy of the function.
60 // Function is also the parameter to the runtime call.
63 __ CallRuntime(function_id, 1);
69 static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
70 __ mov(eax, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
71 __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kCodeOffset));
72 __ lea(eax, FieldOperand(eax, Code::kHeaderSize));
77 static void GenerateTailCallToReturnedCode(MacroAssembler* masm) {
78 __ lea(eax, FieldOperand(eax, Code::kHeaderSize));
83 void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
84 // Checking whether the queued function is ready for install is optional,
85 // since we come across interrupts and stack checks elsewhere. However,
86 // not checking may delay installing ready functions, and always checking
87 // would be quite expensive. A good compromise is to first check against
88 // stack limit as a cue for an interrupt signal.
90 ExternalReference stack_limit =
91 ExternalReference::address_of_stack_limit(masm->isolate());
92 __ cmp(esp, Operand::StaticVariable(stack_limit));
93 __ j(above_equal, &ok, Label::kNear);
95 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode);
96 GenerateTailCallToReturnedCode(masm);
99 GenerateTailCallToSharedCode(masm);
103 static void Generate_JSConstructStubHelper(MacroAssembler* masm,
104 bool is_api_function,
105 bool create_memento) {
106 // ----------- S t a t e -------------
107 // -- eax: number of arguments
108 // -- edi: constructor function
109 // -- ebx: allocation site or undefined
110 // -----------------------------------
112 // Should never create mementos for api functions.
113 DCHECK(!is_api_function || !create_memento);
115 // Enter a construct frame.
117 FrameScope scope(masm, StackFrame::CONSTRUCT);
119 if (create_memento) {
120 __ AssertUndefinedOrAllocationSite(ebx);
124 // Store a smi-tagged arguments count on the stack.
128 // Push the function to invoke on the stack.
131 // Try to allocate the object without transitioning into C code. If any of
132 // the preconditions is not met, the code bails out to the runtime call.
133 Label rt_call, allocated;
134 if (FLAG_inline_new) {
135 Label undo_allocation;
136 ExternalReference debug_step_in_fp =
137 ExternalReference::debug_step_in_fp_address(masm->isolate());
138 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0));
139 __ j(not_equal, &rt_call);
141 // Verified that the constructor is a JSFunction.
142 // Load the initial map and verify that it is in fact a map.
144 __ mov(eax, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
145 // Will both indicate a NULL and a Smi
146 __ JumpIfSmi(eax, &rt_call);
148 // eax: initial map (if proven valid below)
149 __ CmpObjectType(eax, MAP_TYPE, ebx);
150 __ j(not_equal, &rt_call);
152 // Check that the constructor is not constructing a JSFunction (see
153 // comments in Runtime_NewObject in runtime.cc). In which case the
154 // initial map's instance type would be JS_FUNCTION_TYPE.
157 __ CmpInstanceType(eax, JS_FUNCTION_TYPE);
158 __ j(equal, &rt_call);
160 if (!is_api_function) {
162 // The code below relies on these assumptions.
163 STATIC_ASSERT(JSFunction::kNoSlackTracking == 0);
164 STATIC_ASSERT(Map::ConstructionCount::kShift +
165 Map::ConstructionCount::kSize == 32);
166 // Check if slack tracking is enabled.
167 __ mov(esi, FieldOperand(eax, Map::kBitField3Offset));
168 __ shr(esi, Map::ConstructionCount::kShift);
169 __ j(zero, &allocate); // JSFunction::kNoSlackTracking
170 // Decrease generous allocation count.
171 __ sub(FieldOperand(eax, Map::kBitField3Offset),
172 Immediate(1 << Map::ConstructionCount::kShift));
174 __ cmp(esi, JSFunction::kFinishSlackTracking);
175 __ j(not_equal, &allocate);
180 __ push(edi); // constructor
181 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
185 __ xor_(esi, esi); // JSFunction::kNoSlackTracking
190 // Now allocate the JSObject on the heap.
193 __ movzx_b(edi, FieldOperand(eax, Map::kInstanceSizeOffset));
194 __ shl(edi, kPointerSizeLog2);
195 if (create_memento) {
196 __ add(edi, Immediate(AllocationMemento::kSize));
199 __ Allocate(edi, ebx, edi, no_reg, &rt_call, NO_ALLOCATION_FLAGS);
201 Factory* factory = masm->isolate()->factory();
203 // Allocated the JSObject, now initialize the fields.
206 // edi: start of next object (including memento if create_memento)
207 __ mov(Operand(ebx, JSObject::kMapOffset), eax);
208 __ mov(ecx, factory->empty_fixed_array());
209 __ mov(Operand(ebx, JSObject::kPropertiesOffset), ecx);
210 __ mov(Operand(ebx, JSObject::kElementsOffset), ecx);
211 // Set extra fields in the newly allocated object.
214 // edi: start of next object (including memento if create_memento)
215 // esi: slack tracking counter (non-API function case)
216 __ mov(edx, factory->undefined_value());
217 __ lea(ecx, Operand(ebx, JSObject::kHeaderSize));
218 if (!is_api_function) {
219 Label no_inobject_slack_tracking;
221 // Check if slack tracking is enabled.
222 __ cmp(esi, JSFunction::kNoSlackTracking);
223 __ j(equal, &no_inobject_slack_tracking);
225 // Allocate object with a slack.
227 FieldOperand(eax, Map::kPreAllocatedPropertyFieldsOffset));
229 Operand(ebx, esi, times_pointer_size, JSObject::kHeaderSize));
230 // esi: offset of first field after pre-allocated fields
231 if (FLAG_debug_code) {
233 __ Assert(less_equal,
234 kUnexpectedNumberOfPreAllocatedPropertyFields);
236 __ InitializeFieldsWithFiller(ecx, esi, edx);
237 __ mov(edx, factory->one_pointer_filler_map());
238 // Fill the remaining fields with one pointer filler map.
240 __ bind(&no_inobject_slack_tracking);
243 if (create_memento) {
244 __ lea(esi, Operand(edi, -AllocationMemento::kSize));
245 __ InitializeFieldsWithFiller(ecx, esi, edx);
247 // Fill in memento fields if necessary.
248 // esi: points to the allocated but uninitialized memento.
249 __ mov(Operand(esi, AllocationMemento::kMapOffset),
250 factory->allocation_memento_map());
251 // Get the cell or undefined.
252 __ mov(edx, Operand(esp, kPointerSize*2));
253 __ mov(Operand(esi, AllocationMemento::kAllocationSiteOffset),
256 __ InitializeFieldsWithFiller(ecx, edi, edx);
259 // Add the object tag to make the JSObject real, so that we can continue
260 // and jump into the continuation code at any time from now on. Any
261 // failures need to undo the allocation, so that the heap is in a
262 // consistent state and verifiable.
265 // edi: start of next object
266 __ or_(ebx, Immediate(kHeapObjectTag));
268 // Check if a non-empty properties array is needed.
269 // Allocate and initialize a FixedArray if it is.
272 // edi: start of next object
273 // Calculate the total number of properties described by the map.
274 __ movzx_b(edx, FieldOperand(eax, Map::kUnusedPropertyFieldsOffset));
276 FieldOperand(eax, Map::kPreAllocatedPropertyFieldsOffset));
278 // Calculate unused properties past the end of the in-object properties.
279 __ movzx_b(ecx, FieldOperand(eax, Map::kInObjectPropertiesOffset));
281 // Done if no extra properties are to be allocated.
282 __ j(zero, &allocated);
283 __ Assert(positive, kPropertyAllocationCountFailed);
285 // Scale the number of elements by pointer size and add the header for
286 // FixedArrays to the start of the next object calculation from above.
288 // edi: start of next object (will be start of FixedArray)
289 // edx: number of elements in properties array
290 __ Allocate(FixedArray::kHeaderSize,
293 REGISTER_VALUE_IS_INT32,
298 RESULT_CONTAINS_TOP);
300 // Initialize the FixedArray.
303 // edx: number of elements
304 // ecx: start of next object
305 __ mov(eax, factory->fixed_array_map());
306 __ mov(Operand(edi, FixedArray::kMapOffset), eax); // setup the map
308 __ mov(Operand(edi, FixedArray::kLengthOffset), edx); // and length
310 // Initialize the fields to undefined.
313 // ecx: start of next object
315 __ mov(edx, factory->undefined_value());
316 __ lea(eax, Operand(edi, FixedArray::kHeaderSize));
319 __ mov(Operand(eax, 0), edx);
320 __ add(eax, Immediate(kPointerSize));
326 // Store the initialized FixedArray into the properties field of
330 __ or_(edi, Immediate(kHeapObjectTag)); // add the heap tag
331 __ mov(FieldOperand(ebx, JSObject::kPropertiesOffset), edi);
334 // Continue with JSObject being successfully allocated
338 // Undo the setting of the new top so that the heap is verifiable. For
339 // example, the map's unused properties potentially do not match the
340 // allocated objects unused properties.
341 // ebx: JSObject (previous new top)
342 __ bind(&undo_allocation);
343 __ UndoAllocationInNewSpace(ebx);
346 // Allocate the new receiver object using the runtime call.
349 if (create_memento) {
350 // Get the cell or allocation site.
351 __ mov(edi, Operand(esp, kPointerSize * 2));
353 offset = kPointerSize;
356 // Must restore esi (context) and edi (constructor) before calling runtime.
357 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
358 __ mov(edi, Operand(esp, offset));
359 // edi: function (constructor)
361 if (create_memento) {
362 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 2);
364 __ CallRuntime(Runtime::kNewObject, 1);
366 __ mov(ebx, eax); // store result in ebx
368 // If we ended up using the runtime, and we want a memento, then the
369 // runtime call made it for us, and we shouldn't do create count
371 Label count_incremented;
372 if (create_memento) {
373 __ jmp(&count_incremented);
376 // New object allocated.
377 // ebx: newly allocated object
380 if (create_memento) {
381 __ mov(ecx, Operand(esp, kPointerSize * 2));
382 __ cmp(ecx, masm->isolate()->factory()->undefined_value());
383 __ j(equal, &count_incremented);
384 // ecx is an AllocationSite. We are creating a memento from it, so we
385 // need to increment the memento create count.
386 __ add(FieldOperand(ecx, AllocationSite::kPretenureCreateCountOffset),
387 Immediate(Smi::FromInt(1)));
388 __ bind(&count_incremented);
391 // Retrieve the function from the stack.
394 // Retrieve smi-tagged arguments count from the stack.
395 __ mov(eax, Operand(esp, 0));
398 // Push the allocated receiver to the stack. We need two copies
399 // because we may have to return the original one and the calling
400 // conventions dictate that the called function pops the receiver.
404 // Set up pointer to last argument.
405 __ lea(ebx, Operand(ebp, StandardFrameConstants::kCallerSPOffset));
407 // Copy arguments and receiver to the expression stack.
412 __ push(Operand(ebx, ecx, times_4, 0));
415 __ j(greater_equal, &loop);
417 // Call the function.
418 if (is_api_function) {
419 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
421 masm->isolate()->builtins()->HandleApiCallConstruct();
422 __ call(code, RelocInfo::CODE_TARGET);
424 ParameterCount actual(eax);
425 __ InvokeFunction(edi, actual, CALL_FUNCTION,
429 // Store offset of return address for deoptimizer.
430 if (!is_api_function) {
431 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset());
434 // Restore context from the frame.
435 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
437 // If the result is an object (in the ECMA sense), we should get rid
438 // of the receiver and use the result; see ECMA-262 section 13.2.2-7
440 Label use_receiver, exit;
442 // If the result is a smi, it is *not* an object in the ECMA sense.
443 __ JumpIfSmi(eax, &use_receiver);
445 // If the type of the result (stored in its map) is less than
446 // FIRST_SPEC_OBJECT_TYPE, it is not an object in the ECMA sense.
447 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
448 __ j(above_equal, &exit);
450 // Throw away the result of the constructor invocation and use the
451 // on-stack receiver as the result.
452 __ bind(&use_receiver);
453 __ mov(eax, Operand(esp, 0));
455 // Restore the arguments count and leave the construct frame.
457 __ mov(ebx, Operand(esp, kPointerSize)); // Get arguments count.
459 // Leave construct frame.
462 // Remove caller arguments from the stack and return.
463 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
465 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); // 1 ~ receiver
467 __ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1);
472 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
473 Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new);
477 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
478 Generate_JSConstructStubHelper(masm, true, false);
482 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
484 ProfileEntryHookStub::MaybeCallEntryHook(masm);
486 // Clear the context before we push it when entering the internal frame.
487 __ Move(esi, Immediate(0));
490 FrameScope scope(masm, StackFrame::INTERNAL);
492 // Load the previous frame pointer (ebx) to access C arguments
493 __ mov(ebx, Operand(ebp, 0));
495 // Get the function from the frame and setup the context.
496 __ mov(ecx, Operand(ebx, EntryFrameConstants::kFunctionArgOffset));
497 __ mov(esi, FieldOperand(ecx, JSFunction::kContextOffset));
499 // Push the function and the receiver onto the stack.
501 __ push(Operand(ebx, EntryFrameConstants::kReceiverArgOffset));
503 // Load the number of arguments and setup pointer to the arguments.
504 __ mov(eax, Operand(ebx, EntryFrameConstants::kArgcOffset));
505 __ mov(ebx, Operand(ebx, EntryFrameConstants::kArgvOffset));
507 // Copy arguments to the stack in a loop.
509 __ Move(ecx, Immediate(0));
512 __ mov(edx, Operand(ebx, ecx, times_4, 0)); // push parameter from argv
513 __ push(Operand(edx, 0)); // dereference handle
517 __ j(not_equal, &loop);
519 // Get the function from the stack and call it.
520 // kPointerSize for the receiver.
521 __ mov(edi, Operand(esp, eax, times_4, kPointerSize));
525 // No type feedback cell is available
526 __ mov(ebx, masm->isolate()->factory()->undefined_value());
527 CallConstructStub stub(masm->isolate(), NO_CALL_CONSTRUCTOR_FLAGS);
530 ParameterCount actual(eax);
531 __ InvokeFunction(edi, actual, CALL_FUNCTION,
535 // Exit the internal frame. Notice that this also removes the empty.
536 // context and the function left on the stack by the code
539 __ ret(kPointerSize); // Remove receiver.
543 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
544 Generate_JSEntryTrampolineHelper(masm, false);
548 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
549 Generate_JSEntryTrampolineHelper(masm, true);
553 void Builtins::Generate_CompileUnoptimized(MacroAssembler* masm) {
554 CallRuntimePassFunction(masm, Runtime::kCompileUnoptimized);
555 GenerateTailCallToReturnedCode(masm);
560 static void CallCompileOptimized(MacroAssembler* masm, bool concurrent) {
561 FrameScope scope(masm, StackFrame::INTERNAL);
562 // Push a copy of the function.
564 // Function is also the parameter to the runtime call.
566 // Whether to compile in a background thread.
567 __ Push(masm->isolate()->factory()->ToBoolean(concurrent));
569 __ CallRuntime(Runtime::kCompileOptimized, 2);
575 void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
576 CallCompileOptimized(masm, false);
577 GenerateTailCallToReturnedCode(masm);
581 void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
582 CallCompileOptimized(masm, true);
583 GenerateTailCallToReturnedCode(masm);
587 static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) {
588 // For now, we are relying on the fact that make_code_young doesn't do any
589 // garbage collection which allows us to save/restore the registers without
590 // worrying about which of them contain pointers. We also don't build an
591 // internal frame to make the code faster, since we shouldn't have to do stack
592 // crawls in MakeCodeYoung. This seems a bit fragile.
594 // Re-execute the code that was patched back to the young age when
596 __ sub(Operand(esp, 0), Immediate(5));
598 __ mov(eax, Operand(esp, 8 * kPointerSize));
600 FrameScope scope(masm, StackFrame::MANUAL);
601 __ PrepareCallCFunction(2, ebx);
602 __ mov(Operand(esp, 1 * kPointerSize),
603 Immediate(ExternalReference::isolate_address(masm->isolate())));
604 __ mov(Operand(esp, 0), eax);
606 ExternalReference::get_make_code_young_function(masm->isolate()), 2);
612 #define DEFINE_CODE_AGE_BUILTIN_GENERATOR(C) \
613 void Builtins::Generate_Make##C##CodeYoungAgainEvenMarking( \
614 MacroAssembler* masm) { \
615 GenerateMakeCodeYoungAgainCommon(masm); \
617 void Builtins::Generate_Make##C##CodeYoungAgainOddMarking( \
618 MacroAssembler* masm) { \
619 GenerateMakeCodeYoungAgainCommon(masm); \
621 CODE_AGE_LIST(DEFINE_CODE_AGE_BUILTIN_GENERATOR)
622 #undef DEFINE_CODE_AGE_BUILTIN_GENERATOR
625 void Builtins::Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm) {
626 // For now, as in GenerateMakeCodeYoungAgainCommon, we are relying on the fact
627 // that make_code_young doesn't do any garbage collection which allows us to
628 // save/restore the registers without worrying about which of them contain
631 __ mov(eax, Operand(esp, 8 * kPointerSize));
632 __ sub(eax, Immediate(Assembler::kCallInstructionLength));
634 FrameScope scope(masm, StackFrame::MANUAL);
635 __ PrepareCallCFunction(2, ebx);
636 __ mov(Operand(esp, 1 * kPointerSize),
637 Immediate(ExternalReference::isolate_address(masm->isolate())));
638 __ mov(Operand(esp, 0), eax);
640 ExternalReference::get_mark_code_as_executed_function(masm->isolate()),
645 // Perform prologue operations usually performed by the young code stub.
646 __ pop(eax); // Pop return address into scratch register.
647 __ push(ebp); // Caller's frame pointer.
649 __ push(esi); // Callee's context.
650 __ push(edi); // Callee's JS Function.
651 __ push(eax); // Push return address after frame prologue.
653 // Jump to point after the code-age stub.
658 void Builtins::Generate_MarkCodeAsExecutedTwice(MacroAssembler* masm) {
659 GenerateMakeCodeYoungAgainCommon(masm);
663 static void Generate_NotifyStubFailureHelper(MacroAssembler* masm) {
664 // Enter an internal frame.
666 FrameScope scope(masm, StackFrame::INTERNAL);
668 // Preserve registers across notification, this is important for compiled
669 // stubs that tail call the runtime on deopts passing their parameters in
672 __ CallRuntime(Runtime::kNotifyStubFailure, 0);
674 // Tear down internal frame.
677 __ pop(MemOperand(esp, 0)); // Ignore state offset
678 __ ret(0); // Return to IC Miss stub, continuation still on stack.
682 void Builtins::Generate_NotifyStubFailure(MacroAssembler* masm) {
683 Generate_NotifyStubFailureHelper(masm);
687 void Builtins::Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm) {
688 // SaveDoubles is meanless for X87, just used by deoptimizer.cc
689 Generate_NotifyStubFailureHelper(masm);
693 static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm,
694 Deoptimizer::BailoutType type) {
696 FrameScope scope(masm, StackFrame::INTERNAL);
698 // Pass deoptimization type to the runtime system.
699 __ push(Immediate(Smi::FromInt(static_cast<int>(type))));
700 __ CallRuntime(Runtime::kNotifyDeoptimized, 1);
702 // Tear down internal frame.
705 // Get the full codegen state from the stack and untag it.
706 __ mov(ecx, Operand(esp, 1 * kPointerSize));
709 // Switch on the state.
710 Label not_no_registers, not_tos_eax;
711 __ cmp(ecx, FullCodeGenerator::NO_REGISTERS);
712 __ j(not_equal, ¬_no_registers, Label::kNear);
713 __ ret(1 * kPointerSize); // Remove state.
715 __ bind(¬_no_registers);
716 __ mov(eax, Operand(esp, 2 * kPointerSize));
717 __ cmp(ecx, FullCodeGenerator::TOS_REG);
718 __ j(not_equal, ¬_tos_eax, Label::kNear);
719 __ ret(2 * kPointerSize); // Remove state, eax.
721 __ bind(¬_tos_eax);
722 __ Abort(kNoCasesLeft);
726 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) {
727 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER);
731 void Builtins::Generate_NotifySoftDeoptimized(MacroAssembler* masm) {
732 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::SOFT);
736 void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
737 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
741 void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
742 Factory* factory = masm->isolate()->factory();
744 // 1. Make sure we have at least one argument.
747 __ j(not_zero, &done);
749 __ push(Immediate(factory->undefined_value()));
755 // 2. Get the function to call (passed as receiver) from the stack, check
756 // if it is a function.
757 Label slow, non_function;
758 // 1 ~ return address.
759 __ mov(edi, Operand(esp, eax, times_4, 1 * kPointerSize));
760 __ JumpIfSmi(edi, &non_function);
761 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
762 __ j(not_equal, &slow);
765 // 3a. Patch the first argument if necessary when calling a function.
766 Label shift_arguments;
767 __ Move(edx, Immediate(0)); // indicate regular JS_FUNCTION
768 { Label convert_to_object, use_global_proxy, patch_receiver;
769 // Change context eagerly in case we need the global receiver.
770 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
772 // Do not transform the receiver for strict mode functions.
773 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
774 __ test_b(FieldOperand(ebx, SharedFunctionInfo::kStrictModeByteOffset),
775 1 << SharedFunctionInfo::kStrictModeBitWithinByte);
776 __ j(not_equal, &shift_arguments);
778 // Do not transform the receiver for natives (shared already in ebx).
779 __ test_b(FieldOperand(ebx, SharedFunctionInfo::kNativeByteOffset),
780 1 << SharedFunctionInfo::kNativeBitWithinByte);
781 __ j(not_equal, &shift_arguments);
783 // Compute the receiver in sloppy mode.
784 __ mov(ebx, Operand(esp, eax, times_4, 0)); // First argument.
786 // Call ToObject on the receiver if it is not an object, or use the
787 // global object if it is null or undefined.
788 __ JumpIfSmi(ebx, &convert_to_object);
789 __ cmp(ebx, factory->null_value());
790 __ j(equal, &use_global_proxy);
791 __ cmp(ebx, factory->undefined_value());
792 __ j(equal, &use_global_proxy);
793 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
794 __ CmpObjectType(ebx, FIRST_SPEC_OBJECT_TYPE, ecx);
795 __ j(above_equal, &shift_arguments);
797 __ bind(&convert_to_object);
799 { // In order to preserve argument count.
800 FrameScope scope(masm, StackFrame::INTERNAL);
805 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
807 __ Move(edx, Immediate(0)); // restore
813 // Restore the function to edi.
814 __ mov(edi, Operand(esp, eax, times_4, 1 * kPointerSize));
815 __ jmp(&patch_receiver);
817 __ bind(&use_global_proxy);
819 Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
820 __ mov(ebx, FieldOperand(ebx, GlobalObject::kGlobalProxyOffset));
822 __ bind(&patch_receiver);
823 __ mov(Operand(esp, eax, times_4, 0), ebx);
825 __ jmp(&shift_arguments);
828 // 3b. Check for function proxy.
830 __ Move(edx, Immediate(1)); // indicate function proxy
831 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE);
832 __ j(equal, &shift_arguments);
833 __ bind(&non_function);
834 __ Move(edx, Immediate(2)); // indicate non-function
836 // 3c. Patch the first argument when calling a non-function. The
837 // CALL_NON_FUNCTION builtin expects the non-function callee as
838 // receiver, so overwrite the first argument which will ultimately
839 // become the receiver.
840 __ mov(Operand(esp, eax, times_4, 0), edi);
842 // 4. Shift arguments and return address one slot down on the stack
843 // (overwriting the original receiver). Adjust argument count to make
844 // the original first argument the new receiver.
845 __ bind(&shift_arguments);
849 __ mov(ebx, Operand(esp, ecx, times_4, 0));
850 __ mov(Operand(esp, ecx, times_4, kPointerSize), ebx);
852 __ j(not_sign, &loop); // While non-negative (to copy return address).
853 __ pop(ebx); // Discard copy of return address.
854 __ dec(eax); // One fewer argument (first argument is new receiver).
857 // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin,
858 // or a function proxy via CALL_FUNCTION_PROXY.
859 { Label function, non_proxy;
861 __ j(zero, &function);
862 __ Move(ebx, Immediate(0));
863 __ cmp(edx, Immediate(1));
864 __ j(not_equal, &non_proxy);
866 __ pop(edx); // return address
867 __ push(edi); // re-add proxy object as additional argument
870 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY);
871 __ jmp(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
872 RelocInfo::CODE_TARGET);
875 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION);
876 __ jmp(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
877 RelocInfo::CODE_TARGET);
881 // 5b. Get the code to call from the function and check that the number of
882 // expected arguments matches what we're providing. If so, jump
883 // (tail-call) to the code in register edx without checking arguments.
884 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
886 FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
887 __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset));
891 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline());
893 ParameterCount expected(0);
894 __ InvokeCode(edx, expected, expected, JUMP_FUNCTION, NullCallWrapper());
898 void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
899 static const int kArgumentsOffset = 2 * kPointerSize;
900 static const int kReceiverOffset = 3 * kPointerSize;
901 static const int kFunctionOffset = 4 * kPointerSize;
903 FrameScope frame_scope(masm, StackFrame::INTERNAL);
905 __ push(Operand(ebp, kFunctionOffset)); // push this
906 __ push(Operand(ebp, kArgumentsOffset)); // push arguments
907 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION);
909 // Check the stack for overflow. We are not trying to catch
910 // interruptions (e.g. debug break and preemption) here, so the "real stack
911 // limit" is checked.
913 ExternalReference real_stack_limit =
914 ExternalReference::address_of_real_stack_limit(masm->isolate());
915 __ mov(edi, Operand::StaticVariable(real_stack_limit));
916 // Make ecx the space we have left. The stack might already be overflowed
917 // here which will cause ecx to become negative.
920 // Make edx the space we need for the array when it is unrolled onto the
923 __ shl(edx, kPointerSizeLog2 - kSmiTagSize);
924 // Check if the arguments will overflow the stack.
926 __ j(greater, &okay); // Signed comparison.
928 // Out of stack space.
929 __ push(Operand(ebp, 4 * kPointerSize)); // push this
931 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
933 // End of stack check.
935 // Push current index and limit.
936 const int kLimitOffset =
937 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize;
938 const int kIndexOffset = kLimitOffset - 1 * kPointerSize;
939 __ push(eax); // limit
940 __ push(Immediate(0)); // index
943 __ mov(ebx, Operand(ebp, kReceiverOffset));
945 // Check that the function is a JS function (otherwise it must be a proxy).
946 Label push_receiver, use_global_proxy;
947 __ mov(edi, Operand(ebp, kFunctionOffset));
948 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
949 __ j(not_equal, &push_receiver);
951 // Change context eagerly to get the right global object if necessary.
952 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
954 // Compute the receiver.
955 // Do not transform the receiver for strict mode functions.
956 Label call_to_object;
957 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
958 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kStrictModeByteOffset),
959 1 << SharedFunctionInfo::kStrictModeBitWithinByte);
960 __ j(not_equal, &push_receiver);
962 Factory* factory = masm->isolate()->factory();
964 // Do not transform the receiver for natives (shared already in ecx).
965 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kNativeByteOffset),
966 1 << SharedFunctionInfo::kNativeBitWithinByte);
967 __ j(not_equal, &push_receiver);
969 // Compute the receiver in sloppy mode.
970 // Call ToObject on the receiver if it is not an object, or use the
971 // global object if it is null or undefined.
972 __ JumpIfSmi(ebx, &call_to_object);
973 __ cmp(ebx, factory->null_value());
974 __ j(equal, &use_global_proxy);
975 __ cmp(ebx, factory->undefined_value());
976 __ j(equal, &use_global_proxy);
977 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
978 __ CmpObjectType(ebx, FIRST_SPEC_OBJECT_TYPE, ecx);
979 __ j(above_equal, &push_receiver);
981 __ bind(&call_to_object);
983 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
985 __ jmp(&push_receiver);
987 __ bind(&use_global_proxy);
989 Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
990 __ mov(ebx, FieldOperand(ebx, GlobalObject::kGlobalProxyOffset));
992 // Push the receiver.
993 __ bind(&push_receiver);
996 // Copy all arguments from the array to the stack.
998 Register receiver = LoadIC::ReceiverRegister();
999 Register key = LoadIC::NameRegister();
1000 __ mov(key, Operand(ebp, kIndexOffset));
1003 __ mov(receiver, Operand(ebp, kArgumentsOffset)); // load arguments
1005 // Use inline caching to speed up access to arguments.
1006 if (FLAG_vector_ics) {
1007 __ mov(LoadIC::SlotRegister(), Immediate(Smi::FromInt(0)));
1009 Handle<Code> ic = masm->isolate()->builtins()->KeyedLoadIC_Initialize();
1010 __ call(ic, RelocInfo::CODE_TARGET);
1011 // It is important that we do not have a test instruction after the
1012 // call. A test instruction after the call is used to indicate that
1013 // we have generated an inline version of the keyed load. In this
1014 // case, we know that we are not generating a test instruction next.
1016 // Push the nth argument.
1019 // Update the index on the stack and in register key.
1020 __ mov(key, Operand(ebp, kIndexOffset));
1021 __ add(key, Immediate(1 << kSmiTagSize));
1022 __ mov(Operand(ebp, kIndexOffset), key);
1025 __ cmp(key, Operand(ebp, kLimitOffset));
1026 __ j(not_equal, &loop);
1028 // Call the function.
1030 ParameterCount actual(eax);
1033 __ mov(edi, Operand(ebp, kFunctionOffset));
1034 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
1035 __ j(not_equal, &call_proxy);
1036 __ InvokeFunction(edi, actual, CALL_FUNCTION, NullCallWrapper());
1038 frame_scope.GenerateLeaveFrame();
1039 __ ret(3 * kPointerSize); // remove this, receiver, and arguments
1041 // Call the function proxy.
1042 __ bind(&call_proxy);
1043 __ push(edi); // add function proxy as last argument
1045 __ Move(ebx, Immediate(0));
1046 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY);
1047 __ call(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
1048 RelocInfo::CODE_TARGET);
1050 // Leave internal frame.
1052 __ ret(3 * kPointerSize); // remove this, receiver, and arguments
1056 void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
1057 // ----------- S t a t e -------------
1059 // -- esp[0] : return address
1060 // -- esp[4] : last argument
1061 // -----------------------------------
1062 Label generic_array_code;
1064 // Get the InternalArray function.
1065 __ LoadGlobalFunction(Context::INTERNAL_ARRAY_FUNCTION_INDEX, edi);
1067 if (FLAG_debug_code) {
1068 // Initial map for the builtin InternalArray function should be a map.
1069 __ mov(ebx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
1070 // Will both indicate a NULL and a Smi.
1071 __ test(ebx, Immediate(kSmiTagMask));
1072 __ Assert(not_zero, kUnexpectedInitialMapForInternalArrayFunction);
1073 __ CmpObjectType(ebx, MAP_TYPE, ecx);
1074 __ Assert(equal, kUnexpectedInitialMapForInternalArrayFunction);
1077 // Run the native code for the InternalArray function called as a normal
1080 InternalArrayConstructorStub stub(masm->isolate());
1081 __ TailCallStub(&stub);
1085 void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
1086 // ----------- S t a t e -------------
1088 // -- esp[0] : return address
1089 // -- esp[4] : last argument
1090 // -----------------------------------
1091 Label generic_array_code;
1093 // Get the Array function.
1094 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, edi);
1096 if (FLAG_debug_code) {
1097 // Initial map for the builtin Array function should be a map.
1098 __ mov(ebx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
1099 // Will both indicate a NULL and a Smi.
1100 __ test(ebx, Immediate(kSmiTagMask));
1101 __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction);
1102 __ CmpObjectType(ebx, MAP_TYPE, ecx);
1103 __ Assert(equal, kUnexpectedInitialMapForArrayFunction);
1106 // Run the native code for the Array function called as a normal function.
1108 __ mov(ebx, masm->isolate()->factory()->undefined_value());
1109 ArrayConstructorStub stub(masm->isolate());
1110 __ TailCallStub(&stub);
1114 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
1115 // ----------- S t a t e -------------
1116 // -- eax : number of arguments
1117 // -- edi : constructor function
1118 // -- esp[0] : return address
1119 // -- esp[(argc - n) * 4] : arg[n] (zero-based)
1120 // -- esp[(argc + 1) * 4] : receiver
1121 // -----------------------------------
1122 Counters* counters = masm->isolate()->counters();
1123 __ IncrementCounter(counters->string_ctor_calls(), 1);
1125 if (FLAG_debug_code) {
1126 __ LoadGlobalFunction(Context::STRING_FUNCTION_INDEX, ecx);
1128 __ Assert(equal, kUnexpectedStringFunction);
1131 // Load the first argument into eax and get rid of the rest
1132 // (including the receiver).
1135 __ j(zero, &no_arguments);
1136 __ mov(ebx, Operand(esp, eax, times_pointer_size, 0));
1138 __ lea(esp, Operand(esp, eax, times_pointer_size, kPointerSize));
1142 // Lookup the argument in the number to string cache.
1143 Label not_cached, argument_is_string;
1144 __ LookupNumberStringCache(eax, // Input.
1149 __ IncrementCounter(counters->string_ctor_cached_number(), 1);
1150 __ bind(&argument_is_string);
1151 // ----------- S t a t e -------------
1152 // -- ebx : argument converted to string
1153 // -- edi : constructor function
1154 // -- esp[0] : return address
1155 // -----------------------------------
1157 // Allocate a JSValue and put the tagged pointer into eax.
1159 __ Allocate(JSValue::kSize,
1161 ecx, // New allocation top (we ignore it).
1167 __ LoadGlobalFunctionInitialMap(edi, ecx);
1168 if (FLAG_debug_code) {
1169 __ cmpb(FieldOperand(ecx, Map::kInstanceSizeOffset),
1170 JSValue::kSize >> kPointerSizeLog2);
1171 __ Assert(equal, kUnexpectedStringWrapperInstanceSize);
1172 __ cmpb(FieldOperand(ecx, Map::kUnusedPropertyFieldsOffset), 0);
1173 __ Assert(equal, kUnexpectedUnusedPropertiesOfStringWrapper);
1175 __ mov(FieldOperand(eax, HeapObject::kMapOffset), ecx);
1177 // Set properties and elements.
1178 Factory* factory = masm->isolate()->factory();
1179 __ Move(ecx, Immediate(factory->empty_fixed_array()));
1180 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx);
1181 __ mov(FieldOperand(eax, JSObject::kElementsOffset), ecx);
1184 __ mov(FieldOperand(eax, JSValue::kValueOffset), ebx);
1186 // Ensure the object is fully initialized.
1187 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize);
1189 // We're done. Return.
1192 // The argument was not found in the number to string cache. Check
1193 // if it's a string already before calling the conversion builtin.
1194 Label convert_argument;
1195 __ bind(¬_cached);
1196 STATIC_ASSERT(kSmiTag == 0);
1197 __ JumpIfSmi(eax, &convert_argument);
1198 Condition is_string = masm->IsObjectStringType(eax, ebx, ecx);
1199 __ j(NegateCondition(is_string), &convert_argument);
1201 __ IncrementCounter(counters->string_ctor_string_value(), 1);
1202 __ jmp(&argument_is_string);
1204 // Invoke the conversion builtin and put the result into ebx.
1205 __ bind(&convert_argument);
1206 __ IncrementCounter(counters->string_ctor_conversions(), 1);
1208 FrameScope scope(masm, StackFrame::INTERNAL);
1209 __ push(edi); // Preserve the function.
1211 __ InvokeBuiltin(Builtins::TO_STRING, CALL_FUNCTION);
1215 __ jmp(&argument_is_string);
1217 // Load the empty string into ebx, remove the receiver from the
1218 // stack, and jump back to the case where the argument is a string.
1219 __ bind(&no_arguments);
1220 __ Move(ebx, Immediate(factory->empty_string()));
1222 __ lea(esp, Operand(esp, kPointerSize));
1224 __ jmp(&argument_is_string);
1226 // At this point the argument is already a string. Call runtime to
1227 // create a string wrapper.
1228 __ bind(&gc_required);
1229 __ IncrementCounter(counters->string_ctor_gc_required(), 1);
1231 FrameScope scope(masm, StackFrame::INTERNAL);
1233 __ CallRuntime(Runtime::kNewStringWrapper, 1);
1239 static void ArgumentsAdaptorStackCheck(MacroAssembler* masm,
1240 Label* stack_overflow) {
1241 // ----------- S t a t e -------------
1242 // -- eax : actual number of arguments
1243 // -- ebx : expected number of arguments
1244 // -- edi : function (passed through to callee)
1245 // -----------------------------------
1246 // Check the stack for overflow. We are not trying to catch
1247 // interruptions (e.g. debug break and preemption) here, so the "real stack
1248 // limit" is checked.
1249 ExternalReference real_stack_limit =
1250 ExternalReference::address_of_real_stack_limit(masm->isolate());
1251 __ mov(edx, Operand::StaticVariable(real_stack_limit));
1252 // Make ecx the space we have left. The stack might already be overflowed
1253 // here which will cause ecx to become negative.
1256 // Make edx the space we need for the array when it is unrolled onto the
1259 __ shl(edx, kPointerSizeLog2);
1260 // Check if the arguments will overflow the stack.
1262 __ j(less_equal, stack_overflow); // Signed comparison.
1266 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
1270 // Store the arguments adaptor context sentinel.
1271 __ push(Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1273 // Push the function on the stack.
1276 // Preserve the number of arguments on the stack. Must preserve eax,
1277 // ebx and ecx because these registers are used when copying the
1278 // arguments and the receiver.
1279 STATIC_ASSERT(kSmiTagSize == 1);
1280 __ lea(edi, Operand(eax, eax, times_1, kSmiTag));
1285 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
1286 // Retrieve the number of arguments from the stack.
1287 __ mov(ebx, Operand(ebp, ArgumentsAdaptorFrameConstants::kLengthOffset));
1292 // Remove caller arguments from the stack.
1293 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
1295 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); // 1 ~ receiver
1300 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
1301 // ----------- S t a t e -------------
1302 // -- eax : actual number of arguments
1303 // -- ebx : expected number of arguments
1304 // -- edi : function (passed through to callee)
1305 // -----------------------------------
1307 Label invoke, dont_adapt_arguments;
1308 __ IncrementCounter(masm->isolate()->counters()->arguments_adaptors(), 1);
1310 Label stack_overflow;
1311 ArgumentsAdaptorStackCheck(masm, &stack_overflow);
1313 Label enough, too_few;
1314 __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset));
1316 __ j(less, &too_few);
1317 __ cmp(ebx, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
1318 __ j(equal, &dont_adapt_arguments);
1320 { // Enough parameters: Actual >= expected.
1322 EnterArgumentsAdaptorFrame(masm);
1324 // Copy receiver and all expected arguments.
1325 const int offset = StandardFrameConstants::kCallerSPOffset;
1326 __ lea(eax, Operand(ebp, eax, times_4, offset));
1327 __ mov(edi, -1); // account for receiver
1332 __ push(Operand(eax, 0));
1333 __ sub(eax, Immediate(kPointerSize));
1339 { // Too few parameters: Actual < expected.
1341 EnterArgumentsAdaptorFrame(masm);
1343 // Copy receiver and all actual arguments.
1344 const int offset = StandardFrameConstants::kCallerSPOffset;
1345 __ lea(edi, Operand(ebp, eax, times_4, offset));
1346 // ebx = expected - actual.
1348 // eax = -actual - 1
1350 __ sub(eax, Immediate(1));
1355 __ push(Operand(edi, 0));
1356 __ sub(edi, Immediate(kPointerSize));
1358 __ j(not_zero, ©);
1360 // Fill remaining expected arguments with undefined values.
1364 __ push(Immediate(masm->isolate()->factory()->undefined_value()));
1369 // Call the entry point.
1371 // Restore function pointer.
1372 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
1375 // Store offset of return address for deoptimizer.
1376 masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset());
1378 // Leave frame and return.
1379 LeaveArgumentsAdaptorFrame(masm);
1382 // -------------------------------------------
1383 // Dont adapt arguments.
1384 // -------------------------------------------
1385 __ bind(&dont_adapt_arguments);
1388 __ bind(&stack_overflow);
1390 FrameScope frame(masm, StackFrame::MANUAL);
1391 EnterArgumentsAdaptorFrame(masm);
1392 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION);
1398 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
1399 // Lookup the function in the JavaScript frame.
1400 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
1402 FrameScope scope(masm, StackFrame::INTERNAL);
1403 // Pass function as argument.
1405 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1);
1409 // If the code object is null, just return to the unoptimized code.
1410 __ cmp(eax, Immediate(0));
1411 __ j(not_equal, &skip, Label::kNear);
1416 // Load deoptimization data from the code object.
1417 __ mov(ebx, Operand(eax, Code::kDeoptimizationDataOffset - kHeapObjectTag));
1419 // Load the OSR entrypoint offset from the deoptimization data.
1420 __ mov(ebx, Operand(ebx, FixedArray::OffsetOfElementAt(
1421 DeoptimizationInputData::kOsrPcOffsetIndex) - kHeapObjectTag));
1424 // Compute the target address = code_obj + header_size + osr_offset
1425 __ lea(eax, Operand(eax, ebx, times_1, Code::kHeaderSize - kHeapObjectTag));
1427 // Overwrite the return address on the stack.
1428 __ mov(Operand(esp, 0), eax);
1430 // And "return" to the OSR entry point of the function.
1435 void Builtins::Generate_OsrAfterStackCheck(MacroAssembler* masm) {
1436 // We check the stack limit as indicator that recompilation might be done.
1438 ExternalReference stack_limit =
1439 ExternalReference::address_of_stack_limit(masm->isolate());
1440 __ cmp(esp, Operand::StaticVariable(stack_limit));
1441 __ j(above_equal, &ok, Label::kNear);
1443 FrameScope scope(masm, StackFrame::INTERNAL);
1444 __ CallRuntime(Runtime::kStackGuard, 0);
1446 __ jmp(masm->isolate()->builtins()->OnStackReplacement(),
1447 RelocInfo::CODE_TARGET);
1455 } // namespace v8::internal
1457 #endif // V8_TARGET_ARCH_X87