Bug 1234862 - Part 5: Rename DefaultGCPolicy to GCPolicy; r=sfink

This commit is contained in:
Terrence Cole 2016-01-26 12:53:35 -08:00
parent ba5d237f9c
commit 9964bfe4ca
30 changed files with 331 additions and 202 deletions

View File

@ -61,7 +61,7 @@ struct JSObjWrapperHasher
namespace js {
template <>
struct DefaultGCPolicy<nsJSObjWrapper*> {
struct GCPolicy<nsJSObjWrapper*> {
static void trace(JSTracer* trc, nsJSObjWrapper** wrapper, const char* name) {
MOZ_ASSERT(wrapper);
MOZ_ASSERT(*wrapper);

View File

@ -7,6 +7,7 @@
#ifndef GCHashTable_h
#define GCHashTable_h
#include "js/GCPolicyAPI.h"
#include "js/HashTable.h"
#include "js/RootingAPI.h"
#include "js/TracingAPI.h"
@ -17,7 +18,7 @@ namespace js {
template <typename Key, typename Value>
struct DefaultMapSweepPolicy {
static bool needsSweep(Key* key, Value* value) {
return DefaultGCPolicy<Key>::needsSweep(key) || DefaultGCPolicy<Value>::needsSweep(value);
return GCPolicy<Key>::needsSweep(key) || GCPolicy<Value>::needsSweep(value);
}
};
@ -31,11 +32,11 @@ struct DefaultMapSweepPolicy {
// appropriately.
//
// Most types of GC pointers as keys and values can be traced with no extra
// infrastructure. For structs, the DefaultGCPolicy<T> will call a trace()
// method on the struct. For other structs and non-gc-pointer members, ensure
// that there is a specialization of DefaultGCPolicy<T> with an appropriate
// trace() static method available to handle the custom type. Generic helpers
// can be found in js/public/TracingAPI.h.
// infrastructure. For structs, the GCPolicy<T> will call a trace() method on
// the struct. For other structs and non-gc-pointer members, ensure that there
// is a specialization of GCPolicy<T> with an appropriate trace() static method
// available to handle the custom type. Generic helpers can be found in
// js/public/TracingAPI.h.
//
// Note that this HashMap only knows *how* to trace and sweep (and the tracing
// can handle keys that move), but it does not itself cause tracing or sweeping
@ -61,8 +62,8 @@ class GCHashMap : public HashMap<Key, Value, HashPolicy, AllocPolicy>,
if (!this->initialized())
return;
for (typename Base::Enum e(*this); !e.empty(); e.popFront()) {
DefaultGCPolicy<Value>::trace(trc, &e.front().value(), "hashmap value");
DefaultGCPolicy<Key>::trace(trc, &e.front().mutableKey(), "hashmap key");
GCPolicy<Value>::trace(trc, &e.front().value(), "hashmap value");
GCPolicy<Key>::trace(trc, &e.front().mutableKey(), "hashmap key");
}
}
@ -215,8 +216,8 @@ class HandleBase<GCHashMap<A,B,C,D,E>>
//
// Most types of GC pointers can be traced with no extra infrastructure. For
// structs and non-gc-pointer members, ensure that there is a specialization of
// DefaultGCPolicy<T> with an appropriate trace method available to handle the
// custom type. Generic helpers can be found in js/public/TracingAPI.h.
// GCPolicy<T> with an appropriate trace method available to handle the custom
// type. Generic helpers can be found in js/public/TracingAPI.h.
//
// Note that although this HashSet's trace will deal correctly with moved
// elements, it does not itself know when to barrier or trace elements. To
@ -238,14 +239,14 @@ class GCHashSet : public HashSet<T, HashPolicy, AllocPolicy>,
if (!this->initialized())
return;
for (typename Base::Enum e(*this); !e.empty(); e.popFront())
DefaultGCPolicy<T>::trace(trc, &e.mutableFront(), "hashset element");
GCPolicy<T>::trace(trc, &e.mutableFront(), "hashset element");
}
void sweep() {
if (!this->initialized())
return;
for (typename Base::Enum e(*this); !e.empty(); e.popFront()) {
if (DefaultGCPolicy<T>::needsSweep(&e.mutableFront()))
if (GCPolicy<T>::needsSweep(&e.mutableFront()))
e.removeFront();
}
}

114
js/public/GCPolicyAPI.h Normal file
View File

@ -0,0 +1,114 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sts=4 et sw=4 tw=99:
* 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/. */
// GC Policy Mechanism
// A GCPolicy controls how the GC interacts with both direct pointers to GC
// things (e.g. JSObject* or JSString*), tagged and/or optional pointers to GC
// things (e.g. Value or jsid), and C++ aggregate types (e.g.
// JSPropertyDescriptor or GCHashMap).
//
// The GCPolicy provides at a minimum:
//
// static T initial()
// - Tells the GC how to construct an empty T.
//
// static void trace(JSTracer, T* tp, const char* name)
// - Tells the GC how to traverse the edge itself or its children in the
// case of an aggregate.
//
// static bool needsSweep(T* tp)
// - Tells the GC how to tell if an edge is about to be finalized. For
// aggregates, the meaning is less clear. When the aggregate is used in
// a weak container, the return value will determine the semantcs of
// that container's weakness. This is the primary reason that GC-
// supporting containers can override the policy on a per-container
// basis.
#ifndef GCPolicyAPI_h
#define GCPolicyAPI_h
#include "js/TraceKind.h"
#include "js/TracingAPI.h"
class JSAtom;
class JSFunction;
class JSObject;
class JSScript;
class JSString;
namespace JS {
class Symbol;
}
namespace js {
// Defines a policy for aggregate types with non-GC, i.e. C storage. This
// policy dispatches to the underlying aggregate for GC interactions.
template <typename T>
struct StructGCPolicy
{
static T initial() {
return T();
}
static void trace(JSTracer* trc, T* tp, const char* name) {
tp->trace(trc);
}
static bool needsSweep(T* tp) {
return tp->needsSweep();
}
};
// The default GC policy attempts to defer to methods on the underlying type.
// Most C++ structures that contain a default constructor, a trace function and
// a sweep function will work out of the box with Rooted, GCHash{Set,Map}, and
// GCVector.
template <typename T> struct GCPolicy : public StructGCPolicy<T> {};
// This policy ignores any GC interaction, e.g. for non-GC types.
template <typename T>
struct IgnoreGCPolicy {
static T initial() { return T(); }
static void trace(JSTracer* trc, T* t, const char* name) {}
static bool needsSweep(T* v) { return false; }
};
template <> struct GCPolicy<uint32_t> : public IgnoreGCPolicy<uint32_t> {};
template <> struct GCPolicy<uint64_t> : public IgnoreGCPolicy<uint64_t> {};
template <typename T>
struct GCPointerPolicy
{
static T initial() { return nullptr; }
static void trace(JSTracer* trc, T* vp, const char* name) {
if (*vp)
js::UnsafeTraceManuallyBarrieredEdge(trc, vp, name);
}
static void needsSweep(T* vp) {
return js::gc::EdgeNeedsSweep(vp);
}
};
template <> struct GCPolicy<JS::Symbol*> : public GCPointerPolicy<JS::Symbol*> {};
template <> struct GCPolicy<JSAtom*> : public GCPointerPolicy<JSAtom*> {};
template <> struct GCPolicy<JSFunction*> : public GCPointerPolicy<JSFunction*> {};
template <> struct GCPolicy<JSObject*> : public GCPointerPolicy<JSObject*> {};
template <> struct GCPolicy<JSScript*> : public GCPointerPolicy<JSScript*> {};
template <> struct GCPolicy<JSString*> : public GCPointerPolicy<JSString*> {};
template <typename T>
struct GCPolicy<JS::Heap<T>>
{
static void trace(JSTracer* trc, JS::Heap<T>* thingp, const char* name) {
JS::TraceEdge(trc, thingp, name);
}
static bool needsSweep(JS::Heap<T>* thingp) {
return gc::EdgeNeedsSweep(thingp);
}
};
} // namespace js
#endif // GCPolicyAPI_h

View File

@ -9,6 +9,7 @@
#include "mozilla/Vector.h"
#include "js/GCPolicyAPI.h"
#include "js/RootingAPI.h"
#include "js/TracingAPI.h"
#include "js/Vector.h"
@ -121,7 +122,7 @@ class GCVector : public JS::Traceable
void trace(JSTracer* trc) {
for (auto& elem : vector)
DefaultGCPolicy<T>::trace(trc, &elem, "vector element");
GCPolicy<T>::trace(trc, &elem, "vector element");
}
};

View File

@ -172,6 +172,9 @@ template <>
struct GCPolicy<jsid>
{
static jsid initial() { return JSID_VOID; }
static void trace(JSTracer* trc, jsid* idp, const char* name) {
js::UnsafeTraceManuallyBarrieredEdge(trc, idp, name);
}
};
template <>

View File

@ -17,6 +17,7 @@
#include "jspubtd.h"
#include "js/GCAPI.h"
#include "js/GCPolicyAPI.h"
#include "js/HeapAPI.h"
#include "js/TypeDecls.h"
#include "js/Utility.h"
@ -108,11 +109,6 @@ template <typename T>
struct BarrierMethods {
};
template <typename T>
struct GCPolicy {
static T initial() { return T(); }
};
template <typename T>
class RootedBase {};

View File

@ -347,71 +347,6 @@ template <typename T>
extern JS_PUBLIC_API(bool)
EdgeNeedsSweep(JS::Heap<T>* edgep);
} // namespace gc
// Automates static dispatch for GC interaction with TraceableContainers.
template <typename>
struct DefaultGCPolicy;
// This policy dispatches GC methods to a method on the type.
template <typename T>
struct StructGCPolicy {
static void trace(JSTracer* trc, T* t, const char* name) {
// This is the default GC policy for storing GC things in containers.
// If your build is failing here, it means you either need an
// implementation of DefaultGCPolicy<T> for your type or, if this is
// the right policy for you, your struct or container is missing a
// trace method.
t->trace(trc);
}
static bool needsSweep(T* t) {
return t->needsSweep();
}
};
// This policy ignores any GC interaction, e.g. for non-GC types.
template <typename T>
struct IgnoreGCPolicy {
static void trace(JSTracer* trc, T* t, const char* name) {}
static bool needsSweep(T* v) { return false; }
};
// The default policy when no other more specific policy fits (e.g. for a
// direct GC pointer), is to assume a struct type that implements the needed
// methods.
template <typename T>
struct DefaultGCPolicy : public StructGCPolicy<T> {};
template <>
struct DefaultGCPolicy<jsid>
{
static void trace(JSTracer* trc, jsid* idp, const char* name) {
js::UnsafeTraceManuallyBarrieredEdge(trc, idp, name);
}
};
template <>
struct DefaultGCPolicy<JS::Value>
{
static void trace(JSTracer* trc, JS::Value* v, const char* name) {
js::UnsafeTraceManuallyBarrieredEdge(trc, v, name);
}
};
template <> struct DefaultGCPolicy<uint32_t> : public IgnoreGCPolicy<uint32_t> {};
template <> struct DefaultGCPolicy<uint64_t> : public IgnoreGCPolicy<uint64_t> {};
template <typename T>
struct DefaultGCPolicy<JS::Heap<T>>
{
static void trace(JSTracer* trc, JS::Heap<T>* thingp, const char* name) {
JS::TraceEdge(trc, thingp, name);
}
static bool needsSweep(JS::Heap<T>* thingp) {
return gc::EdgeNeedsSweep(thingp);
}
};
} // namespace js
#endif /* js_TracingAPI_h */

View File

@ -1703,6 +1703,9 @@ template <>
struct GCPolicy<JS::Value>
{
static JS::Value initial() { return JS::UndefinedValue(); }
static void trace(JSTracer* trc, JS::Value* v, const char* name) {
js::UnsafeTraceManuallyBarrieredEdge(trc, v, name);
}
};
template <>

View File

@ -33,6 +33,7 @@
#include "asmjs/WasmSerialize.h"
#include "builtin/SIMD.h"
#include "frontend/Parser.h"
#include "gc/Policy.h"
#include "jit/AtomicOperations.h"
#include "jit/MIR.h"
#include "js/Class.h"

View File

@ -9,6 +9,7 @@
#include "builtin/SelfHostingDefines.h"
#include "frontend/ParseNode.h"
#include "frontend/SharedContext.h"
#include "gc/Policy.h"
#include "gc/Tracer.h"
#include "jsobjinlines.h"

View File

@ -40,6 +40,7 @@
#include "builtin/TypedObject.h"
#include "ctypes/Library.h"
#include "gc/Policy.h"
#include "gc/Zone.h"
#include "js/Vector.h"

View File

@ -20,8 +20,8 @@ namespace js {
//
// Most types of GC pointers as keys and values can be traced with no extra
// infrastructure. For structs and non-gc-pointer members, ensure that there is
// a specialization of DefaultGCPolicy<T> with an appropriate trace method
// available to handle the custom type. Generic helpers can be found in
// a specialization of GCPolicy<T> with an appropriate trace method available
// to handle the custom type. Generic helpers can be found in
// js/public/TracingAPI.h. Generic helpers can be found in
// js/public/TracingAPI.h.
//
@ -48,9 +48,9 @@ class TraceableFifo
static void trace(TraceableFifo* tf, JSTracer* trc) {
for (size_t i = 0; i < tf->front_.length(); ++i)
DefaultGCPolicy<T>::trace(trc, &tf->front_[i], "fifo element");
GCPolicy<T>::trace(trc, &tf->front_[i], "fifo element");
for (size_t i = 0; i < tf->rear_.length(); ++i)
DefaultGCPolicy<T>::trace(trc, &tf->rear_[i], "fifo element");
GCPolicy<T>::trace(trc, &tf->rear_[i], "fifo element");
}
};

View File

@ -9,6 +9,7 @@
#include "jscompartment.h"
#include "jsobj.h"
#include "gc/Policy.h"
#include "gc/Zone.h"
#include "js/HashTable.h"
#include "js/Value.h"

View File

@ -17,6 +17,7 @@
#include "builtin/ModuleObject.h"
#include "gc/GCInternals.h"
#include "gc/Policy.h"
#include "jit/IonCode.h"
#include "js/SliceBudget.h"
#include "vm/ArgumentsObject.h"
@ -527,6 +528,7 @@ FOR_EACH_GC_POINTER_TYPE(INSTANTIATE_ALL_VALID_TRACE_FUNCTIONS)
template JS_PUBLIC_API(void) js::UnsafeTraceManuallyBarrieredEdge<type>(JSTracer*, type*, \
const char*);
FOR_EACH_PUBLIC_GC_POINTER_TYPE(INSTANTIATE_PUBLIC_TRACE_FUNCTIONS)
FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(INSTANTIATE_PUBLIC_TRACE_FUNCTIONS)
#undef INSTANTIATE_PUBLIC_TRACE_FUNCTIONS
template <typename T>

View File

@ -441,50 +441,6 @@ template<typename T>
void
CheckTracedThing(JSTracer* trc, T thing);
// Define a default Policy for all pointer types. This may fail to link if this
// policy gets used on a non-GC typed pointer by accident. There is a separate
// default policy for Value and jsid.
template <typename T>
struct DefaultGCPolicy<T*>
{
static void trace(JSTracer* trc, T** thingp, const char* name) {
// If linking is failing here, it likely means that you need to define
// or use a non-default GC policy for your non-gc-pointer type.
if (*thingp)
TraceManuallyBarrieredEdge(trc, thingp, name);
}
static bool needsSweep(T** thingp) {
// If linking is failing here, it likely means that you need to define
// or use a non-default GC policy for your non-gc-pointer type.
return *thingp && gc::IsAboutToBeFinalizedUnbarriered(thingp);
}
};
// RelocatablePtr is only defined for GC pointer types, so this default policy
// should work in all cases.
template <typename T>
struct DefaultGCPolicy<RelocatablePtr<T>>
{
static void trace(JSTracer* trc, RelocatablePtr<T>* thingp, const char* name) {
TraceEdge(trc, thingp, name);
}
static bool needsSweep(RelocatablePtr<T>* thingp) {
return gc::IsAboutToBeFinalizedUnbarriered(thingp);
}
};
template <typename T>
struct DefaultGCPolicy<ReadBarriered<T>>
{
static void trace(JSTracer* trc, ReadBarriered<T>* thingp, const char* name) {
TraceEdge(trc, thingp, name);
}
static bool needsSweep(ReadBarriered<T>* thingp) {
return gc::IsAboutToBeFinalized(thingp);
}
};
} /* namespace js */
#endif /* gc_Marking_h */

161
js/src/gc/Policy.h Normal file
View File

@ -0,0 +1,161 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sts=4 et sw=4 tw=99:
* 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/. */
/* JS Garbage Collector. */
#ifndef gc_Policy_h
#define gc_Policy_h
#include "mozilla/TypeTraits.h"
#include "js/GCPolicyAPI.h"
// Forward declare the types we're defining policies for. This file is
// included in all places that define GC things, so the real definitions
// will be available when we do template expansion, allowing for use of
// static members in the underlying types. We cannot, however, user
// static_assert to verify relations between types.
namespace js {
class AccessorShape;
class ArgumentsObject;
class ArrayBufferObject;
class ArrayBufferObjectMaybeShared;
class ArrayBufferViewObject;
class ArrayObject;
class BaseShape;
class ClonedBlockObject;
class DebugScopeObject;
class ExportEntryObject;
class GlobalObject;
class ImportEntryObject;
class LazyScript;
class ModuleEnvironmentObject;
class ModuleNamespaceObject;
class ModuleObject;
class NativeObject;
class NestedScopeObject;
class ObjectGroup;
class PlainObject;
class PropertyName;
class RegExpObject;
class SavedFrame;
class ScopeObject;
class ScriptSourceObject;
class Shape;
class SharedArrayBufferObject;
class StructTypeDescr;
class UnownedBaseShape;
namespace jit {
class JitCode;
} // namespace jit
} // namespace js
// Expand the given macro D for each public GC pointer.
#define FOR_EACH_PUBLIC_GC_POINTER_TYPE(D) \
D(JS::Symbol*) \
D(JSAtom*) \
D(JSFunction*) \
D(JSObject*) \
D(JSScript*) \
D(JSString*)
// Expand the given macro D for each public tagged GC pointer type.
#define FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(D) \
D(JS::Value) \
D(jsid)
#define FOR_EACH_PUBLIC_AGGREGATE_GC_POINTER_TYPE(D) \
D(JSPropertyDescriptor)
// Expand the given macro D for each valid GC reference type.
#define FOR_EACH_INTERNAL_GC_POINTER_TYPE(D) \
D(JSFlatString*) \
D(JSLinearString*) \
D(js::AccessorShape*) \
D(js::ArgumentsObject*) \
D(js::ArrayBufferObject*) \
D(js::ArrayBufferObjectMaybeShared*) \
D(js::ArrayBufferViewObject*) \
D(js::ArrayObject*) \
D(js::BaseShape*) \
D(js::ClonedBlockObject*) \
D(js::DebugScopeObject*) \
D(js::ExportEntryObject*) \
D(js::GlobalObject*) \
D(js::ImportEntryObject*) \
D(js::LazyScript*) \
D(js::ModuleEnvironmentObject*) \
D(js::ModuleNamespaceObject*) \
D(js::ModuleObject*) \
D(js::NativeObject*) \
D(js::NestedScopeObject*) \
D(js::ObjectGroup*) \
D(js::PlainObject*) \
D(js::PropertyName*) \
D(js::RegExpObject*) \
D(js::SavedFrame*) \
D(js::ScopeObject*) \
D(js::ScriptSourceObject*) \
D(js::Shape*) \
D(js::SharedArrayBufferObject*) \
D(js::StructTypeDescr*) \
D(js::UnownedBaseShape*) \
D(js::jit::JitCode*)
// Expand the given macro D for each internal tagged GC pointer type.
#define FOR_EACH_INTERNAL_TAGGED_GC_POINTER_TYPE(D) \
D(js::TaggedProto)
// Expand the macro D for every GC reference type that we know about.
#define FOR_EACH_GC_POINTER_TYPE(D) \
FOR_EACH_PUBLIC_GC_POINTER_TYPE(D) \
FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(D) \
FOR_EACH_INTERNAL_GC_POINTER_TYPE(D) \
FOR_EACH_INTERNAL_TAGGED_GC_POINTER_TYPE(D)
namespace js {
// Define the GCPolicy for all internal pointers.
template <typename T>
struct InternalGCPointerPolicy {
using Type = typename mozilla::RemovePointer<T>::Type;
static T initial() { return nullptr; }
static void preBarrier(T v) { Type::writeBarrierPre(v); }
static void postBarrier(T* vp, T prev, T next) { Type::writeBarrierPost(vp, prev, next); }
static void readBarrier(T v) { Type::readBarrier(v); }
static void trace(JSTracer* trc, T* vp, const char* name) {
TraceManuallyBarrieredEdge(trc, vp, name);
}
};
#define DEFINE_INTERNAL_GC_POLICY(type) \
template <> struct GCPolicy<type> : public InternalGCPointerPolicy<type> {};
FOR_EACH_INTERNAL_GC_POINTER_TYPE(DEFINE_INTERNAL_GC_POLICY)
#undef DEFINE_INTERNAL_GC_POLICY
template <typename T>
struct GCPolicy<RelocatablePtr<T>>
{
static void trace(JSTracer* trc, RelocatablePtr<T>* thingp, const char* name) {
TraceEdge(trc, thingp, name);
}
static bool needsSweep(RelocatablePtr<T>* thingp) {
return gc::IsAboutToBeFinalized(thingp);
}
};
template <typename T>
struct GCPolicy<ReadBarriered<T>>
{
static void trace(JSTracer* trc, ReadBarriered<T>* thingp, const char* name) {
TraceEdge(trc, thingp, name);
}
static bool needsSweep(ReadBarriered<T>* thingp) {
return gc::IsAboutToBeFinalized(thingp);
}
};
} // namespace js
#endif // gc_Policy_h

View File

@ -15,6 +15,7 @@
#include "builtin/Eval.h"
#include "builtin/SIMD.h"
#include "gc/Policy.h"
#include "jit/BaselineDebugModeOSR.h"
#include "jit/BaselineJIT.h"
#include "jit/JitSpewer.h"

View File

@ -13,6 +13,7 @@
#include "jslibmath.h"
#include "jstypes.h"
#include "gc/Policy.h"
#include "jit/BaselineDebugModeOSR.h"
#include "jit/BaselineIC.h"
#include "jit/JitSpewer.h"

View File

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ds/TraceableFifo.h"
#include "gc/Policy.h"
#include "js/GCHashTable.h"
#include "js/GCVector.h"
#include "js/RootingAPI.h"

View File

@ -59,6 +59,7 @@
#include "frontend/FullParseHandler.h" // for JS_BufferIsCompileableUnit
#include "frontend/Parser.h" // for JS_BufferIsCompileableUnit
#include "gc/Marking.h"
#include "gc/Policy.h"
#include "jit/JitCommon.h"
#include "js/CharacterEncoding.h"
#include "js/Conversions.h"

View File

@ -17,6 +17,7 @@
#include "jswrapper.h"
#include "gc/Marking.h"
#include "gc/Policy.h"
#include "jit/JitCompartment.h"
#include "jit/JitOptions.h"
#include "js/Date.h"

View File

@ -33,6 +33,7 @@
#include "frontend/BytecodeCompiler.h"
#include "frontend/TokenStream.h"
#include "gc/Marking.h"
#include "gc/Policy.h"
#include "jit/InlinableNatives.h"
#include "jit/Ion.h"
#include "jit/JitFrameIterator.h"

View File

@ -51,51 +51,6 @@ enum State {
COMPACT
};
// Expand the given macro D for each publicly exposed GC reference type.
#define FOR_EACH_PUBLIC_GC_POINTER_TYPE(D) \
D(JS::Symbol*) \
D(JSAtom*) \
D(JSFunction*) \
D(JSObject*) \
D(JSScript*) \
D(JSString*) \
D(JS::Value) \
D(jsid)
// Expand the given macro D for each valid GC reference type.
#define FOR_EACH_GC_POINTER_TYPE(D) \
FOR_EACH_PUBLIC_GC_POINTER_TYPE(D) \
D(AccessorShape*) \
D(BaseShape*) \
D(UnownedBaseShape*) \
D(jit::JitCode*) \
D(NativeObject*) \
D(ArrayObject*) \
D(ArgumentsObject*) \
D(ArrayBufferObject*) \
D(ArrayBufferObjectMaybeShared*) \
D(ArrayBufferViewObject*) \
D(DebugScopeObject*) \
D(GlobalObject*) \
D(ModuleObject*) \
D(ModuleEnvironmentObject*) \
D(ModuleNamespaceObject*) \
D(NestedScopeObject*) \
D(PlainObject*) \
D(SavedFrame*) \
D(ScopeObject*) \
D(ScriptSourceObject*) \
D(SharedArrayBufferObject*) \
D(ImportEntryObject*) \
D(ExportEntryObject*) \
D(LazyScript*) \
D(Shape*) \
D(JSFlatString*) \
D(JSLinearString*) \
D(PropertyName*) \
D(js::ObjectGroup*) \
D(TaggedProto)
/* Map from C++ type to alloc kind. JSObject does not have a 1:1 mapping, so must use Arena::thingSize. */
template <typename T> struct MapTypeToFinalizeKind {};
template <> struct MapTypeToFinalizeKind<JSScript> { static const AllocKind kind = AllocKind::SCRIPT; };

View File

@ -43,6 +43,7 @@
#include "builtin/SymbolObject.h"
#include "frontend/BytecodeCompiler.h"
#include "gc/Marking.h"
#include "gc/Policy.h"
#include "jit/BaselineJIT.h"
#include "js/MemoryMetrics.h"
#include "js/Proxy.h"

View File

@ -111,6 +111,7 @@ EXPORTS.js += [
'../public/Debug.h',
'../public/GCAPI.h',
'../public/GCHashTable.h',
'../public/GCPolicyAPI.h',
'../public/GCVector.h',
'../public/HashTable.h',
'../public/HeapAPI.h',

View File

@ -291,9 +291,10 @@ class Debugger : private mozilla::LinkedListElement<Debugger>
RelocatablePtrObject frame;
size_t size;
static void trace(TenurePromotionsLogEntry* e, JSTracer* trc) {
if (e->frame)
TraceEdge(trc, &e->frame, "Debugger::TenurePromotionsLogEntry::frame");
static void trace(TenurePromotionsLogEntry* e, JSTracer* trc) { e->trace(trc); }
void trace(JSTracer* trc) {
if (frame)
TraceEdge(trc, &frame, "Debugger::TenurePromotionsLogEntry::frame");
}
};
@ -318,11 +319,12 @@ class Debugger : private mozilla::LinkedListElement<Debugger>
size_t size;
bool inNursery;
static void trace(AllocationsLogEntry* e, JSTracer* trc) {
if (e->frame)
TraceEdge(trc, &e->frame, "Debugger::AllocationsLogEntry::frame");
if (e->ctorName)
TraceEdge(trc, &e->ctorName, "Debugger::AllocationsLogEntry::ctorName");
static void trace(AllocationsLogEntry* e, JSTracer* trc) { e->trace(trc); }
void trace(JSTracer* trc) {
if (frame)
TraceEdge(trc, &frame, "Debugger::AllocationsLogEntry::frame");
if (ctorName)
TraceEdge(trc, &ctorName, "Debugger::AllocationsLogEntry::ctorName");
}
};
@ -941,20 +943,6 @@ class Debugger : private mozilla::LinkedListElement<Debugger>
Debugger & operator=(const Debugger&) = delete;
};
template<>
struct DefaultGCPolicy<Debugger::TenurePromotionsLogEntry> {
static void trace(JSTracer* trc, Debugger::TenurePromotionsLogEntry* e, const char*) {
Debugger::TenurePromotionsLogEntry::trace(e, trc);
}
};
template<>
struct DefaultGCPolicy<Debugger::AllocationsLogEntry> {
static void trace(JSTracer* trc, Debugger::AllocationsLogEntry* e, const char*) {
Debugger::AllocationsLogEntry::trace(e, trc);
}
};
class BreakpointSite {
friend class Breakpoint;
friend struct ::JSCompartment;

View File

@ -10,6 +10,7 @@
#include "jsobj.h"
#include "gc/Marking.h"
#include "gc/Policy.h"
#include "gc/StoreBuffer.h"
#include "gc/Zone.h"
#include "vm/ArrayObject.h"
@ -1775,7 +1776,7 @@ ObjectGroupCompartment::clearTables()
ObjectGroupCompartment::PlainObjectTableSweepPolicy::needsSweep(PlainObjectKey* key,
PlainObjectEntry* entry)
{
if (!(DefaultGCPolicy<PlainObjectKey>::needsSweep(key) || entry->needsSweep(key->nproperties)))
if (!(GCPolicy<PlainObjectKey>::needsSweep(key) || entry->needsSweep(key->nproperties)))
return false;
js_free(key->properties);
js_free(entry->types);

View File

@ -23,6 +23,7 @@
#include "jsscript.h"
#include "gc/Marking.h"
#include "gc/Policy.h"
#include "gc/Rooting.h"
#include "js/Vector.h"
#include "vm/Debugger.h"

View File

@ -13,9 +13,8 @@
#include "jsiter.h"
#include "builtin/ModuleObject.h"
#include "frontend/ParseNode.h"
#include "gc/Policy.h"
#include "vm/ArgumentsObject.h"
#include "vm/GlobalObject.h"
#include "vm/ProxyObject.h"

View File

@ -31,6 +31,7 @@
#include "builtin/TypedObject.h"
#include "builtin/WeakSetObject.h"
#include "gc/Marking.h"
#include "gc/Policy.h"
#include "jit/AtomicOperations.h"
#include "jit/InlinableNatives.h"
#include "js/Date.h"