Index: src/wasm/wasm-module.cc |
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc |
index 3ba9a9f1ac1b7718d5416fd26c8c6bc3dc035afe..5d8ab1923f7955a5b2ad11f54bab7bfbe3894ac5 100644 |
--- a/src/wasm/wasm-module.cc |
+++ b/src/wasm/wasm-module.cc |
@@ -419,12 +419,6 @@ void InitializeParallelCompilation( |
Isolate* isolate, const std::vector<WasmFunction>& functions, |
std::vector<compiler::WasmCompilationUnit*>& compilation_units, |
ModuleEnv& module_env, ErrorThrower& thrower) { |
- // Create a placeholder code object for all functions. |
- // TODO(ahaas): Maybe we could skip this for external functions. |
titzer
2016/05/26 15:12:25
Why did you delete this code? It's necessary to cr
Mircea Trofin
2016/05/26 15:53:18
The CL has the refactoring one as a dependency. Th
|
- for (uint32_t i = 0; i < functions.size(); i++) { |
- module_env.linker->GetFunctionCode(i); |
- } |
- |
for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); i++) { |
compilation_units[i] = new compiler::WasmCompilationUnit( |
&thrower, isolate, &module_env, &functions[i], i); |
@@ -486,15 +480,11 @@ void FinishCompilationUnits( |
} |
} |
-bool FinishCompilation(Isolate* isolate, const WasmModule* module, |
- const Handle<JSReceiver> ffi, |
- const std::vector<Handle<Code>>& results, |
- const WasmModuleInstance& instance, |
- const Handle<FixedArray>& code_table, |
- ErrorThrower& thrower, Factory* factory, |
- ModuleEnv& module_env, CodeStats& code_stats, |
- PropertyDescriptor& desc) { |
- if (thrower.error()) return false; |
+void CompileSequentially(Isolate* isolate, WasmModuleInstance* instance, |
titzer
2016/05/26 15:12:25
I like the old name better.
Mircea Trofin
2016/05/26 15:53:18
It doesn't finish anything anymore now. It does th
|
+ ErrorThrower* thrower, ModuleEnv* module_env) { |
+ DCHECK(!thrower->error()); |
+ const WasmModule* module = instance->module(); |
+ |
for (uint32_t i = FLAG_skip_compiling_wasm_funcs; |
i < module->functions.size(); i++) { |
const WasmFunction& func = module->functions[i]; |
@@ -502,26 +492,17 @@ bool FinishCompilation(Isolate* isolate, const WasmModule* module, |
DCHECK_EQ(i, func.func_index); |
WasmName str = module->GetName(func.name_offset, func.name_length); |
Handle<Code> code = Handle<Code>::null(); |
- if (FLAG_wasm_num_compilation_tasks != 0) { |
titzer
2016/05/26 15:12:25
wat
Mircea Trofin
2016/05/26 15:53:17
Typo?
|
- code = results[i]; |
- } else { |
- // Compile the function. |
- code = compiler::WasmCompilationUnit::CompileWasmFunction( |
- &thrower, isolate, &module_env, &func); |
- } |
+ // Compile the function. |
+ code = compiler::WasmCompilationUnit::CompileWasmFunction( |
+ thrower, isolate, module_env, &func); |
if (code.is_null()) { |
- thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(), |
- str.start()); |
- return false; |
+ thrower->Error("Compilation of #%d:%.*s failed.", i, str.length(), |
+ str.start()); |
+ break; |
} |
- if (!code.is_null()) { |
// Install the code into the linker table. |
- module_env.linker->Finish(i, code); |
- code_table->set(i, *code); |
- code_stats.Record(*code); |
- } |
+ instance->function_code()[i] = code; |
} |
- return true; |
} |
} // namespace |
@@ -621,6 +602,23 @@ void WasmModuleInstance::InitializeFunctions() { |
} |
} |
+void WasmModuleInstance::ProcessFunctionsPostLinking() { |
titzer
2016/05/26 15:12:25
Please name this function for what it does. SetDeo
Mircea Trofin
2016/05/26 15:53:18
Agreed.
Mircea Trofin
2016/05/27 01:17:33
Actually... Perhaps SetStackTracingHelpers may be
|
+ for (size_t i = FLAG_skip_compiling_wasm_funcs; i < function_code().size(); |
+ ++i) { |
+ Handle<Code> code = function_code()[i]; |
+ DCHECK(code->deoptimization_data() == nullptr || |
+ code->deoptimization_data()->length() == 0); |
+ Handle<FixedArray> deopt_data = |
+ isolate_->factory()->NewFixedArray(2, TENURED); |
+ if (!js_object().is_null()) { |
+ deopt_data->set(0, *js_object()); |
+ } |
+ deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); |
+ deopt_data->set_length(2); |
+ code->set_deoptimization_data(*deopt_data); |
+ } |
+} |
+ |
// Instantiates a wasm module as a JSObject. |
// * allocates a backing store of {mem_size} bytes. |
// * installs a named property "memory" for that buffer if exported |
@@ -634,9 +632,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate( |
ErrorThrower thrower(isolate, "WasmModule::Instantiate()"); |
Factory* factory = isolate->factory(); |
- PropertyDescriptor desc; |
- desc.set_writable(false); |
- |
// If FLAG_print_wasm_code_size is set, this aggregates the sum of all code |
// objects created for this module. |
// TODO(titzer): switch this to TRACE_EVENT |
@@ -702,7 +697,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate( |
std::vector<compiler::WasmCompilationUnit*> compilation_units( |
functions.size()); |
std::queue<compiler::WasmCompilationUnit*> executed_units; |
- std::vector<Handle<Code>> results(functions.size()); |
if (FLAG_wasm_num_compilation_tasks != 0) { |
//----------------------------------------------------------------------- |
@@ -753,25 +747,39 @@ MaybeHandle<JSObject> WasmModule::Instantiate( |
// dequeues it and finishes the compilation unit. Compilation units |
// are finished concurrently to the background threads to save |
// memory. |
- FinishCompilationUnits(executed_units, results, result_mutex); |
+ FinishCompilationUnits(executed_units, instance.function_code(), |
+ result_mutex); |
} |
// 4) After the parallel phase of all compilation units has started, the |
// main thread waits for all {WasmCompilationTask} instances to finish. |
WaitForCompilationTasks(isolate, task_ids.get(), pending_tasks); |
// Finish the compilation of the remaining compilation units. |
- FinishCompilationUnits(executed_units, results, result_mutex); |
+ FinishCompilationUnits(executed_units, instance.function_code(), |
+ result_mutex); |
+ } else { |
+ // 5) The main thread finishes the compilation. |
+ CompileSequentially(isolate, &instance, &thrower, &module_env); |
} |
- // 5) The main thread finishes the compilation. |
- if (!FinishCompilation(isolate, this, ffi, results, instance, code_table, |
- thrower, factory, module_env, code_stats, desc)) { |
+ if (thrower.error()) { |
return Handle<JSObject>::null(); |
} |
+ // At this point, compilation has completed. Update the code table |
+ // and record sizes. |
+ for (size_t i = FLAG_skip_compiling_wasm_funcs; |
+ i < instance.function_code().size(); ++i) { |
+ Code* code = *instance.function_code()[i]; |
+ code_table->set(static_cast<int>(i), code); |
+ code_stats.Record(code); |
+ } |
+ |
// Patch all direct call sites. |
linker.Link(instance.function_table(), this->function_table); |
instance.js_object()->SetInternalField(kWasmModuleFunctionTable, |
Smi::FromInt(0)); |
+ instance.ProcessFunctionsPostLinking(); |
+ |
//------------------------------------------------------------------------- |
// Create and populate the exports object. |
//------------------------------------------------------------------------- |
@@ -790,6 +798,9 @@ MaybeHandle<JSObject> WasmModule::Instantiate( |
exports_object = instance.js_object(); |
} |
+ PropertyDescriptor desc; |
+ desc.set_writable(false); |
+ |
// Compile wrappers and add them to the exports object. |
for (const WasmExport& exp : export_table) { |
if (thrower.error()) break; |