Bug 988486 - Convert static functions to methods on GCRuntime r=terrence

This commit is contained in:
Jon Coppeard 2014-05-09 11:33:01 +01:00
Родитель cbcf60df5e
Коммит f746967097
9 изменённых файлов: 697 добавлений и 566 удалений

Просмотреть файл

@ -43,6 +43,7 @@ namespace gc {
typedef Vector<JS::Zone *, 4, SystemAllocPolicy> ZoneVector;
class MarkingValidator;
class AutoPrepareForTracing;
struct ConservativeGCData
{
@ -88,8 +89,77 @@ class GCRuntime
{
public:
GCRuntime(JSRuntime *rt);
bool init(uint32_t maxbytes);
void finish();
void setGCZeal(uint8_t zeal, uint32_t frequency);
template <typename T> bool addRoot(T *rp, const char *name, JSGCRootType rootType);
void removeRoot(void *rp);
void setMarkStackLimit(size_t limit);
bool isHeapBusy() { return heapState != js::Idle; }
bool isHeapMajorCollecting() { return heapState == js::MajorCollecting; }
bool isHeapMinorCollecting() { return heapState == js::MinorCollecting; }
bool isHeapCollecting() { return isHeapMajorCollecting() || isHeapMinorCollecting(); }
bool triggerGC(JS::gcreason::Reason reason);
bool triggerZoneGC(Zone *zone, JS::gcreason::Reason reason);
void maybeGC(Zone *zone);
void minorGC(JS::gcreason::Reason reason);
void minorGC(JSContext *cx, JS::gcreason::Reason reason);
void gcIfNeeded(JSContext *cx);
void collect(bool incremental, int64_t budget, JSGCInvocationKind gckind,
JS::gcreason::Reason reason);
void gcSlice(JSGCInvocationKind gckind, JS::gcreason::Reason reason, int64_t millis);
void runDebugGC();
private:
// For ArenaLists::allocateFromArenaInline()
friend class ArenaLists;
Chunk *pickChunk(Zone *zone);
inline bool wantBackgroundAllocation() const;
bool initGCZeal();
void recordNativeStackTopForGC();
void requestInterrupt(JS::gcreason::Reason reason);
bool gcCycle(bool incremental, int64_t budget, JSGCInvocationKind gckind,
JS::gcreason::Reason reason);
void budgetIncrementalGC(int64_t *budget);
void resetIncrementalGC(const char *reason);
void incrementalCollectSlice(int64_t budget, JS::gcreason::Reason reason,
JSGCInvocationKind gckind);
void pushZealSelectedObjects();
bool beginMarkPhase();
bool shouldPreserveJITCode(JSCompartment *comp, int64_t currentTime);
bool drainMarkStack(SliceBudget &sliceBudget, gcstats::Phase phase);
template <class CompartmentIterT> void markWeakReferences(gcstats::Phase phase);
void markWeakReferencesInCurrentGroup(gcstats::Phase phase);
template <class ZoneIterT, class CompartmentIterT> void markGrayReferences();
void markGrayReferencesInCurrentGroup();
void beginSweepPhase(bool lastGC);
void findZoneGroups();
void getNextZoneGroup();
void endMarkingZoneGroup();
void beginSweepingZoneGroup();
bool releaseObservedTypes();
void endSweepingZoneGroup();
bool sweepPhase(SliceBudget &sliceBudget);
void endSweepPhase(JSGCInvocationKind gckind, bool lastGC);
void sweepZones(FreeOp *fop, bool lastGC);
void computeNonIncrementalMarkingForValidation();
void validateIncrementalMarking();
void finishMarkingValidation();
#ifdef DEBUG
void checkForCompartmentMismatches();
void markAllWeakReferences(gcstats::Phase phase);
void markAllGrayReferences();
#endif
public: // Internal state, public for now
JSRuntime *rt;
/* Embedders can use this zone however they wish. */
JS::Zone *systemZone;
@ -228,7 +298,7 @@ class GCRuntime
*/
JS::Zone *zoneGroups;
JS::Zone *currentZoneGroup;
int sweepPhase;
int finalizePhase;
JS::Zone *sweepZone;
int sweepKindIndex;
bool abortSweepAfterCurrentGroup;
@ -326,11 +396,11 @@ class GCRuntime
bool validate;
bool fullCompartmentChecks;
JSGCCallback callback;
JSGCCallback gcCallback;
JS::GCSliceCallback sliceCallback;
JSFinalizeCallback finalizeCallback;
void *callbackData;
void *gcCallbackData;
/*
* Malloc counter to measure memory pressure for GC scheduling. It runs
@ -377,11 +447,13 @@ class GCRuntime
PRLock *lock;
mozilla::DebugOnly<PRThread *> lockOwner;
js::GCHelperThread helperThread;
ConservativeGCData conservativeGC;
friend class js::GCHelperThread;
js::GCHelperThread helperThread;
ConservativeGCData conservativeGC;
friend class js::gc::AutoPrepareForTracing; /* For recordNativeStackTopForGC(). */
friend class js::gc::MarkingValidator;
};
} /* namespace gc */

Просмотреть файл

@ -34,6 +34,7 @@ void SetGCZeal(JSRuntime *, uint8_t, uint32_t);
namespace gc {
class Cell;
class Collector;
class MinorCollectionTracer;
} /* namespace gc */
@ -150,6 +151,27 @@ class Nursery
return ((JS::shadow::Runtime *)runtime_)->gcNurseryEnd_;
}
#ifdef JS_GC_ZEAL
/*
* In debug and zeal builds, these bytes indicate the state of an unused
* segment of nursery-allocated memory.
*/
void enterZealMode() {
if (isEnabled())
numActiveChunks_ = NumNurseryChunks;
}
void leaveZealMode() {
if (isEnabled()) {
JS_ASSERT(isEmpty());
setCurrentChunk(0);
currentStart_ = start();
}
}
#else
void enterZealMode() {}
void leaveZealMode() {}
#endif
private:
/*
* The start and end pointers are stored under the runtime so that we can
@ -289,30 +311,8 @@ class Nursery
static void MinorGCCallback(JSTracer *trc, void **thingp, JSGCTraceKind kind);
#ifdef JS_GC_ZEAL
/*
* In debug and zeal builds, these bytes indicate the state of an unused
* segment of nursery-allocated memory.
*/
void enterZealMode() {
if (isEnabled())
numActiveChunks_ = NumNurseryChunks;
}
void leaveZealMode() {
if (isEnabled()) {
JS_ASSERT(isEmpty());
setCurrentChunk(0);
currentStart_ = start();
}
}
#else
void enterZealMode() {}
void leaveZealMode() {}
#endif
friend class gc::MinorCollectionTracer;
friend class jit::MacroAssembler;
friend void SetGCZeal(JSRuntime *, uint8_t, uint32_t);
};
} /* namespace js */

Просмотреть файл

@ -102,6 +102,7 @@ struct Zone : public JS::shadow::Zone,
{
private:
friend bool js::CurrentThreadCanAccessZone(Zone *zone);
friend class js::gc::GCRuntime;
public:
js::Allocator allocator;
@ -321,6 +322,7 @@ struct Zone : public JS::shadow::Zone,
private:
void sweepBreakpoints(js::FreeOp *fop);
void sweepCompartments(js::FreeOp *fop, bool keepAtleastOne, bool lastGC);
#ifdef JS_ION
js::jit::JitZone *jitZone_;

Просмотреть файл

@ -1907,8 +1907,8 @@ JS_PUBLIC_API(void)
JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb, void *data)
{
AssertHeapIsIdle(rt);
rt->gc.callback = cb;
rt->gc.callbackData = data;
rt->gc.gcCallback = cb;
rt->gc.gcCallbackData = data;
}
JS_PUBLIC_API(void)

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -89,8 +89,6 @@ class ChunkPool {
return emptyCount;
}
inline bool wantBackgroundAllocation(JSRuntime *rt) const;
/* Must be called with the GC lock taken. */
inline Chunk *get(JSRuntime *rt);

Просмотреть файл

@ -159,6 +159,7 @@ namespace js {
namespace gc {
class StoreBuffer;
void MarkPersistentRootedChains(JSTracer *);
void FinishPersistentRootedChains(JSRuntime *);
}
}
@ -212,7 +213,7 @@ struct Runtime
private:
template <typename Referent> friend class JS::PersistentRooted;
friend void js::gc::MarkPersistentRootedChains(JSTracer *);
friend void ::js_FinishGC(JSRuntime *rt);
friend void js::gc::FinishPersistentRootedChains(JSRuntime *rt);
mozilla::LinkedList<PersistentRootedFunction> functionPersistentRooteds;
mozilla::LinkedList<PersistentRootedId> idPersistentRooteds;

Просмотреть файл

@ -279,10 +279,7 @@ JSRuntime::init(uint32_t maxbytes)
if (!threadPool.init())
return false;
if (!js_InitGC(this, maxbytes))
return false;
if (!gc.marker.init(gcMode()))
if (!gc.init(maxbytes))
return false;
const char *size = getenv("JSGC_MARK_STACK_LIMIT");
@ -429,7 +426,7 @@ JSRuntime::~JSRuntime()
FinishRuntimeNumberState(this);
#endif
js_FinishGC(this);
gc.finish();
atomsCompartment_ = nullptr;
#ifdef JS_THREADSAFE

Просмотреть файл

@ -925,10 +925,10 @@ struct JSRuntime : public JS::shadow::Runtime,
gc.marker.setGCMode(mode);
}
bool isHeapBusy() { return gc.heapState != js::Idle; }
bool isHeapMajorCollecting() { return gc.heapState == js::MajorCollecting; }
bool isHeapMinorCollecting() { return gc.heapState == js::MinorCollecting; }
bool isHeapCollecting() { return isHeapMajorCollecting() || isHeapMinorCollecting(); }
bool isHeapBusy() { return gc.isHeapBusy(); }
bool isHeapMajorCollecting() { return gc.isHeapMajorCollecting(); }
bool isHeapMinorCollecting() { return gc.isHeapMinorCollecting(); }
bool isHeapCollecting() { return gc.isHeapCollecting(); }
#ifdef JS_GC_ZEAL
int gcZeal() { return gc.zealMode; }