Skip to content

Commit

Permalink
Add needsWriteBarriers for constructors and large objects
Browse files Browse the repository at this point in the history
Differential Revision: D67556001
  • Loading branch information
lavenzg authored and facebook-github-bot committed Dec 26, 2024
1 parent 2d92eeb commit d81ba7d
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/hermes/VM/GCBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,18 @@ class GCBase {
SmallHermesValue value) const = 0;
virtual bool needsWriteBarrier(const GCPointerBase *loc, GCCell *value)
const = 0;
virtual bool needsWriteBarrierInCtor(
const GCHermesValue *loc,
HermesValue value) const = 0;
virtual bool needsWriteBarrierInCtor(
const GCSmallHermesValue *loc,
SmallHermesValue value) const = 0;
virtual bool needsWriteBarrierForLargeObj(
const GCHermesValue *loc,
HermesValue value) const = 0;
virtual bool needsWriteBarrierForLargeObj(
const GCSmallHermesValue *loc,
SmallHermesValue value) const = 0;
/// \}
#endif

Expand Down
10 changes: 10 additions & 0 deletions include/hermes/VM/HadesGC.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,16 @@ class HadesGC final : public GCBase {
const override;
bool needsWriteBarrier(const GCPointerBase *loc, GCCell *value)
const override;
bool needsWriteBarrierInCtor(const GCHermesValue *loc, HermesValue value)
const override;
bool needsWriteBarrierInCtor(
const GCSmallHermesValue *loc,
SmallHermesValue value) const override;
bool needsWriteBarrierForLargeObj(const GCHermesValue *loc, HermesValue value)
const override;
bool needsWriteBarrierForLargeObj(
const GCSmallHermesValue *loc,
SmallHermesValue value) const override;
/// \}
#endif

Expand Down
10 changes: 10 additions & 0 deletions include/hermes/VM/MallocGC.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ class MallocGC final : public GCBase {
const override;
bool needsWriteBarrier(const GCPointerBase *loc, GCCell *value)
const override;
bool needsWriteBarrierInCtor(const GCHermesValue *loc, HermesValue value)
const override;
bool needsWriteBarrierInCtor(
const GCSmallHermesValue *loc,
SmallHermesValue value) const override;
bool needsWriteBarrierForLargeObj(const GCHermesValue *loc, HermesValue value)
const override;
bool needsWriteBarrierForLargeObj(
const GCSmallHermesValue *loc,
SmallHermesValue value) const override;
#endif

#ifdef HERMES_MEMORY_INSTRUMENTATION
Expand Down
46 changes: 46 additions & 0 deletions lib/VM/gcs/HadesGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2289,6 +2289,17 @@ bool HadesGC::needsWriteBarrier(const GCHermesValue *loc, HermesValue value)
return true;
return false;
}
bool HadesGC::needsWriteBarrierInCtor(
const GCHermesValue *loc,
HermesValue value) const {
// Values in the YG never need a barrier.
if (inYoungGen(loc))
return false;
// If the new value is a pointer, a relocation barrier is needed.
if (value.isPointer())
return true;
return false;
}
bool HadesGC::needsWriteBarrier(
const GCSmallHermesValue *loc,
SmallHermesValue value) const {
Expand All @@ -2303,6 +2314,41 @@ bool HadesGC::needsWriteBarrier(
return true;
return false;
}
bool HadesGC::needsWriteBarrierInCtor(
const GCSmallHermesValue *loc,
SmallHermesValue value) const {
// Values in the YG never need a barrier.
if (inYoungGen(loc))
return false;
// If the new value is a pointer, a relocation barrier is needed.
if (value.isPointer())
return true;
return false;
}
bool HadesGC::needsWriteBarrierForLargeObj(
const GCHermesValue *loc,
HermesValue value) const {
// For large allocation, we don't allow skipping barriers if the pointer lives
// in YG. We may revisit this if there is a case that we really want to skip
// barriers (by ensuring that the owning object always lives in YG).
if (loc->isPointer() || loc->isSymbol())
return true;
if (value.isPointer())
return true;
return false;
}
bool HadesGC::needsWriteBarrierForLargeObj(
const GCSmallHermesValue *loc,
SmallHermesValue value) const {
// For large allocation, we don't allow skipping barriers if the pointer lives
// in YG. We may revisit this if there is a case that we really want to skip
// barriers (by ensuring that the owning object always lives in YG).
if (loc->isPointer() || loc->isSymbol())
return true;
if (value.isPointer())
return true;
return false;
}
bool HadesGC::needsWriteBarrier(const GCPointerBase *loc, GCCell *value) const {
return !inYoungGen(loc);
}
Expand Down
20 changes: 20 additions & 0 deletions lib/VM/gcs/MallocGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,35 @@ bool MallocGC::needsWriteBarrier(const GCHermesValue *loc, HermesValue value)
const {
return false;
}
bool MallocGC::needsWriteBarrierInCtor(
const GCHermesValue *loc,
HermesValue value) const {
return false;
}
bool MallocGC::needsWriteBarrier(
const GCSmallHermesValue *loc,
SmallHermesValue value) const {
return false;
}
bool MallocGC::needsWriteBarrierInCtor(
const GCSmallHermesValue *loc,
SmallHermesValue value) const {
return false;
}
bool MallocGC::needsWriteBarrier(const GCPointerBase *loc, GCCell *value)
const {
return false;
}
bool MallocGC::needsWriteBarrierForLargeObj(
const GCHermesValue *loc,
HermesValue value) const {
return false;
}
bool MallocGC::needsWriteBarrierForLargeObj(
const GCSmallHermesValue *loc,
SmallHermesValue value) const {
return false;
}
#endif

#ifdef HERMES_MEMORY_INSTRUMENTATION
Expand Down

0 comments on commit d81ba7d

Please sign in to comment.