mzhaom / gperftools

Fast, multi-threaded malloc() and nifty performance analysis tools
https://code.google.com/p/gperftools/
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

SpinLock on Windows can get into a recursive stack #132

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Here is the basic stack trace of the loop:
    chrome.dll!_calloc_impl(unsigned int n=1, unsigned int size=532)  
Line 61 + 0x3 bytes C++
    chrome.dll!_calloc_crt(unsigned int count=1, unsigned int size=532)  
Line 61 + 0xf bytes C
    chrome.dll!_getptd_noexit()  Line 608 + 0xc bytes   C
    chrome.dll!_errno()  Line 282   C
    chrome.dll!SpinLock::SlowLock()  Line 75 + 0x5 bytes    C++
    chrome.dll!SpinLock::Lock()  Line 76    C++
    chrome.dll!SpinLockHolder::SpinLockHolder(SpinLock * l=0x04eda794)  
Line 150    C++
    chrome.dll!tcmalloc::ThreadCache::CreateCacheIfNecessary()  Line 
367 C++
    chrome.dll!tcmalloc::ThreadCache::GetCache()  Line 403 + 0xb bytes  
C++
    chrome.dll!`anonymous namespace'::do_malloc(unsigned int size=532)  
Line 623 + 0x5 bytes    C++
    chrome.dll!`anonymous namespace'::do_calloc(unsigned int n=1, 
unsigned int elem_size=532)  Line 645 + 0x9 bytes   C++
    chrome.dll!calloc(unsigned int n=1, unsigned int elem_size=532)  
Line 1023 + 0xd bytes   C++
    chrome.dll!_calloc_impl(unsigned int n=1, unsigned int size=532)  
Line 61 + 0xd bytes C++
    chrome.dll!_calloc_crt(unsigned int count=1, unsigned int size=532)  
Line 61 + 0xf bytes C
    chrome.dll!_getptd_noexit()  Line 608 + 0xc bytes   C
    chrome.dll!_errno()  Line 282   C
    chrome.dll!SpinLock::SlowLock()  Line 75 + 0x5 bytes    C++
    chrome.dll!SpinLock::Lock()  Line 76    C++
    chrome.dll!SpinLockHolder::SpinLockHolder(SpinLock * l=0x04eda794)  
Line 150    C++
    chrome.dll!tcmalloc::ThreadCache::CreateCacheIfNecessary()  Line 
367 C++
    chrome.dll!tcmalloc::ThreadCache::GetCache()  Line 403 + 0xb bytes  
C++
    chrome.dll!`anonymous namespace'::do_malloc(unsigned int size=532)  
Line 623 + 0x5 bytes    C++
    chrome.dll!`anonymous namespace'::do_calloc(unsigned int n=1, 
unsigned int elem_size=532)  Line 645 + 0x9 bytes   C++
    chrome.dll!calloc(unsigned int n=1, unsigned int elem_size=532)  
Line 1023 + 0xd bytes   C++
    chrome.dll!_calloc_impl(unsigned int n=1, unsigned int size=532)  
Line 61 + 0xd bytes C++
    chrome.dll!_calloc_crt(unsigned int count=1, unsigned int size=532)  
Line 61 + 0xf bytes C
    chrome.dll!_getptd_noexit()  Line 608 + 0xc bytes   C
    chrome.dll!_errno()  Line 282   C
    chrome.dll!SpinLock::SlowLock()  Line 75 + 0x5 bytes    C++
    chrome.dll!SpinLock::Lock()  Line 76    C++
    chrome.dll!SpinLockHolder::SpinLockHolder(SpinLock * l=0x04eda794)  
Line 150    C++
    chrome.dll!tcmalloc::ThreadCache::CreateCacheIfNecessary()  Line 
367 C++
    chrome.dll!tcmalloc::ThreadCache::GetCache()  Line 403 + 0xb bytes  
C++

The problem is that the SlowLock() case uses errno, which is really a macro 
to _errno() on windows, and that call can attempt to use the heap.

Original issue reported on code.google.com by mike%belshe.com@gtempaccount.com on 20 May 2009 at 8:31

GoogleCodeExporter commented 9 years ago
(This is using the latest SVN snapshot.)  As you suggest, the right fix is to 
not try
to preserve errno on windows in SlowLock.  I don't this SlowLock does anything 
to
change errno on windows, so that change should be safe.

Original comment by csilv...@gmail.com on 20 May 2009 at 6:30

GoogleCodeExporter commented 9 years ago
This should be fixed in perftools 1.3, just released.

Original comment by csilv...@gmail.com on 10 Jun 2009 at 2:04