RFR(S): fix System.arraycopy() C2 intrinsics with arrays of value types
Roland Westrelin
rwestrel at redhat.com
Thu Nov 16 22:13:10 UTC 2017
http://cr.openjdk.java.net/~roland/valhalla/arraycopy/webrev.00/
This changes fixes arraycopy intrinsics (which cover not only
System.arraycopy() but also clone() and copyOf()) so they work with
array of value types, flattened or not.
arraycopy intrinsics rely on stubs and the correct stub must be picked
for value types. In particular, if the array is flattened, the value
type has object fields and barriers needs to be emitted on object
stores, none of the stubs are safe to use and the code should fall back
to a runtime call.
Short array copies are optimized as a series of load/stores. Flattened
arrays need to copy each field of each element of the array. This is
achieved by creating a GraphKit in ArrayCopyNode::Ideal(). Thanks to
that, we can now emit gc barriers in Ideal() and optimize previously
impossible to optimize copies.
I also verified that:
- ArrayCopyNode is properly handled by escape analysis (if the
destination of the copy doesn't escape, an arraycopy doesn't cause it to
be viewed as escaping).
- a LoadNode optimization that replaces a load from the destination of a
arraycopy by a load from the source (in order to optimize the ArrayCopyNode
out) works
- when an ArrayCopyNode is eliminated because of a non escaping
allocation which is scalarized, element values are properly recorded at
safepoints.
Roland.
More information about the valhalla-dev
mailing list