Skip to content

Commit a53dfaa

Browse files
lavenzgfacebook-github-bot
authored andcommitted
Pass the pointer of owning object in GCPointer::set() part II (#1509)
Summary: Pull Request resolved: #1509 Differential Revision: D62227030
1 parent f12ade4 commit a53dfaa

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

include/hermes/VM/GCPointer-inline.h

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ GCPointerBase::set(PointerBase &base, CompressedPointer ptr, GC &gc) {
7171
setNoBarrier(ptr);
7272
}
7373

74+
inline void GCPointerBase::set(
75+
PointerBase &base,
76+
CompressedPointer ptr,
77+
GC &gc,
78+
const GCCell *owningObj) {
79+
assert(
80+
(!ptr || gc.validPointer(ptr.get(base))) &&
81+
"Cannot set a GCPointer to an invalid pointer");
82+
// Write barrier must happen before the write.
83+
(void)owningObj;
84+
gc.writeBarrier(this, ptr.get(base));
85+
setNoBarrier(ptr);
86+
}
87+
7488
inline void GCPointerBase::setNull(GC &gc) {
7589
gc.snapshotWriteBarrier(this);
7690
setNoBarrier(CompressedPointer(nullptr));

include/hermes/VM/GCPointer.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class GCPointerBase : public CompressedPointer {
5757
set(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj) {
5858
setImpl<MaybeLargeObj::Yes, NonNull::No>(base, ptr, gc, owningObj);
5959
}
60+
inline void set(
61+
PointerBase &base,
62+
CompressedPointer ptr,
63+
GC &gc,
64+
const GCCell *owningObj);
6065
inline void
6166
setNonNull(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj) {
6267
setImpl<MaybeLargeObj::Yes, NonNull::Yes>(base, ptr, gc, owningObj);
@@ -140,10 +145,21 @@ class GCPointer : public GCPointerBase {
140145
GCPointerBase::setNonNull(base, ptr, gc, owningObj);
141146
}
142147

143-
/// Convenience overload of GCPointer::set for other GCPointers.
148+
/// Convenience overload of GCPointer::set for other GCPointers. This must not
149+
/// be used if it lives in an object that supports large allocation.
144150
void set(PointerBase &base, const GCPointer<T> &ptr, GC &gc) {
145151
GCPointerBase::set(base, ptr, gc);
146152
}
153+
154+
/// Convenience overload of GCPointer::set for other GCPointers. \p owningObj
155+
/// is used by the writer barriers.
156+
void set(
157+
PointerBase &base,
158+
const GCPointer<T> &ptr,
159+
GC &gc,
160+
const GCCell *owningObj) {
161+
GCPointerBase::set(base, ptr, gc, owningObj);
162+
}
147163
};
148164

149165
} // namespace vm

0 commit comments

Comments
 (0)