Loading...
Searching...
No Matches
liveness-broker.h
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_CPPGC_LIVENESS_BROKER_H_
6#define INCLUDE_CPPGC_LIVENESS_BROKER_H_
7
8#include "cppgc/heap.h"
9#include "cppgc/member.h"
11#include "cppgc/trace-trait.h"
12#include "v8config.h" // NOLINT(build/include_directory)
13
14namespace cppgc {
15
16namespace internal {
17class LivenessBrokerFactory;
18} // namespace internal
19
45 public:
46 template <typename T>
47 bool IsHeapObjectAlive(const T* object) const {
48 // - nullptr objects are considered alive to allow weakness to be used from
49 // stack while running into a conservative GC. Treating nullptr as dead
50 // would mean that e.g. custom collections could not be strongified on
51 // stack.
52 // - Sentinel pointers are also preserved in weakness and not cleared.
53 return !object || object == kSentinelPointer ||
54 IsHeapObjectAliveImpl(
55 TraceTrait<T>::GetTraceDescriptor(object).base_object_payload);
56 }
57
58 template <typename T>
59 bool IsHeapObjectAlive(const WeakMember<T>& weak_member) const {
60 return IsHeapObjectAlive<T>(weak_member.Get());
61 }
62
63 template <typename T>
64 bool IsHeapObjectAlive(const UntracedMember<T>& untraced_member) const {
65 return IsHeapObjectAlive<T>(untraced_member.Get());
66 }
67
68 private:
69 LivenessBroker() = default;
70
71 bool IsHeapObjectAliveImpl(const void*) const;
72
73 friend class internal::LivenessBrokerFactory;
74};
75
76} // namespace cppgc
77
78#endif // INCLUDE_CPPGC_LIVENESS_BROKER_H_
Definition: liveness-broker.h:44
bool IsHeapObjectAlive(const T *object) const
Definition: liveness-broker.h:47
bool IsHeapObjectAlive(const WeakMember< T > &weak_member) const
Definition: liveness-broker.h:59
bool IsHeapObjectAlive(const UntracedMember< T > &untraced_member) const
Definition: liveness-broker.h:64
Definition: member.h:78
T * Get() const
Definition: member.h:264
Definition: allocation.h:38
constexpr internal::SentinelPointer kSentinelPointer
Definition: sentinel-pointer.h:35
Definition: trace-trait.h:105
#define V8_EXPORT
Definition: v8config.h:762