View mode: basic / threaded / horizontal-split · Log in · Help
October 12, 2012
Blog post: Demystifying Garbage Collectors
http://xtzgzorex.wordpress.com/2012/10/11/demystifying-garbage-collectors/

Essentially an explanation of garbage collection for the layman 
programmer. Though, it does assume some familiarity with C and memory 
management. It's an abstract article not particularly specific to any GC 
implementation, but I figured I'd post it here anyway in case anyone's 
interested.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
October 12, 2012
Re: Blog post: Demystifying Garbage Collectors
Nice article!
October 12, 2012
Re: Blog post: Demystifying Garbage Collectors
On 10/11/12 9:15 PM, Alex Rønne Petersen wrote:
> http://xtzgzorex.wordpress.com/2012/10/11/demystifying-garbage-collectors/
>
> Essentially an explanation of garbage collection for the layman
> programmer. Though, it does assume some familiarity with C and memory
> management. It's an abstract article not particularly specific to any GC
> implementation, but I figured I'd post it here anyway in case anyone's
> interested.
>

http://www.reddit.com/r/programming/comments/11doh4/demystifying_garbage_collectors/

Andrei
October 13, 2012
Re: Blog post: Demystifying Garbage Collectors
On Friday, 12 October 2012 at 19:19:23 UTC, Andrei Alexandrescu 
wrote:
> On 10/11/12 9:15 PM, Alex Rønne Petersen wrote:
>> http://xtzgzorex.wordpress.com/2012/10/11/demystifying-garbage-collectors/
>>
>> Essentially an explanation of garbage collection for the 
>> layman programmer. Though, it does assume some familiarity 
>> with C and memory management. It's an abstract article not 
>> particularly specific to any GC implementation, but I figured 
>> I'd post it here anyway in case anyone's interested.
>>
> http://www.reddit.com/r/programming/comments/11doh4/demystifying_garbage_collectors/

 A question comes up, and I don't need an answer but it may be 
useful to know, but I'm curious.

 Does D include an index to bitmaps specifying which offsets in a 
given memory block (say a class or a struct) of which fields 
actually would point to memory? With the strong possibility of 
working with manual pointer management it is possible it's not as 
useful as it could be; But may be considered when making a GC. 
Who knows, I may try my hand at it.

 //some pseudo random number generator class
 class Prng {
  int seed;
  int[] cached;

  //mem location as good as any for an initial seed,
  //maybe xor against time/date
  this() {seed = cast(int) &this;}
 }

 The above may have a bitmap indexed to 00000_010b (or an index 
so enum {nil, charArray, intArray} and thus [nil, intArray, nil], 
so it would skip the ints and only check the only that actually 
would contains a pointer. It could also effectively hold 
additional information on the type for further indexing, so when 
it sees 'cached' it will know it's an array, but if it was an 
array to Objects, then it would scan every part of that inner 
array mentioned for further references.
October 14, 2012
Re: Blog post: Demystifying Garbage Collectors
Era Scarecrow, el 13 de October a las 21:18 me escribiste:
>  Does D include an index to bitmaps specifying which offsets in a
> given memory block (say a class or a struct) of which fields
> actually would point to memory? With the strong possibility of
> working with manual pointer management it is possible it's not as
> useful as it could be; But may be considered when making a GC. Who
> knows, I may try my hand at it.
>
>  //some pseudo random number generator class
>  class Prng {
>   int seed;
>   int[] cached;
>
>   //mem location as good as any for an initial seed,
>   //maybe xor against time/date
>   this() {seed = cast(int) &this;}
>  }
>
>  The above may have a bitmap indexed to 00000_010b (or an index so
> enum {nil, charArray, intArray} and thus [nil, intArray, nil], so it
> would skip the ints and only check the only that actually would
> contains a pointer. It could also effectively hold additional
> information on the type for further indexing, so when it sees
> 'cached' it will know it's an array, but if it was an array to
> Objects, then it would scan every part of that inner array mentioned
> for further references.

There was at least one attempt to make the GC partially precise, which
is what you are suggesting. I've implemented a GC for D which goal was
to make it concurrent (to minimize pause times) but I also made use of
the information about types when available. The main advantage of this
is not really scanning less memory, but avoiding memory leaks by holding
memory cells as if they were alive when they really aren't, which was
a big problem in D now (and maybe it still is, I'm not very updated in
the state of D2's GC, but I'm almost sure there is still no type
information available to the GC in D2).

Unfortunately neither the patch to make DMD emit information about types
nor my GC were ever merged to D2, only Tango accepted the GC but since
DMD never accepted the patches emitting type information, the GC is not
precise in practice.

It worth mentioning that there is one bit of type information. If you
class/struct doesn't have *any* pointers, the memory cell where it is
stored will be marked as it doesn't have to be scanned. Same for arrays
of data that's known not to have pointers (like one of this class/struct
or ints, or floats for example).

There is even a bug report about this, if you want to take a look:
http://d.puremagic.com/issues/show_bug.cgi?id=3463

BTW, there is no need to "follow" arrays in any special way, dynamic
arrays are just a pointer and a size_t and the GC will "follow" the
pointer anyway. The array is allocated in a memory cell that would have
it's own type information and thus can be scanned (or ignored)
as needed.

--
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
22% of the time a pizza will arrive faster than an ambulance in
Great-Britain
Top | Discussion index | About this forum | D home