*** empty log message ***
[IRC.git] / Robust / src / Benchmarks / Scheduling / GC / NON_BAMBOO / cachebench / TestRunner.p
1 /** Bamboo Version  
2  * Ported by: Jin Zhou  11/18/10
3  * **/
4 public class TestRunner extends Thread {
5   
6   public static final int kStretchTreeDepth;//    = 18; // about 16Mb
7   public static final int kLongLivedTreeDepth;//  = 16;  // about 4Mb
8   public static final int kArraySize;//  = 500000;  // about 4Mb
9   public static final int kMinTreeDepth;// = 4;
10   public static final int kMaxTreeDepth;// = 16;
11   
12   Node sharedroot;
13   //int[] sharedarray;
14   
15   public TestRunner(Node sroot) {
16   //public TestRunner(int[] sarray) {
17     kStretchTreeDepth    = 16;// 4Mb 18;  // about 16Mb
18     kLongLivedTreeDepth  = 14; // 1Mb 16;  // about 4Mb
19     kArraySize  = 250000; // 1Mb 500000;  // about 4Mb
20     kMinTreeDepth = 4;
21     kMaxTreeDepth = 4;//8;//14;
22     this.sharedroot = sroot;
23     //this.sharedarray = sarray;
24   }
25
26   // Nodes used by a tree of a given size
27   int TreeSize(int i) {
28     return ((1 << (i + 1)) - 1);
29   }
30
31   // Number of iterations to use for a given tree depth
32   int NumIters(int i) {
33     return 2 * TreeSize(kStretchTreeDepth) / TreeSize(i);
34   }
35
36   // Build tree top down, assigning to older objects. 
37   void Populate(int iDepth, Node thisNode) {
38     if (iDepth<=0) {
39       return;
40     } else {
41       iDepth--;
42       thisNode.left  = new Node();
43       thisNode.right = new Node();
44       Populate (iDepth, thisNode.left);
45       Populate (iDepth, thisNode.right);
46     }
47   }
48
49   // Build tree bottom-up
50   Node MakeTree(int iDepth) {
51     if (iDepth<=0) {
52       return new Node();
53     } else {
54       return new Node(MakeTree(iDepth-1),
55           MakeTree(iDepth-1));
56     }
57   }
58   
59   void tc1(int depth) {
60     Node tempTree = new Node();
61     Populate(depth, tempTree);
62     tempTree = null;
63   }
64   
65   void tc2(int depth) {
66     Node tempTree = MakeTree(depth);
67     tempTree = null;
68   }
69   
70   void traverseTree(Node root, int depth) {
71     if(root == null) {
72       return;
73     }
74     int sum = root.i + root.j;
75     root.i++;
76     tc1(depth);
77     traverseTree(root.left, depth);
78     tc2(depth);
79     traverseTree(root.right, depth);
80   }
81   
82   void tc3(int depth) {
83     // access the shared tree
84     traverseTree(this.sharedroot, depth);
85     /*int sum = 0;
86     for(int i = 0; i < sharedarray.length; i++) {
87       tc1(depth);
88       sum += sharedarray[i];
89       //tc2(depth);
90     }*/
91   }
92
93   void TimeConstruction(int depth) {
94     Node    root;
95     //long    tStart, tFinish;
96     int  iNumIters = NumIters(depth);
97     Node tempTree;
98
99     for (int i = 0; i < iNumIters; ++i) {
100       tc3(depth);  
101     }
102   }
103   
104   public void stretch() {
105     Node    root;
106     Node    longLivedTree;
107     Node    tempTree;
108
109     // Stretch the memory space quickly
110     tempTree = MakeTree(kStretchTreeDepth);
111     tempTree = null;
112   }
113
114   public void run() {
115     Node  root;
116     //Node  longLivedTree;
117     
118     // Stretch the memory space quickly
119     stretch();
120
121     // Create a long lived object
122     //longLivedTree = new Node();
123     //Populate(kLongLivedTreeDepth, longLivedTree);
124
125     // Create long-lived array, filling half of it
126     float array[] = new float[kArraySize];
127     for (int i = 0; i < kArraySize/2; ++i) {
128       array[i] = 1.0f/i;
129     }
130
131     for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
132       TimeConstruction(0);
133     }
134
135     if (/*longLivedTree == null || */array[1000] != 1.0f/1000) {
136       //System.out.println("Failed");
137       System.printI(0xa0);
138       System.printI((int)(array[1000]*1000000));
139     }
140     // fake reference to LongLivedTree
141     // and array
142     // to keep them from being optimized away
143   }
144
145   public static void main(String[] args) {
146     // make a shared array
147     int kLongLivedTreeDepth  = 12; // 256kb 16;  // about 4Mb
148     Helper helper = new Helper(kLongLivedTreeDepth);
149     //int kArraySize = 1250;//0;//0; // 1Mb 500000;  // about 4Mb
150     //int array[] = new int[kArraySize];
151     /*for (int i = 0; i < kArraySize/2; ++i) {
152       array[i] = i;
153     }*/
154
155     int threadnum = THREADNUM;
156     System.setgcprofileflag();
157     TestRunner trarray[]=new TestRunner[threadnum];
158     for(int i = 1; i < threadnum; ++i) {
159       TestRunner tr = new TestRunner(/*array*/helper.root);
160       tr.start();
161       trarray[i]=tr;
162     }
163     TestRunner tr0 = new TestRunner(/*array*/helper.root);
164     tr0.run();
165     for(int i = 1; i < threadnum; ++i) {
166       trarray[i].join();
167     }
168   }
169 } // class JavaGC