Skip to content

Commit c5040b7

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 5167da4 commit c5040b7

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

include/hermes/VM/GCPointer-inline.h

+13
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ inline void GCPointerBase::setNonNull(
8484
setNoBarrier(CompressedPointer::encodeNonNull(ptr, base));
8585
}
8686

87+
inline void GCPointerBase::set(
88+
PointerBase &base,
89+
CompressedPointer ptr,
90+
GC &gc,
91+
const GCCell *owningObj) {
92+
assert(
93+
(!ptr || gc.validPointer(ptr.get(base))) &&
94+
"Cannot set a GCPointer to an invalid pointer");
95+
// Write barrier must happen before the write.
96+
gc.writeBarrierForLargeObj(owningObj, this, ptr.get(base));
97+
setNoBarrier(ptr);
98+
}
99+
87100
inline void GCPointerBase::setNull(GC &gc) {
88101
gc.snapshotWriteBarrier(this);
89102
setNoBarrier(CompressedPointer(nullptr));

include/hermes/VM/GCPointer.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class GCPointerBase : public CompressedPointer {
5151
/// writer barriers.
5252
inline void
5353
set(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj);
54+
inline void set(
55+
PointerBase &base,
56+
CompressedPointer ptr,
57+
GC &gc,
58+
const GCCell *owningObj);
5459
inline void
5560
setNonNull(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj);
5661

@@ -122,10 +127,21 @@ class GCPointer : public GCPointerBase {
122127
GCPointerBase::setNonNull(base, ptr, gc, owningObj);
123128
}
124129

125-
/// Convenience overload of GCPointer::set for other GCPointers.
130+
/// Convenience overload of GCPointer::set for other GCPointers. This must not
131+
/// be used if it lives in an object that supports large allocation.
126132
void set(PointerBase &base, const GCPointer<T> &ptr, GC &gc) {
127133
GCPointerBase::set(base, ptr, gc);
128134
}
135+
136+
/// Convenience overload of GCPointer::set for other GCPointers. \p owningObj
137+
/// is used by the writer barriers.
138+
void set(
139+
PointerBase &base,
140+
const GCPointer<T> &ptr,
141+
GC &gc,
142+
const GCCell *owningObj) {
143+
GCPointerBase::set(base, ptr, gc, owningObj);
144+
}
129145
};
130146

131147
} // namespace vm

0 commit comments

Comments
 (0)