backtrace() vs. _Unwind_Backtrace()

Bryce McKinlay bryce@mckinlay.net.nz
Sat Dec 6 01:47:00 GMT 2003


On Dec 5, 2003, at 11:46 PM, Andrew Haley wrote:

> Java uses backtrace() a lot, and _Unwind_Backtrace() is inefficient.
> I see no good reason to switch unless backtrace() doesn't work on a
> given target.

I disagree - backtrace() tells us nothing. All it gives us is the IP 
for the frame. We need more: the start address of the function, or some 
other way to map to the Class and _Jv_Method that the frame belongs to. 
To get that we need to use the unwinder anyway!

Also, backtrace() is not flexible - for most of the checks that need to 
be fast, we only need to look at the top 1 or 2 frames. Since 
_Unwind_backtrace has a callback that lets us stop walking the stack 
once we've got what we need, its unlikely to be any less efficient than 
having to allocate a buffer to store the entire stack and possibly 
extend it if its too small and call backtrace again.

Further more, backtrace won't work if someone decides to compile their 
code without frame pointers. And its not a standard POSIX function to 
my knowledge, thus not portable at all. Using it is just too fragile.

Regards

Bryce.




More information about the Java mailing list