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 #ifndef V8_INTERPRETER_INTERPRETER_H_ | 5 #ifndef V8_INTERPRETER_INTERPRETER_H_ |
6 #define V8_INTERPRETER_INTERPRETER_H_ | 6 #define V8_INTERPRETER_INTERPRETER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 // Clients of this interface shouldn't depend on lots of interpreter internals. | 10 // Clients of this interface shouldn't depend on lots of interpreter internals. |
11 // Do not include anything from src/interpreter other than | 11 // Do not include anything from src/interpreter other than |
12 // src/interpreter/bytecodes.h here! | 12 // src/interpreter/bytecodes.h here! |
13 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
14 #include "src/builtins/builtins.h" | 14 #include "src/builtins/builtins.h" |
15 #include "src/interpreter/bytecodes.h" | 15 #include "src/interpreter/bytecodes.h" |
16 #include "src/parsing/token.h" | 16 #include "src/parsing/token.h" |
17 #include "src/runtime/runtime.h" | 17 #include "src/runtime/runtime.h" |
18 | 18 |
19 namespace v8 { | 19 namespace v8 { |
20 namespace internal { | 20 namespace internal { |
21 | 21 |
22 class Isolate; | 22 class Isolate; |
23 class Callable; | 23 class Callable; |
24 class CompilationInfo; | 24 class CompilationInfo; |
25 class CompilationJob; | 25 class CompilationJob; |
26 | 26 |
27 namespace compiler { | |
28 class Node; | |
29 } // namespace compiler | |
30 | |
31 namespace interpreter { | 27 namespace interpreter { |
32 | 28 |
33 class InterpreterAssembler; | 29 class InterpreterAssembler; |
34 | 30 |
35 class Interpreter { | 31 class Interpreter { |
36 public: | 32 public: |
37 explicit Interpreter(Isolate* isolate); | 33 explicit Interpreter(Isolate* isolate); |
38 virtual ~Interpreter() {} | 34 virtual ~Interpreter() {} |
39 | 35 |
40 // Initializes the interpreter dispatch table. | 36 // Initializes the interpreter dispatch table. |
41 void Initialize(); | 37 void Initialize(); |
42 | 38 |
43 // Returns the interrupt budget which should be used for the profiler counter. | 39 // Returns the interrupt budget which should be used for the profiler counter. |
44 static int InterruptBudget(); | 40 static int InterruptBudget(); |
45 | 41 |
46 // Creates a compilation job which will generate bytecode for |info|. | 42 // Creates a compilation job which will generate bytecode for |info|. |
47 static CompilationJob* NewCompilationJob(CompilationInfo* info); | 43 static CompilationJob* NewCompilationJob(CompilationInfo* info); |
48 | 44 |
49 // Return bytecode handler for |bytecode|. | 45 // Return bytecode handler for |bytecode|. |
50 Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale); | 46 Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale); |
51 | 47 |
52 // GC support. | 48 // GC support. |
53 void IterateDispatchTable(ObjectVisitor* v); | 49 void IterateDispatchTable(ObjectVisitor* v); |
54 | 50 |
55 // Disassembler support (only useful with ENABLE_DISASSEMBLER defined). | 51 // Disassembler support (only useful with ENABLE_DISASSEMBLER defined). |
56 void TraceCodegen(Handle<Code> code); | |
57 const char* LookupNameOfBytecodeHandler(Code* code); | 52 const char* LookupNameOfBytecodeHandler(Code* code); |
58 | 53 |
59 V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject(); | 54 V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject(); |
60 | 55 |
61 Address dispatch_table_address() { | 56 Address dispatch_table_address() { |
62 return reinterpret_cast<Address>(&dispatch_table_[0]); | 57 return reinterpret_cast<Address>(&dispatch_table_[0]); |
63 } | 58 } |
64 | 59 |
65 Address bytecode_dispatch_counters_table() { | 60 Address bytecode_dispatch_counters_table() { |
66 return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get()); | 61 return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get()); |
67 } | 62 } |
68 | 63 |
69 // TODO(ignition): Tune code size multiplier. | 64 // TODO(ignition): Tune code size multiplier. |
70 static const int kCodeSizeMultiplier = 32; | 65 static const int kCodeSizeMultiplier = 32; |
71 | 66 |
72 private: | 67 private: |
73 // Bytecode handler generator functions. | |
74 #define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, ...) \ | |
75 void Do##Name(InterpreterAssembler* assembler); | |
76 BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR) | |
77 #undef DECLARE_BYTECODE_HANDLER_GENERATOR | |
78 | |
79 typedef void (Interpreter::*BytecodeGeneratorFunc)(InterpreterAssembler*); | |
80 | |
81 // In the case of bytecodes that share handler implementations, copy the code | 68 // In the case of bytecodes that share handler implementations, copy the code |
82 // into the bytecode's dispatcher table entry and return true. | 69 // into the bytecode's dispatcher table entry and return true. |
83 bool ReuseExistingHandler(Bytecode bytecode, OperandScale operand_scale); | 70 bool ReuseExistingHandler(Bytecode bytecode, OperandScale operand_scale); |
84 | 71 |
85 // Generates handler for given |bytecode| and |operand_scale| using | 72 // Generates handler for given |bytecode| and |operand_scale| |
86 // |generator| and installs it into the dispatch table. | 73 // and installs it into the dispatch table. |
87 void InstallBytecodeHandler(Zone* zone, Bytecode bytecode, | 74 void InstallBytecodeHandler(Isolate* isolate, Bytecode bytecode, |
88 OperandScale operand_scale, | 75 OperandScale operand_scale); |
89 BytecodeGeneratorFunc generator); | |
90 | |
91 // Generates code to perform the binary operation via |Generator|. | |
92 template <class Generator> | |
93 void DoBinaryOpWithFeedback(InterpreterAssembler* assembler); | |
94 | |
95 // Generates code to perform the comparison via |Generator| while gathering | |
96 // type feedback. | |
97 void DoCompareOpWithFeedback(Token::Value compare_op, | |
98 InterpreterAssembler* assembler); | |
99 | |
100 // Generates code to perform the bitwise binary operation corresponding to | |
101 // |bitwise_op| while gathering type feedback. | |
102 void DoBitwiseBinaryOp(Token::Value bitwise_op, | |
103 InterpreterAssembler* assembler); | |
104 | |
105 // Generates code to perform the binary operation via |Generator| using | |
106 // an immediate value rather the accumulator as the rhs operand. | |
107 template <class Generator> | |
108 void DoBinaryOpWithImmediate(InterpreterAssembler* assembler); | |
109 | |
110 // Generates code to perform the unary operation via |Generator| while | |
111 // gatering type feedback. | |
112 template <class Generator> | |
113 void DoUnaryOpWithFeedback(InterpreterAssembler* assembler); | |
114 | |
115 // Generates code to perform the comparison operation associated with | |
116 // |compare_op|. | |
117 void DoCompareOp(Token::Value compare_op, InterpreterAssembler* assembler); | |
118 | |
119 // Generates code to perform a global store via |ic|. | |
120 void DoStaGlobal(Callable ic, InterpreterAssembler* assembler); | |
121 | |
122 // Generates code to perform a named property store via |ic|. | |
123 void DoStoreIC(Callable ic, InterpreterAssembler* assembler); | |
124 | |
125 // Generates code to perform a keyed property store via |ic|. | |
126 void DoKeyedStoreIC(Callable ic, InterpreterAssembler* assembler); | |
127 | |
128 // Generates code to perform a JS call that collects type feedback. | |
129 void DoJSCall(InterpreterAssembler* assembler, TailCallMode tail_call_mode); | |
130 | |
131 // Generates code to perform a JS call with a known number of arguments that | |
132 // collects type feedback. | |
133 void DoJSCallN(InterpreterAssembler* assembler, int n); | |
134 | |
135 // Generates code to perform delete via function_id. | |
136 void DoDelete(Runtime::FunctionId function_id, | |
137 InterpreterAssembler* assembler); | |
138 | |
139 // Generates code to perform a lookup slot load via |function_id|. | |
140 void DoLdaLookupSlot(Runtime::FunctionId function_id, | |
141 InterpreterAssembler* assembler); | |
142 | |
143 // Generates code to perform a lookup slot load via |function_id| that can | |
144 // fast path to a context slot load. | |
145 void DoLdaLookupContextSlot(Runtime::FunctionId function_id, | |
146 InterpreterAssembler* assembler); | |
147 | |
148 // Generates code to perform a lookup slot load via |function_id| that can | |
149 // fast path to a global load. | |
150 void DoLdaLookupGlobalSlot(Runtime::FunctionId function_id, | |
151 InterpreterAssembler* assembler); | |
152 | |
153 // Generates code to perform a lookup slot store depending on | |
154 // |language_mode|. | |
155 void DoStaLookupSlot(LanguageMode language_mode, | |
156 InterpreterAssembler* assembler); | |
157 | |
158 // Generates code to load a global property. | |
159 void BuildLoadGlobalIC(int slot_operand_index, int name_operand_index, | |
160 TypeofMode typeof_mode, | |
161 InterpreterAssembler* assembler); | |
162 | |
163 // Generates code to load a property. | |
164 void BuildLoadIC(int recv_operand_index, int slot_operand_index, | |
165 int name_operand_index, InterpreterAssembler* assembler); | |
166 | |
167 // Generates code to prepare the result for ForInPrepare. Cache data | |
168 // are placed into the consecutive series of registers starting at | |
169 // |output_register|. | |
170 void BuildForInPrepareResult(compiler::Node* output_register, | |
171 compiler::Node* cache_type, | |
172 compiler::Node* cache_array, | |
173 compiler::Node* cache_length, | |
174 InterpreterAssembler* assembler); | |
175 | |
176 // Generates code to perform the unary operation via |callable|. | |
177 compiler::Node* BuildUnaryOp(Callable callable, | |
178 InterpreterAssembler* assembler); | |
179 | 76 |
180 uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const; | 77 uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const; |
181 | 78 |
182 // Get dispatch table index of bytecode. | 79 // Get dispatch table index of bytecode. |
183 static size_t GetDispatchTableIndex(Bytecode bytecode, | 80 static size_t GetDispatchTableIndex(Bytecode bytecode, |
184 OperandScale operand_scale); | 81 OperandScale operand_scale); |
185 | 82 |
186 bool IsDispatchTableInitialized(); | 83 bool IsDispatchTableInitialized(); |
187 bool ShouldInitializeDispatchTable(); | 84 bool ShouldInitializeDispatchTable(); |
188 | 85 |
189 static const int kNumberOfWideVariants = 3; | 86 static const int kNumberOfWideVariants = 3; |
190 static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1); | 87 static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1); |
191 static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1; | 88 static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1; |
192 | 89 |
193 Isolate* isolate_; | 90 Isolate* isolate_; |
194 Address dispatch_table_[kDispatchTableSize]; | 91 Address dispatch_table_[kDispatchTableSize]; |
195 std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_; | 92 std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_; |
196 | 93 |
197 DISALLOW_COPY_AND_ASSIGN(Interpreter); | 94 DISALLOW_COPY_AND_ASSIGN(Interpreter); |
198 }; | 95 }; |
199 | 96 |
200 } // namespace interpreter | 97 } // namespace interpreter |
201 } // namespace internal | 98 } // namespace internal |
202 } // namespace v8 | 99 } // namespace v8 |
203 | 100 |
204 #endif // V8_INTERPRETER_INTERPRETER_H_ | 101 #endif // V8_INTERPRETER_INTERPRETER_H_ |
OLD | NEW |