diff --git a/src/heap/cppgc/object-size-trait.cc b/src/heap/cppgc/object-size-trait.cc index 7b82239a61..000b8eef9d 100644 --- a/src/heap/cppgc/object-size-trait.cc +++ b/src/heap/cppgc/object-size-trait.cc @@ -14,7 +14,8 @@ namespace internal { // static size_t BaseObjectSizeTrait::GetObjectSizeForGarbageCollected( const void* object) { - return ObjectView(HeapObjectHeader::FromObject(object)).Size(); + return ObjectView(HeapObjectHeader::FromObject(object)) + .Size(); } // static @@ -26,7 +27,7 @@ size_t BaseObjectSizeTrait::GetObjectSizeForGarbageCollectedMixin( BasePage::FromPayload(address) ->ObjectHeaderFromInnerAddress(address); DCHECK(!header.IsLargeObject()); - return header.ObjectSize(); + return header.ObjectSize(); } } // namespace internal diff --git a/src/heap/cppgc/object-view.h b/src/heap/cppgc/object-view.h index e83145cc31..98b378c5ac 100644 --- a/src/heap/cppgc/object-view.h +++ b/src/heap/cppgc/object-view.h @@ -6,6 +6,7 @@ #define V8_HEAP_CPPGC_OBJECT_VIEW_H_ #include "include/v8config.h" +#include "src/heap/cppgc/globals.h" #include "src/heap/cppgc/heap-object-header.h" #include "src/heap/cppgc/heap-page.h" @@ -20,6 +21,7 @@ class ObjectView final { V8_INLINE Address Start() const; V8_INLINE ConstAddress End() const; + template V8_INLINE size_t Size() const; private: @@ -43,9 +45,10 @@ ConstAddress ObjectView::End() const { : header_.ObjectEnd(); } +template size_t ObjectView::Size() const { return is_large_object_ ? LargePage::From(base_page_)->ObjectSize() - : header_.ObjectSize(); + : header_.ObjectSize(); } } // namespace internal