[wasm] Cleanup and document {WasmCodeManager} mutex.

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

Change-Id: I1daca16797a6a359aaab1703767ae24e2d73e8f2
Reviewed-on: https://chromium-review.googlesource.com/1238240
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56123}
This commit is contained in:
Michael Starzinger 2018-09-21 11:23:31 +02:00 committed by Commit Bot
parent 4456b384a7
commit 632131daa6
2 changed files with 18 additions and 6 deletions

View File

@ -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;
}

View File

@ -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);
};