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

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

Issue 7039036: Fix calls of strict mode function with an implicit receiver. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments. Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/x64/code-stubs-x64.cc ('k') | src/x64/ic-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 info_ = info; 123 info_ = info;
124 SetFunctionPosition(function()); 124 SetFunctionPosition(function());
125 Comment cmnt(masm_, "[ function compiled by full code generator"); 125 Comment cmnt(masm_, "[ function compiled by full code generator");
126 126
127 #ifdef DEBUG 127 #ifdef DEBUG
128 if (strlen(FLAG_stop_at) > 0 && 128 if (strlen(FLAG_stop_at) > 0 &&
129 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { 129 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) {
130 __ int3(); 130 __ int3();
131 } 131 }
132 #endif 132 #endif
133
134 // Strict mode functions need to replace the receiver with undefined
135 // when called as functions (without an explicit receiver
136 // object). rcx is zero for method calls and non-zero for function
137 // calls.
138 if (info->is_strict_mode()) {
139 Label ok;
140 __ testq(rcx, rcx);
141 __ j(zero, &ok, Label::kNear);
142 // +1 for return address.
143 int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize;
144 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex);
145 __ movq(Operand(rsp, receiver_offset), kScratchRegister);
146 __ bind(&ok);
147 }
148
133 __ push(rbp); // Caller's frame pointer. 149 __ push(rbp); // Caller's frame pointer.
134 __ movq(rbp, rsp); 150 __ movq(rbp, rsp);
135 __ push(rsi); // Callee's context. 151 __ push(rsi); // Callee's context.
136 __ push(rdi); // Callee's JS Function. 152 __ push(rdi); // Callee's JS Function.
137 153
138 { Comment cmnt(masm_, "[ Allocate locals"); 154 { Comment cmnt(masm_, "[ Allocate locals");
139 int locals_count = scope()->num_stack_slots(); 155 int locals_count = scope()->num_stack_slots();
140 if (locals_count == 1) { 156 if (locals_count == 1) {
141 __ PushRoot(Heap::kUndefinedValueRootIndex); 157 __ PushRoot(Heap::kUndefinedValueRootIndex);
142 } else if (locals_count > 1) { 158 } else if (locals_count > 1) {
(...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 for (int i = 0; i < arg_count; i++) { 2013 for (int i = 0; i < arg_count; i++) {
1998 VisitForStackValue(args->at(i)); 2014 VisitForStackValue(args->at(i));
1999 } 2015 }
2000 __ Move(rcx, name); 2016 __ Move(rcx, name);
2001 } 2017 }
2002 // Record source position for debugger. 2018 // Record source position for debugger.
2003 SetSourcePosition(expr->position()); 2019 SetSourcePosition(expr->position());
2004 // Call the IC initialization code. 2020 // Call the IC initialization code.
2005 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 2021 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2006 Handle<Code> ic = 2022 Handle<Code> ic =
2007 ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop); 2023 ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode);
2008 EmitCallIC(ic, mode, expr->id()); 2024 EmitCallIC(ic, mode, expr->id());
2009 RecordJSReturnSite(expr); 2025 RecordJSReturnSite(expr);
2010 // Restore context register. 2026 // Restore context register.
2011 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); 2027 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
2012 context()->Plug(rax); 2028 context()->Plug(rax);
2013 } 2029 }
2014 2030
2015 2031
2016 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, 2032 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr,
2017 Expression* key, 2033 Expression* key) {
2018 RelocInfo::Mode mode) {
2019 // Load the key. 2034 // Load the key.
2020 VisitForAccumulatorValue(key); 2035 VisitForAccumulatorValue(key);
2021 2036
2022 // Swap the name of the function and the receiver on the stack to follow 2037 // Swap the name of the function and the receiver on the stack to follow
2023 // the calling convention for call ICs. 2038 // the calling convention for call ICs.
2024 __ pop(rcx); 2039 __ pop(rcx);
2025 __ push(rax); 2040 __ push(rax);
2026 __ push(rcx); 2041 __ push(rcx);
2027 2042
2028 // Load the arguments. 2043 // Load the arguments.
2029 ZoneList<Expression*>* args = expr->arguments(); 2044 ZoneList<Expression*>* args = expr->arguments();
2030 int arg_count = args->length(); 2045 int arg_count = args->length();
2031 { PreservePositionScope scope(masm()->positions_recorder()); 2046 { PreservePositionScope scope(masm()->positions_recorder());
2032 for (int i = 0; i < arg_count; i++) { 2047 for (int i = 0; i < arg_count; i++) {
2033 VisitForStackValue(args->at(i)); 2048 VisitForStackValue(args->at(i));
2034 } 2049 }
2035 } 2050 }
2036 // Record source position for debugger. 2051 // Record source position for debugger.
2037 SetSourcePosition(expr->position()); 2052 SetSourcePosition(expr->position());
2038 // Call the IC initialization code. 2053 // Call the IC initialization code.
2039 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 2054 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2040 Handle<Code> ic = 2055 Handle<Code> ic =
2041 ISOLATE->stub_cache()->ComputeKeyedCallInitialize(arg_count, in_loop); 2056 ISOLATE->stub_cache()->ComputeKeyedCallInitialize(arg_count, in_loop);
2042 __ movq(rcx, Operand(rsp, (arg_count + 1) * kPointerSize)); // Key. 2057 __ movq(rcx, Operand(rsp, (arg_count + 1) * kPointerSize)); // Key.
2043 EmitCallIC(ic, mode, expr->id()); 2058 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
2044 RecordJSReturnSite(expr); 2059 RecordJSReturnSite(expr);
2045 // Restore context register. 2060 // Restore context register.
2046 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); 2061 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
2047 context()->DropAndPlug(1, rax); // Drop the key still on the stack. 2062 context()->DropAndPlug(1, rax); // Drop the key still on the stack.
2048 } 2063 }
2049 2064
2050 2065
2051 void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) { 2066 void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) {
2052 // Code common for calls using the call stub. 2067 // Code common for calls using the call stub.
2053 ZoneList<Expression*>* args = expr->arguments(); 2068 ZoneList<Expression*>* args = expr->arguments();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 } 2159 }
2145 2160
2146 // The runtime call returns a pair of values in rax (function) and 2161 // The runtime call returns a pair of values in rax (function) and
2147 // rdx (receiver). Touch up the stack with the right values. 2162 // rdx (receiver). Touch up the stack with the right values.
2148 __ movq(Operand(rsp, (arg_count + 0) * kPointerSize), rdx); 2163 __ movq(Operand(rsp, (arg_count + 0) * kPointerSize), rdx);
2149 __ movq(Operand(rsp, (arg_count + 1) * kPointerSize), rax); 2164 __ movq(Operand(rsp, (arg_count + 1) * kPointerSize), rax);
2150 } 2165 }
2151 // Record source position for debugger. 2166 // Record source position for debugger.
2152 SetSourcePosition(expr->position()); 2167 SetSourcePosition(expr->position());
2153 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 2168 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2154 CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); 2169 CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_IMPLICIT);
2155 __ CallStub(&stub); 2170 __ CallStub(&stub);
2156 RecordJSReturnSite(expr); 2171 RecordJSReturnSite(expr);
2157 // Restore context register. 2172 // Restore context register.
2158 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); 2173 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
2159 context()->DropAndPlug(1, rax); 2174 context()->DropAndPlug(1, rax);
2160 } else if (var != NULL && !var->is_this() && var->is_global()) { 2175 } else if (var != NULL && !var->is_this() && var->is_global()) {
2161 // Call to a global variable. 2176 // Call to a global variable.
2162 // Push global object as receiver for the call IC lookup. 2177 // Push global object as receiver for the call IC lookup.
2163 __ push(GlobalObjectOperand()); 2178 __ push(GlobalObjectOperand());
2164 EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); 2179 EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT);
(...skipping 28 matching lines...) Expand all
2193 __ jmp(&call, Label::kNear); 2208 __ jmp(&call, Label::kNear);
2194 __ bind(&done); 2209 __ bind(&done);
2195 // Push function. 2210 // Push function.
2196 __ push(rax); 2211 __ push(rax);
2197 // Push global receiver. 2212 // Push global receiver.
2198 __ movq(rbx, GlobalObjectOperand()); 2213 __ movq(rbx, GlobalObjectOperand());
2199 __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); 2214 __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset));
2200 __ bind(&call); 2215 __ bind(&call);
2201 } 2216 }
2202 2217
2203 // The receiver is either the global receiver or a JSObject found by 2218 // The receiver is either the global receiver or an object found
2204 // LoadContextSlot. 2219 // by LoadContextSlot. That object could be the hole if the
2205 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); 2220 // receiver is implicitly the global object.
2221 EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT);
2206 } else if (fun->AsProperty() != NULL) { 2222 } else if (fun->AsProperty() != NULL) {
2207 // Call to an object property. 2223 // Call to an object property.
2208 Property* prop = fun->AsProperty(); 2224 Property* prop = fun->AsProperty();
2209 Literal* key = prop->key()->AsLiteral(); 2225 Literal* key = prop->key()->AsLiteral();
2210 if (key != NULL && key->handle()->IsSymbol()) { 2226 if (key != NULL && key->handle()->IsSymbol()) {
2211 // Call to a named property, use call IC. 2227 // Call to a named property, use call IC.
2212 { PreservePositionScope scope(masm()->positions_recorder()); 2228 { PreservePositionScope scope(masm()->positions_recorder());
2213 VisitForStackValue(prop->obj()); 2229 VisitForStackValue(prop->obj());
2214 } 2230 }
2215 EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); 2231 EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET);
(...skipping 22 matching lines...) Expand all
2238 // Push result (function). 2254 // Push result (function).
2239 __ push(rax); 2255 __ push(rax);
2240 // Push Global receiver. 2256 // Push Global receiver.
2241 __ movq(rcx, GlobalObjectOperand()); 2257 __ movq(rcx, GlobalObjectOperand());
2242 __ push(FieldOperand(rcx, GlobalObject::kGlobalReceiverOffset)); 2258 __ push(FieldOperand(rcx, GlobalObject::kGlobalReceiverOffset));
2243 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); 2259 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS);
2244 } else { 2260 } else {
2245 { PreservePositionScope scope(masm()->positions_recorder()); 2261 { PreservePositionScope scope(masm()->positions_recorder());
2246 VisitForStackValue(prop->obj()); 2262 VisitForStackValue(prop->obj());
2247 } 2263 }
2248 EmitKeyedCallWithIC(expr, prop->key(), RelocInfo::CODE_TARGET); 2264 EmitKeyedCallWithIC(expr, prop->key());
2249 } 2265 }
2250 } 2266 }
2251 } else { 2267 } else {
2252 { PreservePositionScope scope(masm()->positions_recorder()); 2268 { PreservePositionScope scope(masm()->positions_recorder());
2253 VisitForStackValue(fun); 2269 VisitForStackValue(fun);
2254 } 2270 }
2255 // Load global receiver object. 2271 // Load global receiver object.
2256 __ movq(rbx, GlobalObjectOperand()); 2272 __ movq(rbx, GlobalObjectOperand());
2257 __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); 2273 __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset));
2258 // Emit function call. 2274 // Emit function call.
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
3585 // Push the arguments ("left-to-right"). 3601 // Push the arguments ("left-to-right").
3586 int arg_count = args->length(); 3602 int arg_count = args->length();
3587 for (int i = 0; i < arg_count; i++) { 3603 for (int i = 0; i < arg_count; i++) {
3588 VisitForStackValue(args->at(i)); 3604 VisitForStackValue(args->at(i));
3589 } 3605 }
3590 3606
3591 if (expr->is_jsruntime()) { 3607 if (expr->is_jsruntime()) {
3592 // Call the JS runtime function using a call IC. 3608 // Call the JS runtime function using a call IC.
3593 __ Move(rcx, expr->name()); 3609 __ Move(rcx, expr->name());
3594 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 3610 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
3611 RelocInfo::Mode mode = RelocInfo::CODE_TARGET;
3595 Handle<Code> ic = 3612 Handle<Code> ic =
3596 ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop); 3613 ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode);
3597 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); 3614 EmitCallIC(ic, mode, expr->id());
3598 // Restore context register. 3615 // Restore context register.
3599 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); 3616 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
3600 } else { 3617 } else {
3601 __ CallRuntime(expr->function(), arg_count); 3618 __ CallRuntime(expr->function(), arg_count);
3602 } 3619 }
3603 context()->Plug(rax); 3620 context()->Plug(rax);
3604 } 3621 }
3605 3622
3606 3623
3607 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { 3624 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
4295 __ ret(0); 4312 __ ret(0);
4296 } 4313 }
4297 4314
4298 4315
4299 #undef __ 4316 #undef __
4300 4317
4301 4318
4302 } } // namespace v8::internal 4319 } } // namespace v8::internal
4303 4320
4304 #endif // V8_TARGET_ARCH_X64 4321 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/code-stubs-x64.cc ('k') | src/x64/ic-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698