2013-06-18 23:02:07 +04: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__
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
2013-06-18 23:02:14 +04:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
2013-06-18 23:02:15 +04:00
|
|
|
class nsCycleCollectionNoteRootCallback;
|
2013-06-18 23:02:14 +04:00
|
|
|
class nsScriptObjectTracer;
|
|
|
|
|
2013-06-18 23:02:07 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class CycleCollectedJSRuntime
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
CycleCollectedJSRuntime(uint32_t aMaxbytes,
|
2013-06-18 23:02:15 +04:00
|
|
|
JSUseHelperThreads aUseHelperThreads,
|
|
|
|
bool aExpectRootedGlobals);
|
2013-06-18 23:02:07 +04:00
|
|
|
virtual ~CycleCollectedJSRuntime();
|
|
|
|
|
|
|
|
JSRuntime* Runtime() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mJSRuntime);
|
|
|
|
return mJSRuntime;
|
|
|
|
}
|
|
|
|
|
2013-06-18 23:02:15 +04:00
|
|
|
void MaybeTraceGlobals(JSTracer* aTracer) const;
|
2013-06-18 23:02:15 +04:00
|
|
|
virtual void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& aCb) = 0;
|
|
|
|
private:
|
|
|
|
void MaybeTraverseGlobals(nsCycleCollectionNoteRootCallback& aCb) const;
|
|
|
|
|
|
|
|
void TraverseNativeRoots(nsCycleCollectionNoteRootCallback& aCb);
|
2013-06-18 23:02:15 +04:00
|
|
|
|
2013-06-18 23:02:14 +04: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 23:02:15 +04:00
|
|
|
// This returns the singleton nsCycleCollectionParticipant for JSContexts.
|
|
|
|
static nsCycleCollectionParticipant *JSContextParticipant();
|
|
|
|
|
|
|
|
bool NotifyLeaveMainThread() const;
|
|
|
|
void NotifyEnterCycleCollectionThread() const;
|
|
|
|
void NotifyLeaveCycleCollectionThread() const;
|
|
|
|
void NotifyEnterMainThread() const;
|
|
|
|
nsresult BeginCycleCollection(nsCycleCollectionNoteRootCallback &aCb);
|
|
|
|
void FixWeakMappingGrayBits() const;
|
|
|
|
bool NeedCollect() const;
|
|
|
|
|
2013-06-18 23:02:14 +04:00
|
|
|
// XXXkhuey should be private
|
|
|
|
protected:
|
|
|
|
nsDataHashtable<nsPtrHashKey<void>, nsScriptObjectTracer*> mJSHolders;
|
|
|
|
|
2013-06-18 23:02:07 +04:00
|
|
|
private:
|
|
|
|
JSRuntime* mJSRuntime;
|
2013-06-18 23:02:14 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void* mObjectToUnlink;
|
2013-06-18 23:02:15 +04:00
|
|
|
bool mExpectUnrootedGlobals;
|
2013-06-18 23:02:14 +04:00
|
|
|
#endif
|
2013-06-18 23:02:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_CycleCollectedJSRuntime_h__
|