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/parsing/token.h"
17 : #include "src/runtime/runtime.h"
18 :
19 : namespace v8 {
20 : namespace internal {
21 :
22 : class Isolate;
23 : class Callable;
24 : class CompilationInfo;
25 : class CompilationJob;
26 : class FunctionLiteral;
27 : class ParseInfo;
28 : class SetupIsolateDelegate;
29 : class RootVisitor;
30 :
31 : namespace interpreter {
32 :
33 : class InterpreterAssembler;
34 :
35 : class Interpreter {
36 : public:
37 : explicit Interpreter(Isolate* isolate);
38 160095 : virtual ~Interpreter() {}
39 :
40 : // Creates a compilation job which will generate bytecode for |literal|.
41 : static CompilationJob* NewCompilationJob(ParseInfo* parse_info,
42 : FunctionLiteral* literal,
43 : Isolate* isolate);
44 :
45 : // Return bytecode handler for |bytecode|.
46 : Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale);
47 :
48 : // GC support.
49 : void IterateDispatchTable(RootVisitor* v);
50 :
51 : // Disassembler support (only useful with ENABLE_DISASSEMBLER defined).
52 : const char* LookupNameOfBytecodeHandler(Code* code);
53 :
54 : V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject();
55 :
56 : Address dispatch_table_address() {
57 : return reinterpret_cast<Address>(&dispatch_table_[0]);
58 : }
59 :
60 : Address bytecode_dispatch_counters_table() {
61 : return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get());
62 : }
63 :
64 : // The interrupt budget which should be used for the profiler counter.
65 : static const int kInterruptBudget = 144 * KB;
66 :
67 : private:
68 : friend class SetupInterpreter;
69 : friend class v8::internal::SetupIsolateDelegate;
70 :
71 : uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const;
72 :
73 : // Get dispatch table index of bytecode.
74 : static size_t GetDispatchTableIndex(Bytecode bytecode,
75 : OperandScale operand_scale);
76 :
77 : bool IsDispatchTableInitialized();
78 :
79 : static const int kNumberOfWideVariants = 3;
80 : static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
81 : static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1;
82 :
83 : Isolate* isolate_;
84 : Address dispatch_table_[kDispatchTableSize];
85 : std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_;
86 :
87 : DISALLOW_COPY_AND_ASSIGN(Interpreter);
88 : };
89 :
90 : } // namespace interpreter
91 : } // namespace internal
92 : } // namespace v8
93 :
94 : #endif // V8_INTERPRETER_INTERPRETER_H_
|