Commit 356470b0 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[test] Make Multi-Mapped Mock Allocator threadsafe

TSan complains in "isolates" tests otherwise. Also further reduce
virtual memory requirements of the sample test to address flaky
allocation failures on 32-bit platforms.

Change-Id: I26c9a59965009d7083876b4ff4836ee879d33350
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2000138
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65750}
parent 7ddc3f66
...@@ -257,6 +257,7 @@ class MultiMappedAllocator : public ArrayBufferAllocatorBase { ...@@ -257,6 +257,7 @@ class MultiMappedAllocator : public ArrayBufferAllocatorBase {
FATAL("mremap failed with error %d: %s", errno, strerror(errno)); FATAL("mremap failed with error %d: %s", errno, strerror(errno));
} }
} }
base::MutexGuard lock_guard(&regions_mutex_);
regions_[virtual_alloc] = real_alloc; regions_[virtual_alloc] = real_alloc;
return virtual_alloc; return virtual_alloc;
} }
...@@ -265,6 +266,7 @@ class MultiMappedAllocator : public ArrayBufferAllocatorBase { ...@@ -265,6 +266,7 @@ class MultiMappedAllocator : public ArrayBufferAllocatorBase {
if (length < kChunkSize) { if (length < kChunkSize) {
return ArrayBufferAllocatorBase::Free(data, length); return ArrayBufferAllocatorBase::Free(data, length);
} }
base::MutexGuard lock_guard(&regions_mutex_);
void* real_alloc = regions_[data]; void* real_alloc = regions_[data];
munmap(real_alloc, kChunkSize); munmap(real_alloc, kChunkSize);
size_t rounded_length = RoundUp(length, kChunkSize); size_t rounded_length = RoundUp(length, kChunkSize);
...@@ -277,6 +279,7 @@ class MultiMappedAllocator : public ArrayBufferAllocatorBase { ...@@ -277,6 +279,7 @@ class MultiMappedAllocator : public ArrayBufferAllocatorBase {
static constexpr size_t kChunkSize = 2 * 1024 * 1024; static constexpr size_t kChunkSize = 2 * 1024 * 1024;
std::unordered_map<void*, void*> regions_; std::unordered_map<void*, void*> regions_;
base::Mutex regions_mutex_;
}; };
#endif // V8_OS_LINUX #endif // V8_OS_LINUX
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// Chosen for stress runs on 32-bit systems. Physical memory is not an issue // Chosen for stress runs on 32-bit systems. Physical memory is not an issue
// thanks to the mock allocator, but virtual address space is still limited. // thanks to the mock allocator, but virtual address space is still limited.
let kSize = 512 * 1024 * 1024; let kSize = 128 * 1024 * 1024;
// Must be >= MultiMappedMockAllocator::kChunkSize in d8.cc. // Must be >= MultiMappedMockAllocator::kChunkSize in d8.cc.
let kChunkSize = 2 * 1024 * 1024; let kChunkSize = 2 * 1024 * 1024;
let a = new Uint8Array(kSize); let a = new Uint8Array(kSize);
......
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