| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 MacroAssembler* masm_; | 95 MacroAssembler* masm_; |
| 96 Label patch_site_; | 96 Label patch_site_; |
| 97 #ifdef DEBUG | 97 #ifdef DEBUG |
| 98 bool info_emitted_; | 98 bool info_emitted_; |
| 99 #endif | 99 #endif |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 | 102 |
| 103 int FullCodeGenerator::self_optimization_header_size() { |
| 104 return 13; |
| 105 } |
| 106 |
| 107 |
| 103 // Generate code for a JS function. On entry to the function the receiver | 108 // Generate code for a JS function. On entry to the function the receiver |
| 104 // and arguments have been pushed on the stack left to right, with the | 109 // and arguments have been pushed on the stack left to right, with the |
| 105 // return address on top of them. The actual argument count matches the | 110 // return address on top of them. The actual argument count matches the |
| 106 // formal parameter count expected by the function. | 111 // formal parameter count expected by the function. |
| 107 // | 112 // |
| 108 // The live registers are: | 113 // The live registers are: |
| 109 // o edi: the JS function object being called (i.e. ourselves) | 114 // o edi: the JS function object being called (i.e. ourselves) |
| 110 // o esi: our context | 115 // o esi: our context |
| 111 // o ebp: our caller's frame pointer | 116 // o ebp: our caller's frame pointer |
| 112 // o esp: stack pointer (pointing to return address) | 117 // o esp: stack pointer (pointing to return address) |
| 113 // | 118 // |
| 114 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 119 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 115 // frames-ia32.h for its layout. | 120 // frames-ia32.h for its layout. |
| 116 void FullCodeGenerator::Generate() { | 121 void FullCodeGenerator::Generate() { |
| 117 CompilationInfo* info = info_; | 122 CompilationInfo* info = info_; |
| 118 handler_table_ = | 123 handler_table_ = |
| 119 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); | 124 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
| 120 profiling_counter_ = isolate()->factory()->NewJSGlobalPropertyCell( | 125 profiling_counter_ = isolate()->factory()->NewJSGlobalPropertyCell( |
| 121 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget))); | 126 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget))); |
| 122 SetFunctionPosition(function()); | 127 SetFunctionPosition(function()); |
| 123 Comment cmnt(masm_, "[ function compiled by full code generator"); | 128 Comment cmnt(masm_, "[ function compiled by full code generator"); |
| 124 | 129 |
| 125 #ifdef DEBUG | |
| 126 if (strlen(FLAG_stop_at) > 0 && | |
| 127 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { | |
| 128 __ int3(); | |
| 129 } | |
| 130 #endif | |
| 131 | |
| 132 // We can optionally optimize based on counters rather than statistical | 130 // We can optionally optimize based on counters rather than statistical |
| 133 // sampling. | 131 // sampling. |
| 134 if (info->ShouldSelfOptimize()) { | 132 if (info->ShouldSelfOptimize()) { |
| 135 if (FLAG_trace_opt_verbose) { | 133 if (FLAG_trace_opt_verbose) { |
| 136 PrintF("[adding self-optimization header to %s]\n", | 134 PrintF("[adding self-optimization header to %s]\n", |
| 137 *info->function()->debug_name()->ToCString()); | 135 *info->function()->debug_name()->ToCString()); |
| 138 } | 136 } |
| 137 has_self_optimization_header_ = true; |
| 139 MaybeObject* maybe_cell = isolate()->heap()->AllocateJSGlobalPropertyCell( | 138 MaybeObject* maybe_cell = isolate()->heap()->AllocateJSGlobalPropertyCell( |
| 140 Smi::FromInt(Compiler::kCallsUntilPrimitiveOpt)); | 139 Smi::FromInt(Compiler::kCallsUntilPrimitiveOpt)); |
| 141 JSGlobalPropertyCell* cell; | 140 JSGlobalPropertyCell* cell; |
| 142 if (maybe_cell->To(&cell)) { | 141 if (maybe_cell->To(&cell)) { |
| 143 __ sub(Operand::Cell(Handle<JSGlobalPropertyCell>(cell)), | 142 __ sub(Operand::Cell(Handle<JSGlobalPropertyCell>(cell)), |
| 144 Immediate(Smi::FromInt(1))); | 143 Immediate(Smi::FromInt(1))); |
| 145 Handle<Code> compile_stub( | 144 Handle<Code> compile_stub( |
| 146 isolate()->builtins()->builtin(Builtins::kLazyRecompile)); | 145 isolate()->builtins()->builtin(Builtins::kLazyRecompile)); |
| 147 STATIC_ASSERT(kSmiTag == 0); | 146 STATIC_ASSERT(kSmiTag == 0); |
| 148 __ j(zero, compile_stub); | 147 __ j(zero, compile_stub); |
| 148 ASSERT(masm_->pc_offset() == self_optimization_header_size()); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 #ifdef DEBUG |
| 153 if (strlen(FLAG_stop_at) > 0 && |
| 154 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
| 155 __ int3(); |
| 156 } |
| 157 #endif |
| 158 |
| 152 // Strict mode functions and builtins need to replace the receiver | 159 // Strict mode functions and builtins need to replace the receiver |
| 153 // with undefined when called as functions (without an explicit | 160 // with undefined when called as functions (without an explicit |
| 154 // receiver object). ecx is zero for method calls and non-zero for | 161 // receiver object). ecx is zero for method calls and non-zero for |
| 155 // function calls. | 162 // function calls. |
| 156 if (!info->is_classic_mode() || info->is_native()) { | 163 if (!info->is_classic_mode() || info->is_native()) { |
| 157 Label ok; | 164 Label ok; |
| 158 __ test(ecx, ecx); | 165 __ test(ecx, ecx); |
| 159 __ j(zero, &ok, Label::kNear); | 166 __ j(zero, &ok, Label::kNear); |
| 160 // +1 for return address. | 167 // +1 for return address. |
| 161 int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; | 168 int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; |
| (...skipping 4256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4418 *context_length = 0; | 4425 *context_length = 0; |
| 4419 return previous_; | 4426 return previous_; |
| 4420 } | 4427 } |
| 4421 | 4428 |
| 4422 | 4429 |
| 4423 #undef __ | 4430 #undef __ |
| 4424 | 4431 |
| 4425 } } // namespace v8::internal | 4432 } } // namespace v8::internal |
| 4426 | 4433 |
| 4427 #endif // V8_TARGET_ARCH_IA32 | 4434 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |