4 ms·
Languages that support pointer arithmetic have to support "raw" pointers, i.e. pointers that point to any location in memory. This creates some problems for the
by tomp 13y ago
Languages that support pointer arithmetic have to support "raw" pointers, i.e. pointers that point to any location in memory. This creates some problems for the GC, as it can't be sure what objects are live and which aren't. For example, a pointer might point to unallocated memory (in which case the GC must not even dereference it), to a `malloc`-allocated memory, to a GC-allocated memory, or even in the middle of a (GC-allocated or `malloc`-allocated) heap object! In addition, some pointers look like integers and some integers look like pointers, and the GC has no idea how to distinguish them at runtime. In order to still support some kind of GC in such languages, you can write your GC to be imprecise or conservative, which means that it treats every integer that could potentially be a pointer as a pointer and assumes it is pointing to a live object. Potentially, this means that the GC thinks objects are live which are actually not, just because the programmer is using an integer which, if interpreted as a pointer, points to said object.
I'm not intimately familiar with Go implementation, but I assume that they haven't bothered implementing precise stack- and register-scanning, which means that the runtime cannot distinguish pointers from integers on the stack/in the registers. That's a really hard problem in general and solving it requires quite some compiler support and runtime overhead. It looks like that is finally planned for Go 1.3, though.
- kenshiro_o 13y agoI see. This indeed adds a lot more complexity to the GC as it will have to check every integer or type that "looks" like a reference. Does this also mean that GC times will likely be longer in Go 1.3? There is not much detailed info about the Go runtime (like we do have for Java for instance) so it would great for the Go maintainers to publish a more in-depth reference of the internals of the language in version 1.3 /
- cpeterso 13y agoPrecise (or "exactly rooted") GC should have shorter GC pause times because the runtime knows where to look for references to GC objects, rather than scanning stacks and the heap for bytes that might look like a pointer. The problem is that writing code to use precise GC is more cumbersome because you have to worry about extra bookkeeping code for every pointer reference to a GC'd object.
- deleted 13y ago[deleted]
- fulafel 13y agoConservative is where you check every word that looks like a pointer. But it's simpler, it's just brute force.
- zurn 13y ago> Languages that support pointer arithmetic [...] To clarify, Go doesn't have pointer arithmetic. The GC has been evolving from conservative to precise, in Go 1.1 it's gotten as far as "mostly precise".