Skip to content

Commit a4cd1ee

Browse files
backesCommit bot
authored andcommitted
[wasm] Make wasm info available on the stack trace
This changes different locations to extract the reference to the wasm object and the function index from the stack trace, and make it available through all the APIs which process stack traces. The javascript CallSite object now has the new methods isWasm(), getWasmObject() and getWasmFunctionIndex(); the byte offset is available via getPosition(). Function names of wasm frames should be fully functional with this commit, position information works reliably for calls, but not for traps like unreachable or out-of-bounds accesses. R=titzer@chromium.org, yangguo@chromium.org Review-Url: https://codereview.chromium.org/1909353002 Cr-Commit-Position: refs/heads/master@{#36067}
1 parent 3b7ff99 commit a4cd1ee

16 files changed

Lines changed: 353 additions & 257 deletions

src/compiler/wasm-compiler.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,13 +3014,8 @@ class WasmCompilationUnit {
30143014
isolate_->factory()->NewFixedArray(2, TENURED);
30153015
if (!module_env_->instance->js_object.is_null()) {
30163016
deopt_data->set(0, *module_env_->instance->js_object);
3017-
deopt_data->set(1, Smi::FromInt(function_->func_index));
3018-
} else if (info_.GetDebugName().get() != nullptr) {
3019-
MaybeHandle<String> maybe_name = isolate_->factory()->NewStringFromUtf8(
3020-
CStrVector(info_.GetDebugName().get()));
3021-
if (!maybe_name.is_null())
3022-
deopt_data->set(0, *maybe_name.ToHandleChecked());
30233017
}
3018+
deopt_data->set(1, Smi::FromInt(function_->func_index));
30243019
deopt_data->set_length(2);
30253020
code->set_deoptimization_data(*deopt_data);
30263021

src/frames.cc

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "src/safepoint-table.h"
1717
#include "src/string-stream.h"
1818
#include "src/vm-state-inl.h"
19+
#include "src/wasm/wasm-module.h"
1920

2021
namespace v8 {
2122
namespace internal {
@@ -617,21 +618,6 @@ void ExitFrame::FillState(Address fp, Address sp, State* state) {
617618
state->constant_pool_address = NULL;
618619
}
619620

620-
void StandardFrame::Summarize(List<FrameSummary>* functions,
621-
FrameSummary::Mode mode) const {
622-
DCHECK(functions->length() == 0);
623-
// default implementation: no summary added
624-
}
625-
626-
JSFunction* StandardFrame::function() const {
627-
// this default implementation is overridden by JS and WASM frames
628-
return nullptr;
629-
}
630-
631-
Object* StandardFrame::receiver() const {
632-
return isolate()->heap()->undefined_value();
633-
}
634-
635621
Address StandardFrame::GetExpressionAddress(int n) const {
636622
const int offset = StandardFrameConstants::kExpressionsOffset;
637623
return fp() + offset - n * kPointerSize;
@@ -1343,30 +1329,36 @@ Code* WasmFrame::unchecked_code() const {
13431329
return static_cast<Code*>(isolate()->FindCodeObject(pc()));
13441330
}
13451331

1346-
JSFunction* WasmFrame::function() const {
1347-
// TODO(clemensh): generate the right JSFunctions once per wasm function and
1348-
// cache them
1349-
Factory* factory = isolate()->factory();
1350-
Handle<JSFunction> fun =
1351-
factory->NewFunction(factory->NewStringFromAsciiChecked("<WASM>"));
1352-
return *fun;
1332+
void WasmFrame::Iterate(ObjectVisitor* v) const { IterateCompiledFrame(v); }
1333+
1334+
Address WasmFrame::GetCallerStackPointer() const {
1335+
return fp() + ExitFrameConstants::kCallerSPOffset;
13531336
}
13541337

1355-
void WasmFrame::Summarize(List<FrameSummary>* functions,
1356-
FrameSummary::Mode mode) const {
1357-
DCHECK(functions->length() == 0);
1358-
Code* code = LookupCode();
1359-
int offset = static_cast<int>(pc() - code->instruction_start());
1360-
AbstractCode* abstract_code = AbstractCode::cast(code);
1361-
Handle<JSFunction> fun(function(), isolate());
1362-
FrameSummary summary(receiver(), *fun, abstract_code, offset, false);
1363-
functions->Add(summary);
1338+
Object* WasmFrame::wasm_obj() {
1339+
FixedArray* deopt_data = LookupCode()->deoptimization_data();
1340+
DCHECK(deopt_data->length() == 2);
1341+
return deopt_data->get(0);
13641342
}
13651343

1366-
void WasmFrame::Iterate(ObjectVisitor* v) const { IterateCompiledFrame(v); }
1344+
uint32_t WasmFrame::function_index() {
1345+
FixedArray* deopt_data = LookupCode()->deoptimization_data();
1346+
DCHECK(deopt_data->length() == 2);
1347+
Object* func_index_obj = deopt_data->get(1);
1348+
if (func_index_obj->IsUndefined()) return static_cast<uint32_t>(-1);
1349+
if (func_index_obj->IsSmi()) return Smi::cast(func_index_obj)->value();
1350+
DCHECK(func_index_obj->IsHeapNumber());
1351+
uint32_t val = static_cast<uint32_t>(-1);
1352+
func_index_obj->ToUint32(&val);
1353+
DCHECK(val != static_cast<uint32_t>(-1));
1354+
return val;
1355+
}
13671356

1368-
Address WasmFrame::GetCallerStackPointer() const {
1369-
return fp() + ExitFrameConstants::kCallerSPOffset;
1357+
Object* WasmFrame::function_name() {
1358+
Object* wasm_object = wasm_obj();
1359+
if (wasm_object->IsUndefined()) return wasm_object;
1360+
Handle<JSObject> wasm = handle(JSObject::cast(wasm_object));
1361+
return *wasm::GetWasmFunctionName(wasm, function_index());
13701362
}
13711363

13721364
namespace {

src/frames.h

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,8 @@ class JavaScriptFrame;
635635

636636
class FrameSummary BASE_EMBEDDED {
637637
public:
638-
// Mode for StandardFrame::Summarize. Exact summary is required to produce an
639-
// exact stack trace. It will trigger an assertion failure if that is not
638+
// Mode for JavaScriptFrame::Summarize. Exact summary is required to produce
639+
// an exact stack trace. It will trigger an assertion failure if that is not
640640
// possible, e.g., because of missing deoptimization information. The
641641
// approximate mode should produce a summary even without deoptimization
642642
// information, but it might miss frames.
@@ -684,15 +684,6 @@ class StandardFrame : public StackFrame {
684684
return static_cast<StandardFrame*>(frame);
685685
}
686686

687-
// Build a list with summaries for this frame including all inlined frames.
688-
virtual void Summarize(
689-
List<FrameSummary>* frames,
690-
FrameSummary::Mode mode = FrameSummary::kExactSummary) const;
691-
692-
// Accessors.
693-
virtual JSFunction* function() const;
694-
virtual Object* receiver() const;
695-
696687
protected:
697688
inline explicit StandardFrame(StackFrameIteratorBase* iterator);
698689

@@ -737,8 +728,14 @@ class JavaScriptFrame : public StandardFrame {
737728
public:
738729
Type type() const override { return JAVA_SCRIPT; }
739730

740-
JSFunction* function() const override;
741-
Object* receiver() const override;
731+
// Build a list with summaries for this frame including all inlined frames.
732+
virtual void Summarize(
733+
List<FrameSummary>* frames,
734+
FrameSummary::Mode mode = FrameSummary::kExactSummary) const;
735+
736+
// Accessors.
737+
virtual JSFunction* function() const;
738+
virtual Object* receiver() const;
742739

743740
inline void set_receiver(Object* value);
744741

@@ -786,10 +783,6 @@ class JavaScriptFrame : public StandardFrame {
786783
// Return a list with JSFunctions of this frame.
787784
virtual void GetFunctions(List<JSFunction*>* functions) const;
788785

789-
void Summarize(
790-
List<FrameSummary>* frames,
791-
FrameSummary::Mode mode = FrameSummary::kExactSummary) const override;
792-
793786
// Lookup exception handler for current {pc}, returns -1 if none found. Also
794787
// returns data associated with the handler site specific to the frame type:
795788
// - JavaScriptFrame : Data is the stack depth at entry of the try-block.
@@ -975,17 +968,16 @@ class WasmFrame : public StandardFrame {
975968
// Determine the code for the frame.
976969
Code* unchecked_code() const override;
977970

971+
Object* wasm_obj();
972+
uint32_t function_index();
973+
974+
Object* function_name();
975+
978976
static WasmFrame* cast(StackFrame* frame) {
979977
DCHECK(frame->is_wasm());
980978
return static_cast<WasmFrame*>(frame);
981979
}
982980

983-
JSFunction* function() const override;
984-
985-
void Summarize(
986-
List<FrameSummary>* frames,
987-
FrameSummary::Mode mode = FrameSummary::kExactSummary) const override;
988-
989981
protected:
990982
inline explicit WasmFrame(StackFrameIteratorBase* iterator);
991983

src/heap-symbols.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
V(call_site_position_symbol) \
140140
V(call_site_receiver_symbol) \
141141
V(call_site_strict_symbol) \
142+
V(call_site_wasm_obj_symbol) \
143+
V(call_site_wasm_func_index_symbol) \
142144
V(class_end_position_symbol) \
143145
V(class_start_position_symbol) \
144146
V(detailed_stack_trace_symbol) \

0 commit comments

Comments
 (0)