hotspot/test/compiler/arraycopy/TestLoadBypassArrayCopy.java
author thartmann
Thu, 12 May 2016 08:23:25 +0200
changeset 38675 066fcb1eb80a
parent 31231 068d1f94b3bf
child 40059 c2304140ed64
permissions -rw-r--r--
8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks Summary: We should not emit a subtype check for CloneOop arraycopy. Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31231
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     1
/*
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     4
 *
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     8
 *
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    13
 * accompanied this code).
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    14
 *
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    18
 *
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    21
 * questions.
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    22
 */
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    23
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    24
/*
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    25
 * @test
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    26
 * @bug 8086046
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    27
 * @summary load bypasses arraycopy that sets the value after the ArrayCopyNode is expanded
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    28
 * @run main/othervm -XX:-BackgroundCompilation  -XX:-UseOnStackReplacement -XX:CompileCommand=dontinline,TestLoadBypassArrayCopy::test_helper -XX:-TieredCompilation TestLoadBypassArrayCopy
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    29
 *
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    30
 */
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    31
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    32
public class TestLoadBypassArrayCopy {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    33
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    34
    static long i;
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    35
    static boolean test_helper() {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    36
        i++;
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    37
        if ((i%10) == 0) {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    38
            return false;
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    39
        }
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    40
        return true;
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    41
    }
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    42
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    43
    static int test(int[] src, int len, boolean flag) {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    44
        int[] dest = new int[10];
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    45
        int res = 0;
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    46
        while (test_helper()) {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    47
            System.arraycopy(src, 0, dest, 0, len);
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    48
            // predicate moved out of loop so control of following
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    49
            // load is not the ArrayCopyNode. Otherwise, if the memory
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    50
            // of the load is changed and the control is set to the
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    51
            // ArrayCopyNode the graph is unschedulable and the test
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    52
            // doesn't fail.
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    53
            if (flag) {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    54
            }
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    55
            // The memory of this load shouldn't bypass the arraycopy
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    56
            res = dest[0];
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    57
        }
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    58
        return res;
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    59
    }
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    60
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    61
    static public void main(String[] args) {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    62
        int[] src = new int[10];
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    63
        src[0] = 0x42;
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    64
        for (int i = 0; i < 20000; i++) {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    65
            int res = test(src, 10, false);
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    66
            if (res != src[0]) {
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    67
                throw new RuntimeException("test failed");
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    68
            }
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    69
        }
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    70
    }
068d1f94b3bf 8086046: escape analysis generates incorrect code as of B67
roland
parents:
diff changeset
    71
}