| 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 "src/ast/prettyprinter.h" | 7 #include "src/ast/prettyprinter.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/factory.h" | 10 #include "src/factory.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { | 26 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { |
| 27 memset(dispatch_table_, 0, sizeof(dispatch_table_)); | 27 memset(dispatch_table_, 0, sizeof(dispatch_table_)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void Interpreter::Initialize() { | 30 void Interpreter::Initialize() { |
| 31 DCHECK(FLAG_ignition); | 31 DCHECK(FLAG_ignition); |
| 32 if (IsDispatchTableInitialized()) return; | 32 if (IsDispatchTableInitialized()) return; |
| 33 Zone zone; | 33 Zone zone; |
| 34 HandleScope scope(isolate_); | 34 HandleScope scope(isolate_); |
| 35 | 35 |
| 36 if (FLAG_ignition_count_handler_dispatches) { |
| 37 memset(handlers_dispatch_counters_, 0, sizeof(handlers_dispatch_counters_)); |
| 38 } |
| 39 |
| 36 // Generate bytecode handlers for all bytecodes and scales. | 40 // Generate bytecode handlers for all bytecodes and scales. |
| 37 for (OperandScale operand_scale = OperandScale::kSingle; | 41 for (OperandScale operand_scale = OperandScale::kSingle; |
| 38 operand_scale <= OperandScale::kMaxValid; | 42 operand_scale <= OperandScale::kMaxValid; |
| 39 operand_scale = Bytecodes::NextOperandScale(operand_scale)) { | 43 operand_scale = Bytecodes::NextOperandScale(operand_scale)) { |
| 40 #define GENERATE_CODE(Name, ...) \ | 44 #define GENERATE_CODE(Name, ...) \ |
| 41 { \ | 45 { \ |
| 42 if (BytecodeHasHandler(Bytecode::k##Name, operand_scale)) { \ | 46 if (BytecodeHasHandler(Bytecode::k##Name, operand_scale)) { \ |
| 43 InterpreterAssembler assembler(isolate_, &zone, Bytecode::k##Name, \ | 47 InterpreterAssembler assembler(isolate_, &zone, Bytecode::k##Name, \ |
| 44 operand_scale); \ | 48 operand_scale); \ |
| 45 Do##Name(&assembler); \ | 49 Do##Name(&assembler); \ |
| 46 Handle<Code> code = assembler.GenerateCode(); \ | 50 Handle<Code> code = assembler.GenerateCode(); \ |
| 47 size_t index = GetDispatchTableIndex(Bytecode::k##Name, operand_scale); \ | 51 size_t index = GetDispatchTableIndex(Bytecode::k##Name, operand_scale); \ |
| 48 dispatch_table_[index] = *code; \ | 52 dispatch_table_[index] = *code; \ |
| 49 TraceCodegen(code); \ | 53 TraceCodegen(code); \ |
| 50 LOG_CODE_EVENT(isolate_, \ | 54 LOG_CODE_EVENT( \ |
| 51 CodeCreateEvent(Logger::BYTECODE_HANDLER_TAG, \ | 55 isolate_, \ |
| 52 AbstractCode::cast(*code), #Name)); \ | 56 CodeCreateEvent( \ |
| 53 } \ | 57 Logger::BYTECODE_HANDLER_TAG, AbstractCode::cast(*code), \ |
| 58 Bytecodes::ToString(Bytecode::k##Name, operand_scale).c_str())); \ |
| 59 } \ |
| 54 } | 60 } |
| 55 BYTECODE_LIST(GENERATE_CODE) | 61 BYTECODE_LIST(GENERATE_CODE) |
| 56 #undef GENERATE_CODE | 62 #undef GENERATE_CODE |
| 57 } | 63 } |
| 58 | 64 |
| 59 // Fill unused entries will the illegal bytecode handler. | 65 // Fill unused entries will the illegal bytecode handler. |
| 60 size_t illegal_index = | 66 size_t illegal_index = |
| 61 GetDispatchTableIndex(Bytecode::kIllegal, OperandScale::kSingle); | 67 GetDispatchTableIndex(Bytecode::kIllegal, OperandScale::kSingle); |
| 62 for (size_t index = 0; index < arraysize(dispatch_table_); ++index) { | 68 for (size_t index = 0; index < arraysize(dispatch_table_); ++index) { |
| 63 if (dispatch_table_[index] == nullptr) { | 69 if (dispatch_table_[index] == nullptr) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 bytecodes->Print(os); | 152 bytecodes->Print(os); |
| 147 os << std::flush; | 153 os << std::flush; |
| 148 } | 154 } |
| 149 | 155 |
| 150 info->SetBytecodeArray(bytecodes); | 156 info->SetBytecodeArray(bytecodes); |
| 151 info->SetCode(info->isolate()->builtins()->InterpreterEntryTrampoline()); | 157 info->SetCode(info->isolate()->builtins()->InterpreterEntryTrampoline()); |
| 152 return true; | 158 return true; |
| 153 } | 159 } |
| 154 | 160 |
| 155 bool Interpreter::IsDispatchTableInitialized() { | 161 bool Interpreter::IsDispatchTableInitialized() { |
| 156 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen) { | 162 if (FLAG_trace_ignition || FLAG_trace_ignition_codegen || |
| 163 FLAG_ignition_count_handler_dispatches) { |
| 157 // Regenerate table to add bytecode tracing operations | 164 // Regenerate table to add bytecode tracing operations |
| 158 // or to print the assembly code generated by TurboFan. | 165 // or to print the assembly code generated by TurboFan. |
| 159 return false; | 166 return false; |
| 160 } | 167 } |
| 161 return dispatch_table_[0] != nullptr; | 168 return dispatch_table_[0] != nullptr; |
| 162 } | 169 } |
| 163 | 170 |
| 164 void Interpreter::TraceCodegen(Handle<Code> code) { | 171 void Interpreter::TraceCodegen(Handle<Code> code) { |
| 165 #ifdef ENABLE_DISASSEMBLER | 172 #ifdef ENABLE_DISASSEMBLER |
| 166 if (FLAG_trace_ignition_codegen) { | 173 if (FLAG_trace_ignition_codegen) { |
| (...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 // Illegal | 1613 // Illegal |
| 1607 // | 1614 // |
| 1608 // An invalid bytecode aborting execution if dispatched. | 1615 // An invalid bytecode aborting execution if dispatched. |
| 1609 void Interpreter::DoIllegal(InterpreterAssembler* assembler) { | 1616 void Interpreter::DoIllegal(InterpreterAssembler* assembler) { |
| 1610 __ Abort(kInvalidBytecode); | 1617 __ Abort(kInvalidBytecode); |
| 1611 } | 1618 } |
| 1612 | 1619 |
| 1613 } // namespace interpreter | 1620 } // namespace interpreter |
| 1614 } // namespace internal | 1621 } // namespace internal |
| 1615 } // namespace v8 | 1622 } // namespace v8 |
| OLD | NEW |