Commit 7f68cbbf authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Prepare WasmCompilationUnit for lazy compilation

In lazy compilation, we only compile one function at a time, and we
might not have the wire bytes of the whole module available.
This CL prepares the WasmCompilationUnit for this setting.
It will also be helpful for streaming compilation.

Also, the ErrorThrower (which might heap-allocate) is not stored in the
WasmCompilationUnit any more. Instead, it is passed to the
FinishCompilation method which is allowed to heap-allocate.

R=titzer@chromium.org, ahaas@chromium.org
BUG=v8:5991

Review-Url: https://codereview.chromium.org/2726553003
Cr-Commit-Position: refs/heads/master@{#43573}
parent de52562d
This diff is collapsed.
......@@ -12,6 +12,7 @@
#include "src/compilation-info.h"
#include "src/compiler.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/wasm/wasm-result.h"
......@@ -46,45 +47,38 @@ typedef compiler::JSGraph TFGraph;
namespace compiler {
class WasmCompilationUnit final {
public:
WasmCompilationUnit(wasm::ErrorThrower* thrower, Isolate* isolate,
wasm::ModuleBytesEnv* module_env,
const wasm::WasmFunction* function, uint32_t index);
WasmCompilationUnit(Isolate* isolate, wasm::ModuleBytesEnv* module_env,
const wasm::WasmFunction* function);
WasmCompilationUnit(Isolate* isolate, wasm::ModuleEnv* module_env,
wasm::FunctionBody body, wasm::WasmName name, int index);
Zone* graph_zone() { return graph_zone_.get(); }
int index() const { return index_; }
int func_index() const { return func_index_; }
void ExecuteCompilation();
Handle<Code> FinishCompilation();
Handle<Code> FinishCompilation(wasm::ErrorThrower* thrower);
static Handle<Code> CompileWasmFunction(wasm::ErrorThrower* thrower,
Isolate* isolate,
wasm::ModuleBytesEnv* module_env,
const wasm::WasmFunction* function) {
WasmCompilationUnit unit(thrower, isolate, module_env, function,
function->func_index);
unit.ExecuteCompilation();
return unit.FinishCompilation();
}
const wasm::WasmFunction* function);
private:
SourcePositionTable* BuildGraphForWasmFunction(double* decode_ms);
char* GetTaggedFunctionName(const wasm::WasmFunction* function);
wasm::ErrorThrower* thrower_;
Isolate* isolate_;
wasm::ModuleBytesEnv* module_env_;
const wasm::WasmFunction* function_;
// Function name is tagged with uint32 func_index - wasm#<func_index>
char function_name_[16];
wasm::ModuleEnv* module_env_;
wasm::FunctionBody func_body_;
wasm::WasmName func_name_;
// The graph zone is deallocated at the end of ExecuteCompilation.
std::unique_ptr<Zone> graph_zone_;
JSGraph* jsgraph_;
Zone compilation_zone_;
CompilationInfo info_;
std::unique_ptr<CompilationJob> job_;
uint32_t index_;
int func_index_;
wasm::Result<wasm::DecodeStruct*> graph_construction_result_;
bool ok_;
bool ok_ = true;
ZoneVector<trap_handler::ProtectedInstructionData>
protected_instructions_; // Instructions that are protected by the signal
// handler.
......
......@@ -35,7 +35,7 @@ class Vector {
// spanning from and including 'from', to but not including 'to'.
Vector<T> SubVector(int from, int to) const {
DCHECK(0 <= from);
SLOW_DCHECK(from < to);
SLOW_DCHECK(from <= to);
SLOW_DCHECK(static_cast<unsigned>(to) <= static_cast<unsigned>(length_));
return Vector<T>(start() + from, to - from);
}
......
......@@ -262,8 +262,8 @@ class CompilationHelper {
compilation_units_.reserve(funcs_to_compile);
for (uint32_t i = start; i < num_funcs; ++i) {
const WasmFunction* func = &functions[i];
compilation_units_.push_back(new compiler::WasmCompilationUnit(
thrower, isolate_, &module_env, func, i));
compilation_units_.push_back(
new compiler::WasmCompilationUnit(isolate_, &module_env, func));
}
}
......@@ -296,7 +296,8 @@ class CompilationHelper {
}
}
void FinishCompilationUnits(std::vector<Handle<Code>>& results) {
void FinishCompilationUnits(std::vector<Handle<Code>>& results,
ErrorThrower* thrower) {
while (true) {
compiler::WasmCompilationUnit* unit = nullptr;
{
......@@ -307,8 +308,8 @@ class CompilationHelper {
unit = executed_units_.front();
executed_units_.pop();
}
int j = unit->index();
results[j] = unit->FinishCompilation();
int j = unit->func_index();
results[j] = unit->FinishCompilation(thrower);
delete unit;
}
}
......@@ -360,13 +361,13 @@ class CompilationHelper {
// dequeues it and finishes the compilation unit. Compilation units
// are finished concurrently to the background threads to save
// memory.
FinishCompilationUnits(results);
FinishCompilationUnits(results, thrower);
}
// 4) After the parallel phase of all compilation units has started, the
// main thread waits for all {CompilationTask} instances to finish.
WaitForCompilationTasks(task_ids.get());
// Finish the compilation of the remaining compilation units.
FinishCompilationUnits(results);
FinishCompilationUnits(results, thrower);
}
void CompileSequentially(ModuleBytesEnv* module_env,
......
......@@ -609,7 +609,10 @@ class WasmFunctionCompiler : private GraphAndBuilders {
if (kPointerSize == 4) {
desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc);
}
CompilationInfo info(CStrVector("wasm"), this->isolate(), this->zone(),
EmbeddedVector<char, 16> comp_name;
int comp_name_len = SNPrintF(comp_name, "wasm#%u", this->function_index());
comp_name.Truncate(comp_name_len);
CompilationInfo info(comp_name, this->isolate(), this->zone(),
Code::ComputeFlags(Code::WASM_FUNCTION));
std::unique_ptr<CompilationJob> job(Pipeline::NewWasmCompilationJob(
&info, &jsgraph, desc, &source_position_table_, nullptr, false));
......
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