Bug 935800 - Assert that we do not GC in the lifetime of a ForkJoinSlice; r=shu

--HG--
extra : rebase_source : ec2dc1db758e5bef4720b5442e006e9df44c165b
This commit is contained in:
Terrence Cole 2013-11-06 15:43:19 -08:00
parent 09b5ae9027
commit ff9029bd4e
4 changed files with 17 additions and 6 deletions

View File

@ -215,15 +215,18 @@ GetGCNumber();
class JS_PUBLIC_API(AutoAssertNoGC)
{
#ifdef DEBUG
JSRuntime *runtime;
size_t gcNumber;
public:
AutoAssertNoGC();
AutoAssertNoGC(JSRuntime *rt);
~AutoAssertNoGC();
#else
public:
/* Prevent unreferenced local warnings in opt builds. */
AutoAssertNoGC() {}
AutoAssertNoGC(JSRuntime *) {}
#endif
};

View File

@ -5323,15 +5323,18 @@ JS::GetGCNumber()
}
JS::AutoAssertNoGC::AutoAssertNoGC()
: runtime(js::TlsPerThreadData.get()->runtimeFromMainThread())
{
gcNumber = runtime->gcNumber;
}
JS::AutoAssertNoGC::AutoAssertNoGC(JSRuntime *rt)
: runtime(rt), gcNumber(rt->gcNumber)
{
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");
MOZ_ASSERT(gcNumber == runtime->gcNumber, "GC ran inside an AutoAssertNoGC scope.");
}
#endif

View File

@ -1683,7 +1683,8 @@ ForkJoinSlice::ForkJoinSlice(PerThreadData *perThreadData,
numSlices(numSlices),
bailoutRecord(bailoutRecord),
shared(shared),
acquiredContext_(false)
acquiredContext_(false),
nogc_(shared->runtime())
{
/*
* Unsafely set the zone. This is used to track malloc counters and to

View File

@ -390,6 +390,10 @@ class ForkJoinSlice : public ThreadSafeContext
ForkJoinShared *const shared;
bool acquiredContext_;
// ForkJoinSlice is allocated on the stack. It would be dangerous to GC
// with it live because of the GC pointer fields stored in the context.
JS::AutoAssertNoGC nogc_;
};
// Locks a JSContext for its scope. Be very careful, because locking a