Commit b804a54b authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Fix ObjectSizeTrait

HeapObjectHeader::GetSize returns object size including
HeapObjectHeader. This is find for our internal usages since we want to
know the actual size consumed by the object.
ObjectSizeTrait should report object size for external users for which
the HeapObjectHeader should be invisible. The sizes returned by the
trait should exclude the header.

Bug: chromium:1056170
Change-Id: I75111b9a3d0d27d0a39df4abdacaa84f1cee3a5a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2692689
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Auto-Submit: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72723}
parent f5305393
......@@ -72,6 +72,9 @@ class HeapObjectHeader {
inline size_t GetSize() const;
inline void SetSize(size_t size);
template <AccessMode mode = AccessMode::kNonAtomic>
inline size_t PayloadSize() const;
template <AccessMode mode = AccessMode::kNonAtomic>
inline bool IsLargeObject() const;
......@@ -201,6 +204,11 @@ void HeapObjectHeader::SetSize(size_t size) {
encoded_low_ |= EncodeSize(size);
}
template <AccessMode mode>
size_t HeapObjectHeader::PayloadSize() const {
return GetSize<mode>() - sizeof(HeapObjectHeader);
}
template <AccessMode mode>
bool HeapObjectHeader::IsLargeObject() const {
return GetSize<mode>() == kLargeObjectSizeInHeader;
......
......@@ -199,8 +199,7 @@ LargePage* LargePage::Create(PageBackend* page_backend, LargePageSpace* space,
void* memory = page_backend->AllocateLargePageMemory(allocation_size);
LargePage* page = new (memory) LargePage(heap, space, size);
page->SynchronizedStore();
page->heap()->stats_collector()->NotifyAllocatedMemory(
AllocationSize(page->PayloadSize()));
page->heap()->stats_collector()->NotifyAllocatedMemory(allocation_size);
return page;
}
......
......@@ -17,7 +17,7 @@ size_t BaseObjectSizeTrait::GetObjectSizeForGarbageCollected(
return header.IsLargeObject()
? static_cast<const LargePage*>(BasePage::FromPayload(&header))
->PayloadSize()
: header.GetSize();
: header.PayloadSize();
}
// static
......@@ -29,7 +29,7 @@ size_t BaseObjectSizeTrait::GetObjectSizeForGarbageCollectedMixin(
BasePage::FromPayload(address)
->ObjectHeaderFromInnerAddress<AccessMode::kAtomic>(address);
DCHECK(!header.IsLargeObject());
return header.GetSize();
return header.PayloadSize();
}
} // namespace internal
......
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