Commit 1e7d34b8 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Make runtime stubs load CEntry from instance.

This makes the WebAssembly runtime stubs load the correct CEntry stub
from the instance object instead of embedding the address within the
instruction stream. It effectively makes those stubs independent of the
underlying Isolate.

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

Change-Id: I0e7f3ecf7642d3fb1ee7adf83a8f0e6cc4d38fdf
Reviewed-on: https://chromium-review.googlesource.com/1086997
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53575}
parent 0a9c3a0a
......@@ -13,14 +13,26 @@ namespace internal {
typedef compiler::Node Node;
TF_BUILTIN(WasmStackGuard, CodeStubAssembler) {
TailCallRuntime(Runtime::kWasmStackGuard, NoContextConstant());
TNode<Object> instance = UncheckedCast<Object>(
LoadFromParentFrame(WasmCompiledFrameConstants::kWasmInstanceOffset));
TNode<Object> centry = UncheckedCast<Object>(Load(
MachineType::AnyTagged(), instance,
IntPtrConstant(WasmInstanceObject::kCEntryStubOffset - kHeapObjectTag)));
TailCallRuntimeWithCEntry(Runtime::kWasmStackGuard, centry,
NoContextConstant());
}
#define DECLARE_ENUM(name) \
TF_BUILTIN(ThrowWasm##name, CodeStubAssembler) { \
int message_id = wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \
TailCallRuntime(Runtime::kThrowWasmError, NoContextConstant(), \
SmiConstant(message_id)); \
#define DECLARE_ENUM(name) \
TF_BUILTIN(ThrowWasm##name, CodeStubAssembler) { \
TNode<Object> instance = UncheckedCast<Object>( \
LoadFromParentFrame(WasmCompiledFrameConstants::kWasmInstanceOffset)); \
TNode<Object> centry = UncheckedCast<Object>( \
Load(MachineType::AnyTagged(), instance, \
IntPtrConstant(WasmInstanceObject::kCEntryStubOffset - \
kHeapObjectTag))); \
int message_id = wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \
TailCallRuntimeWithCEntry(Runtime::kThrowWasmError, centry, \
NoContextConstant(), SmiConstant(message_id)); \
}
FOREACH_WASM_TRAPREASON(DECLARE_ENUM)
#undef DECLARE_ENUM
......
......@@ -320,18 +320,6 @@ bool Builtins::IsIsolateIndependent(int index) {
// isolate-independent once copies are no longer generated for wasm.
case kWasmCompileLazy:
return false;
// TODO(mstarzinger): Will be made Isolate independent once the CEntry stub
// is loaded from the instance.
case kWasmStackGuard:
case kThrowWasmTrapUnreachable:
case kThrowWasmTrapMemOutOfBounds:
case kThrowWasmTrapDivByZero:
case kThrowWasmTrapDivUnrepresentable:
case kThrowWasmTrapRemByZero:
case kThrowWasmTrapFloatUnrepresentable:
case kThrowWasmTrapFuncInvalid:
case kThrowWasmTrapFuncSigMismatch:
return false;
default:
return true;
}
......
......@@ -204,7 +204,7 @@ TNode<Smi> CodeStubAssembler::SelectSmiConstant(SloppyTNode<BoolT> condition,
SmiConstant(false_value));
}
Node* CodeStubAssembler::NoContextConstant() {
TNode<Object> CodeStubAssembler::NoContextConstant() {
return SmiConstant(Context::kNoContext);
}
......
......@@ -319,7 +319,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
SmiAboveOrEqual)
#undef PARAMETER_BINOP
Node* NoContextConstant();
TNode<Object> NoContextConstant();
#define HEAP_CONSTANT_ACCESSOR(rootIndexName, rootAccessorName, name) \
compiler::TNode<std::remove_reference<decltype( \
*std::declval<Heap>().rootAccessorName())>::type> \
......@@ -2096,7 +2096,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Label* if_null_or_undefined);
template <class... TArgs>
TNode<Object> CallBuiltin(Builtins::Name id, SloppyTNode<Context> context,
TNode<Object> CallBuiltin(Builtins::Name id, SloppyTNode<Object> context,
TArgs... args) {
DCHECK_IMPLIES(Builtins::KindOf(id) == Builtins::TFJ,
!Builtins::IsLazy(id));
......@@ -2105,7 +2105,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
}
template <class... TArgs>
TNode<Object> TailCallBuiltin(Builtins::Name id, SloppyTNode<Context> context,
TNode<Object> TailCallBuiltin(Builtins::Name id, SloppyTNode<Object> context,
TArgs... args) {
DCHECK_IMPLIES(Builtins::KindOf(id) == Builtins::TFJ,
!Builtins::IsLazy(id));
......
......@@ -1115,14 +1115,28 @@ template <class... TArgs>
TNode<Object> CodeAssembler::TailCallRuntimeImpl(Runtime::FunctionId function,
SloppyTNode<Object> context,
TArgs... args) {
int result_size = Runtime::FunctionForId(function)->result_size;
TNode<Object> centry =
HeapConstant(CodeFactory::RuntimeCEntry(isolate(), result_size));
return TailCallRuntimeWithCEntryImpl(function, centry, context, args...);
}
// Instantiate TailCallRuntime() for argument counts used by CSA-generated code
#define INSTANTIATE(...) \
template V8_EXPORT_PRIVATE TNode<Object> CodeAssembler::TailCallRuntimeImpl( \
Runtime::FunctionId, __VA_ARGS__);
REPEAT_1_TO_7(INSTANTIATE, SloppyTNode<Object>)
#undef INSTANTIATE
template <class... TArgs>
TNode<Object> CodeAssembler::TailCallRuntimeWithCEntryImpl(
Runtime::FunctionId function, TNode<Object> centry, TNode<Object> context,
TArgs... args) {
int argc = static_cast<int>(sizeof...(args));
auto call_descriptor = Linkage::GetRuntimeCallDescriptor(
zone(), function, argc, Operator::kNoProperties,
CallDescriptor::kNoFlags);
int return_count = static_cast<int>(call_descriptor->ReturnCount());
Node* centry =
HeapConstant(CodeFactory::RuntimeCEntry(isolate(), return_count));
Node* ref = ExternalConstant(ExternalReference::Create(function));
Node* arity = Int32Constant(argc);
......@@ -1132,11 +1146,13 @@ TNode<Object> CodeAssembler::TailCallRuntimeImpl(Runtime::FunctionId function,
raw_assembler()->TailCallN(call_descriptor, arraysize(nodes), nodes));
}
// Instantiate TailCallRuntime() for argument counts used by CSA-generated code
#define INSTANTIATE(...) \
template V8_EXPORT_PRIVATE TNode<Object> CodeAssembler::TailCallRuntimeImpl( \
Runtime::FunctionId, __VA_ARGS__);
REPEAT_1_TO_7(INSTANTIATE, SloppyTNode<Object>)
// Instantiate TailCallRuntimeWithCEntry() for argument counts used by
// CSA-generated code.
#define INSTANTIATE(...) \
template V8_EXPORT_PRIVATE TNode<Object> \
CodeAssembler::TailCallRuntimeWithCEntryImpl( \
Runtime::FunctionId, TNode<Object>, __VA_ARGS__);
REPEAT_1_TO_7(INSTANTIATE, TNode<Object>)
#undef INSTANTIATE
template <class... TArgs>
......
......@@ -997,6 +997,20 @@ class V8_EXPORT_PRIVATE CodeAssembler {
implicit_cast<SloppyTNode<Object>>(args)...);
}
template <class... TArgs>
TNode<Object> TailCallRuntimeWithCEntryImpl(Runtime::FunctionId function,
TNode<Object> centry,
TNode<Object> context,
TArgs... args);
template <class... TArgs>
TNode<Object> TailCallRuntimeWithCEntry(Runtime::FunctionId function,
TNode<Object> centry,
TNode<Object> context,
TArgs... args) {
return TailCallRuntimeWithCEntryImpl(function, centry, context,
implicit_cast<TNode<Object>>(args)...);
}
//
// If context passed to CallStub is nullptr, it won't be passed to the stub.
//
......
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