@@ -34,17 +34,47 @@ class GCPointerBase : public CompressedPointer {
34
34
class NoBarriers : public std ::false_type {};
35
35
class YesBarriers : public std ::true_type {};
36
36
37
- // / This must be used to assign a new value to this GCPointer.
37
+ // / This must be used to assign a new value to this GCPointer. This must not
38
+ // / be used if it lives in an object that supports large allocation.
38
39
// / \param ptr The memory being pointed to.
39
40
// / \param base The base of ptr.
40
41
// / \param gc Used for write barriers.
41
- inline void set (PointerBase &base, GCCell *ptr, GC &gc);
42
+ inline void set (PointerBase &base, GCCell *ptr, GC &gc) {
43
+ setImpl<MaybeLargeObj::No, NonNull::No>(base, ptr, gc, nullptr );
44
+ }
42
45
inline void set (PointerBase &base, CompressedPointer ptr, GC &gc);
43
- inline void setNonNull (PointerBase &base, GCCell *ptr, GC &gc);
46
+ inline void setNonNull (PointerBase &base, GCCell *ptr, GC &gc) {
47
+ setImpl<MaybeLargeObj::No, NonNull::Yes>(base, ptr, gc, nullptr );
48
+ }
49
+
50
+ // / This must be used to assign a new value to this GCPointer.
51
+ // / \param ptr The memory being pointed to.
52
+ // / \param base The base of ptr.
53
+ // / \param gc Used for write barriers.
54
+ // / \param owningObj The object that contains this GCPointer, used by the
55
+ // / writer barriers.
56
+ inline void
57
+ set (PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj) {
58
+ setImpl<MaybeLargeObj::Yes, NonNull::No>(base, ptr, gc, owningObj);
59
+ }
60
+ inline void
61
+ setNonNull (PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj) {
62
+ setImpl<MaybeLargeObj::Yes, NonNull::Yes>(base, ptr, gc, owningObj);
63
+ }
44
64
45
65
// / Set this pointer to null. This needs a write barrier in some types of
46
66
// / garbage collectors.
47
67
inline void setNull (GC &gc);
68
+
69
+ private:
70
+ enum class MaybeLargeObj { No = 0 , Yes };
71
+ enum class NonNull { No = 0 , Yes };
72
+ // / Implementation details shared by all set* functions here.
73
+ // / \tparam maybeLargeObj Whether the owning object supports large allocation.
74
+ // / If it is false, \p owningObj is not used by the writer barriers.
75
+ // / \tparam nonNull Whether \p is non null.
76
+ template <MaybeLargeObj maybeLargeObj, NonNull nonNull>
77
+ void setImpl (PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj);
48
78
};
49
79
50
80
// / A class to represent "raw" pointers to heap objects. Disallows assignment,
@@ -86,7 +116,8 @@ class GCPointer : public GCPointerBase {
86
116
return vmcast<T>(GCPointerBase::getNonNull (base));
87
117
}
88
118
89
- // / Assign a new value to this GCPointer.
119
+ // / Assign a new value to this GCPointer. This must not be used if it lives in
120
+ // / an object that supports large allocation.
90
121
// / \param base The base of ptr.
91
122
// / \param ptr The memory being pointed to.
92
123
// / \param gc Used for write barriers.
@@ -97,6 +128,18 @@ class GCPointer : public GCPointerBase {
97
128
GCPointerBase::setNonNull (base, ptr, gc);
98
129
}
99
130
131
+ // / Assign a new value to this GCPointer.
132
+ // / \param ptr The memory being pointed to.
133
+ // / \param gc Used for write barriers.
134
+ // / \param owningObj The object that contains this GCPointer, used by the
135
+ // / writer barriers.
136
+ void set (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) {
137
+ GCPointerBase::set (base, ptr, gc, owningObj);
138
+ }
139
+ void setNonNull (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) {
140
+ GCPointerBase::setNonNull (base, ptr, gc, owningObj);
141
+ }
142
+
100
143
// / Convenience overload of GCPointer::set for other GCPointers.
101
144
void set (PointerBase &base, const GCPointer<T> &ptr, GC &gc) {
102
145
GCPointerBase::set (base, ptr, gc);
0 commit comments