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