What's the go with the GC these days?

Nicholas Wilson iamthewilsonator at hotmail.com
Sun Jan 6 05:16:42 UTC 2019


On Sunday, 6 January 2019 at 04:34:30 UTC, H. S. Teoh wrote:
> On Sat, Jan 05, 2019 at 11:12:52PM +0000, Neia Neutuladh via
>> But one thing it could get that would be interesting is a 
>> thread-local GC.
>
> Yes, yes, and yes!  This would allow per-thread segregation of 
> the GC heap, which would allow much better control of GC pauses.
>
>
>> (You'd have a stop-the-world phase that happened infrequently. 
>> Casting something to shared would pin it in the thread it was 
>> allocated from.)
>
> How does this solve the problem of shared, though?  The last 
> time I checked, casting to/from shared is the main showstopper 
> for a thread-local GC.

The recent shared thread by Manu was trying (only somewhat 
successfully) to tie shared to @safe/@trusted with an inductive 
model, i.e. the user writes @trusted foundational layer and 
@safety is verified from there on up the call stack. I wonder if 
that sort of a model would safely permit a thread local GC?

>> Three things about D make it harder to make a good GC for it:
>> * unaligned pointers
>> * unions
>> * externally allocated memory (malloc and friends)
>> 
>> We've pretty much addressed malloc by telling people to 
>> manually add and remove malloced memory from what the GC 
>> scans. A union is pretty much just a pointer that might not be 
>> valid. Unaligned pointers just kind of suck.
>
> Unaligned pointers are generally just a bad idea IMO.  I'm 
> tempted to say it should be defined as UB, along with obscured 
> pointers (like the doubly-linked list with 1 pointer per node 
> trick using XOR). Maybe with a compiler / runtime switch to 
> enable a more conservative GC.
>
> Now that I think of it, we could deal with pointers in unions 
> the same way -- if the compiler detects it, then trigger 
> conservative mode in the GC.
>
> With these two out of the way, a generational GC for D seems 
> closer to the realm of possibility.

With a precise GC that knows the types/layout of what its dealing 
with it ought to be possible to have a way to retrieve all the 
pointers from a type for scanning. For an inactive union that 
would be returning nothing. It could possibly work for an XORlist 
as well, not that I thunk we should be letting that kind of 
monstrosity dictate our designs.  Ditto for unaligned pointers.



More information about the Digitalmars-d mailing list