Index: src/wasm/wasm-module.cc |
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc |
index 0e154016231ef4dd35877ceae7c3ec203978fb04..ed454817832d890fbaaf4c3c000b38ff227d2987 100644 |
--- a/src/wasm/wasm-module.cc |
+++ b/src/wasm/wasm-module.cc |
@@ -509,6 +509,9 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, |
std::vector<compiler::WasmCompilationUnit*> compilation_units( |
functions.size()); |
+ std::queue<compiler::WasmCompilationUnit*> finished_units; |
titzer
2016/05/02 14:49:45
A better name might be "executed_units", since the
ahaas
2016/05/02 16:21:59
Done.
|
+ std::vector<Handle<Code>> results(functions.size()); |
+ |
if (FLAG_wasm_parallel_compilation) { |
// Create a placeholder code object for all functions. |
// TODO(ahaas): Maybe we could skip this for external functions. |
@@ -520,14 +523,26 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, |
i++) { |
if (!functions[i].external) { |
compilation_units[i] = compiler::CreateWasmCompilationUnit( |
- &thrower, isolate, &module_env, &functions[i]); |
+ &thrower, isolate, &module_env, &functions[i], i); |
} |
} |
- for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); |
- i++) { |
- if (!functions[i].external) { |
- compiler::ExecuteCompilation(compilation_units[i]); |
+ index = FLAG_skip_compiling_wasm_funcs; |
+ while (true) { |
+ while (!finished_units.empty()) { |
+ compiler::WasmCompilationUnit* unit = finished_units.front(); |
+ finished_units.pop(); |
+ int i = compiler::GetIndexOfWasmCompilationUnit(unit); |
+ results[i] = compiler::FinishCompilation(unit); |
titzer
2016/05/02 14:49:46
This will go out of the bounds of the vector.
ahaas
2016/05/02 16:21:59
I preallocate the vector with functions.size(), so
|
+ } |
+ if (index < functions.size()) { |
+ if (!functions[index].external) { |
+ compiler::ExecuteCompilation(compilation_units[index]); |
+ finished_units.push(compilation_units[index]); |
+ index++; |
+ } |
+ } else { |
+ break; |
} |
} |
} |
@@ -554,7 +569,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, |
func.sig, str, str_null); |
} else { |
if (FLAG_wasm_parallel_compilation) { |
- code = compiler::FinishCompilation(compilation_units[i]); |
+ code = results[i]; |
} else { |
// Compile the function. |
code = compiler::CompileWasmFunction(&thrower, isolate, &module_env, |