Commit c2928fe4 authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

Revert "Revert "[wasm] Consolidate function table representation.""

This reverts commit 862d605c.

Reason for revert: fixed compile issue

Original change's description:
> Revert "[wasm] Consolidate function table representation."
> 
> This reverts commit 4a45f35f.
> 
> Reason for revert: https://build.chromium.org/p/client.v8/builders/V8%20Linux64%20-%20debug%20builder/builds/25471 
> 
> Original change's description:
> > [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: Brad Nelson <bradnelson@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#46917}
> 
> TBR=bradnelson@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
> 
> Change-Id: Ie7d04f7ec74d6d0b3783df1c78c91c100ab784f4
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/588627
> Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#46918}

TBR=bradnelson@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org

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