// DOB: tester for distributed GC // test the various methods of allowing gp's to escape via "pushes" immutable class X { public char junk; public String str; public char junk2; public X() {} public X(String str) { this.str = str; } } class Y { public X x; public String str; } public class A { public static String str1, str2, str3, str4, str5, str6, str7, str8; public static single void init() { if (Ti.thisProc() == 0) { String foo = new String((Ti.thisProc()==0?"":"argh")); // defeat Java's constant-merging on strings str1 = new String("str1"+foo); str2 = new String("str2"+foo); str3 = new String("str3"+foo); str4 = new String("str4"+foo); str5 = new String("str5"+foo); str6 = new String("str6"+foo); str7 = new String("str7"+foo); str8 = new String("str8"+foo); } // broadcast str1 = broadcast str1 from 0; // exchange String [1d] single exc = new String[0:Ti.numProcs()-1]; exc.exchange(str2); str2 = exc[0]; // immutable broadcast X temp = new X(str3); temp = broadcast temp from 0; str3 = temp.str; // immutable exchange X [1d] single temparr = new X[0:Ti.numProcs()-1]; X temp2 = new X(str4); temparr.exchange(temp2); str4 = temparr[0].str; // assign - gp and immutable Y y = new Y(); Y [1d] single temparr2 = new Y[0:Ti.numProcs()-1]; temparr2.exchange(y); if (Ti.thisProc() == 0) { X tempx = new X(str6); for (int i=0; i < Ti.numProcs(); i++) { temparr2[i].str = str5; temparr2[i].x = tempx; } } Ti.barrier(); str5 = y.str; str6 = y.x.str; // Java array copy X[] xjarr = new X[10]; X [1d] single [] temparr3 = new X[0:Ti.numProcs()-1][]; temparr3.exchange(xjarr); if (Ti.thisProc() == 0) { X foo = new X(str7); xjarr[5] = foo; for (int i=0; i < Ti.numProcs(); i++) { System.arraycopy(xjarr,0,temparr3[i],0,10); } } Ti.barrier(); str7 = xjarr[5].str; // Titanium array copy X[1d] xarr = new X[1:10]; X [1d] single [1d] temparr4 = new X[0:Ti.numProcs()-1][1d]; temparr4.exchange(xarr); if (Ti.thisProc() == 0) { X foo = new X(str8); xarr[5] = foo; for (int i=0; i < Ti.numProcs(); i++) { temparr4[i].copy(xarr); } } Ti.barrier(); str8 = xarr[5].str; } public static single void check() { //String header = ""+Ti.thisProc()+": "; String header = ""; Ti.barrier(); if (Ti.thisProc() != 0) { System.out.println(header + " str1=" + str1 + " str2=" + str2 + " str3=" + str3 + " str4=" + str4 + " str5=" + str5 + " str6=" + str6 + " str7=" + str7 + " str8=" + str8 + ""); } try { Thread.sleep(1000); // time for output } catch (Throwable exn) {} Ti.barrier(); } public static void killref() { // kill all refs to "str*" that live on P0 str1 = null; str2 = null; str3 = null; str4 = null; str5 = null; str6 = null; str7 = null; str8 = null; } public static single void main(String[]args) { if (Ti.thisProc() == 0) System.out.println("init.."); init(); if (Ti.thisProc() == 0) System.out.println("before:"); check(); if (Ti.thisProc() == 0) { System.out.println("killing all 0 refs..."); killref(); System.gc(); // this collection will see "str*" as locally dead doWork(); } if (Ti.thisProc() == 0) System.out.println("after:"); check(); } public static void clearStack(int levels) { int w; int x; int y; int z; if (levels > 0) clearStack(levels-1); } public static void doWork() { clearStack(4000); for (int i=0; i < 10000; i++) { java.util.Stack s = new java.util.Stack(); String x = new String("xxxx-"+i); for (int j=2; j <= 4096; j = j << 2) { s.push(new char[j]); } s = null; } System.gc(); } }