Commit 2809fdbd authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] separate code table from export wrappers

We're moving the code table off the heap, while the export wrappers
are instance-specific, and, thus, won't move off the heap.

Bug: 
Change-Id: I392fb537c7708a0a06f3468f714335df29bc401b
Reviewed-on: https://chromium-review.googlesource.com/636309Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47619}
parent 0f0e274b
This diff is collapsed.
......@@ -297,8 +297,7 @@ class InstanceBuilder {
// Process the exports, creating wrappers for functions, tables, memories,
// and globals.
void ProcessExports(Handle<FixedArray> code_table,
Handle<WasmInstanceObject> instance,
void ProcessExports(Handle<WasmInstanceObject> instance,
Handle<WasmCompiledModule> compiled_module);
void InitializeTables(Handle<WasmInstanceObject> instance,
......@@ -354,6 +353,7 @@ class AsyncCompileJob {
Handle<WasmModuleObject> module_object_;
Handle<WasmCompiledModule> compiled_module_;
Handle<FixedArray> code_table_;
Handle<FixedArray> export_wrappers_;
size_t outstanding_units_ = 0;
std::unique_ptr<CompileStep> step_;
CancelableTaskManager background_task_manager_;
......
......@@ -131,9 +131,9 @@ bool CodeSpecialization::ApplyToWholeInstance(
WasmModule* module = compiled_module->module();
std::vector<WasmFunction>* wasm_functions =
&compiled_module->module()->functions;
DCHECK_EQ(wasm_functions->size() +
compiled_module->module()->num_exported_functions,
code_table->length());
DCHECK_EQ(wasm_functions->size(), code_table->length());
DCHECK_EQ(compiled_module->export_wrappers()->length(),
compiled_module->module()->num_exported_functions);
bool changed = false;
int func_index = module->num_imported_functions;
......@@ -151,10 +151,12 @@ bool CodeSpecialization::ApplyToWholeInstance(
// If we patch direct calls, the instance registered for that
// (relocate_direct_calls_instance) should match the instance we currently
// patch (instance).
int wrapper_index = 0;
DCHECK_EQ(instance, *relocate_direct_calls_instance);
for (auto exp : module->export_table) {
if (exp.kind != kExternalFunction) continue;
Code* export_wrapper = Code::cast(code_table->get(func_index));
Code* export_wrapper =
Code::cast(compiled_module->export_wrappers()->get(wrapper_index));
DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind());
// There must be exactly one call to WASM_FUNCTION or WASM_TO_JS_FUNCTION.
for (RelocIterator it(export_wrapper,
......@@ -170,9 +172,10 @@ bool CodeSpecialization::ApplyToWholeInstance(
break;
}
changed = true;
func_index++;
++wrapper_index;
}
DCHECK_EQ(code_table->length(), func_index);
DCHECK_EQ(compiled_module->export_wrappers()->length(), wrapper_index);
}
return changed;
}
......
......@@ -849,7 +849,7 @@ void WasmSharedModuleData::PrepareForLazyCompilation(
Handle<WasmCompiledModule> WasmCompiledModule::New(
Isolate* isolate, Handle<WasmSharedModuleData> shared,
Handle<FixedArray> code_table,
Handle<FixedArray> code_table, Handle<FixedArray> export_wrappers,
const std::vector<wasm::GlobalHandleAddress>& function_tables,
const std::vector<wasm::GlobalHandleAddress>& signature_tables) {
DCHECK_EQ(function_tables.size(), signature_tables.size());
......@@ -862,6 +862,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
compiled_module->set_shared(shared);
compiled_module->set_native_context(isolate->native_context());
compiled_module->set_code_table(code_table);
compiled_module->set_export_wrappers(export_wrappers);
// TODO(mtrofin): we copy these because the order of finalization isn't
// reliable, and we need these at Reset (which is called at
// finalization). If the order were reliable, and top-down, we could instead
......
......@@ -413,6 +413,7 @@ class WasmCompiledModule : public FixedArray {
MACRO(OBJECT, Context, native_context) \
MACRO(SMALL_CONST_NUMBER, uint32_t, num_imported_functions) \
MACRO(CONST_OBJECT, FixedArray, code_table) \
MACRO(CONST_OBJECT, FixedArray, export_wrappers) \
MACRO(OBJECT, FixedArray, weak_exported_functions) \
MACRO(OBJECT, FixedArray, function_tables) \
MACRO(OBJECT, FixedArray, signature_tables) \
......@@ -450,7 +451,7 @@ class WasmCompiledModule : public FixedArray {
public:
static Handle<WasmCompiledModule> New(
Isolate* isolate, Handle<WasmSharedModuleData> shared,
Handle<FixedArray> code_table,
Handle<FixedArray> code_table, Handle<FixedArray> export_wrappers,
const std::vector<wasm::GlobalHandleAddress>& function_tables,
const std::vector<wasm::GlobalHandleAddress>& signature_tables);
......
......@@ -393,10 +393,10 @@ class TestingModuleBuilder {
WasmSharedModuleData::New(isolate_, module_wrapper, empty_string,
script, Handle<ByteArray>::null());
Handle<FixedArray> code_table = isolate_->factory()->NewFixedArray(0);
Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate_, shared_module_data, code_table,
function_tables_, signature_tables_);
Handle<FixedArray> export_wrappers = isolate_->factory()->NewFixedArray(0);
Handle<WasmCompiledModule> compiled_module = WasmCompiledModule::New(
isolate_, shared_module_data, code_table, export_wrappers,
function_tables_, signature_tables_);
// This method is called when we initialize TestEnvironment. We don't
// have a memory yet, so we won't create it here. We'll update the
// interpreter when we get a memory. We do have globals, though.
......
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