Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: src/interpreter/interpreter.cc

Issue 2240463002: [Interpreter] Introduce InterpreterCompilationJob (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_peekhole
Patch Set: DISALLOW_COPY_AND_ASSIGN Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_.get(); }
44
45 std::unique_ptr<BytecodeGenerator> generator_;
Michael Starzinger 2016/08/16 08:46:40 Would it be possible to just have BytecodeGenerato
rmcilroy 2016/08/16 11:10:44 Done.
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
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_() {}
154
155 InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() {
156 generator_.reset(new BytecodeGenerator(info()));
157 return SUCCEEDED;
158 }
159
160 InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() {
161 generator()->GenerateBytecode();
162
163 if (generator()->HasStackOverflow()) {
164 return FAILED;
165 }
166 return SUCCEEDED;
167 }
168
169 InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() {
170 Handle<BytecodeArray> bytecodes = generator()->FinalizeBytecode();
171 if (generator()->HasStackOverflow()) {
172 return FAILED;
173 }
174
175 if (FLAG_print_bytecode) {
176 OFStream os(stdout);
177 bytecodes->Print(os);
178 os << std::flush;
179 }
180
181 info()->SetBytecodeArray(bytecodes);
182 info()->SetCode(info()->isolate()->builtins()->InterpreterEntryTrampoline());
183 return SUCCEEDED;
184 }
185
135 bool Interpreter::MakeBytecode(CompilationInfo* info) { 186 bool Interpreter::MakeBytecode(CompilationInfo* info) {
136 RuntimeCallTimerScope runtimeTimer(info->isolate(), 187 RuntimeCallTimerScope runtimeTimer(info->isolate(),
137 &RuntimeCallStats::CompileIgnition); 188 &RuntimeCallStats::CompileIgnition);
138 TimerEventScope<TimerEventCompileIgnition> timer(info->isolate()); 189 TimerEventScope<TimerEventCompileIgnition> timer(info->isolate());
139 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( 190 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
140 info->isolate(), &tracing::TraceEventStatsTable::CompileIgnition); 191 info->isolate(), &tracing::TraceEventStatsTable::CompileIgnition);
141 192
142 if (FLAG_print_bytecode || FLAG_print_ast) { 193 if (FLAG_print_bytecode || FLAG_print_ast) {
143 OFStream os(stdout); 194 OFStream os(stdout);
144 std::unique_ptr<char[]> name = info->GetDebugName(); 195 std::unique_ptr<char[]> name = info->GetDebugName();
145 os << "[generating bytecode for function: " << info->GetDebugName().get() 196 os << "[generating bytecode for function: " << info->GetDebugName().get()
146 << "]" << std::endl 197 << "]" << std::endl
147 << std::flush; 198 << std::flush;
148 } 199 }
149 200
150 #ifdef DEBUG 201 #ifdef DEBUG
151 if (info->parse_info() && FLAG_print_ast) { 202 if (info->parse_info() && FLAG_print_ast) {
152 OFStream os(stdout); 203 OFStream os(stdout);
153 os << "--- AST ---" << std::endl 204 os << "--- AST ---" << std::endl
154 << AstPrinter(info->isolate()).PrintProgram(info->literal()) << std::endl 205 << AstPrinter(info->isolate()).PrintProgram(info->literal()) << std::endl
155 << std::flush; 206 << std::flush;
156 } 207 }
157 #endif // DEBUG 208 #endif // DEBUG
158 209
159 BytecodeGenerator generator(info); 210 InterpreterCompilationJob job(info);
160 Handle<BytecodeArray> bytecodes = generator.MakeBytecode(); 211 if (job.PrepareJob() != CompilationJob::SUCCEEDED) return false;
161 212 if (job.ExecuteJob() != CompilationJob::SUCCEEDED) return false;
162 if (generator.HasStackOverflow()) return false; 213 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 } 214 }
174 215
175 bool Interpreter::IsDispatchTableInitialized() { 216 bool Interpreter::IsDispatchTableInitialized() {
176 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen || 217 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen ||
177 FLAG_trace_ignition_dispatches) { 218 FLAG_trace_ignition_dispatches) {
178 // Regenerate table to add bytecode tracing operations, print the assembly 219 // Regenerate table to add bytecode tracing operations, print the assembly
179 // code generated by TurboFan or instrument handlers with dispatch counters. 220 // code generated by TurboFan or instrument handlers with dispatch counters.
180 return false; 221 return false;
181 } 222 }
182 return dispatch_table_[0] != nullptr; 223 return dispatch_table_[0] != nullptr;
(...skipping 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, 2204 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset,
2164 __ SmiTag(new_state)); 2205 __ SmiTag(new_state));
2165 __ SetAccumulator(old_state); 2206 __ SetAccumulator(old_state);
2166 2207
2167 __ Dispatch(); 2208 __ Dispatch();
2168 } 2209 }
2169 2210
2170 } // namespace interpreter 2211 } // namespace interpreter
2171 } // namespace internal 2212 } // namespace internal
2172 } // namespace v8 2213 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698