Rename some "address" to "hint"
The "address" pointer we pass to {Allocate} and {AllocatePages} functions is actually just a hint. The actual address of the reservation is returned by the function. This CL renames the {address} argument of those functions to {hint} to make this semantic more clear. R=mlippautz@chromium.org Bug: v8:9396 Change-Id: I9ff3785ea4e6f9b7d77f26f224445f3f92e11f22 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1784280 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#63549}
This commit is contained in:
parent
019fa2b531
commit
e6cc1fc025
@ -36,9 +36,9 @@ void* PageAllocator::GetRandomMmapAddr() {
|
||||
return base::OS::GetRandomMmapAddr();
|
||||
}
|
||||
|
||||
void* PageAllocator::AllocatePages(void* address, size_t size, size_t alignment,
|
||||
void* PageAllocator::AllocatePages(void* hint, size_t size, size_t alignment,
|
||||
PageAllocator::Permission access) {
|
||||
return base::OS::Allocate(address, size, alignment,
|
||||
return base::OS::Allocate(hint, size, alignment,
|
||||
static_cast<base::OS::MemoryPermission>(access));
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class V8_BASE_EXPORT PageAllocator
|
||||
|
||||
void* GetRandomMmapAddr() override;
|
||||
|
||||
void* AllocatePages(void* address, size_t size, size_t alignment,
|
||||
void* AllocatePages(void* hint, size_t size, size_t alignment,
|
||||
PageAllocator::Permission access) override;
|
||||
|
||||
bool FreePages(void* address, size_t size) override;
|
||||
|
@ -95,13 +95,13 @@ double LocalTimeOffset(double time_ms, bool is_utc) {
|
||||
}
|
||||
|
||||
// static
|
||||
void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
void* OS::Allocate(void* hint, size_t size, size_t alignment,
|
||||
MemoryPermission access) {
|
||||
size_t page_size = AllocatePageSize();
|
||||
DCHECK_EQ(0, size % page_size);
|
||||
DCHECK_EQ(0, alignment % page_size);
|
||||
DCHECK_LE(page_size, alignment);
|
||||
address = AlignedAddress(address, alignment);
|
||||
hint = AlignedAddress(hint, alignment);
|
||||
|
||||
DWORD flags = (access == OS::MemoryPermission::kNoAccess)
|
||||
? MEM_RESERVE
|
||||
@ -109,7 +109,7 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
DWORD protect = GetProtectionFromMemoryPermission(access);
|
||||
|
||||
// First, try an exact size aligned allocation.
|
||||
uint8_t* base = RandomizedVirtualAlloc(size, flags, protect, address);
|
||||
uint8_t* base = RandomizedVirtualAlloc(size, flags, protect, hint);
|
||||
if (base == nullptr) return nullptr; // Can't allocate, we're OOM.
|
||||
|
||||
// If address is suitably aligned, we're done.
|
||||
@ -120,7 +120,7 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
CHECK(Free(base, size));
|
||||
|
||||
// Clear the hint. It's unlikely we can allocate at this address.
|
||||
address = nullptr;
|
||||
hint = nullptr;
|
||||
|
||||
// Add the maximum misalignment so we are guaranteed an aligned base address
|
||||
// in the allocated region.
|
||||
@ -128,7 +128,7 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
const int kMaxAttempts = 3;
|
||||
aligned_base = nullptr;
|
||||
for (int i = 0; i < kMaxAttempts; ++i) {
|
||||
base = RandomizedVirtualAlloc(padded_size, flags, protect, address);
|
||||
base = RandomizedVirtualAlloc(padded_size, flags, protect, hint);
|
||||
if (base == nullptr) return nullptr; // Can't allocate, we're OOM.
|
||||
|
||||
// Try to trim the allocation by freeing the padded allocation and then
|
||||
|
@ -137,10 +137,10 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access) {
|
||||
return flags;
|
||||
}
|
||||
|
||||
void* Allocate(void* address, size_t size, OS::MemoryPermission access) {
|
||||
void* Allocate(void* hint, size_t size, OS::MemoryPermission access) {
|
||||
int prot = GetProtectionFromMemoryPermission(access);
|
||||
int flags = GetFlagsForMemoryPermission(access);
|
||||
void* result = mmap(address, size, prot, flags, kMmapFd, kMmapFdOffset);
|
||||
void* result = mmap(hint, size, prot, flags, kMmapFd, kMmapFdOffset);
|
||||
if (result == MAP_FAILED) return nullptr;
|
||||
return result;
|
||||
}
|
||||
@ -278,16 +278,16 @@ void* OS::GetRandomMmapAddr() {
|
||||
// TODO(bbudge) Move Cygwin and Fuchsia stuff into platform-specific files.
|
||||
#if !V8_OS_CYGWIN && !V8_OS_FUCHSIA
|
||||
// static
|
||||
void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
void* OS::Allocate(void* hint, size_t size, size_t alignment,
|
||||
MemoryPermission access) {
|
||||
size_t page_size = AllocatePageSize();
|
||||
DCHECK_EQ(0, size % page_size);
|
||||
DCHECK_EQ(0, alignment % page_size);
|
||||
address = AlignedAddress(address, alignment);
|
||||
hint = AlignedAddress(hint, alignment);
|
||||
// Add the maximum misalignment so we are guaranteed an aligned base address.
|
||||
size_t request_size = size + (alignment - page_size);
|
||||
request_size = RoundUp(request_size, OS::AllocatePageSize());
|
||||
void* result = base::Allocate(address, request_size, access);
|
||||
void* result = base::Allocate(hint, request_size, access);
|
||||
if (result == nullptr) return nullptr;
|
||||
|
||||
// Unmap memory allocated before the aligned base address.
|
||||
|
@ -798,13 +798,13 @@ uint8_t* RandomizedVirtualAlloc(size_t size, DWORD flags, DWORD protect,
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
void* OS::Allocate(void* hint, size_t size, size_t alignment,
|
||||
MemoryPermission access) {
|
||||
size_t page_size = AllocatePageSize();
|
||||
DCHECK_EQ(0, size % page_size);
|
||||
DCHECK_EQ(0, alignment % page_size);
|
||||
DCHECK_LE(page_size, alignment);
|
||||
address = AlignedAddress(address, alignment);
|
||||
hint = AlignedAddress(hint, alignment);
|
||||
|
||||
DWORD flags = (access == OS::MemoryPermission::kNoAccess)
|
||||
? MEM_RESERVE
|
||||
@ -812,7 +812,7 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
DWORD protect = GetProtectionFromMemoryPermission(access);
|
||||
|
||||
// First, try an exact size aligned allocation.
|
||||
uint8_t* base = RandomizedVirtualAlloc(size, flags, protect, address);
|
||||
uint8_t* base = RandomizedVirtualAlloc(size, flags, protect, hint);
|
||||
if (base == nullptr) return nullptr; // Can't allocate, we're OOM.
|
||||
|
||||
// If address is suitably aligned, we're done.
|
||||
@ -824,7 +824,7 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
CHECK(Free(base, size));
|
||||
|
||||
// Clear the hint. It's unlikely we can allocate at this address.
|
||||
address = nullptr;
|
||||
hint = nullptr;
|
||||
|
||||
// Add the maximum misalignment so we are guaranteed an aligned base address
|
||||
// in the allocated region.
|
||||
@ -832,7 +832,7 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
const int kMaxAttempts = 3;
|
||||
aligned_base = nullptr;
|
||||
for (int i = 0; i < kMaxAttempts; ++i) {
|
||||
base = RandomizedVirtualAlloc(padded_size, flags, protect, address);
|
||||
base = RandomizedVirtualAlloc(padded_size, flags, protect, hint);
|
||||
if (base == nullptr) return nullptr; // Can't allocate, we're OOM.
|
||||
|
||||
// Try to trim the allocation by freeing the padded allocation and then
|
||||
|
@ -20,11 +20,10 @@ LsanPageAllocator::LsanPageAllocator(v8::PageAllocator* page_allocator)
|
||||
DCHECK_NOT_NULL(page_allocator);
|
||||
}
|
||||
|
||||
void* LsanPageAllocator::AllocatePages(void* address, size_t size,
|
||||
void* LsanPageAllocator::AllocatePages(void* hint, size_t size,
|
||||
size_t alignment,
|
||||
PageAllocator::Permission access) {
|
||||
void* result =
|
||||
page_allocator_->AllocatePages(address, size, alignment, access);
|
||||
void* result = page_allocator_->AllocatePages(hint, size, alignment, access);
|
||||
#if defined(LEAK_SANITIZER)
|
||||
if (result != nullptr) {
|
||||
__lsan_register_root_region(result, size);
|
||||
|
@ -161,15 +161,14 @@ void* GetRandomMmapAddr() {
|
||||
return GetPlatformPageAllocator()->GetRandomMmapAddr();
|
||||
}
|
||||
|
||||
void* AllocatePages(v8::PageAllocator* page_allocator, void* address,
|
||||
size_t size, size_t alignment,
|
||||
PageAllocator::Permission access) {
|
||||
void* AllocatePages(v8::PageAllocator* page_allocator, void* hint, size_t size,
|
||||
size_t alignment, PageAllocator::Permission access) {
|
||||
DCHECK_NOT_NULL(page_allocator);
|
||||
DCHECK_EQ(address, AlignedAddress(address, alignment));
|
||||
DCHECK_EQ(hint, AlignedAddress(hint, alignment));
|
||||
DCHECK(IsAligned(size, page_allocator->AllocatePageSize()));
|
||||
void* result = nullptr;
|
||||
for (int i = 0; i < kAllocationTries; ++i) {
|
||||
result = page_allocator->AllocatePages(address, size, alignment, access);
|
||||
result = page_allocator->AllocatePages(hint, size, alignment, access);
|
||||
if (result != nullptr) break;
|
||||
size_t request_size = size + alignment - page_allocator->AllocatePageSize();
|
||||
if (!OnCriticalMemoryPressure(request_size)) break;
|
||||
@ -198,11 +197,11 @@ bool SetPermissions(v8::PageAllocator* page_allocator, void* address,
|
||||
return page_allocator->SetPermissions(address, size, access);
|
||||
}
|
||||
|
||||
byte* AllocatePage(v8::PageAllocator* page_allocator, void* address,
|
||||
byte* AllocatePage(v8::PageAllocator* page_allocator, void* hint,
|
||||
size_t* allocated) {
|
||||
DCHECK_NOT_NULL(page_allocator);
|
||||
size_t page_size = page_allocator->AllocatePageSize();
|
||||
void* result = AllocatePages(page_allocator, address, page_size, page_size,
|
||||
void* result = AllocatePages(page_allocator, hint, page_size, page_size,
|
||||
PageAllocator::kReadWrite);
|
||||
if (result != nullptr) *allocated = page_size;
|
||||
return static_cast<byte*>(result);
|
||||
|
Loading…
Reference in New Issue
Block a user