Fwd: Fwd: Proposal for generics over primitives needs a rethink
maurizio.cimadamore at oracle.com
Mon Jan 5 22:16:21 UTC 2015
On 05/01/15 20:01, Gavin King wrote:
> This is exactly the same as with an Any field: it may or may not
> reference an instance, depending upon whether it is null or primitive.
Exact GC algorithms assume you have a way of knowing where your
references are. In JVMs (at least the ones I know) this is typically
done by associating a GC bitmask where, for each field of a given class
C, a 0 means primitive and 1 means reference; the GC will only 'follow'
the fields whose bit is set to 1. Now, you have the problem of 'nulls'
but, if you think about it, 'null' is a very very special value - it's a
reference with all bits set to 0. So it is very easy for the GC to call
that one out.
Now think about a field whose type is Any - the mask should be set
conservatively to 1, as _in principle_ this might hold a reference to
another object, right? But then, how does the VM/GC distinguish between
an instance of a value class (i.e. value) and a reference? I.e. how can
the GC be instructed not to follow that particular 64-bit value that
looks 'like' a reference?
Now, I can think of several ways around this (and this is not the point
of this email) - but let's not pretend that all this is straightforward.
More information about the valhalla-dev