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 #include <set> | |
9 | 10 |
11 #include "src/ast/ast-traversal-visitor.h" | |
10 #include "src/ast/prettyprinter.h" | 12 #include "src/ast/prettyprinter.h" |
11 #include "src/code-factory.h" | 13 #include "src/code-factory.h" |
12 #include "src/compilation-info.h" | 14 #include "src/compilation-info.h" |
13 #include "src/compiler.h" | 15 #include "src/compiler.h" |
14 #include "src/factory.h" | 16 #include "src/factory.h" |
15 #include "src/interpreter/bytecode-flags.h" | 17 #include "src/interpreter/bytecode-flags.h" |
16 #include "src/interpreter/bytecode-generator.h" | 18 #include "src/interpreter/bytecode-generator.h" |
17 #include "src/interpreter/bytecodes.h" | 19 #include "src/interpreter/bytecodes.h" |
18 #include "src/interpreter/interpreter-assembler.h" | 20 #include "src/interpreter/interpreter-assembler.h" |
19 #include "src/interpreter/interpreter-intrinsics.h" | 21 #include "src/interpreter/interpreter-intrinsics.h" |
20 #include "src/log.h" | 22 #include "src/log.h" |
23 #include "src/parsing/parse-info.h" | |
21 #include "src/zone/zone.h" | 24 #include "src/zone/zone.h" |
22 | 25 |
23 namespace v8 { | 26 namespace v8 { |
24 namespace internal { | 27 namespace internal { |
25 namespace interpreter { | 28 namespace interpreter { |
26 | 29 |
27 using compiler::Node; | 30 using compiler::Node; |
28 typedef CodeStubAssembler::Label Label; | 31 typedef CodeStubAssembler::Label Label; |
29 typedef CodeStubAssembler::Variable Variable; | 32 typedef CodeStubAssembler::Variable Variable; |
30 typedef InterpreterAssembler::Arg Arg; | 33 typedef InterpreterAssembler::Arg Arg; |
31 | 34 |
32 #define __ assembler-> | 35 #define __ assembler-> |
33 | 36 |
34 class InterpreterCompilationJob final : public CompilationJob { | 37 class InterpreterCompilationJob final : public CompilationJob { |
35 public: | 38 public: |
36 explicit InterpreterCompilationJob(CompilationInfo* info); | 39 InterpreterCompilationJob(CompilationInfo* info, |
40 ShouldCompile should_compile); | |
41 | |
42 InterpreterCompilationJob(std::unique_ptr<Zone> zone, | |
43 std::unique_ptr<ParseInfo> parse_info, | |
44 std::unique_ptr<CompilationInfo> info); | |
37 | 45 |
38 protected: | 46 protected: |
39 Status PrepareJobImpl() final; | 47 Status PrepareJobImpl() final; |
40 Status ExecuteJobImpl() final; | 48 Status ExecuteJobImpl() final; |
41 Status FinalizeJobImpl() final; | 49 Status FinalizeJobImpl() final; |
42 | 50 |
43 private: | 51 private: |
44 BytecodeGenerator* generator() { return &generator_; } | 52 BytecodeGenerator* generator() { return &generator_; } |
45 | 53 |
46 BytecodeGenerator generator_; | 54 BytecodeGenerator generator_; |
47 | 55 |
56 ShouldCompile should_compile_; | |
57 | |
58 std::unique_ptr<Zone> zone_; | |
59 std::unique_ptr<ParseInfo> parse_info_; | |
60 std::unique_ptr<CompilationInfo> info_; | |
61 | |
48 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); | 62 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); |
49 }; | 63 }; |
50 | 64 |
51 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { | 65 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { |
52 memset(dispatch_table_, 0, sizeof(dispatch_table_)); | 66 memset(dispatch_table_, 0, sizeof(dispatch_table_)); |
53 } | 67 } |
54 | 68 |
55 void Interpreter::Initialize() { | 69 void Interpreter::Initialize() { |
56 if (IsDispatchTableInitialized()) return; | 70 if (IsDispatchTableInitialized()) return; |
57 Zone zone(isolate_->allocator()); | 71 Zone zone(isolate_->allocator()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 dispatch_table_[i] = reinterpret_cast<Code*>(code)->entry(); | 157 dispatch_table_[i] = reinterpret_cast<Code*>(code)->entry(); |
144 } | 158 } |
145 } | 159 } |
146 } | 160 } |
147 | 161 |
148 // static | 162 // static |
149 int Interpreter::InterruptBudget() { | 163 int Interpreter::InterruptBudget() { |
150 return FLAG_interrupt_budget * kCodeSizeMultiplier; | 164 return FLAG_interrupt_budget * kCodeSizeMultiplier; |
151 } | 165 } |
152 | 166 |
153 InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info) | 167 InterpreterCompilationJob::InterpreterCompilationJob( |
154 : CompilationJob(info->isolate(), info, "Ignition"), generator_(info) {} | 168 CompilationInfo* info, ShouldCompile should_compile) |
169 : CompilationJob(info->isolate(), info, "Ignition"), | |
170 generator_(info), | |
171 should_compile_(should_compile) {} | |
172 | |
173 InterpreterCompilationJob::InterpreterCompilationJob( | |
174 std::unique_ptr<Zone> zone, std::unique_ptr<ParseInfo> parse_info, | |
175 std::unique_ptr<CompilationInfo> info) | |
176 : InterpreterCompilationJob(info.get(), ShouldCompile::kNever) { | |
177 zone_ = std::move(zone); | |
178 parse_info_ = std::move(parse_info); | |
179 info_ = std::move(info); | |
180 } | |
155 | 181 |
156 InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { | 182 InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { |
157 if (FLAG_print_bytecode || FLAG_print_ast) { | 183 if (FLAG_print_bytecode || FLAG_print_ast) { |
158 OFStream os(stdout); | 184 OFStream os(stdout); |
159 std::unique_ptr<char[]> name = info()->GetDebugName(); | 185 std::unique_ptr<char[]> name = info()->GetDebugName(); |
160 os << "[generating bytecode for function: " << info()->GetDebugName().get() | 186 os << "[generating bytecode for function: " << info()->GetDebugName().get() |
161 << "]" << std::endl | 187 << "]" << std::endl |
162 << std::flush; | 188 << std::flush; |
163 } | 189 } |
164 | 190 |
(...skipping 20 matching lines...) Expand all Loading... | |
185 | 211 |
186 generator()->GenerateBytecode(stack_limit()); | 212 generator()->GenerateBytecode(stack_limit()); |
187 | 213 |
188 if (generator()->HasStackOverflow()) { | 214 if (generator()->HasStackOverflow()) { |
189 return FAILED; | 215 return FAILED; |
190 } | 216 } |
191 return SUCCEEDED; | 217 return SUCCEEDED; |
192 } | 218 } |
193 | 219 |
194 InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() { | 220 InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() { |
195 Handle<BytecodeArray> bytecodes = generator()->FinalizeBytecode(isolate()); | 221 Handle<BytecodeArray> bytecodes = |
222 generator()->FinalizeBytecode(isolate(), should_compile_); | |
196 if (generator()->HasStackOverflow()) { | 223 if (generator()->HasStackOverflow()) { |
197 return FAILED; | 224 return FAILED; |
198 } | 225 } |
199 | 226 |
200 if (FLAG_print_bytecode) { | 227 if (FLAG_print_bytecode) { |
201 OFStream os(stdout); | 228 OFStream os(stdout); |
202 bytecodes->Print(os); | 229 bytecodes->Print(os); |
203 os << std::flush; | 230 os << std::flush; |
204 } | 231 } |
205 | 232 |
206 info()->SetBytecodeArray(bytecodes); | 233 info()->SetBytecodeArray(bytecodes); |
207 info()->SetCode(info()->isolate()->builtins()->InterpreterEntryTrampoline()); | 234 info()->SetCode(info()->isolate()->builtins()->InterpreterEntryTrampoline()); |
208 return SUCCEEDED; | 235 return SUCCEEDED; |
209 } | 236 } |
210 | 237 |
211 CompilationJob* Interpreter::NewCompilationJob(CompilationInfo* info) { | 238 class CollectEagerFunctionLiterals final |
212 return new InterpreterCompilationJob(info); | 239 : public AstTraversalVisitor<CollectEagerFunctionLiterals> { |
240 public: | |
241 explicit CollectEagerFunctionLiterals(CompilationInfo* info) | |
242 : AstTraversalVisitor(info->isolate(), info->parse_info()->literal()), | |
243 parse_info_(info->parse_info()) {} | |
244 | |
245 const std::set<FunctionLiteral*>& eager_literals() const { | |
246 return eager_literals_; | |
247 } | |
248 | |
249 private: | |
250 friend class AstTraversalVisitor<CollectEagerFunctionLiterals>; | |
251 | |
252 void VisitFunctionDeclaration(FunctionDeclaration* decl) { | |
253 i::Variable* variable = decl->proxy()->var(); | |
254 DCHECK(variable->mode() == LET || variable->mode() == VAR); | |
255 if (variable->location() == VariableLocation::UNALLOCATED) { | |
256 if (decl->fun()->ShouldEagerCompile()) { | |
257 eager_literals_.insert(decl->fun()); | |
258 } else { | |
259 return; | |
260 } | |
261 } | |
262 AstTraversalVisitor::VisitFunctionDeclaration(decl); | |
263 } | |
264 | |
265 void VisitFunctionLiteral(FunctionLiteral* fun) { | |
266 if (fun->ShouldEagerCompile()) { | |
267 if (fun != parse_info_->literal()) { | |
268 eager_literals_.insert(fun); | |
269 } | |
270 AstTraversalVisitor::VisitFunctionLiteral(fun); | |
271 } | |
272 } | |
273 | |
274 std::set<FunctionLiteral*> eager_literals_; | |
275 ParseInfo* parse_info_; | |
276 | |
277 DISALLOW_COPY_AND_ASSIGN(CollectEagerFunctionLiterals); | |
278 }; | |
279 | |
280 std::vector<std::unique_ptr<CompilationJob>> Interpreter::NewCompilationJob( | |
281 CompilationInfo* info) { | |
282 ShouldCompile should_compile = | |
283 info->is_debug() ? ShouldCompile::kIfNecessary : ShouldCompile::kNever; | |
284 | |
285 std::vector<std::unique_ptr<CompilationJob>> jobs; | |
286 jobs.push_back(std::unique_ptr<InterpreterCompilationJob>( | |
287 new InterpreterCompilationJob(info, should_compile))); | |
288 | |
289 if (should_compile == ShouldCompile::kIfNecessary) return jobs; | |
290 | |
291 CollectEagerFunctionLiterals collector(info); | |
292 collector.Run(); | |
293 | |
294 for (auto fun : collector.eager_literals()) { | |
295 Handle<SharedFunctionInfo> sfi = Compiler::GetSharedFunctionInfo( | |
296 fun, info->script(), info, ShouldCompile::kNever); | |
297 std::unique_ptr<Zone> zone(new Zone(info->isolate()->allocator())); | |
298 std::unique_ptr<ParseInfo> parse_info( | |
299 new ParseInfo(zone.get(), info->script())); | |
300 std::unique_ptr<CompilationInfo> compilation_info( | |
301 new CompilationInfo(parse_info.get(), Handle<JSFunction>::null())); | |
302 parse_info->set_literal(fun); | |
303 parse_info->set_shared_info(sfi); | |
304 parse_info->set_language_mode(fun->scope()->language_mode()); | |
305 if (info->will_serialize()) compilation_info->PrepareForSerializing(); | |
306 DCHECK(!info->is_debug()); | |
307 Compiler::Renumber(parse_info.get()); | |
jochen (gone - plz use gerrit)
2016/10/07 15:40:48
^^^ like this
| |
308 jobs.push_back(std::unique_ptr<InterpreterCompilationJob>( | |
309 new InterpreterCompilationJob(std::move(zone), std::move(parse_info), | |
310 std::move(compilation_info)))); | |
311 } | |
312 return jobs; | |
213 } | 313 } |
214 | 314 |
215 bool Interpreter::IsDispatchTableInitialized() { | 315 bool Interpreter::IsDispatchTableInitialized() { |
216 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen || | 316 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen || |
217 FLAG_trace_ignition_dispatches) { | 317 FLAG_trace_ignition_dispatches) { |
218 // Regenerate table to add bytecode tracing operations, print the assembly | 318 // Regenerate table to add bytecode tracing operations, print the assembly |
219 // code generated by TurboFan or instrument handlers with dispatch counters. | 319 // code generated by TurboFan or instrument handlers with dispatch counters. |
220 return false; | 320 return false; |
221 } | 321 } |
222 return dispatch_table_[0] != nullptr; | 322 return dispatch_table_[0] != nullptr; |
(...skipping 2412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2635 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 2735 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
2636 __ SmiTag(new_state)); | 2736 __ SmiTag(new_state)); |
2637 __ SetAccumulator(old_state); | 2737 __ SetAccumulator(old_state); |
2638 | 2738 |
2639 __ Dispatch(); | 2739 __ Dispatch(); |
2640 } | 2740 } |
2641 | 2741 |
2642 } // namespace interpreter | 2742 } // namespace interpreter |
2643 } // namespace internal | 2743 } // namespace internal |
2644 } // namespace v8 | 2744 } // namespace v8 |
OLD | NEW |