#! /bin/bash

#
# (C) Copyright IBM Corp. 2001
#
# $Id: Run-gather-dna,v 1.17 2004/03/25 16:44:25 dgrove-oss Exp $

# This script will run the system on the SPECjvm98 benchmarks using various 
# compilers to determine their "DNA", i.e., their compilation rate and 
# speedup.
#
# The perl script computeDNA.pl will process the output of this script to 
# produce a summary of the results    
#
# Preconditions
#   1) You must first build the following images
#        FastAdaptiveGenMS (for compilation rates and O2 performance)
#        FastBaseAdaptiveGenMS (for baseline compiler performance)
#        FastOpt0GenMS (for Opt 0 performance)
#        FastOpt1GenMS (for Opt 1 performance)
#     The script BuildImages (in this directory) does this step
#  
#   2) Run this script in the SPECjvm98 directory redirecting the output 
#       to a file
#
#   3) Run computeDNA.pl on this file from step 2
#
#  @author Michael Hind, Oct 30, 2001
#  @author Stephen Fink
#  @modified Peter F Sweeney 8/13/2003 get to run with new command line options

if [[ $# = 0 || $1 = -help || $# < 1 ]]; then
  more <<EOF
   
 This script will run the system on the SPECjvm98 benchmarks using various 
 compilers to determine their "DNA", i.e., their compilation rate and 
 speedup.

 The perl script computeDNA.pl will process the output of this script to 
 produce a summary of the results    

 Preconditions
   1) You must first build the following images
        FastAdaptiveGenMS (for compilation rates and O2 performance)
        FastBaseAdaptiveGenMS (for baseline compiler performance)
        FastOpt0GenMS (for Opt 0 performance)
       FastOpt1GenMS (for Opt 1 performance)
     The script BuildImages (in this directory) does this step
  
   2) Run this script in the SPECjvm98 directory redirecting the output 
       to a file

   3) Run computeDNA.pl on this file from step 2

  Normally it is invoked as:
    $0  builddir

  Where 
    builddir      where to find Jikes RVM images
    
EOF
exit 1
fi

if [[ $RVM_ROOT = "" ]]; then
   echo "$0: please set your RVM_ROOT environment variable (eg. $HOME/jvmShadow)"
   exit 1
fi
if [[ $RVM_SPECJVM98 = "" ]]; then
   echo "$0: RVM_SPECJVM98 environment variable  is not set.  Setting to /homes/meriadoc/jalapeno/contrib/benchmarks/SPECjvm98."
   RVM_SPECJVM98="/homes/meriadoc/jalapeno/contrib/benchmarks/SPECjvm98"
fi

rvm="$RVM_ROOT/rvm/bin/rvm"
# parent of build diectories is command line argument to the script
BUILDDIR=$1

# Generate SPECjvm98 profile data
mkdir -p $RVM_ROOT/support/profileData
PROFILE_FILE=$RVM_ROOT/support/profileData/edgeCounts.SPECjvm98
$RVM_ROOT/rvm/src/tools/computeCompilerDNA/GenerateSPECjvmProfile $PROFILE_FILE $BUILDDIR
PROFILE_ARG="-X:vm:edgeCounterFile=$PROFILE_FILE"
cp="-classpath $RVM_SPECJVM98"

# Define benchmark groups
all='_201_compress _202_jess _209_db _213_javac _222_mpegaudio _227_mtrt _228_jack'

jvmoptions="	        -Xmx400 $PROFILE_ARG"
jvmcompoptions="	-Xmx400 -X:vm:measureCompilation=true"
appcompoptions="	-d3000 -g -m1 -M1 -s100"
appperfoptions="	-d3000 -g -m5 -M5 -s100"

# If you want verbose output of command executions...
set -x

PROCS="1"
OPTLEVELS="O0 O1 O2"

for benchmark in $all
do

# Compilation rates first
  export RVM_BUILD=$BUILDDIR/FastAdaptiveGenMS
  $rvm $jvmcompoptions -X:processors=$PROCS -X:aos:logging_level=0 -X:aos:enable_recompilation=false -X:aos:initial_compiler=base $cp SpecApplication $appcompoptions -a $benchmark

  for optLevel in $OPTLEVELS
  do
    $rvm $jvmcompoptions -X:processors=$PROCS -X:aos:logging_level=0 -X:aos:enable_recompilation=false -X:aos:initial_compiler=opt -X:irc:$optLevel $cp SpecApplication $appcompoptions  -a $benchmark
  done

done

for benchmark in $all
do
# Performance next
   export RVM_BUILD=$BUILDDIR/FastBaseAdaptiveGenMS
    $rvm $jvmoptions -X:processors=$PROCS -X:aos:enable_recompilation=false -X:aos:initial_compiler=base $cp SpecApplication $appperfoptions  -a $benchmark

   export RVM_BUILD=$BUILDDIR/FastOpt0GenMS
   $rvm $jvmoptions -X:processors=$PROCS -X:aos:enable_recompilation=false -X:aos:initial_compiler=opt -X:irc:O0 $cp SpecApplication $appperfoptions  -a $benchmark

   export RVM_BUILD=$BUILDDIR/FastOpt1GenMS
   $rvm $jvmoptions -X:processors=$PROCS -X:aos:enable_recompilation=false -X:aos:initial_compiler=opt -X:irc:O1 $cp SpecApplication $appperfoptions  -a $benchmark

   export RVM_BUILD=$BUILDDIR/FastAdaptiveGenMS
   $rvm $jvmoptions -X:processors=$PROCS -X:aos:enable_recompilation=false -X:aos:initial_compiler=opt -X:irc:O2 $cp SpecApplication $appperfoptions  -a $benchmark

done
