@@ -34,17 +34,45 @@ 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<std::false_type, std::false_type>(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<std::false_type, std::true_type>(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<std::true_type, std::false_type>(base, ptr, gc, owningObj);
59
+ }
60
+ inline void
61
+ setNonNull (PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj) {
62
+ setImpl<std::true_type, std::true_type>(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
+ // / Implementation details shared by all set* functions here.
71
+ // / \tparam MaybeLargeObj Whether the owning object supports large allocation.
72
+ // / If it is false, \p owningObj is not used by the writer barriers.
73
+ // / \tparam NonNull Whether \p is non null.
74
+ template <typename MaybeLargeObj, typename NonNull>
75
+ void setImpl (PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj);
48
76
};
49
77
50
78
// / A class to represent "raw" pointers to heap objects. Disallows assignment,
@@ -86,7 +114,8 @@ class GCPointer : public GCPointerBase {
86
114
return vmcast<T>(GCPointerBase::getNonNull (base));
87
115
}
88
116
89
- // / Assign a new value to this GCPointer.
117
+ // / Assign a new value to this GCPointer. This must not be used if it lives in
118
+ // / an object that supports large allocation.
90
119
// / \param base The base of ptr.
91
120
// / \param ptr The memory being pointed to.
92
121
// / \param gc Used for write barriers.
@@ -97,6 +126,18 @@ class GCPointer : public GCPointerBase {
97
126
GCPointerBase::setNonNull (base, ptr, gc);
98
127
}
99
128
129
+ // / Assign a new value to this GCPointer.
130
+ // / \param ptr The memory being pointed to.
131
+ // / \param gc Used for write barriers.
132
+ // / \param owningObj The object that contains this GCPointer, used by the
133
+ // / writer barriers.
134
+ void set (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) {
135
+ GCPointerBase::set (base, ptr, gc, owningObj);
136
+ }
137
+ void setNonNull (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) {
138
+ GCPointerBase::setNonNull (base, ptr, gc, owningObj);
139
+ }
140
+
100
141
// / Convenience overload of GCPointer::set for other GCPointers.
101
142
void set (PointerBase &base, const GCPointer<T> &ptr, GC &gc) {
102
143
GCPointerBase::set (base, ptr, gc);
0 commit comments