@@ -27,21 +27,53 @@ 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, which lives in
55
+ // / an object of kind that supports large allocation.
56
+ // / \param ptr The memory being pointed to.
57
+ // / \param base The base of ptr.
58
+ // / \param gc Used for write barriers.
59
+ // / \param owningObj The object that contains this GCPointer, used by the
60
+ // / writer barriers.
61
+ inline void setInLargeObj (
62
+ PointerBase &base,
63
+ GCCell *ptr,
64
+ GC &gc,
65
+ const GCCell *owningObj);
66
+ inline void setInLargeObj (
67
+ PointerBase &base,
68
+ CompressedPointer ptr,
69
+ GC &gc,
70
+ const GCCell *owningObj);
71
+ inline void setNonNullInLargeObj (
72
+ PointerBase &base,
73
+ GCCell *ptr,
74
+ GC &gc,
75
+ const GCCell *owningObj);
76
+
45
77
// / Set this pointer to null. This needs a write barrier in some types of
46
78
// / garbage collectors.
47
79
inline void setNull (GC &gc);
@@ -64,12 +96,26 @@ class GCPointer : public GCPointerBase {
64
96
template <typename NeedsBarriers>
65
97
GCPointer (PointerBase &base, T *ptr, GC &gc, NeedsBarriers needsBarriers)
66
98
: GCPointerBase(base, ptr, gc, needsBarriers) {}
99
+ // / Pass the owning object pointer to perform barriers when the object
100
+ // / supports large allocation.
101
+ template <typename NeedsBarriers>
102
+ GCPointer (
103
+ PointerBase &base,
104
+ T *ptr,
105
+ GC &gc,
106
+ const GCCell *owningObj,
107
+ NeedsBarriers needsBarriers)
108
+ : GCPointerBase(base, ptr, gc, owningObj, needsBarriers) {}
67
109
68
110
// / Same as the constructor above, with the default for
69
111
// / NeedsBarriers as "YesBarriers". (We can't use default template
70
112
// / arguments with the idiom used above.)
71
- inline GCPointer (PointerBase &base, T *ptr, GC &gc)
113
+ GCPointer (PointerBase &base, T *ptr, GC &gc)
72
114
: GCPointer<T>(base, ptr, gc, YesBarriers()) {}
115
+ // / Pass the owning object pointer to perform barriers when the object
116
+ // / supports large allocation.
117
+ GCPointer (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj)
118
+ : GCPointer<T>(base, ptr, gc, owningObj, YesBarriers()) {}
73
119
74
120
// / We are not allowed to copy-construct or assign GCPointers.
75
121
GCPointer (const GCPointerBase &) = delete ;
@@ -86,7 +132,8 @@ class GCPointer : public GCPointerBase {
86
132
return vmcast<T>(GCPointerBase::getNonNull (base));
87
133
}
88
134
89
- // / Assign a new value to this GCPointer.
135
+ // / Assign a new value to this GCPointer. This must not be used if it lives in
136
+ // / an object that supports large allocation.
90
137
// / \param base The base of ptr.
91
138
// / \param ptr The memory being pointed to.
92
139
// / \param gc Used for write barriers.
@@ -97,10 +144,40 @@ class GCPointer : public GCPointerBase {
97
144
GCPointerBase::setNonNull (base, ptr, gc);
98
145
}
99
146
100
- // / Convenience overload of GCPointer::set for other GCPointers.
147
+ // / Assign a new value to this GCPointer, which lives in an object of kind
148
+ // / that supports large allocation.
149
+ // / \param base The base of ptr.
150
+ // / \param ptr The memory being pointed to.
151
+ // / \param gc Used for write barriers.
152
+ // / \param owningObj The object that contains this GCPointer, used by the
153
+ // / writer barriers.
154
+ void
155
+ setInLargeObj (PointerBase &base, T *ptr, GC &gc, const GCCell *owningObj) {
156
+ GCPointerBase::set (base, ptr, gc, owningObj);
157
+ }
158
+ void setNonNullInLargeObj (
159
+ PointerBase &base,
160
+ T *ptr,
161
+ GC &gc,
162
+ const GCCell *owningObj) {
163
+ GCPointerBase::setNonNull (base, ptr, gc, owningObj);
164
+ }
165
+
166
+ // / Convenience overload of GCPointer::set for other GCPointers. This must not
167
+ // / be used if it lives in an object that supports large allocation.
101
168
void set (PointerBase &base, const GCPointer<T> &ptr, GC &gc) {
102
169
GCPointerBase::set (base, ptr, gc);
103
170
}
171
+
172
+ // / Convenience overload of GCPointer::set for other GCPointers. \p owningObj
173
+ // / is used by the writer barriers.
174
+ void setInLargeObj (
175
+ PointerBase &base,
176
+ const GCPointer<T> &ptr,
177
+ GC &gc,
178
+ const GCCell *owningObj) {
179
+ GCPointerBase::set (base, ptr, gc, owningObj);
180
+ }
104
181
};
105
182
106
183
} // namespace vm
0 commit comments