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 |
44 BytecodeGenerator* generator() { return &generator_; } | 74 BytecodeGenerator* generator() { return &generator_; } |
45 | 75 |
46 BytecodeGenerator generator_; | 76 BytecodeGenerator generator_; |
| 77 RuntimeCallStats* runtime_call_stats_; |
| 78 RuntimeCallCounter background_execute_counter_; |
47 | 79 |
48 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); | 80 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); |
49 }; | 81 }; |
50 | 82 |
51 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { | 83 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { |
52 memset(dispatch_table_, 0, sizeof(dispatch_table_)); | 84 memset(dispatch_table_, 0, sizeof(dispatch_table_)); |
53 } | 85 } |
54 | 86 |
55 void Interpreter::Initialize() { | 87 void Interpreter::Initialize() { |
56 if (!ShouldInitializeDispatchTable()) return; | 88 if (!ShouldInitializeDispatchTable()) return; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 187 } |
156 | 188 |
157 // static | 189 // static |
158 int Interpreter::InterruptBudget() { | 190 int Interpreter::InterruptBudget() { |
159 return FLAG_interrupt_budget * kCodeSizeMultiplier; | 191 return FLAG_interrupt_budget * kCodeSizeMultiplier; |
160 } | 192 } |
161 | 193 |
162 InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info, | 194 InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info, |
163 LazyCompilationMode mode) | 195 LazyCompilationMode mode) |
164 : CompilationJob(info->isolate(), info, "Ignition"), | 196 : CompilationJob(info->isolate(), info, "Ignition"), |
165 generator_(info, mode) {} | 197 generator_(info, mode), |
| 198 runtime_call_stats_(info->isolate()->counters()->runtime_call_stats()), |
| 199 background_execute_counter_("CompileBackgroundIgnition") {} |
166 | 200 |
167 InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { | 201 InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { |
168 CodeGenerator::MakeCodePrologue(info(), "interpreter"); | 202 CodeGenerator::MakeCodePrologue(info(), "interpreter"); |
169 if (FLAG_print_bytecode) { | 203 if (FLAG_print_bytecode) { |
170 OFStream os(stdout); | 204 OFStream os(stdout); |
171 std::unique_ptr<char[]> name = info()->GetDebugName(); | 205 std::unique_ptr<char[]> name = info()->GetDebugName(); |
172 os << "[generating bytecode for function: " << info()->GetDebugName().get() | 206 os << "[generating bytecode for function: " << info()->GetDebugName().get() |
173 << "]" << std::endl | 207 << "]" << std::endl |
174 << std::flush; | 208 << std::flush; |
175 } | 209 } |
176 | 210 |
177 return SUCCEEDED; | 211 return SUCCEEDED; |
178 } | 212 } |
179 | 213 |
180 InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() { | 214 InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() { |
181 // TODO(5203): These timers aren't thread safe, move to using the CompilerJob | 215 TimerScope runtimeTimer = |
182 // timers. | 216 executed_on_background_thread() |
183 RuntimeCallTimerScope runtimeTimer(info()->isolate(), | 217 ? TimerScope(&background_execute_counter_) |
184 &RuntimeCallStats::CompileIgnition); | 218 : TimerScope(runtime_call_stats_, &RuntimeCallStats::CompileIgnition); |
185 TimerEventScope<TimerEventCompileIgnition> timer(info()->isolate()); | 219 // TODO(lpy): add support for background compilation RCS trace. |
186 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileIgnition"); | 220 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileIgnition"); |
187 | 221 |
188 generator()->GenerateBytecode(stack_limit()); | 222 generator()->GenerateBytecode(stack_limit()); |
189 | 223 |
190 if (generator()->HasStackOverflow()) { | 224 if (generator()->HasStackOverflow()) { |
191 return FAILED; | 225 return FAILED; |
192 } | 226 } |
193 return SUCCEEDED; | 227 return SUCCEEDED; |
194 } | 228 } |
195 | 229 |
196 InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() { | 230 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 |
197 Handle<BytecodeArray> bytecodes = generator()->FinalizeBytecode(isolate()); | 240 Handle<BytecodeArray> bytecodes = generator()->FinalizeBytecode(isolate()); |
198 if (generator()->HasStackOverflow()) { | 241 if (generator()->HasStackOverflow()) { |
199 return FAILED; | 242 return FAILED; |
200 } | 243 } |
201 | 244 |
202 if (FLAG_print_bytecode) { | 245 if (FLAG_print_bytecode) { |
203 OFStream os(stdout); | 246 OFStream os(stdout); |
204 bytecodes->Print(os); | 247 bytecodes->Print(os); |
205 os << std::flush; | 248 os << std::flush; |
206 } | 249 } |
(...skipping 3002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3209 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 3252 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
3210 __ SmiTag(new_state)); | 3253 __ SmiTag(new_state)); |
3211 __ SetAccumulator(old_state); | 3254 __ SetAccumulator(old_state); |
3212 | 3255 |
3213 __ Dispatch(); | 3256 __ Dispatch(); |
3214 } | 3257 } |
3215 | 3258 |
3216 } // namespace interpreter | 3259 } // namespace interpreter |
3217 } // namespace internal | 3260 } // namespace internal |
3218 } // namespace v8 | 3261 } // namespace v8 |
OLD | NEW |