OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 2345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 __ RecordWriteArray(ebx, edi, edx, kDontSaveFPRegs, | 2356 __ RecordWriteArray(ebx, edi, edx, kDontSaveFPRegs, |
2357 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | 2357 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
2358 __ pop(edx); | 2358 __ pop(edx); |
2359 __ pop(ebx); | 2359 __ pop(ebx); |
2360 __ pop(edi); | 2360 __ pop(edi); |
2361 | 2361 |
2362 __ bind(&done); | 2362 __ bind(&done); |
2363 } | 2363 } |
2364 | 2364 |
2365 | 2365 |
2366 void CallFunctionStub::Generate(MacroAssembler* masm) { | 2366 static void GenericCallHelper(MacroAssembler* masm, |
2367 // ebx : feedback vector | 2367 const CallIC::State& state) { |
2368 // edx : (only if ebx is not the megamorphic symbol) slot in feedback | |
2369 // vector (Smi) | |
2370 // edi : the function to call | 2368 // edi : the function to call |
2371 Isolate* isolate = masm->isolate(); | 2369 Isolate* isolate = masm->isolate(); |
2372 Label slow, non_function, wrap, cont; | 2370 Label slow, non_function, wrap, cont; |
2373 | 2371 |
2374 if (NeedsChecks()) { | 2372 if (state.IsGeneric()) { |
2375 // Check that the function really is a JavaScript function. | 2373 // Check that the function really is a JavaScript function. |
2376 __ JumpIfSmi(edi, &non_function); | 2374 __ JumpIfSmi(edi, &non_function); |
2377 | 2375 |
2378 // Goto slow case if we do not have a function. | 2376 // Goto slow case if we do not have a function. |
2379 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); | 2377 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
2380 __ j(not_equal, &slow); | 2378 __ j(not_equal, &slow); |
2381 | |
2382 if (RecordCallTarget()) { | |
2383 GenerateRecordCallTarget(masm); | |
2384 // Type information was updated. Because we may call Array, which | |
2385 // expects either undefined or an AllocationSite in ebx we need | |
2386 // to set ebx to undefined. | |
2387 __ mov(ebx, Immediate(isolate->factory()->undefined_value())); | |
2388 } | |
2389 } | 2379 } |
2390 | 2380 |
2391 // Fast-case: Just invoke the function. | 2381 // Fast-case: Just invoke the function. |
2392 ParameterCount actual(argc_); | 2382 int argc = state.arg_count(); |
| 2383 ParameterCount actual(argc); |
2393 | 2384 |
2394 if (CallAsMethod()) { | 2385 if (state.CallAsMethod()) { |
2395 if (NeedsChecks()) { | 2386 if (state.IsGeneric()) { |
2396 // Do not transform the receiver for strict mode functions. | 2387 // Do not transform the receiver for strict mode functions. |
2397 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 2388 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
2398 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kStrictModeByteOffset), | 2389 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kStrictModeByteOffset), |
2399 1 << SharedFunctionInfo::kStrictModeBitWithinByte); | 2390 1 << SharedFunctionInfo::kStrictModeBitWithinByte); |
2400 __ j(not_equal, &cont); | 2391 __ j(not_equal, &cont); |
2401 | 2392 |
2402 // Do not transform the receiver for natives (shared already in ecx). | 2393 // Do not transform the receiver for natives (shared already in ecx). |
2403 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kNativeByteOffset), | 2394 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kNativeByteOffset), |
2404 1 << SharedFunctionInfo::kNativeBitWithinByte); | 2395 1 << SharedFunctionInfo::kNativeBitWithinByte); |
2405 __ j(not_equal, &cont); | 2396 __ j(not_equal, &cont); |
2406 } | 2397 } |
2407 | 2398 |
2408 // Load the receiver from the stack. | 2399 if (state.IsSloppy()) { |
2409 __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); | 2400 // Load the receiver from the stack. |
| 2401 __ mov(eax, Operand(esp, (argc + 1) * kPointerSize)); |
2410 | 2402 |
2411 if (NeedsChecks()) { | |
2412 __ JumpIfSmi(eax, &wrap); | 2403 __ JumpIfSmi(eax, &wrap); |
2413 | 2404 |
2414 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); | 2405 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
2415 __ j(below, &wrap); | 2406 __ j(below, &wrap); |
2416 } else { | |
2417 __ jmp(&wrap); | |
2418 } | 2407 } |
2419 | 2408 |
2420 __ bind(&cont); | 2409 __ bind(&cont); |
2421 } | 2410 } |
2422 | 2411 |
2423 __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper()); | 2412 if (state.ArgumentsMustMatch()) { |
| 2413 __ InvokeFunction(edi, actual, actual, JUMP_FUNCTION, NullCallWrapper()); |
| 2414 } else { |
| 2415 __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper()); |
| 2416 } |
2424 | 2417 |
2425 if (NeedsChecks()) { | 2418 if (state.IsGeneric()) { |
2426 // Slow-case: Non-function called. | 2419 // Slow-case: Non-function called. |
2427 __ bind(&slow); | 2420 __ bind(&slow); |
2428 if (RecordCallTarget()) { | |
2429 // If there is a call target cache, mark it megamorphic in the | |
2430 // non-function case. MegamorphicSentinel is an immortal immovable | |
2431 // object (megamorphic symbol) so no write barrier is needed. | |
2432 __ mov(FieldOperand(ebx, edx, times_half_pointer_size, | |
2433 FixedArray::kHeaderSize), | |
2434 Immediate(TypeFeedbackInfo::MegamorphicSentinel(isolate))); | |
2435 } | |
2436 // Check for function proxy. | 2421 // Check for function proxy. |
2437 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); | 2422 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
2438 __ j(not_equal, &non_function); | 2423 __ j(not_equal, &non_function); |
2439 __ pop(ecx); | 2424 __ pop(ecx); |
2440 __ push(edi); // put proxy as additional argument under return address | 2425 __ push(edi); // put proxy as additional argument under return address |
2441 __ push(ecx); | 2426 __ push(ecx); |
2442 __ Move(eax, Immediate(argc_ + 1)); | 2427 __ Move(eax, Immediate(argc + 1)); |
2443 __ Move(ebx, Immediate(0)); | 2428 __ Move(ebx, Immediate(0)); |
2444 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); | 2429 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
2445 { | 2430 { |
2446 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); | 2431 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
2447 __ jmp(adaptor, RelocInfo::CODE_TARGET); | 2432 __ jmp(adaptor, RelocInfo::CODE_TARGET); |
2448 } | 2433 } |
2449 | 2434 |
2450 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead | 2435 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
2451 // of the original receiver from the call site). | 2436 // of the original receiver from the call site). |
2452 __ bind(&non_function); | 2437 __ bind(&non_function); |
2453 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); | 2438 __ mov(Operand(esp, (argc + 1) * kPointerSize), edi); |
2454 __ Move(eax, Immediate(argc_)); | 2439 __ Move(eax, Immediate(argc)); |
2455 __ Move(ebx, Immediate(0)); | 2440 __ Move(ebx, Immediate(0)); |
2456 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); | 2441 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
2457 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); | 2442 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
2458 __ jmp(adaptor, RelocInfo::CODE_TARGET); | 2443 __ jmp(adaptor, RelocInfo::CODE_TARGET); |
2459 } | 2444 } |
2460 | 2445 |
2461 if (CallAsMethod()) { | 2446 if (state.CallAsMethod() && state.IsSloppy()) { |
2462 __ bind(&wrap); | 2447 __ bind(&wrap); |
| 2448 |
| 2449 if (!state.IsGeneric()) { |
| 2450 // Do not transform the receiver for natives (shared already in ecx). |
| 2451 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2452 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kNativeByteOffset), |
| 2453 1 << SharedFunctionInfo::kNativeBitWithinByte); |
| 2454 __ j(not_equal, &cont); |
| 2455 } |
| 2456 |
2463 // Wrap the receiver and patch it back onto the stack. | 2457 // Wrap the receiver and patch it back onto the stack. |
2464 { FrameScope frame_scope(masm, StackFrame::INTERNAL); | 2458 { FrameScope frame_scope(masm, StackFrame::INTERNAL); |
2465 __ push(edi); | 2459 __ push(edi); |
2466 __ push(eax); | 2460 __ push(eax); |
2467 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | 2461 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
2468 __ pop(edi); | 2462 __ pop(edi); |
2469 } | 2463 } |
2470 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), eax); | 2464 __ mov(Operand(esp, (argc + 1) * kPointerSize), eax); |
2471 __ jmp(&cont); | 2465 __ jmp(&cont); |
2472 } | 2466 } |
2473 } | 2467 } |
2474 | 2468 |
2475 | 2469 |
| 2470 void CallFunctionStub::Generate(MacroAssembler* masm) { |
| 2471 // edi : the function to call |
| 2472 |
| 2473 // GenericCallHelper expresses it's options in terms of CallIC::State. |
| 2474 CallIC::CallType call_type = CallAsMethod() ? |
| 2475 CallIC::METHOD : CallIC::FUNCTION; |
| 2476 |
| 2477 if (NeedsChecks()) { |
| 2478 GenericCallHelper(masm, |
| 2479 CallIC::State::SlowCallState( |
| 2480 argc_, |
| 2481 call_type)); |
| 2482 } else { |
| 2483 GenericCallHelper(masm, |
| 2484 CallIC::State::MonomorphicCallState( |
| 2485 argc_, |
| 2486 call_type, |
| 2487 CallIC::ARGUMENTS_COUNT_UNKNOWN, |
| 2488 SLOPPY)); |
| 2489 } |
| 2490 } |
| 2491 |
| 2492 |
2476 void CallConstructStub::Generate(MacroAssembler* masm) { | 2493 void CallConstructStub::Generate(MacroAssembler* masm) { |
2477 // eax : number of arguments | 2494 // eax : number of arguments |
2478 // ebx : feedback vector | 2495 // ebx : feedback vector |
2479 // edx : (only if ebx is not the megamorphic symbol) slot in feedback | 2496 // edx : (only if ebx is not the megamorphic symbol) slot in feedback |
2480 // vector (Smi) | 2497 // vector (Smi) |
2481 // edi : constructor function | 2498 // edi : constructor function |
2482 Label slow, non_function_call; | 2499 Label slow, non_function_call; |
2483 | 2500 |
2484 // Check that function is not a smi. | 2501 // Check that function is not a smi. |
2485 __ JumpIfSmi(edi, &non_function_call); | 2502 __ JumpIfSmi(edi, &non_function_call); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2534 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); | 2551 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
2535 __ bind(&do_call); | 2552 __ bind(&do_call); |
2536 // Set expected number of arguments to zero (not changing eax). | 2553 // Set expected number of arguments to zero (not changing eax). |
2537 __ Move(ebx, Immediate(0)); | 2554 __ Move(ebx, Immediate(0)); |
2538 Handle<Code> arguments_adaptor = | 2555 Handle<Code> arguments_adaptor = |
2539 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); | 2556 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
2540 __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); | 2557 __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
2541 } | 2558 } |
2542 | 2559 |
2543 | 2560 |
| 2561 void CallICStub::GenerateMonomorphicCall(MacroAssembler* masm) { |
| 2562 GenericCallHelper(masm, |
| 2563 CallIC::State::MonomorphicCallState( |
| 2564 state_.arg_count(), |
| 2565 state_.call_type(), |
| 2566 state_.argument_check(), |
| 2567 state_.strict_mode())); |
| 2568 } |
| 2569 |
| 2570 |
| 2571 void CallICStub::GenerateSlowCall(MacroAssembler* masm) { |
| 2572 GenericCallHelper(masm, |
| 2573 CallIC::State::SlowCallState( |
| 2574 state_.arg_count(), |
| 2575 state_.call_type())); |
| 2576 } |
| 2577 |
| 2578 |
| 2579 void CallICStub::Generate(MacroAssembler* masm) { |
| 2580 // edi - function |
| 2581 // ebx - vector |
| 2582 // edx - slot id |
| 2583 Isolate* isolate = masm->isolate(); |
| 2584 Label extra_checks_or_miss, slow; |
| 2585 |
| 2586 // The checks. First, does edi match the recorded monomorphic target? |
| 2587 __ cmp(edi, FieldOperand(ebx, edx, times_half_pointer_size, |
| 2588 FixedArray::kHeaderSize)); |
| 2589 __ j(not_equal, &extra_checks_or_miss); |
| 2590 |
| 2591 GenerateMonomorphicCall(masm); |
| 2592 |
| 2593 __ bind(&extra_checks_or_miss); |
| 2594 if (IsGeneric()) { |
| 2595 Label miss_uninit; |
| 2596 |
| 2597 __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 2598 FixedArray::kHeaderSize)); |
| 2599 __ cmp(ecx, Immediate(TypeFeedbackInfo::MegamorphicSentinel(isolate))); |
| 2600 __ j(equal, &slow); |
| 2601 __ cmp(ecx, Immediate(TypeFeedbackInfo::UninitializedSentinel(isolate))); |
| 2602 __ j(equal, &miss_uninit); |
| 2603 // If we get here, go from monomorphic to megamorphic, Don't bother missing, |
| 2604 // just update. |
| 2605 __ mov(FieldOperand(ebx, edx, times_half_pointer_size, |
| 2606 FixedArray::kHeaderSize), |
| 2607 Immediate(TypeFeedbackInfo::MegamorphicSentinel(isolate))); |
| 2608 __ jmp(&slow); |
| 2609 |
| 2610 __ bind(&miss_uninit); |
| 2611 } |
| 2612 |
| 2613 GenerateMiss(masm); |
| 2614 |
| 2615 // the slow case |
| 2616 __ bind(&slow); |
| 2617 GenerateSlowCall(masm); |
| 2618 } |
| 2619 |
| 2620 |
| 2621 void CallICStub::GenerateMiss(MacroAssembler* masm) { |
| 2622 // Get the receiver of the function from the stack; 1 ~ return address. |
| 2623 __ mov(ecx, Operand(esp, (state_.arg_count() + 1) * kPointerSize)); |
| 2624 |
| 2625 { |
| 2626 FrameScope scope(masm, StackFrame::INTERNAL); |
| 2627 |
| 2628 // Push the receiver and the function and feedback info. |
| 2629 __ push(ecx); |
| 2630 __ push(edi); |
| 2631 __ push(ebx); |
| 2632 __ push(edx); |
| 2633 |
| 2634 // Call the entry. |
| 2635 ExternalReference miss = ExternalReference(IC_Utility(IC::kCallIC_Miss), |
| 2636 masm->isolate()); |
| 2637 __ CallExternalReference(miss, 4); |
| 2638 |
| 2639 // Move result to edi and exit the internal frame. |
| 2640 __ mov(edi, eax); |
| 2641 } |
| 2642 } |
| 2643 |
| 2644 |
2544 bool CEntryStub::NeedsImmovableCode() { | 2645 bool CEntryStub::NeedsImmovableCode() { |
2545 return false; | 2646 return false; |
2546 } | 2647 } |
2547 | 2648 |
2548 | 2649 |
2549 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { | 2650 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
2550 CEntryStub::GenerateAheadOfTime(isolate); | 2651 CEntryStub::GenerateAheadOfTime(isolate); |
2551 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); | 2652 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
2552 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); | 2653 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
2553 // It is important that the store buffer overflow stubs are generated first. | 2654 // It is important that the store buffer overflow stubs are generated first. |
(...skipping 2808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5362 Operand(ebp, 7 * kPointerSize), | 5463 Operand(ebp, 7 * kPointerSize), |
5363 NULL); | 5464 NULL); |
5364 } | 5465 } |
5365 | 5466 |
5366 | 5467 |
5367 #undef __ | 5468 #undef __ |
5368 | 5469 |
5369 } } // namespace v8::internal | 5470 } } // namespace v8::internal |
5370 | 5471 |
5371 #endif // V8_TARGET_ARCH_IA32 | 5472 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |