Re: [Gc] Best way to avoid registering data segments in dynamically loaded libraries

Kjetil Matheussen <[email protected]> Sat, 16 Jul 2016 11:52:30 +0200
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <CAC6niEK4knD0Z3XtScqKWDUbk2QbVtJUjs6yDxR8AAVC-B6BdA@mail.gmail.com>
--===============0938499253==
Content-Type: multipart/alternative; boundary=001a1140150093b1880537bdb1d8

--001a1140150093b1880537bdb1d8
Content-Type: text/plain; charset=UTF-8

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 <
[email protected]> wrote:

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

--001a1140150093b1880537bdb1d8
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I&#39;ve excluded dynamically loaded libraries from the ro=
ot set in my program now.<div>I think it&#39;s safe, but if you know of any=
thing that could go wrong, please let me know.</div><div>My program runs on=
 linux, osx and windows.</div><div><br></div><div>For Linux I&#39;ve implem=
ented the GC_register_has_static_roots_callback callback.</div><div>Unfortu=
nately, the callback is called for the main data segment as well, not just<=
/div><div>the dynamic libraries, so I had to add some checks to identify wh=
ether to return 0 or 1.</div><div><br></div><div>For OSX I had to do the sa=
me thing, but the way to identify whether we are</div><div>handling the mai=
n segment seems less flaky on OSX than on Linux.</div><div><br></div><div>F=
or Windows, the GC_register_has_static_roots_callback callback is not calle=
d,</div><div>so instead I called &#39;GC_set_no_dls(1)&#39;, plus adding th=
e main data segments</div><div>manually after calling &#39;GC_INIT()&#39;.<=
/div><div><br></div><div>Code: <a href=3D"https://github.com/kmatheussen/ra=
dium/blob/master/Qt/Qt_Main.cpp">https://github.com/kmatheussen/radium/blob=
/master/Qt/Qt_Main.cpp</a><br></div><div><br></div><div><br></div><div>Rega=
rding the documentation, I think this line in include/gc.h:</div><div><br><=
/div><div>=C2=A0 =C2=A0&quot;A filter function to control the scanning of d=
ynamic libraries.&quot;<br></div><div><br></div><div>should be changed to</=
div><div>=C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 &quot;A filter function to c=
ontrol the scanning of dynamic libraries and the scanning of main program d=
ata segments&quot;</div><div><br></div><div>or something similar.</div><div=
><br></div><div><br></div><div><br><div class=3D"gmail_extra"><br><div clas=
s=3D"gmail_quote">On Fri, Jul 15, 2016 at 12:00 AM, Kjetil Matheussen <span=
 dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_bla=
nk">[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"=
gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border=
-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div=
 dir=3D"ltr"><div><div>Hi,</div><div><br></div><div>I&#39;m getting reports=
 that my program sometimes stutter a little bit, and</div><div>that turning=
 off the garbage collector fixes it.</div><div><br></div><div>So I thought =
I should try to minimize the root set by avoiding to load</div><div>the dat=
a segments of dynamically loaded libraries, since I know</div><div>that the=
re are no root pointers there.</div><div><br></div><div>In gc.h, the most s=
traight forward way seems to be calling &#39;GC_set_no_dls()&#39;,</div><di=
v>But the documentation for it says:</div><div><br></div><div>=C2=A0 &quot;=
In some environments like Microsoft Windows =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div>=C2=A0 =C2=
=A0and Apple&#39;s Darwin, this may also prevent</div><div>=C2=A0 =C2=A0reg=
istration of the main data segment as part</div><div>=C2=A0 =C2=A0of the ro=
ot set&quot;</div><div><br></div><div>This sounds a bit scary. Is this corr=
ect?</div><div><br></div><div>Perhaps it&#39;s better to implement the &#39=
;GC_has_static_roots_func&#39;</div><div>callback, and always let it return=
 0?</div><div><br></div><div>Thanks for any help.</div></div><div><br></div=
></div>
</blockquote></div><br></div></div></div>

--001a1140150093b1880537bdb1d8--

--===============0938499253==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
bdwgc mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/bdwgc
--===============0938499253==--