[wasm] Remove strong reference in TopTierCompiledCallback

Registered callbacks should not keep the NativeModule alive. Otherwise,
tiering will always run to completion, even if the NativeModule is not
being used any more.
This change can cause the callback to not be called if the module dies
before it finishes top-tier compilation. This is the desired behaviour.

R=ahaas@chromium.org
CC=titzer@chromium.org, bbudge@chromium.org

Bug: v8:8689, chromium:719172
Change-Id: Ide9d639f465497c3ed3439c7ce25c76dceeb97eb
Reviewed-on: https://chromium-review.googlesource.com/c/1435937
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59175}
This commit is contained in:
Clemens Hammacher 2019-01-25 12:13:25 +01:00 committed by Commit Bot
parent 0ae14a49e2
commit 368bf36e00

View File

@ -123,7 +123,7 @@ namespace {
class TopTierCompiledCallback {
public:
TopTierCompiledCallback(std::shared_ptr<NativeModule> native_module,
TopTierCompiledCallback(std::weak_ptr<NativeModule> native_module,
StreamingDecoder::ModuleCompiledCallback callback)
: native_module_(std::move(native_module)),
callback_(std::move(callback)) {}
@ -131,7 +131,11 @@ class TopTierCompiledCallback {
void operator()(CompilationEvent event, const WasmError* error) const {
if (event != CompilationEvent::kFinishedTopTierCompilation) return;
DCHECK_NULL(error);
callback_(native_module_);
// 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()) {
callback_(native_module);
}
#ifdef DEBUG
DCHECK(!called_);
called_ = true;
@ -139,7 +143,7 @@ class TopTierCompiledCallback {
}
private:
const std::shared_ptr<NativeModule> native_module_;
const std::weak_ptr<NativeModule> native_module_;
const StreamingDecoder::ModuleCompiledCallback callback_;
#ifdef DEBUG
mutable bool called_ = false;