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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // o esi: our context | 111 // o esi: our context |
112 // o ebp: our caller's frame pointer | 112 // o ebp: our caller's frame pointer |
113 // o esp: stack pointer (pointing to return address) | 113 // o esp: stack pointer (pointing to return address) |
114 // | 114 // |
115 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 115 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
116 // frames-ia32.h for its layout. | 116 // frames-ia32.h for its layout. |
117 void FullCodeGenerator::Generate() { | 117 void FullCodeGenerator::Generate() { |
118 CompilationInfo* info = info_; | 118 CompilationInfo* info = info_; |
119 handler_table_ = | 119 handler_table_ = |
120 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); | 120 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
| 121 feedback_wrapper_.Initialize(isolate(), |
| 122 function()->minimum_feedback_slots(), |
| 123 function()->maximum_feedback_slots()); |
121 profiling_counter_ = isolate()->factory()->NewCell( | 124 profiling_counter_ = isolate()->factory()->NewCell( |
122 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); | 125 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
123 SetFunctionPosition(function()); | 126 SetFunctionPosition(function()); |
124 Comment cmnt(masm_, "[ function compiled by full code generator"); | 127 Comment cmnt(masm_, "[ function compiled by full code generator"); |
125 | 128 |
126 ProfileEntryHookStub::MaybeCallEntryHook(masm_); | 129 ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
127 | 130 |
128 #ifdef DEBUG | 131 #ifdef DEBUG |
129 if (strlen(FLAG_stop_at) > 0 && | 132 if (strlen(FLAG_stop_at) > 0 && |
130 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { | 133 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 ASSERT(loop_depth() == 0); | 298 ASSERT(loop_depth() == 0); |
296 } | 299 } |
297 } | 300 } |
298 | 301 |
299 // Always emit a 'return undefined' in case control fell off the end of | 302 // Always emit a 'return undefined' in case control fell off the end of |
300 // the body. | 303 // the body. |
301 { Comment cmnt(masm_, "[ return <undefined>;"); | 304 { Comment cmnt(masm_, "[ return <undefined>;"); |
302 __ mov(eax, isolate()->factory()->undefined_value()); | 305 __ mov(eax, isolate()->factory()->undefined_value()); |
303 EmitReturnSequence(); | 306 EmitReturnSequence(); |
304 } | 307 } |
| 308 |
| 309 feedback_wrapper_.Finalize(isolate()); |
305 } | 310 } |
306 | 311 |
307 | 312 |
308 void FullCodeGenerator::ClearAccumulator() { | 313 void FullCodeGenerator::ClearAccumulator() { |
309 __ Set(eax, Immediate(Smi::FromInt(0))); | 314 __ Set(eax, Immediate(Smi::FromInt(0))); |
310 } | 315 } |
311 | 316 |
312 | 317 |
313 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { | 318 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
314 __ mov(ebx, Immediate(profiling_counter_)); | 319 __ mov(ebx, Immediate(profiling_counter_)); |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 VisitStatements(clause->statements()); | 1017 VisitStatements(clause->statements()); |
1013 } | 1018 } |
1014 | 1019 |
1015 __ bind(nested_statement.break_label()); | 1020 __ bind(nested_statement.break_label()); |
1016 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | 1021 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
1017 } | 1022 } |
1018 | 1023 |
1019 | 1024 |
1020 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { | 1025 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
1021 Comment cmnt(masm_, "[ ForInStatement"); | 1026 Comment cmnt(masm_, "[ ForInStatement"); |
| 1027 feedback_wrapper_.Visit(isolate(), stmt); |
| 1028 int slot = stmt->ForInFeedbackSlot(); |
| 1029 |
1022 SetStatementPosition(stmt); | 1030 SetStatementPosition(stmt); |
1023 | 1031 |
1024 Label loop, exit; | 1032 Label loop, exit; |
1025 ForIn loop_statement(this, stmt); | 1033 ForIn loop_statement(this, stmt); |
1026 increment_loop_depth(); | 1034 increment_loop_depth(); |
1027 | 1035 |
1028 // Get the object to enumerate over. If the object is null or undefined, skip | 1036 // Get the object to enumerate over. If the object is null or undefined, skip |
1029 // over the loop. See ECMA-262 version 5, section 12.6.4. | 1037 // over the loop. See ECMA-262 version 5, section 12.6.4. |
1030 VisitForAccumulatorValue(stmt->enumerable()); | 1038 VisitForAccumulatorValue(stmt->enumerable()); |
1031 __ cmp(eax, isolate()->factory()->undefined_value()); | 1039 __ cmp(eax, isolate()->factory()->undefined_value()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 __ jmp(&loop); | 1098 __ jmp(&loop); |
1091 | 1099 |
1092 __ bind(&no_descriptors); | 1100 __ bind(&no_descriptors); |
1093 __ add(esp, Immediate(kPointerSize)); | 1101 __ add(esp, Immediate(kPointerSize)); |
1094 __ jmp(&exit); | 1102 __ jmp(&exit); |
1095 | 1103 |
1096 // We got a fixed array in register eax. Iterate through that. | 1104 // We got a fixed array in register eax. Iterate through that. |
1097 Label non_proxy; | 1105 Label non_proxy; |
1098 __ bind(&fixed_array); | 1106 __ bind(&fixed_array); |
1099 | 1107 |
1100 Handle<Cell> cell = isolate()->factory()->NewCell( | 1108 Handle<Object> feedback = Handle<Object>( |
1101 Handle<Object>(Smi::FromInt(TypeFeedbackCells::kForInFastCaseMarker), | 1109 Smi::FromInt(TypeFeedbackInfo::kForInFastCaseMarker), |
1102 isolate())); | 1110 isolate()); |
1103 RecordTypeFeedbackCell(stmt->ForInFeedbackId(), cell); | 1111 StoreFeedbackVectorSlot(slot, feedback); |
1104 __ LoadHeapObject(ebx, cell); | 1112 |
1105 __ mov(FieldOperand(ebx, Cell::kValueOffset), | 1113 // No need for a write barrier, we are storing a Smi in the feedback vector. |
1106 Immediate(Smi::FromInt(TypeFeedbackCells::kForInSlowCaseMarker))); | 1114 __ LoadHeapObject(ebx, FeedbackVector()); |
| 1115 __ mov(FieldOperand(ebx, FixedArray::OffsetOfElementAt(slot)), |
| 1116 Immediate(Smi::FromInt(TypeFeedbackInfo::kForInSlowCaseMarker))); |
1107 | 1117 |
1108 __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check | 1118 __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check |
1109 __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object | 1119 __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object |
1110 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); | 1120 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
1111 __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); | 1121 __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); |
1112 __ j(above, &non_proxy); | 1122 __ j(above, &non_proxy); |
1113 __ Set(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy | 1123 __ Set(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy |
1114 __ bind(&non_proxy); | 1124 __ bind(&non_proxy); |
1115 __ push(ebx); // Smi | 1125 __ push(ebx); // Smi |
1116 __ push(eax); // Array | 1126 __ push(eax); // Array |
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2619 int arg_count = args->length(); | 2629 int arg_count = args->length(); |
2620 { PreservePositionScope scope(masm()->positions_recorder()); | 2630 { PreservePositionScope scope(masm()->positions_recorder()); |
2621 for (int i = 0; i < arg_count; i++) { | 2631 for (int i = 0; i < arg_count; i++) { |
2622 VisitForStackValue(args->at(i)); | 2632 VisitForStackValue(args->at(i)); |
2623 } | 2633 } |
2624 } | 2634 } |
2625 // Record source position for debugger. | 2635 // Record source position for debugger. |
2626 SetSourcePosition(expr->position()); | 2636 SetSourcePosition(expr->position()); |
2627 | 2637 |
2628 Handle<Object> uninitialized = | 2638 Handle<Object> uninitialized = |
2629 TypeFeedbackCells::UninitializedSentinel(isolate()); | 2639 TypeFeedbackInfo::UninitializedSentinel(isolate()); |
2630 Handle<Cell> cell = isolate()->factory()->NewCell(uninitialized); | 2640 StoreFeedbackVectorSlot(expr->CallFeedbackSlot(), uninitialized); |
2631 RecordTypeFeedbackCell(expr->CallFeedbackId(), cell); | 2641 __ LoadHeapObject(ebx, FeedbackVector()); |
2632 __ mov(ebx, cell); | 2642 __ mov(edx, Immediate(Smi::FromInt(expr->CallFeedbackSlot()))); |
2633 | 2643 |
2634 // Record call targets in unoptimized code. | 2644 // Record call targets in unoptimized code. |
2635 CallFunctionStub stub(arg_count, RECORD_CALL_TARGET); | 2645 CallFunctionStub stub(arg_count, RECORD_CALL_TARGET); |
2636 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | 2646 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
2637 __ CallStub(&stub, expr->CallFeedbackId()); | 2647 __ CallStub(&stub, expr->CallFeedbackId()); |
2638 | 2648 |
2639 RecordJSReturnSite(expr); | 2649 RecordJSReturnSite(expr); |
2640 // Restore context register. | 2650 // Restore context register. |
2641 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 2651 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
2642 context()->DropAndPlug(1, eax); | 2652 context()->DropAndPlug(1, eax); |
(...skipping 22 matching lines...) Expand all Loading... |
2665 | 2675 |
2666 | 2676 |
2667 void FullCodeGenerator::VisitCall(Call* expr) { | 2677 void FullCodeGenerator::VisitCall(Call* expr) { |
2668 #ifdef DEBUG | 2678 #ifdef DEBUG |
2669 // We want to verify that RecordJSReturnSite gets called on all paths | 2679 // We want to verify that RecordJSReturnSite gets called on all paths |
2670 // through this function. Avoid early returns. | 2680 // through this function. Avoid early returns. |
2671 expr->return_is_recorded_ = false; | 2681 expr->return_is_recorded_ = false; |
2672 #endif | 2682 #endif |
2673 | 2683 |
2674 Comment cmnt(masm_, "[ Call"); | 2684 Comment cmnt(masm_, "[ Call"); |
| 2685 feedback_wrapper_.Visit(isolate(), expr); |
| 2686 |
2675 Expression* callee = expr->expression(); | 2687 Expression* callee = expr->expression(); |
2676 Call::CallType call_type = expr->GetCallType(isolate()); | 2688 Call::CallType call_type = expr->GetCallType(isolate()); |
2677 | 2689 |
2678 if (call_type == Call::POSSIBLY_EVAL_CALL) { | 2690 if (call_type == Call::POSSIBLY_EVAL_CALL) { |
2679 // In a call to eval, we first call %ResolvePossiblyDirectEval to | 2691 // In a call to eval, we first call %ResolvePossiblyDirectEval to |
2680 // resolve the function we need to call and the receiver of the call. | 2692 // resolve the function we need to call and the receiver of the call. |
2681 // Then we call the resolved function using the given arguments. | 2693 // Then we call the resolved function using the given arguments. |
2682 ZoneList<Expression*>* args = expr->arguments(); | 2694 ZoneList<Expression*>* args = expr->arguments(); |
2683 int arg_count = args->length(); | 2695 int arg_count = args->length(); |
2684 { PreservePositionScope pos_scope(masm()->positions_recorder()); | 2696 { PreservePositionScope pos_scope(masm()->positions_recorder()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2777 | 2789 |
2778 #ifdef DEBUG | 2790 #ifdef DEBUG |
2779 // RecordJSReturnSite should have been called. | 2791 // RecordJSReturnSite should have been called. |
2780 ASSERT(expr->return_is_recorded_); | 2792 ASSERT(expr->return_is_recorded_); |
2781 #endif | 2793 #endif |
2782 } | 2794 } |
2783 | 2795 |
2784 | 2796 |
2785 void FullCodeGenerator::VisitCallNew(CallNew* expr) { | 2797 void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
2786 Comment cmnt(masm_, "[ CallNew"); | 2798 Comment cmnt(masm_, "[ CallNew"); |
| 2799 feedback_wrapper_.Visit(isolate(), expr); |
| 2800 |
2787 // According to ECMA-262, section 11.2.2, page 44, the function | 2801 // According to ECMA-262, section 11.2.2, page 44, the function |
2788 // expression in new calls must be evaluated before the | 2802 // expression in new calls must be evaluated before the |
2789 // arguments. | 2803 // arguments. |
2790 | 2804 |
2791 // Push constructor on the stack. If it's not a function it's used as | 2805 // Push constructor on the stack. If it's not a function it's used as |
2792 // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is | 2806 // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
2793 // ignored. | 2807 // ignored. |
2794 VisitForStackValue(expr->expression()); | 2808 VisitForStackValue(expr->expression()); |
2795 | 2809 |
2796 // Push the arguments ("left-to-right") on the stack. | 2810 // Push the arguments ("left-to-right") on the stack. |
2797 ZoneList<Expression*>* args = expr->arguments(); | 2811 ZoneList<Expression*>* args = expr->arguments(); |
2798 int arg_count = args->length(); | 2812 int arg_count = args->length(); |
2799 for (int i = 0; i < arg_count; i++) { | 2813 for (int i = 0; i < arg_count; i++) { |
2800 VisitForStackValue(args->at(i)); | 2814 VisitForStackValue(args->at(i)); |
2801 } | 2815 } |
2802 | 2816 |
2803 // Call the construct call builtin that handles allocation and | 2817 // Call the construct call builtin that handles allocation and |
2804 // constructor invocation. | 2818 // constructor invocation. |
2805 SetSourcePosition(expr->position()); | 2819 SetSourcePosition(expr->position()); |
2806 | 2820 |
2807 // Load function and argument count into edi and eax. | 2821 // Load function and argument count into edi and eax. |
2808 __ Set(eax, Immediate(arg_count)); | 2822 __ Set(eax, Immediate(arg_count)); |
2809 __ mov(edi, Operand(esp, arg_count * kPointerSize)); | 2823 __ mov(edi, Operand(esp, arg_count * kPointerSize)); |
2810 | 2824 |
2811 // Record call targets in unoptimized code. | 2825 // Record call targets in unoptimized code. |
2812 Handle<Object> uninitialized = | 2826 Handle<Object> uninitialized = |
2813 TypeFeedbackCells::UninitializedSentinel(isolate()); | 2827 TypeFeedbackInfo::UninitializedSentinel(isolate()); |
2814 Handle<Cell> cell = isolate()->factory()->NewCell(uninitialized); | 2828 StoreFeedbackVectorSlot(expr->CallNewFeedbackSlot(), uninitialized); |
2815 RecordTypeFeedbackCell(expr->CallNewFeedbackId(), cell); | 2829 __ LoadHeapObject(ebx, FeedbackVector()); |
2816 __ mov(ebx, cell); | 2830 __ mov(edx, Immediate(Smi::FromInt(expr->CallNewFeedbackSlot()))); |
2817 | 2831 |
2818 CallConstructStub stub(RECORD_CALL_TARGET); | 2832 CallConstructStub stub(RECORD_CALL_TARGET); |
2819 __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); | 2833 __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); |
2820 PrepareForBailoutForId(expr->ReturnId(), TOS_REG); | 2834 PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
2821 context()->Plug(eax); | 2835 context()->Plug(eax); |
2822 } | 2836 } |
2823 | 2837 |
2824 | 2838 |
2825 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { | 2839 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
2826 ZoneList<Expression*>* args = expr->arguments(); | 2840 ZoneList<Expression*>* args = expr->arguments(); |
(...skipping 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4901 | 4915 |
4902 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4916 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4903 Assembler::target_address_at(call_target_address)); | 4917 Assembler::target_address_at(call_target_address)); |
4904 return OSR_AFTER_STACK_CHECK; | 4918 return OSR_AFTER_STACK_CHECK; |
4905 } | 4919 } |
4906 | 4920 |
4907 | 4921 |
4908 } } // namespace v8::internal | 4922 } } // namespace v8::internal |
4909 | 4923 |
4910 #endif // V8_TARGET_ARCH_IA32 | 4924 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |