Commit 5d546c2a authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

[heap] Fix aligned allocation in ConcurrentAllocator

Don't actually free memory as that would maintain free bytes accounting.
Instead, just write a filler that is reclaimed on next garbage
collection, updating counters.

Bug: v8:13000, chromium:1338687
Change-Id: I5339505160fde4b2f522a1a4212d23d7afc2b5f3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3726292Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81407}
parent d2fd55f9
......@@ -170,26 +170,16 @@ AllocationResult ConcurrentAllocator::AllocateOutsideLab(
if (!result) return AllocationResult::Failure();
DCHECK_GE(result->second, aligned_size_in_bytes);
HeapObject object = HeapObject::FromAddress(result->first);
const int filler_size = Heap::GetFillToAlign(object.address(), alignment);
DCHECK_IMPLIES(filler_size != 0, filler_size == requested_filler_size);
// Actually align the allocation.
if (requested_filler_size) {
if (filler_size) {
object = local_heap_->heap()->PrecedeWithFiller(object, filler_size);
} else {
// Free the unneeded filler space.
space_->Free(object.address() + size_in_bytes, requested_filler_size,
SpaceAccountingMode::kSpaceAccounted);
}
}
HeapObject object =
(requested_filler_size)
? owning_heap()->AlignWithFiller(
HeapObject::FromAddress(result->first), size_in_bytes,
static_cast<int>(result->second), alignment)
: HeapObject::FromAddress(result->first);
if (IsBlackAllocationEnabled()) {
owning_heap()->incremental_marking()->MarkBlackBackground(object,
size_in_bytes);
}
return AllocationResult::FromObject(object);
}
......
......@@ -3150,15 +3150,16 @@ HeapObject Heap::PrecedeWithFiller(HeapObject object, int filler_size) {
HeapObject Heap::AlignWithFiller(HeapObject object, int object_size,
int allocation_size,
AllocationAlignment alignment) {
int filler_size = allocation_size - object_size;
const int filler_size = allocation_size - object_size;
DCHECK_LT(0, filler_size);
int pre_filler = GetFillToAlign(object.address(), alignment);
const int pre_filler = GetFillToAlign(object.address(), alignment);
if (pre_filler) {
object = PrecedeWithFiller(object, pre_filler);
filler_size -= pre_filler;
}
if (filler_size) {
CreateFillerObjectAt(object.address() + object_size, filler_size);
DCHECK_LE(0, filler_size - pre_filler);
const int post_filler = filler_size - pre_filler;
if (post_filler) {
CreateFillerObjectAt(object.address() + object_size, post_filler);
}
return object;
}
......
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