[Gc] Determining if pointer GC allocated

Hans Aberg haberg-1 at telia.com
Fri Dec 30 10:43:27 PST 2011


On 29 Dec 2011, at 15:49, Ivan Maidanski wrote:

> I've implemented GC_is_heap_ptr (C, not C++) - see commit dcf6f52 (master branch).
> Does it work for you?

I made some simple timings. It is significantly faster than using GC_base(), and overhead is less than 70% relative a function f() that just returns an integer. It means that, unless one can optimize away the function call, there is little point in cacheing the value.

Below the results of unoptimized and optimized runs of the test program, just some loops of lookups of an empty C++ class A {};. The CPU is at 1.6 GHz (dual core).

Hans


$ clang++ -std=c++0x -stdlib=libc++ -lgc gc-test.cc gc-test1.cc -o gc-test
$ ./gc-test 
A a0, *a1 = new A();
GC_is_heap_ptr(&a0) = 0
GC_is_heap_ptr(a1)  = 1
Loops of 100000000 function calls each:
GC_is_heap_ptr(&a0): 0.93222 s  = 14.9155 cycles 
GC_is_heap_ptr(a1):  0.975134 s = 15.6021 cycles 
f(&a0):              0.709302 s = 11.3488 cycles 
f(a1):               0.948699 s = 15.1792 cycles 
1:                   0.548974 s = 8.78358 cycles 
GC_base(&a0) != 0:   1.7167 s   = 27.4671 cycles 
GC_base(a1) != 0:    4.76767 s  = 76.2827 cycles 

$ clang++ -O3 -std=c++0x -stdlib=libc++ -lgc gc-test.cc gc-test1.cc -o gc-test
$ ./gc-test 
A a0, *a1 = new A();
GC_is_heap_ptr(&a0) = 0
GC_is_heap_ptr(a1)  = 1
Loops of 100000000 function calls each:
GC_is_heap_ptr(&a0): 0.791836 s = 12.6694 cycles 
GC_is_heap_ptr(a1):  0.802271 s = 12.8363 cycles 
f(&a0):              0.472418 s = 7.55869 cycles 
f(a1):               0.487351 s = 7.79762 cycles 
1:                   2e-06 s    = 3.2e-05 cycles 
GC_base(&a0) != 0:   1.42588 s  = 22.8141 cycles 
GC_base(a1) != 0:    3.69902 s  = 59.1843 cycles 





More information about the Gc mailing list