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

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

Issue 2760233005: [snapshot] Move builtins generation into mksnapshot (Closed)
Patch Set: fix GYP builds Created 3 years, 8 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
« no previous file with comments | « src/interpreter/interpreter.h ('k') | src/interpreter/setup-interpreter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/codegen.h" 10 #include "src/codegen.h"
11 #include "src/compilation-info.h" 11 #include "src/compilation-info.h"
12 #include "src/compiler.h" 12 #include "src/compiler.h"
13 #include "src/counters.h" 13 #include "src/counters.h"
14 #include "src/interpreter/bytecode-generator.h" 14 #include "src/interpreter/bytecode-generator.h"
15 #include "src/interpreter/bytecodes.h" 15 #include "src/interpreter/bytecodes.h"
16 #include "src/interpreter/interpreter-generator.h"
17 #include "src/log.h" 16 #include "src/log.h"
18 #include "src/objects.h" 17 #include "src/objects.h"
18 #include "src/setup-isolate.h"
19 19
20 namespace v8 { 20 namespace v8 {
21 namespace internal { 21 namespace internal {
22 namespace interpreter { 22 namespace interpreter {
23 23
24 class InterpreterCompilationJob final : public CompilationJob { 24 class InterpreterCompilationJob final : public CompilationJob {
25 public: 25 public:
26 explicit InterpreterCompilationJob(CompilationInfo* info); 26 explicit InterpreterCompilationJob(CompilationInfo* info);
27 27
28 protected: 28 protected:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 BytecodeGenerator generator_; 66 BytecodeGenerator generator_;
67 RuntimeCallStats* runtime_call_stats_; 67 RuntimeCallStats* runtime_call_stats_;
68 RuntimeCallCounter background_execute_counter_; 68 RuntimeCallCounter background_execute_counter_;
69 bool print_bytecode_; 69 bool print_bytecode_;
70 70
71 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); 71 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob);
72 }; 72 };
73 73
74 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { 74 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) {
75 memset(dispatch_table_, 0, sizeof(dispatch_table_)); 75 memset(dispatch_table_, 0, sizeof(dispatch_table_));
76 }
77
78 void Interpreter::Initialize() {
79 if (!ShouldInitializeDispatchTable()) return;
80 HandleScope scope(isolate_);
81 76
82 if (FLAG_trace_ignition_dispatches) { 77 if (FLAG_trace_ignition_dispatches) {
83 static const int kBytecodeCount = static_cast<int>(Bytecode::kLast) + 1; 78 static const int kBytecodeCount = static_cast<int>(Bytecode::kLast) + 1;
84 bytecode_dispatch_counters_table_.reset( 79 bytecode_dispatch_counters_table_.reset(
85 new uintptr_t[kBytecodeCount * kBytecodeCount]); 80 new uintptr_t[kBytecodeCount * kBytecodeCount]);
86 memset(bytecode_dispatch_counters_table_.get(), 0, 81 memset(bytecode_dispatch_counters_table_.get(), 0,
87 sizeof(uintptr_t) * kBytecodeCount * kBytecodeCount); 82 sizeof(uintptr_t) * kBytecodeCount * kBytecodeCount);
88 } 83 }
89
90 // Generate bytecode handlers for all bytecodes and scales.
91 const OperandScale kOperandScales[] = {
92 #define VALUE(Name, _) OperandScale::k##Name,
93 OPERAND_SCALE_LIST(VALUE)
94 #undef VALUE
95 };
96
97 for (OperandScale operand_scale : kOperandScales) {
98 #define GENERATE_CODE(Name, ...) \
99 InstallBytecodeHandler(isolate_, Bytecode::k##Name, operand_scale);
100 BYTECODE_LIST(GENERATE_CODE)
101 #undef GENERATE_CODE
102 }
103
104 // Fill unused entries will the illegal bytecode handler.
105 size_t illegal_index =
106 GetDispatchTableIndex(Bytecode::kIllegal, OperandScale::kSingle);
107 for (size_t index = 0; index < arraysize(dispatch_table_); ++index) {
108 if (dispatch_table_[index] == nullptr) {
109 dispatch_table_[index] = dispatch_table_[illegal_index];
110 }
111 }
112
113 // Initialization should have been successful.
114 DCHECK(IsDispatchTableInitialized());
115 }
116
117 bool Interpreter::ReuseExistingHandler(Bytecode bytecode,
118 OperandScale operand_scale) {
119 size_t index = GetDispatchTableIndex(bytecode, operand_scale);
120 switch (bytecode) {
121 case Bytecode::kCallProperty:
122 case Bytecode::kCallProperty0:
123 case Bytecode::kCallProperty1:
124 case Bytecode::kCallProperty2: {
125 const int offset = static_cast<int>(Bytecode::kCallProperty) -
126 static_cast<int>(Bytecode::kCall);
127 STATIC_ASSERT(offset ==
128 static_cast<int>(Bytecode::kCallProperty0) -
129 static_cast<int>(Bytecode::kCall0));
130 STATIC_ASSERT(offset ==
131 static_cast<int>(Bytecode::kCallProperty1) -
132 static_cast<int>(Bytecode::kCall1));
133 STATIC_ASSERT(offset ==
134 static_cast<int>(Bytecode::kCallProperty2) -
135 static_cast<int>(Bytecode::kCall2));
136 CHECK_LT(offset, index);
137 dispatch_table_[index] = dispatch_table_[index - offset];
138 return true;
139 break;
140 }
141 default:
142 return false;
143 }
144 }
145
146 void Interpreter::InstallBytecodeHandler(Isolate* isolate, Bytecode bytecode,
147 OperandScale operand_scale) {
148 if (!Bytecodes::BytecodeHasHandler(bytecode, operand_scale)) return;
149 if (ReuseExistingHandler(bytecode, operand_scale)) return;
150
151 size_t index = GetDispatchTableIndex(bytecode, operand_scale);
152 Handle<Code> code = GenerateBytecodeHandler(isolate, bytecode, operand_scale);
153 dispatch_table_[index] = code->entry();
154 } 84 }
155 85
156 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode, 86 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode,
157 OperandScale operand_scale) { 87 OperandScale operand_scale) {
158 DCHECK(IsDispatchTableInitialized()); 88 DCHECK(IsDispatchTableInitialized());
159 DCHECK(Bytecodes::BytecodeHasHandler(bytecode, operand_scale)); 89 DCHECK(Bytecodes::BytecodeHasHandler(bytecode, operand_scale));
160 size_t index = GetDispatchTableIndex(bytecode, operand_scale); 90 size_t index = GetDispatchTableIndex(bytecode, operand_scale);
161 Address code_entry = dispatch_table_[index]; 91 Address code_entry = dispatch_table_[index];
162 return Code::GetCodeFromTargetAddress(code_entry); 92 return Code::GetCodeFromTargetAddress(code_entry);
163 } 93 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 208 }
279 209
280 CompilationJob* Interpreter::NewCompilationJob(CompilationInfo* info) { 210 CompilationJob* Interpreter::NewCompilationJob(CompilationInfo* info) {
281 return new InterpreterCompilationJob(info); 211 return new InterpreterCompilationJob(info);
282 } 212 }
283 213
284 bool Interpreter::IsDispatchTableInitialized() { 214 bool Interpreter::IsDispatchTableInitialized() {
285 return dispatch_table_[0] != nullptr; 215 return dispatch_table_[0] != nullptr;
286 } 216 }
287 217
288 bool Interpreter::ShouldInitializeDispatchTable() {
289 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen ||
290 FLAG_trace_ignition_dispatches) {
291 // Regenerate table to add bytecode tracing operations, print the assembly
292 // code generated by TurboFan or instrument handlers with dispatch counters.
293 return true;
294 }
295 return !IsDispatchTableInitialized();
296 }
297
298 const char* Interpreter::LookupNameOfBytecodeHandler(Code* code) { 218 const char* Interpreter::LookupNameOfBytecodeHandler(Code* code) {
299 #ifdef ENABLE_DISASSEMBLER 219 #ifdef ENABLE_DISASSEMBLER
300 #define RETURN_NAME(Name, ...) \ 220 #define RETURN_NAME(Name, ...) \
301 if (dispatch_table_[Bytecodes::ToByte(Bytecode::k##Name)] == \ 221 if (dispatch_table_[Bytecodes::ToByte(Bytecode::k##Name)] == \
302 code->entry()) { \ 222 code->entry()) { \
303 return #Name; \ 223 return #Name; \
304 } 224 }
305 BYTECODE_LIST(RETURN_NAME) 225 BYTECODE_LIST(RETURN_NAME)
306 #undef RETURN_NAME 226 #undef RETURN_NAME
307 #endif // ENABLE_DISASSEMBLER 227 #endif // ENABLE_DISASSEMBLER
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 counters_map->DefineOwnProperty(context, from_name_object, counters_row) 283 counters_map->DefineOwnProperty(context, from_name_object, counters_row)
364 .IsJust()); 284 .IsJust());
365 } 285 }
366 286
367 return counters_map; 287 return counters_map;
368 } 288 }
369 289
370 } // namespace interpreter 290 } // namespace interpreter
371 } // namespace internal 291 } // namespace internal
372 } // namespace v8 292 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.h ('k') | src/interpreter/setup-interpreter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698