Commit 612471c8 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Assert that lazy compilation does not fail

Since the wasm module is verified before starting execution with lazy
compilation, the compilation of individual functions should not fail
later.
This CL changes the implementation to check this condition earlier
and removes unused error paths.

R=ahaas@chromium.org, mstarzinger@chromium.org
BUG=chromium:719286

Change-Id: If4bab457a47f214b457b2e2bc8570cba8c8bbcfd
Reviewed-on: https://chromium-review.googlesource.com/497755Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45161}
parent da172451
......@@ -3117,13 +3117,8 @@ Handle<Code> wasm::CompileLazy(Isolate* isolate) {
bool patch_caller = caller_code->kind() == Code::JS_TO_WASM_FUNCTION ||
exp_deopt_data.is_null() || exp_deopt_data->length() <= 2;
MaybeHandle<Code> maybe_compiled_code = WasmCompiledModule::CompileLazy(
Handle<Code> compiled_code = WasmCompiledModule::CompileLazy(
isolate, instance, caller_code, offset, func_index, patch_caller);
if (maybe_compiled_code.is_null()) {
DCHECK(isolate->has_pending_exception());
return isolate->builtins()->Illegal();
}
Handle<Code> compiled_code = maybe_compiled_code.ToHandleChecked();
if (!exp_deopt_data.is_null() && exp_deopt_data->length() > 2) {
// See EnsureExportedLazyDeoptData: exp_deopt_data[2...(len-1)] are pairs of
// <export_table, index> followed by undefined values.
......@@ -3146,14 +3141,15 @@ Handle<Code> wasm::CompileLazy(Isolate* isolate) {
return compiled_code;
}
bool LazyCompilationOrchestrator::CompileFunction(
void LazyCompilationOrchestrator::CompileFunction(
Isolate* isolate, Handle<WasmInstanceObject> instance, int func_index) {
Handle<WasmCompiledModule> compiled_module(instance->compiled_module(),
isolate);
if (Code::cast(compiled_module->code_table()->get(func_index))->kind() ==
Code::WASM_FUNCTION) {
return true;
return;
}
size_t num_function_tables =
compiled_module->module()->function_tables.size();
// Store a vector of handles to be embedded in the generated code.
......@@ -3193,6 +3189,11 @@ bool LazyCompilationOrchestrator::CompileFunction(
unit.ExecuteCompilation();
Handle<Code> code = unit.FinishCompilation(&thrower);
// If there is a pending error, something really went wrong. The module was
// verified before starting execution with lazy compilation.
// This might be OOM, but then we cannot continue execution anyway.
CHECK(!thrower.error());
Handle<FixedArray> deopt_data = isolate->factory()->NewFixedArray(2, TENURED);
Handle<WeakCell> weak_instance = isolate->factory()->NewWeakCell(instance);
// TODO(wasm): Introduce constants for the indexes in wasm deopt data.
......@@ -3200,10 +3201,6 @@ bool LazyCompilationOrchestrator::CompileFunction(
deopt_data->set(1, Smi::FromInt(func_index));
code->set_deoptimization_data(*deopt_data);
// If we have a pending error, just return. The ErrorThrower will set the
// pending exception in its destructor.
if (thrower.error()) return false;
DCHECK_EQ(Builtins::kWasmCompileLazy,
Code::cast(compiled_module->code_table()->get(func_index))
->builtin_index());
......@@ -3232,10 +3229,9 @@ bool LazyCompilationOrchestrator::CompileFunction(
Assembler::FlushICache(isolate, code->instruction_start(),
code->instruction_size());
RecordLazyCodeStats(isolate, *code);
return true;
}
MaybeHandle<Code> LazyCompilationOrchestrator::CompileLazy(
Handle<Code> LazyCompilationOrchestrator::CompileLazy(
Isolate* isolate, Handle<WasmInstanceObject> instance, Handle<Code> caller,
int call_offset, int exported_func_index, bool patch_caller) {
struct NonCompiledFunction {
......@@ -3286,9 +3282,7 @@ MaybeHandle<Code> LazyCompilationOrchestrator::CompileLazy(
// TODO(clemensh): compile all functions in non_compiled_functions in
// background, wait for func_to_return_idx.
if (!CompileFunction(isolate, instance, func_to_return_idx)) {
return {};
}
CompileFunction(isolate, instance, func_to_return_idx);
if (is_js_to_wasm || patch_caller) {
DisallowHeapAllocation no_gc;
......
......@@ -501,13 +501,12 @@ Handle<Code> CompileLazy(Isolate* isolate);
// logic to actually orchestrate parallel execution of wasm compilation jobs.
// TODO(clemensh): Implement concurrent lazy compilation.
class LazyCompilationOrchestrator {
bool CompileFunction(Isolate*, Handle<WasmInstanceObject>,
int func_index) WARN_UNUSED_RESULT;
void CompileFunction(Isolate*, Handle<WasmInstanceObject>, int func_index);
public:
MaybeHandle<Code> CompileLazy(Isolate*, Handle<WasmInstanceObject>,
Handle<Code> caller, int call_offset,
int exported_func_index, bool patch_caller);
Handle<Code> CompileLazy(Isolate*, Handle<WasmInstanceObject>,
Handle<Code> caller, int call_offset,
int exported_func_index, bool patch_caller);
};
namespace testing {
......
......@@ -1555,7 +1555,7 @@ MaybeHandle<FixedArray> WasmCompiledModule::CheckBreakPoints(int position) {
return isolate->debug()->GetHitBreakPointObjects(breakpoint_objects);
}
MaybeHandle<Code> WasmCompiledModule::CompileLazy(
Handle<Code> WasmCompiledModule::CompileLazy(
Isolate* isolate, Handle<WasmInstanceObject> instance, Handle<Code> caller,
int offset, int func_index, bool patch_caller) {
isolate->set_context(*instance->compiled_module()->native_context());
......
......@@ -520,12 +520,10 @@ class WasmCompiledModule : public FixedArray {
// call / exported function), func_index must be set. Otherwise it can be -1.
// If patch_caller is set, then all direct calls to functions which were
// already lazily compiled are patched (at least the given call site).
// Returns the Code to be called at the given call site, or an empty Handle if
// an error occured during lazy compilation. In this case, an exception has
// been set on the isolate.
static MaybeHandle<Code> CompileLazy(Isolate*, Handle<WasmInstanceObject>,
Handle<Code> caller, int offset,
int func_index, bool patch_caller);
// Returns the Code to be called at the given call site.
static Handle<Code> CompileLazy(Isolate*, Handle<WasmInstanceObject>,
Handle<Code> caller, int offset,
int func_index, bool patch_caller);
void ReplaceCodeTableForTesting(Handle<FixedArray> testing_table) {
set_code_table(testing_table);
......
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