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 { ...@@ -71,18 +71,20 @@ struct CompilationEnv {
lower_simd(lower_simd) {} lower_simd(lower_simd) {}
}; };
// The implementation of {CompilationState}, {CompilationStateDeleter} and // The implementation of {CompilationState} lives in module-compiler.cc.
// {CancelAndWaitCompilationState} lives in module-compiler.cc. // This is the PIMPL interface to that private class.
struct CompilationStateDeleter { class CompilationState {
void operator()(CompilationState* compilation_state) const; 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 static std::unique_ptr<CompilationState> New(Isolate*, NativeModule*);
// the CompilationState in the header file. };
std::unique_ptr<CompilationState, CompilationStateDeleter> NewCompilationState(
Isolate*, NativeModule*);
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
......
This diff is collapsed.
...@@ -341,7 +341,7 @@ NativeModule::NativeModule(Isolate* isolate, const WasmFeatures& enabled, ...@@ -341,7 +341,7 @@ NativeModule::NativeModule(Isolate* isolate, const WasmFeatures& enabled,
std::shared_ptr<const WasmModule> module) std::shared_ptr<const WasmModule> module)
: enabled_features_(enabled), : enabled_features_(enabled),
module_(std::move(module)), module_(std::move(module)),
compilation_state_(NewCompilationState(isolate, this)), compilation_state_(CompilationState::New(isolate, this)),
import_wrapper_cache_(std::unique_ptr<WasmImportWrapperCache>( import_wrapper_cache_(std::unique_ptr<WasmImportWrapperCache>(
new WasmImportWrapperCache(this))), new WasmImportWrapperCache(this))),
free_code_space_(code_space.region()), free_code_space_(code_space.region()),
...@@ -801,7 +801,7 @@ NativeModule::~NativeModule() { ...@@ -801,7 +801,7 @@ NativeModule::~NativeModule() {
TRACE_HEAP("Deleting native module: %p\n", reinterpret_cast<void*>(this)); TRACE_HEAP("Deleting native module: %p\n", reinterpret_cast<void*>(this));
// Cancel all background compilation before resetting any field of the // Cancel all background compilation before resetting any field of the
// NativeModule or freeing anything. // NativeModule or freeing anything.
CancelAndWaitCompilationState(compilation_state_.get()); compilation_state_->CancelAndWait();
wasm_engine_->code_manager()->FreeNativeModule(this); wasm_engine_->code_manager()->FreeNativeModule(this);
} }
......
...@@ -426,7 +426,7 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -426,7 +426,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
// The compilation state keeps track of compilation tasks for this module. // The compilation state keeps track of compilation tasks for this module.
// Note that its destructor blocks until all tasks are finished/aborted and // Note that its destructor blocks until all tasks are finished/aborted and
// hence needs to be destructed first when this native module dies. // 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. // A cache of the import wrappers, keyed on the kind and signature.
std::unique_ptr<WasmImportWrapperCache> import_wrapper_cache_; 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