Changeset 19245 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jan 29, 2007, 9:07:25 PM (18 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r19234 r19245 1 2007-01-29 Geoffrey Garen <[email protected]> 2 3 Reviewed by Maciej Stachowiak. 4 5 Fixed <rdar://problem/4485644> REGRESSION: JavaScriptCore has init routines 6 7 The TCMalloc module now initializes, if needed, inside GetCache() and 8 fastMallocSetIsMultiThreaded(). We leverage the same synchronization 9 technique used for enabling / disabling the single-threaded optimization 10 to synchronize initialization of the library without requiring a lock 11 for every malloc. 12 13 1,251 runs of tcmalloc_unittest, 2 runs of a custom, massively multi-threaded 14 tcmalloc_unittest, and my custom version of the PLT show no regressions. 15 Super-accurate JS iBench reports a .24% regression, which is right at the 16 limit of its error range, so I'm declaring victory. 17 18 * wtf/FastMalloc.cpp: 19 (WTF::fastMallocSetIsMultiThreaded): Initialize, if needed. (InitModule() 20 checks the "if needed" part.) 21 (WTF::TCMalloc_ThreadCache::GetCache): Restored original TCMalloc code 22 inside #ifdef, for posterity. Added new initialization logic. 23 (WTF::TCMalloc_ThreadCache::InitModule): Call InitTSD(), since we don't 24 have a static initializer to call it for us, now. This means that fastMalloc 25 is not usable as a general libc allocator, but it never was, and if it were 26 the general libc allocator, we wouldn't be here in the first place, so whatever. 27 (WTF::TCMalloc_ThreadCache::InitTSD): Don't try to take the pageheap_lock, 28 since InitModule already has it. 29 1 30 2007-01-29 Kevin McCullough <[email protected]> 2 31 -
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r19209 r19245 1392 1392 } 1393 1393 1394 #ifdef WTF_CHANGES 1394 1395 bool isMultiThreaded; 1395 1396 TCMalloc_ThreadCache *mainThreadCache; 1396 1397 1397 void fastMallocSetIsMultiThreaded() 1398 void fastMallocSetIsMultiThreaded() 1398 1399 { 1399 1400 // We lock when writing mainThreadCache but not when reading it. It's OK if … … 1403 1404 // clients must call this function before allocating on other threads, so they'll 1404 1405 // have synchronized before reading mainThreadCache. 1405 1406 // mainThreadCache is only set when isMultiThreaded is false, to save a 1407 // branch in some cases. 1408 1409 SpinLockHolder lock(&pageheap_lock); 1410 isMultiThreaded = true; 1411 mainThreadCache = 0; 1412 } 1406 1407 // A similar principle applies to isMultiThreaded. It's OK for the main thread 1408 // in GetCache() to read a stale, false value for isMultiThreaded because 1409 // doing so will just cause it to make an unnecessary call to InitModule(), 1410 // which will synchronize it. 1411 1412 // To save a branch in some cases, mainThreadCache is only set when 1413 // isMultiThreaded is false. 1414 1415 { 1416 SpinLockHolder lock(&pageheap_lock); 1417 isMultiThreaded = true; 1418 mainThreadCache = 0; 1419 } 1420 1421 TCMalloc_ThreadCache::InitModule(); 1422 } 1423 #endif 1413 1424 1414 1425 ALWAYS_INLINE TCMalloc_ThreadCache* TCMalloc_ThreadCache::GetCache() { 1415 1426 void* ptr = NULL; 1427 #ifndef WTF_CHANGES 1416 1428 if (!tsd_inited) { 1417 1429 InitModule(); 1418 1430 } else { 1419 if (mainThreadCache) 1420 ptr = mainThreadCache; 1421 else 1422 ptr = pthread_getspecific(heap_key); 1423 } 1431 ptr = pthread_getspecific(heap_key); 1432 } 1433 #else 1434 if (mainThreadCache) // fast path for single-threaded mode 1435 return mainThreadCache; 1436 1437 if (isMultiThreaded) // fast path for multi-threaded mode -- heap_key already initialized 1438 ptr = pthread_getspecific(heap_key); 1439 else // slow path for possible first-time init 1440 InitModule(); 1441 #endif 1424 1442 if (ptr == NULL) ptr = CreateCacheIfNecessary(); 1425 1443 return reinterpret_cast<TCMalloc_ThreadCache*>(ptr); … … 1458 1476 SpinLockHolder h(&pageheap_lock); 1459 1477 if (!phinited) { 1478 #ifdef WTF_CHANGES 1479 InitTSD(); 1480 #endif 1460 1481 InitSizeClasses(); 1461 1482 threadheap_allocator.Init(); … … 1481 1502 pthread_t zero; 1482 1503 memset(&zero, 0, sizeof(zero)); 1504 #ifndef WTF_CHANGES 1483 1505 SpinLockHolder h(&pageheap_lock); 1506 #else 1507 ASSERT(pageheap_lock.IsLocked()); 1508 #endif 1484 1509 for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) { 1485 1510 if (h->tid_ == zero) { … … 2053 2078 }; 2054 2079 2080 #ifndef WTF_CHANGES 2055 2081 static TCMallocGuard module_enter_exit_hook; 2056 2082 #endif 2057 2083 2058 2084 //------------------------------------------------------------------- -
trunk/JavaScriptCore/wtf/TCSpinLock.h
r13089 r19245 95 95 #endif 96 96 } 97 98 #ifdef WTF_CHANGES 99 inline bool IsLocked() { 100 return private_lockword_ != 0; 101 } 102 #endif 97 103 }; 98 104
Note:
See TracChangeset
for help on using the changeset viewer.