• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BuiltinDeserializerAllocator;
23 class Callable;
24 class UnoptimizedCompilationJob;
25 class FunctionLiteral;
26 class ParseInfo;
27 class RootVisitor;
28 class SetupIsolateDelegate;
29 template <typename>
30 class ZoneVector;
31 
32 namespace interpreter {
33 
34 class InterpreterAssembler;
35 
36 class Interpreter {
37  public:
38   explicit Interpreter(Isolate* isolate);
~Interpreter()39   virtual ~Interpreter() {}
40 
41   // Returns the interrupt budget which should be used for the profiler counter.
42   static int InterruptBudget();
43 
44   // Creates a compilation job which will generate bytecode for |literal|.
45   // Additionally, if |eager_inner_literals| is not null, adds any eagerly
46   // compilable inner FunctionLiterals to this list.
47   static UnoptimizedCompilationJob* NewCompilationJob(
48       ParseInfo* parse_info, FunctionLiteral* literal,
49       AccountingAllocator* allocator,
50       ZoneVector<FunctionLiteral*>* eager_inner_literals);
51 
52   // If the bytecode handler for |bytecode| and |operand_scale| has not yet
53   // been loaded, deserialize it. Then return the handler.
54   Code* GetAndMaybeDeserializeBytecodeHandler(Bytecode bytecode,
55                                               OperandScale operand_scale);
56 
57   // Return bytecode handler for |bytecode| and |operand_scale|.
58   Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale);
59 
60   // Set the bytecode handler for |bytecode| and |operand_scale|.
61   void SetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale,
62                           Code* handler);
63 
64   // GC support.
65   void IterateDispatchTable(RootVisitor* v);
66 
67   // Disassembler support (only useful with ENABLE_DISASSEMBLER defined).
68   const char* LookupNameOfBytecodeHandler(const Code* code);
69 
70   V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject();
71 
72   bool IsDispatchTableInitialized() const;
73 
dispatch_table_address()74   Address dispatch_table_address() {
75     return reinterpret_cast<Address>(&dispatch_table_[0]);
76   }
77 
bytecode_dispatch_counters_table()78   Address bytecode_dispatch_counters_table() {
79     return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get());
80   }
81 
82  private:
83   friend class SetupInterpreter;
84   friend class v8::internal::SetupIsolateDelegate;
85   friend class v8::internal::BuiltinDeserializerAllocator;
86 
87   uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const;
88 
89   // Get dispatch table index of bytecode.
90   static size_t GetDispatchTableIndex(Bytecode bytecode,
91                                       OperandScale operand_scale);
92 
93   static const int kNumberOfWideVariants = BytecodeOperands::kOperandScaleCount;
94   static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
95   static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1;
96 
97   Isolate* isolate_;
98   Address dispatch_table_[kDispatchTableSize];
99   std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_;
100 
101   DISALLOW_COPY_AND_ASSIGN(Interpreter);
102 };
103 
104 }  // namespace interpreter
105 }  // namespace internal
106 }  // namespace v8
107 
108 #endif  // V8_INTERPRETER_INTERPRETER_H_
109