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

cppgc: Fix ObjectSizeTrait

LargePage::PayloadSize inclues the heap object header.
Keeping PayloadSize as is to keep it aligned with
NormalPage::PayloadSize and introducing LargePage::ObjectSize as the
counterpart for HeapObjectHeader::ObjectSize that will exclude the
header.

Bug: chromium:1056170
Change-Id: I8a5f50841fd9dbd6c9a4a4035d9040021944cacc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2731533Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73154}
parent 50ee1407
......@@ -73,7 +73,7 @@ class HeapObjectHeader {
inline void SetSize(size_t size);
template <AccessMode mode = AccessMode::kNonAtomic>
inline size_t PayloadSize() const;
inline size_t ObjectSize() const;
template <AccessMode mode = AccessMode::kNonAtomic>
inline bool IsLargeObject() const;
......@@ -205,7 +205,7 @@ void HeapObjectHeader::SetSize(size_t size) {
}
template <AccessMode mode>
size_t HeapObjectHeader::PayloadSize() const {
size_t HeapObjectHeader::ObjectSize() const {
return GetSize<mode>() - sizeof(HeapObjectHeader);
}
......
......@@ -210,6 +210,7 @@ class V8_EXPORT_PRIVATE LargePage final : public BasePage {
ConstAddress PayloadEnd() const;
size_t PayloadSize() const { return payload_size_; }
size_t ObjectSize() const { return payload_size_ - sizeof(HeapObjectHeader); }
bool PayloadContains(ConstAddress address) const {
return (PayloadStart() <= address) && (address < PayloadEnd());
......
......@@ -16,8 +16,8 @@ size_t BaseObjectSizeTrait::GetObjectSizeForGarbageCollected(
const auto& header = HeapObjectHeader::FromPayload(object);
return header.IsLargeObject()
? static_cast<const LargePage*>(BasePage::FromPayload(&header))
->PayloadSize()
: header.PayloadSize();
->ObjectSize()
: header.ObjectSize();
}
// static
......@@ -29,7 +29,7 @@ size_t BaseObjectSizeTrait::GetObjectSizeForGarbageCollectedMixin(
BasePage::FromPayload(address)
->ObjectHeaderFromInnerAddress<AccessMode::kAtomic>(address);
DCHECK(!header.IsLargeObject());
return header.PayloadSize();
return header.ObjectSize();
}
} // 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