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 msg() { 7 if [ "$QUIET" = "n" ]; then 8 echo "$@" 9 fi 10 } 11 12 DEBUGGER="n" 13 PREBUILD="n" 14 GDB="n" 15 ISA="x86" 16 INTERPRETER="n" 17 VERIFY="y" 18 RELOCATE="y" 19 OPTIMIZE="y" 20 INVOKE_WITH="" 21 DEV_MODE="n" 22 QUIET="n" 23 FLAGS="" 24 COMPILER_FLAGS="" 25 BUILD_BOOT_OPT="" 26 SECONDARY_DEX="" 27 exe="${ANDROID_HOST_OUT}/bin/dalvikvm32" 28 main="Main" 29 DEX_VERIFY="" 30 DEX2OAT_SWAP="n" 31 32 while true; do 33 if [ "x$1" = "x--quiet" ]; then 34 QUIET="y" 35 shift 36 elif [ "x$1" = "x--prebuild" ]; then 37 PREBUILD="y" 38 shift 39 elif [ "x$1" = "x--lib" ]; then 40 shift 41 if [ "x$1" = "x" ]; then 42 echo "$0 missing argument to --lib" 1>&2 43 exit 1 44 fi 45 LIB="$1" 46 if [ `uname` = "Darwin" ]; then 47 LIB=${LIB/%so/dylib} 48 fi 49 shift 50 elif [ "x$1" = "x--boot" ]; then 51 shift 52 option="$1" 53 BOOT_OPT="$option" 54 BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}" 55 shift 56 elif [ "x$1" = "x--debug" ]; then 57 DEBUGGER="y" 58 shift 59 elif [ "x$1" = "x--gdb" ]; then 60 GDB="y" 61 DEV_MODE="y" 62 shift 63 elif [ "x$1" = "x--invoke-with" ]; then 64 shift 65 if [ "x$1" = "x" ]; then 66 echo "$0 missing argument to --invoke-with" 1>&2 67 exit 1 68 fi 69 if [ "x$INVOKE_WITH" = "x" ]; then 70 INVOKE_WITH="$1" 71 else 72 INVOKE_WITH="$INVOKE_WITH $1" 73 fi 74 shift 75 elif [ "x$1" = "x--dev" ]; then 76 DEV_MODE="y" 77 shift 78 elif [ "x$1" = "x--interpreter" ]; then 79 INTERPRETER="y" 80 shift 81 elif [ "x$1" = "x--64" ]; then 82 ISA="x86_64" 83 exe="${ANDROID_HOST_OUT}/bin/dalvikvm64" 84 shift 85 elif [ "x$1" = "x--no-verify" ]; then 86 VERIFY="n" 87 shift 88 elif [ "x$1" = "x--no-optimize" ]; then 89 OPTIMIZE="n" 90 shift 91 elif [ "x$1" = "x--no-relocate" ]; then 92 RELOCATE="n" 93 shift 94 elif [ "x$1" = "x--relocate" ]; then 95 RELOCATE="y" 96 shift 97 elif [ "x$1" = "x--secondary" ]; then 98 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar" 99 shift 100 elif [ "x$1" = "x-Xcompiler-option" ]; then 101 shift 102 option="$1" 103 FLAGS="${FLAGS} -Xcompiler-option $option" 104 COMPILER_FLAGS="${COMPILER_FLAGS} $option" 105 shift 106 elif [ "x$1" = "x--runtime-option" ]; then 107 shift 108 option="$1" 109 FLAGS="${FLAGS} $option" 110 shift 111 elif [ "x$1" = "x--dex2oat-swap" ]; then 112 DEX2OAT_SWAP="y" 113 shift 114 elif [ "x$1" = "x--" ]; then 115 shift 116 break 117 elif expr "x$1" : "x--" >/dev/null 2>&1; then 118 echo "unknown $0 option: $1" 1>&2 119 exit 1 120 else 121 break 122 fi 123 done 124 125 if [ "x$1" = "x" ] ; then 126 main="Main" 127 else 128 main="$1" 129 fi 130 131 msg "------------------------------" 132 133 export ANDROID_PRINTF_LOG=brief 134 if [ "$DEV_MODE" = "y" ]; then 135 export ANDROID_LOG_TAGS='*:d' 136 else 137 export ANDROID_LOG_TAGS='*:s' 138 fi 139 export ANDROID_DATA="$DEX_LOCATION" 140 export ANDROID_ROOT="${ANDROID_HOST_OUT}" 141 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib" 142 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib" 143 144 if [ "$DEX2OAT_SWAP" = "y" ]; then 145 COMPILER_FLAGS="${COMPILER_FLAGS} --swap-file=$ANDROID_DATA/dex2oat.swap" 146 fi 147 148 if [ "$DEBUGGER" = "y" ]; then 149 PORT=8000 150 msg "Waiting for jdb to connect:" 151 msg " jdb -attach localhost:$PORT" 152 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" 153 fi 154 155 if [ "$GDB" = "y" ]; then 156 if [ `uname` = "Darwin" ]; then 157 gdb=lldb 158 gdbargs="-- $exe" 159 exe= 160 else 161 gdb=gdb 162 gdbargs="--args $exe" 163 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line. 164 # gdbargs="--annotate=3 $gdbargs" 165 fi 166 fi 167 168 if [ "$INTERPRETER" = "y" ]; then 169 INT_OPTS="-Xint" 170 if [ "$VERIFY" = "y" ] ; then 171 COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only" 172 else 173 COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=verify-none" 174 DEX_VERIFY="${DEX_VERIFY} -Xverify:none" 175 fi 176 fi 177 178 if [ "$RELOCATE" = "y" ]; then 179 FLAGS="${FLAGS} -Xrelocate" 180 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information" 181 # Run test sets a fairly draconian ulimit that we will likely blow right over 182 # since we are relocating. Get the total size of the /system/framework directory 183 # in 512 byte blocks and set it as the ulimit. This should be more than enough 184 # room. 185 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..." 186 ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1 187 fi 188 else 189 FLAGS="${FLAGS} -Xnorelocate" 190 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information" 191 fi 192 193 mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA" 194 if [ "$PREBUILD" = "y" ]; then 195 prebuild_cmd="${ANDROID_HOST_OUT}/bin/dex2oatd $COMPILER_FLAGS --instruction-set=$ISA $BUILD_BOOT_OPT --dex-file=$DEX_LOCATION/$TEST_NAME.jar --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g")" 196 else 197 prebuild_cmd="true" 198 fi 199 200 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" 201 cmdline="$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB $DEX_VERIFY $JNI_OPTS $FLAGS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $main" 202 if [ "$DEV_MODE" = "y" ]; then 203 if [ "$PREBUILD" = "y" ]; then 204 echo "$mkdir_cmd && $prebuild_cmd && $cmdline" 205 elif [ "$RELOCATE" = "y" ]; then 206 echo "$mkdir_cmd && $cmdline" 207 else 208 echo $cmdline 209 fi 210 fi 211 212 cd $ANDROID_BUILD_TOP 213 $mkdir_cmd && $prebuild_cmd && $cmdline "$@" 214