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 2531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2542 } | 2542 } |
2543 | 2543 |
2544 | 2544 |
2545 void FullCodeGenerator::CallIC(Handle<Code> code, | 2545 void FullCodeGenerator::CallIC(Handle<Code> code, |
2546 TypeFeedbackId ast_id) { | 2546 TypeFeedbackId ast_id) { |
2547 ic_total_count_++; | 2547 ic_total_count_++; |
2548 __ call(code, RelocInfo::CODE_TARGET, ast_id); | 2548 __ call(code, RelocInfo::CODE_TARGET, ast_id); |
2549 } | 2549 } |
2550 | 2550 |
2551 | 2551 |
| 2552 // Code common for calls using the IC. |
| 2553 void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) { |
| 2554 Expression* callee = expr->expression(); |
2552 | 2555 |
2553 | 2556 CallIC::CallType call_type = callee->IsVariableProxy() |
2554 // Code common for calls using the IC. | 2557 ? CallIC::FUNCTION |
2555 void FullCodeGenerator::EmitCallWithIC(Call* expr) { | 2558 : CallIC::METHOD; |
2556 Expression* callee = expr->expression(); | |
2557 ZoneList<Expression*>* args = expr->arguments(); | |
2558 int arg_count = args->length(); | |
2559 | |
2560 CallFunctionFlags flags; | |
2561 // Get the target function. | 2559 // Get the target function. |
2562 if (callee->IsVariableProxy()) { | 2560 if (call_type == CallIC::FUNCTION) { |
2563 { StackValueContext context(this); | 2561 { StackValueContext context(this); |
2564 EmitVariableLoad(callee->AsVariableProxy()); | 2562 EmitVariableLoad(callee->AsVariableProxy()); |
2565 PrepareForBailout(callee, NO_REGISTERS); | 2563 PrepareForBailout(callee, NO_REGISTERS); |
2566 } | 2564 } |
2567 // Push undefined as receiver. This is patched in the method prologue if it | 2565 // Push undefined as receiver. This is patched in the method prologue if it |
2568 // is a sloppy mode method. | 2566 // is a sloppy mode method. |
2569 __ push(Immediate(isolate()->factory()->undefined_value())); | 2567 __ push(Immediate(isolate()->factory()->undefined_value())); |
2570 flags = NO_CALL_FUNCTION_FLAGS; | |
2571 } else { | 2568 } else { |
2572 // Load the function from the receiver. | 2569 // Load the function from the receiver. |
2573 ASSERT(callee->IsProperty()); | 2570 ASSERT(callee->IsProperty()); |
2574 __ mov(edx, Operand(esp, 0)); | 2571 __ mov(edx, Operand(esp, 0)); |
2575 EmitNamedPropertyLoad(callee->AsProperty()); | 2572 EmitNamedPropertyLoad(callee->AsProperty()); |
2576 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); | 2573 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
2577 // Push the target function under the receiver. | 2574 // Push the target function under the receiver. |
2578 __ push(Operand(esp, 0)); | 2575 __ push(Operand(esp, 0)); |
2579 __ mov(Operand(esp, kPointerSize), eax); | 2576 __ mov(Operand(esp, kPointerSize), eax); |
2580 flags = CALL_AS_METHOD; | |
2581 } | 2577 } |
2582 | 2578 |
2583 // Load the arguments. | 2579 EmitCall(expr, call_type); |
2584 { PreservePositionScope scope(masm()->positions_recorder()); | |
2585 for (int i = 0; i < arg_count; i++) { | |
2586 VisitForStackValue(args->at(i)); | |
2587 } | |
2588 } | |
2589 | |
2590 // Record source position of the IC call. | |
2591 SetSourcePosition(expr->position()); | |
2592 CallFunctionStub stub(arg_count, flags); | |
2593 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | |
2594 __ CallStub(&stub); | |
2595 RecordJSReturnSite(expr); | |
2596 | |
2597 // Restore context register. | |
2598 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2599 | |
2600 context()->DropAndPlug(1, eax); | |
2601 } | 2580 } |
2602 | 2581 |
2603 | 2582 |
2604 // Code common for calls using the IC. | 2583 // Code common for calls using the IC. |
2605 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, | 2584 void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr, |
2606 Expression* key) { | 2585 Expression* key) { |
2607 // Load the key. | 2586 // Load the key. |
2608 VisitForAccumulatorValue(key); | 2587 VisitForAccumulatorValue(key); |
2609 | 2588 |
2610 Expression* callee = expr->expression(); | 2589 Expression* callee = expr->expression(); |
2611 ZoneList<Expression*>* args = expr->arguments(); | |
2612 int arg_count = args->length(); | |
2613 | 2590 |
2614 // Load the function from the receiver. | 2591 // Load the function from the receiver. |
2615 ASSERT(callee->IsProperty()); | 2592 ASSERT(callee->IsProperty()); |
2616 __ mov(edx, Operand(esp, 0)); | 2593 __ mov(edx, Operand(esp, 0)); |
2617 // Move the key into the right register for the keyed load IC. | 2594 // Move the key into the right register for the keyed load IC. |
2618 __ mov(ecx, eax); | 2595 __ mov(ecx, eax); |
2619 EmitKeyedPropertyLoad(callee->AsProperty()); | 2596 EmitKeyedPropertyLoad(callee->AsProperty()); |
2620 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); | 2597 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
2621 | 2598 |
2622 // Push the target function under the receiver. | 2599 // Push the target function under the receiver. |
2623 __ push(Operand(esp, 0)); | 2600 __ push(Operand(esp, 0)); |
2624 __ mov(Operand(esp, kPointerSize), eax); | 2601 __ mov(Operand(esp, kPointerSize), eax); |
2625 | 2602 |
2626 // Load the arguments. | 2603 EmitCall(expr, CallIC::METHOD); |
2627 { PreservePositionScope scope(masm()->positions_recorder()); | |
2628 for (int i = 0; i < arg_count; i++) { | |
2629 VisitForStackValue(args->at(i)); | |
2630 } | |
2631 } | |
2632 | |
2633 // Record source position of the IC call. | |
2634 SetSourcePosition(expr->position()); | |
2635 CallFunctionStub stub(arg_count, CALL_AS_METHOD); | |
2636 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | |
2637 __ CallStub(&stub); | |
2638 RecordJSReturnSite(expr); | |
2639 | |
2640 // Restore context register. | |
2641 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2642 | |
2643 context()->DropAndPlug(1, eax); | |
2644 } | 2604 } |
2645 | 2605 |
2646 | 2606 |
2647 void FullCodeGenerator::EmitCallWithStub(Call* expr) { | 2607 void FullCodeGenerator::EmitCall(Call* expr, CallIC::CallType call_type) { |
2648 // Code common for calls using the call stub. | 2608 // Load the arguments. |
2649 ZoneList<Expression*>* args = expr->arguments(); | 2609 ZoneList<Expression*>* args = expr->arguments(); |
2650 int arg_count = args->length(); | 2610 int arg_count = args->length(); |
2651 { PreservePositionScope scope(masm()->positions_recorder()); | 2611 { PreservePositionScope scope(masm()->positions_recorder()); |
2652 for (int i = 0; i < arg_count; i++) { | 2612 for (int i = 0; i < arg_count; i++) { |
2653 VisitForStackValue(args->at(i)); | 2613 VisitForStackValue(args->at(i)); |
2654 } | 2614 } |
2655 } | 2615 } |
2656 // Record source position for debugger. | 2616 |
| 2617 // Record source position of the IC call. |
2657 SetSourcePosition(expr->position()); | 2618 SetSourcePosition(expr->position()); |
2658 | 2619 Handle<Code> ic = CallIC::initialize_stub( |
| 2620 isolate(), arg_count, call_type); |
2659 Handle<Object> uninitialized = | 2621 Handle<Object> uninitialized = |
2660 TypeFeedbackInfo::UninitializedSentinel(isolate()); | 2622 TypeFeedbackInfo::UninitializedSentinel(isolate()); |
2661 StoreFeedbackVectorSlot(expr->CallFeedbackSlot(), uninitialized); | 2623 StoreFeedbackVectorSlot(expr->CallFeedbackSlot(), uninitialized); |
2662 __ LoadHeapObject(ebx, FeedbackVector()); | 2624 __ LoadHeapObject(ebx, FeedbackVector()); |
2663 __ mov(edx, Immediate(Smi::FromInt(expr->CallFeedbackSlot()))); | 2625 __ mov(edx, Immediate(Smi::FromInt(expr->CallFeedbackSlot()))); |
2664 | |
2665 // Record call targets in unoptimized code. | |
2666 CallFunctionStub stub(arg_count, RECORD_CALL_TARGET); | |
2667 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | 2626 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
2668 __ CallStub(&stub); | 2627 // Don't assign a type feedback id to the IC, since type feedback is provided |
| 2628 // by the vector above. |
| 2629 CallIC(ic); |
2669 | 2630 |
2670 RecordJSReturnSite(expr); | 2631 RecordJSReturnSite(expr); |
| 2632 |
2671 // Restore context register. | 2633 // Restore context register. |
2672 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 2634 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2635 |
2673 context()->DropAndPlug(1, eax); | 2636 context()->DropAndPlug(1, eax); |
2674 } | 2637 } |
2675 | 2638 |
2676 | 2639 |
2677 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { | 2640 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
2678 // Push copy of the first argument or undefined if it doesn't exist. | 2641 // Push copy of the first argument or undefined if it doesn't exist. |
2679 if (arg_count > 0) { | 2642 if (arg_count > 0) { |
2680 __ push(Operand(esp, arg_count * kPointerSize)); | 2643 __ push(Operand(esp, arg_count * kPointerSize)); |
2681 } else { | 2644 } else { |
2682 __ push(Immediate(isolate()->factory()->undefined_value())); | 2645 __ push(Immediate(isolate()->factory()->undefined_value())); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2735 SetSourcePosition(expr->position()); | 2698 SetSourcePosition(expr->position()); |
2736 CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); | 2699 CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); |
2737 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | 2700 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
2738 __ CallStub(&stub); | 2701 __ CallStub(&stub); |
2739 RecordJSReturnSite(expr); | 2702 RecordJSReturnSite(expr); |
2740 // Restore context register. | 2703 // Restore context register. |
2741 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 2704 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
2742 context()->DropAndPlug(1, eax); | 2705 context()->DropAndPlug(1, eax); |
2743 | 2706 |
2744 } else if (call_type == Call::GLOBAL_CALL) { | 2707 } else if (call_type == Call::GLOBAL_CALL) { |
2745 EmitCallWithIC(expr); | 2708 EmitCallWithLoadIC(expr); |
2746 | 2709 |
2747 } else if (call_type == Call::LOOKUP_SLOT_CALL) { | 2710 } else if (call_type == Call::LOOKUP_SLOT_CALL) { |
2748 // Call to a lookup slot (dynamically introduced variable). | 2711 // Call to a lookup slot (dynamically introduced variable). |
2749 VariableProxy* proxy = callee->AsVariableProxy(); | 2712 VariableProxy* proxy = callee->AsVariableProxy(); |
2750 Label slow, done; | 2713 Label slow, done; |
2751 { PreservePositionScope scope(masm()->positions_recorder()); | 2714 { PreservePositionScope scope(masm()->positions_recorder()); |
2752 // Generate code for loading from variables potentially shadowed by | 2715 // Generate code for loading from variables potentially shadowed by |
2753 // eval-introduced variables. | 2716 // eval-introduced variables. |
2754 EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); | 2717 EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); |
2755 } | 2718 } |
(...skipping 15 matching lines...) Expand all Loading... |
2771 // Push function. | 2734 // Push function. |
2772 __ push(eax); | 2735 __ push(eax); |
2773 // The receiver is implicitly the global receiver. Indicate this by | 2736 // The receiver is implicitly the global receiver. Indicate this by |
2774 // passing the hole to the call function stub. | 2737 // passing the hole to the call function stub. |
2775 __ push(Immediate(isolate()->factory()->undefined_value())); | 2738 __ push(Immediate(isolate()->factory()->undefined_value())); |
2776 __ bind(&call); | 2739 __ bind(&call); |
2777 } | 2740 } |
2778 | 2741 |
2779 // The receiver is either the global receiver or an object found by | 2742 // The receiver is either the global receiver or an object found by |
2780 // LoadContextSlot. | 2743 // LoadContextSlot. |
2781 EmitCallWithStub(expr); | 2744 EmitCall(expr); |
2782 | 2745 |
2783 } else if (call_type == Call::PROPERTY_CALL) { | 2746 } else if (call_type == Call::PROPERTY_CALL) { |
2784 Property* property = callee->AsProperty(); | 2747 Property* property = callee->AsProperty(); |
2785 { PreservePositionScope scope(masm()->positions_recorder()); | 2748 { PreservePositionScope scope(masm()->positions_recorder()); |
2786 VisitForStackValue(property->obj()); | 2749 VisitForStackValue(property->obj()); |
2787 } | 2750 } |
2788 if (property->key()->IsPropertyName()) { | 2751 if (property->key()->IsPropertyName()) { |
2789 EmitCallWithIC(expr); | 2752 EmitCallWithLoadIC(expr); |
2790 } else { | 2753 } else { |
2791 EmitKeyedCallWithIC(expr, property->key()); | 2754 EmitKeyedCallWithLoadIC(expr, property->key()); |
2792 } | 2755 } |
2793 | 2756 |
2794 } else { | 2757 } else { |
2795 ASSERT(call_type == Call::OTHER_CALL); | 2758 ASSERT(call_type == Call::OTHER_CALL); |
2796 // Call to an arbitrary expression not handled specially above. | 2759 // Call to an arbitrary expression not handled specially above. |
2797 { PreservePositionScope scope(masm()->positions_recorder()); | 2760 { PreservePositionScope scope(masm()->positions_recorder()); |
2798 VisitForStackValue(callee); | 2761 VisitForStackValue(callee); |
2799 } | 2762 } |
2800 __ push(Immediate(isolate()->factory()->undefined_value())); | 2763 __ push(Immediate(isolate()->factory()->undefined_value())); |
2801 // Emit function call. | 2764 // Emit function call. |
2802 EmitCallWithStub(expr); | 2765 EmitCall(expr); |
2803 } | 2766 } |
2804 | 2767 |
2805 #ifdef DEBUG | 2768 #ifdef DEBUG |
2806 // RecordJSReturnSite should have been called. | 2769 // RecordJSReturnSite should have been called. |
2807 ASSERT(expr->return_is_recorded_); | 2770 ASSERT(expr->return_is_recorded_); |
2808 #endif | 2771 #endif |
2809 } | 2772 } |
2810 | 2773 |
2811 | 2774 |
2812 void FullCodeGenerator::VisitCallNew(CallNew* expr) { | 2775 void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
(...skipping 29 matching lines...) Expand all Loading... |
2842 if (FLAG_pretenuring_call_new) { | 2805 if (FLAG_pretenuring_call_new) { |
2843 StoreFeedbackVectorSlot(expr->AllocationSiteFeedbackSlot(), | 2806 StoreFeedbackVectorSlot(expr->AllocationSiteFeedbackSlot(), |
2844 isolate()->factory()->NewAllocationSite()); | 2807 isolate()->factory()->NewAllocationSite()); |
2845 ASSERT(expr->AllocationSiteFeedbackSlot() == | 2808 ASSERT(expr->AllocationSiteFeedbackSlot() == |
2846 expr->CallNewFeedbackSlot() + 1); | 2809 expr->CallNewFeedbackSlot() + 1); |
2847 } | 2810 } |
2848 | 2811 |
2849 __ LoadHeapObject(ebx, FeedbackVector()); | 2812 __ LoadHeapObject(ebx, FeedbackVector()); |
2850 __ mov(edx, Immediate(Smi::FromInt(expr->CallNewFeedbackSlot()))); | 2813 __ mov(edx, Immediate(Smi::FromInt(expr->CallNewFeedbackSlot()))); |
2851 | 2814 |
2852 CallConstructStub stub(RECORD_CALL_TARGET); | 2815 CallConstructStub stub(RECORD_CONSTRUCTOR_TARGET); |
2853 __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); | 2816 __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); |
2854 PrepareForBailoutForId(expr->ReturnId(), TOS_REG); | 2817 PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
2855 context()->Plug(eax); | 2818 context()->Plug(eax); |
2856 } | 2819 } |
2857 | 2820 |
2858 | 2821 |
2859 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { | 2822 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
2860 ZoneList<Expression*>* args = expr->arguments(); | 2823 ZoneList<Expression*>* args = expr->arguments(); |
2861 ASSERT(args->length() == 1); | 2824 ASSERT(args->length() == 1); |
2862 | 2825 |
(...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4903 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4866 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4904 Assembler::target_address_at(call_target_address, | 4867 Assembler::target_address_at(call_target_address, |
4905 unoptimized_code)); | 4868 unoptimized_code)); |
4906 return OSR_AFTER_STACK_CHECK; | 4869 return OSR_AFTER_STACK_CHECK; |
4907 } | 4870 } |
4908 | 4871 |
4909 | 4872 |
4910 } } // namespace v8::internal | 4873 } } // namespace v8::internal |
4911 | 4874 |
4912 #endif // V8_TARGET_ARCH_IA32 | 4875 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |