hotspot/test/compiler/gcbarriers/G1CrashTest.java
author lana
Thu, 23 Feb 2017 17:30:12 +0000
changeset 44011 5eea3031ae7b
parent 41705 332239c052cc
permissions -rw-r--r--
Merge
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
 * @test
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    26
 * @bug 8023472
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    27
 * @summary C2 optimization breaks with G1
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    28
 *
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 19709
diff changeset
    29
 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 19709
diff changeset
    30
 *      -Dcount=100000 compiler.gcbarriers.G1CrashTest
19709
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
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 19709
diff changeset
    35
package compiler.gcbarriers;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 19709
diff changeset
    36
19709
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    37
public class G1CrashTest {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    38
    static Object[] set = new Object[11];
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    39
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    40
    public static void main(String[] args) throws InterruptedException {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    41
        for (int j = 0; j < Integer.getInteger("count"); j++) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    42
            Object key = new Object();
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    43
            insertKey(key);
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    44
            if (j > set.length / 2) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    45
                Object[] oldKeys = set;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    46
                set = new Object[2 * set.length - 1];
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    47
                for (Object o : oldKeys) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    48
                    if (o != null)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    49
                        insertKey(o);
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
    }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    54
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    55
    static void insertKey(Object key) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    56
        int hash = key.hashCode() & 0x7fffffff;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    57
        int index = hash % set.length;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    58
        Object cur = set[index];
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    59
        if (cur == null)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    60
            set[index] = key;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    61
        else
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    62
            insertKeyRehash(key, index, hash, cur);
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    63
    }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    64
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    65
    static void insertKeyRehash(Object key, int index, int hash, Object cur) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    66
        int loopIndex = index;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    67
        int firstRemoved = -1;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    68
        do {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    69
            if (cur == "dead")
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    70
                firstRemoved = 1;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    71
            index--;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    72
            if (index < 0)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    73
                index += set.length;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    74
            cur = set[index];
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    75
            if (cur == null) {
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    76
                if (firstRemoved != -1)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    77
                    set[firstRemoved] = "dead";
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    78
                else
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    79
                    set[index] = key;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    80
                return;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    81
            }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    82
        } while (index != loopIndex);
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    83
        if (firstRemoved != -1)
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    84
            set[firstRemoved] = null;
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    85
    }
33aa3e85cc75 8023472: C2 optimization breaks with G1
kvn
parents:
diff changeset
    86
}