Bug 1293419 - Make the trace logger use js::Thread instead of PRThread; r=terrence

This also introduces a hasher for js::Thread::Id.
This commit is contained in:
Nick Fitzgerald 2016-08-09 16:33:39 -07:00
Родитель 4a00e77409
Коммит dea6f2236e
5 изменённых файлов: 34 добавлений и 6 удалений

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

@ -9,6 +9,7 @@
#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/IndexSequence.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Tuple.h"
@ -36,8 +37,11 @@ class ThreadTrampoline;
class Thread
{
public:
struct Hasher;
class Id
{
friend struct Hasher;
class PlatformData;
void* platformData_[2];
@ -68,6 +72,18 @@ public:
size_t stackSize() const { return stackSize_; }
};
// A js::HashTable hash policy for keying hash tables by js::Thread::Id.
struct Hasher
{
typedef Id Lookup;
static HashNumber hash(const Lookup& l);
static bool match(const Id& key, const Lookup& lookup) {
return key == lookup;
}
};
// Create a Thread in an initially unjoinable state. A thread of execution can
// be created for this Thread by calling |init|. Some of the thread's
// properties may be controlled by passing options to this constructor.

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

@ -37,6 +37,12 @@ class js::Thread::Id::PlatformData
bool hasThread;
};
/* static */ js::HashNumber
js::Thread::Hasher::hash(const Lookup& l)
{
return mozilla::HashBytes(&l.platformData()->ptThread, sizeof(pthread_t));
}
inline js::Thread::Id::PlatformData*
js::Thread::Id::platformData()
{

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

@ -21,6 +21,12 @@ class js::Thread::Id::PlatformData
unsigned id;
};
/* static */ js::HashNumber
js::Thread::Hasher::hash(const Lookup& l)
{
return mozilla::HashBytes(l.platformData_, sizeof(l.platformData_));
}
inline js::Thread::Id::PlatformData*
js::Thread::Id::platformData()
{

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

@ -893,14 +893,13 @@ TraceLoggerThreadState::forMainThread(PerThreadData* mainThread)
TraceLoggerThread*
js::TraceLoggerForCurrentThread()
{
PRThread* thread = PR_GetCurrentThread();
if (!EnsureTraceLoggerState())
return nullptr;
return traceLoggerState->forThread(thread);
return traceLoggerState->forThread(ThisThread::GetId());
}
TraceLoggerThread*
TraceLoggerThreadState::forThread(PRThread* thread)
TraceLoggerThreadState::forThread(const Thread::Id& thread)
{
MOZ_ASSERT(initialized);

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

@ -16,6 +16,7 @@
#include "js/TypeDecls.h"
#include "js/Vector.h"
#include "threading/Mutex.h"
#include "threading/Thread.h"
#include "vm/TraceLoggingGraph.h"
#include "vm/TraceLoggingTypes.h"
@ -294,9 +295,9 @@ class TraceLoggerThread
class TraceLoggerThreadState
{
#ifdef JS_TRACE_LOGGING
typedef HashMap<PRThread*,
typedef HashMap<Thread::Id,
TraceLoggerThread*,
PointerHasher<PRThread*, 3>,
Thread::Hasher,
SystemAllocPolicy> ThreadLoggerHashMap;
typedef Vector<TraceLoggerThread*, 1, js::SystemAllocPolicy > MainThreadLoggers;
@ -330,7 +331,7 @@ class TraceLoggerThreadState
TraceLoggerThread* forMainThread(JSRuntime* runtime);
TraceLoggerThread* forMainThread(jit::CompileRuntime* runtime);
TraceLoggerThread* forThread(PRThread* thread);
TraceLoggerThread* forThread(const Thread::Id& thread);
bool isTextIdEnabled(uint32_t textId) {
if (textId < TraceLogger_Last)