www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - precise GC

reply KnightMare <black80 bk.ru> writes:
As I understood conservative-GC scans all allocated memory blocks 
for false pointers. In other hand precise-GC scans only explicit 
memory blocks that contains (objects of types that contains) 
pointers/refs or "muddy" types (void, void[]...).

For example, we have some rooted memory block as
auto rooted = new long[1_000_000];
1) conservative-GC will scan it for false pointers every 
GC-cycle. is it true?
2) precise-GC will NOT scan it at all. is it true?
Mar 04
next sibling parent reply KnightMare <black80 bk.ru> writes:
/* English is not my native, and I tried to use Google translate. 
I hope u will understand subtleties of questions */

For precise-GC:

3) closures: do the closures have any internal types that helps 
to GC or are they (full closure memory block) scanned as in the 
conservative mode?

4) associative arrays:
SomeTypeWithRefsToClasses[string]
any pair will be allocated at some memory block [hash, key, 
value] as I imagine.
Will be precise-GC scan at every pair block only some fields of 
SomeTypeWithRefsToClasses or full [pair-block]?
will be scanned string-key memory block: span-struct and\or chars 
data?
Mar 04
parent reply Rainer Schuetze <r.sagitario gmx.de> writes:
On 04/03/2019 12:12, KnightMare wrote:
 For example, we have some rooted memory block as
 auto rooted = new long[1_000_000];
 1) conservative-GC will scan it for false pointers every GC-cycle. is it
 true?
 2) precise-GC will NOT scan it at all. is it true?
As Adam pointed out, this memory block is neither scanned by the default GC nor the precise GC because they don't contain any references.
 
 3) closures: do the closures have any internal types that helps to GC or
 are they (full closure memory block) scanned as in the conservative mode?
No type information is generated for closures by the compiler, so these are always scanned conservatively.
 
 4) associative arrays:
 SomeTypeWithRefsToClasses[string]
 any pair will be allocated at some memory block [hash, key, value] as I
 imagine.
 Will be precise-GC scan at every pair block only some fields of
 SomeTypeWithRefsToClasses or full [pair-block]?
 will be scanned string-key memory block: span-struct and\or chars data?
associative arrays use allocations containing both key and value. These are scanned as if they are combined to a struct, so only actual pointers with the precise GC, semi-precisely (as Adam put it) with the default GC.
Mar 05
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Mar 05, 2019 at 09:50:34PM +0100, Rainer Schuetze via
Digitalmars-d-learn wrote:
 On 04/03/2019 12:12, KnightMare wrote:
[...]
 3) closures: do the closures have any internal types that helps to
 GC or are they (full closure memory block) scanned as in the
 conservative mode?
No type information is generated for closures by the compiler, so these are always scanned conservatively.
[...] Just out of curiosity, how hard would it be for the compiler to emit type information for closures? Given the prevalence of the range-based idiom in D, I'd think this is a worthwhile area for GC improvements. T -- One Word to write them all, One Access to find them, One Excel to count them all, And thus to Windows bind them. -- Mike Champion
Mar 05
parent Rainer Schuetze <r.sagitario gmx.de> writes:
On 05/03/2019 22:30, H. S. Teoh wrote:
 On Tue, Mar 05, 2019 at 09:50:34PM +0100, Rainer Schuetze via
Digitalmars-d-learn wrote:
 On 04/03/2019 12:12, KnightMare wrote:
[...]
 3) closures: do the closures have any internal types that helps to
 GC or are they (full closure memory block) scanned as in the
 conservative mode?
No type information is generated for closures by the compiler, so these are always scanned conservatively.
[...] Just out of curiosity, how hard would it be for the compiler to emit type information for closures? Given the prevalence of the range-based idiom in D, I'd think this is a worthwhile area for GC improvements.
I tried that first when I added debug information for closures on Windows recently, but it didn't easily work out. I suspect it cannot be generated early in the front-end as closures might also change due to inlining and optimizations. Maybe even worse than the conservative scanning: if structs are moved into the closure, their destructors are never called, even if the closure is collected.
Mar 05
prev sibling next sibling parent KnightMare <black80 bk.ru> writes:
IMO need more explanations about precise-GC and cases where 
behavior of precise and conservative same and differs
Mar 04
prev sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 4 March 2019 at 10:38:29 UTC, KnightMare wrote:
 For example, we have some rooted memory block as
 auto rooted = new long[1_000_000];
 1) conservative-GC will scan it for false pointers every 
 GC-cycle. is it true?
Well, conservative GC in general might, but D's GC would NOT. D's old GC is arguably semi-precise. It would scan void[] conservatively, anything that looks like a pointer is considered maybe a pointer. But it would NOT scan blocks allocated as long[] or ubyte[]. It would allocate those as NO_SCAN blocks. The difference is in combination things, like the stack or structs with static blocks. struct { int a; void* b; } The old GC would treat that whole struct as potentially pointers, both a and b. The new precise GC would know only b needs to be scanned inside that struct. The even bigger deal with precise is it also knows only b would need to be changed if the pointer were to move - that's the big gain precise is setting the groundwork for, to enable moving GC optimizations.
Mar 04