online
  5   ˆl–Ðz¾”d
i?u8 \¸Ø.å1hß�þB gÁe™”¬‹ùÉƒh¹È¿Å      online
  !   ˆÊ�þZp,Ù$‘¸Û•¢ þÉ„¯‰¯ÈÇ¿Å ?÷     /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef js_TracingAPI_h
#define js_TracingAPI_h

#include "js/AllocPolicy.h"
#include "js/GCTypeMacros.h"
#include "js/HashTable.h"
#include "js/HeapAPI.h"
#include "js/TraceKind.h"

class JS_PUBLIC_API JSTracer;

namespace JS {
class JS_PUBLIC_API CallbackTracer;
template <typename T>
class Heap;
template <typename T>
class TenuredHeap;

/** Returns a static string equivalent of |kind|. */
JS_FRIEND_API const char* GCTraceKindToAscii(JS::TraceKind kind);

/** Returns the base size in bytes of the GC thing of kind |kind|. */
JS_FRIEND_API size_t GCTraceKindSize(JS::TraceKind kind);

}  // namespace JS

enum WeakMapTraceKind {
  /**
   * Do not trace into weak map keys or values during traversal. Users must
   * handle weak maps manually.
   */
  DoNotTraceWeakMaps,

  /**
   * Do true ephemeron marking with a weak key lookup marking phase. This is
   * the default for GCMarker.
   */
  ExpandWeakMaps,

  /**
   * Trace through to all values, irrespective of whether the keys are live
   * or not. Used for non-marking tracers.
   */
  TraceWeakMapValues,

  /**
   * Trace through to all keys and values, irrespective of whether the keys
   * are live or not. Used for non-marking tracers.
   */
  TraceWeakMapKeysValues
};

class JS_PUBLIC_API JSTracer {
 public:
  // Return the runtime set on the tracer.
  JSRuntime* runtime() const { return runtime_; }

  // Return the weak map tracing behavior currently set on this tracer.
  WeakMapTraceKind weakMapAction() const { return weakMapAction_; }

  enum class TracerKindTag {
    // Marking path: a tracer used only for marking liveness of cells, not
    // for moving them. The kind will transition to WeakMarking after
    // everything reachable by regular edges has been marked.
    Marking,

    // A tracer that traverses the graph for the purposes of moving objects
    // from the nursery to the tenured area.
    Tenuring,

    // General-purpose traversal that invokes a callback on each cell.
    // Traversing children is the responsibility of the callback.
    Callback
  };
  bool isMarkingTracer() const { return tag_ == TracerKindTag::Marking; }
  bool isTenuringTracer() const { return tag_ == TracerKindTag::Tenuring; }
  bool isCallbackTracer() const { return tag_ == TracerKindTag::Callback; }
  inline JS::CallbackTracer* asCallbackTracer();
  bool traceWeakEdges() const { return traceWeakEdges_; }
  bool canSkipJsids() const { return canSkipJsids_; }
#ifdef DEBUG
  bool checkEdges() { return checkEdges_; }
#endif

  // Get the current GC number. Only call this method if |isMarkingTracer()|
  // is true.
  uint32_t gcNumberForMarking() const;

 protected:
  JSTracer(JSRuntime* rt, TracerKindTag tag,
           WeakMapTraceKind weakTraceKind = TraceWeakMapValues)
      : runtime_(rt),
        weakMapAction_(weakTraceKind),
        tag_(tag),
        traceWeakEdges_(true),
#ifdef DEBUG
        checkEdges_(true),
#endif
        canSkipJsids_(false) {
  }

  void setTraceWeakEdges(bool value) { traceWeakEdges_ = value; }

#ifdef DEBUG
  // Set whether to check edges are valid in debug builds.
  void setCheckEdges(bool check) { checkEdges_ = check; }
#endif

 private:
  JSRuntime* const runtime_;
  const WeakMapTraceKind weakMapAction_;
  const TracerKindTag tag_;

  // Whether the tracer should trace weak edges. GCMarker sets this to false.
  bool traceWeakEdges_;

#ifdef DEBUG
  bool checkEdges_;
#endif

 protected:
  bool canSkipJsids_;
};

namespace JS {

class AutoTracingName;
class AutoTracingIndex;
class AutoTracingCallback;

class JS_PUBLIC_API CallbackTracer : public JSTracer {
 public:
  CallbackTracer(JSRuntime* rt,
   