OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 bool LCodeGen::GeneratePrologue() { | 133 bool LCodeGen::GeneratePrologue() { |
134 ASSERT(is_generating()); | 134 ASSERT(is_generating()); |
135 | 135 |
136 #ifdef DEBUG | 136 #ifdef DEBUG |
137 if (strlen(FLAG_stop_at) > 0 && | 137 if (strlen(FLAG_stop_at) > 0 && |
138 info_->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { | 138 info_->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
139 __ int3(); | 139 __ int3(); |
140 } | 140 } |
141 #endif | 141 #endif |
142 | 142 |
| 143 // Strict mode functions need to replace the receiver with undefined |
| 144 // when called as functions (without an explicit receiver |
| 145 // object). rcx is zero for method calls and non-zero for function |
| 146 // calls. |
| 147 if (info_->is_strict_mode()) { |
| 148 Label ok; |
| 149 __ testq(rcx, rcx); |
| 150 __ j(zero, &ok, Label::kNear); |
| 151 // +1 for return address. |
| 152 int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize; |
| 153 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); |
| 154 __ movq(Operand(rsp, receiver_offset), kScratchRegister); |
| 155 __ bind(&ok); |
| 156 } |
| 157 |
143 __ push(rbp); // Caller's frame pointer. | 158 __ push(rbp); // Caller's frame pointer. |
144 __ movq(rbp, rsp); | 159 __ movq(rbp, rsp); |
145 __ push(rsi); // Callee's context. | 160 __ push(rsi); // Callee's context. |
146 __ push(rdi); // Callee's JS function. | 161 __ push(rdi); // Callee's JS function. |
147 | 162 |
148 // Reserve space for the stack slots needed by the code. | 163 // Reserve space for the stack slots needed by the code. |
149 int slots = GetStackSlotCount(); | 164 int slots = GetStackSlotCount(); |
150 if (slots > 0) { | 165 if (slots > 0) { |
151 if (FLAG_debug_code) { | 166 if (FLAG_debug_code) { |
152 __ Set(rax, slots); | 167 __ Set(rax, slots); |
(...skipping 2528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2681 | 2696 |
2682 void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { | 2697 void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
2683 Register global = ToRegister(instr->global()); | 2698 Register global = ToRegister(instr->global()); |
2684 Register result = ToRegister(instr->result()); | 2699 Register result = ToRegister(instr->result()); |
2685 __ movq(result, FieldOperand(global, GlobalObject::kGlobalReceiverOffset)); | 2700 __ movq(result, FieldOperand(global, GlobalObject::kGlobalReceiverOffset)); |
2686 } | 2701 } |
2687 | 2702 |
2688 | 2703 |
2689 void LCodeGen::CallKnownFunction(Handle<JSFunction> function, | 2704 void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
2690 int arity, | 2705 int arity, |
2691 LInstruction* instr) { | 2706 LInstruction* instr, |
| 2707 CallKind call_kind) { |
2692 // Change context if needed. | 2708 // Change context if needed. |
2693 bool change_context = | 2709 bool change_context = |
2694 (info()->closure()->context() != function->context()) || | 2710 (info()->closure()->context() != function->context()) || |
2695 scope()->contains_with() || | 2711 scope()->contains_with() || |
2696 (scope()->num_heap_slots() > 0); | 2712 (scope()->num_heap_slots() > 0); |
2697 if (change_context) { | 2713 if (change_context) { |
2698 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 2714 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
2699 } | 2715 } |
2700 | 2716 |
2701 // Set rax to arguments count if adaption is not needed. Assumes that rax | 2717 // Set rax to arguments count if adaption is not needed. Assumes that rax |
2702 // is available to write to at this point. | 2718 // is available to write to at this point. |
2703 if (!function->NeedsArgumentsAdaption()) { | 2719 if (!function->NeedsArgumentsAdaption()) { |
2704 __ Set(rax, arity); | 2720 __ Set(rax, arity); |
2705 } | 2721 } |
2706 | 2722 |
2707 LPointerMap* pointers = instr->pointer_map(); | 2723 LPointerMap* pointers = instr->pointer_map(); |
2708 RecordPosition(pointers->position()); | 2724 RecordPosition(pointers->position()); |
2709 | 2725 |
2710 // Invoke function. | 2726 // Invoke function. |
| 2727 __ SetCallKind(rcx, call_kind); |
2711 if (*function == *info()->closure()) { | 2728 if (*function == *info()->closure()) { |
2712 __ CallSelf(); | 2729 __ CallSelf(); |
2713 } else { | 2730 } else { |
2714 __ call(FieldOperand(rdi, JSFunction::kCodeEntryOffset)); | 2731 __ call(FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
2715 } | 2732 } |
2716 | 2733 |
2717 // Setup deoptimization. | 2734 // Setup deoptimization. |
2718 RegisterLazyDeoptimization(instr, RECORD_SIMPLE_SAFEPOINT, 0); | 2735 RegisterLazyDeoptimization(instr, RECORD_SIMPLE_SAFEPOINT, 0); |
2719 | 2736 |
2720 // Restore context. | 2737 // Restore context. |
2721 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 2738 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
2722 } | 2739 } |
2723 | 2740 |
2724 | 2741 |
2725 void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { | 2742 void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
2726 ASSERT(ToRegister(instr->result()).is(rax)); | 2743 ASSERT(ToRegister(instr->result()).is(rax)); |
2727 __ Move(rdi, instr->function()); | 2744 __ Move(rdi, instr->function()); |
2728 CallKnownFunction(instr->function(), instr->arity(), instr); | 2745 CallKnownFunction(instr->function(), |
| 2746 instr->arity(), |
| 2747 instr, |
| 2748 CALL_AS_METHOD); |
2729 } | 2749 } |
2730 | 2750 |
2731 | 2751 |
2732 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { | 2752 void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { |
2733 Register input_reg = ToRegister(instr->InputAt(0)); | 2753 Register input_reg = ToRegister(instr->InputAt(0)); |
2734 __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), | 2754 __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), |
2735 Heap::kHeapNumberMapRootIndex); | 2755 Heap::kHeapNumberMapRootIndex); |
2736 DeoptimizeIf(not_equal, instr->environment()); | 2756 DeoptimizeIf(not_equal, instr->environment()); |
2737 | 2757 |
2738 Label done; | 2758 Label done; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3069 arity, NOT_IN_LOOP); | 3089 arity, NOT_IN_LOOP); |
3070 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 3090 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
3071 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 3091 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
3072 } | 3092 } |
3073 | 3093 |
3074 | 3094 |
3075 void LCodeGen::DoCallNamed(LCallNamed* instr) { | 3095 void LCodeGen::DoCallNamed(LCallNamed* instr) { |
3076 ASSERT(ToRegister(instr->result()).is(rax)); | 3096 ASSERT(ToRegister(instr->result()).is(rax)); |
3077 | 3097 |
3078 int arity = instr->arity(); | 3098 int arity = instr->arity(); |
3079 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize( | 3099 RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
3080 arity, NOT_IN_LOOP); | 3100 Handle<Code> ic = |
| 3101 isolate()->stub_cache()->ComputeCallInitialize(arity, NOT_IN_LOOP, mode); |
3081 __ Move(rcx, instr->name()); | 3102 __ Move(rcx, instr->name()); |
3082 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 3103 CallCode(ic, mode, instr); |
3083 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 3104 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
3084 } | 3105 } |
3085 | 3106 |
3086 | 3107 |
3087 void LCodeGen::DoCallFunction(LCallFunction* instr) { | 3108 void LCodeGen::DoCallFunction(LCallFunction* instr) { |
3088 ASSERT(ToRegister(instr->result()).is(rax)); | 3109 ASSERT(ToRegister(instr->result()).is(rax)); |
3089 | 3110 |
3090 int arity = instr->arity(); | 3111 int arity = instr->arity(); |
3091 CallFunctionStub stub(arity, NOT_IN_LOOP, RECEIVER_MIGHT_BE_VALUE); | 3112 CallFunctionStub stub(arity, NOT_IN_LOOP, RECEIVER_MIGHT_BE_IMPLICIT); |
3092 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 3113 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
3093 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 3114 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
3094 __ Drop(1); | 3115 __ Drop(1); |
3095 } | 3116 } |
3096 | 3117 |
3097 | 3118 |
3098 void LCodeGen::DoCallGlobal(LCallGlobal* instr) { | 3119 void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
3099 ASSERT(ToRegister(instr->result()).is(rax)); | 3120 ASSERT(ToRegister(instr->result()).is(rax)); |
3100 int arity = instr->arity(); | 3121 int arity = instr->arity(); |
3101 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize( | 3122 RelocInfo::Mode mode = RelocInfo::CODE_TARGET_CONTEXT; |
3102 arity, NOT_IN_LOOP); | 3123 Handle<Code> ic = |
| 3124 isolate()->stub_cache()->ComputeCallInitialize(arity, NOT_IN_LOOP, mode); |
3103 __ Move(rcx, instr->name()); | 3125 __ Move(rcx, instr->name()); |
3104 CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); | 3126 CallCode(ic, mode, instr); |
3105 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 3127 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
3106 } | 3128 } |
3107 | 3129 |
3108 | 3130 |
3109 void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { | 3131 void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
3110 ASSERT(ToRegister(instr->result()).is(rax)); | 3132 ASSERT(ToRegister(instr->result()).is(rax)); |
3111 __ Move(rdi, instr->target()); | 3133 __ Move(rdi, instr->target()); |
3112 CallKnownFunction(instr->target(), instr->arity(), instr); | 3134 CallKnownFunction(instr->target(), instr->arity(), instr, CALL_AS_FUNCTION); |
3113 } | 3135 } |
3114 | 3136 |
3115 | 3137 |
3116 void LCodeGen::DoCallNew(LCallNew* instr) { | 3138 void LCodeGen::DoCallNew(LCallNew* instr) { |
3117 ASSERT(ToRegister(instr->InputAt(0)).is(rdi)); | 3139 ASSERT(ToRegister(instr->InputAt(0)).is(rdi)); |
3118 ASSERT(ToRegister(instr->result()).is(rax)); | 3140 ASSERT(ToRegister(instr->result()).is(rax)); |
3119 | 3141 |
3120 Handle<Code> builtin = isolate()->builtins()->JSConstructCall(); | 3142 Handle<Code> builtin = isolate()->builtins()->JSConstructCall(); |
3121 __ Set(rax, instr->arity()); | 3143 __ Set(rax, instr->arity()); |
3122 CallCode(builtin, RelocInfo::CONSTRUCT_CALL, instr); | 3144 CallCode(builtin, RelocInfo::CONSTRUCT_CALL, instr); |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4236 RegisterEnvironmentForDeoptimization(environment); | 4258 RegisterEnvironmentForDeoptimization(environment); |
4237 ASSERT(osr_pc_offset_ == -1); | 4259 ASSERT(osr_pc_offset_ == -1); |
4238 osr_pc_offset_ = masm()->pc_offset(); | 4260 osr_pc_offset_ = masm()->pc_offset(); |
4239 } | 4261 } |
4240 | 4262 |
4241 #undef __ | 4263 #undef __ |
4242 | 4264 |
4243 } } // namespace v8::internal | 4265 } } // namespace v8::internal |
4244 | 4266 |
4245 #endif // V8_TARGET_ARCH_X64 | 4267 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |