11cb0ef41Sopenharmony_ci// Copyright 2015 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_INTERPRETER_INTERPRETER_H_ 61cb0ef41Sopenharmony_ci#define V8_INTERPRETER_INTERPRETER_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include <memory> 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Clients of this interface shouldn't depend on lots of interpreter internals. 111cb0ef41Sopenharmony_ci// Do not include anything from src/interpreter other than 121cb0ef41Sopenharmony_ci// src/interpreter/bytecodes.h here! 131cb0ef41Sopenharmony_ci#include "src/base/macros.h" 141cb0ef41Sopenharmony_ci#include "src/builtins/builtins.h" 151cb0ef41Sopenharmony_ci#include "src/interpreter/bytecodes.h" 161cb0ef41Sopenharmony_ci#include "src/runtime/runtime.h" 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cinamespace v8 { 191cb0ef41Sopenharmony_cinamespace internal { 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciclass BytecodeArray; 221cb0ef41Sopenharmony_ciclass Callable; 231cb0ef41Sopenharmony_ciclass UnoptimizedCompilationJob; 241cb0ef41Sopenharmony_ciclass FunctionLiteral; 251cb0ef41Sopenharmony_ciclass IgnitionStatisticsTester; 261cb0ef41Sopenharmony_ciclass Isolate; 271cb0ef41Sopenharmony_ciclass LocalIsolate; 281cb0ef41Sopenharmony_ciclass ParseInfo; 291cb0ef41Sopenharmony_ciclass RootVisitor; 301cb0ef41Sopenharmony_ciclass SetupIsolateDelegate; 311cb0ef41Sopenharmony_citemplate <typename> 321cb0ef41Sopenharmony_ciclass ZoneVector; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cinamespace interpreter { 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciclass InterpreterAssembler; 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ciclass Interpreter { 391cb0ef41Sopenharmony_ci public: 401cb0ef41Sopenharmony_ci explicit Interpreter(Isolate* isolate); 411cb0ef41Sopenharmony_ci virtual ~Interpreter() = default; 421cb0ef41Sopenharmony_ci Interpreter(const Interpreter&) = delete; 431cb0ef41Sopenharmony_ci Interpreter& operator=(const Interpreter&) = delete; 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci // Creates a compilation job which will generate bytecode for |literal|. 461cb0ef41Sopenharmony_ci // Additionally, if |eager_inner_literals| is not null, adds any eagerly 471cb0ef41Sopenharmony_ci // compilable inner FunctionLiterals to this list. 481cb0ef41Sopenharmony_ci static std::unique_ptr<UnoptimizedCompilationJob> NewCompilationJob( 491cb0ef41Sopenharmony_ci ParseInfo* parse_info, FunctionLiteral* literal, Handle<Script> script, 501cb0ef41Sopenharmony_ci AccountingAllocator* allocator, 511cb0ef41Sopenharmony_ci std::vector<FunctionLiteral*>* eager_inner_literals, 521cb0ef41Sopenharmony_ci LocalIsolate* local_isolate); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci // Creates a compilation job which will generate source positions for 551cb0ef41Sopenharmony_ci // |literal| and when finalized, store the result into |existing_bytecode|. 561cb0ef41Sopenharmony_ci static std::unique_ptr<UnoptimizedCompilationJob> 571cb0ef41Sopenharmony_ci NewSourcePositionCollectionJob(ParseInfo* parse_info, 581cb0ef41Sopenharmony_ci FunctionLiteral* literal, 591cb0ef41Sopenharmony_ci Handle<BytecodeArray> existing_bytecode, 601cb0ef41Sopenharmony_ci AccountingAllocator* allocator, 611cb0ef41Sopenharmony_ci LocalIsolate* local_isolate); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci // If the bytecode handler for |bytecode| and |operand_scale| has not yet 641cb0ef41Sopenharmony_ci // been loaded, deserialize it. Then return the handler. 651cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE CodeT GetBytecodeHandler(Bytecode bytecode, 661cb0ef41Sopenharmony_ci OperandScale operand_scale); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci // Set the bytecode handler for |bytecode| and |operand_scale|. 691cb0ef41Sopenharmony_ci void SetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale, 701cb0ef41Sopenharmony_ci CodeT handler); 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci // Disassembler support. 731cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE const char* LookupNameOfBytecodeHandler(const Code code); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE Handle<JSObject> GetDispatchCountersObject(); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci void ForEachBytecode(const std::function<void(Bytecode, OperandScale)>& f); 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci void Initialize(); 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci bool IsDispatchTableInitialized() const; 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci Address dispatch_table_address() { 841cb0ef41Sopenharmony_ci return reinterpret_cast<Address>(&dispatch_table_[0]); 851cb0ef41Sopenharmony_ci } 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci Address bytecode_dispatch_counters_table() { 881cb0ef41Sopenharmony_ci return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get()); 891cb0ef41Sopenharmony_ci } 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci Address address_of_interpreter_entry_trampoline_instruction_start() const { 921cb0ef41Sopenharmony_ci return reinterpret_cast<Address>( 931cb0ef41Sopenharmony_ci &interpreter_entry_trampoline_instruction_start_); 941cb0ef41Sopenharmony_ci } 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci private: 971cb0ef41Sopenharmony_ci friend class SetupInterpreter; 981cb0ef41Sopenharmony_ci friend class v8::internal::SetupIsolateDelegate; 991cb0ef41Sopenharmony_ci friend class v8::internal::IgnitionStatisticsTester; 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE void InitDispatchCounters(); 1021cb0ef41Sopenharmony_ci V8_EXPORT_PRIVATE uintptr_t GetDispatchCounter(Bytecode from, 1031cb0ef41Sopenharmony_ci Bytecode to) const; 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ci // Get dispatch table index of bytecode. 1061cb0ef41Sopenharmony_ci static size_t GetDispatchTableIndex(Bytecode bytecode, 1071cb0ef41Sopenharmony_ci OperandScale operand_scale); 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ci static const int kNumberOfWideVariants = BytecodeOperands::kOperandScaleCount; 1101cb0ef41Sopenharmony_ci static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1); 1111cb0ef41Sopenharmony_ci static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1; 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ci Isolate* isolate_; 1141cb0ef41Sopenharmony_ci Address dispatch_table_[kDispatchTableSize]; 1151cb0ef41Sopenharmony_ci std::unique_ptr<uintptr_t[]> bytecode_dispatch_counters_table_; 1161cb0ef41Sopenharmony_ci Address interpreter_entry_trampoline_instruction_start_; 1171cb0ef41Sopenharmony_ci}; 1181cb0ef41Sopenharmony_ci 1191cb0ef41Sopenharmony_ci#ifdef V8_IGNITION_DISPATCH_COUNTING 1201cb0ef41Sopenharmony_ci#define V8_IGNITION_DISPATCH_COUNTING_BOOL true 1211cb0ef41Sopenharmony_ci#else 1221cb0ef41Sopenharmony_ci#define V8_IGNITION_DISPATCH_COUNTING_BOOL false 1231cb0ef41Sopenharmony_ci#endif 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ci} // namespace interpreter 1261cb0ef41Sopenharmony_ci} // namespace internal 1271cb0ef41Sopenharmony_ci} // namespace v8 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci#endif // V8_INTERPRETER_INTERPRETER_H_ 130