RFR(S): 8146828: Subsequent arraycopy does not always eliminate array zeroing

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Feb 17 13:33:56 UTC 2016


Hi Roland,

On 02/12/2016 06:23 PM, Roland Westrelin wrote:
> Thanks for taking a look at this, Vladimir.
> 
>> Yes, it is complicated code with assumptions not covered by comments.
>>
>> Needs more comments in place where you check too_many_traps to explain why such reasons are checked (this bug description).
> 
> Here is a new webrev with more comments:
> http://cr.openjdk.java.net/~roland/8146828/webrev.01/

This patch indeed improves the benchmark from the bug report. However,
the ArrayList.toArray case from which the benchmark was derived is not
improving. To follow up further I have updated the benchmark with more
cases:
  http://cr.openjdk.java.net/~shade/8146828/ArrayZeroingBench.java
  http://cr.openjdk.java.net/~shade/8146828/benchmarks.jar

The test cases from the previous benchmarks are now known as
"*_backtoback" -- and they are indeed improving a lot, due to the
absence of zeroing. ArrayList.toArray case is closer to
"field_generic_inline", although it may turn into
"field_generic_dontinline" if inlining hiccups -- and it had not improved.

Another thing that concerns me is that "base" case that does not cover
the destination array in full:

    @Benchmark
    public Foo[] base() {
        Foo[] dst = new Foo[size];
        System.arraycopy(src, 0, dst, 0, size - 1);
        return dst;
    }

...now eliminates zeroing. This sounds like a functional bug.

Cheers,
-Aleksey

--------------------------------------------------------------------------

*** Original hs-comp:

Benchmark                     (size)  Mode  Cnt    Score    Error  Units

# Eliminate zeroing
copyOf_field                    1000  avgt   15  670.242 ±  7.064  ns/op
copyOf_srcLength                1000  avgt   15  663.790 ±  4.337  ns/op
srcLength_backtoback            1000  avgt   15  678.564 ± 16.078  ns/op

# Have zeroing
base                            1000  avgt   15  899.566 ± 10.140  ns/op
dstLength_backtoback            1000  avgt   15  901.168 ±  7.448  ns/op
dstLength_dontinline            1000  avgt   15  893.555 ±  6.441  ns/op
dstLength_generic_dontinline    1000  avgt   15  906.428 ± 12.023  ns/op
dstLength_generic_inline        1000  avgt   15  890.435 ±  5.727  ns/op
dstLength_inline                1000  avgt   15  893.364 ±  6.754  ns/op
field_backtoback                1000  avgt   15  896.103 ±  6.933  ns/op
field_dontinline                1000  avgt   15  895.276 ±  5.245  ns/op
field_generic_dontinline        1000  avgt   15  913.208 ± 33.095  ns/op
field_generic_inline            1000  avgt   15  896.768 ± 19.996  ns/op
field_inline                    1000  avgt   15  893.639 ±  5.799  ns/op
srcLength_dontinline            1000  avgt   15  900.281 ±  9.121  ns/op
srcLength_generic_dontinline    1000  avgt   15  894.431 ±  6.684  ns/op
srcLength_generic_inline        1000  avgt   15  899.178 ± 12.900  ns/op
srcLength_inline                1000  avgt   15  897.053 ±  5.433  ns/op

--------------------------------------------------------------------------

*** Patched hs-comp:

Benchmark                     (size)  Mode  Cnt    Score    Error  Units

# Eliminate zeroing
base                            1000  avgt   15  686.523 ±  6.865  ns/op
copyOf_field                    1000  avgt   15  682.847 ± 11.112  ns/op
copyOf_srcLength                1000  avgt   15  676.604 ±  6.397  ns/op
dstLength_backtoback            1000  avgt   15  673.739 ±  8.046  ns/op
field_backtoback                1000  avgt   15  684.339 ± 16.042  ns/op
srcLength_backtoback            1000  avgt   15  668.501 ±  7.876  ns/op

# Have zeroing
dstLength_dontinline            1000  avgt   15  898.067 ±  7.785  ns/op
dstLength_generic_dontinline    1000  avgt   15  897.727 ± 12.140  ns/op
dstLength_generic_inline        1000  avgt   15  893.653 ±  7.720  ns/op
dstLength_inline                1000  avgt   15  892.346 ±  5.594  ns/op
field_dontinline                1000  avgt   15  898.671 ± 10.030  ns/op
field_generic_dontinline        1000  avgt   15  899.473 ±  6.913  ns/op
field_generic_inline            1000  avgt   15  898.713 ± 19.982  ns/op
field_inline                    1000  avgt   15  905.791 ± 14.564  ns/op
srcLength_dontinline            1000  avgt   15  903.012 ± 11.919  ns/op
srcLength_generic_dontinline    1000  avgt   15  894.738 ±  8.232  ns/op
srcLength_generic_inline        1000  avgt   15  905.205 ± 18.927  ns/op
srcLength_inline                1000  avgt   15  920.086 ± 20.310  ns/op


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20160217/b5dd630d/signature.asc>


More information about the hotspot-compiler-dev mailing list