[wasm] Load jump table start from the instance
This makes js-to-wasm wrappers module-independent, so that we can eventually share them isolate-wide. R=mstarzinger@chromium.org Bug: chromium:862123 Change-Id: I3d9571cf247b95330ffb17f41901278a5dfacca0 Reviewed-on: https://chromium-review.googlesource.com/1131187 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#54363}
This commit is contained in:
parent
17568b9130
commit
3839e88320
@ -4404,8 +4404,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
|
||||
return function_index;
|
||||
}
|
||||
|
||||
void BuildJSToWasmWrapper(Address jump_table_start, bool is_import,
|
||||
uint32_t num_imported_functions) {
|
||||
void BuildJSToWasmWrapper(bool is_import) {
|
||||
const int wasm_count = static_cast<int>(sig_->parameter_count());
|
||||
|
||||
// Build the start and the JS parameter nodes.
|
||||
@ -4466,13 +4465,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
|
||||
} else {
|
||||
// Call to a wasm function defined in this module.
|
||||
// The call target is the jump table slot for that function. This is
|
||||
// {jump_table + (func_index - num_imports) * kJumpTableSlotSize}.
|
||||
// Compute as
|
||||
// jump_table_adjusted (static) := jump_table - num_imports * kJTSS.
|
||||
// call_target := jump_table_adjusted + func_index * kJTSS.
|
||||
Node* jump_table_adjusted = mcgraph()->IntPtrConstant(
|
||||
jump_table_start - num_imported_functions *
|
||||
wasm::JumpTableAssembler::kJumpTableSlotSize);
|
||||
// {jump_table + (func_index - num_imports) * kJumpTableSlotSize}
|
||||
// == {jump_table_adjusted + func_index * kJumpTableSlotSize}.
|
||||
Node* jump_table_adjusted =
|
||||
LOAD_INSTANCE_FIELD(JumpTableAdjustedStart, MachineType::Pointer());
|
||||
Node* jump_table_offset = graph()->NewNode(
|
||||
mcgraph()->machine()->IntMul(), Uint32ToUintptr(function_index),
|
||||
mcgraph()->IntPtrConstant(
|
||||
@ -4828,8 +4824,7 @@ MaybeHandle<Code> CompileJSToWasmWrapper(
|
||||
StubCallMode::kCallOnHeapBuiltin);
|
||||
builder.set_control_ptr(&control);
|
||||
builder.set_effect_ptr(&effect);
|
||||
builder.BuildJSToWasmWrapper(native_module->jump_table_start(), is_import,
|
||||
module->num_imported_functions);
|
||||
builder.BuildJSToWasmWrapper(is_import);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Run the compilation pipeline.
|
||||
|
@ -116,9 +116,11 @@ MaybeHandle<Code> CompileWasmToJSWrapper(Isolate*, Handle<JSReceiver> target,
|
||||
|
||||
// Creates a code object calling a wasm function with the given signature,
|
||||
// callable from JS.
|
||||
// TODO(clemensh): Remove the {UseTrapHandler} parameter to make js-to-wasm
|
||||
// wrappers sharable across instances.
|
||||
V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper(
|
||||
Isolate*, const wasm::NativeModule*, wasm::FunctionSig*, bool is_import,
|
||||
wasm::UseTrapHandler use_trap_handler);
|
||||
wasm::UseTrapHandler);
|
||||
|
||||
// Compiles a stub that redirects a call to a wasm function to the wasm
|
||||
// interpreter. It's ABI compatible with the compiled wasm function.
|
||||
|
@ -156,6 +156,8 @@ PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_sig_ids,
|
||||
uint32_t*, kIndirectFunctionTableSigIdsOffset)
|
||||
PRIMITIVE_ACCESSORS(WasmInstanceObject, indirect_function_table_targets,
|
||||
Address*, kIndirectFunctionTableTargetsOffset)
|
||||
PRIMITIVE_ACCESSORS(WasmInstanceObject, jump_table_adjusted_start, Address,
|
||||
kJumpTableAdjustedStartOffset)
|
||||
|
||||
ACCESSORS(WasmInstanceObject, module_object, WasmModuleObject,
|
||||
kModuleObjectOffset)
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/objects/debug-objects-inl.h"
|
||||
#include "src/trap-handler/trap-handler.h"
|
||||
#include "src/wasm/jump-table-assembler.h"
|
||||
#include "src/wasm/module-compiler.h"
|
||||
#include "src/wasm/module-decoder.h"
|
||||
#include "src/wasm/wasm-code-manager.h"
|
||||
@ -1263,6 +1264,10 @@ Handle<WasmInstanceObject> WasmInstanceObject::New(
|
||||
instance->set_module_object(*module_object);
|
||||
instance->set_undefined_value(ReadOnlyRoots(isolate).undefined_value());
|
||||
instance->set_null_value(ReadOnlyRoots(isolate).null_value());
|
||||
instance->set_jump_table_adjusted_start(
|
||||
module_object->native_module()->jump_table_start() -
|
||||
wasm::JumpTableAssembler::kJumpTableSlotSize *
|
||||
module->num_imported_functions);
|
||||
|
||||
// Insert the new instance into the modules weak list of instances.
|
||||
// TODO(mstarzinger): Allow to reuse holes in the {WeakArrayList} below.
|
||||
|
@ -401,6 +401,7 @@ class WasmInstanceObject : public JSObject {
|
||||
DECL_PRIMITIVE_ACCESSORS(indirect_function_table_size, uint32_t)
|
||||
DECL_PRIMITIVE_ACCESSORS(indirect_function_table_sig_ids, uint32_t*)
|
||||
DECL_PRIMITIVE_ACCESSORS(indirect_function_table_targets, Address*)
|
||||
DECL_PRIMITIVE_ACCESSORS(jump_table_adjusted_start, Address)
|
||||
|
||||
// Dispatched behavior.
|
||||
DECL_PRINTER(WasmInstanceObject)
|
||||
@ -435,6 +436,7 @@ class WasmInstanceObject : public JSObject {
|
||||
V(kImportedMutableGlobalsOffset, kPointerSize) /* untagged */ \
|
||||
V(kIndirectFunctionTableSigIdsOffset, kPointerSize) /* untagged */ \
|
||||
V(kIndirectFunctionTableTargetsOffset, kPointerSize) /* untagged */ \
|
||||
V(kJumpTableAdjustedStartOffset, kPointerSize) /* untagged */ \
|
||||
V(kIndirectFunctionTableSizeOffset, kUInt32Size) /* untagged */ \
|
||||
V(k64BitArchPaddingOffset, kPointerSize - kUInt32Size) /* padding */ \
|
||||
V(kSize, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user