Commit b0209337 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Add some more DCHECKs for native module caching

When updating the native module cache, the native module must have been
created in the same engine before. Hence replace a conditional by a
DCHECK, and add two more DCHECKs to ensure that all involved modules
belong to the same engine.

R=thibaudm@chromium.org

Bug: v8:6847
Change-Id: Ieb66b6b0bda40cd3c4637d38918762bc01c3a2d5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2182640Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67597}
parent 6817e074
......@@ -738,6 +738,7 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
Handle<WasmModuleObject> WasmEngine::ImportNativeModule(
Isolate* isolate, std::shared_ptr<NativeModule> shared_native_module,
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 =
......@@ -1015,6 +1016,7 @@ 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.
......@@ -1024,12 +1026,10 @@ bool WasmEngine::UpdateNativeModuleCache(
if (prev == native_module->get()) return true;
base::MutexGuard guard(&mutex_);
auto& native_module_info = native_modules_[native_module->get()];
if (!native_module_info) {
native_module_info = std::make_unique<NativeModuleInfo>();
}
native_module_info->isolates.insert(isolate);
isolates_[isolate]->native_modules.insert((*native_module).get());
DCHECK_EQ(1, native_modules_.count(native_module->get()));
native_modules_[native_module->get()]->isolates.insert(isolate);
DCHECK_EQ(1, isolates_.count(isolate));
isolates_[isolate]->native_modules.insert(native_module->get());
return false;
}
......
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