hotspot/test/compiler/arraycopy/TestArrayCopyBadReexec.java
author roland
Mon, 16 Mar 2015 12:24:06 +0100
changeset 30185 4b08d63ac105
child 40059 c2304140ed64
permissions -rw-r--r--
8073866: Fix for 8064703 is not sufficient Summary: side effects between allocation and arraycopy can be reexecuted, unreachable uninitialized array can be seen by GCs Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30185
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     1
/*
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     4
 *
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     8
 *
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    13
 * accompanied this code).
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    14
 *
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    18
 *
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    21
 * questions.
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    22
 */
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    23
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    24
/*
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    25
 * @test
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    26
 * @bug 8073866
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    27
 * @summary Fix for 8064703 may also cause stores between the allocation and arraycopy to be rexecuted after a deoptimization
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    28
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestArrayCopyBadReexec
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    29
 *
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    30
 */
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    31
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    32
public class TestArrayCopyBadReexec {
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    33
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    34
    static int val;
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    35
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    36
    static int[] m1(int[] src, int l) {
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    37
        if (src == null) {
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    38
            return null;
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    39
        }
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    40
        int[] dest = new int[10];
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    41
        val++;
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    42
        try {
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    43
            System.arraycopy(src, 0, dest, 0, l);
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    44
        } catch (IndexOutOfBoundsException npe) {
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    45
        }
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    46
        return dest;
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    47
    }
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    48
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    49
    static public void main(String[] args) {
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    50
        int[] src = new int[10];
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    51
        int[] res = null;
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    52
        boolean success = true;
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    53
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    54
        for (int i = 0; i < 20000; i++) {
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    55
            m1(src, 10);
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    56
        }
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    57
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    58
        int val_before = val;
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    59
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    60
        m1(src, -1);
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    61
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    62
        if (val - val_before != 1) {
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    63
            System.out.println("Bad increment: " + (val - val_before));
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    64
            throw new RuntimeException("Test failed");
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    65
        }
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    66
    }
4b08d63ac105 8073866: Fix for 8064703 is not sufficient
roland
parents:
diff changeset
    67
}