Commit 7e200011 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Remove deprecated WASM_CONTEXT_TABLES macro.

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

Change-Id: I57d5065490703e0106a87bbb6855e750ee5ca34a
Reviewed-on: https://chromium-review.googlesource.com/959002
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51887}
parent 825d0175
......@@ -2630,69 +2630,41 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t sig_index, Node** args,
static_assert(compiler::kFunctionTableCodeOffset == 1, "consistency");
int32_t canonical_sig_num = env_->module->signature_ids[sig_index];
if (WASM_CONTEXT_TABLES) {
// The table entries are {IndirectFunctionTableEntry} structs.
Node* scaled_key =
graph()->NewNode(machine->Int32Mul(), key,
Int32Constant(sizeof(IndirectFunctionTableEntry)));
const Operator* add = nullptr;
if (machine->Is64()) {
scaled_key = graph()->NewNode(machine->ChangeInt32ToInt64(), scaled_key);
add = machine->Int64Add();
} else {
add = machine->Int32Add();
}
Node* entry_address = graph()->NewNode(add, table, scaled_key);
Node* loaded_sig = graph()->NewNode(
machine->Load(MachineType::Int32()), entry_address,
Int32Constant(offsetof(IndirectFunctionTableEntry, sig_id)), *effect_,
*control_);
Node* sig_match = graph()->NewNode(machine->WordEqual(), loaded_sig,
Int32Constant(canonical_sig_num));
TrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position);
Node* target = graph()->NewNode(
machine->Load(MachineType::Pointer()), entry_address,
Int32Constant(offsetof(IndirectFunctionTableEntry, target)), *effect_,
*control_);
Node* loaded_context = graph()->NewNode(
machine->Load(MachineType::Pointer()), entry_address,
Int32Constant(offsetof(IndirectFunctionTableEntry, context)), *effect_,
*control_);
args[0] = target;
return BuildWasmCall(sig, args, rets, position, loaded_context);
}
// The table entries are elements of a fixed array.
ElementAccess access = AccessBuilder::ForFixedArrayElement();
const int fixed_offset = access.header_size - access.tag();
Node* key_offset = graph()->NewNode(machine->Word32Shl(), key,
Int32Constant(kPointerSizeLog2 + 1));
Node* loaded_sig =
graph()->NewNode(machine->Load(MachineType::AnyTagged()), table,
graph()->NewNode(machine->Int32Add(), key_offset,
Int32Constant(fixed_offset)),
*effect_, *control_);
CHECK_GE(canonical_sig_num, 0);
// The table entries are {IndirectFunctionTableEntry} structs.
Node* scaled_key =
graph()->NewNode(machine->Int32Mul(), key,
Int32Constant(sizeof(IndirectFunctionTableEntry)));
const Operator* add = nullptr;
if (machine->Is64()) {
scaled_key = graph()->NewNode(machine->ChangeInt32ToInt64(), scaled_key);
add = machine->Int64Add();
} else {
add = machine->Int32Add();
}
Node* entry_address = graph()->NewNode(add, table, scaled_key);
Node* loaded_sig = graph()->NewNode(
machine->Load(MachineType::Int32()), entry_address,
Int32Constant(offsetof(IndirectFunctionTableEntry, sig_id)), *effect_,
*control_);
Node* sig_match = graph()->NewNode(machine->WordEqual(), loaded_sig,
jsgraph()->SmiConstant(canonical_sig_num));
Int32Constant(canonical_sig_num));
TrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position);
// Load code object from the table. It is held by a Foreign.
Node* entry = graph()->NewNode(
machine->Load(MachineType::AnyTagged()), table,
graph()->NewNode(machine->Int32Add(), key_offset,
Uint32Constant(fixed_offset + kPointerSize)),
*effect_, *control_);
args[0] = entry;
constexpr Node* wasm_context = nullptr;
const bool use_retpoline = FLAG_untrusted_code_mitigations;
return BuildWasmCall(sig, args, rets, position, wasm_context, use_retpoline);
Node* target = graph()->NewNode(
machine->Load(MachineType::Pointer()), entry_address,
Int32Constant(offsetof(IndirectFunctionTableEntry, target)), *effect_,
*control_);
Node* loaded_context = graph()->NewNode(
machine->Load(MachineType::Pointer()), entry_address,
Int32Constant(offsetof(IndirectFunctionTableEntry, context)), *effect_,
*control_);
args[0] = target;
return BuildWasmCall(sig, args, rets, position, loaded_context);
}
Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) {
......@@ -3401,10 +3373,9 @@ void WasmGraphBuilder::BuildCWasmEntry() {
*effect_ = start;
// Create parameter nodes (offset by 1 for the receiver parameter).
Node* code_obj = nullptr;
Node* foreign_code_obj = Param(CWasmEntryParameters::kCodeObject + 1);
MachineOperatorBuilder* machine = jsgraph()->machine();
code_obj = graph()->NewNode(
Node* code_obj = graph()->NewNode(
machine->Load(MachineType::Pointer()), foreign_code_obj,
Int32Constant(Foreign::kForeignAddressOffset - kHeapObjectTag), *effect_,
*control_);
......@@ -3637,43 +3608,19 @@ Node* WasmGraphBuilder::CurrentMemoryPages() {
void WasmGraphBuilder::GetFunctionTableNodes(uint32_t table_index, Node** table,
Node** table_size) {
if (WASM_CONTEXT_TABLES) {
// The table address and size are stored in the WasmContext.
// Don't bother caching them, since they are only used in indirect calls,
// which would cause them to be spilled on the stack anyway.
*table = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::UintPtr()), wasm_context_.get(),
jsgraph()->Int32Constant(
static_cast<int32_t>(offsetof(WasmContext, table))),
*effect_, *control_);
*table_size = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::Uint32()), wasm_context_.get(),
jsgraph()->Int32Constant(
static_cast<int32_t>(offsetof(WasmContext, table_size))),
*effect_, *control_);
} else {
// The function table nodes are relocatable constants.
if (function_tables_.size() == 0) {
size_t tables_size = env_->function_tables.size();
for (size_t i = 0; i < tables_size; ++i) {
wasm::GlobalHandleAddress function_handle_address =
env_->function_tables[i];
Node* table_addr = jsgraph()->RelocatableIntPtrConstant(
reinterpret_cast<intptr_t>(function_handle_address),
RelocInfo::WASM_GLOBAL_HANDLE);
uint32_t table_size = env_->module->function_tables[i].initial_size;
Node* size = jsgraph()->RelocatableInt32Constant(
static_cast<uint32_t>(table_size),
RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE);
function_tables_.push_back({table_addr, size});
}
}
*table_size = function_tables_[table_index].size;
*table =
graph()->NewNode(jsgraph()->machine()->Load(MachineType::AnyTagged()),
function_tables_[table_index].table_addr,
jsgraph()->IntPtrConstant(0), *effect_, *control_);
}
// The table address and size are stored in the WasmContext.
// Don't bother caching them, since they are only used in indirect calls,
// which would cause them to be spilled on the stack anyway.
*table = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::UintPtr()), wasm_context_.get(),
jsgraph()->Int32Constant(
static_cast<int32_t>(offsetof(WasmContext, table))),
*effect_, *control_);
*table_size = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::Uint32()), wasm_context_.get(),
jsgraph()->Int32Constant(
static_cast<int32_t>(offsetof(WasmContext, table_size))),
*effect_, *control_);
}
Node* WasmGraphBuilder::BuildModifyThreadInWasmFlag(bool new_value) {
......
......@@ -1807,15 +1807,14 @@ bool WasmCompiledFrame::at_to_number_conversion() const {
// Check whether our callee is a WASM_TO_JS frame, and this frame is at the
// ToNumber conversion call.
Address callee_pc = reinterpret_cast<Address>(this->callee_pc());
int pos = -1;
wasm::WasmCode* code =
callee_pc
? isolate()->wasm_engine()->code_manager()->LookupCode(callee_pc)
: nullptr;
if (!code || code->kind() != wasm::WasmCode::kWasmToJsWrapper) return false;
int offset = static_cast<int>(callee_pc - code->instructions().start());
pos = FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(code,
offset);
int pos = FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(
code, offset);
DCHECK(pos == 0 || pos == 1);
// The imported call has position 0, ToNumber has position 1.
return !!pos;
......
......@@ -64,16 +64,6 @@ class MovableLabel {
};
#endif
wasm::WasmValue WasmPtrValue(uintptr_t ptr) {
using int_t = std::conditional<kPointerSize == 8, uint64_t, uint32_t>::type;
static_assert(sizeof(int_t) == sizeof(uintptr_t), "weird uintptr_t");
return wasm::WasmValue(static_cast<int_t>(ptr));
}
wasm::WasmValue WasmPtrValue(void* ptr) {
return WasmPtrValue(reinterpret_cast<uintptr_t>(ptr));
}
compiler::CallDescriptor* GetLoweredCallDescriptor(
Zone* zone, compiler::CallDescriptor* call_desc) {
return kPointerSize == 4 ? compiler::GetI32WasmCallDescriptor(zone, call_desc)
......@@ -1258,9 +1248,6 @@ class LiftoffCompiler {
return;
}
// Assume only one table for now.
uint32_t table_index = 0;
// Pop the index.
LiftoffRegister index = __ PopToRegister();
// If that register is still being used after popping, we move it to another
......@@ -1287,103 +1274,49 @@ class LiftoffCompiler {
static constexpr LoadType kPointerLoadType =
kPointerSize == 8 ? LoadType::kI64Load : LoadType::kI32Load;
static constexpr int kFixedArrayOffset =
FixedArray::kHeaderSize - kHeapObjectTag;
uint32_t canonical_sig_num = env_->module->signature_ids[operand.sig_index];
DCHECK_GE(canonical_sig_num, 0);
DCHECK_GE(kMaxInt, canonical_sig_num);
if (WASM_CONTEXT_TABLES) {
// Compare against table size stored in {wasm_context->table_size}.
__ LoadFromContext(tmp_const.gp(), offsetof(WasmContext, table_size),
sizeof(uint32_t));
__ emit_cond_jump(kUnsignedGreaterEqual, invalid_func_label, kWasmI32,
index.gp(), tmp_const.gp());
// Load the table from {wasm_context->table}
__ LoadFromContext(table.gp(), offsetof(WasmContext, table),
kPointerSize);
// Load the signature from {wasm_context->table[$index].sig_id}
// == wasm_context.table + $index * #sizeof(IndirectionFunctionTableEntry)
// + #offsetof(sig_id)
__ LoadConstant(
tmp_const,
WasmValue(static_cast<uint32_t>(sizeof(IndirectFunctionTableEntry))));
__ emit_i32_mul(index.gp(), index.gp(), tmp_const.gp());
__ Load(scratch, table.gp(), index.gp(),
offsetof(IndirectFunctionTableEntry, sig_id), LoadType::kI32Load,
pinned);
__ LoadConstant(tmp_const, WasmValue(canonical_sig_num));
Label* sig_mismatch_label = AddOutOfLineTrap(
decoder->position(), Builtins::kThrowWasmTrapFuncSigMismatch);
__ emit_cond_jump(kUnequal, sig_mismatch_label,
LiftoffAssembler::kWasmIntPtr, scratch.gp(),
tmp_const.gp());
// Load the target address from {wasm_context->table[$index].target}
__ Load(scratch, table.gp(), index.gp(),
offsetof(IndirectFunctionTableEntry, target), kPointerLoadType,
pinned);
// Load the context from {wasm_context->table[$index].context}
// TODO(wasm): directly allocate the correct context register to avoid
// any potential moves.
__ Load(tmp_const, table.gp(), index.gp(),
offsetof(IndirectFunctionTableEntry, context), kPointerLoadType,
pinned);
explicit_context = &tmp_const;
} else {
// Compare against table size, which is a patchable constant.
uint32_t table_size =
env_->module->function_tables[table_index].initial_size;
__ LoadConstant(tmp_const, WasmValue(table_size),
RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE);
__ emit_cond_jump(kUnsignedGreaterEqual, invalid_func_label, kWasmI32,
index.gp(), tmp_const.gp());
wasm::GlobalHandleAddress function_table_handle_address =
env_->function_tables[table_index];
__ LoadConstant(table, WasmPtrValue(function_table_handle_address),
RelocInfo::WASM_GLOBAL_HANDLE);
__ Load(table, table.gp(), no_reg, 0, kPointerLoadType, pinned);
// Load signature from the table and check.
// The table is a FixedArray; signatures are encoded as SMIs.
// [sig1, code1, sig2, code2, sig3, code3, ...]
static_assert(compiler::kFunctionTableEntrySize == 2, "consistency");
static_assert(compiler::kFunctionTableSignatureOffset == 0,
"consistency");
static_assert(compiler::kFunctionTableCodeOffset == 1, "consistency");
__ LoadConstant(tmp_const, WasmValue(kPointerSizeLog2 + 1));
// Shift index such that it's the offset of the signature in the
// FixedArray.
__ emit_i32_shl(index.gp(), index.gp(), tmp_const.gp(), pinned);
// Load the signature.
__ Load(scratch, table.gp(), index.gp(), kFixedArrayOffset,
kPointerLoadType, pinned);
__ LoadConstant(tmp_const, WasmPtrValue(Smi::FromInt(canonical_sig_num)));
Label* sig_mismatch_label = AddOutOfLineTrap(
decoder->position(), Builtins::kThrowWasmTrapFuncSigMismatch);
__ emit_cond_jump(kUnequal, sig_mismatch_label,
LiftoffAssembler::kWasmIntPtr, scratch.gp(),
tmp_const.gp());
// Load code object.
__ Load(scratch, table.gp(), index.gp(), kFixedArrayOffset + kPointerSize,
kPointerLoadType, pinned);
// Move the pointer from the Code object to the instruction start.
__ LoadConstant(tmp_const,
WasmPtrValue(Code::kHeaderSize - kHeapObjectTag));
__ emit_ptrsize_add(scratch.gp(), scratch.gp(), tmp_const.gp());
}
// Compare against table size stored in {wasm_context->table_size}.
__ LoadFromContext(tmp_const.gp(), offsetof(WasmContext, table_size),
sizeof(uint32_t));
__ emit_cond_jump(kUnsignedGreaterEqual, invalid_func_label, kWasmI32,
index.gp(), tmp_const.gp());
// Load the table from {wasm_context->table}
__ LoadFromContext(table.gp(), offsetof(WasmContext, table), kPointerSize);
// Load the signature from {wasm_context->table[$index].sig_id}
// == wasm_context.table + $index * #sizeof(IndirectionFunctionTableEntry)
// + #offsetof(sig_id)
__ LoadConstant(
tmp_const,
WasmValue(static_cast<uint32_t>(sizeof(IndirectFunctionTableEntry))));
__ emit_i32_mul(index.gp(), index.gp(), tmp_const.gp());
__ Load(scratch, table.gp(), index.gp(),
offsetof(IndirectFunctionTableEntry, sig_id), LoadType::kI32Load,
pinned);
__ LoadConstant(tmp_const, WasmValue(canonical_sig_num));
Label* sig_mismatch_label = AddOutOfLineTrap(
decoder->position(), Builtins::kThrowWasmTrapFuncSigMismatch);
__ emit_cond_jump(kUnequal, sig_mismatch_label,
LiftoffAssembler::kWasmIntPtr, scratch.gp(),
tmp_const.gp());
// Load the target address from {wasm_context->table[$index].target}
__ Load(scratch, table.gp(), index.gp(),
offsetof(IndirectFunctionTableEntry, target), kPointerLoadType,
pinned);
// Load the context from {wasm_context->table[$index].context}
// TODO(wasm): directly allocate the correct context register to avoid
// any potential moves.
__ Load(tmp_const, table.gp(), index.gp(),
offsetof(IndirectFunctionTableEntry, context), kPointerLoadType,
pinned);
explicit_context = &tmp_const;
source_position_table_builder_->AddPosition(
__ pc_offset(), SourcePosition(decoder->position()), false);
......
......@@ -557,7 +557,6 @@ Address CompileLazy(Isolate* isolate) {
int func_index = static_cast<int>(result->index());
if (!exp_deopt_data_entry.is_null() && exp_deopt_data_entry->IsFixedArray()) {
int patched = 0;
Handle<FixedArray> exp_deopt_data =
Handle<FixedArray>::cast(exp_deopt_data_entry);
......@@ -568,35 +567,19 @@ Address CompileLazy(Isolate* isolate) {
// of <export_table, index> followed by undefined values. Use this
// information here to patch all export tables.
Address target = result->instructions().start();
Handle<Foreign> foreign_holder =
isolate->factory()->NewForeign(target, TENURED);
for (int idx = 0, end = exp_deopt_data->length(); idx < end; idx += 2) {
if (exp_deopt_data->get(idx)->IsUndefined(isolate)) break;
DisallowHeapAllocation no_gc;
int exp_index = Smi::ToInt(exp_deopt_data->get(idx + 1));
FixedArray* exp_table = FixedArray::cast(exp_deopt_data->get(idx));
if (WASM_CONTEXT_TABLES) {
// TODO(titzer): patching of function tables for lazy compilation
// only works for a single instance.
instance->wasm_context()->get()->table[exp_index].target = target;
} else {
int table_index = compiler::FunctionTableCodeOffset(exp_index);
DCHECK_EQ(Foreign::cast(exp_table->get(table_index))->foreign_address(),
lazy_stub_or_copy->instructions().start());
exp_table->set(table_index, *foreign_holder);
++patched;
}
// TODO(titzer): patching of function tables for lazy compilation
// only works for a single instance.
instance->wasm_context()->get()->table[exp_index].target = target;
}
// After processing, remove the list of exported entries, such that we don't
// do the patching redundantly.
compiled_module->lazy_compile_data()->set(
func_index, isolate->heap()->undefined_value());
if (!WASM_CONTEXT_TABLES) {
DCHECK_LT(0, patched);
USE(patched);
}
}
return result->instructions().start();
......@@ -1756,7 +1739,7 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
funcs_to_compile > 1 &&
V8::GetCurrentPlatform()->NumberOfWorkerThreads() > 0;
// Avoid a race condition by collecting results into a second vector.
std::vector<Handle<Code>> results(0);
std::vector<Handle<Code>> results;
if (compile_parallel) {
CompileInParallel(wire_bytes, env.get(), results, thrower);
......@@ -2432,11 +2415,8 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
i += kFunctionTableEntrySize) {
table_instance.function_table->set(i, Smi::FromInt(kInvalidSigIndex));
}
WasmContext* wasm_context = nullptr;
if (WASM_CONTEXT_TABLES) {
wasm_context = instance->wasm_context()->get();
EnsureWasmContextTable(wasm_context, imported_cur_size);
}
WasmContext* wasm_context = instance->wasm_context()->get();
EnsureWasmContextTable(wasm_context, imported_cur_size);
// Initialize the dispatch table with the (foreign) JS functions
// that are already in the table.
for (int i = 0; i < imported_cur_size; ++i) {
......@@ -2454,30 +2434,17 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
// id, then the signature does not appear at all in this module,
// so putting {-1} in the table will cause checks to always fail.
auto target = Handle<WasmExportedFunction>::cast(val);
if (!WASM_CONTEXT_TABLES) {
FunctionSig* sig = nullptr;
Handle<Code> code =
MakeWasmToWasmWrapper(isolate_, target, nullptr, &sig,
&imported_wasm_instances, instance, 0)
.GetCode();
int sig_index = module_->signature_map.Find(sig);
table_instance.function_table->set(
compiler::FunctionTableSigOffset(i), Smi::FromInt(sig_index));
table_instance.function_table->set(
compiler::FunctionTableCodeOffset(i), *code);
} else {
Handle<WasmInstanceObject> imported_instance =
handle(target->instance());
const wasm::WasmCode* exported_code =
target->GetWasmCode().GetWasmCode();
FunctionSig* sig = imported_instance->module()
->functions[exported_code->index()]
.sig;
auto& entry = wasm_context->table[i];
entry.context = imported_instance->wasm_context()->get();
entry.sig_id = module_->signature_map.Find(sig);
entry.target = exported_code->instructions().start();
}
Handle<WasmInstanceObject> imported_instance =
handle(target->instance());
const wasm::WasmCode* exported_code =
target->GetWasmCode().GetWasmCode();
FunctionSig* sig = imported_instance->module()
->functions[exported_code->index()]
.sig;
auto& entry = wasm_context->table[i];
entry.context = imported_instance->wasm_context()->get();
entry.sig_id = module_->signature_map.Find(sig);
entry.target = exported_code->instructions().start();
}
num_imported_tables++;
......@@ -2859,10 +2826,8 @@ void InstanceBuilder::InitializeTables(
int num_table_entries = static_cast<int>(table.initial_size);
int table_size = compiler::kFunctionTableEntrySize * num_table_entries;
if (WASM_CONTEXT_TABLES) {
WasmContext* wasm_context = instance->wasm_context()->get();
EnsureWasmContextTable(wasm_context, num_table_entries);
}
WasmContext* wasm_context = instance->wasm_context()->get();
EnsureWasmContextTable(wasm_context, num_table_entries);
if (table_instance.function_table.is_null()) {
// Create a new dispatch table if necessary.
......@@ -2965,13 +2930,11 @@ void InstanceBuilder::LoadTableSegments(Handle<FixedArray> code_table,
compiler::FunctionTableCodeOffset(table_index),
*value_to_update_with);
if (WASM_CONTEXT_TABLES) {
WasmContext* wasm_context = instance->wasm_context()->get();
auto& entry = wasm_context->table[table_index];
entry.sig_id = sig_id;
entry.context = wasm_context;
entry.target = wasm_code.instructions().start();
}
WasmContext* wasm_context = instance->wasm_context()->get();
auto& entry = wasm_context->table[table_index];
entry.sig_id = sig_id;
entry.context = wasm_context;
entry.target = wasm_code.instructions().start();
if (!table_instance.table_object.is_null()) {
// Update the table object's other dispatch tables.
......
......@@ -2630,50 +2630,25 @@ class ThreadImpl {
DCHECK_EQ(canonical_sig_index,
module()->signature_map.Find(module()->signatures[sig_index]));
if (!WASM_CONTEXT_TABLES) {
// Check signature.
FixedArray* fun_tables = compiled_module->function_tables();
if (table_index >= static_cast<uint32_t>(fun_tables->length())) {
return {ExternalCallResult::INVALID_FUNC};
}
// Reconstitute the global handle to the function table, from the
// address stored in the respective table of tables.
int table_index_as_int = static_cast<int>(table_index);
FixedArray* fun_table = *reinterpret_cast<FixedArray**>(
WasmCompiledModule::GetTableValue(fun_tables, table_index_as_int));
// Function tables store <smi, code> pairs.
int num_funcs_in_table =
fun_table->length() / compiler::kFunctionTableEntrySize;
if (entry_index >= static_cast<uint32_t>(num_funcs_in_table)) {
return {ExternalCallResult::INVALID_FUNC};
}
int found_sig = Smi::ToInt(fun_table->get(
compiler::FunctionTableSigOffset(static_cast<int>(entry_index))));
if (static_cast<uint32_t>(found_sig) != canonical_sig_index) {
return {ExternalCallResult::SIGNATURE_MISMATCH};
}
} else {
// The function table is stored in the wasm context.
// TODO(wasm): the wasm interpreter currently supports only one table.
CHECK_EQ(0, table_index);
// Bounds check against table size.
if (entry_index >= wasm_context_->table_size) {
return {ExternalCallResult::INVALID_FUNC};
}
// Signature check.
int32_t entry_sig = wasm_context_->table[entry_index].sig_id;
if (entry_sig != static_cast<int32_t>(canonical_sig_index)) {
return {ExternalCallResult::SIGNATURE_MISMATCH};
}
// Load the target address (first instruction of code).
Address first_instr = wasm_context_->table[entry_index].target;
// TODO(titzer): load the wasm context instead of relying on the
// target code being specialized to the target instance.
// Get code object.
target =
isolate->wasm_engine()->code_manager()->GetCodeFromStartAddress(
first_instr);
// The function table is stored in the wasm context.
// TODO(wasm): the wasm interpreter currently supports only one table.
CHECK_EQ(0, table_index);
// Bounds check against table size.
if (entry_index >= wasm_context_->table_size) {
return {ExternalCallResult::INVALID_FUNC};
}
// Signature check.
int32_t entry_sig = wasm_context_->table[entry_index].sig_id;
if (entry_sig != static_cast<int32_t>(canonical_sig_index)) {
return {ExternalCallResult::SIGNATURE_MISMATCH};
}
// Load the target address (first instruction of code).
Address first_instr = wasm_context_->table[entry_index].target;
// TODO(titzer): load the wasm context instead of relying on the
// target code being specialized to the target instance.
// Get code object.
target = isolate->wasm_engine()->code_manager()->GetCodeFromStartAddress(
first_instr);
}
// Call the code object. Use a new HandleScope to avoid leaking /
......
This diff is collapsed.
......@@ -38,9 +38,6 @@ class WasmCompiledModule;
class WasmDebugInfo;
class WasmInstanceObject;
// TODO(mstarzinger): Remove this macro!
#define WASM_CONTEXT_TABLES true
#define DECL_OPTIONAL_ACCESSORS(name, type) \
INLINE(bool has_##name()); \
DECL_ACCESSORS(name, type)
......
......@@ -152,14 +152,12 @@ void TestingModuleBuilder::AddIndirectFunctionTable(
function_tables_.push_back(
isolate_->global_handles()->Create(func_table).address());
if (WASM_CONTEXT_TABLES) {
WasmContext* wasm_context = instance_object()->wasm_context()->get();
wasm_context->table = reinterpret_cast<IndirectFunctionTableEntry*>(
calloc(table_size, sizeof(IndirectFunctionTableEntry)));
wasm_context->table_size = table_size;
for (uint32_t i = 0; i < table_size; i++) {
wasm_context->table[i].sig_id = -1;
}
WasmContext* wasm_context = instance_object()->wasm_context()->get();
wasm_context->table = reinterpret_cast<IndirectFunctionTableEntry*>(
calloc(table_size, sizeof(IndirectFunctionTableEntry)));
wasm_context->table_size = table_size;
for (uint32_t i = 0; i < table_size; i++) {
wasm_context->table[i].sig_id = -1;
}
}
......@@ -177,17 +175,11 @@ void TestingModuleBuilder::PopulateIndirectFunctionTable() {
int sig_id = test_module_.signature_map.Find(function.sig);
function_table->set(compiler::FunctionTableSigOffset(j),
Smi::FromInt(sig_id));
if (WASM_CONTEXT_TABLES) {
auto start = native_module_->GetCode(function.func_index)
->instructions()
.start();
wasm_context->table[j].context = wasm_context;
wasm_context->table[j].sig_id = sig_id;
wasm_context->table[j].target = start;
} else {
function_table->set(compiler::FunctionTableCodeOffset(j),
*function_code_[function.func_index]);
}
auto start =
native_module_->GetCode(function.func_index)->instructions().start();
wasm_context->table[j].context = wasm_context;
wasm_context->table[j].sig_id = sig_id;
wasm_context->table[j].target = start;
}
}
}
......
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