Ignore:
Timestamp:
Jul 24, 2013, 8:59:31 PM (12 years ago)
Author:
[email protected]
Message:

fourthTier: Profiler should be thread-safe
https://bugs.webkit.org/show_bug.cgi?id=115445

Reviewed by Geoffrey Garen.

Change the Profiler::Database API for Compilation creation so that we don't add
it to the Database until it's completely constructed. This prevents the Database
from seeing Compilations that are being concurrently constructed.

Change the Profiler::Database itself to do locking for creation of Bytecodes and
for modifying the map. This map may be consulted by both the main thread and the
concurrent thread.

  • dfg/DFGGraph.cpp:

(JSC::DFG::Graph::Graph):

  • dfg/DFGJITCompiler.cpp:

(JSC::DFG::JITCompiler::link):
(JSC::DFG::JITCompiler::linkFunction):

  • jit/JIT.cpp:

(JSC::JIT::privateCompile):

  • profiler/ProfilerBytecodes.h:
  • profiler/ProfilerDatabase.cpp:

(JSC::Profiler::Database::ensureBytecodesFor):
(JSC::Profiler::Database::notifyDestruction):
(JSC::Profiler::Database::addCompilation):

  • profiler/ProfilerDatabase.h:

(Database):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/profiler/ProfilerDatabase.h

    r148696 r153143  
    3636#include <wtf/PassRefPtr.h>
    3737#include <wtf/SegmentedVector.h>
     38#include <wtf/ThreadingPrimitives.h>
    3839#include <wtf/text/WTFString.h>
    3940
     
    5152    void notifyDestruction(CodeBlock*);
    5253   
    53     PassRefPtr<Compilation> newCompilation(CodeBlock*, CompilationKind);
    54     PassRefPtr<Compilation> newCompilation(Bytecodes*, CompilationKind);
     54    void addCompilation(PassRefPtr<Compilation>);
    5555   
    5656    // Converts the database to a JavaScript object that is suitable for JSON stringification.
     
    7171   
    7272private:
     73    // Use a full-blown adaptive mutex because:
     74    // - There is only one ProfilerDatabase per VM. The size overhead of the system's
     75    //   mutex is negligible if you only have one of them.
     76    // - It's locked infrequently - once per bytecode generation, compilation, and
     77    //   code block collection - so the fact that the fast path still requires a
     78    //   function call is neglible.
     79    // - It tends to be held for a while. Currently, we hold it while generating
     80    //   Profiler::Bytecodes for a CodeBlock. That's uncommon and shouldn't affect
     81    //   performance, but if we did have contention, we would want a sensible,
     82    //   power-aware backoff. An adaptive mutex will do this as a matter of course,
     83    //   but a spinlock won't.
     84    typedef Mutex Lock;
     85    typedef MutexLocker Locker;
     86   
    7387
    7488    void addDatabaseToAtExit();
     
    86100    CString m_atExitSaveFilename;
    87101    Database* m_nextRegisteredDatabase;
     102    Lock m_lock;
    88103};
    89104
Note: See TracChangeset for help on using the changeset viewer.