Skip to content

Commit 8e20882

Browse files
lavenzgfacebook-github-bot
authored andcommitted
Pass the pointer of owning object in GCHermesValueBase::set() (#1512)
Summary: Pull Request resolved: #1512 This variant will be used by write barriers that support large allocation in following diffs. Differential Revision: D62196480
1 parent 7dfbd62 commit 8e20882

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

include/hermes/VM/HermesValue-inline.h

+17
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ inline void GCHermesValueBase<HVType>::set(HVType hv, GC &gc) {
6161
HVType::setNoBarrier(hv);
6262
}
6363

64+
template <typename HVType>
65+
template <typename NeedsBarriers>
66+
inline void
67+
GCHermesValueBase<HVType>::set(HVType hv, GC &gc, const GCCell *owningObj) {
68+
if (hv.isPointer()) {
69+
HERMES_SLOW_ASSERT(
70+
gc.validPointer(hv.getPointer(gc.getPointerBase())) &&
71+
"Setting an invalid pointer into a GCHermesValue");
72+
}
73+
assert(NeedsBarriers::value || !gc.needsWriteBarrier(this, hv));
74+
(void)owningObj;
75+
if constexpr (NeedsBarriers::value) {
76+
gc.writeBarrier(this, hv);
77+
}
78+
HVType::setNoBarrier(hv);
79+
}
80+
6481
template <typename HVType>
6582
void GCHermesValueBase<HVType>::setNonPtr(HVType hv, GC &gc) {
6683
assert(!hv.isPointer());

include/hermes/VM/HermesValue.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,19 @@ class GCHermesValueBase final : public HVType {
530530
GCHermesValueBase(HVType hv, GC &gc, std::nullptr_t);
531531
GCHermesValueBase(const HVType &) = delete;
532532

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

539+
/// The HermesValue \p hv may be an object pointer. Assign the value, and
540+
/// perform any necessary write barriers. \p owningObj is the object that
541+
/// contains this GCHermesValueBase, and it may support large allocation.
542+
/// for which the object pointer is needed by writer barriers.
543+
template <typename NeedsBarriers = std::true_type>
544+
inline void set(HVType hv, GC &gc, const GCCell *owningObj);
545+
538546
/// The HermesValue \p hv must not be an object pointer. Assign the
539547
/// value.
540548
/// Some GCs still need to do a write barrier though, so pass a GC parameter.

0 commit comments

Comments
 (0)