summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/cppgc/pointer-policies.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/heap/cppgc/pointer-policies.cc')
-rw-r--r--deps/v8/src/heap/cppgc/pointer-policies.cc38
1 files changed, 23 insertions, 15 deletions
diff --git a/deps/v8/src/heap/cppgc/pointer-policies.cc b/deps/v8/src/heap/cppgc/pointer-policies.cc
index 3c7cb61761..b50f96d70e 100644
--- a/deps/v8/src/heap/cppgc/pointer-policies.cc
+++ b/deps/v8/src/heap/cppgc/pointer-policies.cc
@@ -30,8 +30,8 @@ bool IsOnStack(const void* address) {
} // namespace
-void EnabledCheckingPolicy::CheckPointerImpl(const void* ptr,
- bool points_to_payload) {
+void SameThreadEnabledCheckingPolicyBase::CheckPointerImpl(
+ const void* ptr, bool points_to_payload, bool check_off_heap_assignments) {
// `ptr` must not reside on stack.
DCHECK(!IsOnStack(ptr));
auto* base_page = BasePage::FromPayload(ptr);
@@ -41,12 +41,14 @@ void EnabledCheckingPolicy::CheckPointerImpl(const void* ptr,
// References cannot change their heap association which means that state is
// immutable once it is set.
+ bool is_on_heap = true;
if (!heap_) {
heap_ = &base_page->heap();
if (!heap_->page_backend()->Lookup(reinterpret_cast<Address>(this))) {
// If `this` is not contained within the heap of `ptr`, we must deal with
// an on-stack or off-heap reference. For both cases there should be no
// heap registered.
+ is_on_heap = false;
CHECK(!HeapRegistry::TryFromManagedPointer(this));
}
}
@@ -54,6 +56,8 @@ void EnabledCheckingPolicy::CheckPointerImpl(const void* ptr,
// Member references should never mix heaps.
DCHECK_EQ(heap_, &base_page->heap());
+ DCHECK_EQ(heap_->GetCreationThreadId(), v8::base::OS::GetCurrentThreadId());
+
// Header checks.
const HeapObjectHeader* header = nullptr;
if (points_to_payload) {
@@ -68,20 +72,24 @@ void EnabledCheckingPolicy::CheckPointerImpl(const void* ptr,
DCHECK(!header->IsFree());
}
-#ifdef CPPGC_CHECK_ASSIGNMENTS_IN_PREFINALIZERS
- if (heap_->prefinalizer_handler()->IsInvokingPreFinalizers()) {
- // During prefinalizers invocation, check that |ptr| refers to a live object
- // and that it is assigned to a live slot.
- DCHECK(header->IsMarked());
- // Slot can be in a large object.
- const auto* slot_page = BasePage::FromInnerAddress(heap_, this);
- // Off-heap slots (from other heaps or on-stack) are considered live.
- bool slot_is_live =
- !slot_page || slot_page->ObjectHeaderFromInnerAddress(this).IsMarked();
- DCHECK(slot_is_live);
- USE(slot_is_live);
+#ifdef CPPGC_VERIFY_HEAP
+ if (check_off_heap_assignments || is_on_heap) {
+ if (heap_->prefinalizer_handler()->IsInvokingPreFinalizers()) {
+ // Slot can be in a large object.
+ const auto* slot_page = BasePage::FromInnerAddress(heap_, this);
+ // Off-heap slots (from other heaps or on-stack) are considered live.
+ bool slot_is_live =
+ !slot_page ||
+ slot_page->ObjectHeaderFromInnerAddress(this).IsMarked();
+ // During prefinalizers invocation, check that if the slot is live then
+ // |ptr| refers to a live object.
+ DCHECK_IMPLIES(slot_is_live, header->IsMarked());
+ USE(slot_is_live);
+ }
}
-#endif // CPPGC_CHECK_ASSIGNMENTS_IN_PREFINALIZERS
+#else
+ USE(is_on_heap);
+#endif // CPPGC_VERIFY_HEAP
}
PersistentRegion& StrongPersistentPolicy::GetPersistentRegion(