v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
macro-assembler-base.cc
Go to the documentation of this file.
1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
10#include "src/common/globals.h"
14
15namespace v8 {
16namespace internal {
17
19 const AssemblerOptions& options,
20 CodeObjectRequired create_code_object,
21 std::unique_ptr<AssemblerBuffer> buffer)
22 : MacroAssemblerBase(isolate, isolate->allocator(), options,
23 create_code_object, std::move(buffer)) {}
24
27 AssemblerOptions options,
28 CodeObjectRequired create_code_object,
29 std::unique_ptr<AssemblerBuffer> buffer)
30 : Assembler(zone, options, std::move(buffer)), isolate_(isolate) {
31 if (create_code_object == CodeObjectRequired::kYes) {
33 ReadOnlyRoots(isolate).self_reference_marker(), isolate);
34 }
35}
39 if (isolate_ != nullptr) {
41 DCHECK_EQ(entry,
42 EmbeddedData::FromBlob(isolate_).InstructionStartOf(builtin));
43 return entry;
44 }
46 return d.InstructionStartOf(builtin);
47}
48
50 Handle<HeapObject> object) {
52
53 // Before falling back to the (fairly slow) lookup from the constants table,
54 // check if any of the fast paths can be applied.
55
57 RootIndex root_index;
58 if (isolate()->roots_table().IsRootHandle(object, &root_index)) {
59 // Roots are loaded relative to the root register.
60 LoadRoot(destination, root_index);
61 } else if (isolate()->builtins()->IsBuiltinHandle(object, &builtin)) {
62 // Similar to roots, builtins may be loaded from the builtins table.
64 } else if (object.is_identical_to(code_object_) &&
66 // The self-reference loaded through Codevalue() may also be a builtin
67 // and thus viable for a fast load.
69 } else {
70 CHECK(isolate()->IsGeneratingEmbeddedBuiltins());
71 // Ensure the given object is in the builtins constants table and fetch its
72 // index.
75 uint32_t index = builder->AddObject(object);
76
77 // Slow load from the constants table.
79 }
80}
81
85
86 if (IsAddressableThroughRootRegister(isolate(), reference)) {
87 // Some external references can be efficiently loaded as an offset from
88 // kRootRegister.
89 intptr_t offset =
92 } else {
93 // Otherwise, do a memory load from the external reference table.
97 }
98}
99
100// static
105
106// static
110
111// static
113 Isolate* isolate, const ExternalReference& reference) {
114 if (reference.IsIsolateFieldId()) {
115 return reference.offset_from_root_register();
116 }
117 return static_cast<intptr_t>(reference.address() - isolate->isolate_root());
118}
119
120// static
122 Isolate* isolate, const ExternalReference& reference) {
123 // Encode as an index into the external reference table stored on the
124 // isolate.
125 ExternalReferenceEncoder encoder(isolate);
126 ExternalReferenceEncoder::Value v = encoder.Encode(reference.address());
127 CHECK(!v.is_from_api());
128
129 return IsolateData::external_reference_table_offset() +
131}
132
133// static
135 Isolate* isolate, const ExternalReference& reference) {
136 if (reference.IsIsolateFieldId()) return true;
137
138 Address address = reference.address();
139 return isolate->root_register_addressable_region().contains(address);
140}
141
142// static
144 Isolate* isolate) {
145 DCHECK(CanBeImmediate(index));
146 Tagged<Object> obj = isolate->root(index);
147 CHECK(IsHeapObject(obj));
149}
150
154
155} // namespace internal
156} // namespace v8
Isolate * isolate_
static constexpr int ToInt(Builtin id)
Definition builtins.h:144
static constexpr bool IsBuiltinId(Builtin builtin)
Definition builtins.h:128
static EmbeddedData FromBlob()
static constexpr uint32_t OffsetOfEntry(uint32_t i)
V8_EXPORT_PRIVATE Address address() const
static V8_INLINE Handle< T > New(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:46
static constexpr int root_slot_offset(RootIndex root_index)
static constexpr int BuiltinSlotOffset(Builtin id)
BuiltinsConstantsTableBuilder * builtins_constants_table_builder() const
Definition isolate.h:1901
Address * builtin_entry_table()
Definition isolate.h:1283
Address BuiltinEntry(Builtin builtin)
virtual void LoadRoot(Register destination, RootIndex index)=0
static bool IsAddressableThroughRootRegister(Isolate *isolate, const ExternalReference &reference)
virtual void LoadRootRelative(Register destination, int32_t offset)=0
static constexpr bool CanBeImmediate(RootIndex index)
virtual void LoadRootRegisterOffset(Register destination, intptr_t offset)=0
MacroAssemblerBase(Isolate *isolate, CodeObjectRequired create_code_object, std::unique_ptr< AssemblerBuffer > buffer={})
static int32_t RootRegisterOffsetForExternalReferenceTableEntry(Isolate *isolate, const ExternalReference &reference)
static int32_t RootRegisterOffsetForRootIndex(RootIndex root_index)
virtual void LoadFromConstantsTable(Register destination, int constant_index)=0
Tagged_t ReadOnlyRootPtr(RootIndex index)
IndirectHandle< HeapObject > code_object_
void IndirectLoadConstant(Register destination, Handle< HeapObject > object)
static intptr_t RootRegisterOffsetForExternalReference(Isolate *isolate, const ExternalReference &reference)
void IndirectLoadExternalReference(Register destination, ExternalReference reference)
static int32_t RootRegisterOffsetForBuiltin(Builtin builtin)
V8_INLINE constexpr StorageType ptr() const
static V8_INLINE Tagged_t CompressObject(Address tagged)
int32_t offset
InstructionOperand destination
STL namespace.
std::variant< Zone *, AccountingAllocator * > MaybeAssemblerZone
Definition assembler.h:262
Address Tagged_t
Definition globals.h:547
V8_INLINE constexpr bool IsHeapObject(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:669
#define CHECK(condition)
Definition logging.h:124
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485