add new benchmark lcss which was ported frim nofib benchmark suite
[IRC.git] / Robust / src / Benchmarks / Scheduling / GC / GCBench / GCBench.java
1 /** Bamboo Version  
2  * Ported by: Jin Zhou  07/14/10
3  * **/
4
5 //This is adapted from a benchmark written by John Ellis and Pete Kovac
6 //of Post Communications.
7 //It was modified by Hans Boehm of Silicon Graphics.
8
9 //This is no substitute for real applications.  No actual application
10 //is likely to behave in exactly this way.  However, this benchmark was
11 //designed to be more representative of real applications than other
12 //Java GC benchmarks of which we are aware.
13 //It attempts to model those properties of allocation requests that
14 //are important to current GC techniques.
15 //It is designed to be used either to obtain a single overall performance
16 //number, or to give a more detailed estimate of how collector
17 //performance varies with object lifetimes.  It prints the time
18 //required to allocate and collect balanced binary trees of various
19 //sizes.  Smaller trees result in shorter object lifetimes.  Each cycle
20 //allocates roughly the same amount of memory.
21 //Two data structures are kept around during the entire process, so
22 //that the measured performance is representative of applications
23 //that maintain some live in-memory data.  One of these is a tree
24 //containing many pointers.  The other is a large array containing
25 //double precision floating point numbers.  Both should be of comparable
26 //size.
27
28 //The results are only really meaningful together with a specification
29 //of how much memory was used.  It is possible to trade memory for
30 //better time performance.  This benchmark should be run in a 32 MB
31 //heap, though we don't currently know how to enforce that uniformly.
32
33 //Unlike the original Ellis and Kovac benchmark, we do not attempt
34 //measure pause times.  This facility should eventually be added back
35 //in.  There are several reasons for omitting it for now.  The original
36 //implementation depended on assumptions about the thread scheduler
37 //that don't hold uniformly.  The results really measure both the
38 //scheduler and GC.  Pause time measurements tend to not fit well with
39 //current benchmark suites.  As far as we know, none of the current
40 //commercial Java implementations seriously attempt to minimize GC pause
41 //times.
42
43 //Known deficiencies:
44 //- No way to check on memory use
45 //- No cyclic data structures
46 //- No attempt to measure variation with object size
47 //- Results are sensitive to locking cost, but we dont
48 //check for proper locking
49
50 task t1(StartupObject s{initialstate}) {
51   //System.printString("task t1\n");
52
53   int threadnum = 62; // 56;
54   for(int i = 0; i < threadnum; ++i) {
55     TestRunner gcb = new TestRunner(){run};
56   }
57
58   taskexit(s{!initialstate});
59 }
60
61 task t2(TestRunner gcb{run}) {
62   //System.printString("task t2\n");
63   gcb.run();
64   taskexit(gcb{!run});
65 }
66
67
68 class Node {
69   Node left, right;
70   int i, j;
71   Node(Node l, Node r) { left = l; right = r; }
72   Node() { }
73 }
74
75 public class TestRunner {
76   
77   flag run;
78
79   public static final int kStretchTreeDepth;//    = 18; // about 16Mb
80   public static final int kLongLivedTreeDepth;//  = 16;  // about 4Mb
81   public static final int kArraySize;//  = 500000;  // about 4Mb
82   public static final int kMinTreeDepth;// = 4;
83   public static final int kMaxTreeDepth;// = 16;
84   
85   public TestRunner() {
86     kStretchTreeDepth    = 16;// 4Mb 18;  // about 16Mb
87     kLongLivedTreeDepth  = 14; // 1Mb 16;  // about 4Mb
88     kArraySize  = 250000; // 1Mb 500000;  // about 4Mb
89     kMinTreeDepth = 4;
90     kMaxTreeDepth = 14;
91   }
92
93   // Nodes used by a tree of a given size
94   int TreeSize(int i) {
95     return ((1 << (i + 1)) - 1);
96   }
97
98   // Number of iterations to use for a given tree depth
99   int NumIters(int i) {
100     return 2 * TreeSize(kStretchTreeDepth) / TreeSize(i);
101   }
102
103   // Build tree top down, assigning to older objects. 
104   void Populate(int iDepth, Node thisNode) {
105     if (iDepth<=0) {
106       return;
107     } else {
108       iDepth--;
109       thisNode.left  = new Node();
110       thisNode.right = new Node();
111       Populate (iDepth, thisNode.left);
112       Populate (iDepth, thisNode.right);
113     }
114   }
115
116   // Build tree bottom-up
117   Node MakeTree(int iDepth) {
118     if (iDepth<=0) {
119       return new Node();
120     } else {
121       return new Node(MakeTree(iDepth-1),
122           MakeTree(iDepth-1));
123     }
124   }
125
126   /*static void PrintDiagnostics() {
127     long lFreeMemory = Runtime.getRuntime().freeMemory();
128     long lTotalMemory = Runtime.getRuntime().totalMemory();
129
130     System.out.print(" Total memory available="
131         + lTotalMemory + " bytes");
132     System.out.println("  Free memory=" + lFreeMemory + " bytes");
133   }*/
134   
135   void tc1(int depth) {
136     Node tempTree = new Node();
137     Populate(depth, tempTree);
138     tempTree = null;
139   }
140   
141   void tc2(int depth) {
142     Node tempTree = MakeTree(depth);
143     tempTree = null;
144   }
145
146   void TimeConstruction(int depth) {
147     Node    root;
148     //long    tStart, tFinish;
149     int         iNumIters = NumIters(depth);
150     Node        tempTree;
151
152     /*System.out.println("Creating " + iNumIters +
153         " trees of depth " + depth);
154     tStart = System.currentTimeMillis();*/
155     for (int i = 0; i < iNumIters; ++i) {
156       /*tempTree = new Node();
157       Populate(depth, tempTree);
158       tempTree = null;*/
159       tc1(depth);
160     }
161     /*tFinish = System.currentTimeMillis();
162     System.out.println("\tTop down construction took "
163         + (tFinish - tStart) + "msecs");
164     tStart = System.currentTimeMillis();*/
165     for (int i = 0; i < iNumIters; ++i) {
166       /*tempTree = MakeTree(depth);
167       tempTree = null;*/
168       tc2(depth);
169     }
170     /*tFinish = System.currentTimeMillis();
171     System.out.println("\tBottom up construction took "
172         + (tFinish - tStart) + "msecs");*/
173
174   }
175   
176   public void stretch() {
177     Node    root;
178     Node    longLivedTree;
179     Node    tempTree;
180     /*long  tStart, tFinish;
181     long    tElapsed;*/
182
183
184     /*System.out.println("Garbage Collector Test");
185     System.out.println(
186         " Stretching memory with a binary tree of depth "
187         + kStretchTreeDepth);
188     PrintDiagnostics();
189     tStart = System.currentTimeMillis();*/
190
191     // Stretch the memory space quickly
192     tempTree = MakeTree(kStretchTreeDepth);
193     tempTree = null;
194   }
195
196   public void run() {
197     Node        root;
198     Node        longLivedTree;
199     
200     // Stretch the memory space quickly
201     stretch();
202
203     // Create a long lived object
204     /*System.out.println(
205         " Creating a long-lived binary tree of depth " +
206         kLongLivedTreeDepth);*/
207     longLivedTree = new Node();
208     Populate(kLongLivedTreeDepth, longLivedTree);
209
210     // Create long-lived array, filling half of it
211     /*System.out.println(
212         " Creating a long-lived array of "
213         + kArraySize + " doubles");*/
214     float array[] = new float[kArraySize];
215     for (int i = 0; i < kArraySize/2; ++i) {
216       array[i] = 1.0f/i;
217     }
218     //PrintDiagnostics();
219
220     for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
221       TimeConstruction(d);
222     }
223
224     if (longLivedTree == null || array[1000] != 1.0f/1000) {
225       //System.out.println("Failed");
226       System.printI(0xa0);
227       System.printI((int)(array[1000]*1000000));
228     }
229     // fake reference to LongLivedTree
230     // and array
231     // to keep them from being optimized away
232
233     /*tFinish = System.currentTimeMillis();
234     tElapsed = tFinish-tStart;
235     PrintDiagnostics();
236     System.out.println("Completed in " + tElapsed + "ms.");*/
237   }
238 } // class JavaGC