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 20 matching lines...) Expand all Loading... |
31 if (IsDispatchTableInitialized()) return; | 31 if (IsDispatchTableInitialized()) return; |
32 Zone zone; | 32 Zone zone; |
33 HandleScope scope(isolate_); | 33 HandleScope scope(isolate_); |
34 | 34 |
35 // Generate bytecode handlers for all bytecodes and scales. | 35 // Generate bytecode handlers for all bytecodes and scales. |
36 for (OperandScale operand_scale = OperandScale::kSingle; | 36 for (OperandScale operand_scale = OperandScale::kSingle; |
37 operand_scale <= OperandScale::kMaxValid; | 37 operand_scale <= OperandScale::kMaxValid; |
38 operand_scale = Bytecodes::NextOperandScale(operand_scale)) { | 38 operand_scale = Bytecodes::NextOperandScale(operand_scale)) { |
39 #define GENERATE_CODE(Name, ...) \ | 39 #define GENERATE_CODE(Name, ...) \ |
40 { \ | 40 { \ |
41 if (BytecodeHasHandler(Bytecode::k##Name, operand_scale)) { \ | 41 if (Bytecodes::BytecodeHasHandler(Bytecode::k##Name, operand_scale)) { \ |
42 InterpreterAssembler assembler(isolate_, &zone, Bytecode::k##Name, \ | 42 InterpreterAssembler assembler(isolate_, &zone, Bytecode::k##Name, \ |
43 operand_scale); \ | 43 operand_scale); \ |
44 Do##Name(&assembler); \ | 44 Do##Name(&assembler); \ |
45 Handle<Code> code = assembler.GenerateCode(); \ | 45 Handle<Code> code = assembler.GenerateCode(); \ |
46 size_t index = GetDispatchTableIndex(Bytecode::k##Name, operand_scale); \ | 46 size_t index = GetDispatchTableIndex(Bytecode::k##Name, operand_scale); \ |
47 dispatch_table_[index] = *code; \ | 47 dispatch_table_[index] = *code; \ |
48 TraceCodegen(code); \ | 48 TraceCodegen(code); \ |
49 LOG_CODE_EVENT( \ | 49 LOG_CODE_EVENT( \ |
50 isolate_, \ | 50 isolate_, \ |
51 CodeCreateEvent( \ | 51 CodeCreateEvent( \ |
(...skipping 11 matching lines...) Expand all Loading... |
63 for (size_t index = 0; index < arraysize(dispatch_table_); ++index) { | 63 for (size_t index = 0; index < arraysize(dispatch_table_); ++index) { |
64 if (dispatch_table_[index] == nullptr) { | 64 if (dispatch_table_[index] == nullptr) { |
65 dispatch_table_[index] = dispatch_table_[illegal_index]; | 65 dispatch_table_[index] = dispatch_table_[illegal_index]; |
66 } | 66 } |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode, | 70 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode, |
71 OperandScale operand_scale) { | 71 OperandScale operand_scale) { |
72 DCHECK(IsDispatchTableInitialized()); | 72 DCHECK(IsDispatchTableInitialized()); |
73 DCHECK(BytecodeHasHandler(bytecode, operand_scale)); | 73 DCHECK(Bytecodes::BytecodeHasHandler(bytecode, operand_scale)); |
74 size_t index = GetDispatchTableIndex(bytecode, operand_scale); | 74 size_t index = GetDispatchTableIndex(bytecode, operand_scale); |
75 return dispatch_table_[index]; | 75 return dispatch_table_[index]; |
76 } | 76 } |
77 | 77 |
78 // static | 78 // static |
79 size_t Interpreter::GetDispatchTableIndex(Bytecode bytecode, | 79 size_t Interpreter::GetDispatchTableIndex(Bytecode bytecode, |
80 OperandScale operand_scale) { | 80 OperandScale operand_scale) { |
81 static const size_t kEntriesPerOperandScale = 1u << kBitsPerByte; | 81 static const size_t kEntriesPerOperandScale = 1u << kBitsPerByte; |
82 size_t index = static_cast<size_t>(bytecode); | 82 size_t index = static_cast<size_t>(bytecode); |
83 OperandScale current_scale = OperandScale::kSingle; | 83 OperandScale current_scale = OperandScale::kSingle; |
84 while (current_scale != operand_scale) { | 84 while (current_scale != operand_scale) { |
85 index += kEntriesPerOperandScale; | 85 index += kEntriesPerOperandScale; |
86 current_scale = Bytecodes::NextOperandScale(current_scale); | 86 current_scale = Bytecodes::NextOperandScale(current_scale); |
87 } | 87 } |
88 return index; | 88 return index; |
89 } | 89 } |
90 | 90 |
91 // static | |
92 bool Interpreter::BytecodeHasHandler(Bytecode bytecode, | |
93 OperandScale operand_scale) { | |
94 return operand_scale == OperandScale::kSingle || | |
95 Bytecodes::IsBytecodeWithScalableOperands(bytecode); | |
96 } | |
97 | |
98 void Interpreter::IterateDispatchTable(ObjectVisitor* v) { | 91 void Interpreter::IterateDispatchTable(ObjectVisitor* v) { |
99 v->VisitPointers( | 92 v->VisitPointers( |
100 reinterpret_cast<Object**>(&dispatch_table_[0]), | 93 reinterpret_cast<Object**>(&dispatch_table_[0]), |
101 reinterpret_cast<Object**>(&dispatch_table_[0] + kDispatchTableSize)); | 94 reinterpret_cast<Object**>(&dispatch_table_[0] + kDispatchTableSize)); |
102 } | 95 } |
103 | 96 |
104 // static | 97 // static |
105 int Interpreter::InterruptBudget() { | 98 int Interpreter::InterruptBudget() { |
106 // TODO(ignition): Tune code size multiplier. | 99 // TODO(ignition): Tune code size multiplier. |
107 const int kCodeSizeMultiplier = 32; | 100 const int kCodeSizeMultiplier = 32; |
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 // Illegal | 1611 // Illegal |
1619 // | 1612 // |
1620 // An invalid bytecode aborting execution if dispatched. | 1613 // An invalid bytecode aborting execution if dispatched. |
1621 void Interpreter::DoIllegal(InterpreterAssembler* assembler) { | 1614 void Interpreter::DoIllegal(InterpreterAssembler* assembler) { |
1622 __ Abort(kInvalidBytecode); | 1615 __ Abort(kInvalidBytecode); |
1623 } | 1616 } |
1624 | 1617 |
1625 } // namespace interpreter | 1618 } // namespace interpreter |
1626 } // namespace internal | 1619 } // namespace internal |
1627 } // namespace v8 | 1620 } // namespace v8 |
OLD | NEW |