Commit fbc1f32d authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[serializer] DCHECK deserializer allocations are initialized

Add a DCHECK during deserializer allocation that the previous allocation
is sufficiently initialized to be iterable. This is an step towards
allowing GC during deserializer execution.

Bug: v8:10815
Change-Id: I29da21b93e6b826bdb7b5f9f5a9723da1698a225
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2396079
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69802}
parent 6798619a
...@@ -64,6 +64,22 @@ Address DeserializerAllocator::AllocateRaw(SnapshotSpace space, int size) { ...@@ -64,6 +64,22 @@ Address DeserializerAllocator::AllocateRaw(SnapshotSpace space, int size) {
} }
Address DeserializerAllocator::Allocate(SnapshotSpace space, int size) { Address DeserializerAllocator::Allocate(SnapshotSpace space, int size) {
#ifdef DEBUG
if (previous_allocation_start_ != kNullAddress) {
// Make sure that the previous allocation is initialized sufficiently to
// be iterated over by the GC.
Address object_address = previous_allocation_start_;
Address previous_allocation_end =
previous_allocation_start_ + previous_allocation_size_;
while (object_address != previous_allocation_end) {
int object_size = HeapObject::FromAddress(object_address).Size();
DCHECK_GT(object_size, 0);
DCHECK_LE(object_address + object_size, previous_allocation_end);
object_address += object_size;
}
}
#endif
Address address; Address address;
HeapObject obj; HeapObject obj;
// TODO(steveblackburn) Note that the third party heap allocates objects // TODO(steveblackburn) Note that the third party heap allocates objects
...@@ -80,9 +96,9 @@ Address DeserializerAllocator::Allocate(SnapshotSpace space, int size) { ...@@ -80,9 +96,9 @@ Address DeserializerAllocator::Allocate(SnapshotSpace space, int size) {
// abstracting away the details of the memory allocator from this code. // abstracting away the details of the memory allocator from this code.
// At each allocation, the regular allocator performs allocation, // At each allocation, the regular allocator performs allocation,
// and a fixed-sized table is used to track and fix all back references. // and a fixed-sized table is used to track and fix all back references.
if (V8_ENABLE_THIRD_PARTY_HEAP_BOOL) return AllocateRaw(space, size); if (V8_ENABLE_THIRD_PARTY_HEAP_BOOL) {
address = AllocateRaw(space, size);
if (next_alignment_ != kWordAligned) { } else if (next_alignment_ != kWordAligned) {
const int reserved = size + Heap::GetMaximumFillToAlign(next_alignment_); const int reserved = size + Heap::GetMaximumFillToAlign(next_alignment_);
address = AllocateRaw(space, reserved); address = AllocateRaw(space, reserved);
obj = HeapObject::FromAddress(address); obj = HeapObject::FromAddress(address);
...@@ -95,10 +111,16 @@ Address DeserializerAllocator::Allocate(SnapshotSpace space, int size) { ...@@ -95,10 +111,16 @@ Address DeserializerAllocator::Allocate(SnapshotSpace space, int size) {
obj = Heap::AlignWithFiller(roots_, obj, size, reserved, next_alignment_); obj = Heap::AlignWithFiller(roots_, obj, size, reserved, next_alignment_);
address = obj.address(); address = obj.address();
next_alignment_ = kWordAligned; next_alignment_ = kWordAligned;
return address;
} else { } else {
return AllocateRaw(space, size); address = AllocateRaw(space, size);
} }
#ifdef DEBUG
previous_allocation_start_ = address;
previous_allocation_size_ = size;
#endif
return address;
} }
void DeserializerAllocator::MoveToNextChunk(SnapshotSpace space) { void DeserializerAllocator::MoveToNextChunk(SnapshotSpace space) {
......
...@@ -73,6 +73,12 @@ class DeserializerAllocator final { ...@@ -73,6 +73,12 @@ class DeserializerAllocator final {
uint32_t current_chunk_[kNumberOfPreallocatedSpaces]; uint32_t current_chunk_[kNumberOfPreallocatedSpaces];
Address high_water_[kNumberOfPreallocatedSpaces]; Address high_water_[kNumberOfPreallocatedSpaces];
#ifdef DEBUG
// Record the previous object allocated for DCHECKs.
Address previous_allocation_start_ = kNullAddress;
int previous_allocation_size_ = 0;
#endif
// The alignment of the next allocation. // The alignment of the next allocation.
AllocationAlignment next_alignment_ = kWordAligned; AllocationAlignment next_alignment_ = kWordAligned;
......
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