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 12 matching lines...) Expand all Loading... |
23 namespace internal { | 23 namespace internal { |
24 namespace interpreter { | 24 namespace interpreter { |
25 | 25 |
26 using compiler::Node; | 26 using compiler::Node; |
27 typedef CodeStubAssembler::Label Label; | 27 typedef CodeStubAssembler::Label Label; |
28 typedef CodeStubAssembler::Variable Variable; | 28 typedef CodeStubAssembler::Variable Variable; |
29 typedef InterpreterAssembler::Arg Arg; | 29 typedef InterpreterAssembler::Arg Arg; |
30 | 30 |
31 #define __ assembler-> | 31 #define __ assembler-> |
32 | 32 |
33 class InterpreterCompilationJob final : public CompilationJob { | |
34 public: | |
35 explicit InterpreterCompilationJob(CompilationInfo* info); | |
36 | |
37 protected: | |
38 Status PrepareJobImpl() final; | |
39 Status ExecuteJobImpl() final; | |
40 Status FinalizeJobImpl() final; | |
41 | |
42 private: | |
43 BytecodeGenerator* generator() { return &generator_; } | |
44 | |
45 BytecodeGenerator generator_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); | |
48 }; | |
49 | |
50 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { | 33 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { |
51 memset(dispatch_table_, 0, sizeof(dispatch_table_)); | 34 memset(dispatch_table_, 0, sizeof(dispatch_table_)); |
52 } | 35 } |
53 | 36 |
54 void Interpreter::Initialize() { | 37 void Interpreter::Initialize() { |
55 if (IsDispatchTableInitialized()) return; | 38 if (IsDispatchTableInitialized()) return; |
56 Zone zone(isolate_->allocator()); | 39 Zone zone(isolate_->allocator()); |
57 HandleScope scope(isolate_); | 40 HandleScope scope(isolate_); |
58 | 41 |
59 if (FLAG_trace_ignition_dispatches) { | 42 if (FLAG_trace_ignition_dispatches) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 dispatch_table_[i] = reinterpret_cast<Code*>(code)->entry(); | 125 dispatch_table_[i] = reinterpret_cast<Code*>(code)->entry(); |
143 } | 126 } |
144 } | 127 } |
145 } | 128 } |
146 | 129 |
147 // static | 130 // static |
148 int Interpreter::InterruptBudget() { | 131 int Interpreter::InterruptBudget() { |
149 return FLAG_interrupt_budget * kCodeSizeMultiplier; | 132 return FLAG_interrupt_budget * kCodeSizeMultiplier; |
150 } | 133 } |
151 | 134 |
152 InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info) | |
153 : CompilationJob(info, "Ignition"), generator_(info) {} | |
154 | |
155 InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { | |
156 return SUCCEEDED; | |
157 } | |
158 | |
159 InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() { | |
160 generator()->GenerateBytecode(); | |
161 | |
162 if (generator()->HasStackOverflow()) { | |
163 return FAILED; | |
164 } | |
165 return SUCCEEDED; | |
166 } | |
167 | |
168 InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() { | |
169 Handle<BytecodeArray> bytecodes = generator()->FinalizeBytecode(); | |
170 if (generator()->HasStackOverflow()) { | |
171 return FAILED; | |
172 } | |
173 | |
174 if (FLAG_print_bytecode) { | |
175 OFStream os(stdout); | |
176 bytecodes->Print(os); | |
177 os << std::flush; | |
178 } | |
179 | |
180 info()->SetBytecodeArray(bytecodes); | |
181 info()->SetCode(info()->isolate()->builtins()->InterpreterEntryTrampoline()); | |
182 return SUCCEEDED; | |
183 } | |
184 | |
185 bool Interpreter::MakeBytecode(CompilationInfo* info) { | 135 bool Interpreter::MakeBytecode(CompilationInfo* info) { |
186 RuntimeCallTimerScope runtimeTimer(info->isolate(), | 136 RuntimeCallTimerScope runtimeTimer(info->isolate(), |
187 &RuntimeCallStats::CompileIgnition); | 137 &RuntimeCallStats::CompileIgnition); |
188 TimerEventScope<TimerEventCompileIgnition> timer(info->isolate()); | 138 TimerEventScope<TimerEventCompileIgnition> timer(info->isolate()); |
189 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( | 139 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( |
190 info->isolate(), &tracing::TraceEventStatsTable::CompileIgnition); | 140 info->isolate(), &tracing::TraceEventStatsTable::CompileIgnition); |
191 | 141 |
192 if (FLAG_print_bytecode || FLAG_print_ast) { | 142 if (FLAG_print_bytecode || FLAG_print_ast) { |
193 OFStream os(stdout); | 143 OFStream os(stdout); |
194 std::unique_ptr<char[]> name = info->GetDebugName(); | 144 std::unique_ptr<char[]> name = info->GetDebugName(); |
195 os << "[generating bytecode for function: " << info->GetDebugName().get() | 145 os << "[generating bytecode for function: " << info->GetDebugName().get() |
196 << "]" << std::endl | 146 << "]" << std::endl |
197 << std::flush; | 147 << std::flush; |
198 } | 148 } |
199 | 149 |
200 #ifdef DEBUG | 150 #ifdef DEBUG |
201 if (info->parse_info() && FLAG_print_ast) { | 151 if (info->parse_info() && FLAG_print_ast) { |
202 OFStream os(stdout); | 152 OFStream os(stdout); |
203 os << "--- AST ---" << std::endl | 153 os << "--- AST ---" << std::endl |
204 << AstPrinter(info->isolate()).PrintProgram(info->literal()) << std::endl | 154 << AstPrinter(info->isolate()).PrintProgram(info->literal()) << std::endl |
205 << std::flush; | 155 << std::flush; |
206 } | 156 } |
207 #endif // DEBUG | 157 #endif // DEBUG |
208 | 158 |
209 InterpreterCompilationJob job(info); | 159 BytecodeGenerator generator(info); |
210 if (job.PrepareJob() != CompilationJob::SUCCEEDED) return false; | 160 Handle<BytecodeArray> bytecodes = generator.MakeBytecode(); |
211 if (job.ExecuteJob() != CompilationJob::SUCCEEDED) return false; | 161 |
212 return job.FinalizeJob() == CompilationJob::SUCCEEDED; | 162 if (generator.HasStackOverflow()) return false; |
| 163 |
| 164 if (FLAG_print_bytecode) { |
| 165 OFStream os(stdout); |
| 166 bytecodes->Print(os); |
| 167 os << std::flush; |
| 168 } |
| 169 |
| 170 info->SetBytecodeArray(bytecodes); |
| 171 info->SetCode(info->isolate()->builtins()->InterpreterEntryTrampoline()); |
| 172 return true; |
213 } | 173 } |
214 | 174 |
215 bool Interpreter::IsDispatchTableInitialized() { | 175 bool Interpreter::IsDispatchTableInitialized() { |
216 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen || | 176 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen || |
217 FLAG_trace_ignition_dispatches) { | 177 FLAG_trace_ignition_dispatches) { |
218 // Regenerate table to add bytecode tracing operations, print the assembly | 178 // Regenerate table to add bytecode tracing operations, print the assembly |
219 // code generated by TurboFan or instrument handlers with dispatch counters. | 179 // code generated by TurboFan or instrument handlers with dispatch counters. |
220 return false; | 180 return false; |
221 } | 181 } |
222 return dispatch_table_[0] != nullptr; | 182 return dispatch_table_[0] != nullptr; |
(...skipping 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2276 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 2236 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
2277 __ SmiTag(new_state)); | 2237 __ SmiTag(new_state)); |
2278 __ SetAccumulator(old_state); | 2238 __ SetAccumulator(old_state); |
2279 | 2239 |
2280 __ Dispatch(); | 2240 __ Dispatch(); |
2281 } | 2241 } |
2282 | 2242 |
2283 } // namespace interpreter | 2243 } // namespace interpreter |
2284 } // namespace internal | 2244 } // namespace internal |
2285 } // namespace v8 | 2245 } // namespace v8 |
OLD | NEW |