1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/6843752/Test.java Wed May 27 12:35:51 2009 -0700 1.3 @@ -0,0 +1,119 @@ 1.4 +/* 1.5 + * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6843752 1.30 + * @summary missing code for an anti-dependent Phi in GCM 1.31 + * @run main/othervm -Xbatch Test 1.32 + */ 1.33 + 1.34 +public class Test { 1.35 + 1.36 + Item list; 1.37 + 1.38 + static class Item { 1.39 + public Item next; 1.40 + public Item prev; 1.41 + public boolean remove; 1.42 + 1.43 + Item(boolean r) { remove = r; } 1.44 + } 1.45 + 1.46 + private void linkIn(Item item) { 1.47 + Item head = list; 1.48 + if (head == null) { 1.49 + item.next = item; 1.50 + item.prev = item; 1.51 + list = item; 1.52 + } else { 1.53 + item.next = head; 1.54 + item.prev = head.prev; 1.55 + head.prev.next = item; 1.56 + head.prev = item; 1.57 + } 1.58 + } 1.59 + 1.60 + private void linkOut(Item item) { 1.61 + Item head = list; 1.62 + if (item.next == item) { 1.63 + list = null; 1.64 + } else { 1.65 + item.prev.next = item.next; 1.66 + item.next.prev = item.prev; 1.67 + if (head == item) { 1.68 + list = item.next; 1.69 + } 1.70 + } 1.71 + item.next = null; 1.72 + item.prev = null; // this is the null pointer we are seeing 1.73 + } 1.74 + 1.75 + private void removeItems(int numItems) { 1.76 + Item item = list; 1.77 + if (item == null) { 1.78 + return; 1.79 + } 1.80 + Item last = item.prev; 1.81 + boolean done = false; 1.82 + while (!done && numItems > 1) { 1.83 + // the original code "done = (item == last);" triggered an infinite loop 1.84 + // and was changed slightly in order to produce an exception instead. 1.85 + done = (item.next == last.next); 1.86 + item = item.next; 1.87 + if (item.prev.remove) { 1.88 + linkOut(item.prev); 1.89 + } 1.90 + } 1.91 + } 1.92 + 1.93 + public void perform(int numItems) { 1.94 + for (int i = 0; i < numItems; i++) { 1.95 + linkIn(new Item(i == 0)); 1.96 + } 1.97 + removeItems(numItems); 1.98 + list = null; 1.99 + } 1.100 + 1.101 + static public void main(String[] args) { 1.102 + int caseCnt = 0; 1.103 + Test bj = new Test(); 1.104 + try { 1.105 + for (; caseCnt < 500000;) { 1.106 + int numItems = (++caseCnt % 2); 1.107 + if ((caseCnt % 64) == 0) { 1.108 + numItems = 5; 1.109 + } 1.110 + bj.perform(numItems); 1.111 + if ((caseCnt % 100000) == 0) { 1.112 + System.out.println("successfully performed " + caseCnt + " cases"); 1.113 + } 1.114 + } 1.115 + } catch (Exception e) { 1.116 + System.out.println("ERROR: crashed during case " + caseCnt); 1.117 + e.printStackTrace(System.out); 1.118 + System.exit(97); 1.119 + } 1.120 + } 1.121 +} 1.122 +