Commit 972c2902 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove WasmCompilationUnit::failed

Compilation failures are already stored in the {CompilationState}. We
never use the information which individual compilation unit failed.
Hence remove that getter, and only check for failure of the overall
compilation.

R=ahaas@chromium.org

Bug: v8:7921, v8:8343
Change-Id: Ibf90be233c9ff576ec8a3413ba5abefe2fdb645e
Reviewed-on: https://chromium-review.googlesource.com/c/1373783Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58195}
parent fac40e55
...@@ -1087,11 +1087,10 @@ RUNTIME_FUNCTION(Runtime_WasmTierUpFunction) { ...@@ -1087,11 +1087,10 @@ RUNTIME_FUNCTION(Runtime_WasmTierUpFunction) {
DCHECK_EQ(2, args.length()); DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmInstanceObject, instance, 0); CONVERT_ARG_HANDLE_CHECKED(WasmInstanceObject, instance, 0);
CONVERT_SMI_ARG_CHECKED(function_index, 1); CONVERT_SMI_ARG_CHECKED(function_index, 1);
if (!isolate->wasm_engine()->CompileFunction( auto* native_module = instance->module_object()->native_module();
isolate, instance->module_object()->native_module(), function_index, isolate->wasm_engine()->CompileFunction(
wasm::ExecutionTier::kOptimized)) { isolate, native_module, function_index, wasm::ExecutionTier::kOptimized);
return ReadOnlyRoots(isolate).exception(); CHECK(!native_module->compilation_state()->failed());
}
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
......
...@@ -99,10 +99,12 @@ class CompilationState { ...@@ -99,10 +99,12 @@ class CompilationState {
void SetWireBytesStorage(std::shared_ptr<WireBytesStorage>); void SetWireBytesStorage(std::shared_ptr<WireBytesStorage>);
std::shared_ptr<WireBytesStorage> GetWireBytesStorage(); std::shared_ptr<WireBytesStorage> GetWireBytesStorage() const;
void AddCallback(callback_t); void AddCallback(callback_t);
bool failed() const;
private: private:
friend class NativeModule; friend class NativeModule;
CompilationState() = delete; CompilationState() = delete;
......
...@@ -125,7 +125,7 @@ void WasmCompilationUnit::SwitchTier(ExecutionTier new_tier) { ...@@ -125,7 +125,7 @@ void WasmCompilationUnit::SwitchTier(ExecutionTier new_tier) {
} }
// static // static
bool WasmCompilationUnit::CompileWasmFunction(Isolate* isolate, void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
NativeModule* native_module, NativeModule* native_module,
WasmFeatures* detected, WasmFeatures* detected,
const WasmFunction* function, const WasmFunction* function,
...@@ -141,7 +141,6 @@ bool WasmCompilationUnit::CompileWasmFunction(Isolate* isolate, ...@@ -141,7 +141,6 @@ bool WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
unit.ExecuteCompilation( unit.ExecuteCompilation(
&env, native_module->compilation_state()->GetWireBytesStorage(), &env, native_module->compilation_state()->GetWireBytesStorage(),
isolate->counters(), detected); isolate->counters(), detected);
return !unit.failed();
} }
void WasmCompilationUnit::SetResult(WasmCode* code, Counters* counters) { void WasmCompilationUnit::SetResult(WasmCode* code, Counters* counters) {
......
...@@ -47,10 +47,9 @@ class WasmCompilationUnit final { ...@@ -47,10 +47,9 @@ class WasmCompilationUnit final {
NativeModule* native_module() const { return native_module_; } NativeModule* native_module() const { return native_module_; }
ExecutionTier tier() const { return tier_; } ExecutionTier tier() const { return tier_; }
bool failed() const { return result_ == nullptr; } // TODO(clemensh): Remove.
WasmCode* result() const { return result_; } WasmCode* result() const { return result_; }
static bool CompileWasmFunction(Isolate* isolate, NativeModule* native_module, static void CompileWasmFunction(Isolate* isolate, NativeModule* native_module,
WasmFeatures* detected, WasmFeatures* detected,
const WasmFunction* function, const WasmFunction* function,
ExecutionTier = GetDefaultExecutionTier()); ExecutionTier = GetDefaultExecutionTier());
......
...@@ -157,7 +157,7 @@ class CompilationStateImpl { ...@@ -157,7 +157,7 @@ class CompilationStateImpl {
wire_bytes_storage_ = wire_bytes_storage; wire_bytes_storage_ = wire_bytes_storage;
} }
std::shared_ptr<WireBytesStorage> GetWireBytesStorage() { std::shared_ptr<WireBytesStorage> GetWireBytesStorage() const {
base::MutexGuard guard(&mutex_); base::MutexGuard guard(&mutex_);
return wire_bytes_storage_; return wire_bytes_storage_;
} }
...@@ -436,12 +436,17 @@ class InstanceBuilder { ...@@ -436,12 +436,17 @@ class InstanceBuilder {
CompilationStateImpl* Impl(CompilationState* compilation_state) { CompilationStateImpl* Impl(CompilationState* compilation_state) {
return reinterpret_cast<CompilationStateImpl*>(compilation_state); return reinterpret_cast<CompilationStateImpl*>(compilation_state);
} }
const CompilationStateImpl* Impl(const CompilationState* compilation_state) {
return reinterpret_cast<const CompilationStateImpl*>(compilation_state);
}
} // namespace } // namespace
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// PIMPL implementation of {CompilationState}. // PIMPL implementation of {CompilationState}.
CompilationState::~CompilationState() { Impl(this)->~CompilationStateImpl(); }
void CompilationState::CancelAndWait() { Impl(this)->CancelAndWait(); } void CompilationState::CancelAndWait() { Impl(this)->CancelAndWait(); }
void CompilationState::SetError(uint32_t func_index, void CompilationState::SetError(uint32_t func_index,
...@@ -454,7 +459,8 @@ void CompilationState::SetWireBytesStorage( ...@@ -454,7 +459,8 @@ void CompilationState::SetWireBytesStorage(
Impl(this)->SetWireBytesStorage(std::move(wire_bytes_storage)); Impl(this)->SetWireBytesStorage(std::move(wire_bytes_storage));
} }
std::shared_ptr<WireBytesStorage> CompilationState::GetWireBytesStorage() { std::shared_ptr<WireBytesStorage> CompilationState::GetWireBytesStorage()
const {
return Impl(this)->GetWireBytesStorage(); return Impl(this)->GetWireBytesStorage();
} }
...@@ -462,7 +468,7 @@ void CompilationState::AddCallback(CompilationState::callback_t callback) { ...@@ -462,7 +468,7 @@ void CompilationState::AddCallback(CompilationState::callback_t callback) {
return Impl(this)->AddCallback(std::move(callback)); return Impl(this)->AddCallback(std::move(callback));
} }
CompilationState::~CompilationState() { Impl(this)->~CompilationStateImpl(); } bool CompilationState::failed() const { return Impl(this)->failed(); }
// static // static
std::unique_ptr<CompilationState> CompilationState::New( std::unique_ptr<CompilationState> CompilationState::New(
...@@ -510,12 +516,12 @@ WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module, ...@@ -510,12 +516,12 @@ WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module,
isolate->counters(), isolate->counters(),
Impl(native_module->compilation_state())->detected_features()); Impl(native_module->compilation_state())->detected_features());
// If there is a pending error, something really went wrong. The module was // During lazy compilation, we should never get compilation errors. The module
// verified before starting execution with lazy compilation. // was verified before starting execution with lazy compilation.
// This might be OOM, but then we cannot continue execution anyway. // This might be OOM, but then we cannot continue execution anyway.
// TODO(clemensh): According to the spec, we can actually skip validation at // TODO(clemensh): According to the spec, we can actually skip validation at
// module creation time, and return a function that always traps here. // module creation time, and return a function that always traps here.
CHECK(!unit.failed()); CHECK(!native_module->compilation_state()->failed());
WasmCode* code = unit.result(); WasmCode* code = unit.result();
...@@ -652,7 +658,9 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env, ...@@ -652,7 +658,9 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env,
ExecutionTier tier = unit->tier(); ExecutionTier tier = unit->tier();
unit->ExecuteCompilation(env, compilation_state->GetSharedWireBytesStorage(), unit->ExecuteCompilation(env, compilation_state->GetSharedWireBytesStorage(),
counters, detected); counters, detected);
if (!unit->failed()) compilation_state->ScheduleCodeLogging(unit->result()); if (WasmCode* result = unit->result()) {
compilation_state->ScheduleCodeLogging(result);
}
compilation_state->ScheduleUnitForFinishing(std::move(unit), tier); compilation_state->ScheduleUnitForFinishing(std::move(unit), tier);
return true; return true;
...@@ -678,11 +686,6 @@ void FinishCompilationUnits(CompilationStateImpl* compilation_state) { ...@@ -678,11 +686,6 @@ void FinishCompilationUnits(CompilationStateImpl* compilation_state) {
compilation_state->GetNextExecutedUnit(); compilation_state->GetNextExecutedUnit();
if (unit == nullptr) break; if (unit == nullptr) break;
if (unit->failed()) {
compilation_state->Abort();
break;
}
// Update the compilation state. // Update the compilation state.
compilation_state->OnFinishedUnit(); compilation_state->OnFinishedUnit();
} }
...@@ -783,16 +786,15 @@ void CompileSequentially(Isolate* isolate, NativeModule* native_module, ...@@ -783,16 +786,15 @@ void CompileSequentially(Isolate* isolate, NativeModule* native_module,
ModuleWireBytes wire_bytes(native_module->wire_bytes()); ModuleWireBytes wire_bytes(native_module->wire_bytes());
const WasmModule* module = native_module->module(); const WasmModule* module = native_module->module();
WasmFeatures detected = kNoWasmFeatures; WasmFeatures detected = kNoWasmFeatures;
for (uint32_t i = 0; i < module->functions.size(); ++i) { auto* comp_state = Impl(native_module->compilation_state());
const WasmFunction& func = module->functions[i]; for (const WasmFunction& func : module->functions) {
if (func.imported) continue; // Imports are compiled at instantiation time. if (func.imported) continue; // Imports are compiled at instantiation time.
// Compile the function. // Compile the function.
bool success = WasmCompilationUnit::CompileWasmFunction( WasmCompilationUnit::CompileWasmFunction(isolate, native_module, &detected,
isolate, native_module, &detected, &func); &func);
if (!success) { if (comp_state->failed()) {
thrower->CompileFailed( thrower->CompileFailed(comp_state->GetCompileError());
Impl(native_module->compilation_state())->GetCompileError());
break; break;
} }
} }
...@@ -912,8 +914,7 @@ class FinishCompileTask : public CancelableTask { ...@@ -912,8 +914,7 @@ class FinishCompileTask : public CancelableTask {
break; break;
} }
DCHECK_IMPLIES(unit->failed(), compilation_state_->failed()); if (compilation_state_->failed()) break;
if (unit->failed()) break;
// Update the compilation state, and possibly notify // Update the compilation state, and possibly notify
// threads waiting for events. // threads waiting for events.
......
...@@ -226,11 +226,11 @@ std::shared_ptr<StreamingDecoder> WasmEngine::StartStreamingCompilation( ...@@ -226,11 +226,11 @@ std::shared_ptr<StreamingDecoder> WasmEngine::StartStreamingCompilation(
return job->CreateStreamingDecoder(); return job->CreateStreamingDecoder();
} }
bool WasmEngine::CompileFunction(Isolate* isolate, NativeModule* native_module, void WasmEngine::CompileFunction(Isolate* isolate, NativeModule* native_module,
uint32_t function_index, ExecutionTier tier) { uint32_t function_index, ExecutionTier tier) {
// Note we assume that "one-off" compilations can discard detected features. // Note we assume that "one-off" compilations can discard detected features.
WasmFeatures detected = kNoWasmFeatures; WasmFeatures detected = kNoWasmFeatures;
return WasmCompilationUnit::CompileWasmFunction( WasmCompilationUnit::CompileWasmFunction(
isolate, native_module, &detected, isolate, native_module, &detected,
&native_module->module()->functions[function_index], tier); &native_module->module()->functions[function_index], tier);
} }
......
...@@ -98,10 +98,10 @@ class V8_EXPORT_PRIVATE WasmEngine { ...@@ -98,10 +98,10 @@ class V8_EXPORT_PRIVATE WasmEngine {
Isolate* isolate, const WasmFeatures& enabled, Handle<Context> context, Isolate* isolate, const WasmFeatures& enabled, Handle<Context> context,
std::shared_ptr<CompilationResultResolver> resolver); std::shared_ptr<CompilationResultResolver> resolver);
// Compiles the function with the given index at a specific compilation tier // Compiles the function with the given index at a specific compilation tier.
// and returns true on success, false otherwise. This is mostly used for // Errors are stored internally in the CompilationState.
// testing to force a function into a specific tier. // This is mostly used for testing to force a function into a specific tier.
bool CompileFunction(Isolate* isolate, NativeModule* native_module, void CompileFunction(Isolate* isolate, NativeModule* native_module,
uint32_t function_index, ExecutionTier tier); uint32_t function_index, ExecutionTier tier);
// Exports the sharable parts of the given module object so that they can be // Exports the sharable parts of the given module object so that they can be
......
...@@ -425,8 +425,9 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) { ...@@ -425,8 +425,9 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
unit.ExecuteCompilation( unit.ExecuteCompilation(
&env, native_module->compilation_state()->GetWireBytesStorage(), &env, native_module->compilation_state()->GetWireBytesStorage(),
isolate()->counters(), &unused_detected_features); isolate()->counters(), &unused_detected_features);
CHECK(!unit.failed()); WasmCode* result = unit.result();
if (WasmCode::ShouldBeLogged(isolate())) unit.result()->LogCode(isolate()); DCHECK_NOT_NULL(result);
if (WasmCode::ShouldBeLogged(isolate())) result->LogCode(isolate());
} }
WasmFunctionCompiler::WasmFunctionCompiler(Zone* zone, FunctionSig* sig, WasmFunctionCompiler::WasmFunctionCompiler(Zone* zone, FunctionSig* sig,
......
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