hotspot/test/compiler/gcbarriers/G1CrashTest.java
author fzhinkin
Wed, 03 Sep 2014 15:29:57 +0400
changeset 26439 0fa6c2cb6007
parent 19709 33aa3e85cc75
child 40059 c2304140ed64
permissions -rw-r--r--
8055904: Develop tests for new command-line options related to SHA intrinsics Reviewed-by: kvn, iignatyev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19709
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     1
/*
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     4
 *
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     8
 *
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    13
 * accompanied this code).
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    14
 *
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    18
 *
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    21
 * questions.
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    22
 *
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    23
 */
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    24
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    25
/**
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    26
 * @test
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    27
 * @bug 8023472
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    28
 * @summary C2 optimization breaks with G1
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    29
 *
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    30
 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -Dcount=100000 G1CrashTest
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    31
 *
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    32
 * @author pbiswal@palantir.com
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    33
 */
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    34
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    35
public class G1CrashTest {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    36
    static Object[] set = new Object[11];
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    37
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    38
    public static void main(String[] args) throws InterruptedException {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    39
        for (int j = 0; j < Integer.getInteger("count"); j++) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    40
            Object key = new Object();
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    41
            insertKey(key);
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    42
            if (j > set.length / 2) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    43
                Object[] oldKeys = set;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    44
                set = new Object[2 * set.length - 1];
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    45
                for (Object o : oldKeys) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    46
                    if (o != null)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    47
                        insertKey(o);
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    48
                }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    49
            }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    50
        }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    51
    }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    52
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    53
    static void insertKey(Object key) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    54
        int hash = key.hashCode() & 0x7fffffff;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    55
        int index = hash % set.length;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    56
        Object cur = set[index];
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    57
        if (cur == null)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    58
            set[index] = key;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    59
        else
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    60
            insertKeyRehash(key, index, hash, cur);
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    61
    }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    62
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    63
    static void insertKeyRehash(Object key, int index, int hash, Object cur) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    64
        int loopIndex = index;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    65
        int firstRemoved = -1;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    66
        do {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    67
            if (cur == "dead")
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    68
                firstRemoved = 1;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    69
            index--;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    70
            if (index < 0)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    71
                index += set.length;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    72
            cur = set[index];
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    73
            if (cur == null) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    74
                if (firstRemoved != -1)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    75
                    set[firstRemoved] = "dead";
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    76
                else
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    77
                    set[index] = key;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    78
                return;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    79
            }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    80
        } while (index != loopIndex);
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    81
        if (firstRemoved != -1)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    82
            set[firstRemoved] = null;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    83
    }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    84
}