2013-06-18 12:02:07 -07:00
|
|
|
/* -*- 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 mozilla_CycleCollectedJSRuntime_h__
|
|
|
|
#define mozilla_CycleCollectedJSRuntime_h__
|
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
#include "jsprvtd.h"
|
2013-06-18 12:02:07 -07:00
|
|
|
#include "jsapi.h"
|
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-06-18 12:02:14 -07:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
class nsCycleCollectionNoteRootCallback;
|
2013-06-18 12:02:14 -07:00
|
|
|
class nsScriptObjectTracer;
|
|
|
|
|
2013-06-18 12:02:07 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
class JSGCThingParticipant: public nsCycleCollectionParticipant
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static NS_METHOD RootImpl(void *n)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD UnlinkImpl(void *n)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD UnrootImpl(void *n)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD_(void) UnmarkIfPurpleImpl(void *n)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD TraverseImpl(JSGCThingParticipant *that, void *n,
|
|
|
|
nsCycleCollectionTraversalCallback &cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
class JSZoneParticipant : public nsCycleCollectionParticipant
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
static NS_METHOD RootImpl(void *p)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD UnlinkImpl(void *p)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD UnrootImpl(void *p)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD_(void) UnmarkIfPurpleImpl(void *n)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_METHOD TraverseImpl(JSZoneParticipant *that, void *p,
|
|
|
|
nsCycleCollectionTraversalCallback &cb);
|
|
|
|
};
|
|
|
|
|
2013-06-18 12:02:07 -07:00
|
|
|
class CycleCollectedJSRuntime
|
|
|
|
{
|
2013-06-18 12:02:15 -07:00
|
|
|
friend class JSGCThingParticipant;
|
|
|
|
friend class JSZoneParticipant;
|
2013-06-18 12:02:07 -07:00
|
|
|
protected:
|
|
|
|
CycleCollectedJSRuntime(uint32_t aMaxbytes,
|
2013-06-18 12:02:15 -07:00
|
|
|
JSUseHelperThreads aUseHelperThreads,
|
|
|
|
bool aExpectRootedGlobals);
|
2013-06-18 12:02:07 -07:00
|
|
|
virtual ~CycleCollectedJSRuntime();
|
|
|
|
|
|
|
|
JSRuntime* Runtime() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mJSRuntime);
|
|
|
|
return mJSRuntime;
|
|
|
|
}
|
|
|
|
|
2013-06-18 12:02:16 -07:00
|
|
|
size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
|
|
|
|
void UnmarkSkippableJSHolders();
|
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
virtual void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& aCb) = 0;
|
2013-06-18 12:02:16 -07:00
|
|
|
virtual void TraceAdditionalNativeGrayRoots(JSTracer* aTracer) = 0;
|
2013-06-18 12:02:15 -07:00
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
private:
|
2013-06-18 12:02:15 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
DescribeGCThing(bool aIsMarked, void* aThing, JSGCTraceKind aTraceKind,
|
|
|
|
nsCycleCollectionTraversalCallback& aCb) const;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DescribeCustomObjects(JSObject* aObject, js::Class* aClasp,
|
|
|
|
char (&aName)[72]) const = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
NoteGCThingJSChildren(void* aThing, JSGCTraceKind aTraceKind,
|
|
|
|
nsCycleCollectionTraversalCallback& aCb) const;
|
|
|
|
|
|
|
|
void
|
|
|
|
NoteGCThingXPCOMChildren(js::Class* aClasp, JSObject* aObj,
|
|
|
|
nsCycleCollectionTraversalCallback& aCb) const;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
NoteCustomGCThingXPCOMChildren(js::Class* aClasp, JSObject* aObj,
|
|
|
|
nsCycleCollectionTraversalCallback& aCb) const = 0;
|
|
|
|
|
|
|
|
|
|
|
|
enum TraverseSelect {
|
|
|
|
TRAVERSE_CPP,
|
|
|
|
TRAVERSE_FULL
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
TraverseGCThing(TraverseSelect aTs, void* aThing,
|
|
|
|
JSGCTraceKind aTraceKind,
|
|
|
|
nsCycleCollectionTraversalCallback& aCb);
|
|
|
|
|
|
|
|
void
|
|
|
|
TraverseZone(JS::Zone* aZone, nsCycleCollectionTraversalCallback& aCb);
|
|
|
|
|
|
|
|
static void
|
|
|
|
TraverseObjectShim(void* aData, void* aThing);
|
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
void MaybeTraverseGlobals(nsCycleCollectionNoteRootCallback& aCb) const;
|
|
|
|
|
|
|
|
void TraverseNativeRoots(nsCycleCollectionNoteRootCallback& aCb);
|
2013-06-18 12:02:15 -07:00
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
void MaybeTraceGlobals(JSTracer* aTracer) const;
|
|
|
|
|
2013-06-18 12:02:16 -07:00
|
|
|
|
|
|
|
static void TraceBlackJS(JSTracer* aTracer, void* aData);
|
2013-06-18 12:02:15 -07:00
|
|
|
static void TraceGrayJS(JSTracer* aTracer, void* aData);
|
|
|
|
|
2013-06-18 12:02:16 -07:00
|
|
|
virtual void TraceNativeBlackRoots(JSTracer* aTracer) { };
|
|
|
|
void TraceNativeGrayRoots(JSTracer* aTracer);
|
2013-06-18 12:02:15 -07:00
|
|
|
|
2013-06-18 12:02:14 -07:00
|
|
|
public:
|
|
|
|
void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer);
|
|
|
|
void RemoveJSHolder(void* aHolder);
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool TestJSHolder(void* aHolder);
|
|
|
|
void SetObjectToUnlink(void* aObject) { mObjectToUnlink = aObject; }
|
|
|
|
void AssertNoObjectsToTrace(void* aPossibleJSHolder);
|
|
|
|
#endif
|
|
|
|
|
2013-06-18 12:02:15 -07:00
|
|
|
// This returns the singleton nsCycleCollectionParticipant for JSContexts.
|
2013-06-18 12:02:15 -07:00
|
|
|
static nsCycleCollectionParticipant* JSContextParticipant();
|
|
|
|
|
|
|
|
nsCycleCollectionParticipant* GCThingParticipant() const;
|
|
|
|
nsCycleCollectionParticipant* ZoneParticipant() const;
|
2013-06-18 12:02:15 -07:00
|
|
|
|
|
|
|
bool NotifyLeaveMainThread() const;
|
|
|
|
void NotifyEnterCycleCollectionThread() const;
|
|
|
|
void NotifyLeaveCycleCollectionThread() const;
|
|
|
|
void NotifyEnterMainThread() const;
|
|
|
|
nsresult BeginCycleCollection(nsCycleCollectionNoteRootCallback &aCb);
|
2013-06-18 12:02:16 -07:00
|
|
|
bool UsefulToMergeZones() const;
|
2013-06-18 12:02:15 -07:00
|
|
|
void FixWeakMappingGrayBits() const;
|
|
|
|
bool NeedCollect() const;
|
2013-06-18 12:02:16 -07:00
|
|
|
void Collect(uint32_t reason) const;
|
2013-06-18 12:02:15 -07:00
|
|
|
|
2013-06-19 14:06:50 -07:00
|
|
|
virtual void PrepareForForgetSkippable() {}
|
|
|
|
virtual void PrepareForCollection() {}
|
|
|
|
|
2013-06-18 12:02:07 -07:00
|
|
|
private:
|
2013-06-18 12:02:15 -07:00
|
|
|
typedef const CCParticipantVTable<JSGCThingParticipant>::Type GCThingParticipantVTable;
|
|
|
|
const GCThingParticipantVTable mGCThingCycleCollectorGlobal;
|
|
|
|
|
|
|
|
typedef const CCParticipantVTable<JSZoneParticipant>::Type JSZoneParticipantVTable;
|
|
|
|
const JSZoneParticipantVTable mJSZoneCycleCollectorGlobal;
|
|
|
|
|
2013-06-18 12:02:07 -07:00
|
|
|
JSRuntime* mJSRuntime;
|
2013-06-18 12:02:14 -07:00
|
|
|
|
2013-06-18 12:02:16 -07:00
|
|
|
nsDataHashtable<nsPtrHashKey<void>, nsScriptObjectTracer*> mJSHolders;
|
|
|
|
|
2013-06-18 12:02:14 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void* mObjectToUnlink;
|
2013-06-18 12:02:15 -07:00
|
|
|
bool mExpectUnrootedGlobals;
|
2013-06-18 12:02:14 -07:00
|
|
|
#endif
|
2013-06-18 12:02:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_CycleCollectedJSRuntime_h__
|