www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Garbage Collectors

reply IchorDev <zxinsworld gmail.com> writes:
So, D’s default garbage collector is the one named “conservative” 
in DRuntime…
I see there’s also “manual” which doesn’t actually function as a 
GC, which is interesting.
Nothing says what ProtoGC is… so I guess it’s useless.
Has anyone ever published any custom GCs? A search through the 
dub package registry yielded nothing. How hard would it be to 
port (for instance) a Java GC to D’s interface?
Jul 19 2023
next sibling parent reply Sergey <kornburn yandex.ru> writes:
On Wednesday, 19 July 2023 at 07:24:06 UTC, IchorDev wrote:
 So, D’s default garbage collector is the one named 
 “conservative” in DRuntime…
 I see there’s also “manual” which doesn’t actually function as 
 a GC, which is interesting.
 Nothing says what ProtoGC is… so I guess it’s useless.
 Has anyone ever published any custom GCs? A search through the 
 dub package registry yielded nothing. How hard would it be to 
 port (for instance) a Java GC to D’s interface?
Forking GC was introduced some time ago. But I don't think it is quite different from regular (https://forum.dlang.org/post/tf8mbo$1jvp$1 digitalmars.com) There are some posts about it GCs, but I don't think anything was released. https://forum.dlang.org/thread/jquklsqxtfgvsezrcuzu forum.dlang.org?page=1 https://forum.dlang.org/post/yonbmhifafbyjhwpcixp forum.dlang.org
Jul 19 2023
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 19/07/2023 7:44 PM, Sergey wrote:
 Forking GC was introduced some time ago. But I don't think it is quite 
 different from regular 
 (https://forum.dlang.org/post/tf8mbo$1jvp$1 digitalmars.com)
It is a modification of the conservative GC. Rather than a unique GC implementation and is upstreamed.
 There are some posts about it GCs, but I don't think anything was released.
 https://forum.dlang.org/thread/jquklsqxtfgvsezrcuzu forum.dlang.org?page=1
 https://forum.dlang.org/post/yonbmhifafbyjhwpcixp forum.dlang.org
The only GC design I know of that is semi-interesting is Rainer's concurrent GC for Windows. http://rainers.github.io/visuald/druntime/concurrentgc.html This has not been upstreamed.
Jul 19 2023
prev sibling next sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
Its not as simple as porting to the API unfortunately.

We don't have barriers of any kind, so that removes most GC designs you 
would want to use today. We are very close to maxing out what we can do 
as a result.

A whole pile of logic is hidden in rt, so you have no choice but to 
either do the work to fix that, or recompile druntime with your GC.
Jul 19 2023
parent reply IchorDev <zxinsworld gmail.com> writes:
On Wednesday, 19 July 2023 at 08:27:18 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 Its not as simple as porting to the API unfortunately.

 We don't have barriers of any kind, so that removes most GC 
 designs you would want to use today. We are very close to 
 maxing out what we can do as a result.

 A whole pile of logic is hidden in rt, so you have no choice 
 but to either do the work to fix that, or recompile druntime 
 with your GC.
I'm mostly a frontend person, but is what would need doing there? Is there any existing discussion about that?
Jul 19 2023
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 19/07/2023 9:02 PM, IchorDev wrote:
 On Wednesday, 19 July 2023 at 08:27:18 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 Its not as simple as porting to the API unfortunately.

 We don't have barriers of any kind, so that removes most GC designs 
 you would want to use today. We are very close to maxing out what we 
 can do as a result.

 A whole pile of logic is hidden in rt, so you have no choice but to 
 either do the work to fix that, or recompile druntime with your GC.
I'm mostly a frontend person, but is what would need doing there? Is there any existing discussion about that?
Not really, last time I tried, I didn't document what was hidden. Copying out the conservative GC, register it under a different name and getting that to compile and link without recompiling druntime would be a good place to begin without having to understand how GC's work.
Jul 19 2023
parent reply IchorDev <zxinsworld gmail.com> writes:
On Wednesday, 19 July 2023 at 10:50:07 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 Copying out the conservative GC, register it under a different 
 name and getting that to compile and link without recompiling 
 druntime would be a good place to begin without having to 
 understand how GC's work.
That sounds pretty easy, but I don't really see how would that be particularly helpful to allowing a different style of GC to be registered?
Jul 19 2023
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 19/07/2023 11:13 PM, IchorDev wrote:
 On Wednesday, 19 July 2023 at 10:50:07 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 Copying out the conservative GC, register it under a different name 
 and getting that to compile and link without recompiling druntime 
 would be a good place to begin without having to understand how GC's 
 work.
That sounds pretty easy, but I don't really see how would that be particularly helpful to allowing a different style of GC to be registered?
druntime supports registering of GC's not compiled with druntime. But because some of the machinery isn't available to you, you would have to recreate it. So in practice you cannot find a GC on the dub-registry to try it out. Even if one were to exist, you would have to do a new build of druntime/phobos special which isn't the easiest thing to do. https://github.com/dlang/dmd/blob/master/druntime/src/core/gc/registry.d#L39 Regardless, its a barrier to anyone wanting to try writing a GC to experiment with (or port one).
Jul 19 2023
next sibling parent IchorDev <zxinsworld gmail.com> writes:
On Wednesday, 19 July 2023 at 11:27:14 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 druntime supports registering of GC's not compiled with 
 druntime.

 But because some of the machinery isn't available to you, you 
 would have to recreate it.
Oh right, so it's more of a matter of making GC-related code part of the GC implementation so that it's more convenient for others to build their own GC on top of it.
 So in practice you cannot find a GC on the dub-registry to try 
 it out. Even if one were to exist, you would have to do a new 
 build of druntime/phobos special which isn't the easiest thing 
 to do.
Just to confirm: would none of this would require *me* recompiling DRuntime at all, or is it that DRuntime would have to be modified to the point where anyone else registering a unique GC from user code wouldn't have to recompile DRuntime?
Jul 19 2023
prev sibling parent reply Johan <j j.nl> writes:
On Wednesday, 19 July 2023 at 11:27:14 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 [...] you would have to do a new build of druntime/phobos 
 special which isn't the easiest thing to do.
Side remark: LDC ships with the ldc-build-runtime tool which should help the user a lot in building druntime/phobos. (downloads the correct source belonging to the specific compiler version, and then builds the libraries with user-specified flags, compilers, etc.) -Johan
Jul 19 2023
parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/19/23 10:46 AM, Johan wrote:
 On Wednesday, 19 July 2023 at 11:27:14 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 [...] you would have to do a new build of druntime/phobos special 
 which isn't the easiest thing to do.
Side remark: LDC ships with the ldc-build-runtime tool which should help the user a lot in building druntime/phobos. (downloads the correct source belonging to the specific compiler version, and then builds the libraries with user-specified flags, compilers, etc.)
This is very cool to know, I wasn't aware! -Steve
Jul 22 2023
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/19/23 3:24 AM, IchorDev wrote:
 So, D’s default garbage collector is the one named “conservative” in 
 DRuntime…
 I see there’s also “manual” which doesn’t actually function as a GC, 
 which is interesting.
 Nothing says what ProtoGC is… so I guess it’s useless.
 Has anyone ever published any custom GCs? A search through the dub 
 package registry yielded nothing. How hard would it be to port (for 
 instance) a Java GC to D’s interface?
To answer the question about ProtoGC, it is a stub GC which will create the appropriate GC (based on runtime flags) when the first function that requires actually using the GC is called. It is actually the default GC. This was introduced to implement more pay-as-you-go runtime features. If you don't use the GC, no GC is created. If I recall correctly, you must attempt to allocate using the GC for the ProtoGC to do its thing. Everything else is just simple stubs (e.g. ProtoGC.free does nothing, since it can never allocate memory) -Steve
Jul 19 2023