Commit 8f7537f8 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Encapsulate CompilationState nicer

This uses the PIMPL idiom to hide the implementation of
{CompilationState} while still allowing to call methods on
{CompilationState} using the externally visible type.
It also allows to pass the {CompilationState} in a unique_ptr
without a custom deleter.

R=ahaas@chromium.org, mstarzinger@chromium.org

Bug: v8:8238
Change-Id: I5e842723270bc6bb36b605253e3e88103caec61a
Reviewed-on: https://chromium-review.googlesource.com/c/1297956
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56996}
parent e893eb14
......@@ -71,18 +71,20 @@ struct CompilationEnv {
lower_simd(lower_simd) {}
};
// The implementation of {CompilationState}, {CompilationStateDeleter} and
// {CancelAndWaitCompilationState} lives in module-compiler.cc.
struct CompilationStateDeleter {
void operator()(CompilationState* compilation_state) const;
};
// The implementation of {CompilationState} lives in module-compiler.cc.
// This is the PIMPL interface to that private class.
class CompilationState {
public:
~CompilationState();
void CancelAndWait();
void CancelAndWaitCompilationState(CompilationState* state);
private:
friend class NativeModule;
CompilationState() = delete;
// Wrapper to create a CompilationState exists in order to avoid having
// the CompilationState in the header file.
std::unique_ptr<CompilationState, CompilationStateDeleter> NewCompilationState(
Isolate*, NativeModule*);
static std::unique_ptr<CompilationState> New(Isolate*, NativeModule*);
};
} // namespace wasm
} // namespace internal
......
This diff is collapsed.
......@@ -341,7 +341,7 @@ NativeModule::NativeModule(Isolate* isolate, const WasmFeatures& enabled,
std::shared_ptr<const WasmModule> module)
: enabled_features_(enabled),
module_(std::move(module)),
compilation_state_(NewCompilationState(isolate, this)),
compilation_state_(CompilationState::New(isolate, this)),
import_wrapper_cache_(std::unique_ptr<WasmImportWrapperCache>(
new WasmImportWrapperCache(this))),
free_code_space_(code_space.region()),
......@@ -801,7 +801,7 @@ NativeModule::~NativeModule() {
TRACE_HEAP("Deleting native module: %p\n", reinterpret_cast<void*>(this));
// Cancel all background compilation before resetting any field of the
// NativeModule or freeing anything.
CancelAndWaitCompilationState(compilation_state_.get());
compilation_state_->CancelAndWait();
wasm_engine_->code_manager()->FreeNativeModule(this);
}
......
......@@ -426,7 +426,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
// The compilation state keeps track of compilation tasks for this module.
// Note that its destructor blocks until all tasks are finished/aborted and
// hence needs to be destructed first when this native module dies.
std::unique_ptr<CompilationState, CompilationStateDeleter> compilation_state_;
std::unique_ptr<CompilationState> compilation_state_;
// A cache of the import wrappers, keyed on the kind and signature.
std::unique_ptr<WasmImportWrapperCache> import_wrapper_cache_;
......
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