1 #!/bin/sh 2 # 3 # Run the code in test.jar on a host-local virtual machine. The jar should 4 # contain a top-level class named Main to run. 5 # 6 # Options: 7 # --quiet -- don't chatter 8 # --fast -- use the fast interpreter (the default) 9 # --jit -- use the jit 10 # --portable -- use the portable interpreter 11 # --debug -- wait for debugger to attach 12 # --valgrind -- use valgrind 13 # --no-verify -- turn off verification (on by default) 14 # --no-optimize -- turn off optimization (on by default) 15 16 msg() { 17 if [ "$QUIET" = "n" ]; then 18 echo "$@" 19 fi 20 } 21 22 INTERP="" 23 DEBUG="n" 24 GDB="n" 25 VERIFY="y" 26 OPTIMIZE="y" 27 VALGRIND="n" 28 DEV_MODE="n" 29 QUIET="n" 30 PRECISE="y" 31 32 while true; do 33 if [ "x$1" = "x--quiet" ]; then 34 QUIET="y" 35 shift 36 elif [ "x$1" = "x--jit" ]; then 37 INTERP="jit" 38 msg "Using jit" 39 shift 40 elif [ "x$1" = "x--fast" ]; then 41 INTERP="fast" 42 msg "Using fast interpreter" 43 shift 44 elif [ "x$1" = "x--portable" ]; then 45 INTERP="portable" 46 msg "Using portable interpreter" 47 shift 48 elif [ "x$1" = "x--debug" ]; then 49 DEBUG="y" 50 shift 51 elif [ "x$1" = "x--gdb" ]; then 52 GDB="y" 53 shift 54 elif [ "x$1" = "x--valgrind" ]; then 55 VALGRIND="y" 56 shift 57 elif [ "x$1" = "x--dev" ]; then 58 DEV_MODE="y" 59 shift 60 elif [ "x$1" = "x--no-verify" ]; then 61 VERIFY="n" 62 shift 63 elif [ "x$1" = "x--no-optimize" ]; then 64 OPTIMIZE="n" 65 shift 66 elif [ "x$1" = "x--no-precise" ]; then 67 PRECISE="n" 68 shift 69 elif [ "x$1" = "x--" ]; then 70 shift 71 break 72 elif expr "x$1" : "x--" >/dev/null 2>&1; then 73 echo "unknown option: $1" 1>&2 74 exit 1 75 else 76 break 77 fi 78 done 79 80 if [ "x$INTERP" = "x" ]; then 81 INTERP="fast" 82 msg "Using fast interpreter by default" 83 fi 84 85 if [ "$OPTIMIZE" = "y" ]; then 86 if [ "$VERIFY" = "y" ]; then 87 DEX_OPTIMIZE="-Xdexopt:verified" 88 else 89 DEX_OPTIMIZE="-Xdexopt:all" 90 fi 91 msg "Performing optimizations" 92 else 93 DEX_OPTIMIZE="-Xdexopt:none" 94 msg "Skipping optimizations" 95 fi 96 97 if [ "$VERIFY" = "y" ]; then 98 DEX_VERIFY="" 99 msg "Performing verification" 100 else 101 DEX_VERIFY="-Xverify:none" 102 msg "Skipping verification" 103 fi 104 105 if [ "$VALGRIND" = "y" ]; then 106 msg "Running with valgrind" 107 valgrind_cmd="valgrind" 108 #valgrind_cmd="valgrind --leak-check=full" 109 else 110 valgrind_cmd="" 111 fi 112 113 if [ "$PRECISE" = "y" ]; then 114 GC_OPTS="-Xgc:precise -Xgenregmap" 115 else 116 GC_OPTS="-Xgc:noprecise" 117 fi 118 119 msg "------------------------------" 120 121 BASE="$OUT" # from build environment 122 DATA_DIR=/tmp 123 DEBUG_OPTS="-Xcheck:jni -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" 124 125 export ANDROID_PRINTF_LOG=brief 126 if [ "$DEV_MODE" = "y" ]; then 127 export ANDROID_LOG_TAGS='*:d' 128 else 129 export ANDROID_LOG_TAGS='*:s' 130 fi 131 export ANDROID_DATA="$DATA_DIR" 132 export ANDROID_ROOT="${BASE}/system" 133 export LD_LIBRARY_PATH="${BASE}/system/lib" 134 export DYLD_LIBRARY_PATH="${BASE}/system/lib" 135 136 exe="${BASE}/system/bin/dalvikvm" 137 framework="${BASE}/system/framework" 138 bpath="${framework}/core.jar:${framework}/ext.jar:${framework}/framework.jar" 139 140 if [ "$DEBUG" = "y" ]; then 141 PORT=8000 142 msg "Waiting for debugger to connect on localhost:$PORT" 143 DEX_DEBUG="-agentlib:jdwp=transport=dt_socket,addres=$PORT,server=y,suspend=y" 144 fi 145 146 if [ "$GDB" = "y" ]; then 147 gdb=gdb 148 gdbargs="--args $exe" 149 fi 150 151 $valgrind_cmd $gdb $exe $gdbargs "-Xbootclasspath:${bpath}" \ 152 $DEX_VERIFY $DEX_OPTIMIZE $DEX_DEBUG $GC_OPTS "-Xint:${INTERP}" -ea \ 153 -cp test.jar Main "$@" 154