cppgc: Add same thread check for Members and Persistents
Bug: chromium:1056170 Change-Id: I0876d1977694c50995a7b97145748bdb365289ad Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3194266 Commit-Queue: Omer Katz <omerkatz@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Cr-Commit-Position: refs/heads/main@{#77162}
This commit is contained in:
parent
2cbcf6e089
commit
ea2723c9ec
@ -51,7 +51,7 @@ struct NoWriteBarrierPolicy {
|
||||
static void AssigningBarrier(const void*, const void*) {}
|
||||
};
|
||||
|
||||
class V8_EXPORT EnabledCheckingPolicyBase {
|
||||
class V8_EXPORT SameThreadEnabledCheckingPolicyBase {
|
||||
protected:
|
||||
void CheckPointerImpl(const void* ptr, bool points_to_payload,
|
||||
bool check_off_heap_assignments);
|
||||
@ -60,7 +60,8 @@ class V8_EXPORT EnabledCheckingPolicyBase {
|
||||
};
|
||||
|
||||
template <bool kCheckOffHeapAssignments>
|
||||
class V8_EXPORT EnabledCheckingPolicy : private EnabledCheckingPolicyBase {
|
||||
class V8_EXPORT SameThreadEnabledCheckingPolicy
|
||||
: private SameThreadEnabledCheckingPolicyBase {
|
||||
protected:
|
||||
template <typename T>
|
||||
void CheckPointer(const T* ptr) {
|
||||
@ -72,14 +73,14 @@ class V8_EXPORT EnabledCheckingPolicy : private EnabledCheckingPolicyBase {
|
||||
private:
|
||||
template <typename T, bool = IsCompleteV<T>>
|
||||
struct CheckPointersImplTrampoline {
|
||||
static void Call(EnabledCheckingPolicy* policy, const T* ptr) {
|
||||
static void Call(SameThreadEnabledCheckingPolicy* policy, const T* ptr) {
|
||||
policy->CheckPointerImpl(ptr, false, kCheckOffHeapAssignments);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct CheckPointersImplTrampoline<T, true> {
|
||||
static void Call(EnabledCheckingPolicy* policy, const T* ptr) {
|
||||
static void Call(SameThreadEnabledCheckingPolicy* policy, const T* ptr) {
|
||||
policy->CheckPointerImpl(ptr, IsGarbageCollectedTypeV<T>,
|
||||
kCheckOffHeapAssignments);
|
||||
}
|
||||
@ -95,9 +96,9 @@ class DisabledCheckingPolicy {
|
||||
// Off heap members are not connected to object graph and thus cannot ressurect
|
||||
// dead objects.
|
||||
using DefaultMemberCheckingPolicy =
|
||||
EnabledCheckingPolicy<false /* kCheckOffHeapAssignments*/>;
|
||||
SameThreadEnabledCheckingPolicy<false /* kCheckOffHeapAssignments*/>;
|
||||
using DefaultPersistentCheckingPolicy =
|
||||
EnabledCheckingPolicy<true /* kCheckOffHeapAssignments*/>;
|
||||
SameThreadEnabledCheckingPolicy<true /* kCheckOffHeapAssignments*/>;
|
||||
#else
|
||||
using DefaultMemberCheckingPolicy = DisabledCheckingPolicy;
|
||||
using DefaultPersistentCheckingPolicy = DisabledCheckingPolicy;
|
||||
|
@ -206,6 +206,8 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
|
||||
stats_collector_->SetMetricRecorder(std::move(histogram_recorder));
|
||||
}
|
||||
|
||||
int GetCreationThreadId() const { return creation_thread_id_; }
|
||||
|
||||
protected:
|
||||
// Used by the incremental scheduler to finalize a GC if supported.
|
||||
virtual void FinalizeIncrementalGarbageCollectionIfNeeded(
|
||||
@ -270,6 +272,8 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
|
||||
|
||||
bool in_atomic_pause_ = false;
|
||||
|
||||
int creation_thread_id_ = v8::base::OS::GetCurrentThreadId();
|
||||
|
||||
friend class MarkerBase::IncrementalMarkingTask;
|
||||
friend class testing::TestWithHeap;
|
||||
friend class cppgc::subtle::DisallowGarbageCollectionScope;
|
||||
|
@ -30,7 +30,7 @@ bool IsOnStack(const void* address) {
|
||||
|
||||
} // namespace
|
||||
|
||||
void EnabledCheckingPolicyBase::CheckPointerImpl(
|
||||
void SameThreadEnabledCheckingPolicyBase::CheckPointerImpl(
|
||||
const void* ptr, bool points_to_payload, bool check_off_heap_assignments) {
|
||||
// `ptr` must not reside on stack.
|
||||
DCHECK(!IsOnStack(ptr));
|
||||
@ -56,6 +56,8 @@ void EnabledCheckingPolicyBase::CheckPointerImpl(
|
||||
// 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user