[ext-code-space] Store builtins' stack slots count in embedded data

Previously these values weres stored only in the Code object associated
with the embedded builtins.

Bug: v8:11880
Change-Id: I8adf3f654c5c729a8cb58fc6941999b4c251896a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3764442
Auto-Submit: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81755}
This commit is contained in:
ishell@chromium.org 2022-07-15 17:11:00 +02:00 committed by V8 LUCI CQ
parent 88e538179e
commit 5d8ac381fe
6 changed files with 51 additions and 2 deletions

View File

@ -806,6 +806,12 @@ bool Code::uses_safepoint_table() const {
return is_turbofanned() || is_maglevved() || is_wasm_code();
}
#ifdef V8_EXTERNAL_CODE_SPACE
bool CodeDataContainer::uses_safepoint_table() const {
return is_turbofanned() || is_maglevved() || is_wasm_code();
}
#endif // V8_EXTERNAL_CODE_SPACE
int Code::stack_slots() const {
const uint32_t flags = RELAXED_READ_UINT32_FIELD(*this, kFlagsOffset);
const int slots = StackSlotsField::decode(flags);
@ -813,6 +819,14 @@ int Code::stack_slots() const {
return slots;
}
#ifdef V8_EXTERNAL_CODE_SPACE
int CodeDataContainer::stack_slots() const {
return V8_UNLIKELY(is_off_heap_trampoline())
? OffHeapStackSlots(*this, builtin_id())
: code().stack_slots();
}
#endif // V8_EXTERNAL_CODE_SPACE
bool CodeDataContainer::marked_for_deoptimization() const {
#ifdef V8_EXTERNAL_CODE_SPACE
// kind field is not available on CodeDataContainer when external code space
@ -866,6 +880,12 @@ bool Code::is_optimized_code() const {
bool Code::is_wasm_code() const { return kind() == CodeKind::WASM_FUNCTION; }
#ifdef V8_EXTERNAL_CODE_SPACE
bool CodeDataContainer::is_wasm_code() const {
return kind() == CodeKind::WASM_FUNCTION;
}
#endif
int Code::constant_pool_offset() const {
if (!FLAG_enable_embedded_constant_pool) {
// Redirection needed since the field doesn't exist in this case.

View File

@ -145,6 +145,11 @@ int OffHeapUnwindingInfoSize(HeapObject code, Builtin builtin) {
return d.UnwindingInfoSizeOf(builtin);
}
int OffHeapStackSlots(HeapObject code, Builtin builtin) {
EmbeddedData d = EmbeddedDataWithMaybeRemappedEmbeddedBuiltins(code);
return d.StackSlotsOf(builtin);
}
void Code::ClearEmbeddedObjects(Heap* heap) {
HeapObject undefined = ReadOnlyRoots(heap).undefined_value();
int mode_mask = RelocInfo::EmbeddedObjectModeMask();

View File

@ -152,6 +152,14 @@ class CodeDataContainer : public HeapObject {
// this is a trampoline to an off-heap builtin.
inline bool is_off_heap_trampoline() const;
// [uses_safepoint_table]: Whether this Code object uses safepoint tables
// (note the table may still be empty, see has_safepoint_table).
inline bool uses_safepoint_table() const;
// [stack_slots]: If {uses_safepoint_table()}, the number of stack slots
// reserved in the code prologue; otherwise 0.
inline int stack_slots() const;
DECL_GETTER(deoptimization_data, FixedArray)
DECL_GETTER(bytecode_or_interpreter_data, HeapObject)
DECL_GETTER(source_position_table, ByteArray)
@ -788,6 +796,7 @@ V8_EXPORT_PRIVATE Address OffHeapUnwindingInfoAddress(HeapObject code,
Builtin builtin);
V8_EXPORT_PRIVATE int OffHeapUnwindingInfoSize(HeapObject code,
Builtin builtin);
V8_EXPORT_PRIVATE int OffHeapStackSlots(HeapObject code, Builtin builtin);
// Represents result of the code by inner address (or pc) lookup.
// When V8_EXTERNAL_CODE_SPACE is disabled there might be two variants:

View File

@ -131,6 +131,12 @@ uint32_t EmbeddedData::UnwindingInfoSizeOf(Builtin builtin) const {
return desc.metadata_length - desc.unwinding_info_offset_offset;
}
uint32_t EmbeddedData::StackSlotsOf(Builtin builtin) const {
DCHECK(Builtins::IsBuiltinId(builtin));
const struct LayoutDescription& desc = LayoutDescription(builtin);
return desc.stack_slots;
}
Address EmbeddedData::InstructionStartOfBytecodeHandlers() const {
return InstructionStartOfBuiltin(Builtin::kFirstBytecodeHandler);
}

View File

@ -312,6 +312,9 @@ EmbeddedData EmbeddedData::FromIsolate(Isolate* isolate) {
raw_data_size + static_cast<uint32_t>(code.code_comments_offset());
layout_desc.unwinding_info_offset_offset =
raw_data_size + static_cast<uint32_t>(code.unwinding_info_offset());
layout_desc.stack_slots = static_cast<uint32_t>(code.stack_slots());
CHECK_EQ(code.deoptimization_data().length(), 0);
}
// Align the start of each section.
raw_code_size += PadAndAlignCode(instruction_size);

View File

@ -152,6 +152,8 @@ class EmbeddedData final {
inline Address UnwindingInfoStartOf(Builtin builtin) const;
inline uint32_t UnwindingInfoSizeOf(Builtin builtin) const;
inline uint32_t StackSlotsOf(Builtin builtin) const;
uint32_t AddressForHashing(Address addr) {
DCHECK(IsInCodeRange(addr));
Address start = reinterpret_cast<Address>(code_);
@ -197,6 +199,8 @@ class EmbeddedData final {
#endif
uint32_t code_comments_offset_offset;
uint32_t unwinding_info_offset_offset;
uint32_t stack_slots;
};
static_assert(offsetof(LayoutDescription, instruction_offset) ==
0 * kUInt32Size);
@ -215,13 +219,15 @@ class EmbeddedData final {
6 * kUInt32Size);
static_assert(offsetof(LayoutDescription, unwinding_info_offset_offset) ==
7 * kUInt32Size);
static_assert(sizeof(LayoutDescription) == 8 * kUInt32Size);
static_assert(offsetof(LayoutDescription, stack_slots) == 8 * kUInt32Size);
static_assert(sizeof(LayoutDescription) == 9 * kUInt32Size);
#else
static_assert(offsetof(LayoutDescription, code_comments_offset_offset) ==
5 * kUInt32Size);
static_assert(offsetof(LayoutDescription, unwinding_info_offset_offset) ==
6 * kUInt32Size);
static_assert(sizeof(LayoutDescription) == 7 * kUInt32Size);
static_assert(offsetof(LayoutDescription, stack_slots) == 7 * kUInt32Size);
static_assert(sizeof(LayoutDescription) == 8 * kUInt32Size);
#endif
// The layout of the blob is as follows: