Path: blob/master/test/hotspot/jtreg/compiler/gcbarriers/G1CrashTest.java
41149 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 802347226* @summary C2 optimization breaks with G127*28* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation29* -Dcount=100000 compiler.gcbarriers.G1CrashTest30*31* @author [email protected]32*/3334package compiler.gcbarriers;3536public class G1CrashTest {37static Object[] set = new Object[11];3839public static void main(String[] args) throws InterruptedException {40for (int j = 0; j < Integer.getInteger("count"); j++) {41Object key = new Object();42insertKey(key);43if (j > set.length / 2) {44Object[] oldKeys = set;45set = new Object[2 * set.length - 1];46for (Object o : oldKeys) {47if (o != null)48insertKey(o);49}50}51}52}5354static void insertKey(Object key) {55int hash = key.hashCode() & 0x7fffffff;56int index = hash % set.length;57Object cur = set[index];58if (cur == null)59set[index] = key;60else61insertKeyRehash(key, index, hash, cur);62}6364static void insertKeyRehash(Object key, int index, int hash, Object cur) {65int loopIndex = index;66int firstRemoved = -1;67do {68if (cur == "dead")69firstRemoved = 1;70index--;71if (index < 0)72index += set.length;73cur = set[index];74if (cur == null) {75if (firstRemoved != -1)76set[firstRemoved] = "dead";77else78set[index] = key;79return;80}81} while (index != loopIndex);82if (firstRemoved != -1)83set[firstRemoved] = null;84}85}868788