Bug 994163 - TraceLoggeing: Fix --disable-threadsafe builds, r=bbouvier

This commit is contained in:
Hannes Verschore 2014-04-11 23:33:20 +02:00
parent 6d68487619
commit b69446b27b
6 changed files with 34 additions and 17 deletions

View File

@ -194,7 +194,7 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco
if (cx->isJSContext())
logger = TraceLoggerForMainThread(cx->asJSContext()->runtime());
else
logger = TraceLoggerForThread(PR_GetCurrentThread());
logger = TraceLoggerForCurrentThread();
uint32_t logId = js::TraceLogCreateTextId(logger, options);
js::AutoTraceLog scriptLogger(logger, logId);
js::AutoTraceLog typeLogger(logger, TraceLogger::ParserCompileScript);

View File

@ -1257,7 +1257,7 @@ OptimizeMIR(MIRGenerator *mir)
if (GetIonContext()->runtime->onMainThread())
logger = TraceLoggerForMainThread(GetIonContext()->runtime);
else
logger = TraceLoggerForThread(PR_GetCurrentThread());
logger = TraceLoggerForCurrentThread();
if (!mir->compilingAsmJS()) {
if (!MakeMRegExpHoistable(graph))

View File

@ -2556,7 +2556,7 @@ GCHelperThread::threadLoop()
{
AutoLockGC lock(rt);
TraceLogger *logger = TraceLoggerForThread(PR_GetCurrentThread());
TraceLogger *logger = TraceLoggerForCurrentThread();
/*
* Even on the first iteration the state can be SHUTDOWN or SWEEPING if

View File

@ -797,7 +797,7 @@ WorkerThread::handleIonWorkload()
ionBuilder = WorkerThreadState().ionWorklist().popCopy();
TraceLogger *logger = TraceLoggerForThread(thread);
TraceLogger *logger = TraceLoggerForCurrentThread();
AutoTraceLog logScript(logger, TraceLogCreateTextId(logger, ionBuilder->script()));
AutoTraceLog logCompile(logger, TraceLogger::IonCompilation);

View File

@ -616,7 +616,7 @@ TraceLogging::TraceLogging()
lock = PR_NewLock();
if (!lock)
MOZ_CRASH();
#endif
#endif // JS_THREADSAFE
}
TraceLogging::~TraceLogging()
@ -627,6 +627,12 @@ TraceLogging::~TraceLogging()
out = nullptr;
}
for (size_t i = 0; i < mainThreadLoggers.length(); i++)
delete mainThreadLoggers[i];
mainThreadLoggers.clear();
#ifdef JS_THREADSAFE
if (threadLoggers.initialized()) {
for (ThreadLoggerHashMap::Range r = threadLoggers.all(); !r.empty(); r.popFront())
delete r.front().value();
@ -634,15 +640,11 @@ TraceLogging::~TraceLogging()
threadLoggers.finish();
}
for (size_t i = 0; i < mainThreadLoggers.length(); i++)
delete mainThreadLoggers[i];
mainThreadLoggers.clear();
if (lock) {
PR_DestroyLock(lock);
lock = nullptr;
}
#endif // JS_THREADSAFE
enabled = false;
}
@ -673,8 +675,10 @@ TraceLogging::lazyInit()
return false;
fprintf(out, "[");
#ifdef JS_THREADSAFE
if (!threadLoggers.init())
return false;
#endif // JS_THREADSAFE
const char *env = getenv("TLLOG");
if (!env)
@ -794,11 +798,17 @@ TraceLogging::forMainThread(PerThreadData *mainThread)
}
TraceLogger *
js::TraceLoggerForThread(PRThread *thread)
js::TraceLoggerForCurrentThread()
{
#ifdef JS_THREADSAFE
PRThread *thread = PR_GetCurrentThread();
return traceLoggers.forThread(thread);
#else
MOZ_ASSUME_UNREACHABLE("No threads supported. Use TraceLoggerForMainThread for the main thread.");
#endif // JS_THREADSAFE
}
#ifdef JS_THREADSAFE
TraceLogger *
TraceLogging::forThread(PRThread *thread)
{
@ -822,6 +832,7 @@ TraceLogging::forThread(PRThread *thread)
return logger;
}
#endif // JS_THREADSAFE
TraceLogger *
TraceLogging::create()

View File

@ -88,7 +88,7 @@ namespace jit {
* Logging something is done in 3 stages.
* 1) Get the tracelogger of the current thread.
* - TraceLoggerForMainThread(JSRuntime *)
* - TraceLoggerForThread(PR_GetCurrentThread());
* - TraceLoggerForCurrentThread(); // Should NOT be used for the mainthread.
* 2) Optionally create a textId for the text that needs to get logged. This
* step takes some time, so try to do this beforehand, outside the hot
* path and don't do unnecessary repetitions, since it will criple
@ -385,16 +385,20 @@ class TraceLogger
class TraceLogging
{
#ifdef JS_TRACE_LOGGING
#ifdef JS_THREADSAFE
typedef HashMap<PRThread *,
TraceLogger *,
PointerHasher<PRThread *, 3>,
SystemAllocPolicy> ThreadLoggerHashMap;
#endif // JS_THREADSAFE
typedef Vector<TraceLogger *, 1, js::SystemAllocPolicy > MainThreadLoggers;
bool initialized;
bool enabled;
bool enabledTextIds[TraceLogger::LAST];
#ifdef JS_THREADSAFE
ThreadLoggerHashMap threadLoggers;
#endif // JS_THREADSAFE
MainThreadLoggers mainThreadLoggers;
uint32_t loggerId;
FILE *out;
@ -403,14 +407,16 @@ class TraceLogging
uint64_t startupTime;
#ifdef JS_THREADSAFE
PRLock *lock;
#endif
#endif // JS_THREADSAFE
TraceLogging();
~TraceLogging();
TraceLogger *forMainThread(JSRuntime *runtime);
TraceLogger *forMainThread(jit::CompileRuntime *runtime);
#ifdef JS_THREADSAFE
TraceLogger *forThread(PRThread *thread);
#endif // JS_THREADSAFE
bool isTextIdEnabled(uint32_t textId) {
if (textId < TraceLogger::LAST)
@ -428,7 +434,7 @@ class TraceLogging
#ifdef JS_TRACE_LOGGING
TraceLogger *TraceLoggerForMainThread(JSRuntime *runtime);
TraceLogger *TraceLoggerForMainThread(jit::CompileRuntime *runtime);
TraceLogger *TraceLoggerForThread(PRThread *thread);
TraceLogger *TraceLoggerForCurrentThread();
#else
inline TraceLogger *TraceLoggerForMainThread(JSRuntime *runtime) {
return nullptr;
@ -436,7 +442,7 @@ inline TraceLogger *TraceLoggerForMainThread(JSRuntime *runtime) {
inline TraceLogger *TraceLoggerForMainThread(jit::CompileRuntime *runtime) {
return nullptr;
};
inline TraceLogger *TraceLoggerForThread(PRThread *thread) {
inline TraceLogger *TraceLoggerForCurrentThread() {
return nullptr;
};
#endif
@ -554,12 +560,12 @@ class AutoTraceLoggingLock
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
#ifdef JS_THREADSAFE
PR_Lock(logging->lock);
#endif
#endif // JS_THREADSAFE
}
~AutoTraceLoggingLock() {
#ifdef JS_THREADSAFE
PR_Unlock(logging->lock);
#endif
#endif // JS_THREADSAFE
}
private:
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER