Skip to content

Commit d0468de

Browse files
Bill BudgeCommit Bot
authored andcommitted
[heap] Fix StoreBuffer setup.
- Solves a problem for PPC in a configuration where commit page size is 64K. https://chromium-review.googlesource.com/c/v8/v8/+/1149515 - Uses existing VM allocation code to get properly aligned memory. - Makes sure the size for SetPermissions is a multiple of system page size. Bug:chromium:756050 Change-Id: Ib3799ab7a3bb44b0091c234234c1cc47938379c2 Reviewed-on: https://chromium-review.googlesource.com/1161210 Commit-Queue: Bill Budge <[email protected]> Reviewed-by: Michael Lippautz <[email protected]> Reviewed-by: Michael Starzinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#54930}
1 parent 083c5a6 commit d0468de

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

src/heap/store-buffer.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,28 @@ StoreBuffer::StoreBuffer(Heap* heap)
3131
}
3232

3333
void StoreBuffer::SetUp() {
34-
// Allocate 3x the buffer size, so that we can start the new store buffer
35-
// aligned to 2x the size. This lets us use a bit test to detect the end of
36-
// the area.
34+
const size_t requested_size = kStoreBufferSize * kStoreBuffers;
35+
// Allocate buffer memory aligned at least to kStoreBufferSize. This lets us
36+
// use a bit test to detect the ends of the buffers.
37+
const size_t alignment =
38+
std::max<size_t>(kStoreBufferSize, AllocatePageSize());
39+
void* hint = AlignedAddress(heap_->GetRandomMmapAddr(), alignment);
3740
VirtualMemory reservation;
38-
if (!AllocVirtualMemory(kStoreBufferSize * 3, heap_->GetRandomMmapAddr(),
39-
&reservation)) {
41+
if (!AlignedAllocVirtualMemory(requested_size, alignment, hint,
42+
&reservation)) {
4043
heap_->FatalProcessOutOfMemory("StoreBuffer::SetUp");
4144
}
45+
4246
Address start = reservation.address();
43-
start_[0] = reinterpret_cast<Address*>(::RoundUp(start, kStoreBufferSize));
47+
const size_t allocated_size = reservation.size();
48+
49+
start_[0] = reinterpret_cast<Address*>(start);
4450
limit_[0] = start_[0] + (kStoreBufferSize / kPointerSize);
4551
start_[1] = limit_[0];
4652
limit_[1] = start_[1] + (kStoreBufferSize / kPointerSize);
4753

48-
Address* vm_limit = reinterpret_cast<Address*>(start + reservation.size());
49-
54+
// Sanity check the buffers.
55+
Address* vm_limit = reinterpret_cast<Address*>(start + allocated_size);
5056
USE(vm_limit);
5157
for (int i = 0; i < kStoreBuffers; i++) {
5258
DCHECK(reinterpret_cast<Address>(start_[i]) >= reservation.address());
@@ -56,8 +62,9 @@ void StoreBuffer::SetUp() {
5662
DCHECK_EQ(0, reinterpret_cast<Address>(limit_[i]) & kStoreBufferMask);
5763
}
5864

59-
if (!reservation.SetPermissions(reinterpret_cast<Address>(start_[0]),
60-
kStoreBufferSize * kStoreBuffers,
65+
// Set RW permissions only on the pages we use.
66+
const size_t used_size = RoundUp(requested_size, CommitPageSize());
67+
if (!reservation.SetPermissions(start, used_size,
6168
PageAllocator::kReadWrite)) {
6269
heap_->FatalProcessOutOfMemory("StoreBuffer::SetUp");
6370
}
@@ -66,7 +73,6 @@ void StoreBuffer::SetUp() {
6673
virtual_memory_.TakeControl(&reservation);
6774
}
6875

69-
7076
void StoreBuffer::TearDown() {
7177
if (virtual_memory_.IsReserved()) virtual_memory_.Free();
7278
top_ = nullptr;

0 commit comments

Comments
 (0)