Skip to content

Commit bc2bc6b

Browse files
LeszekSwirskiCommit Bot
authored andcommitted
[offthread] Make Heap::AlignWithFiller static
Enable the use of Heap::AlignWithFiller off-thread by making the method static. Bug: chromium:1075999 Change-Id: I8071ae678f954dd4e960b2cd83f63dd22a948920 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2184230 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/master@{#67602}
1 parent c64b52a commit bc2bc6b

4 files changed

Lines changed: 26 additions & 19 deletions

File tree

src/heap/heap.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,7 @@ int Heap::GetMaximumFillToAlign(AllocationAlignment alignment) {
28482848
return 0;
28492849
}
28502850

2851-
2851+
// static
28522852
int Heap::GetFillToAlign(Address address, AllocationAlignment alignment) {
28532853
if (alignment == kDoubleAligned && (address & kDoubleAlignmentMask) != 0)
28542854
return kTaggedSize;
@@ -2861,24 +2861,28 @@ size_t Heap::GetCodeRangeReservedAreaSize() {
28612861
return kReservedCodeRangePages * MemoryAllocator::GetCommitPageSize();
28622862
}
28632863

2864-
HeapObject Heap::PrecedeWithFiller(HeapObject object, int filler_size) {
2865-
CreateFillerObjectAt(object.address(), filler_size, ClearRecordedSlots::kNo);
2864+
// static
2865+
HeapObject Heap::PrecedeWithFiller(ReadOnlyRoots roots, HeapObject object,
2866+
int filler_size) {
2867+
CreateFillerObjectAt(roots, object.address(), filler_size,
2868+
ClearFreedMemoryMode::kDontClearFreedMemory);
28662869
return HeapObject::FromAddress(object.address() + filler_size);
28672870
}
28682871

2869-
HeapObject Heap::AlignWithFiller(HeapObject object, int object_size,
2870-
int allocation_size,
2872+
// static
2873+
HeapObject Heap::AlignWithFiller(ReadOnlyRoots roots, HeapObject object,
2874+
int object_size, int allocation_size,
28712875
AllocationAlignment alignment) {
28722876
int filler_size = allocation_size - object_size;
28732877
DCHECK_LT(0, filler_size);
28742878
int pre_filler = GetFillToAlign(object.address(), alignment);
28752879
if (pre_filler) {
2876-
object = PrecedeWithFiller(object, pre_filler);
2880+
object = PrecedeWithFiller(roots, object, pre_filler);
28772881
filler_size -= pre_filler;
28782882
}
28792883
if (filler_size) {
2880-
CreateFillerObjectAt(object.address() + object_size, filler_size,
2881-
ClearRecordedSlots::kNo);
2884+
CreateFillerObjectAt(roots, object.address() + object_size, filler_size,
2885+
ClearFreedMemoryMode::kDontClearFreedMemory);
28822886
}
28832887
return object;
28842888
}

src/heap/heap.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,15 +1330,15 @@ class Heap {
13301330
// ===========================================================================
13311331

13321332
// Creates a filler object and returns a heap object immediately after it.
1333-
V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT HeapObject
1334-
PrecedeWithFiller(HeapObject object, int filler_size);
1333+
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT HeapObject
1334+
PrecedeWithFiller(ReadOnlyRoots roots, HeapObject object, int filler_size);
13351335

13361336
// Creates a filler object if needed for alignment and returns a heap object
13371337
// immediately after it. If any space is left after the returned object,
13381338
// another filler object is created so the over allocated memory is iterable.
1339-
V8_WARN_UNUSED_RESULT HeapObject
1340-
AlignWithFiller(HeapObject object, int object_size, int allocation_size,
1341-
AllocationAlignment alignment);
1339+
static V8_WARN_UNUSED_RESULT HeapObject
1340+
AlignWithFiller(ReadOnlyRoots roots, HeapObject object, int object_size,
1341+
int allocation_size, AllocationAlignment alignment);
13421342

13431343
// Allocate an external backing store with the given allocation callback.
13441344
// If the callback fails (indicated by a nullptr result) then this function

src/heap/spaces-inl.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,9 @@ AllocationResult LocalAllocationBuffer::AllocateRawAligned(
335335

336336
allocation_info_.set_top(new_top);
337337
if (filler_size > 0) {
338-
return heap_->PrecedeWithFiller(HeapObject::FromAddress(current_top),
339-
filler_size);
338+
return Heap::PrecedeWithFiller(ReadOnlyRoots(heap_),
339+
HeapObject::FromAddress(current_top),
340+
filler_size);
340341
}
341342

342343
return AllocationResult(HeapObject::FromAddress(current_top));
@@ -369,8 +370,9 @@ HeapObject PagedSpace::TryAllocateLinearlyAligned(
369370
allocation_info_.set_top(new_top);
370371
if (filler_size > 0) {
371372
*size_in_bytes += filler_size;
372-
return heap()->PrecedeWithFiller(HeapObject::FromAddress(current_top),
373-
filler_size);
373+
return Heap::PrecedeWithFiller(ReadOnlyRoots(heap()),
374+
HeapObject::FromAddress(current_top),
375+
filler_size);
374376
}
375377

376378
return HeapObject::FromAddress(current_top);
@@ -484,7 +486,7 @@ AllocationResult NewSpace::AllocateRawAligned(int size_in_bytes,
484486
DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
485487

486488
if (filler_size > 0) {
487-
obj = heap()->PrecedeWithFiller(obj, filler_size);
489+
obj = Heap::PrecedeWithFiller(ReadOnlyRoots(heap()), obj, filler_size);
488490
}
489491

490492
MSAN_ALLOCATED_UNINITIALIZED_MEMORY(obj.address(), size_in_bytes);

src/snapshot/deserializer-allocator.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ Address DeserializerAllocator::Allocate(SnapshotSpace space, int size) {
8585
DCHECK(ReadOnlyRoots(heap_).free_space_map().IsMap());
8686
DCHECK(ReadOnlyRoots(heap_).one_pointer_filler_map().IsMap());
8787
DCHECK(ReadOnlyRoots(heap_).two_pointer_filler_map().IsMap());
88-
obj = heap_->AlignWithFiller(obj, size, reserved, next_alignment_);
88+
obj = Heap::AlignWithFiller(ReadOnlyRoots(heap_), obj, size, reserved,
89+
next_alignment_);
8990
address = obj.address();
9091
next_alignment_ = kWordAligned;
9192
return address;

0 commit comments

Comments
 (0)