Skip to content

Commit

Permalink
Add owning cell to parameters of GCHermesValueBase::set()
Browse files Browse the repository at this point in the history
Differential Revision: D62196480
  • Loading branch information
lavenzg authored and facebook-github-bot committed Nov 22, 2024
1 parent e25d39f commit b8eee35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions include/hermes/VM/HermesValue-inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ inline void GCHermesValueBase<HVType>::set(HVType hv, GC &gc) {
HVType::setNoBarrier(hv);
}

template <typename HVType>
template <typename NeedsBarriers>
inline void
GCHermesValueBase<HVType>::set(HVType hv, GC &gc, const GCCell *owningObj) {
if (hv.isPointer()) {
HERMES_SLOW_ASSERT(
gc.validPointer(hv.getPointer(gc.getPointerBase())) &&
"Setting an invalid pointer into a GCHermesValue");
}
assert(NeedsBarriers::value || !gc.needsWriteBarrier(this, hv));
if constexpr (NeedsBarriers::value) {
gc.writeBarrierForLargeObj(owningObj, this, hv);
}
HVType::setNoBarrier(hv);
}

template <typename HVType>
void GCHermesValueBase<HVType>::setNonPtr(HVType hv, GC &gc) {
assert(!hv.isPointer());
Expand Down
12 changes: 10 additions & 2 deletions include/hermes/VM/HermesValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,19 @@ class GCHermesValueBase final : public HVType {
GCHermesValueBase(HVType hv, GC &gc, std::nullptr_t);
GCHermesValueBase(const HVType &) = delete;

/// The HermesValue \p hv may be an object pointer. Assign the
/// value, and perform any necessary write barriers.
/// The HermesValue \p hv may be an object pointer. Assign the value, and
/// perform any necessary write barriers. This must not be used if it lives in
/// an object that supports large allocation.
template <typename NeedsBarriers = std::true_type>
inline void set(HVType hv, GC &gc);

/// The HermesValue \p hv may be an object pointer. Assign the value, and
/// perform any necessary write barriers. \p owningObj is the object that
/// contains this GCHermesValueBase, and it may support large allocation.
/// for which the object pointer is needed by writer barriers.
template <typename NeedsBarriers = std::true_type>
inline void set(HVType hv, GC &gc, const GCCell *owningObj);

/// The HermesValue \p hv must not be an object pointer. Assign the
/// value.
/// Some GCs still need to do a write barrier though, so pass a GC parameter.
Expand Down

0 comments on commit b8eee35

Please sign in to comment.