OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 2179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2190 __ Pop(rbx); | 2190 __ Pop(rbx); |
2191 __ Pop(rdi); | 2191 __ Pop(rdi); |
2192 | 2192 |
2193 __ bind(&done); | 2193 __ bind(&done); |
2194 __ Integer32ToSmi(rdx, rdx); | 2194 __ Integer32ToSmi(rdx, rdx); |
2195 | 2195 |
2196 __ bind(&done_no_smi_convert); | 2196 __ bind(&done_no_smi_convert); |
2197 } | 2197 } |
2198 | 2198 |
2199 | 2199 |
| 2200 static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) { |
| 2201 // Do not transform the receiver for strict mode functions. |
| 2202 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 2203 __ testb(FieldOperand(rcx, SharedFunctionInfo::kStrictModeByteOffset), |
| 2204 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); |
| 2205 __ j(not_equal, cont); |
| 2206 |
| 2207 // Do not transform the receiver for natives. |
| 2208 // SharedFunctionInfo is already loaded into rcx. |
| 2209 __ testb(FieldOperand(rcx, SharedFunctionInfo::kNativeByteOffset), |
| 2210 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); |
| 2211 __ j(not_equal, cont); |
| 2212 } |
| 2213 |
| 2214 |
| 2215 static void EmitSlowCase(Isolate* isolate, |
| 2216 MacroAssembler* masm, |
| 2217 StackArgumentsAccessor* args, |
| 2218 int argc, |
| 2219 Label* non_function) { |
| 2220 // Check for function proxy. |
| 2221 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); |
| 2222 __ j(not_equal, non_function); |
| 2223 __ PopReturnAddressTo(rcx); |
| 2224 __ Push(rdi); // put proxy as additional argument under return address |
| 2225 __ PushReturnAddressFrom(rcx); |
| 2226 __ Set(rax, argc + 1); |
| 2227 __ Set(rbx, 0); |
| 2228 __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY); |
| 2229 { |
| 2230 Handle<Code> adaptor = |
| 2231 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 2232 __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2233 } |
| 2234 |
| 2235 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 2236 // of the original receiver from the call site). |
| 2237 __ bind(non_function); |
| 2238 __ movp(args->GetReceiverOperand(), rdi); |
| 2239 __ Set(rax, argc); |
| 2240 __ Set(rbx, 0); |
| 2241 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION); |
| 2242 Handle<Code> adaptor = |
| 2243 isolate->builtins()->ArgumentsAdaptorTrampoline(); |
| 2244 __ Jump(adaptor, RelocInfo::CODE_TARGET); |
| 2245 } |
| 2246 |
| 2247 |
| 2248 static void EmitWrapCase(MacroAssembler* masm, |
| 2249 StackArgumentsAccessor* args, |
| 2250 Label* cont) { |
| 2251 // Wrap the receiver and patch it back onto the stack. |
| 2252 { FrameScope frame_scope(masm, StackFrame::INTERNAL); |
| 2253 __ Push(rdi); |
| 2254 __ Push(rax); |
| 2255 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 2256 __ Pop(rdi); |
| 2257 } |
| 2258 __ movp(args->GetReceiverOperand(), rax); |
| 2259 __ jmp(cont); |
| 2260 } |
| 2261 |
| 2262 |
2200 void CallFunctionStub::Generate(MacroAssembler* masm) { | 2263 void CallFunctionStub::Generate(MacroAssembler* masm) { |
2201 // rbx : feedback vector | |
2202 // rdx : (only if rbx is not the megamorphic symbol) slot in feedback | |
2203 // vector (Smi) | |
2204 // rdi : the function to call | 2264 // rdi : the function to call |
| 2265 |
| 2266 // wrap_and_call can only be true if we are compiling a monomorphic method. |
2205 Isolate* isolate = masm->isolate(); | 2267 Isolate* isolate = masm->isolate(); |
2206 Label slow, non_function, wrap, cont; | 2268 Label slow, non_function, wrap, cont; |
2207 StackArgumentsAccessor args(rsp, argc_); | 2269 int argc = argc_; |
| 2270 StackArgumentsAccessor args(rsp, argc); |
2208 | 2271 |
2209 if (NeedsChecks()) { | 2272 if (NeedsChecks()) { |
2210 // Check that the function really is a JavaScript function. | 2273 // Check that the function really is a JavaScript function. |
2211 __ JumpIfSmi(rdi, &non_function); | 2274 __ JumpIfSmi(rdi, &non_function); |
2212 | 2275 |
2213 // Goto slow case if we do not have a function. | 2276 // Goto slow case if we do not have a function. |
2214 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 2277 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
2215 __ j(not_equal, &slow); | 2278 __ j(not_equal, &slow); |
2216 | |
2217 if (RecordCallTarget()) { | |
2218 GenerateRecordCallTarget(masm); | |
2219 // Type information was updated. Because we may call Array, which | |
2220 // expects either undefined or an AllocationSite in rbx we need | |
2221 // to set rbx to undefined. | |
2222 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); | |
2223 } | |
2224 } | 2279 } |
2225 | 2280 |
2226 // Fast-case: Just invoke the function. | 2281 // Fast-case: Just invoke the function. |
2227 ParameterCount actual(argc_); | 2282 ParameterCount actual(argc); |
2228 | 2283 |
2229 if (CallAsMethod()) { | 2284 if (CallAsMethod()) { |
2230 if (NeedsChecks()) { | 2285 if (NeedsChecks()) { |
2231 // Do not transform the receiver for strict mode functions. | 2286 EmitContinueIfStrictOrNative(masm, &cont); |
2232 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | |
2233 __ testb(FieldOperand(rcx, SharedFunctionInfo::kStrictModeByteOffset), | |
2234 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); | |
2235 __ j(not_equal, &cont); | |
2236 | |
2237 // Do not transform the receiver for natives. | |
2238 // SharedFunctionInfo is already loaded into rcx. | |
2239 __ testb(FieldOperand(rcx, SharedFunctionInfo::kNativeByteOffset), | |
2240 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); | |
2241 __ j(not_equal, &cont); | |
2242 } | 2287 } |
2243 | 2288 |
2244 | |
2245 // Load the receiver from the stack. | 2289 // Load the receiver from the stack. |
2246 __ movp(rax, args.GetReceiverOperand()); | 2290 __ movp(rax, args.GetReceiverOperand()); |
2247 | 2291 |
2248 if (NeedsChecks()) { | 2292 if (NeedsChecks()) { |
2249 __ JumpIfSmi(rax, &wrap); | 2293 __ JumpIfSmi(rax, &wrap); |
2250 | 2294 |
2251 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); | 2295 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); |
2252 __ j(below, &wrap); | 2296 __ j(below, &wrap); |
2253 } else { | 2297 } else { |
2254 __ jmp(&wrap); | 2298 __ jmp(&wrap); |
2255 } | 2299 } |
2256 | 2300 |
2257 __ bind(&cont); | 2301 __ bind(&cont); |
2258 } | 2302 } |
| 2303 |
2259 __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper()); | 2304 __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper()); |
2260 | 2305 |
2261 if (NeedsChecks()) { | 2306 if (NeedsChecks()) { |
2262 // Slow-case: Non-function called. | 2307 // Slow-case: Non-function called. |
2263 __ bind(&slow); | 2308 __ bind(&slow); |
2264 if (RecordCallTarget()) { | 2309 EmitSlowCase(isolate, masm, &args, argc, &non_function); |
2265 // If there is a call target cache, mark it megamorphic in the | |
2266 // non-function case. MegamorphicSentinel is an immortal immovable | |
2267 // object (megamorphic symbol) so no write barrier is needed. | |
2268 __ SmiToInteger32(rdx, rdx); | |
2269 __ Move(FieldOperand(rbx, rdx, times_pointer_size, | |
2270 FixedArray::kHeaderSize), | |
2271 TypeFeedbackInfo::MegamorphicSentinel(isolate)); | |
2272 __ Integer32ToSmi(rdx, rdx); | |
2273 } | |
2274 // Check for function proxy. | |
2275 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); | |
2276 __ j(not_equal, &non_function); | |
2277 __ PopReturnAddressTo(rcx); | |
2278 __ Push(rdi); // put proxy as additional argument under return address | |
2279 __ PushReturnAddressFrom(rcx); | |
2280 __ Set(rax, argc_ + 1); | |
2281 __ Set(rbx, 0); | |
2282 __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY); | |
2283 { | |
2284 Handle<Code> adaptor = | |
2285 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); | |
2286 __ jmp(adaptor, RelocInfo::CODE_TARGET); | |
2287 } | |
2288 | |
2289 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead | |
2290 // of the original receiver from the call site). | |
2291 __ bind(&non_function); | |
2292 __ movp(args.GetReceiverOperand(), rdi); | |
2293 __ Set(rax, argc_); | |
2294 __ Set(rbx, 0); | |
2295 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION); | |
2296 Handle<Code> adaptor = | |
2297 isolate->builtins()->ArgumentsAdaptorTrampoline(); | |
2298 __ Jump(adaptor, RelocInfo::CODE_TARGET); | |
2299 } | 2310 } |
2300 | 2311 |
2301 if (CallAsMethod()) { | 2312 if (CallAsMethod()) { |
2302 __ bind(&wrap); | 2313 __ bind(&wrap); |
2303 // Wrap the receiver and patch it back onto the stack. | 2314 EmitWrapCase(masm, &args, &cont); |
2304 { FrameScope frame_scope(masm, StackFrame::INTERNAL); | |
2305 __ Push(rdi); | |
2306 __ Push(rax); | |
2307 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | |
2308 __ Pop(rdi); | |
2309 } | |
2310 __ movp(args.GetReceiverOperand(), rax); | |
2311 __ jmp(&cont); | |
2312 } | 2315 } |
2313 } | 2316 } |
2314 | 2317 |
2315 | 2318 |
2316 void CallConstructStub::Generate(MacroAssembler* masm) { | 2319 void CallConstructStub::Generate(MacroAssembler* masm) { |
2317 // rax : number of arguments | 2320 // rax : number of arguments |
2318 // rbx : feedback vector | 2321 // rbx : feedback vector |
2319 // rdx : (only if rbx is not the megamorphic symbol) slot in feedback | 2322 // rdx : (only if rbx is not the megamorphic symbol) slot in feedback |
2320 // vector (Smi) | 2323 // vector (Smi) |
2321 // rdi : constructor function | 2324 // rdi : constructor function |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 __ bind(&non_function_call); | 2375 __ bind(&non_function_call); |
2373 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); | 2376 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
2374 __ bind(&do_call); | 2377 __ bind(&do_call); |
2375 // Set expected number of arguments to zero (not changing rax). | 2378 // Set expected number of arguments to zero (not changing rax). |
2376 __ Set(rbx, 0); | 2379 __ Set(rbx, 0); |
2377 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), | 2380 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
2378 RelocInfo::CODE_TARGET); | 2381 RelocInfo::CODE_TARGET); |
2379 } | 2382 } |
2380 | 2383 |
2381 | 2384 |
| 2385 static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) { |
| 2386 __ movp(vector, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 2387 __ movp(vector, FieldOperand(vector, JSFunction::kSharedFunctionInfoOffset)); |
| 2388 __ movp(vector, FieldOperand(vector, |
| 2389 SharedFunctionInfo::kFeedbackVectorOffset)); |
| 2390 } |
| 2391 |
| 2392 |
| 2393 void CallICStub::Generate(MacroAssembler* masm) { |
| 2394 // rdi - function |
| 2395 // rbx - vector |
| 2396 // rdx - slot id |
| 2397 Isolate* isolate = masm->isolate(); |
| 2398 Label extra_checks_or_miss, slow_start; |
| 2399 Label slow, non_function, wrap, cont; |
| 2400 Label have_js_function; |
| 2401 int argc = state_.arg_count(); |
| 2402 StackArgumentsAccessor args(rsp, argc); |
| 2403 ParameterCount actual(argc); |
| 2404 |
| 2405 EmitLoadTypeFeedbackVector(masm, rbx); |
| 2406 |
| 2407 // The checks. First, does rdi match the recorded monomorphic target? |
| 2408 __ SmiToInteger32(rdx, rdx); |
| 2409 __ cmpq(rdi, FieldOperand(rbx, rdx, times_pointer_size, |
| 2410 FixedArray::kHeaderSize)); |
| 2411 __ j(not_equal, &extra_checks_or_miss); |
| 2412 |
| 2413 __ bind(&have_js_function); |
| 2414 if (state_.CallAsMethod()) { |
| 2415 EmitContinueIfStrictOrNative(masm, &cont); |
| 2416 |
| 2417 // Load the receiver from the stack. |
| 2418 __ movp(rax, args.GetReceiverOperand()); |
| 2419 |
| 2420 __ JumpIfSmi(rax, &wrap); |
| 2421 |
| 2422 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); |
| 2423 __ j(below, &wrap); |
| 2424 |
| 2425 __ bind(&cont); |
| 2426 } |
| 2427 |
| 2428 __ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper()); |
| 2429 |
| 2430 __ bind(&slow); |
| 2431 EmitSlowCase(isolate, masm, &args, argc, &non_function); |
| 2432 |
| 2433 if (state_.CallAsMethod()) { |
| 2434 __ bind(&wrap); |
| 2435 EmitWrapCase(masm, &args, &cont); |
| 2436 } |
| 2437 |
| 2438 __ bind(&extra_checks_or_miss); |
| 2439 Label miss; |
| 2440 |
| 2441 __ movp(rcx, FieldOperand(rbx, rdx, times_pointer_size, |
| 2442 FixedArray::kHeaderSize)); |
| 2443 __ Cmp(rcx, TypeFeedbackInfo::MegamorphicSentinel(isolate)); |
| 2444 __ j(equal, &slow_start); |
| 2445 __ Cmp(rcx, TypeFeedbackInfo::UninitializedSentinel(isolate)); |
| 2446 __ j(equal, &miss); |
| 2447 |
| 2448 if (!FLAG_trace_ic) { |
| 2449 // We are going megamorphic, and we don't want to visit the runtime. |
| 2450 __ Move(FieldOperand(rbx, rdx, times_pointer_size, |
| 2451 FixedArray::kHeaderSize), |
| 2452 TypeFeedbackInfo::MegamorphicSentinel(isolate)); |
| 2453 __ jmp(&slow_start); |
| 2454 } |
| 2455 |
| 2456 // We are here because tracing is on or we are going monomorphic. |
| 2457 __ bind(&miss); |
| 2458 GenerateMiss(masm); |
| 2459 |
| 2460 // the slow case |
| 2461 __ bind(&slow_start); |
| 2462 // Check that function is not a smi. |
| 2463 __ JumpIfSmi(rdi, &non_function); |
| 2464 // Check that function is a JSFunction. |
| 2465 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
| 2466 __ j(not_equal, &slow); |
| 2467 __ jmp(&have_js_function); |
| 2468 |
| 2469 // Unreachable |
| 2470 __ int3(); |
| 2471 } |
| 2472 |
| 2473 |
| 2474 void CallICStub::GenerateMiss(MacroAssembler* masm) { |
| 2475 // Get the receiver of the function from the stack; 1 ~ return address. |
| 2476 __ movp(rcx, Operand(rsp, (state_.arg_count() + 1) * kPointerSize)); |
| 2477 |
| 2478 { |
| 2479 FrameScope scope(masm, StackFrame::INTERNAL); |
| 2480 |
| 2481 // Push the receiver and the function and feedback info. |
| 2482 __ Push(rcx); |
| 2483 __ Push(rdi); |
| 2484 __ Push(rbx); |
| 2485 __ Integer32ToSmi(rdx, rdx); |
| 2486 __ Push(rdx); |
| 2487 |
| 2488 // Call the entry. |
| 2489 ExternalReference miss = ExternalReference(IC_Utility(IC::kCallIC_Miss), |
| 2490 masm->isolate()); |
| 2491 __ CallExternalReference(miss, 4); |
| 2492 |
| 2493 // Move result to edi and exit the internal frame. |
| 2494 __ movp(rdi, rax); |
| 2495 } |
| 2496 } |
| 2497 |
| 2498 |
2382 bool CEntryStub::NeedsImmovableCode() { | 2499 bool CEntryStub::NeedsImmovableCode() { |
2383 return false; | 2500 return false; |
2384 } | 2501 } |
2385 | 2502 |
2386 | 2503 |
2387 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { | 2504 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
2388 CEntryStub::GenerateAheadOfTime(isolate); | 2505 CEntryStub::GenerateAheadOfTime(isolate); |
2389 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); | 2506 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
2390 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); | 2507 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
2391 // It is important that the store buffer overflow stubs are generated first. | 2508 // It is important that the store buffer overflow stubs are generated first. |
(...skipping 2562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4954 return_value_operand, | 5071 return_value_operand, |
4955 NULL); | 5072 NULL); |
4956 } | 5073 } |
4957 | 5074 |
4958 | 5075 |
4959 #undef __ | 5076 #undef __ |
4960 | 5077 |
4961 } } // namespace v8::internal | 5078 } } // namespace v8::internal |
4962 | 5079 |
4963 #endif // V8_TARGET_ARCH_X64 | 5080 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |