Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8179678

ArrayCopy with same src and dst can cause incorrect execution or compiler crash

    Details

    • Subcomponent:
    • Resolved In Build:
      b173
    • Verification:
      Verified

      Backports

        Description

        public class TestACSameSrcDst {
            static int test1(int[] src, int[] dst) {
                System.arraycopy(src, 5, dst, 0, 10);
                return dst[0];
            }

            static int test2(int[] src) {
                System.arraycopy(src, 0, src, 0, 10);
                return src[0];
            }

            public static void main(String[] args) {
                int[] array = new int[15];
                for (int i = 0; i < 20000; i++) {
                    for (int j = 0; j < array.length; j++) {
                        array[j] = j;
                    }
                    int expected = array[5];
                    int res = test1(array, array);
                    if (res != expected) {
                        throw new RuntimeException("bad result: " + res + " != " + expected);
                    }
                    test2(array);
                }
            }
        }

        test1() above causes an incorrect execution. test2() causes an infinite loop in GVN:

        # Internal Error (/home/roland/hs/hotspot/src/share/vm/opto/phaseX.cpp:791), pid=6855, tid=6892
        # assert(loop_count++ < K) failed: infinite loop in PhaseGVN::transform

        Both are caused by LoadNode::can_see_arraycopy_value()

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  roland Roland Westrelin
                  Reporter:
                  roland Roland Westrelin
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: