Changeset 162774 in webkit


Ignore:
Timestamp:
Jan 25, 2014 11:24:14 AM (10 years ago)
Author:
andersca@apple.com
Message:

Modernize HashTable threading code
https://bugs.webkit.org/show_bug.cgi?id=127621

Reviewed by Darin Adler.

Source/WebCore:

Explicitly include headers that used to be brought in by HashTable.h

  • platform/DragData.h:

Change a Windows-specific typedef to avoid having to include WindDef.h from a header.

  • platform/audio/AudioSession.h:
  • platform/network/cf/SocketStreamHandle.h:

Source/WebKit/win:

Explicitly include headers that used to be brought in by HashTable.h

  • WebLocalizableStrings.cpp:

Source/WebKit2:

Explicitly include headers that used to be brought in by HashTable.h

  • Shared/BlockingResponseMap.h:

Source/WTF:

Use std::mutex and std::atomic instead of WTF threading primitives.

  • wtf/DynamicAnnotations.h:

Include Platform.h here since this file relies on USE macros.

  • wtf/HashTable.cpp:

(WTF::HashTableStats::recordCollisionAtCount):
Change this to take an unsigned.

(WTF::HashTableStats::dumpStats):

  • wtf/HashTable.h:

(WTF::KeyTraits>::HashTable):
(WTF::KeyTraits>::remove):
(WTF::KeyTraits>::invalidateIterators):
Use a single probe counter.

(WTF::addIterator):
(WTF::removeIterator):

Tools:

Explicitly include headers that used to be brought in by HashTable.h

  • DumpRenderTree/JavaScriptThreading.cpp:
Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r162765 r162774  
     12014-01-25  Anders Carlsson  <andersca@apple.com>
     2
     3        Modernize HashTable threading code
     4        https://bugs.webkit.org/show_bug.cgi?id=127621
     5
     6        Reviewed by Darin Adler.
     7
     8        Use std::mutex and std::atomic instead of WTF threading primitives.
     9
     10        * wtf/DynamicAnnotations.h:
     11        Include Platform.h here since this file relies on USE macros.
     12
     13        * wtf/HashTable.cpp:
     14        (WTF::HashTableStats::recordCollisionAtCount):
     15        Change this to take an unsigned.
     16
     17        (WTF::HashTableStats::dumpStats):
     18        * wtf/HashTable.h:
     19        (WTF::KeyTraits>::HashTable):
     20        (WTF::KeyTraits>::remove):
     21        (WTF::KeyTraits>::invalidateIterators):
     22        Use a single probe counter.
     23
     24        (WTF::addIterator):
     25        (WTF::removeIterator):
     26
    1272014-01-25  Darin Adler  <darin@apple.com>
    228
  • trunk/Source/WTF/wtf/DynamicAnnotations.h

    r111778 r162774  
    2727#ifndef WTF_DynamicAnnotations_h
    2828#define WTF_DynamicAnnotations_h
     29
     30#include <wtf/Platform.h>
    2931
    3032/* This file defines dynamic annotations for use with dynamic analysis
  • trunk/Source/WTF/wtf/HashTable.cpp

    r161849 r162774  
    2828#if DUMP_HASHTABLE_STATS
    2929
    30 int HashTableStats::numAccesses;
    31 int HashTableStats::numCollisions;
    32 int HashTableStats::collisionGraph[4096];
    33 int HashTableStats::maxCollisions;
    34 int HashTableStats::numRehashes;
    35 int HashTableStats::numRemoves;
    36 int HashTableStats::numReinserts;
     30std::atomic<unsigned> HashTableStats::numAccesses;
     31std::atomic<unsigned> HashTableStats::numRehashes;
     32std::atomic<unsigned> HashTableStats::numRemoves;
     33std::atomic<unsigned> HashTableStats::numReinserts;
     34
     35unsigned HashTableStats::numCollisions;
     36unsigned HashTableStats::collisionGraph[4096];
     37unsigned HashTableStats::maxCollisions;
    3738
    3839static std::mutex& hashTableStatsMutex()
     
    4748}
    4849
    49 void HashTableStats::recordCollisionAtCount(int count)
     50void HashTableStats::recordCollisionAtCount(unsigned count)
    5051{
    5152    std::lock_guard<std::mutex> lock(hashTableStatsMutex());
     
    6263
    6364    dataLogF("\nWTF::HashTable statistics\n\n");
    64     dataLogF("%d accesses\n", numAccesses);
     65    dataLogF("%u accesses\n", numAccesses.load());
    6566    dataLogF("%d total collisions, average %.2f probes per access\n", numCollisions, 1.0 * (numAccesses + numCollisions) / numAccesses);
    6667    dataLogF("longest collision chain: %d\n", maxCollisions);
    67     for (int i = 1; i <= maxCollisions; i++) {
    68         dataLogF("  %d lookups with exactly %d collisions (%.2f%% , %.2f%% with this many or more)\n", collisionGraph[i], i, 100.0 * (collisionGraph[i] - collisionGraph[i+1]) / numAccesses, 100.0 * collisionGraph[i] / numAccesses);
     68    for (unsigned i = 1; i <= maxCollisions; i++) {
     69        dataLogF("  %u lookups with exactly %u collisions (%.2f%% , %.2f%% with this many or more)\n", collisionGraph[i], i, 100.0 * (collisionGraph[i] - collisionGraph[i+1]) / numAccesses, 100.0 * collisionGraph[i] / numAccesses);
    6970    }
    70     dataLogF("%d rehashes\n", numRehashes);
    71     dataLogF("%d reinserts\n", numReinserts);
     71    dataLogF("%d rehashes\n", numRehashes.load());
     72    dataLogF("%d reinserts\n", numReinserts.load());
    7273}
    7374
  • trunk/Source/WTF/wtf/HashTable.h

    r156968 r162774  
    2323#define WTF_HashTable_h
    2424
     25#include <atomic>
     26#include <mutex>
    2527#include <string.h>
    2628#include <type_traits>
     
    3032#include <wtf/HashTraits.h>
    3133#include <wtf/StdLibExtras.h>
    32 #include <wtf/Threading.h>
    3334#include <wtf/ValueCheck.h>
    34 
    35 #ifndef NDEBUG
    36 // Required for CHECK_HASHTABLE_ITERATORS.
    37 #include <wtf/OwnPtr.h>
    38 #include <wtf/PassOwnPtr.h>
    39 #endif
    4035
    4136#define DUMP_HASHTABLE_STATS 0
     
    6358    struct HashTableStats {
    6459        // The following variables are all atomically incremented when modified.
    65         WTF_EXPORTDATA static int numAccesses;
    66         WTF_EXPORTDATA static int numRehashes;
    67         WTF_EXPORTDATA static int numRemoves;
    68         WTF_EXPORTDATA static int numReinserts;
     60        WTF_EXPORTDATA static std::atomic<unsigned> numAccesses;
     61        WTF_EXPORTDATA static std::atomic<unsigned> numRehashes;
     62        WTF_EXPORTDATA static std::atomic<unsigned> numRemoves;
     63        WTF_EXPORTDATA static std::atomic<unsigned> numReinserts;
    6964
    7065        // The following variables are only modified in the recordCollisionAtCount method within a mutex.
    71         WTF_EXPORTDATA static int maxCollisions;
    72         WTF_EXPORTDATA static int numCollisions;
    73         WTF_EXPORTDATA static int collisionGraph[4096];
    74 
    75         WTF_EXPORT_PRIVATE static void recordCollisionAtCount(int count);
     66        WTF_EXPORTDATA static unsigned maxCollisions;
     67        WTF_EXPORTDATA static unsigned numCollisions;
     68        WTF_EXPORTDATA static unsigned collisionGraph[4096];
     69
     70        WTF_EXPORT_PRIVATE static void recordCollisionAtCount(unsigned count);
    7671        WTF_EXPORT_PRIVATE static void dumpStats();
    7772    };
     
    484479        mutable const_iterator* m_iterators;
    485480        // Use OwnPtr so HashTable can still be memmove'd or memcpy'ed.
    486         mutable std::unique_ptr<Mutex> m_mutex;
     481        mutable std::unique_ptr<std::mutex> m_mutex;
    487482#endif
    488483
    489484#if DUMP_HASHTABLE_STATS_PER_TABLE
    490485    public:
    491         mutable OwnPtr<Stats> m_stats;
     486        mutable std::unique_ptr<Stats> m_stats;
    492487#endif
    493488    };
     
    540535#if CHECK_HASHTABLE_ITERATORS
    541536        , m_iterators(0)
    542         , m_mutex(std::make_unique<Mutex>())
     537        , m_mutex(std::make_unique<std::mutex>())
    543538#endif
    544539#if DUMP_HASHTABLE_STATS_PER_TABLE
     
    600595
    601596#if DUMP_HASHTABLE_STATS
    602         atomicIncrement(&HashTableStats::numAccesses);
    603         int probeCount = 0;
     597        ++HashTableStats::numAccesses;
     598        unsigned probeCount = 0;
    604599#endif
    605600
    606601#if DUMP_HASHTABLE_STATS_PER_TABLE
    607602        ++m_stats->numAccesses;
    608         int perTableProbeCount = 0;
    609603#endif
    610604
     
    632626
    633627#if DUMP_HASHTABLE_STATS_PER_TABLE
    634             ++perTableProbeCount;
    635             m_stats->recordCollisionAtCount(perTableProbeCount);
     628            m_stats->recordCollisionAtCount(probeCount);
    636629#endif
    637630
     
    656649
    657650#if DUMP_HASHTABLE_STATS
    658         atomicIncrement(&HashTableStats::numAccesses);
     651        ++HashTableStats::numAccesses;
    659652        int probeCount = 0;
    660653#endif
     
    662655#if DUMP_HASHTABLE_STATS_PER_TABLE
    663656        ++m_stats->numAccesses;
    664         int perTableProbeCount = 0;
    665657#endif
    666658
     
    695687
    696688#if DUMP_HASHTABLE_STATS_PER_TABLE
    697             ++perTableProbeCount;
    698             m_stats->recordCollisionAtCount(perTableProbeCount);
     689            m_stats->recordCollisionAtCount(probeCount);
    699690#endif
    700691
     
    719710
    720711#if DUMP_HASHTABLE_STATS
    721         atomicIncrement(&HashTableStats::numAccesses);
    722         int probeCount = 0;
     712        ++HashTableStats::numAccesses;
     713        unsigned probeCount = 0;
    723714#endif
    724715
    725716#if DUMP_HASHTABLE_STATS_PER_TABLE
    726717        ++m_stats->numAccesses;
    727         int perTableProbeCount = 0;
    728718#endif
    729719
     
    758748
    759749#if DUMP_HASHTABLE_STATS_PER_TABLE
    760             ++perTableProbeCount;
    761             m_stats->recordCollisionAtCount(perTableProbeCount);
     750            m_stats->recordCollisionAtCount(probeCount);
    762751#endif
    763752
     
    815804
    816805#if DUMP_HASHTABLE_STATS
    817         atomicIncrement(&HashTableStats::numAccesses);
    818         int probeCount = 0;
     806        ++HashTableStats::numAccesses;
     807        unsigned probeCount = 0;
    819808#endif
    820809
    821810#if DUMP_HASHTABLE_STATS_PER_TABLE
    822811        ++m_stats->numAccesses;
    823         int perTableProbeCount = 0;
    824812#endif
    825813
     
    854842
    855843#if DUMP_HASHTABLE_STATS_PER_TABLE
    856             ++perTableProbeCount;
    857             m_stats->recordCollisionAtCount(perTableProbeCount);
     844            m_stats->recordCollisionAtCount(probeCount);
    858845#endif
    859846
     
    925912        ASSERT(!isDeletedBucket(*(lookupForWriting(Extractor::extract(entry)).first)));
    926913#if DUMP_HASHTABLE_STATS
    927         atomicIncrement(&HashTableStats::numReinserts);
     914        ++HashTableStats::numReinserts;
    928915#endif
    929916#if DUMP_HASHTABLE_STATS_PER_TABLE
     
    995982    {
    996983#if DUMP_HASHTABLE_STATS
    997         atomicIncrement(&HashTableStats::numRemoves);
     984        ++HashTableStats::numRemoves;
    998985#endif
    999986#if DUMP_HASHTABLE_STATS_PER_TABLE
     
    10911078#if DUMP_HASHTABLE_STATS
    10921079        if (oldTableSize != 0)
    1093             atomicIncrement(&HashTableStats::numRehashes);
     1080            ++HashTableStats::numRehashes;
    10941081#endif
    10951082
     
    11481135#if CHECK_HASHTABLE_ITERATORS
    11491136        , m_iterators(0)
    1150         , m_mutex(std::make_unique<Mutex>())
     1137        , m_mutex(std::make_unique<std::mutex>())
    11511138#endif
    11521139#if DUMP_HASHTABLE_STATS_PER_TABLE
     
    12531240    void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::invalidateIterators()
    12541241    {
    1255         MutexLocker lock(*m_mutex);
     1242        std::lock_guard<std::mutex> lock(*m_mutex);
    12561243        const_iterator* next;
    12571244        for (const_iterator* p = m_iterators; p; p = next) {
     
    12751262            it->m_next = 0;
    12761263        } else {
    1277             MutexLocker lock(*table->m_mutex);
     1264            std::lock_guard<std::mutex> lock(*table->m_mutex);
    12781265            ASSERT(table->m_iterators != it);
    12791266            it->m_next = table->m_iterators;
     
    12971284            ASSERT(!it->m_previous);
    12981285        } else {
    1299             MutexLocker lock(*it->m_table->m_mutex);
     1286            std::lock_guard<std::mutex> lock(*it->m_table->m_mutex);
    13001287            if (it->m_next) {
    13011288                ASSERT(it->m_next->m_previous == it);
  • trunk/Source/WebCore/ChangeLog

    r162773 r162774  
     12014-01-25  Anders Carlsson  <andersca@apple.com>
     2
     3        Modernize HashTable threading code
     4        https://bugs.webkit.org/show_bug.cgi?id=127621
     5
     6        Reviewed by Darin Adler.
     7
     8        Explicitly include headers that used to be brought in by HashTable.h
     9
     10        * platform/DragData.h:
     11        Change a Windows-specific typedef to avoid having to include WindDef.h from a header.
     12
     13        * platform/audio/AudioSession.h:
     14        * platform/network/cf/SocketStreamHandle.h:
     15
    1162014-01-25  Zan Dobersek  <zdobersek@igalia.com>
    217
  • trunk/Source/WebCore/platform/DragData.h

    r162451 r162774  
    7575
    7676#if PLATFORM(WIN)
    77 typedef HashMap<UINT, Vector<String>> DragDataMap;
     77typedef HashMap<unsigned, Vector<String>> DragDataMap;
    7878#endif
    7979
  • trunk/Source/WebCore/platform/audio/AudioSession.h

    r162368 r162774  
    3131#include <memory>
    3232#include <wtf/HashSet.h>
     33#include <wtf/Noncopyable.h>
    3334
    3435namespace WebCore {
  • trunk/Source/WebCore/platform/network/cf/SocketStreamHandle.h

    r162235 r162774  
    3636#include "SocketStreamHandleBase.h"
    3737#include <wtf/RetainPtr.h>
     38#include <wtf/ThreadSafeRefCounted.h>
    3839
    3940typedef struct __CFHTTPMessage* CFHTTPMessageRef;
  • trunk/Source/WebCore/platform/win/WindowMessageBroadcaster.h

    r76248 r162774  
    3232#include <wtf/HashMap.h>
    3333#include <wtf/HashSet.h>
     34#include <wtf/Noncopyable.h>
    3435
    3536namespace WebCore {
  • trunk/Source/WebCore/rendering/svg/SVGResourcesCycleSolver.h

    r159000 r162774  
    2323#if ENABLE(SVG)
    2424#include <wtf/HashSet.h>
     25#include <wtf/Noncopyable.h>
    2526
    2627namespace WebCore {
  • trunk/Source/WebKit/win/ChangeLog

    r162745 r162774  
     12014-01-25  Anders Carlsson  <andersca@apple.com>
     2
     3        Modernize HashTable threading code
     4        https://bugs.webkit.org/show_bug.cgi?id=127621
     5
     6        Reviewed by Darin Adler.
     7
     8        Explicitly include headers that used to be brought in by HashTable.h
     9
     10        * WebLocalizableStrings.cpp:
     11
    1122014-01-24  Anders Carlsson  <andersca@apple.com>
    213
  • trunk/Source/WebKit/win/WebLocalizableStrings.cpp

    r152143 r162774  
    3737#include <wtf/RetainPtr.h>
    3838#include <wtf/StdLibExtras.h>
     39#include <wtf/ThreadingPrimitives.h>
    3940#include <CoreFoundation/CoreFoundation.h>
    4041
  • trunk/Source/WebKit2/ChangeLog

    r162768 r162774  
     12014-01-25  Anders Carlsson  <andersca@apple.com>
     2
     3        Modernize HashTable threading code
     4        https://bugs.webkit.org/show_bug.cgi?id=127621
     5
     6        Reviewed by Darin Adler.
     7
     8        Explicitly include headers that used to be brought in by HashTable.h
     9
     10        * Shared/BlockingResponseMap.h:
     11
    1122014-01-25  Zan Dobersek  <zdobersek@igalia.com>
    213
  • trunk/Source/WebKit2/Shared/BlockingResponseMap.h

    r161005 r162774  
    2929#include <condition_variable>
    3030#include <wtf/HashMap.h>
     31#include <wtf/Noncopyable.h>
    3132
    3233template<typename T>
  • trunk/Tools/ChangeLog

    r162733 r162774  
     12014-01-25  Anders Carlsson  <andersca@apple.com>
     2
     3        Modernize HashTable threading code
     4        https://bugs.webkit.org/show_bug.cgi?id=127621
     5
     6        Reviewed by Darin Adler.
     7
     8        Explicitly include headers that used to be brought in by HashTable.h
     9
     10        * DumpRenderTree/JavaScriptThreading.cpp:
     11
    1122014-01-24  Eric Carlson  <eric.carlson@apple.com>
    213
  • trunk/Tools/DumpRenderTree/JavaScriptThreading.cpp

    r149843 r162774  
    3737#include <wtf/Assertions.h>
    3838#include <wtf/HashSet.h>
     39#include <wtf/Threading.h>
     40#include <wtf/ThreadingPrimitives.h>
    3941#include <wtf/Vector.h>
    4042
Note: See TracChangeset for help on using the changeset viewer.