OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/interpreter/interpreter.h" | 5 #include "src/interpreter/interpreter.h" |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 class InterpreterCompilationJob final : public CompilationJob { | 34 class InterpreterCompilationJob final : public CompilationJob { |
35 public: | 35 public: |
36 InterpreterCompilationJob(CompilationInfo* info, LazyCompilationMode mode); | 36 InterpreterCompilationJob(CompilationInfo* info, LazyCompilationMode mode); |
37 | 37 |
38 protected: | 38 protected: |
39 Status PrepareJobImpl() final; | 39 Status PrepareJobImpl() final; |
40 Status ExecuteJobImpl() final; | 40 Status ExecuteJobImpl() final; |
41 Status FinalizeJobImpl() final; | 41 Status FinalizeJobImpl() final; |
42 | 42 |
43 private: | 43 private: |
44 class TimerScope final { | |
45 public: | |
46 TimerScope(RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) | |
47 : stats_(stats) { | |
48 if (V8_UNLIKELY(FLAG_runtime_stats)) { | |
49 RuntimeCallStats::Enter(stats_, &timer_, counter_id); | |
50 } | |
51 } | |
52 | |
53 explicit TimerScope(RuntimeCallCounter* counter) : stats_(nullptr) { | |
54 if (V8_UNLIKELY(FLAG_runtime_stats)) { | |
55 timer_.Start(counter, nullptr); | |
56 } | |
57 } | |
58 | |
59 ~TimerScope() { | |
60 if (V8_UNLIKELY(FLAG_runtime_stats)) { | |
61 if (stats_) { | |
62 RuntimeCallStats::Leave(stats_, &timer_); | |
63 } else { | |
64 timer_.Stop(); | |
65 } | |
66 } | |
67 } | |
68 | |
69 private: | |
70 RuntimeCallStats* stats_; | |
71 RuntimeCallTimer timer_; | |
72 }; | |
73 | |
74 BytecodeGenerator* generator() { return &generator_; } | 44 BytecodeGenerator* generator() { return &generator_; } |
75 | 45 |
76 BytecodeGenerator generator_; | 46 BytecodeGenerator generator_; |
77 RuntimeCallStats* runtime_call_stats_; | |
78 RuntimeCallCounter background_execute_counter_; | |
79 | 47 |
80 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); | 48 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); |
81 }; | 49 }; |
82 | 50 |
83 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { | 51 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { |
84 memset(dispatch_table_, 0, sizeof(dispatch_table_)); | 52 memset(dispatch_table_, 0, sizeof(dispatch_table_)); |
85 } | 53 } |
86 | 54 |
87 void Interpreter::Initialize() { | 55 void Interpreter::Initialize() { |
88 if (!ShouldInitializeDispatchTable()) return; | 56 if (!ShouldInitializeDispatchTable()) return; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 155 } |
188 | 156 |
189 // static | 157 // static |
190 int Interpreter::InterruptBudget() { | 158 int Interpreter::InterruptBudget() { |
191 return FLAG_interrupt_budget * kCodeSizeMultiplier; | 159 return FLAG_interrupt_budget * kCodeSizeMultiplier; |
192 } | 160 } |
193 | 161 |
194 InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info, | 162 InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info, |
195 LazyCompilationMode mode) | 163 LazyCompilationMode mode) |
196 : CompilationJob(info->isolate(), info, "Ignition"), | 164 : CompilationJob(info->isolate(), info, "Ignition"), |
197 generator_(info, mode), | 165 generator_(info, mode) {} |
198 runtime_call_stats_(info->isolate()->counters()->runtime_call_stats()), | |
199 background_execute_counter_("CompileBackgroundIgnition") {} | |
200 | 166 |
201 InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { | 167 InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { |
202 CodeGenerator::MakeCodePrologue(info(), "interpreter"); | 168 CodeGenerator::MakeCodePrologue(info(), "interpreter"); |
203 if (FLAG_print_bytecode) { | 169 if (FLAG_print_bytecode) { |
204 OFStream os(stdout); | 170 OFStream os(stdout); |
205 std::unique_ptr<char[]> name = info()->GetDebugName(); | 171 std::unique_ptr<char[]> name = info()->GetDebugName(); |
206 os << "[generating bytecode for function: " << info()->GetDebugName().get() | 172 os << "[generating bytecode for function: " << info()->GetDebugName().get() |
207 << "]" << std::endl | 173 << "]" << std::endl |
208 << std::flush; | 174 << std::flush; |
209 } | 175 } |
210 | 176 |
211 return SUCCEEDED; | 177 return SUCCEEDED; |
212 } | 178 } |
213 | 179 |
214 InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() { | 180 InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() { |
215 TimerScope runtimeTimer = | 181 // TODO(5203): These timers aren't thread safe, move to using the CompilerJob |
216 executed_on_background_thread() | 182 // timers. |
217 ? TimerScope(&background_execute_counter_) | 183 RuntimeCallTimerScope runtimeTimer(info()->isolate(), |
218 : TimerScope(runtime_call_stats_, &RuntimeCallStats::CompileIgnition); | 184 &RuntimeCallStats::CompileIgnition); |
219 // TODO(lpy): add support for background compilation RCS trace. | 185 TimerEventScope<TimerEventCompileIgnition> timer(info()->isolate()); |
220 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileIgnition"); | 186 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileIgnition"); |
221 | 187 |
222 generator()->GenerateBytecode(stack_limit()); | 188 generator()->GenerateBytecode(stack_limit()); |
223 | 189 |
224 if (generator()->HasStackOverflow()) { | 190 if (generator()->HasStackOverflow()) { |
225 return FAILED; | 191 return FAILED; |
226 } | 192 } |
227 return SUCCEEDED; | 193 return SUCCEEDED; |
228 } | 194 } |
229 | 195 |
230 InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() { | 196 InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() { |
231 // Add background runtime call stats. | |
232 if (V8_UNLIKELY(FLAG_runtime_stats && executed_on_background_thread())) { | |
233 runtime_call_stats_->CompileBackgroundIgnition.Add( | |
234 &background_execute_counter_); | |
235 } | |
236 | |
237 RuntimeCallTimerScope runtimeTimer( | |
238 runtime_call_stats_, &RuntimeCallStats::CompileIgnitionFinalization); | |
239 | |
240 Handle<BytecodeArray> bytecodes = generator()->FinalizeBytecode(isolate()); | 197 Handle<BytecodeArray> bytecodes = generator()->FinalizeBytecode(isolate()); |
241 if (generator()->HasStackOverflow()) { | 198 if (generator()->HasStackOverflow()) { |
242 return FAILED; | 199 return FAILED; |
243 } | 200 } |
244 | 201 |
245 if (FLAG_print_bytecode) { | 202 if (FLAG_print_bytecode) { |
246 OFStream os(stdout); | 203 OFStream os(stdout); |
247 bytecodes->Print(os); | 204 bytecodes->Print(os); |
248 os << std::flush; | 205 os << std::flush; |
249 } | 206 } |
(...skipping 3002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3252 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 3209 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
3253 __ SmiTag(new_state)); | 3210 __ SmiTag(new_state)); |
3254 __ SetAccumulator(old_state); | 3211 __ SetAccumulator(old_state); |
3255 | 3212 |
3256 __ Dispatch(); | 3213 __ Dispatch(); |
3257 } | 3214 } |
3258 | 3215 |
3259 } // namespace interpreter | 3216 } // namespace interpreter |
3260 } // namespace internal | 3217 } // namespace internal |
3261 } // namespace v8 | 3218 } // namespace v8 |
OLD | NEW |