X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/93a3786624b2768d89bfa27e46598dc64e2fb70a..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/profiler/ProfilerDatabase.cpp diff --git a/profiler/ProfilerDatabase.cpp b/profiler/ProfilerDatabase.cpp index a2fffd9..236a5c8 100644 --- a/profiler/ProfilerDatabase.cpp +++ b/profiler/ProfilerDatabase.cpp @@ -29,21 +29,18 @@ #include "CodeBlock.h" #include "JSONObject.h" #include "ObjectConstructor.h" -#include "Operations.h" +#include "JSCInlines.h" namespace JSC { namespace Profiler { -#if COMPILER(MINGW) || COMPILER(MSVC7_OR_LOWER) || OS(WINCE) -static int databaseCounter; -#else -static volatile int databaseCounter; -#endif -static SpinLock registrationLock = SPINLOCK_INITIALIZER; -static int didRegisterAtExit; +static std::atomic databaseCounter; + +static StaticSpinLock registrationLock; +static std::atomic didRegisterAtExit; static Database* firstDatabase; Database::Database(VM& vm) - : m_databaseID(atomicIncrement(&databaseCounter)) + : m_databaseID(++databaseCounter) , m_vm(vm) , m_shouldSaveAtExit(false) , m_nextRegisteredDatabase(0) @@ -60,6 +57,8 @@ Database::~Database() Bytecodes* Database::ensureBytecodesFor(CodeBlock* codeBlock) { + Locker locker(m_lock); + codeBlock = codeBlock->baselineVersion(); HashMap::iterator iter = m_bytecodesMap.find(codeBlock); @@ -76,19 +75,16 @@ Bytecodes* Database::ensureBytecodesFor(CodeBlock* codeBlock) void Database::notifyDestruction(CodeBlock* codeBlock) { + Locker locker(m_lock); + m_bytecodesMap.remove(codeBlock); } -PassRefPtr Database::newCompilation(Bytecodes* bytecodes, CompilationKind kind) +void Database::addCompilation(PassRefPtr compilation) { - RefPtr compilation = adoptRef(new Compilation(bytecodes, kind)); + ASSERT(!isCompilationThread()); + m_compilations.append(compilation); - return compilation.release(); -} - -PassRefPtr Database::newCompilation(CodeBlock* codeBlock, CompilationKind kind) -{ - return newCompilation(ensureBytecodesFor(codeBlock), kind); } JSValue Database::toJS(ExecState* exec) const @@ -118,7 +114,7 @@ String Database::toJSON() const bool Database::save(const char* filename) const { - OwnPtr out = FilePrintStream::open(filename, "w"); + auto out = FilePrintStream::open(filename, "w"); if (!out) return false; @@ -139,17 +135,17 @@ void Database::registerToSaveAtExit(const char* filename) void Database::addDatabaseToAtExit() { - if (atomicIncrement(&didRegisterAtExit) == 1) + if (++didRegisterAtExit == 1) atexit(atExitCallback); - TCMalloc_SpinLockHolder holder(®istrationLock); + SpinLockHolder holder(registrationLock); m_nextRegisteredDatabase = firstDatabase; firstDatabase = this; } void Database::removeDatabaseFromAtExit() { - TCMalloc_SpinLockHolder holder(®istrationLock); + SpinLockHolder holder(registrationLock); for (Database** current = &firstDatabase; *current; current = &(*current)->m_nextRegisteredDatabase) { if (*current != this) continue; @@ -167,7 +163,7 @@ void Database::performAtExitSave() const Database* Database::removeFirstAtExitDatabase() { - TCMalloc_SpinLockHolder holder(®istrationLock); + SpinLockHolder holder(registrationLock); Database* result = firstDatabase; if (result) { firstDatabase = result->m_nextRegisteredDatabase;