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 2557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2568 } | 2568 } |
2569 | 2569 |
2570 | 2570 |
2571 void FullCodeGenerator::CallIC(Handle<Code> code, | 2571 void FullCodeGenerator::CallIC(Handle<Code> code, |
2572 TypeFeedbackId ast_id) { | 2572 TypeFeedbackId ast_id) { |
2573 ic_total_count_++; | 2573 ic_total_count_++; |
2574 __ call(code, RelocInfo::CODE_TARGET, ast_id); | 2574 __ call(code, RelocInfo::CODE_TARGET, ast_id); |
2575 } | 2575 } |
2576 | 2576 |
2577 | 2577 |
| 2578 // Code common for calls using the IC. |
| 2579 void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) { |
| 2580 Expression* callee = expr->expression(); |
2578 | 2581 |
2579 | 2582 CallIC::CallType call_type = callee->IsVariableProxy() |
2580 // Code common for calls using the IC. | 2583 ? CallIC::FUNCTION |
2581 void FullCodeGenerator::EmitCallWithIC(Call* expr) { | 2584 : CallIC::METHOD; |
2582 Expression* callee = expr->expression(); | |
2583 ZoneList<Expression*>* args = expr->arguments(); | |
2584 int arg_count = args->length(); | |
2585 | |
2586 CallFunctionFlags flags; | |
2587 // Get the target function. | 2585 // Get the target function. |
2588 if (callee->IsVariableProxy()) { | 2586 if (call_type == CallIC::FUNCTION) { |
2589 { StackValueContext context(this); | 2587 { StackValueContext context(this); |
2590 EmitVariableLoad(callee->AsVariableProxy()); | 2588 EmitVariableLoad(callee->AsVariableProxy()); |
2591 PrepareForBailout(callee, NO_REGISTERS); | 2589 PrepareForBailout(callee, NO_REGISTERS); |
2592 } | 2590 } |
2593 // Push undefined as receiver. This is patched in the method prologue if it | 2591 // Push undefined as receiver. This is patched in the method prologue if it |
2594 // is a sloppy mode method. | 2592 // is a sloppy mode method. |
2595 __ push(Immediate(isolate()->factory()->undefined_value())); | 2593 __ push(Immediate(isolate()->factory()->undefined_value())); |
2596 flags = NO_CALL_FUNCTION_FLAGS; | |
2597 } else { | 2594 } else { |
2598 // Load the function from the receiver. | 2595 // Load the function from the receiver. |
2599 ASSERT(callee->IsProperty()); | 2596 ASSERT(callee->IsProperty()); |
2600 __ mov(edx, Operand(esp, 0)); | 2597 __ mov(edx, Operand(esp, 0)); |
2601 EmitNamedPropertyLoad(callee->AsProperty()); | 2598 EmitNamedPropertyLoad(callee->AsProperty()); |
2602 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); | 2599 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
2603 // Push the target function under the receiver. | 2600 // Push the target function under the receiver. |
2604 __ push(Operand(esp, 0)); | 2601 __ push(Operand(esp, 0)); |
2605 __ mov(Operand(esp, kPointerSize), eax); | 2602 __ mov(Operand(esp, kPointerSize), eax); |
2606 flags = CALL_AS_METHOD; | |
2607 } | 2603 } |
2608 | 2604 |
2609 // Load the arguments. | 2605 EmitCall(expr, call_type); |
2610 { PreservePositionScope scope(masm()->positions_recorder()); | |
2611 for (int i = 0; i < arg_count; i++) { | |
2612 VisitForStackValue(args->at(i)); | |
2613 } | |
2614 } | |
2615 | |
2616 // Record source position of the IC call. | |
2617 SetSourcePosition(expr->position()); | |
2618 CallFunctionStub stub(arg_count, flags); | |
2619 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | |
2620 __ CallStub(&stub); | |
2621 RecordJSReturnSite(expr); | |
2622 | |
2623 // Restore context register. | |
2624 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2625 | |
2626 context()->DropAndPlug(1, eax); | |
2627 } | 2606 } |
2628 | 2607 |
2629 | 2608 |
2630 // Code common for calls using the IC. | 2609 // Code common for calls using the IC. |
2631 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, | 2610 void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr, |
2632 Expression* key) { | 2611 Expression* key) { |
2633 // Load the key. | 2612 // Load the key. |
2634 VisitForAccumulatorValue(key); | 2613 VisitForAccumulatorValue(key); |
2635 | 2614 |
2636 Expression* callee = expr->expression(); | 2615 Expression* callee = expr->expression(); |
2637 ZoneList<Expression*>* args = expr->arguments(); | |
2638 int arg_count = args->length(); | |
2639 | 2616 |
2640 // Load the function from the receiver. | 2617 // Load the function from the receiver. |
2641 ASSERT(callee->IsProperty()); | 2618 ASSERT(callee->IsProperty()); |
2642 __ mov(edx, Operand(esp, 0)); | 2619 __ mov(edx, Operand(esp, 0)); |
2643 // Move the key into the right register for the keyed load IC. | 2620 // Move the key into the right register for the keyed load IC. |
2644 __ mov(ecx, eax); | 2621 __ mov(ecx, eax); |
2645 EmitKeyedPropertyLoad(callee->AsProperty()); | 2622 EmitKeyedPropertyLoad(callee->AsProperty()); |
2646 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); | 2623 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
2647 | 2624 |
2648 // Push the target function under the receiver. | 2625 // Push the target function under the receiver. |
2649 __ push(Operand(esp, 0)); | 2626 __ push(Operand(esp, 0)); |
2650 __ mov(Operand(esp, kPointerSize), eax); | 2627 __ mov(Operand(esp, kPointerSize), eax); |
2651 | 2628 |
2652 // Load the arguments. | 2629 EmitCall(expr, CallIC::METHOD); |
2653 { PreservePositionScope scope(masm()->positions_recorder()); | |
2654 for (int i = 0; i < arg_count; i++) { | |
2655 VisitForStackValue(args->at(i)); | |
2656 } | |
2657 } | |
2658 | |
2659 // Record source position of the IC call. | |
2660 SetSourcePosition(expr->position()); | |
2661 CallFunctionStub stub(arg_count, CALL_AS_METHOD); | |
2662 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | |
2663 __ CallStub(&stub); | |
2664 RecordJSReturnSite(expr); | |
2665 | |
2666 // Restore context register. | |
2667 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2668 | |
2669 context()->DropAndPlug(1, eax); | |
2670 } | 2630 } |
2671 | 2631 |
2672 | 2632 |
2673 void FullCodeGenerator::EmitCallWithStub(Call* expr) { | 2633 void FullCodeGenerator::EmitCall(Call* expr, CallIC::CallType call_type) { |
2674 // Code common for calls using the call stub. | 2634 // Load the arguments. |
2675 ZoneList<Expression*>* args = expr->arguments(); | 2635 ZoneList<Expression*>* args = expr->arguments(); |
2676 int arg_count = args->length(); | 2636 int arg_count = args->length(); |
2677 { PreservePositionScope scope(masm()->positions_recorder()); | 2637 { PreservePositionScope scope(masm()->positions_recorder()); |
2678 for (int i = 0; i < arg_count; i++) { | 2638 for (int i = 0; i < arg_count; i++) { |
2679 VisitForStackValue(args->at(i)); | 2639 VisitForStackValue(args->at(i)); |
2680 } | 2640 } |
2681 } | 2641 } |
2682 // Record source position for debugger. | 2642 |
| 2643 // Record source position of the IC call. |
2683 SetSourcePosition(expr->position()); | 2644 SetSourcePosition(expr->position()); |
2684 | 2645 Handle<Code> ic = CallIC::initialize_stub( |
2685 __ LoadHeapObject(ebx, FeedbackVector()); | 2646 isolate(), arg_count, call_type); |
2686 __ mov(edx, Immediate(Smi::FromInt(expr->CallFeedbackSlot()))); | 2647 __ mov(edx, Immediate(Smi::FromInt(expr->CallFeedbackSlot()))); |
2687 | |
2688 // Record call targets in unoptimized code. | |
2689 CallFunctionStub stub(arg_count, RECORD_CALL_TARGET); | |
2690 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | 2648 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
2691 __ CallStub(&stub); | 2649 // Don't assign a type feedback id to the IC, since type feedback is provided |
| 2650 // by the vector above. |
| 2651 CallIC(ic); |
2692 | 2652 |
2693 RecordJSReturnSite(expr); | 2653 RecordJSReturnSite(expr); |
| 2654 |
2694 // Restore context register. | 2655 // Restore context register. |
2695 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 2656 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2657 |
2696 context()->DropAndPlug(1, eax); | 2658 context()->DropAndPlug(1, eax); |
2697 } | 2659 } |
2698 | 2660 |
2699 | 2661 |
2700 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { | 2662 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
2701 // Push copy of the first argument or undefined if it doesn't exist. | 2663 // Push copy of the first argument or undefined if it doesn't exist. |
2702 if (arg_count > 0) { | 2664 if (arg_count > 0) { |
2703 __ push(Operand(esp, arg_count * kPointerSize)); | 2665 __ push(Operand(esp, arg_count * kPointerSize)); |
2704 } else { | 2666 } else { |
2705 __ push(Immediate(isolate()->factory()->undefined_value())); | 2667 __ push(Immediate(isolate()->factory()->undefined_value())); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2758 SetSourcePosition(expr->position()); | 2720 SetSourcePosition(expr->position()); |
2759 CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); | 2721 CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); |
2760 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | 2722 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
2761 __ CallStub(&stub); | 2723 __ CallStub(&stub); |
2762 RecordJSReturnSite(expr); | 2724 RecordJSReturnSite(expr); |
2763 // Restore context register. | 2725 // Restore context register. |
2764 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 2726 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
2765 context()->DropAndPlug(1, eax); | 2727 context()->DropAndPlug(1, eax); |
2766 | 2728 |
2767 } else if (call_type == Call::GLOBAL_CALL) { | 2729 } else if (call_type == Call::GLOBAL_CALL) { |
2768 EmitCallWithIC(expr); | 2730 EmitCallWithLoadIC(expr); |
2769 | 2731 |
2770 } else if (call_type == Call::LOOKUP_SLOT_CALL) { | 2732 } else if (call_type == Call::LOOKUP_SLOT_CALL) { |
2771 // Call to a lookup slot (dynamically introduced variable). | 2733 // Call to a lookup slot (dynamically introduced variable). |
2772 VariableProxy* proxy = callee->AsVariableProxy(); | 2734 VariableProxy* proxy = callee->AsVariableProxy(); |
2773 Label slow, done; | 2735 Label slow, done; |
2774 { PreservePositionScope scope(masm()->positions_recorder()); | 2736 { PreservePositionScope scope(masm()->positions_recorder()); |
2775 // Generate code for loading from variables potentially shadowed by | 2737 // Generate code for loading from variables potentially shadowed by |
2776 // eval-introduced variables. | 2738 // eval-introduced variables. |
2777 EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); | 2739 EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); |
2778 } | 2740 } |
(...skipping 15 matching lines...) Expand all Loading... |
2794 // Push function. | 2756 // Push function. |
2795 __ push(eax); | 2757 __ push(eax); |
2796 // The receiver is implicitly the global receiver. Indicate this by | 2758 // The receiver is implicitly the global receiver. Indicate this by |
2797 // passing the hole to the call function stub. | 2759 // passing the hole to the call function stub. |
2798 __ push(Immediate(isolate()->factory()->undefined_value())); | 2760 __ push(Immediate(isolate()->factory()->undefined_value())); |
2799 __ bind(&call); | 2761 __ bind(&call); |
2800 } | 2762 } |
2801 | 2763 |
2802 // The receiver is either the global receiver or an object found by | 2764 // The receiver is either the global receiver or an object found by |
2803 // LoadContextSlot. | 2765 // LoadContextSlot. |
2804 EmitCallWithStub(expr); | 2766 EmitCall(expr); |
2805 | 2767 |
2806 } else if (call_type == Call::PROPERTY_CALL) { | 2768 } else if (call_type == Call::PROPERTY_CALL) { |
2807 Property* property = callee->AsProperty(); | 2769 Property* property = callee->AsProperty(); |
2808 { PreservePositionScope scope(masm()->positions_recorder()); | 2770 { PreservePositionScope scope(masm()->positions_recorder()); |
2809 VisitForStackValue(property->obj()); | 2771 VisitForStackValue(property->obj()); |
2810 } | 2772 } |
2811 if (property->key()->IsPropertyName()) { | 2773 if (property->key()->IsPropertyName()) { |
2812 EmitCallWithIC(expr); | 2774 EmitCallWithLoadIC(expr); |
2813 } else { | 2775 } else { |
2814 EmitKeyedCallWithIC(expr, property->key()); | 2776 EmitKeyedCallWithLoadIC(expr, property->key()); |
2815 } | 2777 } |
2816 | 2778 |
2817 } else { | 2779 } else { |
2818 ASSERT(call_type == Call::OTHER_CALL); | 2780 ASSERT(call_type == Call::OTHER_CALL); |
2819 // Call to an arbitrary expression not handled specially above. | 2781 // Call to an arbitrary expression not handled specially above. |
2820 { PreservePositionScope scope(masm()->positions_recorder()); | 2782 { PreservePositionScope scope(masm()->positions_recorder()); |
2821 VisitForStackValue(callee); | 2783 VisitForStackValue(callee); |
2822 } | 2784 } |
2823 __ push(Immediate(isolate()->factory()->undefined_value())); | 2785 __ push(Immediate(isolate()->factory()->undefined_value())); |
2824 // Emit function call. | 2786 // Emit function call. |
2825 EmitCallWithStub(expr); | 2787 EmitCall(expr); |
2826 } | 2788 } |
2827 | 2789 |
2828 #ifdef DEBUG | 2790 #ifdef DEBUG |
2829 // RecordJSReturnSite should have been called. | 2791 // RecordJSReturnSite should have been called. |
2830 ASSERT(expr->return_is_recorded_); | 2792 ASSERT(expr->return_is_recorded_); |
2831 #endif | 2793 #endif |
2832 } | 2794 } |
2833 | 2795 |
2834 | 2796 |
2835 void FullCodeGenerator::VisitCallNew(CallNew* expr) { | 2797 void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
(...skipping 25 matching lines...) Expand all Loading... |
2861 // Record call targets in unoptimized code. | 2823 // Record call targets in unoptimized code. |
2862 if (FLAG_pretenuring_call_new) { | 2824 if (FLAG_pretenuring_call_new) { |
2863 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); | 2825 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); |
2864 ASSERT(expr->AllocationSiteFeedbackSlot() == | 2826 ASSERT(expr->AllocationSiteFeedbackSlot() == |
2865 expr->CallNewFeedbackSlot() + 1); | 2827 expr->CallNewFeedbackSlot() + 1); |
2866 } | 2828 } |
2867 | 2829 |
2868 __ LoadHeapObject(ebx, FeedbackVector()); | 2830 __ LoadHeapObject(ebx, FeedbackVector()); |
2869 __ mov(edx, Immediate(Smi::FromInt(expr->CallNewFeedbackSlot()))); | 2831 __ mov(edx, Immediate(Smi::FromInt(expr->CallNewFeedbackSlot()))); |
2870 | 2832 |
2871 CallConstructStub stub(RECORD_CALL_TARGET); | 2833 CallConstructStub stub(RECORD_CONSTRUCTOR_TARGET); |
2872 __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); | 2834 __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); |
2873 PrepareForBailoutForId(expr->ReturnId(), TOS_REG); | 2835 PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
2874 context()->Plug(eax); | 2836 context()->Plug(eax); |
2875 } | 2837 } |
2876 | 2838 |
2877 | 2839 |
2878 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { | 2840 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
2879 ZoneList<Expression*>* args = expr->arguments(); | 2841 ZoneList<Expression*>* args = expr->arguments(); |
2880 ASSERT(args->length() == 1); | 2842 ASSERT(args->length() == 1); |
2881 | 2843 |
(...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4905 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4867 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4906 Assembler::target_address_at(call_target_address, | 4868 Assembler::target_address_at(call_target_address, |
4907 unoptimized_code)); | 4869 unoptimized_code)); |
4908 return OSR_AFTER_STACK_CHECK; | 4870 return OSR_AFTER_STACK_CHECK; |
4909 } | 4871 } |
4910 | 4872 |
4911 | 4873 |
4912 } } // namespace v8::internal | 4874 } } // namespace v8::internal |
4913 | 4875 |
4914 #endif // V8_TARGET_ARCH_IA32 | 4876 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |