tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Marking.h (4645B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /*
      8 * Marking and sweeping APIs for use by implementations of different GC cell
      9 * kinds.
     10 */
     11 
     12 #ifndef gc_Marking_h
     13 #define gc_Marking_h
     14 
     15 #include "gc/Barrier.h"
     16 #include "gc/Tracer.h"
     17 #include "js/TypeDecls.h"
     18 
     19 class JSTracer;
     20 struct JSClass;
     21 
     22 namespace js {
     23 class GCMarker;
     24 class Shape;
     25 class WeakMapBase;
     26 
     27 namespace gc {
     28 
     29 struct Cell;
     30 
     31 /*** Liveness ***/
     32 
     33 // The IsMarkedInternal and IsAboutToBeFinalizedInternal function templates are
     34 // used to implement the IsMarked and IsAboutToBeFinalized set of functions.
     35 // These internal functions are instantiated for the base GC types and should
     36 // not be called directly.
     37 //
     38 // Note that there are two function templates declared for each, not one
     39 // template and a specialization. This is necessary so that pointer arguments
     40 // (e.g. JSObject**) and tagged value arguments (e.g. JS::Value*) are routed to
     41 // separate implementations.
     42 
     43 template <typename T>
     44 bool IsMarkedInternal(JSRuntime* rt, T* thing);
     45 
     46 template <typename T>
     47 bool IsAboutToBeFinalizedInternal(T* thing);
     48 template <typename T>
     49 bool IsAboutToBeFinalizedInternal(const T& thing);
     50 
     51 // Report whether a GC thing has been marked with any color. Things which are in
     52 // zones that are not currently being collected or are owned by another runtime
     53 // are always reported as being marked.
     54 template <typename T>
     55 inline bool IsMarked(JSRuntime* rt, const BarrieredBase<T>& thing) {
     56  return IsMarkedInternal(rt, *ConvertToBase(thing.unbarrieredAddress()));
     57 }
     58 template <typename T>
     59 inline bool IsMarkedUnbarriered(JSRuntime* rt, T thing) {
     60  return IsMarkedInternal(rt, *ConvertToBase(&thing));
     61 }
     62 
     63 // Report whether a GC thing is dead and will be finalized in the current sweep
     64 // group. This is mainly used in read barriers for incremental sweeping.
     65 //
     66 // This no longer updates pointers moved by the GC (tracing should be used for
     67 // this instead).
     68 template <typename T>
     69 inline bool IsAboutToBeFinalized(const BarrieredBase<T>& thing) {
     70  return IsAboutToBeFinalizedInternal(
     71      *ConvertToBase(thing.unbarrieredAddress()));
     72 }
     73 template <typename T>
     74 inline bool IsAboutToBeFinalizedUnbarriered(T* thing) {
     75  return IsAboutToBeFinalizedInternal(*ConvertToBase(&thing));
     76 }
     77 template <typename T>
     78 inline bool IsAboutToBeFinalizedUnbarriered(const T& thing) {
     79  return IsAboutToBeFinalizedInternal(thing);
     80 }
     81 
     82 inline bool IsAboutToBeFinalizedDuringMinorSweep(Cell* cell);
     83 
     84 inline Cell* ToMarkable(const Value& v) {
     85  if (v.isGCThing()) {
     86    return (Cell*)v.toGCThing();
     87  }
     88  return nullptr;
     89 }
     90 
     91 inline Cell* ToMarkable(Cell* cell) { return cell; }
     92 
     93 bool UnmarkGrayGCThingUnchecked(GCMarker* marker, JS::GCCellPtr thing);
     94 
     95 } /* namespace gc */
     96 
     97 namespace gc {
     98 
     99 // Functions for checking and updating GC thing pointers that might have been
    100 // moved by compacting GC. Overloads are also provided that work with Values.
    101 //
    102 // IsForwarded    - check whether a pointer refers to an GC thing that has been
    103 //                  moved.
    104 //
    105 // Forwarded      - return a pointer to the new location of a GC thing given a
    106 //                  pointer to old location.
    107 //
    108 // MaybeForwarded - used before dereferencing a pointer that may refer to a
    109 //                  moved GC thing without updating it. For JSObjects this will
    110 //                  also update the object's shape pointer if it has been moved
    111 //                  to allow slots to be accessed.
    112 
    113 template <typename T>
    114 inline bool IsForwarded(const T* t);
    115 inline bool IsForwarded(const JS::Value& value);
    116 
    117 template <typename T>
    118 inline T* Forwarded(const T* t);
    119 inline Value Forwarded(const JS::Value& value);
    120 
    121 template <typename T>
    122 inline T MaybeForwarded(const T& t);
    123 
    124 // Helper functions for use in situations where the object's group might be
    125 // forwarded, for example while marking.
    126 
    127 inline const JSClass* MaybeForwardedObjectClass(const JSObject* obj);
    128 
    129 template <typename T>
    130 inline bool MaybeForwardedObjectIs(const JSObject* obj);
    131 
    132 template <typename T>
    133 inline T& MaybeForwardedObjectAs(JSObject* obj);
    134 
    135 #ifdef JSGC_HASH_TABLE_CHECKS
    136 
    137 template <typename T>
    138 inline bool IsGCThingValidAfterMovingGC(T* t);
    139 
    140 template <typename T>
    141 inline void CheckGCThingAfterMovingGC(T* t);
    142 
    143 template <typename T>
    144 inline void CheckGCThingAfterMovingGC(const WeakHeapPtr<T*>& t);
    145 
    146 #endif  // JSGC_HASH_TABLE_CHECKS
    147 
    148 } /* namespace gc */
    149 
    150 } /* namespace js */
    151 
    152 #endif /* gc_Marking_h */