hotspot/test/compiler/arraycopy/TestInitializingACLoadWithBadMem.java
author roland
Mon, 03 Jul 2017 14:33:00 +0200
changeset 46754 2e49bb347cbc
permissions -rw-r--r--
8182036: Load from initializing arraycopy uses wrong memory state Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46754
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     1
/*
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     2
 * Copyright (c) 2017, Red Hat, Inc. All rights reserved.
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     4
 *
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     8
 *
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    13
 * accompanied this code).
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    14
 *
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    18
 *
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    21
 * questions.
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    22
 */
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    23
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    24
/**
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    25
 * @test
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    26
 * @bug 8182036
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    27
 * @summary Load from initializing arraycopy uses wrong memory state
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    28
 *
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    29
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions -XX:+StressGCM -XX:+StressLCM TestInitializingACLoadWithBadMem
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    30
 *
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    31
 */
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    32
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    33
import java.util.Arrays;
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    34
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    35
public class TestInitializingACLoadWithBadMem {
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    36
    static Object test_dummy;
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    37
    static int test1() {
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    38
        int[] src = new int[10];
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    39
        test_dummy = src;
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    40
        int[] dst = new int[10];
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    41
        src[1] = 0x42;
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    42
        // arraycopy generates a load from src/store to dst which must
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    43
        // be after the store to src above.
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    44
        System.arraycopy(src, 1, dst, 1, 9);
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    45
        return dst[1];
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    46
    }
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    47
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    48
    static public void main(String[] args) {
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    49
        int[] src = new int[10];
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    50
        for (int i = 0; i < 20000; i++) {
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    51
            int res = test1();
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    52
            if (res != 0x42) {
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    53
                throw new RuntimeException("bad result: " + res + " != " + 0x42);
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    54
            }
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    55
        }
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    56
    }
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents:
diff changeset
    57
}