interpreter.h 2.67 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/parsing/token.h"
17
#include "src/runtime/runtime.h"
18 19 20 21 22

namespace v8 {
namespace internal {

class Isolate;
23
class Callable;
24
class CompilationInfo;
25
class CompilationJob;
26
class SetupIsolateDelegate;
27 28 29

namespace interpreter {

30 31
class InterpreterAssembler;

32 33 34 35 36
class Interpreter {
 public:
  explicit Interpreter(Isolate* isolate);
  virtual ~Interpreter() {}

37 38 39
  // Returns the interrupt budget which should be used for the profiler counter.
  static int InterruptBudget();

40
  // Creates a compilation job which will generate bytecode for |info|.
41
  static CompilationJob* NewCompilationJob(CompilationInfo* info);
42

43
  // Return bytecode handler for |bytecode|.
44
  Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale);
45

46 47 48
  // GC support.
  void IterateDispatchTable(ObjectVisitor* v);

49 50
  // Disassembler support (only useful with ENABLE_DISASSEMBLER defined).
  const char* LookupNameOfBytecodeHandler(Code* code);
51

52
  V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject();
53

54 55 56 57
  Address dispatch_table_address() {
    return reinterpret_cast<Address>(&dispatch_table_[0]);
  }

58 59
  Address bytecode_dispatch_counters_table() {
    return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get());
60 61
  }

62
  // TODO(ignition): Tune code size multiplier.
63
  static const int kCodeSizeMultiplier = 24;
64

65
 private:
66 67
  friend class SetupInterpreter;
  friend class v8::internal::SetupIsolateDelegate;
68

69 70
  uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const;

71 72 73 74
  // Get dispatch table index of bytecode.
  static size_t GetDispatchTableIndex(Bytecode bytecode,
                                      OperandScale operand_scale);

75 76
  bool IsDispatchTableInitialized();

77 78
  static const int kNumberOfWideVariants = 3;
  static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
79
  static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1;
80

81
  Isolate* isolate_;
82
  Address dispatch_table_[kDispatchTableSize];
83
  std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_;
84 85 86 87 88 89 90 91 92

  DISALLOW_COPY_AND_ASSIGN(Interpreter);
};

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

#endif  // V8_INTERPRETER_INTERPRETER_H_