5#ifndef V8_OBJECTS_CODE_INL_H_
6#define V8_OBJECTS_CODE_INL_H_
35#define GCSAFE_CODE_FWD_ACCESSOR(ReturnType, Name) \
36 ReturnType GcSafeCode::Name() const { return UnsafeCastToCode()->Name(); }
56#undef GCSAFE_CODE_FWD_ACCESSOR
76 for (
int i = 0;
i < deopt_data->DeoptCount();
i++) {
77 if (deopt_data->Pc(
i).value() == -1)
continue;
79 if (
address ==
pc && deopt_data->GetBytecodeOffsetOrBuiltinContinuationId(
98inline uint16_t
Code::parameter_count_without_receiver()
const {
115 *
this, kDeoptimizationDataOrInterpreterDataOffset, value, mode);
128 kDeoptimizationDataOrInterpreterDataOffset);
138 DCHECK(IsBytecodeArray(value) || IsInterpreterData(value));
142 *
this, kDeoptimizationDataOrInterpreterDataOffset, value, mode);
201 if (
kind() == CodeKind::BASELINE) {
202 return sfi->GetBytecodeArray(isolate)->SourcePositionTable(isolate);
205 if (!has_source_position_table()) {
206 return *isolate->factory()->empty_trusted_byte_array();
209 return source_position_table();
219 return instruction_start() + instruction_size();
225 return instruction_start() + instruction_size();
251 return static_cast<int>(
offset);
273 return constant_pool_offset() - handler_table_offset();
279 const int size = code_comments_offset() - constant_pool_offset();
297 ? instruction_stream()->relocation_start()
303 ? instruction_stream()->relocation_end()
309 ? instruction_stream()->relocation_size()
315 if (inner_pointer <
start)
return false;
316 return inner_pointer <
start + instruction_size();
327 size += deoptimization_data()->Size();
342 Address pc = baseline_pc - instruction_start();
357 if (IsBytecodeArray(maybe_bytecodes)) {
360 CHECK(IsInterpreterData(maybe_bytecodes));
396 reinterpret_cast<Address*
>(&bytecodes));
400 if (bytecode == interpreter::Bytecode::kJumpLoop) {
412 bool checks_state = (
builtin_id() == Builtin::kCompileLazy ||
413 builtin_id() == Builtin::kInterpreterEntryTrampoline ||
415 return checks_state ||
420 return kind != CodeKind::JS_TO_WASM_FUNCTION &&
421 kind != CodeKind::C_WASM_ENTRY &&
kind != CodeKind::WASM_FUNCTION;
425#if V8_ENABLE_WEBASSEMBLY
443unsigned Code::inlined_bytecode_size()
const {
449void Code::set_inlined_bytecode_size(
unsigned size) {
459void Code::set_wasm_js_tagged_parameter_count(uint16_t count) {
464uint16_t Code::wasm_js_tagged_parameter_count()
const {
469void Code::set_wasm_js_first_tagged_parameter(uint16_t count) {
474uint16_t Code::wasm_js_first_tagged_parameter()
const {
479BytecodeOffset Code::osr_offset()
const {
483void Code::set_osr_offset(BytecodeOffset
offset) {
501bool Code::marked_for_deoptimization()
const {
505void Code::set_marked_for_deoptimization(
bool flag) {
509 int32_t updated = MarkedForDeoptimizationField::update(
previous, flag);
515 set_marked_for_deoptimization(
true);
517 if (reason != LazyDeoptimizeReason::kEagerDeopt &&
521#ifdef V8_ENABLE_LEAPTIERING
527 if (
v8_flags.reopt_after_lazy_deopts &&
528 isolate->concurrent_recompilation_enabled()) {
529 jdt->SetCodeNoWriteBarrier(
539 case LazyDeoptimizeReason::kAllocationSiteTenuringChange:
540 case LazyDeoptimizeReason::kAllocationSiteTransitionChange:
541 case LazyDeoptimizeReason::kEmptyContextExtensionChange:
542 case LazyDeoptimizeReason::kFrameValueMaterialized:
543 case LazyDeoptimizeReason::kPropertyCellChange:
544 case LazyDeoptimizeReason::kScriptContextSlotPropertyChange:
545 case LazyDeoptimizeReason::kPrototypeChange:
546 case LazyDeoptimizeReason::kExceptionCaught:
547 case LazyDeoptimizeReason::kFieldTypeConstChange:
548 case LazyDeoptimizeReason::kFieldRepresentationChange:
549 case LazyDeoptimizeReason::kFieldTypeChange:
550 case LazyDeoptimizeReason::kInitialMapChange:
551 case LazyDeoptimizeReason::kMapDeprecated:
552 jdt->SetTieringRequest(
553 handle, TieringBuiltin::kMarkReoptimizeLazyDeoptimized,
560 jdt->SetTieringRequest(
handle, TieringBuiltin::kMarkLazyDeoptimized,
581 int32_t updated = Code::EmbeddedObjectsClearedField::update(
previous, flag);
585inline bool Code::can_have_weak_objects()
const {
589inline void Code::set_can_have_weak_objects(
bool value) {
591 int32_t updated = CanHaveWeakObjectsField::update(
previous, value);
597int Code::constant_pool_offset()
const {
600 return code_comments_offset();
605void Code::set_constant_pool_offset(
int value) {
624 return builtin_jump_table_info_offset() - code_comments_offset();
629int32_t Code::builtin_jump_table_info_offset()
const {
632 return unwinding_info_offset();
637void Code::set_builtin_jump_table_info_offset(int32_t value) {
651 return unwinding_info_offset() - builtin_jump_table_info_offset();
685 if (InstanceTypeChecker::IsMap(map_object)) {
686 return Cast<Map>(
object)->CanTransition();
688 return InstanceTypeChecker::IsPropertyCell(map_object) ||
689 InstanceTypeChecker::IsJSReceiver(map_object) ||
690 InstanceTypeChecker::IsContext(map_object);
710 if (deopt_data->length() == 0)
return;
713 const int literals_length = literals->length();
714 for (
int i = 0;
i < literals_length; ++
i) {
726 return Code::raw_instruction_stream(cage_base);
729Tagged<Object> Code::raw_instruction_stream(PtrComprCageBase cage_base)
const {
730 return ExternalCodeField<Object>::load(cage_base, *
this);
735 ExternalCodeField<Object>::Release_Store(*
this, value);
740#if defined(V8_COMPRESS_POINTERS) || !defined(V8_HOST_ARCH_64_BIT)
750#if defined(V8_COMPRESS_POINTERS) || !defined(V8_HOST_ARCH_64_BIT)
751 const uint32_t value =
754 const uint64_t value =
755 RELAXED_READ_INT64_FIELD(*
this, kInstructionStreamOffset);
762#ifdef V8_EXTERNAL_CODE_SPACE
774 return Code::instruction_stream(cage_base);
784 return ExternalCodeField<InstructionStream>::load(cage_base, *
this);
789 return Code::instruction_stream(cage_base, tag);
793 RelaxedLoadTag tag)
const {
795 return ExternalCodeField<InstructionStream>::Relaxed_Load(cage_base, *
this);
798Tagged<Object> Code::raw_instruction_stream(RelaxedLoadTag tag)
const {
800 return Code::raw_instruction_stream(cage_base, tag);
803Tagged<Object> Code::raw_instruction_stream(PtrComprCageBase cage_base,
804 RelaxedLoadTag tag)
const {
805 return ExternalCodeField<Object>::Relaxed_Load(cage_base, *
this);
809#ifdef V8_ENABLE_SANDBOX
813 return ReadField<Address>(kInstructionStartOffset);
818#ifdef V8_ENABLE_SANDBOX
828 case CodeKind::BYTECODE_HANDLER:
830 case CodeKind::BUILTIN:
832 case CodeKind::REGEXP:
834 case CodeKind::WASM_FUNCTION:
835 case CodeKind::WASM_TO_CAPI_FUNCTION:
836 case CodeKind::WASM_TO_JS_FUNCTION:
838 case CodeKind::JS_TO_WASM_FUNCTION:
849 set_raw_instruction_stream(code, mode);
860#ifdef V8_ENABLE_SANDBOX
871 DCHECK_EQ(raw_instruction_stream(), istream);
876 memset(
reinterpret_cast<void*
>(
address() + kUnalignedSize), 0,
877 kSize - kUnalignedSize);
883 bool is_turbofanned) {
885 uint32_t value = KindField::encode(
kind) |
886 IsContextSpecializedField::encode(is_context_specialized) |
887 IsTurbofannedField::encode(is_turbofanned);
896static_assert(Builtins::kBuiltinCount < std::numeric_limits<int16_t>::max());
929 return builtin_id() == Builtin::kBaselineLeaveFrame;
932#ifdef V8_ENABLE_LEAPTIERING
#define BUILTIN_CODE(isolate, name)
#define SBXCHECK_EQ(lhs, rhs)
#define SLOW_DCHECK(condition)
static V8_EXPORT_PRIVATE CodeEntrypointTag EntrypointTagFor(Builtin builtin)
static constexpr BytecodeOffset None()
void set_instruction_start(IsolateForSandbox isolate, Address value)
Address builtin_jump_table_info() const
bool checks_tiering_state() const
bool has_source_position_table() const
Tagged< InstructionStream > unchecked_instruction_stream() const
int InstructionStreamObjectSize() const
void TraceMarkForDeoptimization(Isolate *isolate, LazyDeoptimizeReason reason)
bool is_baseline_trampoline_builtin() const
uintptr_t GetBaselinePCForBytecodeOffset(int bytecode_offset, BytecodeToPCPosition position, Tagged< BytecodeArray > bytecodes)
CodeEntrypointTag entrypoint_tag() const
bool CanContainWeakObjects()
int handler_table_size() const
uint32_t stack_slots() const
Address InstructionStart(Isolate *isolate, Address pc) const
bool uses_safepoint_table() const
Address body_start() const
void set_embedded_objects_cleared(bool flag)
Address unwinding_info_end() const
void SetInstructionStreamAndInstructionStart(IsolateForSandbox isolate, Tagged< InstructionStream > code, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
static Tagged< Code > FromTargetAddress(Address address)
Address metadata_end() const
Address instruction_end() const
bool is_turbofanned() const
void clear_source_position_table_and_bytecode_offset_table()
int unwinding_info_size() const
bool has_deoptimization_data_or_interpreter_data() const
void SetMarkedForDeoptimization(Isolate *isolate, LazyDeoptimizeReason reason)
bool has_tagged_outgoing_params() const
int code_comments_size() const
int safepoint_table_offset() const
int constant_pool_size() const
Address constant_pool() const
bool is_wasm_code() const
void set_bytecode_or_interpreter_data(Tagged< TrustedObject > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
uintptr_t GetBaselineStartPCForBytecodeOffset(int bytecode_offset, Tagged< BytecodeArray > bytecodes)
int SizeIncludingMetadata() const
bool contains(Isolate *isolate, Address pc) const
bool IsWeakObject(Tagged< HeapObject > object)
Address handler_table_address() const
uintptr_t GetBaselineEndPCForBytecodeOffset(int bytecode_offset, Tagged< BytecodeArray > bytecodes)
uintptr_t GetBaselinePCForNextExecutedBytecode(int bytecode_offset, Tagged< BytecodeArray > bytecodes)
Tagged< TrustedObject > bytecode_or_interpreter_data() const
uint8_t * relocation_end() const
bool is_optimized_code() const
bool has_unwinding_info() const
bool is_interpreter_trampoline_builtin() const
Address InstructionEnd(Isolate *isolate, Address pc) const
int safepoint_table_size() const
int relocation_size() const
void SetInstructionStartForOffHeapBuiltin(IsolateForSandbox isolate, Address entry)
bool has_constant_pool() const
Address safepoint_table_address() const
Address unwinding_info_start() const
bool is_context_specialized() const
void set_builtin_id(Builtin builtin_id)
bool has_handler_table() const
int GetOffsetFromInstructionStart(Isolate *isolate, Address pc) const
bool has_safepoint_table() const
void ClearInstructionStartForSerialization(IsolateForSandbox isolate)
bool is_baseline_leave_frame_builtin() const
Tagged< ProtectedFixedArray > unchecked_deoptimization_data() const
static bool IsWeakObjectInOptimizedCode(Tagged< HeapObject > object)
int builtin_jump_table_info_size() const
void IterateDeoptimizationLiterals(RootVisitor *v)
Address code_comments() const
bool uses_deoptimization_data() const
int GetBytecodeOffsetForBaselinePC(Address baseline_pc, Tagged< BytecodeArray > bytecodes)
static bool IsWeakObjectInDeoptimizationLiteralArray(Tagged< Object > object)
uint8_t * relocation_start() const
bool has_code_comments() const
bool embedded_objects_cleared() const
bool is_maglevved() const
void UpdateInstructionStart(IsolateForSandbox isolate, Tagged< InstructionStream > istream)
PtrComprCageBase code_cage_base() const
Address metadata_start() const
Builtin builtin_id() const
void clear_deoptimization_data_and_interpreter_data()
bool has_builtin_jump_table_info() const
bool has_bytecode_offset_table() const
bool has_instruction_stream() const
bool has_source_position_table_or_bytecode_offset_table() const
Address InstructionStartOf(Builtin builtin) const
Address MetadataStartOf(Builtin builtin) const
static EmbeddedData FromBlob()
static EmbeddedData FromBlobForPc(Isolate *isolate, Address maybe_builtin_pc)
Address InstructionEnd(Isolate *isolate, Address pc) const
bool CanDeoptAt(Isolate *isolate, Address pc) const
Tagged< Object > raw_instruction_stream() const
Address InstructionStart(Isolate *isolate, Address pc) const
Tagged< Code > UnsafeCastToCode() const
int GetOffsetFromInstructionStart(Isolate *isolate, Address pc) const
Address instruction_start() const
static V8_INLINE bool InYoungGeneration(Tagged< Object > object)
static V8_INLINE bool InReadOnlySpace(Tagged< HeapObject > object)
void Relaxed_WriteField(size_t offset, T value)
T ReadField(size_t offset) const
void WriteField(size_t offset, T value) const
static NEVER_READ_ONLY_SPACE constexpr bool kOnHeapBodyIsContiguous
static constexpr bool kOffHeapBodyIsContiguous
static Tagged< InstructionStream > FromTargetAddress(Address address)
static constexpr int SizeFor(int body_size)
static IsolateGroup * current()
virtual void VisitRootPointer(Root root, const char *description, FullObjectSlot p)
static constexpr Tagged< Smi > zero()
static PtrType load(Tagged< HeapObject > host, int offset=0)
static void store(Tagged< HeapObject > host, PtrType value)
friend class FullObjectSlot
constexpr bool SafeEquals(TaggedImpl< kOtherRefType, Address > other) const
bool GetHeapObject(Tagged< HeapObject > *result) const
constexpr bool IsHeapObject() const
void ClearProtectedPointerField(int offset)
void WriteProtectedPointerField(int offset, Tagged< TrustedObject > value)
bool IsProtectedPointerFieldEmpty(int offset) const
Tagged< TrustedObject > ReadProtectedPointerField(int offset) const
void AdvanceToPCOffset(Address pc_offset)
Address current_pc_end_offset() const
void AdvanceToBytecodeOffset(int bytecode_offset)
int current_bytecode_offset() const
Address current_pc_start_offset() const
Bytecode current_bytecode() const
int GetJumpTargetOffset() const
static constexpr bool Returns(Bytecode bytecode)
static constexpr bool IsSwitch(Bytecode bytecode)
static constexpr bool IsJump(Bytecode bytecode)
#define GCSAFE_CODE_FWD_ACCESSOR(ReturnType, Name)
#define V8_EMBEDDED_CONSTANT_POOL_BOOL
#define V8_BUILTIN_JUMP_TABLE_INFO_BOOL
base::SmallVector< int32_t, 1 > stack_slots
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
V8_INLINE Address ReadCodeEntrypointViaCodePointerField(Address field_address, CodeEntrypointTag tag)
constexpr bool CodeKindIsOptimizedJSFunction(CodeKind kind)
uint32_t SafepointTableStackSlotsField_t
V8_INLINE constexpr bool IsInterpreterTrampolineBuiltin(Builtin builtin_id)
constexpr int kSafepointTableStackSlotsOffset
constexpr bool CodeKindCanTierUp(CodeKind kind)
Tagged(T object) -> Tagged< T >
V8_INLINE constexpr bool IsBaselineTrampolineBuiltin(Builtin builtin_id)
@ kBytecodeHandlerEntrypointTag
@ kDefaultCodeEntrypointTag
V8_INLINE Isolate * GetIsolateFromWritableObject(Tagged< HeapObject > object)
base::StrongAlias< JSDispatchHandleAliasTag, uint32_t > JSDispatchHandle
constexpr int kFunctionExitBytecodeOffset
constexpr bool CodeKindIsInterpretedJSFunction(CodeKind kind)
Handle< To > UncheckedCast(Handle< From > value)
V8_INLINE PtrComprCageBase GetPtrComprCageBase()
constexpr JSDispatchHandle kNullJSDispatchHandle(0)
constexpr bool CodeKindMayLackSourcePositionTable(CodeKind kind)
constexpr bool CodeKindHasTaggedOutgoingParams(CodeKind kind)
V8_EXPORT_PRIVATE FlagValues v8_flags
constexpr CodePointerHandle kNullCodePointerHandle
static constexpr Address kNullAddress
constexpr bool CodeKindUsesDeoptimizationData(CodeKind kind)
constexpr bool CodeKindUsesBytecodeOffsetTable(CodeKind kind)
V8_INLINE void WriteCodeEntrypointViaCodePointerField(Address field_address, Address value, CodeEntrypointTag tag)
constexpr bool CodeKindCanDeoptimize(CodeKind kind)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
static constexpr RelaxedLoadTag kRelaxedLoad
static constexpr RelaxedStoreTag kRelaxedStore
static constexpr AcquireLoadTag kAcquireLoad
#define RELAXED_WRITE_INT32_FIELD(p, offset, value)
#define RELAXED_WRITE_UINT_FIELD(p, offset, value)
#define CODE_POINTER_ACCESSORS(holder, name, offset)
#define OBJECT_CONSTRUCTORS_IMPL(Type, Super)
#define RELAXED_READ_INT32_FIELD(p, offset)
#define CONDITIONAL_PROTECTED_POINTER_WRITE_BARRIER(object, offset, value, mode)
#define UINT16_ACCESSORS(holder, name, offset)
#define RELAXED_READ_UINT_FIELD(p, offset)
#define ACCESSORS(holder, name, type, offset)
#define INT_ACCESSORS(holder, name, offset)
#define CONDITIONAL_WRITE_BARRIER(object, offset, value, mode)
#define INT32_ACCESSORS(holder, name, offset)
#define RELAXED_WRITE_UINT16_FIELD(p, offset, value)
#define RELAXED_UINT32_ACCESSORS(holder, name, offset)
#define RELAXED_READ_UINT16_FIELD(p, offset)
#define DEF_GETTER(Camel, Lower, Bit)
#define DCHECK_LE(v1, v2)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_GE(v1, v2)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
#define V8_LIKELY(condition)
#define V8_UNLIKELY(condition)