Skip to content

Commit e6cc1fc

Browse files
backesCommit Bot
authored andcommitted
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}
1 parent 019fa2b commit e6cc1fc

7 files changed

Lines changed: 26 additions & 28 deletions

File tree

src/base/page-allocator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ void* PageAllocator::GetRandomMmapAddr() {
3636
return base::OS::GetRandomMmapAddr();
3737
}
3838

39-
void* PageAllocator::AllocatePages(void* address, size_t size, size_t alignment,
39+
void* PageAllocator::AllocatePages(void* hint, size_t size, size_t alignment,
4040
PageAllocator::Permission access) {
41-
return base::OS::Allocate(address, size, alignment,
41+
return base::OS::Allocate(hint, size, alignment,
4242
static_cast<base::OS::MemoryPermission>(access));
4343
}
4444

src/base/page-allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class V8_BASE_EXPORT PageAllocator
2626

2727
void* GetRandomMmapAddr() override;
2828

29-
void* AllocatePages(void* address, size_t size, size_t alignment,
29+
void* AllocatePages(void* hint, size_t size, size_t alignment,
3030
PageAllocator::Permission access) override;
3131

3232
bool FreePages(void* address, size_t size) override;

src/base/platform/platform-cygwin.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ double LocalTimeOffset(double time_ms, bool is_utc) {
9595
}
9696

9797
// static
98-
void* OS::Allocate(void* address, size_t size, size_t alignment,
98+
void* OS::Allocate(void* hint, size_t size, size_t alignment,
9999
MemoryPermission access) {
100100
size_t page_size = AllocatePageSize();
101101
DCHECK_EQ(0, size % page_size);
102102
DCHECK_EQ(0, alignment % page_size);
103103
DCHECK_LE(page_size, alignment);
104-
address = AlignedAddress(address, alignment);
104+
hint = AlignedAddress(hint, alignment);
105105

106106
DWORD flags = (access == OS::MemoryPermission::kNoAccess)
107107
? MEM_RESERVE
108108
: MEM_RESERVE | MEM_COMMIT;
109109
DWORD protect = GetProtectionFromMemoryPermission(access);
110110

111111
// First, try an exact size aligned allocation.
112-
uint8_t* base = RandomizedVirtualAlloc(size, flags, protect, address);
112+
uint8_t* base = RandomizedVirtualAlloc(size, flags, protect, hint);
113113
if (base == nullptr) return nullptr; // Can't allocate, we're OOM.
114114

115115
// If address is suitably aligned, we're done.
@@ -120,15 +120,15 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
120120
CHECK(Free(base, size));
121121

122122
// Clear the hint. It's unlikely we can allocate at this address.
123-
address = nullptr;
123+
hint = nullptr;
124124

125125
// Add the maximum misalignment so we are guaranteed an aligned base address
126126
// in the allocated region.
127127
size_t padded_size = size + (alignment - page_size);
128128
const int kMaxAttempts = 3;
129129
aligned_base = nullptr;
130130
for (int i = 0; i < kMaxAttempts; ++i) {
131-
base = RandomizedVirtualAlloc(padded_size, flags, protect, address);
131+
base = RandomizedVirtualAlloc(padded_size, flags, protect, hint);
132132
if (base == nullptr) return nullptr; // Can't allocate, we're OOM.
133133

134134
// Try to trim the allocation by freeing the padded allocation and then

src/base/platform/platform-posix.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access) {
137137
return flags;
138138
}
139139

140-
void* Allocate(void* address, size_t size, OS::MemoryPermission access) {
140+
void* Allocate(void* hint, size_t size, OS::MemoryPermission access) {
141141
int prot = GetProtectionFromMemoryPermission(access);
142142
int flags = GetFlagsForMemoryPermission(access);
143-
void* result = mmap(address, size, prot, flags, kMmapFd, kMmapFdOffset);
143+
void* result = mmap(hint, size, prot, flags, kMmapFd, kMmapFdOffset);
144144
if (result == MAP_FAILED) return nullptr;
145145
return result;
146146
}
@@ -278,16 +278,16 @@ void* OS::GetRandomMmapAddr() {
278278
// TODO(bbudge) Move Cygwin and Fuchsia stuff into platform-specific files.
279279
#if !V8_OS_CYGWIN && !V8_OS_FUCHSIA
280280
// static
281-
void* OS::Allocate(void* address, size_t size, size_t alignment,
281+
void* OS::Allocate(void* hint, size_t size, size_t alignment,
282282
MemoryPermission access) {
283283
size_t page_size = AllocatePageSize();
284284
DCHECK_EQ(0, size % page_size);
285285
DCHECK_EQ(0, alignment % page_size);
286-
address = AlignedAddress(address, alignment);
286+
hint = AlignedAddress(hint, alignment);
287287
// Add the maximum misalignment so we are guaranteed an aligned base address.
288288
size_t request_size = size + (alignment - page_size);
289289
request_size = RoundUp(request_size, OS::AllocatePageSize());
290-
void* result = base::Allocate(address, request_size, access);
290+
void* result = base::Allocate(hint, request_size, access);
291291
if (result == nullptr) return nullptr;
292292

293293
// Unmap memory allocated before the aligned base address.

src/base/platform/platform-win32.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,21 +798,21 @@ uint8_t* RandomizedVirtualAlloc(size_t size, DWORD flags, DWORD protect,
798798
} // namespace
799799

800800
// static
801-
void* OS::Allocate(void* address, size_t size, size_t alignment,
801+
void* OS::Allocate(void* hint, size_t size, size_t alignment,
802802
MemoryPermission access) {
803803
size_t page_size = AllocatePageSize();
804804
DCHECK_EQ(0, size % page_size);
805805
DCHECK_EQ(0, alignment % page_size);
806806
DCHECK_LE(page_size, alignment);
807-
address = AlignedAddress(address, alignment);
807+
hint = AlignedAddress(hint, alignment);
808808

809809
DWORD flags = (access == OS::MemoryPermission::kNoAccess)
810810
? MEM_RESERVE
811811
: MEM_RESERVE | MEM_COMMIT;
812812
DWORD protect = GetProtectionFromMemoryPermission(access);
813813

814814
// First, try an exact size aligned allocation.
815-
uint8_t* base = RandomizedVirtualAlloc(size, flags, protect, address);
815+
uint8_t* base = RandomizedVirtualAlloc(size, flags, protect, hint);
816816
if (base == nullptr) return nullptr; // Can't allocate, we're OOM.
817817

818818
// If address is suitably aligned, we're done.
@@ -824,15 +824,15 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
824824
CHECK(Free(base, size));
825825

826826
// Clear the hint. It's unlikely we can allocate at this address.
827-
address = nullptr;
827+
hint = nullptr;
828828

829829
// Add the maximum misalignment so we are guaranteed an aligned base address
830830
// in the allocated region.
831831
size_t padded_size = size + (alignment - page_size);
832832
const int kMaxAttempts = 3;
833833
aligned_base = nullptr;
834834
for (int i = 0; i < kMaxAttempts; ++i) {
835-
base = RandomizedVirtualAlloc(padded_size, flags, protect, address);
835+
base = RandomizedVirtualAlloc(padded_size, flags, protect, hint);
836836
if (base == nullptr) return nullptr; // Can't allocate, we're OOM.
837837

838838
// Try to trim the allocation by freeing the padded allocation and then

src/sanitizer/lsan-page-allocator.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ LsanPageAllocator::LsanPageAllocator(v8::PageAllocator* page_allocator)
2020
DCHECK_NOT_NULL(page_allocator);
2121
}
2222

23-
void* LsanPageAllocator::AllocatePages(void* address, size_t size,
23+
void* LsanPageAllocator::AllocatePages(void* hint, size_t size,
2424
size_t alignment,
2525
PageAllocator::Permission access) {
26-
void* result =
27-
page_allocator_->AllocatePages(address, size, alignment, access);
26+
void* result = page_allocator_->AllocatePages(hint, size, alignment, access);
2827
#if defined(LEAK_SANITIZER)
2928
if (result != nullptr) {
3029
__lsan_register_root_region(result, size);

src/utils/allocation.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,14 @@ void* GetRandomMmapAddr() {
161161
return GetPlatformPageAllocator()->GetRandomMmapAddr();
162162
}
163163

164-
void* AllocatePages(v8::PageAllocator* page_allocator, void* address,
165-
size_t size, size_t alignment,
166-
PageAllocator::Permission access) {
164+
void* AllocatePages(v8::PageAllocator* page_allocator, void* hint, size_t size,
165+
size_t alignment, PageAllocator::Permission access) {
167166
DCHECK_NOT_NULL(page_allocator);
168-
DCHECK_EQ(address, AlignedAddress(address, alignment));
167+
DCHECK_EQ(hint, AlignedAddress(hint, alignment));
169168
DCHECK(IsAligned(size, page_allocator->AllocatePageSize()));
170169
void* result = nullptr;
171170
for (int i = 0; i < kAllocationTries; ++i) {
172-
result = page_allocator->AllocatePages(address, size, alignment, access);
171+
result = page_allocator->AllocatePages(hint, size, alignment, access);
173172
if (result != nullptr) break;
174173
size_t request_size = size + alignment - page_allocator->AllocatePageSize();
175174
if (!OnCriticalMemoryPressure(request_size)) break;
@@ -198,11 +197,11 @@ bool SetPermissions(v8::PageAllocator* page_allocator, void* address,
198197
return page_allocator->SetPermissions(address, size, access);
199198
}
200199

201-
byte* AllocatePage(v8::PageAllocator* page_allocator, void* address,
200+
byte* AllocatePage(v8::PageAllocator* page_allocator, void* hint,
202201
size_t* allocated) {
203202
DCHECK_NOT_NULL(page_allocator);
204203
size_t page_size = page_allocator->AllocatePageSize();
205-
void* result = AllocatePages(page_allocator, address, page_size, page_size,
204+
void* result = AllocatePages(page_allocator, hint, page_size, page_size,
206205
PageAllocator::kReadWrite);
207206
if (result != nullptr) *allocated = page_size;
208207
return static_cast<byte*>(result);

0 commit comments

Comments
 (0)