Bug 916986 - Implement a JSAutoAssertNoGC for the analysis to pay attention to, r=terrence

This commit is contained in:
Steve Fink 2013-09-17 10:50:03 -07:00
Родитель d4b22fae39
Коммит 016400d5a3
2 изменённых файлов: 35 добавлений и 0 удалений

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

@ -208,6 +208,19 @@ PokeGC(JSRuntime *rt);
extern JS_FRIEND_API(bool)
WasIncrementalGC(JSRuntime *rt);
extern JS_FRIEND_API(size_t)
GetGCNumber();
class AutoAssertNoGC {
#ifdef DEBUG
size_t gcNumber;
public:
AutoAssertNoGC();
~AutoAssertNoGC();
#endif
};
class JS_PUBLIC_API(ObjectPtr)
{
Heap<JSObject *> value;

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

@ -5219,4 +5219,26 @@ JS::AssertGCThingMustBeTenured(JSObject *obj)
JS_ASSERT((!IsNurseryAllocable(obj->tenuredGetAllocKind()) || obj->getClass()->finalize) &&
obj->isTenured());
}
JS_FRIEND_API(size_t)
JS::GetGCNumber()
{
JSRuntime *rt = js::TlsPerThreadData.get()->runtimeFromMainThread();
if (!rt)
return 0;
return rt->gcNumber;
}
JS::AutoAssertNoGC::AutoAssertNoGC()
{
JSRuntime *rt = js::TlsPerThreadData.get()->runtimeFromMainThread();
gcNumber = rt ? rt->gcNumber : size_t(-1);
}
JS::AutoAssertNoGC::~AutoAssertNoGC()
{
JSRuntime *rt = js::TlsPerThreadData.get()->runtimeFromMainThread();
if (rt)
MOZ_ASSERT(gcNumber == rt->gcNumber, "GC ran inside an AutoAssertNoGC scope");
}
#endif