Commit f88eca81 authored by Jon Coppeard's avatar Jon Coppeard
Browse files

Bug 1585921 - Use root marking functions to trace unbarriered pointers in...

Bug 1585921 - Use root marking functions to trace unbarriered pointers in GCPolicy traits since this is only safe when we're marking roots r=sfink

The root marking functions have assertions that will catch this being used outside of heap marking.

Differential Revision: https://phabricator.services.mozilla.com/D48534

--HG--
extra : moz-landing-system : lando
parent f5b37220
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -109,9 +109,9 @@ struct GCPointerPolicy {
                "Non-pointer type not allowed for GCPointerPolicy");
                "Non-pointer type not allowed for GCPointerPolicy");


  static void trace(JSTracer* trc, T* vp, const char* name) {
  static void trace(JSTracer* trc, T* vp, const char* name) {
    if (*vp) {
    // It's not safe to trace unbarriered pointers except as part of root
      js::UnsafeTraceManuallyBarrieredEdge(trc, vp, name);
    // marking.
    }
    UnsafeTraceRoot(trc, vp, name);
  }
  }
  static bool needsSweep(T* vp) {
  static bool needsSweep(T* vp) {
    if (*vp) {
    if (*vp) {
+3 −1
Original line number Original line Diff line number Diff line
@@ -170,7 +170,9 @@ namespace JS {
template <>
template <>
struct GCPolicy<jsid> {
struct GCPolicy<jsid> {
  static void trace(JSTracer* trc, jsid* idp, const char* name) {
  static void trace(JSTracer* trc, jsid* idp, const char* name) {
    js::UnsafeTraceManuallyBarrieredEdge(trc, idp, name);
    // It's not safe to trace unbarriered pointers except as part of root
    // marking.
    UnsafeTraceRoot(trc, idp, name);
  }
  }
  static bool isValid(jsid id) {
  static bool isValid(jsid id) {
    return !JSID_IS_GCTHING(id) ||
    return !JSID_IS_GCTHING(id) ||
+3 −1
Original line number Original line Diff line number Diff line
@@ -1077,7 +1077,9 @@ JS_PUBLIC_API void HeapValueWriteBarriers(Value* valuep, const Value& prev,
template <>
template <>
struct GCPolicy<JS::Value> {
struct GCPolicy<JS::Value> {
  static void trace(JSTracer* trc, Value* v, const char* name) {
  static void trace(JSTracer* trc, Value* v, const char* name) {
    js::UnsafeTraceManuallyBarrieredEdge(trc, v, name);
    // It's not safe to trace unbarriered pointers except as part of root
    // marking.
    UnsafeTraceRoot(trc, v, name);
  }
  }
  static bool isTenured(const Value& thing) {
  static bool isTenured(const Value& thing) {
    return !thing.isGCThing() || !IsInsideNursery(thing.toGCThing());
    return !thing.isGCThing() || !IsInsideNursery(thing.toGCThing());
+4 −3
Original line number Original line Diff line number Diff line
@@ -44,9 +44,10 @@ struct InternalGCPointerPolicy : public JS::GCPointerPolicy<T> {
    }
    }
  }
  }
  static void trace(JSTracer* trc, T* vp, const char* name) {
  static void trace(JSTracer* trc, T* vp, const char* name) {
    if (*vp) {
    // It's not safe to trace unbarriered pointers except as part of root
      TraceManuallyBarrieredEdge(trc, vp, name);
    // marking. If you get an assertion here you probably need to add a barrier,
    }
    // e.g. HeapPtr<T>.
    TraceNullableRoot(trc, vp, name);
  }
  }
};
};


+1 −1
Original line number Original line Diff line number Diff line
@@ -532,7 +532,7 @@ void ParseTask::trace(JSTracer* trc) {
    return;
    return;
  }
  }


  TraceManuallyBarrieredEdge(trc, &parseGlobal, "ParseTask::parseGlobal");
  TraceRoot(trc, &parseGlobal, "ParseTask::parseGlobal");
  scripts.trace(trc);
  scripts.trace(trc);
  sourceObjects.trace(trc);
  sourceObjects.trace(trc);
}
}
Loading