Instructions for selecting another GC

Per Nordlöw per.nordlow at gmail.com
Wed Jun 12 12:40:12 UTC 2019


On Tuesday, 11 June 2019 at 19:41:00 UTC, kinke wrote:
> Rebuilding the compiler shouldn't be necessary, but now you 
> don't need to rebuild druntime either and can link your custom 
> GC directly into your binary and instruct druntime to use it:
> https://dlang.org/spec/garbage.html#gc_registry

Ok, great.

So something like


import core.gc.gcinterface, core.gc.registry;
import segregated_gc;

extern (C) pragma(crt_constructor) void registerSegregatedGC()
{
     registerGCFactory("segregated", &createSegregatedGC);
}

GC createSegregatedGC()
{
     __gshared instance = new SegregatedGC;
     instance.initialize();
     return instance;
}

/* The new GC is added to the list of available garbage 
collectors that can be
  * selected via the usual configuration options, e.g. by 
embedding rt_options
  * into the binary:
  */
extern (C) __gshared string[] rt_options = 
["gcopt=gc:segregated"];


works for me to hardcode the GC by linking my app with 
https://github.com/nordlow/phobos-next/blob/de1bdaaeac839cbfc65dd8bc7714128f657c19da/benchmarks/gc-benchmark/source/register_segregated_gc.d

But in my test suite (at 
https://github.com/nordlow/phobos-next/blob/de1bdaaeac839cbfc65dd8bc7714128f657c19da/benchmarks/gc-benchmark/test.sh) doing

     dub run --build=release-nobounds -- 
--DRT-gcopt=gc:conservative
     dub run --build=release-nobounds -- --DRT-gcopt=gc:precise
     dub run --build=release-nobounds -- --DRT-gcopt=gc:segregated

I don't want to hardcode the `gc:segregated`. Therefore I comment 
out the line

     extern (C) __gshared string[] rt_options = 
["gcopt=gc:segregated"];

. But then the last call to

     dub run --build=release-nobounds -- --DRT-gcopt=gc:segregated

fails as

     No GC was initialized, please recheck the name of the 
selected GC ('segregated').

How do I make a custom GC accessible without hardcoding it to be 
default and instead being able to select it a run-time via the 
parameter `--DRT-gcopt`?

The above mentioned test can be called by running it locally as

     ./test.sh


More information about the Digitalmars-d mailing list