RFR: Handle checkcast arraycopy correctly in barriers. Make arraycopy+barriers a single loop.
Roman Kennke
rkennke at redhat.com
Mon Feb 26 20:08:28 UTC 2018
We currently have a problem, introduced by the new Access API's
arraycopy barrier. We currently don't handle checkcast-oop-arraycopy
correctly: it is possible to copy an Object[] with elements of Foo
into a Bar[], even if Foo and Bar as disjoint types (demonstrated and
tested by the included test). The reason for that is that the Raw
arraycopy routine (which we call to do the actual copy) does not
handle the checkcast at all. The checkcast is only introduced in the
ModRefBarrierSet, but we don't subclass that.
The solution is to do single-element copy with the appropriate
checkcast. And while we're at this, we can solve another slight
problem: our old arraycopy barriers iterates the arrays 3x:
1. to load and enqueue the previous values in the dst array
2. to do the actual copy
3. to update references in the dst array
... while we could do all this in one scan.
Which is implemented here:
http://cr.openjdk.java.net/~rkennke/arraycopy-loop/webrev.00/
The routine first figures out what needs to be done (checkcast, SATB,
matrix, storeval-barrier or any combination of these), then curries
the argument into the appropriate template call into the optimized
loop (or, if nothing needs to be done -- quite frequently -- calls
into the Raw bulk-copy-routine to use blitting if possible).
I encountered one gotcha: the src and dst array ranges don't need to
be disjoint. For this reason I detect which direction we need to copy,
and do the correct loop.
Unfortunately, this is only used on slow paths. C2 and C1 arraycopy
still go through the fast stubs, and call the BarrierSet's
write_ref_array_pre() and write_ref_array() methods, which means
several scans over the array. The upcoming CodeGen stuff will probably
allow us to optimize this better.
(For traversal, I've got a plan to eliminate any extra barrier work on
arraycopy, i.e. one bulk-copy operation plus a very cheap
constant-time enqueing for almost all arraycopies, incl. c1/c2 and
clone-barriers)
Test: hotspot_gc_shenandoah, new test, specjvm point-testing
Ok?
Roman
More information about the shenandoah-dev
mailing list