[wasm] Do not pass the error to callbacks
Instead of passing the error explicitly, make the callbacks get the error from the CompilationState. This prepares a change to call the callbacks asynchronously, because from the background we cannot construct the final error message (because this requires access to the wire bytes). Thus the callbacks will have to get the actual compile error from the CompilationState from a foreground task if they need it. R=mstarzinger@chromium.org Bug: v8:8689 Change-Id: I22accabf895bf21fa7492e2f5cb8bac93237c765 Reviewed-on: https://chromium-review.googlesource.com/c/1445975 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#59216}
This commit is contained in:
parent
be8c9e730d
commit
d928d25c44
@ -98,7 +98,8 @@ enum class CompilationEvent : uint8_t {
|
||||
// This is the PIMPL interface to that private class.
|
||||
class CompilationState {
|
||||
public:
|
||||
using callback_t = std::function<void(CompilationEvent, const WasmError*)>;
|
||||
using callback_t = std::function<void(CompilationEvent)>;
|
||||
|
||||
~CompilationState();
|
||||
|
||||
void CancelAndWait();
|
||||
|
@ -216,7 +216,7 @@ class CompilationStateImpl {
|
||||
: func_index(func_index), error(std::move(error)) {}
|
||||
};
|
||||
|
||||
void NotifyOnEvent(CompilationEvent event, const WasmError* error);
|
||||
void NotifyOnEvent(CompilationEvent event);
|
||||
|
||||
std::vector<std::unique_ptr<WasmCompilationUnit>>& finish_units() {
|
||||
return baseline_compilation_finished() ? tiering_finish_units_
|
||||
@ -1081,7 +1081,7 @@ class AsyncCompileJob::CompilationStateCallback {
|
||||
public:
|
||||
explicit CompilationStateCallback(AsyncCompileJob* job) : job_(job) {}
|
||||
|
||||
void operator()(CompilationEvent event, const WasmError* error) {
|
||||
void operator()(CompilationEvent event) {
|
||||
// This callback is only being called from a foreground task.
|
||||
switch (event) {
|
||||
case CompilationEvent::kFinishedBaselineCompilation:
|
||||
@ -1099,14 +1099,12 @@ class AsyncCompileJob::CompilationStateCallback {
|
||||
break;
|
||||
case CompilationEvent::kFailedCompilation:
|
||||
DCHECK(!last_event_.has_value());
|
||||
DCHECK_NOT_NULL(error);
|
||||
// Tier-up compilation should not fail if baseline compilation
|
||||
// did not fail.
|
||||
DCHECK(!Impl(job_->native_module_->compilation_state())
|
||||
->baseline_compilation_finished());
|
||||
|
||||
// Note: The WasmError is copied here for use in the foreground task.
|
||||
job_->DoSync<CompileFailed, kUseExistingForegroundTask>(*error);
|
||||
job_->DoSync<CompileFailed, kUseExistingForegroundTask>();
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
@ -1350,15 +1348,12 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
|
||||
//==========================================================================
|
||||
class AsyncCompileJob::CompileFailed : public CompileStep {
|
||||
public:
|
||||
explicit CompileFailed(WasmError error) : error_(std::move(error)) {}
|
||||
|
||||
void RunInForeground(AsyncCompileJob* job) override {
|
||||
TRACE_COMPILE("(4b) Compilation Failed...\n");
|
||||
return job->AsyncCompileFailed("Async compilation failed", error_);
|
||||
WasmError error =
|
||||
Impl(job->native_module_->compilation_state())->GetCompileError();
|
||||
return job->AsyncCompileFailed("Async compilation failed", error);
|
||||
}
|
||||
|
||||
private:
|
||||
WasmError error_;
|
||||
};
|
||||
|
||||
void AsyncCompileJob::CompileWrappers() {
|
||||
@ -1736,7 +1731,7 @@ void CompilationStateImpl::OnFinishedUnit(ExecutionTier tier, WasmCode* code) {
|
||||
for (auto event : {CompilationEvent::kFinishedBaselineCompilation,
|
||||
CompilationEvent::kFinishedTopTierCompilation}) {
|
||||
if (!events.contains(event)) continue;
|
||||
NotifyOnEvent(event, nullptr);
|
||||
NotifyOnEvent(event);
|
||||
}
|
||||
};
|
||||
foreground_task_runner_->PostTask(
|
||||
@ -1845,17 +1840,14 @@ void CompilationStateImpl::SetError(uint32_t func_index,
|
||||
compile_error.release();
|
||||
// Schedule a foreground task to call the callback and notify users about the
|
||||
// compile error.
|
||||
foreground_task_runner_->PostTask(
|
||||
MakeCancelableTask(&foreground_task_manager_, [this] {
|
||||
WasmError error = GetCompileError();
|
||||
NotifyOnEvent(CompilationEvent::kFailedCompilation, &error);
|
||||
}));
|
||||
foreground_task_runner_->PostTask(MakeCancelableTask(
|
||||
&foreground_task_manager_,
|
||||
[this] { NotifyOnEvent(CompilationEvent::kFailedCompilation); }));
|
||||
}
|
||||
|
||||
void CompilationStateImpl::NotifyOnEvent(CompilationEvent event,
|
||||
const WasmError* error) {
|
||||
void CompilationStateImpl::NotifyOnEvent(CompilationEvent event) {
|
||||
HandleScope scope(isolate_);
|
||||
for (auto& callback : callbacks_) callback(event, error);
|
||||
for (auto& callback : callbacks_) callback(event);
|
||||
// If no more events are expected after this one, clear the callbacks to free
|
||||
// memory. We can safely do this here, as this method is only called from
|
||||
// foreground tasks.
|
||||
|
@ -128,9 +128,8 @@ class TopTierCompiledCallback {
|
||||
: native_module_(std::move(native_module)),
|
||||
callback_(std::move(callback)) {}
|
||||
|
||||
void operator()(CompilationEvent event, const WasmError* error) const {
|
||||
void operator()(CompilationEvent event) const {
|
||||
if (event != CompilationEvent::kFinishedTopTierCompilation) return;
|
||||
DCHECK_NULL(error);
|
||||
// If the native module is still alive, get back a shared ptr and call the
|
||||
// callback.
|
||||
if (std::shared_ptr<NativeModule> native_module = native_module_.lock()) {
|
||||
|
Loading…
Reference in New Issue
Block a user