Chromium Code Reviews| 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/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" |
| 19 | 18 |
| 20 namespace v8 { | 19 namespace v8 { |
| 21 namespace internal { | 20 namespace internal { |
| 22 namespace interpreter { | 21 namespace interpreter { |
| 23 | 22 |
| 24 class InterpreterCompilationJob final : public CompilationJob { | 23 class InterpreterCompilationJob final : public CompilationJob { |
| 25 public: | 24 public: |
| 26 explicit InterpreterCompilationJob(CompilationInfo* info); | 25 explicit InterpreterCompilationJob(CompilationInfo* info); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 RuntimeCallCounter background_execute_counter_; | 67 RuntimeCallCounter background_execute_counter_; |
| 69 bool print_bytecode_; | 68 bool print_bytecode_; |
| 70 | 69 |
| 71 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); | 70 DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob); |
| 72 }; | 71 }; |
| 73 | 72 |
| 74 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { | 73 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { |
| 75 memset(dispatch_table_, 0, sizeof(dispatch_table_)); | 74 memset(dispatch_table_, 0, sizeof(dispatch_table_)); |
| 76 } | 75 } |
| 77 | 76 |
| 78 void Interpreter::Initialize() { | |
|
Jakob Kummerow
2017/03/21 16:38:00
This moved to setup-interpreter-full.cc.
| |
| 79 if (!ShouldInitializeDispatchTable()) return; | |
| 80 HandleScope scope(isolate_); | |
| 81 | |
| 82 if (FLAG_trace_ignition_dispatches) { | |
| 83 static const int kBytecodeCount = static_cast<int>(Bytecode::kLast) + 1; | |
| 84 bytecode_dispatch_counters_table_.reset( | |
| 85 new uintptr_t[kBytecodeCount * kBytecodeCount]); | |
| 86 memset(bytecode_dispatch_counters_table_.get(), 0, | |
| 87 sizeof(uintptr_t) * kBytecodeCount * kBytecodeCount); | |
| 88 } | |
| 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, | 77 bool Interpreter::ReuseExistingHandler(Bytecode bytecode, |
| 118 OperandScale operand_scale) { | 78 OperandScale operand_scale) { |
| 119 size_t index = GetDispatchTableIndex(bytecode, operand_scale); | 79 size_t index = GetDispatchTableIndex(bytecode, operand_scale); |
| 120 switch (bytecode) { | 80 switch (bytecode) { |
| 121 case Bytecode::kCallProperty: | 81 case Bytecode::kCallProperty: |
| 122 case Bytecode::kCallProperty0: | 82 case Bytecode::kCallProperty0: |
| 123 case Bytecode::kCallProperty1: | 83 case Bytecode::kCallProperty1: |
| 124 case Bytecode::kCallProperty2: { | 84 case Bytecode::kCallProperty2: { |
| 125 const int offset = static_cast<int>(Bytecode::kCallProperty) - | 85 const int offset = static_cast<int>(Bytecode::kCallProperty) - |
| 126 static_cast<int>(Bytecode::kCall); | 86 static_cast<int>(Bytecode::kCall); |
| 127 STATIC_ASSERT(offset == | 87 STATIC_ASSERT(offset == |
| 128 static_cast<int>(Bytecode::kCallProperty0) - | 88 static_cast<int>(Bytecode::kCallProperty0) - |
| 129 static_cast<int>(Bytecode::kCall0)); | 89 static_cast<int>(Bytecode::kCall0)); |
| 130 STATIC_ASSERT(offset == | 90 STATIC_ASSERT(offset == |
| 131 static_cast<int>(Bytecode::kCallProperty1) - | 91 static_cast<int>(Bytecode::kCallProperty1) - |
| 132 static_cast<int>(Bytecode::kCall1)); | 92 static_cast<int>(Bytecode::kCall1)); |
| 133 STATIC_ASSERT(offset == | 93 STATIC_ASSERT(offset == |
| 134 static_cast<int>(Bytecode::kCallProperty2) - | 94 static_cast<int>(Bytecode::kCallProperty2) - |
| 135 static_cast<int>(Bytecode::kCall2)); | 95 static_cast<int>(Bytecode::kCall2)); |
| 136 CHECK_LT(offset, index); | 96 CHECK_LT(offset, index); |
| 137 dispatch_table_[index] = dispatch_table_[index - offset]; | 97 dispatch_table_[index] = dispatch_table_[index - offset]; |
| 138 return true; | 98 return true; |
| 139 break; | 99 break; |
| 140 } | 100 } |
| 141 default: | 101 default: |
| 142 return false; | 102 return false; |
| 143 } | 103 } |
| 144 } | 104 } |
| 145 | 105 |
| 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 } | |
| 155 | |
| 156 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode, | 106 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode, |
| 157 OperandScale operand_scale) { | 107 OperandScale operand_scale) { |
| 158 DCHECK(IsDispatchTableInitialized()); | 108 DCHECK(IsDispatchTableInitialized()); |
| 159 DCHECK(Bytecodes::BytecodeHasHandler(bytecode, operand_scale)); | 109 DCHECK(Bytecodes::BytecodeHasHandler(bytecode, operand_scale)); |
| 160 size_t index = GetDispatchTableIndex(bytecode, operand_scale); | 110 size_t index = GetDispatchTableIndex(bytecode, operand_scale); |
| 161 Address code_entry = dispatch_table_[index]; | 111 Address code_entry = dispatch_table_[index]; |
| 162 return Code::GetCodeFromTargetAddress(code_entry); | 112 return Code::GetCodeFromTargetAddress(code_entry); |
| 163 } | 113 } |
| 164 | 114 |
| 165 // static | 115 // static |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 } | 228 } |
| 279 | 229 |
| 280 CompilationJob* Interpreter::NewCompilationJob(CompilationInfo* info) { | 230 CompilationJob* Interpreter::NewCompilationJob(CompilationInfo* info) { |
| 281 return new InterpreterCompilationJob(info); | 231 return new InterpreterCompilationJob(info); |
| 282 } | 232 } |
| 283 | 233 |
| 284 bool Interpreter::IsDispatchTableInitialized() { | 234 bool Interpreter::IsDispatchTableInitialized() { |
| 285 return dispatch_table_[0] != nullptr; | 235 return dispatch_table_[0] != nullptr; |
| 286 } | 236 } |
| 287 | 237 |
| 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) { | 238 const char* Interpreter::LookupNameOfBytecodeHandler(Code* code) { |
| 299 #ifdef ENABLE_DISASSEMBLER | 239 #ifdef ENABLE_DISASSEMBLER |
| 300 #define RETURN_NAME(Name, ...) \ | 240 #define RETURN_NAME(Name, ...) \ |
| 301 if (dispatch_table_[Bytecodes::ToByte(Bytecode::k##Name)] == \ | 241 if (dispatch_table_[Bytecodes::ToByte(Bytecode::k##Name)] == \ |
| 302 code->entry()) { \ | 242 code->entry()) { \ |
| 303 return #Name; \ | 243 return #Name; \ |
| 304 } | 244 } |
| 305 BYTECODE_LIST(RETURN_NAME) | 245 BYTECODE_LIST(RETURN_NAME) |
| 306 #undef RETURN_NAME | 246 #undef RETURN_NAME |
| 307 #endif // ENABLE_DISASSEMBLER | 247 #endif // ENABLE_DISASSEMBLER |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 counters_map->DefineOwnProperty(context, from_name_object, counters_row) | 303 counters_map->DefineOwnProperty(context, from_name_object, counters_row) |
| 364 .IsJust()); | 304 .IsJust()); |
| 365 } | 305 } |
| 366 | 306 |
| 367 return counters_map; | 307 return counters_map; |
| 368 } | 308 } |
| 369 | 309 |
| 370 } // namespace interpreter | 310 } // namespace interpreter |
| 371 } // namespace internal | 311 } // namespace internal |
| 372 } // namespace v8 | 312 } // namespace v8 |
| OLD | NEW |