interpreter.h 3.55 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_INTERPRETER_INTERPRETER_H_
#define V8_INTERPRETER_INTERPRETER_H_

8 9
#include <memory>

10 11 12 13
// Clients of this interface shouldn't depend on lots of interpreter internals.
// Do not include anything from src/interpreter other than
// src/interpreter/bytecodes.h here!
#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 19 20 21

namespace v8 {
namespace internal {

class Isolate;
22
class Callable;
23
class UnoptimizedCompilationJob;
24
class FunctionLiteral;
25
class ParseInfo;
26
class RootVisitor;
27
class SetupIsolateDelegate;
28 29
template <typename>
class ZoneVector;
30 31 32

namespace interpreter {

33 34
class InterpreterAssembler;

35 36 37
class Interpreter {
 public:
  explicit Interpreter(Isolate* isolate);
38
  virtual ~Interpreter() = default;
39

40 41 42
  // Returns the interrupt budget which should be used for the profiler counter.
  static int InterruptBudget();

43
  // Creates a compilation job which will generate bytecode for |literal|.
44 45
  // Additionally, if |eager_inner_literals| is not null, adds any eagerly
  // compilable inner FunctionLiterals to this list.
46
  static UnoptimizedCompilationJob* NewCompilationJob(
47 48
      ParseInfo* parse_info, FunctionLiteral* literal,
      AccountingAllocator* allocator,
49
      std::vector<FunctionLiteral*>* eager_inner_literals);
50

51 52
  // If the bytecode handler for |bytecode| and |operand_scale| has not yet
  // been loaded, deserialize it. Then return the handler.
53
  Code GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale);
54

55 56
  // Set the bytecode handler for |bytecode| and |operand_scale|.
  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 68
  void ForEachBytecode(const std::function<void(Bytecode, OperandScale)>& f);

69
  void Initialize();
70

71 72
  bool IsDispatchTableInitialized() const;

73 74 75 76
  Address dispatch_table_address() {
    return reinterpret_cast<Address>(&dispatch_table_[0]);
  }

77 78
  Address bytecode_dispatch_counters_table() {
    return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get());
79 80
  }

81 82 83 84 85
  Address address_of_interpreter_entry_trampoline_instruction_start() const {
    return reinterpret_cast<Address>(
        &interpreter_entry_trampoline_instruction_start_);
  }

86
 private:
87 88
  friend class SetupInterpreter;
  friend class v8::internal::SetupIsolateDelegate;
89

90 91
  uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const;

92 93 94 95
  // Get dispatch table index of bytecode.
  static size_t GetDispatchTableIndex(Bytecode bytecode,
                                      OperandScale operand_scale);

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 106 107 108 109 110 111 112

  DISALLOW_COPY_AND_ASSIGN(Interpreter);
};

}  // namespace interpreter
}  // namespace internal
}  // namespace v8

#endif  // V8_INTERPRETER_INTERPRETER_H_