test/hotspot/jtreg/compiler/arraycopy/ACasLoadsStoresBadMem.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 51085 ad9d95f1a1f6
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51085
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     1
/*
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     2
 * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     4
 *
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     8
 *
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    13
 * accompanied this code).
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    14
 *
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    18
 *
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    21
 * questions.
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    22
 */
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    23
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    24
/**
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    25
 * @test
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    26
 * @bug 8200282
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    27
 * @summary arraycopy converted as a series of loads/stores uses wrong slice for loads
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    28
 *
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    29
 * @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:CompileCommand=dontinline,ACasLoadsStoresBadMem::not_inlined  ACasLoadsStoresBadMem
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    30
 *
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    31
 */
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    32
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    33
public class ACasLoadsStoresBadMem {
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    34
    public static void main(String[] args) {
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    35
        int[] dst = new int[5];
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    36
        for (int i = 0; i < 20_000; i++) {
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    37
            test1(dst, 1);
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    38
            for (int j = 1; j < 5; j++) {
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    39
                if (dst[j] != j) {
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    40
                    throw new RuntimeException("Bad copy ");
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    41
                }
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    42
            }
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    43
        }
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    44
    }
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    45
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    46
    private static void test1(int[] dst, int dstPos) {
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    47
        int[] src = new int[4];
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    48
        not_inlined();
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    49
        src[0] = 1;
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    50
        src[1] = 2;
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    51
        src[2] = 3;
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    52
        src[3] = 4;
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    53
        System.arraycopy(src, 0, dst, dstPos, 4);
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    54
    }
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    55
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    56
    private static void not_inlined() {
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    57
    }
ad9d95f1a1f6 8200282: Serializing non-zero byte as zero to ByteBuffer
roland
parents:
diff changeset
    58
}