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