Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 791603003: WIP context-allocation for “this” in arrow functions Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: WIP v3 Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #if V8_TARGET_ARCH_X64 7 #if V8_TARGET_ARCH_X64
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 #ifdef DEBUG 107 #ifdef DEBUG
108 if (strlen(FLAG_stop_at) > 0 && 108 if (strlen(FLAG_stop_at) > 0 &&
109 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { 109 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
110 __ int3(); 110 __ int3();
111 } 111 }
112 #endif 112 #endif
113 113
114 // Sloppy mode functions and builtins need to replace the receiver with the 114 // Sloppy mode functions and builtins need to replace the receiver with the
115 // global proxy when called as functions (without an explicit receiver 115 // global proxy when called as functions (without an explicit receiver
116 // object). 116 // object). Arrow functions need to replace the receiver with the receiver
117 if (info->strict_mode() == SLOPPY && !info->is_native()) { 117 // of the parent scope, so this does not need to be done for those.
wingo 2015/01/15 10:09:06 It's not necessarily the receiver from the parent
aperez 2015/01/15 16:58:03 Done.
118 if (info->strict_mode() == SLOPPY && !info->is_native() &&
119 !info->function()->is_arrow()) {
118 Label ok; 120 Label ok;
119 // +1 for return address. 121 // +1 for return address.
120 StackArgumentsAccessor args(rsp, info->scope()->num_parameters()); 122 StackArgumentsAccessor args(rsp, info->scope()->num_parameters());
121 __ movp(rcx, args.GetReceiverOperand()); 123 __ movp(rcx, args.GetReceiverOperand());
122 124
123 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); 125 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex);
124 __ j(not_equal, &ok, Label::kNear); 126 __ j(not_equal, &ok, Label::kNear);
125 127
126 __ movp(rcx, GlobalObjectOperand()); 128 __ movp(rcx, GlobalObjectOperand());
127 __ movp(rcx, FieldOperand(rcx, GlobalObject::kGlobalProxyOffset)); 129 __ movp(rcx, FieldOperand(rcx, GlobalObject::kGlobalProxyOffset));
128 130
129 __ movp(args.GetReceiverOperand(), rcx); 131 __ movp(args.GetReceiverOperand(), rcx);
130 132
131 __ bind(&ok); 133 __ bind(&ok);
132 } 134 }
133 135
134 // Open a frame scope to indicate that there is a frame on the stack. The 136 // Open a frame scope to indicate that there is a frame on the stack. The
135 // MANUAL indicates that the scope shouldn't actually generate code to set up 137 // MANUAL indicates that the scope shouldn't actually generate code to set up
136 // the frame (that is done below). 138 // the frame (that is done below).
137 FrameScope frame_scope(masm_, StackFrame::MANUAL); 139 FrameScope frame_scope(masm_, StackFrame::MANUAL);
138 140
139 info->set_prologue_offset(masm_->pc_offset()); 141 info->set_prologue_offset(masm_->pc_offset());
140 __ Prologue(info->IsCodePreAgingActive()); 142 __ Prologue(info->IsCodePreAgingActive());
141 info->AddNoFrameRange(0, masm_->pc_offset()); 143 info->AddNoFrameRange(0, masm_->pc_offset());
142 144
145 // For arrow functions the value of the receiver is stored in the context,
146 // so in the case of a function that actually uses "this", the receiver is
147 // replaced by the one resulting from looking it up in the context.
148 if (info->function()->is_arrow() && info->scope()->uses_this()) {
149 DCHECK(info->scope()->scope_type() == ARROW_SCOPE);
150 Comment cmnt(masm_, "[ Patch receiver for arrow function");
151 StackArgumentsAccessor args(rbp, info->scope()->num_parameters());
152 __ Push(rsi); // Context
153 __ Push(isolate()->factory()->this_string());
154 __ CallRuntime(Runtime::kLoadLookupSlot, 2);
155 __ movp(args.GetReceiverOperand(), rax);
156 }
157
143 { Comment cmnt(masm_, "[ Allocate locals"); 158 { Comment cmnt(masm_, "[ Allocate locals");
144 int locals_count = info->scope()->num_stack_slots(); 159 int locals_count = info->scope()->num_stack_slots();
145 // Generators allocate locals, if any, in context slots. 160 // Generators allocate locals, if any, in context slots.
146 DCHECK(!info->function()->is_generator() || locals_count == 0); 161 DCHECK(!info->function()->is_generator() || locals_count == 0);
147 if (locals_count == 1) { 162 if (locals_count == 1) {
148 __ PushRoot(Heap::kUndefinedValueRootIndex); 163 __ PushRoot(Heap::kUndefinedValueRootIndex);
149 } else if (locals_count > 1) { 164 } else if (locals_count > 1) {
150 if (locals_count >= 128) { 165 if (locals_count >= 128) {
151 Label ok; 166 Label ok;
152 __ movp(rcx, rsp); 167 __ movp(rcx, rsp);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 __ Push(rdi); 215 __ Push(rdi);
201 __ CallRuntime(Runtime::kNewFunctionContext, 1); 216 __ CallRuntime(Runtime::kNewFunctionContext, 1);
202 } 217 }
203 function_in_register = false; 218 function_in_register = false;
204 // Context is returned in rax. It replaces the context passed to us. 219 // Context is returned in rax. It replaces the context passed to us.
205 // It's saved in the stack and kept live in rsi. 220 // It's saved in the stack and kept live in rsi.
206 __ movp(rsi, rax); 221 __ movp(rsi, rax);
207 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax); 222 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax);
208 223
209 // Copy any necessary parameters into the context. 224 // Copy any necessary parameters into the context.
225 if (info->scope()->inner_uses_this()) {
wingo 2015/01/15 10:09:06 Let's factor this into the loop below
aperez 2015/01/15 16:58:03 Done.
226 Comment cmnt(masm_, "[ Save receiver in context for arrow function");
227 DCHECK(info->scope()->receiver()->IsContextSlot());
228 // Put the "this" in the context after the rest of the function
229 // parameters, to avoid having to change the case that handles those.
230 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
231 info->scope()->num_parameters() * kPointerSize;
232 __ movp(rax, Operand(rbp, parameter_offset));
233
234 // Store it in the context.
235 int context_offset = Context::SlotOffset(scope()->receiver()->index());
236 __ movp(Operand(rsi, context_offset), rax);
237
238 if (need_write_barrier) {
239 __ RecordWriteContextSlot(
240 rsi, context_offset, rax, rbx, kDontSaveFPRegs);
241 } else if (FLAG_debug_code) {
242 Label done;
243 __ JumpIfInNewSpace(rsi, rax, &done, Label::kNear);
244 __ Abort(kExpectedNewSpaceObject);
245 __ bind(&done);
246 }
247 }
248
210 int num_parameters = info->scope()->num_parameters(); 249 int num_parameters = info->scope()->num_parameters();
211 for (int i = 0; i < num_parameters; i++) { 250 for (int i = 0; i < num_parameters; i++) {
212 Variable* var = scope()->parameter(i); 251 Variable* var = scope()->parameter(i);
213 if (var->IsContextSlot()) { 252 if (var->IsContextSlot()) {
214 int parameter_offset = StandardFrameConstants::kCallerSPOffset + 253 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
215 (num_parameters - 1 - i) * kPointerSize; 254 (num_parameters - 1 - i) * kPointerSize;
216 // Load parameter from stack. 255 // Load parameter from stack.
217 __ movp(rax, Operand(rbp, parameter_offset)); 256 __ movp(rax, Operand(rbp, parameter_offset));
218 // Store it in the context. 257 // Store it in the context.
219 int context_offset = Context::SlotOffset(var->index()); 258 int context_offset = Context::SlotOffset(var->index());
(...skipping 2494 matching lines...) Expand 10 before | Expand all | Expand 10 after
2714 2753
2715 CallICState::CallType call_type = 2754 CallICState::CallType call_type =
2716 callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD; 2755 callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD;
2717 // Get the target function. 2756 // Get the target function.
2718 if (call_type == CallICState::FUNCTION) { 2757 if (call_type == CallICState::FUNCTION) {
2719 { StackValueContext context(this); 2758 { StackValueContext context(this);
2720 EmitVariableLoad(callee->AsVariableProxy()); 2759 EmitVariableLoad(callee->AsVariableProxy());
2721 PrepareForBailout(callee, NO_REGISTERS); 2760 PrepareForBailout(callee, NO_REGISTERS);
2722 } 2761 }
2723 // Push undefined as receiver. This is patched in the method prologue if it 2762 // Push undefined as receiver. This is patched in the method prologue if it
2724 // is a sloppy mode method. 2763 // is a sloppy mode method, or by the function prologue it is an arrow
wingo 2015/01/15 10:09:06 "if it is"
aperez 2015/01/15 16:58:03 Done.
2764 // function.
2725 __ Push(isolate()->factory()->undefined_value()); 2765 __ Push(isolate()->factory()->undefined_value());
2726 } else { 2766 } else {
2727 // Load the function from the receiver. 2767 // Load the function from the receiver.
2728 DCHECK(callee->IsProperty()); 2768 DCHECK(callee->IsProperty());
2729 DCHECK(!callee->AsProperty()->IsSuperAccess()); 2769 DCHECK(!callee->AsProperty()->IsSuperAccess());
2730 __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, 0)); 2770 __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, 0));
2731 EmitNamedPropertyLoad(callee->AsProperty()); 2771 EmitNamedPropertyLoad(callee->AsProperty());
2732 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); 2772 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
2733 // Push the target function under the receiver. 2773 // Push the target function under the receiver.
2734 __ Push(Operand(rsp, 0)); 2774 __ Push(Operand(rsp, 0));
(...skipping 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after
5193 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 5233 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
5194 Assembler::target_address_at(call_target_address, 5234 Assembler::target_address_at(call_target_address,
5195 unoptimized_code)); 5235 unoptimized_code));
5196 return OSR_AFTER_STACK_CHECK; 5236 return OSR_AFTER_STACK_CHECK;
5197 } 5237 }
5198 5238
5199 5239
5200 } } // namespace v8::internal 5240 } } // namespace v8::internal
5201 5241
5202 #endif // V8_TARGET_ARCH_X64 5242 #endif // V8_TARGET_ARCH_X64
OLDNEW
« src/scopes.cc ('K') | « src/scopes.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698