@@ -27,21 +27,46 @@ class GCPointerBase : public CompressedPointer {
27
27
template <typename NeedsBarriers>
28
28
inline GCPointerBase (PointerBase &base, GCCell *ptr, GC &gc, NeedsBarriers);
29
29
30
+ template <typename NeedsBarriers>
31
+ inline GCPointerBase (
32
+ PointerBase &base,
33
+ GCCell *ptr,
34
+ GC &gc,
35
+ const GCCell *owningObj,
36
+ NeedsBarriers);
37
+
30
38
public:
31
39
// These classes are used as arguments to GCPointer constructors, to
32
40
// indicate whether write barriers are necessary in initializing the
33
41
// GCPointer.
34
42
class NoBarriers : public std ::false_type {};
35
43
class YesBarriers : public std ::true_type {};
36
44
37
- // / This must be used to assign a new value to this GCPointer.
45
+ // / This must be used to assign a new value to this GCPointer. This must not
46
+ // / be used if it lives in an object that supports large allocation.
38
47
// / \param ptr The memory being pointed to.
39
48
// / \param base The base of ptr.
40
49
// / \param gc Used for write barriers.
41
50
inline void set (PointerBase &base, GCCell *ptr, GC &gc);
42
51
inline void set (PointerBase &base, CompressedPointer ptr, GC &gc);
43
52
inline void setNonNull (PointerBase &base, GCCell *ptr, GC &gc);
44
53
54
+ // / This must be used to assign a new value to this GCPointer.
55
+ // / \param ptr The memory being pointed to.
56
+ // / \param base The base of ptr.
57
+ // / \param gc Used for write barriers.
58
+ // / \param owningObj The object that contains this GCPointer, used by the
59
+ // / writer barriers.
60
+ inline void
61
+ set (PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj);
62
+ inline void set (
63
+ PointerBase &base,
64
+ CompressedPointer ptr,
65
+ GC &gc,
66
+ const GCCell *owningObj);
67
+ inline void
68
+ setNonNull (PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj);
69
+
45
70
// / Set this pointer to null. This needs a write barrier in some types of
46
71
// / garbage collectors.
47
72
inline void setNull (GC &gc);
@@ -64,12 +89,26 @@ class GCPointer : public GCPointerBase {
64
89
template <typename NeedsBarriers>
65
90
GCPointer (PointerBase &base, T *ptr, GC &gc, NeedsBarriers needsBarriers)
66
91
: GCPointerBase(base, ptr, gc, needsBarriers) {}
92
+ // / Pass the owning object pointer to perform barriers when the object
93
+ // / supports large allocation.
94
+ template <typename NeedsBarriers>
95
+ GCPointer (
96
+ PointerBase &base,
97
+ T *ptr,
98
+ GC &gc,
99
+ const GCCell *owningObj,
100
+ NeedsBarriers needsBarriers)
101
+ : GCPointerBase(base, ptr, gc, owningObj, needsBarriers) {}
67
102
68
103
// / Same as the constructor above, with the default for
69
104
// / NeedsBarriers as "YesBarriers". (We can't use default template
70
105
// / arguments with the idiom used above.)
71
- inline GCPointer (PointerBase &base, T *ptr, GC &gc)
106
+ GCPointer (PointerBase &base, T *ptr, GC &gc)
72
107
: GCPointer<T>(base, ptr, gc, YesBarriers()) {}
108
+ // / Pass the owning object pointer to perform barriers when the object
109
+ // / supports large allocation.
110
+ GCPointer (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj)
111
+ : GCPointer<T>(base, ptr, gc, owningObj, YesBarriers()) {}
73
112
74
113
// / We are not allowed to copy-construct or assign GCPointers.
75
114
GCPointer (const GCPointerBase &) = delete ;
@@ -86,7 +125,8 @@ class GCPointer : public GCPointerBase {
86
125
return vmcast<T>(GCPointerBase::getNonNull (base));
87
126
}
88
127
89
- // / Assign a new value to this GCPointer.
128
+ // / Assign a new value to this GCPointer. This must not be used if it lives in
129
+ // / an object that supports large allocation.
90
130
// / \param base The base of ptr.
91
131
// / \param ptr The memory being pointed to.
92
132
// / \param gc Used for write barriers.
@@ -97,10 +137,33 @@ class GCPointer : public GCPointerBase {
97
137
GCPointerBase::setNonNull (base, ptr, gc);
98
138
}
99
139
100
- // / Convenience overload of GCPointer::set for other GCPointers.
140
+ // / Assign a new value to this GCPointer.
141
+ // / \param ptr The memory being pointed to.
142
+ // / \param gc Used for write barriers.
143
+ // / \param owningObj The object that contains this GCPointer, used by the
144
+ // / writer barriers.
145
+ void set (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) {
146
+ GCPointerBase::set (base, ptr, gc, owningObj);
147
+ }
148
+ void setNonNull (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) {
149
+ GCPointerBase::setNonNull (base, ptr, gc, owningObj);
150
+ }
151
+
152
+ // / Convenience overload of GCPointer::set for other GCPointers. This must not
153
+ // / be used if it lives in an object that supports large allocation.
101
154
void set (PointerBase &base, const GCPointer<T> &ptr, GC &gc) {
102
155
GCPointerBase::set (base, ptr, gc);
103
156
}
157
+
158
+ // / Convenience overload of GCPointer::set for other GCPointers. \p owningObj
159
+ // / is used by the writer barriers.
160
+ void set (
161
+ PointerBase &base,
162
+ const GCPointer<T> &ptr,
163
+ GC &gc,
164
+ const GCCell *owningObj) {
165
+ GCPointerBase::set (base, ptr, gc, owningObj);
166
+ }
104
167
};
105
168
106
169
} // namespace vm
0 commit comments