1 #!/bin/sh 2 # 3 # Run the code in test.jar using the host-mode 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="jit" 82 msg "Using jit 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 HOSTBASE="${ANDROID_BUILD_TOP}/out/host" 122 BASE="$OUT" # from build environment 123 DATA_DIR=/tmp 124 DEBUG_OPTS="-Xcheck:jni -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" 125 126 if [ ! -d $DATA_DIR/dalvik-cache ]; then 127 mkdir -p $DATA_DIR/dalvik-cache 128 [[ $? -ne 0 ]] && exit 129 fi 130 131 export ANDROID_PRINTF_LOG=brief 132 if [ "$DEV_MODE" = "y" ]; then 133 export ANDROID_LOG_TAGS='*:d' 134 else 135 export ANDROID_LOG_TAGS='*:s' 136 fi 137 export ANDROID_DATA="$DATA_DIR" 138 export ANDROID_ROOT="${HOSTBASE}/linux-x86" 139 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib" 140 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib" 141 142 exe="${ANDROID_ROOT}/bin/dalvikvm" 143 framework="${BASE}/system/framework" 144 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/ext.jar:${framework}/framework.jar" 145 146 if [ "$DEBUG" = "y" ]; then 147 PORT=8000 148 msg "Waiting for debugger to connect on localhost:$PORT" 149 DEX_DEBUG="-agentlib:jdwp=transport=dt_socket,addres=$PORT,server=y,suspend=y" 150 fi 151 152 if [ "$GDB" = "y" ]; then 153 gdb=gdb 154 gdbargs="--args $exe" 155 fi 156 157 $valgrind_cmd $gdb $exe $gdbargs "-Xbootclasspath:${bpath}" \ 158 $DEX_VERIFY $DEX_OPTIMIZE $DEX_DEBUG $GC_OPTS "-Xint:${INTERP}" -ea \ 159 -cp test.jar Main "$@" 160