Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_INTERPRETER_INTERPRETER_H_
6 : #define V8_INTERPRETER_INTERPRETER_H_
7 :
8 : #include <memory>
9 :
10 : // Clients of this interface shouldn't depend on lots of interpreter internals.
11 : // Do not include anything from src/interpreter other than
12 : // src/interpreter/bytecodes.h here!
13 : #include "src/base/macros.h"
14 : #include "src/builtins/builtins.h"
15 : #include "src/interpreter/bytecodes.h"
16 : #include "src/runtime/runtime.h"
17 :
18 : namespace v8 {
19 : namespace internal {
20 :
21 : class Isolate;
22 : class Callable;
23 : class UnoptimizedCompilationJob;
24 : class FunctionLiteral;
25 : class ParseInfo;
26 : class RootVisitor;
27 : class SetupIsolateDelegate;
28 : template <typename>
29 : class ZoneVector;
30 :
31 : namespace interpreter {
32 :
33 : class InterpreterAssembler;
34 :
35 : class Interpreter {
36 : public:
37 : explicit Interpreter(Isolate* isolate);
38 124814 : virtual ~Interpreter() = default;
39 :
40 : // Returns the interrupt budget which should be used for the profiler counter.
41 : V8_EXPORT_PRIVATE static int InterruptBudget();
42 :
43 : // Creates a compilation job which will generate bytecode for |literal|.
44 : // Additionally, if |eager_inner_literals| is not null, adds any eagerly
45 : // compilable inner FunctionLiterals to this list.
46 : static UnoptimizedCompilationJob* NewCompilationJob(
47 : ParseInfo* parse_info, FunctionLiteral* literal,
48 : AccountingAllocator* allocator,
49 : std::vector<FunctionLiteral*>* eager_inner_literals);
50 :
51 : // If the bytecode handler for |bytecode| and |operand_scale| has not yet
52 : // been loaded, deserialize it. Then return the handler.
53 : V8_EXPORT_PRIVATE Code GetBytecodeHandler(Bytecode bytecode,
54 : OperandScale operand_scale);
55 :
56 : // Set the bytecode handler for |bytecode| and |operand_scale|.
57 : void SetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale,
58 : Code handler);
59 :
60 : // GC support.
61 : void IterateDispatchTable(RootVisitor* v);
62 :
63 : // Disassembler support (only useful with ENABLE_DISASSEMBLER defined).
64 : const char* LookupNameOfBytecodeHandler(const Code code);
65 :
66 : V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject();
67 :
68 : void ForEachBytecode(const std::function<void(Bytecode, OperandScale)>& f);
69 :
70 : void Initialize();
71 :
72 : bool IsDispatchTableInitialized() const;
73 :
74 : Address dispatch_table_address() {
75 64102 : return reinterpret_cast<Address>(&dispatch_table_[0]);
76 : }
77 :
78 : Address bytecode_dispatch_counters_table() {
79 62422 : return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get());
80 : }
81 :
82 : Address address_of_interpreter_entry_trampoline_instruction_start() const {
83 : return reinterpret_cast<Address>(
84 62534 : &interpreter_entry_trampoline_instruction_start_);
85 : }
86 :
87 : private:
88 : friend class SetupInterpreter;
89 : friend class v8::internal::SetupIsolateDelegate;
90 :
91 : uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const;
92 :
93 : // Get dispatch table index of bytecode.
94 : static size_t GetDispatchTableIndex(Bytecode bytecode,
95 : OperandScale operand_scale);
96 :
97 : static const int kNumberOfWideVariants = BytecodeOperands::kOperandScaleCount;
98 : static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
99 : static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1;
100 :
101 : Isolate* isolate_;
102 : Address dispatch_table_[kDispatchTableSize];
103 : std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_;
104 : Address interpreter_entry_trampoline_instruction_start_;
105 :
106 : DISALLOW_COPY_AND_ASSIGN(Interpreter);
107 : };
108 :
109 : } // namespace interpreter
110 : } // namespace internal
111 : } // namespace v8
112 :
113 : #endif // V8_INTERPRETER_INTERPRETER_H_
|