test/compiler/gcbarriers/G1CrashTest.java

changeset 5627
b17d8f6d9ed7
parent 0
f90c822e73f8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/gcbarriers/G1CrashTest.java	Fri Aug 23 18:04:35 2013 -0700
     1.3 @@ -0,0 +1,84 @@
     1.4 +/*
     1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +/**
    1.29 + * @test
    1.30 + * @bug 8023472
    1.31 + * @summary C2 optimization breaks with G1
    1.32 + *
    1.33 + * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -Dcount=100000 G1CrashTest
    1.34 + *
    1.35 + * @author pbiswal@palantir.com
    1.36 + */
    1.37 +
    1.38 +public class G1CrashTest {
    1.39 +    static Object[] set = new Object[11];
    1.40 +
    1.41 +    public static void main(String[] args) throws InterruptedException {
    1.42 +        for (int j = 0; j < Integer.getInteger("count"); j++) {
    1.43 +            Object key = new Object();
    1.44 +            insertKey(key);
    1.45 +            if (j > set.length / 2) {
    1.46 +                Object[] oldKeys = set;
    1.47 +                set = new Object[2 * set.length - 1];
    1.48 +                for (Object o : oldKeys) {
    1.49 +                    if (o != null)
    1.50 +                        insertKey(o);
    1.51 +                }
    1.52 +            }
    1.53 +        }
    1.54 +    }
    1.55 +
    1.56 +    static void insertKey(Object key) {
    1.57 +        int hash = key.hashCode() & 0x7fffffff;
    1.58 +        int index = hash % set.length;
    1.59 +        Object cur = set[index];
    1.60 +        if (cur == null)
    1.61 +            set[index] = key;
    1.62 +        else
    1.63 +            insertKeyRehash(key, index, hash, cur);
    1.64 +    }
    1.65 +
    1.66 +    static void insertKeyRehash(Object key, int index, int hash, Object cur) {
    1.67 +        int loopIndex = index;
    1.68 +        int firstRemoved = -1;
    1.69 +        do {
    1.70 +            if (cur == "dead")
    1.71 +                firstRemoved = 1;
    1.72 +            index--;
    1.73 +            if (index < 0)
    1.74 +                index += set.length;
    1.75 +            cur = set[index];
    1.76 +            if (cur == null) {
    1.77 +                if (firstRemoved != -1)
    1.78 +                    set[firstRemoved] = "dead";
    1.79 +                else
    1.80 +                    set[index] = key;
    1.81 +                return;
    1.82 +            }
    1.83 +        } while (index != loopIndex);
    1.84 +        if (firstRemoved != -1)
    1.85 +            set[firstRemoved] = null;
    1.86 +    }
    1.87 +}

mercurial