test/hotspot/jtreg/compiler/arraycopy/TestLoadBypassACWithWrongMem.java
author prr
Thu, 26 Jul 2018 10:00:40 -0700
changeset 51251 0a7a0a6dfa22
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45766
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     1
/*
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     2
 * Copyright (c) 2017, Red Hat, Inc. All rights reserved.
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     4
 *
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     8
 *
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    13
 * accompanied this code).
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    14
 *
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    18
 *
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    21
 * questions.
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    22
 */
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    23
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    24
/**
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    25
 * @test
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    26
 * @bug 8181742
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    27
 * @summary Loads that bypass arraycopy ends up with wrong memory state
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    28
 *
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    29
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions -XX:+StressGCM -XX:+StressLCM TestLoadBypassACWithWrongMem
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    30
 *
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    31
 */
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    32
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    33
import java.util.Arrays;
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    34
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    35
public class TestLoadBypassACWithWrongMem {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    36
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    37
    static int test1(int[] src) {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    38
        int[] dst = new int[10];
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    39
        System.arraycopy(src, 0, dst, 0, 10);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    40
        src[1] = 0x42;
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    41
        // dst[1] is transformed to src[1], src[1] must use the
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    42
        // correct memory state (not the store above).
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    43
        return dst[1];
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    44
    }
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    45
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    46
    static int test2(int[] src) {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    47
        int[] dst = (int[])src.clone();
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    48
        src[1] = 0x42;
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    49
        // Same as above for clone
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    50
        return dst[1];
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    51
    }
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    52
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    53
    static Object test5_src = null;
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    54
    static int test3() {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    55
        int[] dst = new int[10];
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    56
        System.arraycopy(test5_src, 0, dst, 0, 10);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    57
        ((int[])test5_src)[1] = 0x42;
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    58
        System.arraycopy(test5_src, 0, dst, 0, 10);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    59
        // dst[1] is transformed to test5_src[1]. test5_src is Object
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    60
        // but test5_src[1] must be on the slice for int[] not
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    61
        // Object+some offset.
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    62
        return dst[1];
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    63
    }
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    64
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    65
    static public void main(String[] args) {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    66
        int[] src = new int[10];
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    67
        for (int i = 0; i < 20000; i++) {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    68
            Arrays.fill(src, 0);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    69
            int res = test1(src);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    70
            if (res != 0) {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    71
                throw new RuntimeException("bad result: " + res + " != " + 0);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    72
            }
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    73
            Arrays.fill(src, 0);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    74
            res = test2(src);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    75
            if (res != 0) {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    76
                throw new RuntimeException("bad result: " + res + " != " + 0);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    77
            }
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    78
            Arrays.fill(src, 0);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    79
            test5_src = src;
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    80
            res = test3();
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    81
            if (res != 0x42) {
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    82
                throw new RuntimeException("bad result: " + res + " != " + 0x42);
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    83
            }
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    84
         }
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    85
    }
4b5557c9b656 8181742: Load that bypasses arraycopy has wrong memory state
roland
parents:
diff changeset
    86
}