[ext-code-space] Prepare frame-related code for Code-less builtins, pt.1

Bug: v8:11880
Change-Id: I62e3d309721f3de50c15c0a6e39b82831dd46337
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3780532
Reviewed-by: Patrick Thier <pthier@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Auto-Submit: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81894}
This commit is contained in:
ishell@chromium.org 2022-07-22 13:06:38 +02:00 committed by V8 LUCI CQ
parent edbe337397
commit 38e3ac8f88
6 changed files with 120 additions and 25 deletions

View File

@ -19,6 +19,15 @@ MaglevSafepointTable::MaglevSafepointTable(Isolate* isolate, Address pc,
DCHECK(code.is_maglevved());
}
#ifdef V8_EXTERNAL_CODE_SPACE
MaglevSafepointTable::MaglevSafepointTable(Isolate* isolate, Address pc,
CodeDataContainer code)
: MaglevSafepointTable(code.InstructionStart(isolate, pc),
code.SafepointTableAddress()) {
DCHECK(code.is_maglevved());
}
#endif // V8_EXTERNAL_CODE_SPACE
MaglevSafepointTable::MaglevSafepointTable(Address instruction_start,
Address safepoint_table_address)
: instruction_start_(instruction_start),

View File

@ -63,7 +63,10 @@ class MaglevSafepointTable {
// The isolate and pc arguments are used for figuring out whether pc
// belongs to the embedded or un-embedded code blob.
explicit MaglevSafepointTable(Isolate* isolate, Address pc, Code code);
#ifdef V8_EXTERNAL_CODE_SPACE
explicit MaglevSafepointTable(Isolate* isolate, Address pc,
CodeDataContainer code);
#endif
MaglevSafepointTable(const MaglevSafepointTable&) = delete;
MaglevSafepointTable& operator=(const MaglevSafepointTable&) = delete;

View File

@ -681,8 +681,7 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
switch (lookup_result.kind()) {
case CodeKind::BUILTIN: {
if (StackFrame::IsTypeMarker(marker)) break;
// TODO(v8:11880): avoid unnecessary conversion to Code or CodeT.
Code code_obj = lookup_result.ToCode();
CodeT code_obj = lookup_result.ToCodeT();
if (code_obj.is_interpreter_trampoline_builtin() ||
// Frames for baseline entry trampolines on the stack are still
// interpreted frames.
@ -904,10 +903,10 @@ void BuiltinExitFrame::Summarize(std::vector<FrameSummary>* frames) const {
DCHECK(frames->empty());
Handle<FixedArray> parameters = GetParameters();
DisallowGarbageCollection no_gc;
Code code = LookupCode();
CodeLookupResult code = LookupCodeT();
int code_offset = code.GetOffsetFromInstructionStart(isolate(), pc());
FrameSummary::JavaScriptFrameSummary summary(
isolate(), receiver(), function(), AbstractCode::cast(code), code_offset,
isolate(), receiver(), function(), code.ToAbstractCode(), code_offset,
IsConstructor(), *parameters);
frames->push_back(summary);
}
@ -1094,36 +1093,33 @@ void CommonFrame::IterateCompiledFrame(RootVisitor* v) const {
CHECK(entry->code.IsFound());
code_lookup_result = entry->code;
Code code = entry->code.ToCode();
is_maglev = code.is_maglevved();
is_maglev = code_lookup_result.is_maglevved();
if (is_maglev) {
if (!entry->maglev_safepoint_entry.is_initialized()) {
entry->maglev_safepoint_entry =
entry->code.ToCode().GetMaglevSafepointEntry(isolate(),
inner_pointer);
entry->code.GetMaglevSafepointEntry(isolate(), inner_pointer);
DCHECK(entry->maglev_safepoint_entry.is_initialized());
} else {
DCHECK_EQ(entry->maglev_safepoint_entry,
entry->code.ToCode().GetMaglevSafepointEntry(isolate(),
inner_pointer));
DCHECK_EQ(
entry->maglev_safepoint_entry,
entry->code.GetMaglevSafepointEntry(isolate(), inner_pointer));
}
maglev_safepoint_entry = entry->maglev_safepoint_entry;
} else {
if (!entry->safepoint_entry.is_initialized()) {
entry->safepoint_entry =
entry->code.ToCode().GetSafepointEntry(isolate(), inner_pointer);
entry->code.GetSafepointEntry(isolate(), inner_pointer);
DCHECK(entry->safepoint_entry.is_initialized());
} else {
DCHECK_EQ(
entry->safepoint_entry,
entry->code.ToCode().GetSafepointEntry(isolate(), inner_pointer));
DCHECK_EQ(entry->safepoint_entry,
entry->code.GetSafepointEntry(isolate(), inner_pointer));
}
safepoint_entry = entry->safepoint_entry;
}
stack_slots = code.stack_slots();
stack_slots = entry->code.stack_slots();
has_tagged_outgoing_params = code.has_tagged_outgoing_params();
has_tagged_outgoing_params = entry->code.has_tagged_outgoing_params();
#if V8_ENABLE_WEBASSEMBLY
// With inlined JS-to-Wasm calls, we can be in an OptimizedFrame and
@ -1390,7 +1386,7 @@ Code CommonFrameWithJSLinkage::unchecked_code() const {
}
int TurbofanFrame::ComputeParametersCount() const {
Code code = LookupCode();
CodeLookupResult code = LookupCodeT();
if (code.kind() == CodeKind::BUILTIN) {
return static_cast<int>(
Memory<intptr_t>(fp() + StandardFrameConstants::kArgCOffset)) -
@ -1428,9 +1424,9 @@ bool CommonFrameWithJSLinkage::IsConstructor() const {
void CommonFrameWithJSLinkage::Summarize(
std::vector<FrameSummary>* functions) const {
DCHECK(functions->empty());
Code code = LookupCode();
CodeLookupResult code = LookupCodeT();
int offset = code.GetOffsetFromInstructionStart(isolate(), pc());
Handle<AbstractCode> abstract_code(AbstractCode::cast(code), isolate());
Handle<AbstractCode> abstract_code(code.ToAbstractCode(), isolate());
Handle<FixedArray> params = GetParameters();
FrameSummary::JavaScriptFrameSummary summary(
isolate(), receiver(), function(), *abstract_code, offset,
@ -1847,7 +1843,7 @@ void OptimizedFrame::Summarize(std::vector<FrameSummary>* frames) const {
// Delegate to JS frame in absence of deoptimization info.
// TODO(turbofan): Revisit once we support deoptimization across the board.
Code code = LookupCode();
CodeLookupResult code = LookupCodeT();
if (code.kind() == CodeKind::BUILTIN) {
return JavaScriptFrame::Summarize(frames);
}
@ -1989,7 +1985,7 @@ void OptimizedFrame::GetFunctions(
// Delegate to JS frame in absence of turbofan deoptimization.
// TODO(turbofan): Revisit once we support deoptimization across the board.
Code code = LookupCode();
CodeLookupResult code = LookupCodeT();
if (code.kind() == CodeKind::BUILTIN) {
return JavaScriptFrame::GetFunctions(functions);
}
@ -2525,8 +2521,7 @@ void InternalFrame::Iterate(RootVisitor* v) const {
// the full stack frame contains only tagged pointers or only raw values.
// This is used for the WasmCompileLazy builtin, where we actually pass
// untagged arguments and also store untagged values on the stack.
// TODO(v8:11880): avoid unnecessary conversion to Code or CodeT.
if (code.ToCode().has_tagged_outgoing_params()) IterateExpressions(v);
if (code.has_tagged_outgoing_params()) IterateExpressions(v);
}
// -------------------------------------------------------------------------

View File

@ -473,7 +473,50 @@ CODE_LOOKUP_RESULT_FWD_ACCESSOR(GetBuiltinCatchPrediction,
#undef CODE_LOOKUP_RESULT_FWD_ACCESSOR
int CodeLookupResult::GetOffsetFromInstructionStart(Isolate* isolate,
Address pc) const {
DCHECK(IsFound());
#ifdef V8_EXTERNAL_CODE_SPACE
if (IsCodeDataContainer()) {
return code_data_container().GetOffsetFromInstructionStart(isolate, pc);
}
#endif
return code().GetOffsetFromInstructionStart(isolate, pc);
}
SafepointEntry CodeLookupResult::GetSafepointEntry(Isolate* isolate,
Address pc) const {
DCHECK(IsFound());
#ifdef V8_EXTERNAL_CODE_SPACE
if (IsCodeDataContainer()) {
return code_data_container().GetSafepointEntry(isolate, pc);
}
#endif
return code().GetSafepointEntry(isolate, pc);
}
MaglevSafepointEntry CodeLookupResult::GetMaglevSafepointEntry(
Isolate* isolate, Address pc) const {
DCHECK(IsFound());
#ifdef V8_EXTERNAL_CODE_SPACE
if (IsCodeDataContainer()) {
return code_data_container().GetMaglevSafepointEntry(isolate, pc);
}
#endif
return code().GetMaglevSafepointEntry(isolate, pc);
}
AbstractCode CodeLookupResult::ToAbstractCode() const {
DCHECK(IsFound());
if (V8_REMOVE_BUILTINS_CODE_OBJECTS) {
return IsCodeDataContainer() ? AbstractCode::cast(code_data_container())
: AbstractCode::cast(code());
}
return AbstractCode::cast(ToCode());
}
Code CodeLookupResult::ToCode() const {
DCHECK(IsFound());
#ifdef V8_EXTERNAL_CODE_SPACE
return IsCode() ? code() : FromCodeT(code_data_container());
#else
@ -625,6 +668,16 @@ int Code::GetOffsetFromInstructionStart(Isolate* isolate, Address pc) const {
return static_cast<int>(offset);
}
#ifdef V8_EXTERNAL_CODE_SPACE
int CodeDataContainer::GetOffsetFromInstructionStart(Isolate* isolate,
Address pc) const {
Address instruction_start = InstructionStart(isolate, pc);
Address offset = pc - instruction_start;
DCHECK_LE(offset, InstructionSize());
return static_cast<int>(offset);
}
#endif
Address Code::raw_metadata_end() const {
return raw_metadata_start() + raw_metadata_size();
}

View File

@ -225,6 +225,15 @@ SafepointEntry Code::GetSafepointEntry(Isolate* isolate, Address pc) {
return table.FindEntry(pc);
}
#ifdef V8_EXTERNAL_CODE_SPACE
SafepointEntry CodeDataContainer::GetSafepointEntry(Isolate* isolate,
Address pc) {
DCHECK(!is_maglevved());
SafepointTable table(isolate, pc, *this);
return table.FindEntry(pc);
}
#endif // V8_EXTERNAL_CODE_SPACE
MaglevSafepointEntry Code::GetMaglevSafepointEntry(Isolate* isolate,
Address pc) {
DCHECK(is_maglevved());
@ -232,6 +241,15 @@ MaglevSafepointEntry Code::GetMaglevSafepointEntry(Isolate* isolate,
return table.FindEntry(pc);
}
#ifdef V8_EXTERNAL_CODE_SPACE
MaglevSafepointEntry CodeDataContainer::GetMaglevSafepointEntry(
Isolate* isolate, Address pc) {
DCHECK(is_maglevved());
MaglevSafepointTable table(isolate, pc, *this);
return table.FindEntry(pc);
}
#endif // V8_EXTERNAL_CODE_SPACE
Address Code::OffHeapInstructionStart(Isolate* isolate, Address pc) const {
DCHECK(is_off_heap_trampoline());
EmbeddedData d = EmbeddedData::GetEmbeddedDataForPC(isolate, pc);

View File

@ -204,6 +204,14 @@ class CodeDataContainer : public HeapObject {
inline Address InstructionEnd() const;
inline int InstructionSize() const;
// Get the safepoint entry for the given pc.
SafepointEntry GetSafepointEntry(Isolate* isolate, Address pc);
// Get the maglev safepoint entry for the given pc.
MaglevSafepointEntry GetMaglevSafepointEntry(Isolate* isolate, Address pc);
inline int GetOffsetFromInstructionStart(Isolate* isolate, Address pc) const;
#endif // V8_EXTERNAL_CODE_SPACE
DECL_CAST(CodeDataContainer)
@ -906,6 +914,15 @@ class CodeLookupResult {
inline int stack_slots() const;
inline HandlerTable::CatchPrediction GetBuiltinCatchPrediction() const;
inline int GetOffsetFromInstructionStart(Isolate* isolate, Address pc) const;
inline SafepointEntry GetSafepointEntry(Isolate* isolate, Address pc) const;
inline MaglevSafepointEntry GetMaglevSafepointEntry(Isolate* isolate,
Address pc) const;
// Helper method, coverts the successful lookup result to AbstractCode object.
inline AbstractCode ToAbstractCode() const;
// Helper method, coverts the successful lookup result to Code object.
// It's not safe to be used from GC because conversion to Code might perform
// a map check.