5 #ifndef V8_RELOC_INFO_H_ 6 #define V8_RELOC_INFO_H_ 8 #include "src/globals.h" 9 #include "src/objects.h" 10 #include "src/objects/code.h" 23 enum ICacheFlushMode { FLUSH_ICACHE_IF_NEEDED, SKIP_ICACHE_FLUSH };
41 static const char*
const kFillerCommentString;
45 static const int kMinRelocCommentSize = 2 + kPointerSize;
48 static const int kMaxCallSize = 6;
51 static const int kMaxSmallPCDelta;
71 INTERNAL_REFERENCE_ENCODED,
94 LAST_CODE_TARGET_MODE = RELATIVE_CODE_TARGET,
95 FIRST_REAL_RELOC_MODE = CODE_TARGET,
96 LAST_REAL_RELOC_MODE = VENEER_POOL,
97 LAST_GCED_ENUM = EMBEDDED_OBJECT,
98 FIRST_SHAREABLE_RELOC_MODE = WASM_CALL,
101 STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt);
106 Address constant_pool = kNullAddress)
111 constant_pool_(constant_pool) {}
113 static constexpr
bool IsRealRelocMode(Mode mode) {
114 return mode >= FIRST_REAL_RELOC_MODE && mode <= LAST_REAL_RELOC_MODE;
117 static constexpr
bool IsGCRelocMode(Mode mode) {
118 return mode <= LAST_GCED_ENUM;
120 static constexpr
bool IsShareableRelocMode(Mode mode) {
121 static_assert(RelocInfo::NONE >= RelocInfo::FIRST_SHAREABLE_RELOC_MODE,
122 "Users of this function rely on NONE being a sharable " 124 return mode >= RelocInfo::FIRST_SHAREABLE_RELOC_MODE;
126 static constexpr
bool IsCodeTarget(Mode mode) {
return mode == CODE_TARGET; }
127 static constexpr
bool IsCodeTargetMode(Mode mode) {
128 return mode <= LAST_CODE_TARGET_MODE;
130 static constexpr
bool IsRelativeCodeTarget(Mode mode) {
131 return mode == RELATIVE_CODE_TARGET;
133 static constexpr
bool IsEmbeddedObject(Mode mode) {
134 return mode == EMBEDDED_OBJECT;
136 static constexpr
bool IsRuntimeEntry(Mode mode) {
137 return mode == RUNTIME_ENTRY;
139 static constexpr
bool IsWasmCall(Mode mode) {
return mode == WASM_CALL; }
140 static constexpr
bool IsWasmReference(Mode mode) {
return mode == WASM_CALL; }
141 static constexpr
bool IsWasmStubCall(Mode mode) {
142 return mode == WASM_STUB_CALL;
144 static constexpr
bool IsComment(Mode mode) {
return mode == COMMENT; }
145 static constexpr
bool IsConstPool(Mode mode) {
return mode == CONST_POOL; }
146 static constexpr
bool IsVeneerPool(Mode mode) {
return mode == VENEER_POOL; }
147 static constexpr
bool IsDeoptPosition(Mode mode) {
148 return mode == DEOPT_SCRIPT_OFFSET || mode == DEOPT_INLINING_ID;
150 static constexpr
bool IsDeoptReason(Mode mode) {
151 return mode == DEOPT_REASON;
153 static constexpr
bool IsDeoptId(Mode mode) {
return mode == DEOPT_ID; }
154 static constexpr
bool IsExternalReference(Mode mode) {
155 return mode == EXTERNAL_REFERENCE;
157 static constexpr
bool IsInternalReference(Mode mode) {
158 return mode == INTERNAL_REFERENCE;
160 static constexpr
bool IsInternalReferenceEncoded(Mode mode) {
161 return mode == INTERNAL_REFERENCE_ENCODED;
163 static constexpr
bool IsOffHeapTarget(Mode mode) {
164 return mode == OFF_HEAP_TARGET;
166 static constexpr
bool IsNone(Mode mode) {
return mode == NONE; }
168 static bool IsOnlyForSerializer(Mode mode) {
169 #ifdef V8_TARGET_ARCH_IA32 171 DCHECK_NE((kApplyMask & ModeMask(OFF_HEAP_TARGET)), 0);
172 DCHECK_EQ((kApplyMask & ModeMask(EXTERNAL_REFERENCE)), 0);
173 return mode == EXTERNAL_REFERENCE;
175 DCHECK_EQ((kApplyMask & ModeMask(OFF_HEAP_TARGET)), 0);
176 DCHECK_EQ((kApplyMask & ModeMask(EXTERNAL_REFERENCE)), 0);
177 return mode == EXTERNAL_REFERENCE || mode == OFF_HEAP_TARGET;
181 static constexpr
int ModeMask(Mode mode) {
return 1 << mode; }
184 Address pc()
const {
return pc_; }
185 Mode rmode()
const {
return rmode_; }
186 intptr_t data()
const {
return data_; }
187 Code host()
const {
return host_; }
188 Address constant_pool()
const {
return constant_pool_; }
194 V8_INLINE
void apply(intptr_t delta);
199 bool IsCodedSpecially();
203 static bool OffHeapTargetIsCodedSpecially();
207 bool IsInConstantPool();
212 int GetDeoptimizationId(
Isolate* isolate, DeoptimizeKind kind);
214 Address wasm_call_address()
const;
215 Address wasm_stub_call_address()
const;
219 void set_wasm_call_address(
220 Address, ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
221 void set_wasm_stub_call_address(
222 Address, ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
224 void set_target_address(
226 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
227 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
231 V8_INLINE
Address target_address();
234 V8_INLINE
void set_target_object(
236 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
237 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
239 V8_INLINE
void set_target_runtime_entry(
241 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
242 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
243 V8_INLINE
Address target_off_heap_target();
244 V8_INLINE
Cell* target_cell();
246 V8_INLINE
void set_target_cell(
247 Cell* cell, WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
248 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
249 V8_INLINE
void set_target_external_reference(
250 Address, ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
254 V8_INLINE
Address constant_pool_entry_address();
262 V8_INLINE
Address target_address_address();
273 V8_INLINE
int target_address_size();
277 V8_INLINE
Address target_external_reference();
281 V8_INLINE
Address target_internal_reference();
285 V8_INLINE
Address target_internal_reference_address();
289 V8_INLINE
void WipeOut();
291 template <
typename ObjectVisitor>
296 static bool RequiresRelocationAfterCodegen(
const CodeDesc& desc);
297 static bool RequiresRelocation(
Code code);
299 #ifdef ENABLE_DISASSEMBLER 301 static const char* RelocModeName(Mode rmode);
302 void Print(
Isolate* isolate, std::ostream& os);
303 #endif // ENABLE_DISASSEMBLER 308 static const int kApplyMask;
313 static int PostCodegenRelocationMask() {
314 return ModeMask(RelocInfo::CODE_TARGET) |
315 ModeMask(RelocInfo::EMBEDDED_OBJECT) |
316 ModeMask(RelocInfo::RUNTIME_ENTRY) |
317 ModeMask(RelocInfo::RELATIVE_CODE_TARGET) | kApplyMask;
327 Address constant_pool_ = kNullAddress;
337 byte* pos()
const {
return pos_; }
338 byte* last_pc()
const {
return last_pc_; }
344 void Reposition(byte* pos, byte* pc) {
351 static constexpr
int kMaxSize = 1 + 4 + 1 + 1 + kPointerSize;
356 inline void WriteShortTaggedPC(
uint32_t pc_delta,
int tag);
357 inline void WriteShortData(intptr_t data_delta);
359 inline void WriteMode(RelocInfo::Mode rmode);
360 inline void WriteModeAndPC(
uint32_t pc_delta, RelocInfo::Mode rmode);
361 inline void WriteIntData(
int data_delta);
362 inline void WriteData(intptr_t data_delta);
396 bool done()
const {
return done_; }
407 const byte* end,
int mode_mask);
412 void Advance(
int bytes = 1) { pos_ -= bytes; }
414 RelocInfo::Mode GetMode();
416 void AdvanceReadLongPCJump();
418 void ReadShortTaggedPC();
419 void ReadShortData();
421 void AdvanceReadPC();
422 void AdvanceReadInt();
423 void AdvanceReadData();
427 bool SetMode(RelocInfo::Mode mode) {
428 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode,
true) :
false;
435 const int mode_mask_;
443 #endif // V8_RELOC_INFO_H_