0N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A */
2362N/A
0N/A/*
0N/A * @test
0N/A * @bug 6843752
0N/A * @summary missing code for an anti-dependent Phi in GCM
0N/A * @run main/othervm -Xbatch Test
0N/A */
0N/A
0N/Apublic class Test {
0N/A
0N/A Item list;
0N/A
0N/A static class Item {
0N/A public Item next;
0N/A public Item prev;
0N/A public boolean remove;
0N/A
0N/A Item(boolean r) { remove = r; }
0N/A }
0N/A
0N/A private void linkIn(Item item) {
0N/A Item head = list;
0N/A if (head == null) {
0N/A item.next = item;
0N/A item.prev = item;
0N/A list = item;
0N/A } else {
0N/A item.next = head;
0N/A item.prev = head.prev;
0N/A head.prev.next = item;
0N/A head.prev = item;
0N/A }
0N/A }
0N/A
0N/A private void linkOut(Item item) {
0N/A Item head = list;
0N/A if (item.next == item) {
0N/A list = null;
0N/A } else {
0N/A item.prev.next = item.next;
0N/A item.next.prev = item.prev;
0N/A if (head == item) {
0N/A list = item.next;
0N/A }
0N/A }
0N/A item.next = null;
0N/A item.prev = null; // this is the null pointer we are seeing
0N/A }
0N/A
0N/A private void removeItems(int numItems) {
0N/A Item item = list;
0N/A if (item == null) {
0N/A return;
0N/A }
0N/A Item last = item.prev;
0N/A boolean done = false;
0N/A while (!done && numItems > 1) {
0N/A // the original code "done = (item == last);" triggered an infinite loop
0N/A // and was changed slightly in order to produce an exception instead.
0N/A done = (item.next == last.next);
0N/A item = item.next;
0N/A if (item.prev.remove) {
0N/A linkOut(item.prev);
0N/A }
0N/A }
0N/A }
0N/A
0N/A public void perform(int numItems) {
0N/A for (int i = 0; i < numItems; i++) {
0N/A linkIn(new Item(i == 0));
0N/A }
0N/A removeItems(numItems);
0N/A list = null;
0N/A }
0N/A
0N/A static public void main(String[] args) {
0N/A int caseCnt = 0;
0N/A Test bj = new Test();
0N/A try {
0N/A for (; caseCnt < 500000;) {
0N/A int numItems = (++caseCnt % 2);
0N/A if ((caseCnt % 64) == 0) {
0N/A numItems = 5;
0N/A }
0N/A bj.perform(numItems);
0N/A if ((caseCnt % 100000) == 0) {
0N/A System.out.println("successfully performed " + caseCnt + " cases");
0N/A }
0N/A }
0N/A } catch (Exception e) {
0N/A System.out.println("ERROR: crashed during case " + caseCnt);
e.printStackTrace(System.out);
System.exit(97);
}
}
}