// Copyright 2018 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_ISOLATE_DATA_H_ #define V8_ISOLATE_DATA_H_ #include "src/builtins/builtins.h" #include "src/constants-arch.h" #include "src/external-reference-table.h" #include "src/roots.h" #include "src/utils.h" namespace v8 { namespace internal { class Isolate; // This class contains a collection of data accessible from both C++ runtime // and compiled code (including assembly stubs, builtins, interpreter bytecode // handlers and optimized code). // In particular, it contains pointer to the V8 heap roots table, external // reference table and builtins array. // The compiled code accesses the isolate data fields indirectly via the root // register. class IsolateData final { public: IsolateData() = default; static constexpr intptr_t kIsolateRootBias = kRootRegisterBias; // The value of the kRootRegister. Address isolate_root() const { return reinterpret_cast
(this) + kIsolateRootBias; } // Root-register-relative offset of the roots table. static constexpr int roots_table_offset() { return kRootsTableOffset - kIsolateRootBias; } // Root-register-relative offset of the given root table entry. static constexpr int root_slot_offset(RootIndex root_index) { return roots_table_offset() + RootsTable::offset_of(root_index); } // Root-register-relative offset of the external reference table. static constexpr int external_reference_table_offset() { return kExternalReferenceTableOffset - kIsolateRootBias; } // Root-register-relative offset of the builtins table. static constexpr int builtins_table_offset() { return kBuiltinsTableOffset - kIsolateRootBias; } // Root-register-relative offset of the given builtin table entry. // TODO(ishell): remove in favour of typified id version. static int builtin_slot_offset(int builtin_index) { DCHECK(Builtins::IsBuiltinId(builtin_index)); return builtins_table_offset() + builtin_index * kPointerSize; } // Root-register-relative offset of the builtin table entry. static int builtin_slot_offset(Builtins::Name id) { return builtins_table_offset() + id * kPointerSize; } // Root-register-relative offset of the virtual call target register value. static constexpr int virtual_call_target_register_offset() { return kVirtualCallTargetRegisterOffset - kIsolateRootBias; } // The FP and PC that are saved right before TurboAssembler::CallCFunction. Address* fast_c_call_caller_fp_address() { return &fast_c_call_caller_fp_; } Address* fast_c_call_caller_pc_address() { return &fast_c_call_caller_pc_; } Address fast_c_call_caller_fp() { return fast_c_call_caller_fp_; } Address fast_c_call_caller_pc() { return fast_c_call_caller_pc_; } // Returns true if this address points to data stored in this instance. // If it's the case then the value can be accessed indirectly through the // root register. bool contains(Address address) const { STATIC_ASSERT(std::is_unsigned::value); Address start = reinterpret_cast(this); return (address - start) < sizeof(*this); } RootsTable& roots() { return roots_; } const RootsTable& roots() const { return roots_; } ExternalReferenceTable* external_reference_table() { return &external_reference_table_; } Address* builtins() { return builtins_; } private: // Static layout definition. #define FIELDS(V) \ V(kEmbedderDataOffset, Internals::kNumIsolateDataSlots* kPointerSize) \ V(kExternalMemoryOffset, kInt64Size) \ V(kExternalMemoryLlimitOffset, kInt64Size) \ V(kExternalMemoryAtLastMarkCompactOffset, kInt64Size) \ V(kRootsTableOffset, RootsTable::kEntriesCount* kPointerSize) \ V(kExternalReferenceTableOffset, ExternalReferenceTable::kSizeInBytes) \ V(kBuiltinsTableOffset, Builtins::builtin_count* kPointerSize) \ V(kVirtualCallTargetRegisterOffset, kPointerSize) \ V(kFastCCallCallerFPOffset, kPointerSize) \ V(kFastCCallCallerPCOffset, kPointerSize) \ /* This padding aligns IsolateData size by 8 bytes. */ \ V(kPaddingOffset, \ 8 + RoundUp<8>(static_cast