Skip to content

Commit

Permalink
Pass the pointer of owning object in ctor of GCHermesValueBase (#1508)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #1508

Differential Revision: D62222238
  • Loading branch information
lavenzg authored and facebook-github-bot committed Nov 8, 2024
1 parent beffe9a commit 1998926
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions include/hermes/VM/HermesValue-inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ GCHermesValueBase<HVType>::GCHermesValueBase(HVType hv, GC &gc) : HVType{hv} {
gc.constructorWriteBarrier(this, hv);
}

template <typename HVType>
template <typename NeedsBarriers>
GCHermesValueBase<HVType>::GCHermesValueBase(
HVType hv,
GC &gc,
const GCCell *owningObj)
: HVType{hv} {
assert(!hv.isPointer() || hv.getPointer());
(void)owningObj;
if (NeedsBarriers::value)
gc.constructorWriteBarrier(this, hv);
}

template <typename HVType>
template <typename NeedsBarriers>
GCHermesValueBase<HVType>::GCHermesValueBase(HVType hv, GC &gc, std::nullptr_t)
Expand Down
8 changes: 7 additions & 1 deletion include/hermes/VM/HermesValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,15 @@ template <typename HVType>
class GCHermesValueBase final : public HVType {
public:
GCHermesValueBase() : HVType(HVType::encodeUndefinedValue()) {}
/// Initialize a GCHermesValue from another HV. Performs a write barrier.
/// Initialize a GCHermesValue from another HV. Performs a write barrier. This
/// must not be used if it lives in an object that supports large allocation.
template <typename NeedsBarriers = std::true_type>
GCHermesValueBase(HVType hv, GC &gc);
/// Initialize a GCHermesValue from another HV. Performs a write barrier using
/// \p owningObj, which owns this GCHermesValue and may support large
/// allocation.
template <typename NeedsBarriers = std::true_type>
GCHermesValueBase(HVType hv, GC &gc, const GCCell *owningObj);
/// Initialize a GCHermesValue from a non-pointer HV. Might perform a write
/// barrier, depending on the GC.
/// NOTE: The last parameter is unused, but acts as an overload selector.
Expand Down

0 comments on commit 1998926

Please sign in to comment.