Commit 4d717997 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove patching of generated stack traces

Our first implementation passed the source position as argument to the
runtime function, which would then generate an Error object, patch the
contained stack trace to point to the position given as argument, and
then throw the Error.
Since all our paths are now changed to call a builtin with proper
source position information, we do not need to patch anything any more.

R=ahaas@chromium.org

Bug: v8:5007
Change-Id: I70dce1b9fcf9966a13865c1c373f3e354908b009
Reviewed-on: https://chromium-review.googlesource.com/732117Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48876}
parent dc6c7be9
......@@ -19,7 +19,7 @@ TF_BUILTIN(WasmStackGuard, CodeStubAssembler) {
#define DECLARE_ENUM(name) \
TF_BUILTIN(ThrowWasm##name, CodeStubAssembler) { \
int message_id = wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \
TailCallRuntime(Runtime::kThrowWasmErrorFromTrapIf, NoContextConstant(), \
TailCallRuntime(Runtime::kThrowWasmError, NoContextConstant(), \
SmiConstant(message_id)); \
}
FOREACH_WASM_TRAPREASON(DECLARE_ENUM)
......
......@@ -1665,10 +1665,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
->compiled_module());
int func_index = elements->WasmFunctionIndex(i)->value();
int code_offset = elements->Offset(i)->value();
// TODO(wasm): Clean this up (bug 5007).
int byte_offset = code_offset < 0
? (-1 - code_offset)
: elements->Code(i)->SourcePosition(code_offset);
int byte_offset = elements->Code(i)->SourcePosition(code_offset);
bool is_at_number_conversion =
elements->IsAsmJsWasmFrame(i) &&
elements->Flags(i)->value() & FrameArray::kAsmJsAtNumberConversion;
......
......@@ -709,9 +709,7 @@ MaybeHandle<String> WasmStackFrame::ToString() {
}
int WasmStackFrame::GetPosition() const {
if (IsInterpreted()) return offset_;
// TODO(wasm): Clean this up (bug 5007).
return (offset_ < 0) ? (-1 - offset_) : code_->SourcePosition(offset_);
return IsInterpreted() ? offset_ : code_->SourcePosition(offset_);
}
Handle<Object> WasmStackFrame::Null() const {
......
......@@ -79,70 +79,19 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
WasmInstanceObject::GrowMemory(isolate, instance, delta_pages));
}
Object* ThrowRuntimeError(Isolate* isolate, int message_id, int byte_offset,
bool patch_source_position) {
RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
DCHECK_EQ(1, args.length());
CONVERT_SMI_ARG_CHECKED(message_id, 0);
ClearThreadInWasmScope clear_wasm_flag(isolate->context() == nullptr);
HandleScope scope(isolate);
DCHECK_NULL(isolate->context());
isolate->set_context(GetWasmContextOnStackTop(isolate));
Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError(
static_cast<MessageTemplate::Template>(message_id));
if (!patch_source_position) {
return isolate->Throw(*error_obj);
}
// For wasm traps, the byte offset (a.k.a source position) can not be
// determined from relocation info, since the explicit checks for traps
// converge in one singe block which calls this runtime function.
// We hence pass the byte offset explicitely, and patch it into the top-most
// frame (a wasm frame) on the collected stack trace.
// TODO(wasm): This implementation is temporary, see bug #5007:
// https://bugs.chromium.org/p/v8/issues/detail?id=5007
Handle<JSObject> error = Handle<JSObject>::cast(error_obj);
Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty(
error, isolate->factory()->stack_trace_symbol());
// Patch the stack trace (array of <receiver, function, code, position>).
if (stack_trace_obj->IsJSArray()) {
Handle<FrameArray> stack_elements(
FrameArray::cast(JSArray::cast(*stack_trace_obj)->elements()));
DCHECK(stack_elements->Code(0)->kind() == AbstractCode::WASM_FUNCTION);
DCHECK_LE(0, stack_elements->Offset(0)->value());
stack_elements->SetOffset(0, Smi::FromInt(-1 - byte_offset));
}
// Patch the detailed stack trace (array of JSObjects with various
// properties).
Handle<Object> detailed_stack_trace_obj = JSReceiver::GetDataProperty(
error, isolate->factory()->detailed_stack_trace_symbol());
if (detailed_stack_trace_obj->IsFixedArray()) {
Handle<FixedArray> stack_elements(
FixedArray::cast(*detailed_stack_trace_obj));
DCHECK_GE(stack_elements->length(), 1);
Handle<StackFrameInfo> top_frame(
StackFrameInfo::cast(stack_elements->get(0)));
if (top_frame->column_number()) {
top_frame->set_column_number(byte_offset + 1);
}
}
return isolate->Throw(*error_obj);
}
RUNTIME_FUNCTION(Runtime_ThrowWasmErrorFromTrapIf) {
DCHECK_EQ(1, args.length());
CONVERT_SMI_ARG_CHECKED(message_id, 0);
ClearThreadInWasmScope clear_wasm_flag(isolate->context() == nullptr);
return ThrowRuntimeError(isolate, message_id, 0, false);
}
RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
DCHECK_EQ(2, args.length());
CONVERT_SMI_ARG_CHECKED(message_id, 0);
CONVERT_SMI_ARG_CHECKED(byte_offset, 1);
ClearThreadInWasmScope clear_wasm_flag(isolate->context() == nullptr);
return ThrowRuntimeError(isolate, message_id, byte_offset, true);
}
RUNTIME_FUNCTION(Runtime_ThrowWasmStackOverflow) {
SealHandleScope shs(isolate);
DCHECK_LE(0, args.length());
......
......@@ -646,8 +646,7 @@ namespace internal {
#define FOR_EACH_INTRINSIC_WASM(F) \
F(WasmGrowMemory, 1, 1) \
F(ThrowWasmError, 2, 1) \
F(ThrowWasmErrorFromTrapIf, 1, 1) \
F(ThrowWasmError, 1, 1) \
F(ThrowWasmStackOverflow, 0, 1) \
F(WasmThrowTypeError, 0, 1) \
F(WasmThrowCreate, 2, 1) \
......
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