Changeset 162774 in webkit
- Timestamp:
- Jan 25, 2014 11:24:14 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r162765 r162774 1 2014-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 1 27 2014-01-25 Darin Adler <darin@apple.com> 2 28 -
trunk/Source/WTF/wtf/DynamicAnnotations.h
r111778 r162774 27 27 #ifndef WTF_DynamicAnnotations_h 28 28 #define WTF_DynamicAnnotations_h 29 30 #include <wtf/Platform.h> 29 31 30 32 /* This file defines dynamic annotations for use with dynamic analysis -
trunk/Source/WTF/wtf/HashTable.cpp
r161849 r162774 28 28 #if DUMP_HASHTABLE_STATS 29 29 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; 30 std::atomic<unsigned> HashTableStats::numAccesses; 31 std::atomic<unsigned> HashTableStats::numRehashes; 32 std::atomic<unsigned> HashTableStats::numRemoves; 33 std::atomic<unsigned> HashTableStats::numReinserts; 34 35 unsigned HashTableStats::numCollisions; 36 unsigned HashTableStats::collisionGraph[4096]; 37 unsigned HashTableStats::maxCollisions; 37 38 38 39 static std::mutex& hashTableStatsMutex() … … 47 48 } 48 49 49 void HashTableStats::recordCollisionAtCount( intcount)50 void HashTableStats::recordCollisionAtCount(unsigned count) 50 51 { 51 52 std::lock_guard<std::mutex> lock(hashTableStatsMutex()); … … 62 63 63 64 dataLogF("\nWTF::HashTable statistics\n\n"); 64 dataLogF("% d accesses\n", numAccesses);65 dataLogF("%u accesses\n", numAccesses.load()); 65 66 dataLogF("%d total collisions, average %.2f probes per access\n", numCollisions, 1.0 * (numAccesses + numCollisions) / numAccesses); 66 67 dataLogF("longest collision chain: %d\n", maxCollisions); 67 for ( inti = 1; i <= maxCollisions; i++) {68 dataLogF(" % d lookups with exactly %dcollisions (%.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); 69 70 } 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()); 72 73 } 73 74 -
trunk/Source/WTF/wtf/HashTable.h
r156968 r162774 23 23 #define WTF_HashTable_h 24 24 25 #include <atomic> 26 #include <mutex> 25 27 #include <string.h> 26 28 #include <type_traits> … … 30 32 #include <wtf/HashTraits.h> 31 33 #include <wtf/StdLibExtras.h> 32 #include <wtf/Threading.h>33 34 #include <wtf/ValueCheck.h> 34 35 #ifndef NDEBUG36 // Required for CHECK_HASHTABLE_ITERATORS.37 #include <wtf/OwnPtr.h>38 #include <wtf/PassOwnPtr.h>39 #endif40 35 41 36 #define DUMP_HASHTABLE_STATS 0 … … 63 58 struct HashTableStats { 64 59 // The following variables are all atomically incremented when modified. 65 WTF_EXPORTDATA static intnumAccesses;66 WTF_EXPORTDATA static intnumRehashes;67 WTF_EXPORTDATA static intnumRemoves;68 WTF_EXPORTDATA static intnumReinserts;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; 69 64 70 65 // The following variables are only modified in the recordCollisionAtCount method within a mutex. 71 WTF_EXPORTDATA static intmaxCollisions;72 WTF_EXPORTDATA static intnumCollisions;73 WTF_EXPORTDATA static intcollisionGraph[4096];74 75 WTF_EXPORT_PRIVATE static void recordCollisionAtCount( intcount);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); 76 71 WTF_EXPORT_PRIVATE static void dumpStats(); 77 72 }; … … 484 479 mutable const_iterator* m_iterators; 485 480 // 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; 487 482 #endif 488 483 489 484 #if DUMP_HASHTABLE_STATS_PER_TABLE 490 485 public: 491 mutable OwnPtr<Stats> m_stats;486 mutable std::unique_ptr<Stats> m_stats; 492 487 #endif 493 488 }; … … 540 535 #if CHECK_HASHTABLE_ITERATORS 541 536 , m_iterators(0) 542 , m_mutex(std::make_unique< Mutex>())537 , m_mutex(std::make_unique<std::mutex>()) 543 538 #endif 544 539 #if DUMP_HASHTABLE_STATS_PER_TABLE … … 600 595 601 596 #if DUMP_HASHTABLE_STATS 602 atomicIncrement(&HashTableStats::numAccesses);603 intprobeCount = 0;597 ++HashTableStats::numAccesses; 598 unsigned probeCount = 0; 604 599 #endif 605 600 606 601 #if DUMP_HASHTABLE_STATS_PER_TABLE 607 602 ++m_stats->numAccesses; 608 int perTableProbeCount = 0;609 603 #endif 610 604 … … 632 626 633 627 #if DUMP_HASHTABLE_STATS_PER_TABLE 634 ++perTableProbeCount; 635 m_stats->recordCollisionAtCount(perTableProbeCount); 628 m_stats->recordCollisionAtCount(probeCount); 636 629 #endif 637 630 … … 656 649 657 650 #if DUMP_HASHTABLE_STATS 658 atomicIncrement(&HashTableStats::numAccesses);651 ++HashTableStats::numAccesses; 659 652 int probeCount = 0; 660 653 #endif … … 662 655 #if DUMP_HASHTABLE_STATS_PER_TABLE 663 656 ++m_stats->numAccesses; 664 int perTableProbeCount = 0;665 657 #endif 666 658 … … 695 687 696 688 #if DUMP_HASHTABLE_STATS_PER_TABLE 697 ++perTableProbeCount; 698 m_stats->recordCollisionAtCount(perTableProbeCount); 689 m_stats->recordCollisionAtCount(probeCount); 699 690 #endif 700 691 … … 719 710 720 711 #if DUMP_HASHTABLE_STATS 721 atomicIncrement(&HashTableStats::numAccesses);722 intprobeCount = 0;712 ++HashTableStats::numAccesses; 713 unsigned probeCount = 0; 723 714 #endif 724 715 725 716 #if DUMP_HASHTABLE_STATS_PER_TABLE 726 717 ++m_stats->numAccesses; 727 int perTableProbeCount = 0;728 718 #endif 729 719 … … 758 748 759 749 #if DUMP_HASHTABLE_STATS_PER_TABLE 760 ++perTableProbeCount; 761 m_stats->recordCollisionAtCount(perTableProbeCount); 750 m_stats->recordCollisionAtCount(probeCount); 762 751 #endif 763 752 … … 815 804 816 805 #if DUMP_HASHTABLE_STATS 817 atomicIncrement(&HashTableStats::numAccesses);818 intprobeCount = 0;806 ++HashTableStats::numAccesses; 807 unsigned probeCount = 0; 819 808 #endif 820 809 821 810 #if DUMP_HASHTABLE_STATS_PER_TABLE 822 811 ++m_stats->numAccesses; 823 int perTableProbeCount = 0;824 812 #endif 825 813 … … 854 842 855 843 #if DUMP_HASHTABLE_STATS_PER_TABLE 856 ++perTableProbeCount; 857 m_stats->recordCollisionAtCount(perTableProbeCount); 844 m_stats->recordCollisionAtCount(probeCount); 858 845 #endif 859 846 … … 925 912 ASSERT(!isDeletedBucket(*(lookupForWriting(Extractor::extract(entry)).first))); 926 913 #if DUMP_HASHTABLE_STATS 927 atomicIncrement(&HashTableStats::numReinserts);914 ++HashTableStats::numReinserts; 928 915 #endif 929 916 #if DUMP_HASHTABLE_STATS_PER_TABLE … … 995 982 { 996 983 #if DUMP_HASHTABLE_STATS 997 atomicIncrement(&HashTableStats::numRemoves);984 ++HashTableStats::numRemoves; 998 985 #endif 999 986 #if DUMP_HASHTABLE_STATS_PER_TABLE … … 1091 1078 #if DUMP_HASHTABLE_STATS 1092 1079 if (oldTableSize != 0) 1093 atomicIncrement(&HashTableStats::numRehashes);1080 ++HashTableStats::numRehashes; 1094 1081 #endif 1095 1082 … … 1148 1135 #if CHECK_HASHTABLE_ITERATORS 1149 1136 , m_iterators(0) 1150 , m_mutex(std::make_unique< Mutex>())1137 , m_mutex(std::make_unique<std::mutex>()) 1151 1138 #endif 1152 1139 #if DUMP_HASHTABLE_STATS_PER_TABLE … … 1253 1240 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::invalidateIterators() 1254 1241 { 1255 MutexLockerlock(*m_mutex);1242 std::lock_guard<std::mutex> lock(*m_mutex); 1256 1243 const_iterator* next; 1257 1244 for (const_iterator* p = m_iterators; p; p = next) { … … 1275 1262 it->m_next = 0; 1276 1263 } else { 1277 MutexLockerlock(*table->m_mutex);1264 std::lock_guard<std::mutex> lock(*table->m_mutex); 1278 1265 ASSERT(table->m_iterators != it); 1279 1266 it->m_next = table->m_iterators; … … 1297 1284 ASSERT(!it->m_previous); 1298 1285 } else { 1299 MutexLockerlock(*it->m_table->m_mutex);1286 std::lock_guard<std::mutex> lock(*it->m_table->m_mutex); 1300 1287 if (it->m_next) { 1301 1288 ASSERT(it->m_next->m_previous == it); -
trunk/Source/WebCore/ChangeLog
r162773 r162774 1 2014-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 1 16 2014-01-25 Zan Dobersek <zdobersek@igalia.com> 2 17 -
trunk/Source/WebCore/platform/DragData.h
r162451 r162774 75 75 76 76 #if PLATFORM(WIN) 77 typedef HashMap< UINT, Vector<String>> DragDataMap;77 typedef HashMap<unsigned, Vector<String>> DragDataMap; 78 78 #endif 79 79 -
trunk/Source/WebCore/platform/audio/AudioSession.h
r162368 r162774 31 31 #include <memory> 32 32 #include <wtf/HashSet.h> 33 #include <wtf/Noncopyable.h> 33 34 34 35 namespace WebCore { -
trunk/Source/WebCore/platform/network/cf/SocketStreamHandle.h
r162235 r162774 36 36 #include "SocketStreamHandleBase.h" 37 37 #include <wtf/RetainPtr.h> 38 #include <wtf/ThreadSafeRefCounted.h> 38 39 39 40 typedef struct __CFHTTPMessage* CFHTTPMessageRef; -
trunk/Source/WebCore/platform/win/WindowMessageBroadcaster.h
r76248 r162774 32 32 #include <wtf/HashMap.h> 33 33 #include <wtf/HashSet.h> 34 #include <wtf/Noncopyable.h> 34 35 35 36 namespace WebCore { -
trunk/Source/WebCore/rendering/svg/SVGResourcesCycleSolver.h
r159000 r162774 23 23 #if ENABLE(SVG) 24 24 #include <wtf/HashSet.h> 25 #include <wtf/Noncopyable.h> 25 26 26 27 namespace WebCore { -
trunk/Source/WebKit/win/ChangeLog
r162745 r162774 1 2014-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 1 12 2014-01-24 Anders Carlsson <andersca@apple.com> 2 13 -
trunk/Source/WebKit/win/WebLocalizableStrings.cpp
r152143 r162774 37 37 #include <wtf/RetainPtr.h> 38 38 #include <wtf/StdLibExtras.h> 39 #include <wtf/ThreadingPrimitives.h> 39 40 #include <CoreFoundation/CoreFoundation.h> 40 41 -
trunk/Source/WebKit2/ChangeLog
r162768 r162774 1 2014-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 1 12 2014-01-25 Zan Dobersek <zdobersek@igalia.com> 2 13 -
trunk/Source/WebKit2/Shared/BlockingResponseMap.h
r161005 r162774 29 29 #include <condition_variable> 30 30 #include <wtf/HashMap.h> 31 #include <wtf/Noncopyable.h> 31 32 32 33 template<typename T> -
trunk/Tools/ChangeLog
r162733 r162774 1 2014-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 1 12 2014-01-24 Eric Carlson <eric.carlson@apple.com> 2 13 -
trunk/Tools/DumpRenderTree/JavaScriptThreading.cpp
r149843 r162774 37 37 #include <wtf/Assertions.h> 38 38 #include <wtf/HashSet.h> 39 #include <wtf/Threading.h> 40 #include <wtf/ThreadingPrimitives.h> 39 41 #include <wtf/Vector.h> 40 42
Note: See TracChangeset
for help on using the changeset viewer.