V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
interpreter.h
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  virtual ~Interpreter() = default;
39 
40  // Returns the interrupt budget which should be used for the profiler counter.
41  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  Code GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale);
54 
55  // Set the bytecode handler for |bytecode| and |operand_scale|.
56  void SetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale,
57  Code handler);
58 
59  // GC support.
60  void IterateDispatchTable(RootVisitor* v);
61 
62  // Disassembler support (only useful with ENABLE_DISASSEMBLER defined).
63  const char* LookupNameOfBytecodeHandler(const Code code);
64 
65  V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject();
66 
67  void ForEachBytecode(const std::function<void(Bytecode, OperandScale)>& f);
68 
69  void Initialize();
70 
71  bool IsDispatchTableInitialized() const;
72 
73  Address dispatch_table_address() {
74  return reinterpret_cast<Address>(&dispatch_table_[0]);
75  }
76 
77  Address bytecode_dispatch_counters_table() {
78  return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get());
79  }
80 
81  Address address_of_interpreter_entry_trampoline_instruction_start() const {
82  return reinterpret_cast<Address>(
83  &interpreter_entry_trampoline_instruction_start_);
84  }
85 
86  private:
87  friend class SetupInterpreter;
89 
90  uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const;
91 
92  // Get dispatch table index of bytecode.
93  static size_t GetDispatchTableIndex(Bytecode bytecode,
94  OperandScale operand_scale);
95 
96  static const int kNumberOfWideVariants = BytecodeOperands::kOperandScaleCount;
97  static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
98  static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1;
99 
100  Isolate* isolate_;
101  Address dispatch_table_[kDispatchTableSize];
102  std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_;
103  Address interpreter_entry_trampoline_instruction_start_;
104 
105  DISALLOW_COPY_AND_ASSIGN(Interpreter);
106 };
107 
108 } // namespace interpreter
109 } // namespace internal
110 } // namespace v8
111 
112 #endif // V8_INTERPRETER_INTERPRETER_H_
Definition: libplatform.h:13