1#!/bin/sh 2# 3# Run the code in test.jar on the device. The jar should contain a top-level 4# class named Main to run. 5 6msg() { 7 if [ "$QUIET" = "n" ]; then 8 echo "$@" 9 fi 10} 11 12LIB="libartd.so" 13GDB="n" 14DEBUGGER="n" 15INTERPRETER="n" 16VERIFY="y" 17OPTIMIZE="y" 18ZYGOTE="" 19QUIET="n" 20DEV_MODE="n" 21INVOKE_WITH="" 22 23while true; do 24 if [ "x$1" = "x--quiet" ]; then 25 QUIET="y" 26 shift 27 elif [ "x$1" = "x-lib" ]; then 28 shift 29 LIB="$1" 30 elif [ "x$1" = "x-O" ]; then 31 LIB="libart.so" 32 shift 33 elif [ "x$1" = "x--debug" ]; then 34 DEBUGGER="y" 35 shift 36 elif [ "x$1" = "x--gdb" ]; then 37 GDB="y" 38 DEV_MODE="y" 39 shift 40 elif [ "x$1" = "x--zygote" ]; then 41 ZYGOTE="--zygote" 42 msg "Spawning from zygote" 43 shift 44 elif [ "x$1" = "x--dev" ]; then 45 DEV_MODE="y" 46 shift 47 elif [ "x$1" = "x--interpreter" ]; then 48 INTERPRETER="y" 49 shift 50 elif [ "x$1" = "x--invoke-with" ]; then 51 shift 52 if [ "x$INVOKE_WITH" = "x" ]; then 53 INVOKE_WITH="$1" 54 else 55 INVOKE_WITH="$INVOKE_WITH $1" 56 fi 57 shift 58 elif [ "x$1" = "x--no-verify" ]; then 59 VERIFY="n" 60 shift 61 elif [ "x$1" = "x--no-optimize" ]; then 62 OPTIMIZE="n" 63 shift 64 elif [ "x$1" = "x--" ]; then 65 shift 66 break 67 elif expr "x$1" : "x--" >/dev/null 2>&1; then 68 echo "unknown $0 option: $1" 1>&2 69 exit 1 70 else 71 break 72 fi 73done 74 75if [ "$ZYGOTE" = "" ]; then 76 if [ "$OPTIMIZE" = "y" ]; then 77 if [ "$VERIFY" = "y" ]; then 78 DEX_OPTIMIZE="-Xdexopt:verified" 79 else 80 DEX_OPTIMIZE="-Xdexopt:all" 81 fi 82 msg "Performing optimizations" 83 else 84 DEX_OPTIMIZE="-Xdexopt:none" 85 msg "Skipping optimizations" 86 fi 87 88 if [ "$VERIFY" = "y" ]; then 89 DEX_VERIFY="" 90 msg "Performing verification" 91 else 92 DEX_VERIFY="-Xverify:none" 93 msg "Skipping verification" 94 fi 95fi 96 97msg "------------------------------" 98 99if [ "$QUIET" = "n" ]; then 100 adb shell rm -r $DEX_LOCATION 101 adb shell mkdir -p $DEX_LOCATION 102 adb push $TEST_NAME.jar $DEX_LOCATION 103 adb push $TEST_NAME-ex.jar $DEX_LOCATION 104else 105 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1 106 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1 107 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1 108 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1 109fi 110 111if [ "$DEBUGGER" = "y" ]; then 112 # Use this instead for ddms and connect by running 'ddms': 113 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y" 114 # TODO: add a separate --ddms option? 115 116 PORT=12345 117 msg "Waiting for jdb to connect:" 118 msg " adb forward tcp:$PORT tcp:$PORT" 119 msg " jdb -attach localhost:$PORT" 120 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" 121fi 122 123if [ "$GDB" = "y" ]; then 124 gdb="gdbserver :5039" 125 gdbargs="--args $exe" 126fi 127 128if [ "$INTERPRETER" = "y" ]; then 129 INT_OPTS="-Xint" 130fi 131 132JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" 133 134cmdline="cd $DEX_LOCATION && mkdir dalvik-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \ 135 $INVOKE_WITH $gdb dalvikvm $gdbargs -XXlib:$LIB $ZYGOTE $JNI_OPTS $INT_OPTS $DEBUGGER_OPTS -Ximage:/data/art-test/core.art -cp $DEX_LOCATION/$TEST_NAME.jar Main" 136if [ "$DEV_MODE" = "y" ]; then 137 echo $cmdline "$@" 138fi 139 140adb shell $cmdline "$@" 141