Re[2]: [Gc] Determining if pointer GC allocated

Ivan Maidanski ivmai at mail.ru
Fri Dec 30 12:12:32 PST 2011


Hi Hans A.,

30 12 2011, 22:43 Hans Aberg <haberg-1 at telia.com>:
> 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 caching the value.

If your test case were written in C then it would be possible to define GC_API=static and include extra/gc.c directly from your code thus resulting everything to be compiled as a single module with GC_is_heap_ptr inlined (at some level of -O).

Regards.

> 
> 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