Commit 632131da authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Cleanup and document {WasmCodeManager} mutex.

R=clemensh@chromium.org
BUG=v8:8015

Change-Id: I1daca16797a6a359aaab1703767ae24e2d73e8f2
Reviewed-on: https://chromium-review.googlesource.com/1238240Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56123}
parent 4456b384
......@@ -661,8 +661,6 @@ Address NativeModule::AllocateForCode(size_t size) {
wasm_code_manager_->TryAllocate(size, reinterpret_cast<void*>(hint)));
VirtualMemory& new_mem = owned_code_space_.back();
if (!new_mem.IsReserved()) return kNullAddress;
base::LockGuard<base::Mutex> lock(
&wasm_code_manager_->native_modules_mutex_);
wasm_code_manager_->AssignRanges(new_mem.address(), new_mem.end(), this);
free_code_space_.Merge({new_mem.address(), new_mem.end()});
......@@ -810,9 +808,17 @@ bool WasmCodeManager::Commit(Address start, size_t size) {
void WasmCodeManager::AssignRanges(Address start, Address end,
NativeModule* native_module) {
base::LockGuard<base::Mutex> lock(&native_modules_mutex_);
lookup_map_.insert(std::make_pair(start, std::make_pair(end, native_module)));
}
void WasmCodeManager::AssignRangesAndAddModule(Address start, Address end,
NativeModule* native_module) {
base::LockGuard<base::Mutex> lock(&native_modules_mutex_);
lookup_map_.insert(std::make_pair(start, std::make_pair(end, native_module)));
native_modules_.emplace(native_module);
}
VirtualMemory WasmCodeManager::TryAllocate(size_t size, void* hint) {
v8::PageAllocator* page_allocator = GetPlatformPageAllocator();
DCHECK_GT(size, 0);
......@@ -929,9 +935,7 @@ std::unique_ptr<NativeModule> WasmCodeManager::NewNativeModule(
std::move(module), env));
TRACE_HEAP("New NativeModule %p: Mem: %" PRIuPTR ",+%zu\n", this, start,
size);
base::LockGuard<base::Mutex> lock(&native_modules_mutex_);
AssignRanges(start, end, ret.get());
native_modules_.emplace(ret.get());
AssignRangesAndAddModule(start, end, ret.get());
return ret;
}
......
......@@ -469,13 +469,21 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
void FreeNativeModule(NativeModule*);
void Free(VirtualMemory* mem);
void AssignRanges(Address start, Address end, NativeModule*);
void AssignRangesAndAddModule(Address start, Address end, NativeModule*);
bool ShouldForceCriticalMemoryPressureNotification();
WasmMemoryTracker* const memory_tracker_;
std::atomic<size_t> remaining_uncommitted_code_space_;
mutable base::Mutex native_modules_mutex_;
//////////////////////////////////////////////////////////////////////////////
// Protected by {native_modules_mutex_}:
std::map<Address, std::pair<Address, NativeModule*>> lookup_map_;
std::unordered_set<NativeModule*> native_modules_;
std::atomic<size_t> remaining_uncommitted_code_space_;
// End of fields protected by {native_modules_mutex_}.
//////////////////////////////////////////////////////////////////////////////
DISALLOW_COPY_AND_ASSIGN(WasmCodeManager);
};
......
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