Commit 72131a74 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Improve exception throwing code sequence.

This reduces the size a "Throw" or "Rethrow" takes in generated code by
switching from runtime calls to using WebAssembly runtime stubs. It also
removes a specialized runtime function and instead uses {Runtime_Throw}
which is generic and used by all code (including JavaScript code).

R=clemensh@chromium.org
BUG=v8:8091

Change-Id: Id4f637525f2ea9d81227931b1290d90ca5f376d1
Reviewed-on: https://chromium-review.googlesource.com/1243106
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56215}
parent 69f264f5
......@@ -1225,6 +1225,7 @@ namespace internal {
TFC(WasmGrowMemory, WasmGrowMemory, 1) \
TFC(WasmStackGuard, NoContext, 1) \
TFC(WasmToNumber, TypeConversion, 1) \
TFC(WasmThrow, WasmThrow, 1) \
TFS(ThrowWasmTrapUnreachable) \
TFS(ThrowWasmTrapMemOutOfBounds) \
TFS(ThrowWasmTrapUnalignedAccess) \
......@@ -1496,6 +1497,7 @@ namespace internal {
V(WasmGrowMemory) \
V(WasmStackGuard) \
V(WasmToNumber) \
V(WasmThrow) \
V(DoubleToI)
// The exception thrown in the following builtins are caught internally and will
......
......@@ -80,6 +80,14 @@ TF_BUILTIN(WasmStackGuard, WasmBuiltinsAssembler) {
TailCallRuntimeWithCEntry(Runtime::kWasmStackGuard, centry, context);
}
TF_BUILTIN(WasmThrow, WasmBuiltinsAssembler) {
TNode<Object> exception = UncheckedParameter(Descriptor::kException);
TNode<Object> instance = LoadInstanceFromFrame();
TNode<Code> centry = LoadCEntryFromInstance(instance);
TNode<Object> context = LoadContextFromInstance(instance);
TailCallRuntimeWithCEntry(Runtime::kThrow, centry, context, exception);
}
TF_BUILTIN(WasmGrowMemory, WasmBuiltinsAssembler) {
TNode<Int32T> num_pages =
UncheckedCast<Int32T>(Parameter(Descriptor::kNumPages));
......
......@@ -2083,7 +2083,16 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
}
}
DCHECK_EQ(encoded_size, index);
return BuildCallToRuntime(Runtime::kWasmThrow, &except_obj, 1);
WasmThrowDescriptor interface_descriptor;
auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), interface_descriptor,
interface_descriptor.GetStackParameterCount(), CallDescriptor::kNoFlags,
Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub);
Node* call_target = mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmThrow, RelocInfo::WASM_STUB_CALL);
return SetEffect(SetControl(
graph()->NewNode(mcgraph()->common()->Call(call_descriptor), call_target,
except_obj, Effect(), Control())));
}
void WasmGraphBuilder::BuildEncodeException32BitValue(Node* except_obj,
......@@ -2122,8 +2131,16 @@ Node* WasmGraphBuilder::BuildDecodeException32BitValue(Node* const* values,
Node* WasmGraphBuilder::Rethrow(Node* except_obj) {
needs_stack_check_ = true;
Node* result = BuildCallToRuntime(Runtime::kWasmThrow, &except_obj, 1);
return result;
WasmThrowDescriptor interface_descriptor;
auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), interface_descriptor,
interface_descriptor.GetStackParameterCount(), CallDescriptor::kNoFlags,
Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub);
Node* call_target = mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmThrow, RelocInfo::WASM_STUB_CALL);
return SetEffect(SetControl(
graph()->NewNode(mcgraph()->common()->Call(call_descriptor), call_target,
except_obj, Effect(), Control())));
}
Node* WasmGraphBuilder::ExceptionTagEqual(Node* caught_tag,
......
......@@ -344,6 +344,11 @@ void WasmGrowMemoryDescriptor::InitializePlatformSpecific(
DefaultInitializePlatformSpecific(data, kParameterCount);
}
void WasmThrowDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
DefaultInitializePlatformSpecific(data, kParameterCount);
}
void CloneObjectWithVectorDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
DefaultInitializePlatformSpecific(data, kParameterCount);
......
......@@ -74,6 +74,7 @@ namespace internal {
V(FrameDropperTrampoline) \
V(RunMicrotasks) \
V(WasmGrowMemory) \
V(WasmThrow) \
V(CloneObjectWithVector) \
BUILTIN_LIST_TFS(V)
......@@ -1085,6 +1086,14 @@ class WasmGrowMemoryDescriptor final : public CallInterfaceDescriptor {
DECLARE_DESCRIPTOR(WasmGrowMemoryDescriptor, CallInterfaceDescriptor)
};
class WasmThrowDescriptor final : public CallInterfaceDescriptor {
public:
DEFINE_PARAMETERS_NO_CONTEXT(kException)
DEFINE_RESULT_AND_PARAMETER_TYPES(MachineType::AnyTagged(), // result 1
MachineType::AnyTagged()) // kException
DECLARE_DESCRIPTOR(WasmThrowDescriptor, CallInterfaceDescriptor)
};
class CloneObjectWithVectorDescriptor final : public CallInterfaceDescriptor {
public:
DEFINE_PARAMETERS(kSource, kFlags, kSlot, kVector)
......
......@@ -122,16 +122,6 @@ RUNTIME_FUNCTION(Runtime_WasmThrowCreate) {
return *exception;
}
RUNTIME_FUNCTION(Runtime_WasmThrow) {
// TODO(kschimpf): Can this be replaced with equivalent TurboFan code/calls.
SealHandleScope shs(isolate);
DCHECK_EQ(1, args.length());
DCHECK_NULL(isolate->context());
isolate->set_context(GetNativeContextFromWasmInstanceOnStackTop(isolate));
CONVERT_ARG_CHECKED(Object, except_obj, 0);
return isolate->Throw(except_obj);
}
RUNTIME_FUNCTION(Runtime_WasmExceptionGetTag) {
// TODO(kschimpf): Can this be replaced with equivalent TurboFan code/calls.
HandleScope scope(isolate);
......
......@@ -530,7 +530,6 @@ namespace internal {
F(WasmGrowMemory, 2, 1) \
F(WasmRunInterpreter, 2, 1) \
F(WasmStackGuard, 0, 1) \
F(WasmThrow, 1, 1) \
F(WasmThrowCreate, 2, 1) \
F(WasmThrowTypeError, 0, 1) \
F(WasmCompileLazy, 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