interpreter.h 3.36 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 BuiltinDeserializerAllocator;
23
class Callable;
24
class CompilationInfo;
25
class CompilationJob;
26
class FunctionLiteral;
27
class ParseInfo;
28
class RootVisitor;
29
class SetupIsolateDelegate;
30 31 32

namespace interpreter {

33 34
class InterpreterAssembler;

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

40
  // Creates a compilation job which will generate bytecode for |literal|.
41 42
  static CompilationJob* NewCompilationJob(ParseInfo* parse_info,
                                           FunctionLiteral* literal,
43
                                           AccountingAllocator* allocator);
44

45 46 47 48 49
  // If the bytecode handler for |bytecode| and |operand_scale| has not yet
  // been loaded, deserialize it. Then return the handler.
  Code* GetAndMaybeDeserializeBytecodeHandler(Bytecode bytecode,
                                              OperandScale operand_scale);

50
  // Return bytecode handler for |bytecode| and |operand_scale|.
51
  Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale);
52

53 54 55 56
  // Set the bytecode handler for |bytecode| and |operand_scale|.
  void SetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale,
                          Code* handler);

57
  // GC support.
58
  void IterateDispatchTable(RootVisitor* v);
59

60 61
  // Disassembler support (only useful with ENABLE_DISASSEMBLER defined).
  const char* LookupNameOfBytecodeHandler(Code* code);
62

63
  V8_EXPORT_PRIVATE Local<v8::Object> GetDispatchCountersObject();
64

65 66
  bool IsDispatchTableInitialized() const;

67 68 69 70
  Address dispatch_table_address() {
    return reinterpret_cast<Address>(&dispatch_table_[0]);
  }

71 72
  Address bytecode_dispatch_counters_table() {
    return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get());
73 74
  }

75
  // The interrupt budget which should be used for the profiler counter.
76
  static const int kInterruptBudget = 144 * KB;
77

78
 private:
79 80
  friend class SetupInterpreter;
  friend class v8::internal::SetupIsolateDelegate;
81
  friend class v8::internal::BuiltinDeserializerAllocator;
82

83 84
  uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const;

85 86 87 88
  // Get dispatch table index of bytecode.
  static size_t GetDispatchTableIndex(Bytecode bytecode,
                                      OperandScale operand_scale);

89
  static const int kNumberOfWideVariants = BytecodeOperands::kOperandScaleCount;
90
  static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
91
  static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1;
92

93
  Isolate* isolate_;
94
  Address dispatch_table_[kDispatchTableSize];
95
  std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_;
96 97 98 99 100 101 102 103 104

  DISALLOW_COPY_AND_ASSIGN(Interpreter);
};

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

#endif  // V8_INTERPRETER_INTERPRETER_H_