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 class SetupIsolateDelegate; |
26 | 27 |
27 namespace interpreter { | 28 namespace interpreter { |
28 | 29 |
29 class InterpreterAssembler; | 30 class InterpreterAssembler; |
30 | 31 |
31 class Interpreter { | 32 class Interpreter { |
32 public: | 33 public: |
33 explicit Interpreter(Isolate* isolate); | 34 explicit Interpreter(Isolate* isolate); |
34 virtual ~Interpreter() {} | 35 virtual ~Interpreter() {} |
35 | 36 |
36 // Initializes the interpreter dispatch table. | |
37 void Initialize(); | |
38 | |
39 // Returns the interrupt budget which should be used for the profiler counter. | 37 // Returns the interrupt budget which should be used for the profiler counter. |
40 static int InterruptBudget(); | 38 static int InterruptBudget(); |
41 | 39 |
42 // Creates a compilation job which will generate bytecode for |info|. | 40 // Creates a compilation job which will generate bytecode for |info|. |
43 static CompilationJob* NewCompilationJob(CompilationInfo* info); | 41 static CompilationJob* NewCompilationJob(CompilationInfo* info); |
44 | 42 |
45 // Return bytecode handler for |bytecode|. | 43 // Return bytecode handler for |bytecode|. |
46 Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale); | 44 Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale); |
47 | 45 |
48 // GC support. | 46 // GC support. |
49 void IterateDispatchTable(ObjectVisitor* v); | 47 void IterateDispatchTable(ObjectVisitor* v); |
50 | 48 |
51 // Disassembler support (only useful with ENABLE_DISASSEMBLER defined). | 49 // Disassembler support (only useful with ENABLE_DISASSEMBLER defined). |
52 const char* LookupNameOfBytecodeHandler(Code* code); | 50 const char* LookupNameOfBytecodeHandler(Code* code); |
53 | 51 |
54 V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject(); | 52 V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject(); |
55 | 53 |
56 Address dispatch_table_address() { | 54 Address dispatch_table_address() { |
57 return reinterpret_cast<Address>(&dispatch_table_[0]); | 55 return reinterpret_cast<Address>(&dispatch_table_[0]); |
58 } | 56 } |
59 | 57 |
60 Address bytecode_dispatch_counters_table() { | 58 Address bytecode_dispatch_counters_table() { |
61 return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get()); | 59 return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get()); |
62 } | 60 } |
63 | 61 |
64 // TODO(ignition): Tune code size multiplier. | 62 // TODO(ignition): Tune code size multiplier. |
65 static const int kCodeSizeMultiplier = 24; | 63 static const int kCodeSizeMultiplier = 24; |
66 | 64 |
67 private: | 65 private: |
68 // In the case of bytecodes that share handler implementations, copy the code | 66 friend class SetupInterpreter; |
69 // into the bytecode's dispatcher table entry and return true. | 67 friend class v8::internal::SetupIsolateDelegate; |
70 bool ReuseExistingHandler(Bytecode bytecode, OperandScale operand_scale); | |
71 | |
72 // Generates handler for given |bytecode| and |operand_scale| | |
73 // and installs it into the dispatch table. | |
74 void InstallBytecodeHandler(Isolate* isolate, Bytecode bytecode, | |
75 OperandScale operand_scale); | |
76 | 68 |
77 uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const; | 69 uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const; |
78 | 70 |
79 // Get dispatch table index of bytecode. | 71 // Get dispatch table index of bytecode. |
80 static size_t GetDispatchTableIndex(Bytecode bytecode, | 72 static size_t GetDispatchTableIndex(Bytecode bytecode, |
81 OperandScale operand_scale); | 73 OperandScale operand_scale); |
82 | 74 |
83 bool IsDispatchTableInitialized(); | 75 bool IsDispatchTableInitialized(); |
84 bool ShouldInitializeDispatchTable(); | |
85 | 76 |
86 static const int kNumberOfWideVariants = 3; | 77 static const int kNumberOfWideVariants = 3; |
87 static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1); | 78 static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1); |
88 static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1; | 79 static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1; |
89 | 80 |
90 Isolate* isolate_; | 81 Isolate* isolate_; |
91 Address dispatch_table_[kDispatchTableSize]; | 82 Address dispatch_table_[kDispatchTableSize]; |
92 std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_; | 83 std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_; |
93 | 84 |
94 DISALLOW_COPY_AND_ASSIGN(Interpreter); | 85 DISALLOW_COPY_AND_ASSIGN(Interpreter); |
95 }; | 86 }; |
96 | 87 |
97 } // namespace interpreter | 88 } // namespace interpreter |
98 } // namespace internal | 89 } // namespace internal |
99 } // namespace v8 | 90 } // namespace v8 |
100 | 91 |
101 #endif // V8_INTERPRETER_INTERPRETER_H_ | 92 #endif // V8_INTERPRETER_INTERPRETER_H_ |
OLD | NEW |