[wasm] Remove NativeModule::engine_ pointer
There is only one global wasm engine, so we do not need to store the pointer in the NativeModule. We just use {GetWasmEngine()} instead, which reads the global pointer. R=jkummerow@chromium.org Bug: v8:11879 Change-Id: I66dedd571755774d96621b8d20ff23bdfef8134f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2983208 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#75366}
This commit is contained in:
parent
0b3bb24adc
commit
9f747b5f56
@ -6291,8 +6291,7 @@ std::unique_ptr<DebugSideTable> GenerateLiftoffDebugSideTable(
|
||||
FunctionBody func_body{function->sig, 0, function_bytes.begin(),
|
||||
function_bytes.end()};
|
||||
|
||||
AccountingAllocator* allocator = native_module->engine()->allocator();
|
||||
Zone zone(allocator, "LiftoffDebugSideTableZone");
|
||||
Zone zone(GetWasmEngine()->allocator(), "LiftoffDebugSideTableZone");
|
||||
auto call_descriptor = compiler::GetWasmCallDescriptor(&zone, function->sig);
|
||||
DebugSideTableBuilder debug_sidetable_builder;
|
||||
WasmFeatures detected;
|
||||
|
@ -2404,8 +2404,7 @@ class SampleTopTierCodeSizeCallback {
|
||||
void operator()(CompilationEvent event) {
|
||||
if (event != CompilationEvent::kFinishedTopTierCompilation) return;
|
||||
if (std::shared_ptr<NativeModule> native_module = native_module_.lock()) {
|
||||
native_module->engine()->SampleTopTierCodeSizeInAllIsolates(
|
||||
native_module);
|
||||
GetWasmEngine()->SampleTopTierCodeSizeInAllIsolates(native_module);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3326,7 +3325,7 @@ void CompilationStateImpl::PublishCode(
|
||||
native_module_->PublishCode(std::move(code));
|
||||
// Defer logging code in case wire bytes were not fully received yet.
|
||||
if (native_module_->HasWireBytes()) {
|
||||
native_module_->engine()->LogCode(base::VectorOf(published_code));
|
||||
GetWasmEngine()->LogCode(base::VectorOf(published_code));
|
||||
}
|
||||
|
||||
OnFinishedUnits(base::VectorOf(std::move(published_code)));
|
||||
|
@ -470,7 +470,7 @@ WasmCode::~WasmCode() {
|
||||
}
|
||||
|
||||
V8_WARN_UNUSED_RESULT bool WasmCode::DecRefOnPotentiallyDeadCode() {
|
||||
if (native_module_->engine()->AddPotentiallyDeadCode(this)) {
|
||||
if (GetWasmEngine()->AddPotentiallyDeadCode(this)) {
|
||||
// The code just became potentially dead. The ref count we wanted to
|
||||
// decrement is now transferred to the set of potentially dead code, and
|
||||
// will be decremented when the next GC is run.
|
||||
@ -486,16 +486,14 @@ void WasmCode::DecrementRefCount(base::Vector<WasmCode* const> code_vec) {
|
||||
// Decrement the ref counter of all given code objects. Keep the ones whose
|
||||
// ref count drops to zero.
|
||||
WasmEngine::DeadCodeMap dead_code;
|
||||
WasmEngine* engine = nullptr;
|
||||
for (WasmCode* code : code_vec) {
|
||||
if (!code->DecRef()) continue; // Remaining references.
|
||||
dead_code[code->native_module()].push_back(code);
|
||||
if (!engine) engine = code->native_module()->engine();
|
||||
DCHECK_EQ(engine, code->native_module()->engine());
|
||||
}
|
||||
|
||||
DCHECK_EQ(dead_code.empty(), engine == nullptr);
|
||||
if (engine) engine->FreeDeadCode(dead_code);
|
||||
if (dead_code.empty()) return;
|
||||
|
||||
GetWasmEngine()->FreeDeadCode(dead_code);
|
||||
}
|
||||
|
||||
int WasmCode::GetSourcePositionBefore(int offset) {
|
||||
@ -833,13 +831,13 @@ size_t WasmCodeAllocator::GetNumCodeSpaces() const {
|
||||
// static
|
||||
constexpr base::AddressRegion WasmCodeAllocator::kUnrestrictedRegion;
|
||||
|
||||
NativeModule::NativeModule(WasmEngine* engine, const WasmFeatures& enabled,
|
||||
NativeModule::NativeModule(const WasmFeatures& enabled,
|
||||
VirtualMemory code_space,
|
||||
std::shared_ptr<const WasmModule> module,
|
||||
std::shared_ptr<Counters> async_counters,
|
||||
std::shared_ptr<NativeModule>* shared_this)
|
||||
: engine_(engine),
|
||||
engine_scope_(engine->GetBarrierForBackgroundCompile()->TryLock()),
|
||||
: engine_scope_(
|
||||
GetWasmEngine()->GetBarrierForBackgroundCompile()->TryLock()),
|
||||
code_allocator_(async_counters),
|
||||
enabled_features_(enabled),
|
||||
module_(std::move(module)),
|
||||
@ -1700,7 +1698,7 @@ NativeModule::~NativeModule() {
|
||||
// Cancel all background compilation before resetting any field of the
|
||||
// NativeModule or freeing anything.
|
||||
compilation_state_->CancelCompilation();
|
||||
engine_->FreeNativeModule(this);
|
||||
GetWasmEngine()->FreeNativeModule(this);
|
||||
// Free the import wrapper cache before releasing the {WasmCode} objects in
|
||||
// {owned_code_}. The destructor of {WasmImportWrapperCache} still needs to
|
||||
// decrease reference counts on the {WasmCode} objects.
|
||||
@ -1961,8 +1959,8 @@ size_t WasmCodeManager::EstimateNativeModuleMetaDataSize(
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeModule> WasmCodeManager::NewNativeModule(
|
||||
WasmEngine* engine, Isolate* isolate, const WasmFeatures& enabled,
|
||||
size_t code_size_estimate, std::shared_ptr<const WasmModule> module) {
|
||||
Isolate* isolate, const WasmFeatures& enabled, size_t code_size_estimate,
|
||||
std::shared_ptr<const WasmModule> module) {
|
||||
if (total_committed_code_space_.load() >
|
||||
critical_committed_code_space_.load()) {
|
||||
(reinterpret_cast<v8::Isolate*>(isolate))
|
||||
@ -2013,7 +2011,7 @@ std::shared_ptr<NativeModule> WasmCodeManager::NewNativeModule(
|
||||
size_t size = code_space.size();
|
||||
Address end = code_space.end();
|
||||
std::shared_ptr<NativeModule> ret;
|
||||
new NativeModule(engine, enabled, std::move(code_space), std::move(module),
|
||||
new NativeModule(enabled, std::move(code_space), std::move(module),
|
||||
isolate->async_counters(), &ret);
|
||||
// The constructor initialized the shared_ptr.
|
||||
DCHECK_NOT_NULL(ret);
|
||||
|
@ -706,7 +706,6 @@ class V8_EXPORT_PRIVATE NativeModule final {
|
||||
size_t liftoff_bailout_count() const { return liftoff_bailout_count_.load(); }
|
||||
size_t liftoff_code_size() const { return liftoff_code_size_.load(); }
|
||||
size_t turbofan_code_size() const { return turbofan_code_size_.load(); }
|
||||
WasmEngine* engine() const { return engine_; }
|
||||
|
||||
bool HasWireBytes() const {
|
||||
auto wire_bytes = std::atomic_load(&wire_bytes_);
|
||||
@ -787,8 +786,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
|
||||
};
|
||||
|
||||
// Private constructor, called via {WasmCodeManager::NewNativeModule()}.
|
||||
NativeModule(WasmEngine* engine, const WasmFeatures& enabled_features,
|
||||
VirtualMemory code_space,
|
||||
NativeModule(const WasmFeatures& enabled_features, VirtualMemory code_space,
|
||||
std::shared_ptr<const WasmModule> module,
|
||||
std::shared_ptr<Counters> async_counters,
|
||||
std::shared_ptr<NativeModule>* shared_this);
|
||||
@ -828,7 +826,6 @@ class V8_EXPORT_PRIVATE NativeModule final {
|
||||
|
||||
// -- Fields of {NativeModule} start here.
|
||||
|
||||
WasmEngine* const engine_;
|
||||
// Keep the engine alive as long as this NativeModule is alive. In its
|
||||
// destructor, the NativeModule still communicates with the WasmCodeManager,
|
||||
// owned by the engine. This fields comes before other fields which also still
|
||||
@ -971,9 +968,8 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
|
||||
friend class WasmEngine;
|
||||
|
||||
std::shared_ptr<NativeModule> NewNativeModule(
|
||||
WasmEngine* engine, Isolate* isolate,
|
||||
const WasmFeatures& enabled_features, size_t code_size_estimate,
|
||||
std::shared_ptr<const WasmModule> module);
|
||||
Isolate* isolate, const WasmFeatures& enabled_features,
|
||||
size_t code_size_estimate, std::shared_ptr<const WasmModule> module);
|
||||
|
||||
V8_WARN_UNUSED_RESULT VirtualMemory TryAllocate(size_t size,
|
||||
void* hint = nullptr);
|
||||
|
@ -846,7 +846,6 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
|
||||
Handle<WasmModuleObject> WasmEngine::ImportNativeModule(
|
||||
Isolate* isolate, std::shared_ptr<NativeModule> shared_native_module,
|
||||
base::Vector<const char> source_url) {
|
||||
DCHECK_EQ(this, shared_native_module->engine());
|
||||
NativeModule* native_module = shared_native_module.get();
|
||||
ModuleWireBytes wire_bytes(native_module->wire_bytes());
|
||||
Handle<Script> script =
|
||||
@ -1138,7 +1137,7 @@ std::shared_ptr<NativeModule> WasmEngine::NewNativeModule(
|
||||
|
||||
std::shared_ptr<NativeModule> native_module =
|
||||
GetWasmCodeManager()->NewNativeModule(
|
||||
this, isolate, enabled, code_size_estimate, std::move(module));
|
||||
isolate, enabled, code_size_estimate, std::move(module));
|
||||
base::MutexGuard lock(&mutex_);
|
||||
auto pair = native_modules_.insert(std::make_pair(
|
||||
native_module.get(), std::make_unique<NativeModuleInfo>(native_module)));
|
||||
@ -1194,7 +1193,6 @@ std::shared_ptr<NativeModule> WasmEngine::MaybeGetNativeModule(
|
||||
bool WasmEngine::UpdateNativeModuleCache(
|
||||
bool error, std::shared_ptr<NativeModule>* native_module,
|
||||
Isolate* isolate) {
|
||||
DCHECK_EQ(this, native_module->get()->engine());
|
||||
// Pass {native_module} by value here to keep it alive until at least after
|
||||
// we returned from {Update}. Otherwise, we might {Erase} it inside {Update}
|
||||
// which would lock the mutex twice.
|
||||
|
Loading…
Reference in New Issue
Block a user