2 * Ported by: Jin Zhou 11/18/10
4 public class TestRunner extends Thread {
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;
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
21 kMaxTreeDepth = 4;//8;//14;
22 this.sharedroot = sroot;
23 //this.sharedarray = sarray;
26 // Nodes used by a tree of a given size
28 return ((1 << (i + 1)) - 1);
31 // Number of iterations to use for a given tree depth
33 return 2 * TreeSize(kStretchTreeDepth) / TreeSize(i);
36 // Build tree top down, assigning to older objects.
37 void Populate(int iDepth, Node thisNode) {
42 thisNode.left = new Node();
43 thisNode.right = new Node();
44 Populate (iDepth, thisNode.left);
45 Populate (iDepth, thisNode.right);
49 // Build tree bottom-up
50 Node MakeTree(int iDepth) {
54 return new Node(MakeTree(iDepth-1),
60 Node tempTree = new Node();
61 Populate(depth, tempTree);
66 Node tempTree = MakeTree(depth);
70 void traverseTree(Node root, int depth) {
74 int sum = root.i + root.j;
77 traverseTree(root.left, depth);
79 traverseTree(root.right, depth);
83 // access the shared tree
84 traverseTree(this.sharedroot, depth);
86 for(int i = 0; i < sharedarray.length; i++) {
88 sum += sharedarray[i];
93 void TimeConstruction(int depth) {
95 //long tStart, tFinish;
96 int iNumIters = NumIters(depth);
99 for (int i = 0; i < iNumIters; ++i) {
104 public void stretch() {
109 // Stretch the memory space quickly
110 tempTree = MakeTree(kStretchTreeDepth);
116 //Node longLivedTree;
118 // Stretch the memory space quickly
121 // Create a long lived object
122 //longLivedTree = new Node();
123 //Populate(kLongLivedTreeDepth, longLivedTree);
125 // Create long-lived array, filling half of it
126 float array[] = new float[kArraySize];
127 for (int i = 0; i < kArraySize/2; ++i) {
131 for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
135 if (/*longLivedTree == null || */array[1000] != 1.0f/1000) {
136 //System.out.println("Failed");
138 System.printI((int)(array[1000]*1000000));
140 // fake reference to LongLivedTree
142 // to keep them from being optimized away
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) {
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);
163 TestRunner tr0 = new TestRunner(/*array*/helper.root);
165 for(int i = 1; i < threadnum; ++i) {