cppgc: Make ObjectSizeTrait::GetSize atomic

ObjectSizeTrait::GetSize is used by Trace methods in Blink and may be
called while concurrent marking is active. The current version is
non-atmoic and therefore can race with marking on other threads.

Bug: chromium:1261860
Change-Id: Ia0b41ec496ac64ae3dd5a040b25f6972b21561c5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3240832
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77527}
This commit is contained in:
Omer Katz 2021-10-25 14:39:34 +02:00 committed by V8 LUCI CQ
parent cf98260e46
commit 5fe0aa3bc7
2 changed files with 7 additions and 3 deletions

View File

@ -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<AccessMode::kAtomic>();
}
// static
@ -26,7 +27,7 @@ size_t BaseObjectSizeTrait::GetObjectSizeForGarbageCollectedMixin(
BasePage::FromPayload(address)
->ObjectHeaderFromInnerAddress<AccessMode::kAtomic>(address);
DCHECK(!header.IsLargeObject());
return header.ObjectSize();
return header.ObjectSize<AccessMode::kAtomic>();
}
} // namespace internal

View File

@ -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 <AccessMode = AccessMode::kNonAtomic>
V8_INLINE size_t Size() const;
private:
@ -43,9 +45,10 @@ ConstAddress ObjectView::End() const {
: header_.ObjectEnd();
}
template <AccessMode mode>
size_t ObjectView::Size() const {
return is_large_object_ ? LargePage::From(base_page_)->ObjectSize()
: header_.ObjectSize();
: header_.ObjectSize<mode>();
}
} // namespace internal