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 |
33 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { | 50 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { |
34 memset(dispatch_table_, 0, sizeof(dispatch_table_)); | 51 memset(dispatch_table_, 0, sizeof(dispatch_table_)); |
35 } | 52 } |
36 | 53 |
37 void Interpreter::Initialize() { | 54 void Interpreter::Initialize() { |
38 if (IsDispatchTableInitialized()) return; | 55 if (IsDispatchTableInitialized()) return; |
39 Zone zone(isolate_->allocator()); | 56 Zone zone(isolate_->allocator()); |
40 HandleScope scope(isolate_); | 57 HandleScope scope(isolate_); |
41 | 58 |
42 if (FLAG_trace_ignition_dispatches) { | 59 if (FLAG_trace_ignition_dispatches) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 dispatch_table_[i] = reinterpret_cast<Code*>(code)->entry(); | 142 dispatch_table_[i] = reinterpret_cast<Code*>(code)->entry(); |
126 } | 143 } |
127 } | 144 } |
128 } | 145 } |
129 | 146 |
130 // static | 147 // static |
131 int Interpreter::InterruptBudget() { | 148 int Interpreter::InterruptBudget() { |
132 return FLAG_interrupt_budget * kCodeSizeMultiplier; | 149 return FLAG_interrupt_budget * kCodeSizeMultiplier; |
133 } | 150 } |
134 | 151 |
| 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(isolate()); |
| 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 |
135 bool Interpreter::MakeBytecode(CompilationInfo* info) { | 185 bool Interpreter::MakeBytecode(CompilationInfo* info) { |
136 RuntimeCallTimerScope runtimeTimer(info->isolate(), | 186 RuntimeCallTimerScope runtimeTimer(info->isolate(), |
137 &RuntimeCallStats::CompileIgnition); | 187 &RuntimeCallStats::CompileIgnition); |
138 TimerEventScope<TimerEventCompileIgnition> timer(info->isolate()); | 188 TimerEventScope<TimerEventCompileIgnition> timer(info->isolate()); |
139 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( | 189 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( |
140 info->isolate(), &tracing::TraceEventStatsTable::CompileIgnition); | 190 info->isolate(), &tracing::TraceEventStatsTable::CompileIgnition); |
141 | 191 |
142 if (FLAG_print_bytecode || FLAG_print_ast) { | 192 if (FLAG_print_bytecode || FLAG_print_ast) { |
143 OFStream os(stdout); | 193 OFStream os(stdout); |
144 std::unique_ptr<char[]> name = info->GetDebugName(); | 194 std::unique_ptr<char[]> name = info->GetDebugName(); |
145 os << "[generating bytecode for function: " << info->GetDebugName().get() | 195 os << "[generating bytecode for function: " << info->GetDebugName().get() |
146 << "]" << std::endl | 196 << "]" << std::endl |
147 << std::flush; | 197 << std::flush; |
148 } | 198 } |
149 | 199 |
150 #ifdef DEBUG | 200 #ifdef DEBUG |
151 if (info->parse_info() && FLAG_print_ast) { | 201 if (info->parse_info() && FLAG_print_ast) { |
152 OFStream os(stdout); | 202 OFStream os(stdout); |
153 os << "--- AST ---" << std::endl | 203 os << "--- AST ---" << std::endl |
154 << AstPrinter(info->isolate()).PrintProgram(info->literal()) << std::endl | 204 << AstPrinter(info->isolate()).PrintProgram(info->literal()) << std::endl |
155 << std::flush; | 205 << std::flush; |
156 } | 206 } |
157 #endif // DEBUG | 207 #endif // DEBUG |
158 | 208 |
159 BytecodeGenerator generator(info); | 209 InterpreterCompilationJob job(info); |
160 Handle<BytecodeArray> bytecodes = generator.MakeBytecode(info->isolate()); | 210 if (job.PrepareJob() != CompilationJob::SUCCEEDED) return false; |
161 | 211 if (job.ExecuteJob() != CompilationJob::SUCCEEDED) return false; |
162 if (generator.HasStackOverflow()) return false; | 212 return job.FinalizeJob() == CompilationJob::SUCCEEDED; |
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; | |
173 } | 213 } |
174 | 214 |
175 bool Interpreter::IsDispatchTableInitialized() { | 215 bool Interpreter::IsDispatchTableInitialized() { |
176 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen || | 216 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen || |
177 FLAG_trace_ignition_dispatches) { | 217 FLAG_trace_ignition_dispatches) { |
178 // Regenerate table to add bytecode tracing operations, print the assembly | 218 // Regenerate table to add bytecode tracing operations, print the assembly |
179 // code generated by TurboFan or instrument handlers with dispatch counters. | 219 // code generated by TurboFan or instrument handlers with dispatch counters. |
180 return false; | 220 return false; |
181 } | 221 } |
182 return dispatch_table_[0] != nullptr; | 222 return dispatch_table_[0] != nullptr; |
(...skipping 2081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2264 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 2304 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
2265 __ SmiTag(new_state)); | 2305 __ SmiTag(new_state)); |
2266 __ SetAccumulator(old_state); | 2306 __ SetAccumulator(old_state); |
2267 | 2307 |
2268 __ Dispatch(); | 2308 __ Dispatch(); |
2269 } | 2309 } |
2270 | 2310 |
2271 } // namespace interpreter | 2311 } // namespace interpreter |
2272 } // namespace internal | 2312 } // namespace internal |
2273 } // namespace v8 | 2313 } // namespace v8 |
OLD | NEW |