| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 1851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 for (int i = 0; i < arg_count; i++) { | 2010 for (int i = 0; i < arg_count; i++) { |
| 1995 VisitForStackValue(args->at(i)); | 2011 VisitForStackValue(args->at(i)); |
| 1996 } | 2012 } |
| 1997 __ Move(rcx, name); | 2013 __ Move(rcx, name); |
| 1998 } | 2014 } |
| 1999 // Record source position for debugger. | 2015 // Record source position for debugger. |
| 2000 SetSourcePosition(expr->position()); | 2016 SetSourcePosition(expr->position()); |
| 2001 // Call the IC initialization code. | 2017 // Call the IC initialization code. |
| 2002 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; | 2018 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 2003 Handle<Code> ic = | 2019 Handle<Code> ic = |
| 2004 ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop); | 2020 ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode); |
| 2005 EmitCallIC(ic, mode, expr->id()); | 2021 EmitCallIC(ic, mode, expr->id()); |
| 2006 RecordJSReturnSite(expr); | 2022 RecordJSReturnSite(expr); |
| 2007 // Restore context register. | 2023 // Restore context register. |
| 2008 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 2024 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2009 context()->Plug(rax); | 2025 context()->Plug(rax); |
| 2010 } | 2026 } |
| 2011 | 2027 |
| 2012 | 2028 |
| 2013 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, | 2029 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
| 2014 Expression* key, | 2030 Expression* key) { |
| 2015 RelocInfo::Mode mode) { | |
| 2016 // Load the key. | 2031 // Load the key. |
| 2017 VisitForAccumulatorValue(key); | 2032 VisitForAccumulatorValue(key); |
| 2018 | 2033 |
| 2019 // Swap the name of the function and the receiver on the stack to follow | 2034 // Swap the name of the function and the receiver on the stack to follow |
| 2020 // the calling convention for call ICs. | 2035 // the calling convention for call ICs. |
| 2021 __ pop(rcx); | 2036 __ pop(rcx); |
| 2022 __ push(rax); | 2037 __ push(rax); |
| 2023 __ push(rcx); | 2038 __ push(rcx); |
| 2024 | 2039 |
| 2025 // Load the arguments. | 2040 // Load the arguments. |
| 2026 ZoneList<Expression*>* args = expr->arguments(); | 2041 ZoneList<Expression*>* args = expr->arguments(); |
| 2027 int arg_count = args->length(); | 2042 int arg_count = args->length(); |
| 2028 { PreservePositionScope scope(masm()->positions_recorder()); | 2043 { PreservePositionScope scope(masm()->positions_recorder()); |
| 2029 for (int i = 0; i < arg_count; i++) { | 2044 for (int i = 0; i < arg_count; i++) { |
| 2030 VisitForStackValue(args->at(i)); | 2045 VisitForStackValue(args->at(i)); |
| 2031 } | 2046 } |
| 2032 } | 2047 } |
| 2033 // Record source position for debugger. | 2048 // Record source position for debugger. |
| 2034 SetSourcePosition(expr->position()); | 2049 SetSourcePosition(expr->position()); |
| 2035 // Call the IC initialization code. | 2050 // Call the IC initialization code. |
| 2036 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; | 2051 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 2037 Handle<Code> ic = | 2052 Handle<Code> ic = |
| 2038 ISOLATE->stub_cache()->ComputeKeyedCallInitialize(arg_count, in_loop); | 2053 ISOLATE->stub_cache()->ComputeKeyedCallInitialize(arg_count, in_loop); |
| 2039 __ movq(rcx, Operand(rsp, (arg_count + 1) * kPointerSize)); // Key. | 2054 __ movq(rcx, Operand(rsp, (arg_count + 1) * kPointerSize)); // Key. |
| 2040 EmitCallIC(ic, mode, expr->id()); | 2055 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
| 2041 RecordJSReturnSite(expr); | 2056 RecordJSReturnSite(expr); |
| 2042 // Restore context register. | 2057 // Restore context register. |
| 2043 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 2058 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2044 context()->DropAndPlug(1, rax); // Drop the key still on the stack. | 2059 context()->DropAndPlug(1, rax); // Drop the key still on the stack. |
| 2045 } | 2060 } |
| 2046 | 2061 |
| 2047 | 2062 |
| 2048 void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) { | 2063 void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) { |
| 2049 // Code common for calls using the call stub. | 2064 // Code common for calls using the call stub. |
| 2050 ZoneList<Expression*>* args = expr->arguments(); | 2065 ZoneList<Expression*>* args = expr->arguments(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 } | 2156 } |
| 2142 | 2157 |
| 2143 // The runtime call returns a pair of values in rax (function) and | 2158 // The runtime call returns a pair of values in rax (function) and |
| 2144 // rdx (receiver). Touch up the stack with the right values. | 2159 // rdx (receiver). Touch up the stack with the right values. |
| 2145 __ movq(Operand(rsp, (arg_count + 0) * kPointerSize), rdx); | 2160 __ movq(Operand(rsp, (arg_count + 0) * kPointerSize), rdx); |
| 2146 __ movq(Operand(rsp, (arg_count + 1) * kPointerSize), rax); | 2161 __ movq(Operand(rsp, (arg_count + 1) * kPointerSize), rax); |
| 2147 } | 2162 } |
| 2148 // Record source position for debugger. | 2163 // Record source position for debugger. |
| 2149 SetSourcePosition(expr->position()); | 2164 SetSourcePosition(expr->position()); |
| 2150 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; | 2165 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 2151 CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); | 2166 CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_IMPLICIT); |
| 2152 __ CallStub(&stub); | 2167 __ CallStub(&stub); |
| 2153 RecordJSReturnSite(expr); | 2168 RecordJSReturnSite(expr); |
| 2154 // Restore context register. | 2169 // Restore context register. |
| 2155 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 2170 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2156 context()->DropAndPlug(1, rax); | 2171 context()->DropAndPlug(1, rax); |
| 2157 } else if (var != NULL && !var->is_this() && var->is_global()) { | 2172 } else if (var != NULL && !var->is_this() && var->is_global()) { |
| 2158 // Call to a global variable. | 2173 // Call to a global variable. |
| 2159 // Push global object as receiver for the call IC lookup. | 2174 // Push global object as receiver for the call IC lookup. |
| 2160 __ push(GlobalObjectOperand()); | 2175 __ push(GlobalObjectOperand()); |
| 2161 EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); | 2176 EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2190 __ jmp(&call, Label::kNear); | 2205 __ jmp(&call, Label::kNear); |
| 2191 __ bind(&done); | 2206 __ bind(&done); |
| 2192 // Push function. | 2207 // Push function. |
| 2193 __ push(rax); | 2208 __ push(rax); |
| 2194 // Push global receiver. | 2209 // Push global receiver. |
| 2195 __ movq(rbx, GlobalObjectOperand()); | 2210 __ movq(rbx, GlobalObjectOperand()); |
| 2196 __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); | 2211 __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); |
| 2197 __ bind(&call); | 2212 __ bind(&call); |
| 2198 } | 2213 } |
| 2199 | 2214 |
| 2200 // The receiver is either the global receiver or a JSObject found by | 2215 // The receiver is either the global receiver or an object found |
| 2201 // LoadContextSlot. | 2216 // by LoadContextSlot. That object could be the hole if the |
| 2202 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); | 2217 // receiver is implicitly the global object. |
| 2218 EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT); |
| 2203 } else if (fun->AsProperty() != NULL) { | 2219 } else if (fun->AsProperty() != NULL) { |
| 2204 // Call to an object property. | 2220 // Call to an object property. |
| 2205 Property* prop = fun->AsProperty(); | 2221 Property* prop = fun->AsProperty(); |
| 2206 Literal* key = prop->key()->AsLiteral(); | 2222 Literal* key = prop->key()->AsLiteral(); |
| 2207 if (key != NULL && key->handle()->IsSymbol()) { | 2223 if (key != NULL && key->handle()->IsSymbol()) { |
| 2208 // Call to a named property, use call IC. | 2224 // Call to a named property, use call IC. |
| 2209 { PreservePositionScope scope(masm()->positions_recorder()); | 2225 { PreservePositionScope scope(masm()->positions_recorder()); |
| 2210 VisitForStackValue(prop->obj()); | 2226 VisitForStackValue(prop->obj()); |
| 2211 } | 2227 } |
| 2212 EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); | 2228 EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2235 // Push result (function). | 2251 // Push result (function). |
| 2236 __ push(rax); | 2252 __ push(rax); |
| 2237 // Push Global receiver. | 2253 // Push Global receiver. |
| 2238 __ movq(rcx, GlobalObjectOperand()); | 2254 __ movq(rcx, GlobalObjectOperand()); |
| 2239 __ push(FieldOperand(rcx, GlobalObject::kGlobalReceiverOffset)); | 2255 __ push(FieldOperand(rcx, GlobalObject::kGlobalReceiverOffset)); |
| 2240 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); | 2256 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); |
| 2241 } else { | 2257 } else { |
| 2242 { PreservePositionScope scope(masm()->positions_recorder()); | 2258 { PreservePositionScope scope(masm()->positions_recorder()); |
| 2243 VisitForStackValue(prop->obj()); | 2259 VisitForStackValue(prop->obj()); |
| 2244 } | 2260 } |
| 2245 EmitKeyedCallWithIC(expr, prop->key(), RelocInfo::CODE_TARGET); | 2261 EmitKeyedCallWithIC(expr, prop->key()); |
| 2246 } | 2262 } |
| 2247 } | 2263 } |
| 2248 } else { | 2264 } else { |
| 2249 { PreservePositionScope scope(masm()->positions_recorder()); | 2265 { PreservePositionScope scope(masm()->positions_recorder()); |
| 2250 VisitForStackValue(fun); | 2266 VisitForStackValue(fun); |
| 2251 } | 2267 } |
| 2252 // Load global receiver object. | 2268 // Load global receiver object. |
| 2253 __ movq(rbx, GlobalObjectOperand()); | 2269 __ movq(rbx, GlobalObjectOperand()); |
| 2254 __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); | 2270 __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); |
| 2255 // Emit function call. | 2271 // Emit function call. |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3582 // Push the arguments ("left-to-right"). | 3598 // Push the arguments ("left-to-right"). |
| 3583 int arg_count = args->length(); | 3599 int arg_count = args->length(); |
| 3584 for (int i = 0; i < arg_count; i++) { | 3600 for (int i = 0; i < arg_count; i++) { |
| 3585 VisitForStackValue(args->at(i)); | 3601 VisitForStackValue(args->at(i)); |
| 3586 } | 3602 } |
| 3587 | 3603 |
| 3588 if (expr->is_jsruntime()) { | 3604 if (expr->is_jsruntime()) { |
| 3589 // Call the JS runtime function using a call IC. | 3605 // Call the JS runtime function using a call IC. |
| 3590 __ Move(rcx, expr->name()); | 3606 __ Move(rcx, expr->name()); |
| 3591 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; | 3607 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 3608 RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
| 3592 Handle<Code> ic = | 3609 Handle<Code> ic = |
| 3593 ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop); | 3610 ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode); |
| 3594 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); | 3611 EmitCallIC(ic, mode, expr->id()); |
| 3595 // Restore context register. | 3612 // Restore context register. |
| 3596 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 3613 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 3597 } else { | 3614 } else { |
| 3598 __ CallRuntime(expr->function(), arg_count); | 3615 __ CallRuntime(expr->function(), arg_count); |
| 3599 } | 3616 } |
| 3600 context()->Plug(rax); | 3617 context()->Plug(rax); |
| 3601 } | 3618 } |
| 3602 | 3619 |
| 3603 | 3620 |
| 3604 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { | 3621 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4292 __ ret(0); | 4309 __ ret(0); |
| 4293 } | 4310 } |
| 4294 | 4311 |
| 4295 | 4312 |
| 4296 #undef __ | 4313 #undef __ |
| 4297 | 4314 |
| 4298 | 4315 |
| 4299 } } // namespace v8::internal | 4316 } } // namespace v8::internal |
| 4300 | 4317 |
| 4301 #endif // V8_TARGET_ARCH_X64 | 4318 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |