collect statistics
[IRC.git] / Robust / src / buildscript
1 #!/bin/bash
2
3 printhelp() {
4 echo -robustroot set up the ROBUSTROOT to directory other than default one
5 echo -dsm distributed shared memory
6 echo -singleTM single machine committing transactions
7 echo -abortreaders abort readers immediately
8 echo -trueprob double - probabiltiy of true branch
9 echo -dsmcaching -enable caching in dsm runtime
10 echo -mac distributed shared memory mac support
11 echo -check generate check code
12 echo -dmalloc link in dmalloc
13 echo -recover compile task code
14 echo -fastcheck fast checkpointing for Bristlecone
15 echo -specdir directory
16 echo -printflat print out flat representation
17 echo -selfloop task - this task cannot self loop forever
18 echo "-excprefetch methoddescriptor - exclude prefetches for this method (specified as class.method)"
19 echo -taskstate do task state analysis
20 echo -tagstate do tag state analysis
21 echo -scheduling do task scheduling
22 echo -multicore generate multi-core version binary
23 echo "-numcore set the number of cores (should be used together with -multicore), defaultly set as 1"
24 echo "-raw generate raw version binary (should be used together with -multicore)"
25 echo "-rawcacheflush enable cache flush in raw version binary (should be used togethere with -raw)"
26 echo "-interrupt generate raw version binary with interruption (should be used togethere with -raw)"
27 echo "-rawconfig config raw simulator as 4xn (should be used together with -raw)"
28 echo "-rawpath print out execute path information for raw version (should be used together with -raw)"
29 echo "-useprofile use profiling data for scheduling (should be used together with -raw)"
30 echo -threadsimulate generate multi-thread simulate version binary
31 echo -printscheduling print out scheduling graphs
32 echo -printschedulesim print out scheduling simulator result graphs
33 echo -abcclose close the array boundary check
34 echo -optional enable optional
35 echo -debug generate debug symbols
36 echo -prefetch do prefetch analysis
37 echo -transstats generates transaction stats on commits and aborts
38 echo -garbagestats Print garbage collection statistics
39 echo -webinterface enable web interface
40 echo -runtimedebug printout runtime debug messages
41 echo "-thread use support for multiple threads"
42 echo "-optimize call gcc with -O9 (optimize)"
43 echo "-nooptimize call gcc with -O0 (do not optimize)"
44 echo -curdir directory 
45 echo -mainclass class with main method
46 echo -o binary
47 echo -nojava do not run bristlecone compiler
48 echo -instructionfailures inject code for instructionfailures
49 echo -profile build with profile options
50 echo "-rawuseio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version"
51 echo "-enable-assertions execute assert statements during compilation"
52 echo -justanalyze exit after compiler analyses complete
53 echo -help help
54 }
55
56 ABORTREADERS=false;
57 ROBUSTROOT=~/research/Robust/src
58 DSMRUNTIME=$ROBUSTROOT/Runtime/DSTM/interface/
59 REPAIRROOT=~/research/Repair/RepairCompiler/
60 CURDIR=`pwd`
61 DSMFLAG=false
62 SINGLETM=false
63 NOJAVA=false
64 CHECKFLAG=false
65 RECOVERFLAG=false
66 MLPFLAG=false
67 MULTICOREFLAG=false
68 RAWFLAG=false
69 RAWCACHEFLUSHFLAG=false
70 RAWCONFIG=''
71 RAWDEBUGFLAG=false
72 RAWPATHFLAG=false
73 RAWPROFILEFLAG=false
74 RAWUSEIOFLAG=false
75 INTERRUPTFLAG=false
76 THREADSIMULATEFLAG=false;
77 USEDMALLOC=false
78 THREADFLAG=false
79 FASTCHECK=false
80 SPECDIR=`pwd`
81 SRCFILES=''
82 EXTRAOPTIONS=''
83 MAINFILE='a'
84 JAVAFORWARDOPTS=''
85 JAVAOPTS=''
86 OPTIONALFLAG=false
87 EXITAFTERANALYSIS=false
88
89 if [[ -z $1 ]]
90 then
91 printhelp
92 exit
93 fi
94
95 while [[ -n $1 ]]
96 do
97 if [[ $1 = '-help' ]]
98 then
99 printhelp
100 exit
101 elif [[ $1 = '-justanalyze' ]]
102 then
103 EXITAFTERANALYSIS=true
104 elif [[ $1 = '-abortreaders' ]]
105 then
106 ABORTREADERS=true
107 EXTRAOPTIONS="$EXTRAOPTIONS -DABORTREADERS"
108 JAVAOPTS="$JAVAOPTS -abortreaders"
109 elif [[ $1 = '-robustroot' ]]
110 then
111 ROBUSTROOT="$2"
112 shift
113 elif [[ $1 = '-nojava' ]]
114 then
115 NOJAVA=true
116 elif [[ $1 = '-garbagestats' ]]
117 then
118 EXTRAOPTIONS="$EXTRAOPTIONS -DGARBAGESTATS"
119 elif [[ $1 = '-fastcheck' ]]
120 then
121 EXTRAOPTIONS="$EXTRAOPTIONS -DFASTCHECK"
122 JAVAOPTS="$JAVAOPTS -fastcheck"
123 FASTCHECK=true
124 elif [[ $1 = '-o' ]]
125 then
126 MAINFILE="$2"
127 shift
128 elif [[ $1 = '-mainclass' ]]
129 then
130 JAVAOPTS="$JAVAOPTS -mainclass $2"
131 shift
132 elif [[ $1 = '-selfloop' ]]
133 then
134 JAVAOPTS="$JAVAOPTS -selfloop $2"
135 shift
136 elif [[ $1 = '-excprefetch' ]]
137 then
138 JAVAOPTS="$JAVAOPTS -excprefetch $2"
139 shift
140 elif [[ $1 = '-dsm' ]]
141 then
142 JAVAOPTS="$JAVAOPTS -dsm"
143 DSMFLAG=true
144 elif [[ $1 = '-singleTM' ]]
145 then
146 JAVAOPTS="$JAVAOPTS -singleTM"
147 EXTRAOPTIONS="$EXTRAOPTIONS -DSTM"
148 SINGLETM=true
149 elif [[ $1 = '-prefetch' ]]
150 then
151 JAVAOPTS="$JAVAOPTS -prefetch"
152 elif [[ $1 = '-transstats' ]]
153 then
154 EXTRAOPTIONS="$EXTRAOPTIONS -DTRANSSTATS"
155 elif [[ $1 = '-printflat' ]]
156 then
157 JAVAOPTS="$JAVAOPTS -printflat"
158 elif [[ $1 = '-trueprob' ]]
159 then
160 JAVAOPTS="$JAVAOPTS -trueprob $2"
161 shift
162 elif [[ $1 = '-mac' ]]
163 then
164 EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"
165 elif [[ $1 = '-profile' ]]
166 then
167 RAWPROFILEFLAG=true
168 EXTRAOPTIONS="$EXTRAOPTIONS -pg"
169 elif [[ $1 = '-rawuseio' ]]
170 then
171 RAWUSEIOFLAG=true
172 elif [[ $1 = '-taskstate' ]]
173 then
174 JAVAOPTS="$JAVAOPTS -taskstate"
175 elif [[ $1 = '-tagstate' ]]
176 then
177 JAVAOPTS="$JAVAOPTS -tagstate"
178 elif [[ $1 = '-scheduling' ]]
179 then
180 JAVAOPTS="$JAVAOPTS -scheduling"
181 elif [[ $1 = '-multicore' ]]
182 then
183 MULTICOREFLAG=true
184 JAVAOPTS="$JAVAOPTS -multicore"
185 elif [[ $1 = '-numcore' ]]
186 then
187 JAVAOPTS="$JAVAOPTS -numcore $2"
188 shift
189 elif [[ $1 = '-raw' ]]
190 then
191 RAWFLAG=true
192 JAVAOPTS="$JAVAOPTS -raw"
193 elif [[ $1 = '-rawcacheflush' ]]
194 then
195 RAWCACHEFLUSHFLAG=true
196 elif [[ $1 = '-rawconfig' ]]
197 then
198 RAWCONFIG="$2"
199 shift
200 elif [[ $1 = '-interrupt' ]]
201 then
202 INTERRUPTFLAG=true
203 elif [[ $1 = '-threadsimulate' ]]
204 then
205 THREADSIMULATEFLAG=true
206 elif [[ $1 = '-abcclose' ]]
207 then
208 JAVAOPTS="$JAVAOPTS -abcclose"
209 elif [[ $1 = '-optional' ]]
210 then
211 JAVAOPTS="$JAVAOPTS -optional"
212 OPTIONALFLAG=true
213 elif [[ $1 = '-dmalloc' ]]
214 then
215 USEDMALLOC=true
216 elif [[ $1 = '-recover' ]]
217 then
218 RECOVERFLAG=true
219 JAVAOPTS="$JAVAOPTS -task"
220 elif [[ $1 = '-useprofile' ]]
221 then
222 JAVAOPTS="$JAVAOPTS -useprofile"
223 elif [[ $1 = '-webinterface' ]]
224 then
225 JAVAOPTS="$JAVAOPTS -webinterface"
226 elif [[ $1 = '-instructionfailures' ]]
227 then
228 JAVAOPTS="$JAVAOPTS -instructionfailures"
229 elif [[ $1 = '-joptimize' ]]
230 then
231 JAVAOPTS="$JAVAOPTS -optimize"
232 elif [[ $1 = '-mlp' ]]
233 then
234 JAVAOPTS="$JAVAOPTS -mlp"
235 elif [[ $1 = '-check' ]]
236 then
237 CHECKFLAG=true
238 JAVAOPTS="$JAVAOPTS -conscheck"
239 elif [[ $1 = '-enable-assertions' ]]
240 then
241 JAVAFORWARDOPTS="$JAVAFORWARDOPTS -ea"
242 elif [[ $1 = '-specdir' ]]
243 then
244 cd $2
245 SPECDIR=`pwd`
246 cd $CURDIR
247 shift
248 elif [[ $1 = '-debug' ]]
249 then
250 RAWDEBUGFLAG=true
251 EXTRAOPTIONS="$EXTRAOPTIONS -g"
252 elif [[ $1 = '-rawpath' ]]
253 then
254 RAWPATHFLAG=true
255 elif [[ $1 = '-runtimedebug' ]]
256 then
257 EXTRAOPTIONS="$EXTRAOPTIONS -DDEBUG"
258 elif [[ $1 = '-dsmcaching' ]]
259 then
260 EXTRAOPTIONS="$EXTRAOPTIONS -DCACHE"
261 elif [[ $1 = '-rangeprefetch' ]]
262 then
263 EXTRAOPTIONS="$EXTRAOPTIONS -DRANGEPREFETCH"
264 elif [[ $1 = '-nooptimize' ]]
265 then
266 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
267 elif [[ $1 = '-optimize' ]]
268 then
269 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
270 elif [[ $1 = '-thread' ]]
271 then
272 JAVAOPTS="$JAVAOPTS -thread"
273 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
274 THREADFLAG=true
275 elif [[ $1 = '-distributioninfo' ]]
276 then
277 JAVAOPTS="$JAVAOPTS -distributioninfo"
278 elif [[ $1 = '-curdir' ]]
279 then
280 CURDIR=$2
281 shift
282 elif [[ $1 = '-outputdir' ]]
283 then
284 JAVAOPTS="$JAVAOPTS -outputdir $2"
285 shift
286 else
287 SRCFILES="$SRCFILES $1"
288 fi
289 shift
290 done
291
292 BUILDDIR="$CURDIR/tmpbuilddirectory"
293
294 cd $1
295 cd $CURDIR
296 shift
297
298 mkdir $BUILDDIR
299
300 if $CHECKFLAG #Generate structure files for repair tool
301 then
302 JAVAOPTS="$JAVAOPTS -struct structfile"
303 fi
304
305 # Setup class path
306
307 if $RECOVERFLAG
308 then
309 if $FASTCHECK
310 then
311 #fast transactions
312 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/FastCheck"
313 else
314 #base bristlecone files
315 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/Bristlecone"
316 fi
317 else
318 if $DSMFLAG
319 then
320 #dsm stuff
321 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaDSM"
322 elif $SINGLETM
323 then
324 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaSTM"
325 elif $THREADFLAG
326 then
327 #threading java stuff
328 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaThread"
329 fi
330 #base java stuff
331 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/Java"
332 fi
333
334 # Build bristlecone/java sources
335
336 if $MULTICOREFLAG
337 then
338 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx800m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
339 $ROBUSTROOT/ClassLibrary/ -classlibrary $ROBUSTROOT/ClassLibrary/gnu/ \
340 -dir $BUILDDIR $JAVAOPTS $SRCFILES
341 then exit $?
342 fi
343 else
344 #if ! ${ROBUSTROOT}/ourjava -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
345 if ! $NOJAVA
346 then
347 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx600m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
348 $ROBUSTROOT/ClassLibrary/ -classlibrary $ROBUSTROOT/ClassLibrary/gnu/ -dir $BUILDDIR -precise \
349 $JAVAOPTS $SRCFILES
350 then exit $?
351 fi
352 fi
353 fi
354
355 if $EXITAFTERANALYSIS
356 then
357 exit
358 fi
359
360 # Build all of the consistency specs
361
362 if $CHECKFLAG # CHECKFLAG
363 then
364 cd $SPECDIR
365 mkdir $BUILDDIR/specdir
366 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
367
368 echo > $BUILDDIR/specs
369
370 # compile specs into C code
371 for i in * # iterate over all directories
372 do
373 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
374 then
375 cd $SPECDIR/$i
376 cat $BUILDDIR/structfile.struct $i.label > $i.struct
377 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
378 cp size.[c,h] $BUILDDIR/specdir
379 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
380 echo $i >> $BUILDDIR/specs
381 fi # CVSDIR CHECK
382 done # iterate over all directories
383
384 #compile C code
385
386 cd $BUILDDIR/specdir
387 ./buildrobust
388 echo > $BUILDDIR/checkers.h
389 for i in `cat $BUILDDIR/specs`
390 do
391 gcc -O0 -g -fbounds-check -c $i\_aux.c
392 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
393 done
394 fi # CHECKFLAG
395
396 #build and link everything
397
398 if $RAWFLAG
399 then # RAWFLAG
400 RAWDIR="$CURDIR/raw"
401 MAKEFILE="../Makefile.raw"
402 mkdir $RAWDIR
403 cd $RAWDIR
404 make clean
405 rm ./*
406
407 export RAWRGCCFLAGS="-DTASK -DMULTICORE -DRAW"
408
409 if $RAWCACHEFLUSHFLAG
410 then # print path
411 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWCACHEFLUSH"
412 fi
413
414 if $RAWPATHFLAG
415 then # print path
416 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPATH"
417 fi
418
419 if $RAWDEBUGFLAG
420 then #debug version
421 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWDEBUG"
422 fi
423
424 if $RAWPROFILEFLAG
425 then # profile version
426 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPROFILE"
427 fi
428
429 if $RAWUSEIOFLAG
430 then # useio version
431 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWUSEIO"
432 fi
433
434 if $INTERRUPTFLAG
435 then #INTERRUPT version
436 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DINTERRUPT"
437 fi #INTERRUPT version
438
439 if $RAWUSEIOFLAG
440 then # useio version
441 MAKEFILE="$MAKEFILE.io"
442 echo "+++++++++++use Makefile.raw.io++++++++++++++++"
443 else
444 MAKEFILE="$MAKEFILE.$RAWCONFIG"
445 fi #useio version
446
447 cp $MAKEFILE ./Makefile
448 cp ../Runtime/*.c ./
449 cp ../Runtime/*.h ./
450 cp ../Runtime/*.S ./
451 cp ../Runtime/*.s ./
452 cp ../tmpbuilddirectory/*.c ./
453 cp ../tmpbuilddirectory/*.h ./
454
455 make
456
457 else #!RAWFLAG
458 cd $CURDIR 
459
460 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
461 -I$BUILDDIR"
462
463 if $MULTICOREFLAG
464 then
465 RUNTIMEFILE="$ROBUSTROOT/Runtime/multicoreruntime.c $ROBUSTROOT/Runtime/multicoretask.c"
466 else
467 RUNTIMEFILE="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c"
468 fi
469
470 FILES="$RUNTIMEFILE \
471 $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
472 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
473 $ROBUSTROOT/Runtime/ObjectHash.c \
474 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
475 $ROBUSTROOT/Runtime/math.c \
476 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
477
478 if $DSMFLAG
479 then
480 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME"
481 FILES="$FILES $DSMRUNTIME/trans.c $DSMRUNTIME/mcpileq.c $DSMRUNTIME/objstr.c $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/threadnotify.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $ROBUSTROOT/Runtime/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c $DSMRUNTIME/signal.c $DSMRUNTIME/gCollect.c $DSMRUNTIME/addPrefetchEnhance.c $DSMRUNTIME/dsmlock.c $DSMRUNTIME/prefetch.c"
482 fi
483
484 if $SINGLETM
485 then
486 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -I$DSMRUNTIME"
487 FILES="$FILES $DSMRUNTIME/dsmlock.c $DSMRUNTIME/singleTMCommit.c $DSMRUNTIME/clookup.c $ROBUSTROOT/Runtime/thread.c"
488 fi
489
490 if $ABORTREADERS
491 then
492 FILES="$FILES $DSMRUNTIME/abortreaders.c"
493 fi
494
495 if $FASTCHECK
496 then
497 FILES="$FILES $ROBUSTROOT/Runtime/localobjects.c"
498 fi
499
500 if $MLP
501 then
502 FILES="$FILES $ROBUSTROOT/Runtime/mlp_runtime.c"
503 fi
504
505 if $RECOVERFLAG
506 then
507 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
508 if $MULTICOREFLAG
509 then
510 EXTRAOPTIONS="$EXTRAOPTIONS -DMULTICORE"
511 fi
512 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/chash.c"
513 if $RAWFLAG
514 then
515 EXTRAOPTIONS="$EXTRAOPTIONS -DRAW"
516 fi
517 if $THREADSIMULATEFLAG
518 then
519 # -lpthread for pthread functions, -lrt for message queue functions
520 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADSIMULATE -lpthread -lrt"
521 fi
522 fi
523
524 if $OPTIONALFLAG
525 then
526 EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
527 FILES="$FILES tmpbuilddirectory/optionalarrays.c"
528 fi
529
530 if $THREADFLAG
531 then
532 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
533 fi
534
535 if $CHECKFLAG
536 then
537 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
538 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
539 fi
540
541 if $USEDMALLOC
542 then
543 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
544 fi
545
546 if $MULTICOREFLAG
547 then
548 gcc $INCLUDES $EXTRAOPTIONS \
549 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
550 else
551 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
552 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
553 fi
554
555 fi #!RAWFLAG
556
557 exit
558