jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 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 | # |
| 6 | # Options: |
| 7 | # --quiet -- don't chatter |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 8 | # --debug -- wait for debugger to attach |
| 9 | # --zygote -- use the zygote (if so, all other options are ignored) |
| 10 | # --dev -- development mode (print the vm invocation cmdline) |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame^] | 11 | # --interpreter -- enable interpreter only mode (off by default) |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 12 | # --no-verify -- turn off verification (on by default) |
| 13 | # --no-optimize -- turn off optimization (on by default) |
| 14 | # --no-precise -- turn off precise GC (on by default) |
Ian Rogers | 7769f50 | 2012-02-03 18:02:28 -0800 | [diff] [blame] | 15 | # -O -- run non-debug code |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 16 | |
| 17 | msg() { |
| 18 | if [ "$QUIET" = "n" ]; then |
| 19 | echo "$@" |
| 20 | fi |
| 21 | } |
| 22 | |
Ian Rogers | 7769f50 | 2012-02-03 18:02:28 -0800 | [diff] [blame] | 23 | OATEXEC="oatexecd" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 24 | DEBUG="n" |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame^] | 25 | INTERPRETER="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 26 | VERIFY="y" |
| 27 | OPTIMIZE="y" |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 28 | ZYGOTE="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 29 | QUIET="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 30 | DEV_MODE="n" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 31 | INVOKE_WITH="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 32 | |
| 33 | while true; do |
| 34 | if [ "x$1" = "x--quiet" ]; then |
| 35 | QUIET="y" |
| 36 | shift |
Ian Rogers | 7769f50 | 2012-02-03 18:02:28 -0800 | [diff] [blame] | 37 | elif [ "x$1" = "x-O" ]; then |
| 38 | OATEXEC="oatexec" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 39 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 40 | elif [ "x$1" = "x--debug" ]; then |
| 41 | DEBUG="y" |
| 42 | shift |
| 43 | elif [ "x$1" = "x--zygote" ]; then |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 44 | ZYGOTE="--zygote" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 45 | msg "Spawning from zygote" |
| 46 | shift |
| 47 | elif [ "x$1" = "x--dev" ]; then |
| 48 | DEV_MODE="y" |
| 49 | shift |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame^] | 50 | elif [ "x$1" = "x--interpreter" ]; then |
| 51 | INTERPRETER="y" |
| 52 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 53 | elif [ "x$1" = "x--invoke-with" ]; then |
| 54 | shift |
| 55 | INVOKE_WITH="$1" |
| 56 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 57 | elif [ "x$1" = "x--no-verify" ]; then |
| 58 | VERIFY="n" |
| 59 | shift |
| 60 | elif [ "x$1" = "x--no-optimize" ]; then |
| 61 | OPTIMIZE="n" |
| 62 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 63 | elif [ "x$1" = "x--" ]; then |
| 64 | shift |
| 65 | break |
| 66 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 67 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 68 | exit 1 |
| 69 | else |
| 70 | break |
| 71 | fi |
| 72 | done |
| 73 | |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 74 | if [ "$ZYGOTE" = "" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 75 | if [ "$OPTIMIZE" = "y" ]; then |
| 76 | if [ "$VERIFY" = "y" ]; then |
| 77 | DEX_OPTIMIZE="-Xdexopt:verified" |
| 78 | else |
| 79 | DEX_OPTIMIZE="-Xdexopt:all" |
| 80 | fi |
| 81 | msg "Performing optimizations" |
| 82 | else |
| 83 | DEX_OPTIMIZE="-Xdexopt:none" |
| 84 | msg "Skipping optimizations" |
| 85 | fi |
| 86 | |
| 87 | if [ "$VERIFY" = "y" ]; then |
| 88 | DEX_VERIFY="" |
| 89 | msg "Performing verification" |
| 90 | else |
| 91 | DEX_VERIFY="-Xverify:none" |
| 92 | msg "Skipping verification" |
| 93 | fi |
| 94 | fi |
| 95 | |
| 96 | msg "------------------------------" |
| 97 | |
| 98 | if [ "$QUIET" = "n" ]; then |
Brian Carlstrom | 4ec9b1f | 2012-06-17 22:27:43 -0700 | [diff] [blame] | 99 | adb shell rm -r $DEX_LOCATION |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 100 | adb shell mkdir -p $DEX_LOCATION |
| 101 | adb push $TEST_NAME.jar $DEX_LOCATION |
| 102 | adb push $TEST_NAME-ex.jar $DEX_LOCATION |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 103 | else |
Brian Carlstrom | 4ec9b1f | 2012-06-17 22:27:43 -0700 | [diff] [blame] | 104 | adb shell rm -r $DEX_LOCATION >/dev/null 2>&1 |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 105 | adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1 |
| 106 | adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1 |
| 107 | adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 108 | fi |
| 109 | |
| 110 | if [ "$DEBUG" = "y" ]; then |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 111 | # Use this instead for ddms and connect by running 'ddms': |
| 112 | # DEBUG_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y" |
| 113 | # TODO: add a separate --ddms option? |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 114 | |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 115 | PORT=12345 |
| 116 | msg "Waiting for jdb to connect:" |
| 117 | msg " adb forward tcp:$PORT tcp:$PORT" |
| 118 | msg " jdb -attach localhost:$PORT" |
| 119 | DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 120 | fi |
| 121 | |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame^] | 122 | if [ "$INTERPRETER" = "y" ]; then |
| 123 | INT_OPTS="-Xint" |
| 124 | fi |
| 125 | |
Mathieu Chartier | dbe6f46 | 2012-09-25 16:54:50 -0700 | [diff] [blame] | 126 | JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 127 | |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 128 | cmdline="cd $DEX_LOCATION && mkdir art-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \ |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame^] | 129 | $INVOKE_WITH $OATEXEC $ZYGOTE $JNI_OPTS $INT_OPTS $DEBUG_OPTS -Ximage:/data/art-test/core.art -cp $DEX_LOCATION/$TEST_NAME.jar Main" |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 130 | if [ "$DEV_MODE" = "y" ]; then |
| 131 | echo $cmdline "$@" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 132 | fi |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 133 | |
| 134 | adb shell $cmdline "$@" |