#ifndef V8_INTERPRETER_INTERPRETER_H_
#define V8_INTERPRETER_INTERPRETER_H_
#include <memory>
#include "src/base/macros.h"
#include "src/builtins/builtins.h"
#include "src/interpreter/bytecodes.h"
namespace v8 {
namespace internal {
class AccountingAllocator;
class BytecodeArray;
class Callable;
class UnoptimizedCompilationJob;
class FunctionLiteral;
class IgnitionStatisticsTester;
class Isolate;
class LocalIsolate;
class ParseInfo;
class RootVisitor;
class SetupIsolateDelegate;
template <typename>
class ZoneVector;
namespace interpreter {
class InterpreterAssembler;
struct BytecodeHandlerData {
BytecodeHandlerData(Bytecode bytecode, OperandScale operand_scale)
: bytecode(bytecode), operand_scale(operand_scale) {}
Bytecode bytecode;
OperandScale operand_scale;
ImplicitRegisterUse implicit_register_use = ImplicitRegisterUse::kNone;
bool made_call = false;
bool reloaded_frame_ptr = false;
bool bytecode_array_valid = true;
};
class Interpreter {
public:
explicit Interpreter(Isolate* isolate);
virtual ~Interpreter() = default;
Interpreter(const Interpreter&) = delete;
Interpreter& operator=(const Interpreter&) = delete;
static std::unique_ptr<UnoptimizedCompilationJob> NewCompilationJob(
ParseInfo* parse_info, FunctionLiteral* literal, Handle<Script> script,
AccountingAllocator* allocator,
std::vector<FunctionLiteral*>* eager_inner_literals,
LocalIsolate* local_isolate);
static std::unique_ptr<UnoptimizedCompilationJob>
NewSourcePositionCollectionJob(ParseInfo* parse_info,
FunctionLiteral* literal,
Handle<BytecodeArray> existing_bytecode,
AccountingAllocator* allocator,
LocalIsolate* local_isolate);
V8_EXPORT_PRIVATE Tagged<Code> GetBytecodeHandler(Bytecode bytecode,
OperandScale operand_scale);
void SetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale,
Tagged<Code> handler);
V8_EXPORT_PRIVATE DirectHandle<JSObject> GetDispatchCountersObject();
void ForEachBytecode(const std::function<void(Bytecode, OperandScale)>& f);
void Initialize();
bool IsDispatchTableInitialized() const;
Address dispatch_table_address() {
return reinterpret_cast<Address>(&dispatch_table_[0]);
}
Address bytecode_dispatch_counters_table() {
return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get());
}
Address address_of_interpreter_entry_trampoline_instruction_start() const {
return reinterpret_cast<Address>(
&interpreter_entry_trampoline_instruction_start_);
}
private:
friend class SetupInterpreter;
friend class v8::internal::SetupIsolateDelegate;
friend class v8::internal::IgnitionStatisticsTester;
V8_EXPORT_PRIVATE void InitDispatchCounters();
V8_EXPORT_PRIVATE uintptr_t GetDispatchCounter(Bytecode from,
Bytecode to) const;
static size_t GetDispatchTableIndex(Bytecode bytecode,
OperandScale operand_scale);
static const int kNumberOfWideVariants = BytecodeOperands::kOperandScaleCount;
static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1;
Isolate* isolate_;
Address dispatch_table_[kDispatchTableSize];
std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_;
Address interpreter_entry_trampoline_instruction_start_;
};
#ifdef V8_IGNITION_DISPATCH_COUNTING
#define V8_IGNITION_DISPATCH_COUNTING_BOOL true
#else
#define V8_IGNITION_DISPATCH_COUNTING_BOOL false
#endif
}
}
}
#endif