Discussion:
[Gc] Best way to avoid registering data segments in dynamically loaded libraries
(too old to reply)
Kjetil Matheussen
2016-07-14 22:00:22 UTC
Permalink
Raw Message
Hi,

I'm getting reports that my program sometimes stutter a little bit, and
that turning off the garbage collector fixes it.

So I thought I should try to minimize the root set by avoiding to load
the data segments of dynamically loaded libraries, since I know
that there are no root pointers there.

In gc.h, the most straight forward way seems to be calling
'GC_set_no_dls()',
But the documentation for it says:

"In some environments like Microsoft Windows

and Apple's Darwin, this may also prevent
registration of the main data segment as part
of the root set"

This sounds a bit scary. Is this correct?

Perhaps it's better to implement the 'GC_has_static_roots_func'
callback, and always let it return 0?

Thanks for any help.
Kjetil Matheussen
2016-07-16 09:52:30 UTC
Permalink
Raw Message
I've excluded dynamically loaded libraries from the root set in my program
now.
I think it's safe, but if you know of anything that could go wrong, please
let me know.
My program runs on linux, osx and windows.

For Linux I've implemented the GC_register_has_static_roots_callback
callback.
Unfortunately, the callback is called for the main data segment as well,
not just
the dynamic libraries, so I had to add some checks to identify whether to
return 0 or 1.

For OSX I had to do the same thing, but the way to identify whether we are
handling the main segment seems less flaky on OSX than on Linux.

For Windows, the GC_register_has_static_roots_callback callback is not
called,
so instead I called 'GC_set_no_dls(1)', plus adding the main data segments
manually after calling 'GC_INIT()'.

Code: https://github.com/kmatheussen/radium/blob/master/Qt/Qt_Main.cpp


Regarding the documentation, I think this line in include/gc.h:

"A filter function to control the scanning of dynamic libraries."

should be changed to

"A filter function to control the scanning of dynamic libraries and the
scanning of main program data segments"

or something similar.




On Fri, Jul 15, 2016 at 12:00 AM, Kjetil Matheussen <
Post by Kjetil Matheussen
Hi,
I'm getting reports that my program sometimes stutter a little bit, and
that turning off the garbage collector fixes it.
So I thought I should try to minimize the root set by avoiding to load
the data segments of dynamically loaded libraries, since I know
that there are no root pointers there.
In gc.h, the most straight forward way seems to be calling
'GC_set_no_dls()',
"In some environments like Microsoft Windows
and Apple's Darwin, this may also prevent
registration of the main data segment as part
of the root set"
This sounds a bit scary. Is this correct?
Perhaps it's better to implement the 'GC_has_static_roots_func'
callback, and always let it return 0?
Thanks for any help.
Loading...