Ignore:
Timestamp:
Jan 22, 2010, 2:00:37 PM (15 years ago)
Author:
[email protected]
Message:

Fix the leak of ThreadIdentifiers in threadMap across threads.
https://bugs.webkit.org/show_bug.cgi?id=32689

Reviewed by Maciej Stachowiak.

JavaScriptCore:

Test is added to DumpRenderTree.mm.

  • Android.mk: Added file ThreadIdentifierDataPthreads.(h|cpp) to build.
  • Android.v8.wtf.mk: Ditto.
  • GNUmakefile.am: Ditto.
  • JavaScriptCore.gyp/JavaScriptCore.gyp: Ditto.
  • JavaScriptCore.gypi: Ditto.
  • JavaScriptCore.xcodeproj/project.pbxproj: Ditto.
  • wtf/ThreadIdentifierDataPthreads.cpp: Added. Contains custom implementation of thread-specific data that uses custom destructor.

(WTF::ThreadIdentifierData::~ThreadIdentifierData): Removes the ThreadIdentifier from the threadMap.
(WTF::ThreadIdentifierData::identifier):
(WTF::ThreadIdentifierData::initialize):
(WTF::ThreadIdentifierData::destruct): Custom thread-specific destructor. Resets the value for the key again to cause second invoke.
(WTF::ThreadIdentifierData::initializeKeyOnceHelper):
(WTF::ThreadIdentifierData::initializeKeyOnce): Need to use pthread_once since initialization may come on any thread(s).

  • wtf/ThreadIdentifierDataPthreads.h: Added.

(WTF::ThreadIdentifierData::ThreadIdentifierData):

  • wtf/Threading.cpp:

(WTF::threadEntryPoint): Move initializeCurrentThreadInternal to after the lock to make

sure it is invoked when ThreadIdentifier is already established.

  • wtf/Threading.h: Rename setThreadNameInternal -> initializeCurrentThreadInternal since it does more then only set the name now.
  • wtf/ThreadingNone.cpp:

(WTF::initializeCurrentThreadInternal): Ditto.

  • wtf/ThreadingWin.cpp:

(WTF::initializeCurrentThreadInternal): Ditto.
(WTF::initializeThreading): Ditto.

  • wtf/gtk/ThreadingGtk.cpp:

(WTF::initializeCurrentThreadInternal): Ditto.

  • wtf/qt/ThreadingQt.cpp:

(WTF::initializeCurrentThreadInternal): Ditto.

  • wtf/ThreadingPthreads.cpp:

(WTF::establishIdentifierForPthreadHandle):
(WTF::clearPthreadHandleForIdentifier): Make it not 'static' so the ~ThreadIdentifierData() in another file can call it.
(WTF::initializeCurrentThreadInternal): Set the thread-specific data. The ThreadIdentifier is already established by creating thread.
(WTF::waitForThreadCompletion): Remove call to clearPthreadHandleForIdentifier(threadID) since it is now done in ~ThreadIdentifierData().
(WTF::detachThread): Ditto.
(WTF::currentThread): Use the thread-specific data to get the ThreadIdentifier. It's many times faster then Mutex-protected iteration through the map.

Also, set the thread-specific data if called first time on the thread.

WebKitTools:

Add a new test to verify the ThreadIdentifiers are not reused across threads.
The test runs in the beginning of DumpRenderTree and spawns 2 non-WTF treads sequentially,
waiting for the previous thread to terminate before starting the next.
The treads use WTF::currentThread() in their thread function. Without a fix, this
causes both threads to have the same ThreadIdentifier which triggers ASSERT in thread function.
It also starts another thread using WTF. Without the fix, this finds pthread handle from previous
threads in the WTF threadMap and asserts in WTF::establishIdentifierForPthreadHandle().
The test practically does not affect the DRT run time because the threads end immediately.

  • DumpRenderTree/mac/DumpRenderTree.mm:

(runThread): Test thread function.
(testThreadIdentifierMap):
(dumpRenderTree):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r52776 r53714  
    178178                180B9B080F16D94F009BDBC5 /* CurrentTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 180B9AF00F16C569009BDBC5 /* CurrentTime.h */; settings = {ATTRIBUTES = (Private, ); }; };
    179179                180B9BFE0F16E94D009BDBC5 /* CurrentTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 180B9AEF0F16C569009BDBC5 /* CurrentTime.cpp */; };
     180                18BAB55310DAE054000D945B /* ThreadIdentifierDataPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18BAB52710DADFCD000D945B /* ThreadIdentifierDataPthreads.cpp */; };
     181                18BAB55410DAE066000D945B /* ThreadIdentifierDataPthreads.h in Headers */ = {isa = PBXBuildFile; fileRef = 18BAB52810DADFCD000D945B /* ThreadIdentifierDataPthreads.h */; };
    180182                1C61516C0EBAC7A00031376F /* ProfilerServer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C61516A0EBAC7A00031376F /* ProfilerServer.mm */; settings = {COMPILER_FLAGS = "-fno-strict-aliasing"; }; };
    181183                1C61516D0EBAC7A00031376F /* ProfilerServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C61516B0EBAC7A00031376F /* ProfilerServer.h */; };
     
    655657                180B9AEF0F16C569009BDBC5 /* CurrentTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CurrentTime.cpp; sourceTree = "<group>"; };
    656658                180B9AF00F16C569009BDBC5 /* CurrentTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CurrentTime.h; sourceTree = "<group>"; };
     659                18BAB52710DADFCD000D945B /* ThreadIdentifierDataPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadIdentifierDataPthreads.cpp; sourceTree = "<group>"; };
     660                18BAB52810DADFCD000D945B /* ThreadIdentifierDataPthreads.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadIdentifierDataPthreads.h; sourceTree = "<group>"; };
    657661                1C61516A0EBAC7A00031376F /* ProfilerServer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ProfilerServer.mm; path = profiler/ProfilerServer.mm; sourceTree = "<group>"; };
    658662                1C61516B0EBAC7A00031376F /* ProfilerServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProfilerServer.h; path = profiler/ProfilerServer.h; sourceTree = "<group>"; };
     
    13721376                                6541BD7008E80A17002CBEE7 /* TCSystemAlloc.cpp */,
    13731377                                6541BD7108E80A17002CBEE7 /* TCSystemAlloc.h */,
     1378                                18BAB52710DADFCD000D945B /* ThreadIdentifierDataPthreads.cpp */,
     1379                                18BAB52810DADFCD000D945B /* ThreadIdentifierDataPthreads.h */,
    13741380                                5D6A566A0F05995500266145 /* Threading.cpp */,
    13751381                                E1EE79220D6C95CD00FEA3BA /* Threading.h */,
     
    20392045                                14A1563210966365006FA260 /* DateInstanceCache.h in Headers */,
    20402046                                1420BE7B10AA6DDB00F455D2 /* WeakRandom.h in Headers */,
     2047                                18BAB55410DAE066000D945B /* ThreadIdentifierDataPthreads.h in Headers */,
    20412048                                8698B86910D44D9400D8D01B /* StringBuilder.h in Headers */,
    20422049                                8698BB3910D86BAF00D8D01B /* UStringImpl.h in Headers */,
     
    24762483                                BCCF0D0C0EF0B8A500413C8F /* StructureStubInfo.cpp in Sources */,
    24772484                                14F8BA43107EC88C009892DC /* TCSystemAlloc.cpp in Sources */,
     2485                                18BAB55310DAE054000D945B /* ThreadIdentifierDataPthreads.cpp in Sources */,
    24782486                                5D6A566B0F05995500266145 /* Threading.cpp in Sources */,
    24792487                                E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.