Commit 4a45f35f authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] Consolidate function table representation.

This CL avoids the need to reference the function tables (and signatures)
as either fixed arrays or vectors, preferring vectors.

The only place we need fixed arrays is on the compiled module, to support
serialization. When we move off the GC heap, we'll also move away
from fixed arrays in that last case.

The CL aids with getting wasm of the GC heap, by reducing the places 
and representations we'll need to change  when changing the way we 
reference fixed tables.

Bug: 
Change-Id: Id4e43905a3df39062bf2839fa72dd5d9a0fe87da
Reviewed-on: https://chromium-review.googlesource.com/588334
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46917}
parent 675e00d8
......@@ -337,23 +337,17 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObject(
// Initialize the indirect tables with placeholders.
int function_table_count = static_cast<int>(module_->function_tables.size());
Handle<FixedArray> function_tables =
factory->NewFixedArray(function_table_count, TENURED);
Handle<FixedArray> signature_tables =
factory->NewFixedArray(function_table_count, TENURED);
for (int i = 0; i < function_table_count; ++i) {
temp_instance.function_tables[i] = factory->NewFixedArray(1, TENURED);
temp_instance.signature_tables[i] = factory->NewFixedArray(1, TENURED);
function_tables->set(i, *temp_instance.function_tables[i]);
signature_tables->set(i, *temp_instance.signature_tables[i]);
}
TimedHistogramScope wasm_compile_module_time_scope(
module_->is_wasm() ? counters()->wasm_compile_wasm_module_time()
: counters()->wasm_compile_asm_module_time());
return CompileToModuleObjectInternal(
thrower, wire_bytes, asm_js_script, asm_js_offset_table_bytes, factory,
&temp_instance, &function_tables, &signature_tables);
return CompileToModuleObjectInternal(thrower, wire_bytes, asm_js_script,
asm_js_offset_table_bytes, factory,
&temp_instance);
}
namespace {
......@@ -562,8 +556,7 @@ void ResolvePromise(Isolate* isolate, Handle<Context> context,
MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
ErrorThrower* thrower, const ModuleWireBytes& wire_bytes,
Handle<Script> asm_js_script, Vector<const byte> asm_js_offset_table_bytes,
Factory* factory, WasmInstance* temp_instance,
Handle<FixedArray>* function_tables, Handle<FixedArray>* signature_tables) {
Factory* factory, WasmInstance* temp_instance) {
ModuleBytesEnv module_env(module_.get(), temp_instance, wire_bytes);
// The {code_table} array contains import wrappers and functions (which
......@@ -668,7 +661,8 @@ MaybeHandle<WasmModuleObject> ModuleCompiler::CompileToModuleObjectInternal(
// serializable. Instantiation may occur off a deserialized version of this
// object.
Handle<WasmCompiledModule> compiled_module = WasmCompiledModule::New(
isolate_, shared, code_table, *function_tables, *signature_tables);
isolate_, shared, code_table, *module_env.module_env.function_tables,
*module_env.module_env.signature_tables);
// If we created a wasm script, finish it now and make it public to the
// debugger.
......@@ -1912,8 +1906,6 @@ AsyncCompileJob::~AsyncCompileJob() {
void AsyncCompileJob::ReopenHandlesInDeferredScope() {
DeferredHandleScope deferred(isolate_);
function_tables_ = handle(*function_tables_, isolate_);
signature_tables_ = handle(*signature_tables_, isolate_);
code_table_ = handle(*code_table_, isolate_);
temp_instance_->ReopenHandles(isolate_);
compiler_->ReopenHandlesInDeferredScope();
......@@ -2079,18 +2071,11 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
// Initialize the indirect tables with placeholders.
int function_table_count =
static_cast<int>(module_->function_tables.size());
job_->function_tables_ =
factory->NewFixedArray(function_table_count, TENURED);
job_->signature_tables_ =
factory->NewFixedArray(function_table_count, TENURED);
for (int i = 0; i < function_table_count; ++i) {
job_->temp_instance_->function_tables[i] =
factory->NewFixedArray(1, TENURED);
job_->temp_instance_->signature_tables[i] =
factory->NewFixedArray(1, TENURED);
job_->function_tables_->set(i, *job_->temp_instance_->function_tables[i]);
job_->signature_tables_->set(i,
*job_->temp_instance_->signature_tables[i]);
}
// The {code_table} array contains import wrappers and functions (which
......@@ -2302,9 +2287,10 @@ class AsyncCompileJob::FinishCompile : public CompileStep {
// and information needed at instantiation time. This object needs to be
// serializable. Instantiation may occur off a deserialized version of
// this object.
job_->compiled_module_ = WasmCompiledModule::New(
job_->isolate_, shared, job_->code_table_, job_->function_tables_,
job_->signature_tables_);
job_->compiled_module_ =
WasmCompiledModule::New(job_->isolate_, shared, job_->code_table_,
job_->temp_instance_->function_tables,
job_->temp_instance_->signature_tables);
// Finish the wasm script now and make it public to the debugger.
script->set_wasm_compiled_module(*job_->compiled_module_);
......
......@@ -163,8 +163,7 @@ class ModuleCompiler {
ErrorThrower* thrower, const ModuleWireBytes& wire_bytes,
Handle<Script> asm_js_script,
Vector<const byte> asm_js_offset_table_bytes, Factory* factory,
WasmInstance* temp_instance, Handle<FixedArray>* function_tables,
Handle<FixedArray>* signature_tables);
WasmInstance* temp_instance);
Isolate* isolate_;
std::unique_ptr<WasmModule> module_;
......@@ -348,8 +347,6 @@ class AsyncCompileJob {
std::vector<DeferredHandles*> deferred_handles_;
Handle<WasmModuleObject> module_object_;
Handle<FixedArray> function_tables_;
Handle<FixedArray> signature_tables_;
Handle<WasmCompiledModule> compiled_module_;
Handle<FixedArray> code_table_;
std::unique_ptr<WasmInstance> temp_instance_ = nullptr;
......
......@@ -793,8 +793,8 @@ void WasmSharedModuleData::PrepareForLazyCompilation(
Handle<WasmCompiledModule> WasmCompiledModule::New(
Isolate* isolate, Handle<WasmSharedModuleData> shared,
Handle<FixedArray> code_table,
MaybeHandle<FixedArray> maybe_empty_function_tables,
MaybeHandle<FixedArray> maybe_signature_tables) {
const std::vector<Handle<FixedArray>>& function_tables,
const std::vector<Handle<FixedArray>>& signature_tables) {
Handle<FixedArray> ret =
isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED);
// WasmCompiledModule::cast would fail since fields are not set yet.
......@@ -804,15 +804,22 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
compiled_module->set_shared(shared);
compiled_module->set_native_context(isolate->native_context());
compiled_module->set_code_table(code_table);
int function_table_count =
static_cast<int>(shared->module()->function_tables.size());
size_t function_table_count = shared->module()->function_tables.size();
if (function_table_count > 0) {
compiled_module->set_signature_tables(
maybe_signature_tables.ToHandleChecked());
compiled_module->set_empty_function_tables(
maybe_empty_function_tables.ToHandleChecked());
compiled_module->set_function_tables(
maybe_empty_function_tables.ToHandleChecked());
DCHECK_EQ(function_tables.size(), signature_tables.size());
DCHECK_EQ(function_tables.size(), function_table_count);
int count_as_int = static_cast<int>(function_table_count);
Handle<FixedArray> sig_tables =
isolate->factory()->NewFixedArray(count_as_int, TENURED);
Handle<FixedArray> func_tables =
isolate->factory()->NewFixedArray(count_as_int, TENURED);
for (int i = 0; i < count_as_int; ++i) {
sig_tables->set(i, *(signature_tables[static_cast<size_t>(i)]));
func_tables->set(i, *(function_tables[static_cast<size_t>(i)]));
}
compiled_module->set_signature_tables(sig_tables);
compiled_module->set_empty_function_tables(func_tables);
compiled_module->set_function_tables(func_tables);
}
// TODO(mtrofin): we copy these because the order of finalization isn't
// reliable, and we need these at Reset (which is called at
......
......@@ -424,8 +424,8 @@ class WasmCompiledModule : public FixedArray {
static Handle<WasmCompiledModule> New(
Isolate* isolate, Handle<WasmSharedModuleData> shared,
Handle<FixedArray> code_table,
MaybeHandle<FixedArray> maybe_empty_function_tables,
MaybeHandle<FixedArray> maybe_signature_tables);
const std::vector<Handle<FixedArray>>& function_tables,
const std::vector<Handle<FixedArray>>& signature_tables);
static Handle<WasmCompiledModule> Clone(Isolate* isolate,
Handle<WasmCompiledModule> module);
......
......@@ -344,8 +344,7 @@ class TestingModule : public ModuleEnv {
Handle<FixedArray> code_table = isolate_->factory()->NewFixedArray(0);
Handle<WasmCompiledModule> compiled_module = WasmCompiledModule::New(
isolate_, shared_module_data, code_table, MaybeHandle<FixedArray>(),
MaybeHandle<FixedArray>());
isolate_, shared_module_data, code_table, {}, {});
Handle<FixedArray> weak_exported = isolate_->factory()->NewFixedArray(0);
compiled_module->set_weak_exported_functions(weak_exported);
DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
......
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