Commit 81ba8d1e authored by Victor Gomes's avatar Victor Gomes Committed by Commit Bot

Reland "[cleanup] Create virtual FrameWithJSLinkages"

This is a reland of 5afa3add

Original change's description:
> [cleanup] Create virtual FrameWithJSLinkages
>
> - CommonFrameWithJSLinkage
> - TypedFrameWithJSLinkage
>
> Change-Id: Ib70967c6b8bc9129d7562ec5587076e66312ca25
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2480562
> Commit-Queue: Victor Gomes <victorgomes@chromium.org>
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#70609}

Change-Id: I6e952cdeb8ec37c02f16ad854e8366ef742072b6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2483845Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70618}
parent e5c6b69d
......@@ -97,6 +97,14 @@ inline Address* StackFrame::ResolveReturnAddressLocation(Address* pc_address) {
inline TypedFrame::TypedFrame(StackFrameIteratorBase* iterator)
: CommonFrame(iterator) {}
inline CommonFrameWithJSLinkage::CommonFrameWithJSLinkage(
StackFrameIteratorBase* iterator)
: CommonFrame(iterator) {}
inline TypedFrameWithJSLinkage::TypedFrameWithJSLinkage(
StackFrameIteratorBase* iterator)
: CommonFrameWithJSLinkage(iterator) {}
inline NativeFrame::NativeFrame(StackFrameIteratorBase* iterator)
: TypedFrame(iterator) {}
......@@ -175,16 +183,16 @@ inline bool CommonFrame::IsArgumentsAdaptorFrame(Address fp) {
return frame_type == StackFrame::TypeToMarker(StackFrame::ARGUMENTS_ADAPTOR);
}
inline bool CommonFrame::IsConstructFrame(Address fp) {
inline bool CommonFrameWithJSLinkage::IsConstructFrame(Address fp) {
intptr_t frame_type =
base::Memory<intptr_t>(fp + TypedFrameConstants::kFrameTypeOffset);
return frame_type == StackFrame::TypeToMarker(StackFrame::CONSTRUCT);
}
inline JavaScriptFrame::JavaScriptFrame(StackFrameIteratorBase* iterator)
: CommonFrame(iterator) {}
: CommonFrameWithJSLinkage(iterator) {}
Address JavaScriptFrame::GetParameterSlot(int index) const {
Address CommonFrameWithJSLinkage::GetParameterSlot(int index) const {
DCHECK_LE(-1, index);
#ifdef V8_NO_ARGUMENTS_ADAPTOR
DCHECK_LT(index,
......@@ -197,6 +205,12 @@ Address JavaScriptFrame::GetParameterSlot(int index) const {
return caller_sp() + parameter_offset;
}
#ifdef V8_NO_ARGUMENTS_ADAPTOR
inline int CommonFrameWithJSLinkage::GetActualArgumentCount() const {
return 0;
}
#endif
inline void JavaScriptFrame::set_receiver(Object value) {
base::Memory<Address>(GetParameterSlot(-1)) = value.ptr();
}
......@@ -226,7 +240,7 @@ inline ArgumentsAdaptorFrame::ArgumentsAdaptorFrame(
}
inline BuiltinFrame::BuiltinFrame(StackFrameIteratorBase* iterator)
: TypedFrame(iterator) {}
: TypedFrameWithJSLinkage(iterator) {}
inline WasmFrame::WasmFrame(StackFrameIteratorBase* iterator)
: TypedFrame(iterator) {}
......@@ -264,7 +278,7 @@ inline BuiltinContinuationFrame::BuiltinContinuationFrame(
inline JavaScriptBuiltinContinuationFrame::JavaScriptBuiltinContinuationFrame(
StackFrameIteratorBase* iterator)
: JavaScriptFrame(iterator) {}
: TypedFrameWithJSLinkage(iterator) {}
inline JavaScriptBuiltinContinuationWithCatchFrame::
JavaScriptBuiltinContinuationWithCatchFrame(
......
......@@ -156,6 +156,13 @@ StackFrame* StackFrameIteratorBase::SingletonFor(StackFrame::Type type) {
// -------------------------------------------------------------------------
void TypedFrameWithJSLinkage::Iterate(RootVisitor* v) const {
IterateExpressions(v);
IteratePc(v, pc_address(), constant_pool_address(), LookupCode());
}
// -------------------------------------------------------------------------
void JavaScriptFrameIterator::Advance() {
do {
iterator_.Advance();
......@@ -1090,7 +1097,9 @@ bool JavaScriptFrame::HasInlinedFrames() const {
return functions.size() > 1;
}
Code JavaScriptFrame::unchecked_code() const { return function().code(); }
Code CommonFrameWithJSLinkage::unchecked_code() const {
return function().code();
}
int OptimizedFrame::ComputeParametersCount() const {
Code code = LookupCode();
......@@ -1123,7 +1132,12 @@ void JavaScriptFrame::GetFunctions(
}
}
void JavaScriptFrame::Summarize(std::vector<FrameSummary>* functions) const {
bool CommonFrameWithJSLinkage::IsConstructor() const {
return IsConstructFrame(caller_fp());
}
void CommonFrameWithJSLinkage::Summarize(
std::vector<FrameSummary>* functions) const {
DCHECK(functions->empty());
Code code = LookupCode();
int offset = static_cast<int>(pc() - code.InstructionStart());
......@@ -1148,7 +1162,7 @@ Object JavaScriptFrame::unchecked_function() const {
return function_slot_object();
}
Object JavaScriptFrame::receiver() const { return GetParameter(-1); }
Object CommonFrameWithJSLinkage::receiver() const { return GetParameter(-1); }
Object JavaScriptFrame::context() const {
const int offset = StandardFrameConstants::kContextOffset;
......@@ -1161,7 +1175,7 @@ Script JavaScriptFrame::script() const {
return Script::cast(function().shared().script());
}
int JavaScriptFrame::LookupExceptionHandlerInTable(
int CommonFrameWithJSLinkage::LookupExceptionHandlerInTable(
int* stack_depth, HandlerTable::CatchPrediction* prediction) {
DCHECK(!LookupCode().has_handler_table());
DCHECK(!LookupCode().is_optimized_code());
......@@ -1256,11 +1270,11 @@ void JavaScriptFrame::CollectFunctionAndOffsetForICStats(JSFunction function,
}
}
Object JavaScriptFrame::GetParameter(int index) const {
Object CommonFrameWithJSLinkage::GetParameter(int index) const {
return Object(Memory<Address>(GetParameterSlot(index)));
}
int JavaScriptFrame::ComputeParametersCount() const {
int CommonFrameWithJSLinkage::ComputeParametersCount() const {
DCHECK(can_access_heap_objects() &&
isolate()->heap()->gc_state() == Heap::NOT_IN_GC);
return function().shared().internal_formal_parameter_count();
......@@ -1273,7 +1287,7 @@ int JavaScriptFrame::GetActualArgumentCount() const {
}
#endif
Handle<FixedArray> JavaScriptFrame::GetParameters() const {
Handle<FixedArray> CommonFrameWithJSLinkage::GetParameters() const {
if (V8_LIKELY(!FLAG_detailed_error_stack_trace)) {
return isolate()->factory()->empty_fixed_array();
}
......@@ -1287,6 +1301,11 @@ Handle<FixedArray> JavaScriptFrame::GetParameters() const {
return parameters;
}
JSFunction JavaScriptBuiltinContinuationFrame::function() const {
const int offset = BuiltinContinuationFrameConstants::kFunctionOffset;
return JSFunction::cast(Object(base::Memory<Address>(fp() + offset)));
}
int JavaScriptBuiltinContinuationFrame::ComputeParametersCount() const {
// Assert that the first allocatable register is also the argument count
// register.
......@@ -1770,6 +1789,11 @@ Code ArgumentsAdaptorFrame::unchecked_code() const {
return isolate()->builtins()->builtin(Builtins::kArgumentsAdaptorTrampoline);
}
JSFunction BuiltinFrame::function() const {
const int offset = BuiltinFrameConstants::kFunctionOffset;
return JSFunction::cast(Object(base::Memory<Address>(fp() + offset)));
}
int BuiltinFrame::ComputeParametersCount() const {
const int offset = BuiltinFrameConstants::kLengthOffset;
return Smi::ToInt(Object(base::Memory<Address>(fp() + offset)));
......
......@@ -14,11 +14,14 @@
//
// Frame inheritance hierarchy (please keep in sync with frame-constants.h):
// - CommonFrame
// - CommonFrameWithJSLinkage
// - JavaScriptFrame (aka StandardFrame)
// - InterpretedFrame
// - OptimizedFrame
// - ArgumentsAdaptorFrame (technically a TypedFrame)
// - JavaScriptBuiltinContinuationFrame (*)
// - TypedFrameWithJSLinkage
// - BuiltinFrame
// - JavaScriptBuiltinContinuationFrame
// - JavaScriptBuiltinContinuationWithCatchFrame
// - TypedFrame
// - NativeFrame
......@@ -29,7 +32,6 @@
// - StubFrame
// - JsToWasmFrame
// - CWasmEntryFrame
// - BuiltinFrame
// - Internal
// - ConstructFrame
// - BuiltinContinuationFrame
......@@ -38,11 +40,6 @@
// - WasmDebugBreakFrame
// - WasmCompileLazyFrame
//
// (*) This is actually a BuiltinContinuationFrame with JS arguments.
//
// TODO(victorgomes): Create a class to access JS arguments and change
// BuiltinContinuationFrame to be of type TypedFrame.
namespace v8 {
namespace internal {
......@@ -232,9 +229,7 @@ class StackFrame {
bool is_java_script() const {
Type type = this->type();
return (type == OPTIMIZED) || (type == INTERPRETED) || (type == BUILTIN) ||
(type == JAVA_SCRIPT_BUILTIN_CONTINUATION) ||
(type == JAVA_SCRIPT_BUILTIN_CONTINUATION_WITH_CATCH);
return (type == OPTIMIZED) || (type == INTERPRETED);
}
bool is_wasm_to_js() const { return type() == WASM_TO_JS; }
bool is_js_to_wasm() const { return type() == JS_TO_WASM; }
......@@ -469,7 +464,8 @@ class V8_EXPORT_PRIVATE FrameSummary {
class CommonFrame : public StackFrame {
public:
// Accessors.
virtual Object context() const;
virtual Object context()
const; // TODO(victorgomes): CommonFrames don't have context.
virtual int position() const;
// Access the expressions in the stack frame including locals.
......@@ -517,10 +513,6 @@ class CommonFrame : public StackFrame {
// an arguments adaptor frame.
static inline bool IsArgumentsAdaptorFrame(Address fp);
// Determines if the standard frame for the given frame pointer is a
// construct frame.
static inline bool IsConstructFrame(Address fp);
// Used by OptimizedFrames and StubFrames.
void IterateCompiledFrame(RootVisitor* v) const;
......@@ -538,35 +530,74 @@ class TypedFrame : public CommonFrame {
inline explicit TypedFrame(StackFrameIteratorBase* iterator);
};
class JavaScriptFrame : public CommonFrame {
class CommonFrameWithJSLinkage : public CommonFrame {
public:
Type type() const override = 0;
// Accessors.
virtual JSFunction function() const = 0;
// Access the parameters.
virtual Object receiver() const;
virtual Object GetParameter(int index) const;
virtual int ComputeParametersCount() const;
Handle<FixedArray> GetParameters() const;
#ifdef V8_NO_ARGUMENTS_ADAPTOR
virtual int GetActualArgumentCount() const;
#endif
// Determine the code for the frame.
Code unchecked_code() const override;
// Lookup exception handler for current {pc}, returns -1 if none found. Also
// returns data associated with the handler site specific to the frame type:
// - OptimizedFrame : Data is not used and will not return a value.
// - InterpretedFrame: Data is the register index holding the context.
virtual int LookupExceptionHandlerInTable(
int* data, HandlerTable::CatchPrediction* prediction);
// Check if this frame is a constructor frame invoked through 'new'.
virtual bool IsConstructor() const;
// Summarize Frame
void Summarize(std::vector<FrameSummary>* frames) const override;
protected:
inline explicit CommonFrameWithJSLinkage(StackFrameIteratorBase* iterator);
// Determines if the standard frame for the given frame pointer is a
// construct frame.
static inline bool IsConstructFrame(Address fp);
inline Address GetParameterSlot(int index) const;
};
class TypedFrameWithJSLinkage : public CommonFrameWithJSLinkage {
public:
void Iterate(RootVisitor* v) const override;
protected:
inline explicit TypedFrameWithJSLinkage(StackFrameIteratorBase* iterator);
};
class JavaScriptFrame : public CommonFrameWithJSLinkage {
public:
Type type() const override = 0;
// Accessors.
virtual JSFunction function() const;
JSFunction function() const override;
Object unchecked_function() const;
Object receiver() const;
Object context() const override;
Script script() const;
Object context() const override;
inline void set_receiver(Object value);
// Access the parameters.
inline Address GetParameterSlot(int index) const;
Object GetParameter(int index) const;
virtual int ComputeParametersCount() const;
#ifdef V8_NO_ARGUMENTS_ADAPTOR
int GetActualArgumentCount() const;
int GetActualArgumentCount() const override;
#endif
Handle<FixedArray> GetParameters() const;
inline void set_receiver(Object value);
// Debugger access.
void SetParameterValue(int index, Object value) const;
// Check if this frame is a constructor frame invoked through 'new'.
bool IsConstructor() const;
bool IsConstructor() const override;
// Determines whether this frame includes inlined activations. To get details
// about the inlined frames use {GetFunctions} and {Summarize}.
......@@ -584,21 +615,11 @@ class JavaScriptFrame : public CommonFrame {
void Print(StringStream* accumulator, PrintMode mode,
int index) const override;
// Determine the code for the frame.
Code unchecked_code() const override;
// Return a list with {SharedFunctionInfo} objects of this frame.
virtual void GetFunctions(std::vector<SharedFunctionInfo>* functions) const;
void GetFunctions(std::vector<Handle<SharedFunctionInfo>>* functions) const;
// Lookup exception handler for current {pc}, returns -1 if none found. Also
// returns data associated with the handler site specific to the frame type:
// - OptimizedFrame : Data is not used and will not return a value.
// - InterpretedFrame: Data is the register index holding the context.
virtual int LookupExceptionHandlerInTable(
int* data, HandlerTable::CatchPrediction* prediction);
// Architecture-specific register description.
static Register fp_register();
static Register context_register();
......@@ -895,7 +916,7 @@ class ArgumentsAdaptorFrame : public JavaScriptFrame {
// Builtin frames are built for builtins with JavaScript linkage, such as
// various standard library functions (i.e. Math.asin, Math.floor, etc.).
class BuiltinFrame final : public TypedFrame {
class BuiltinFrame final : public TypedFrameWithJSLinkage {
public:
Type type() const final { return BUILTIN; }
......@@ -903,7 +924,9 @@ class BuiltinFrame final : public TypedFrame {
DCHECK(frame->is_builtin());
return static_cast<BuiltinFrame*>(frame);
}
int ComputeParametersCount() const;
JSFunction function() const override;
int ComputeParametersCount() const override;
protected:
inline explicit BuiltinFrame(StackFrameIteratorBase* iterator);
......@@ -1103,7 +1126,7 @@ class BuiltinContinuationFrame : public InternalFrame {
friend class StackFrameIteratorBase;
};
class JavaScriptBuiltinContinuationFrame : public JavaScriptFrame {
class JavaScriptBuiltinContinuationFrame : public TypedFrameWithJSLinkage {
public:
Type type() const override { return JAVA_SCRIPT_BUILTIN_CONTINUATION; }
......@@ -1112,6 +1135,7 @@ class JavaScriptBuiltinContinuationFrame : public JavaScriptFrame {
return static_cast<JavaScriptBuiltinContinuationFrame*>(frame);
}
JSFunction function() const override;
int ComputeParametersCount() const override;
intptr_t GetSPToFPDelta() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment