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
8#   --fast        -- use the fast interpreter (the default)
9#   --portable    -- use the portable interpreter
10#   --debug       -- wait for debugger to attach
11#   --zygote      -- use the zygote (if so, all other options are ignored)
12#   --dev         -- development mode
13#   --no-verify   -- turn off verification (on by default)
14#   --no-optimize -- turn off optimization (on by default)
15
16msg() {
17    if [ "$QUIET" = "n" ]; then
18        echo "$@"
19    fi
20}
21
22INTERP=""
23DEBUG="n"
24VERIFY="y"
25OPTIMIZE="y"
26ZYGOTE="n"
27QUIET="n"
28
29while true; do
30    if [ "x$1" = "x--quiet" ]; then
31        QUIET="y"
32        shift
33    elif [ "x$1" = "x--fast" ]; then
34        INTERP="fast"
35        msg "Using fast interpreter"
36        shift
37    elif [ "x$1" = "x--portable" ]; then
38        INTERP="portable"
39        msg "Using portable interpreter"
40        shift
41    elif [ "x$1" = "x--debug" ]; then
42        DEBUG="y"
43        shift
44    elif [ "x$1" = "x--zygote" ]; then
45        ZYGOTE="y"
46        msg "Spawning from zygote"
47        shift
48    elif [ "x$1" = "x--dev" ]; then
49        # not used; ignore
50        shift
51    elif [ "x$1" = "x--no-verify" ]; then
52        VERIFY="n"
53        shift
54    elif [ "x$1" = "x--no-optimize" ]; then
55        OPTIMIZE="n"
56        shift
57    elif [ "x$1" = "x--" ]; then
58        shift
59        break
60    elif expr "x$1" : "x--" >/dev/null 2>&1; then
61        echo "unknown option: $1" 1>&2
62        exit 1
63    else
64        break
65    fi
66done
67
68if [ "$ZYGOTE" = "n" ]; then
69    if [ "x$INTERP" = "x" ]; then
70        INTERP="fast"
71        msg "Using fast interpreter by default"
72    fi
73
74    if [ "$OPTIMIZE" = "y" ]; then
75        if [ "$VERIFY" = "y" ]; then
76            DEX_OPTIMIZE="-Xdexopt:verified"
77        else
78            DEX_OPTIMIZE="-Xdexopt:all"
79        fi
80        msg "Performing optimizations"
81    else
82        DEX_OPTIMIZE="-Xdexopt:none"
83        msg "Skipping optimizations"
84    fi
85
86    if [ "$VERIFY" = "y" ]; then
87        DEX_VERIFY=""
88        msg "Performing verification"
89    else
90        DEX_VERIFY="-Xverify:none"
91        msg "Skipping verification"
92    fi
93fi
94
95msg "------------------------------"
96
97if [ "$QUIET" = "n" ]; then
98    adb push test.jar /data
99    adb push test-ex.jar /data
100else
101    adb push test.jar /data >/dev/null 2>&1
102    adb push test-ex.jar /data >/dev/null 2>&1
103fi
104
105if [ "$DEBUG" = "y" ]; then
106    DEX_DEBUG="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
107fi
108
109if [ "$ZYGOTE" = "y" ]; then
110    adb shell cd /data \; dvz -classpath test.jar Main "$@"
111else
112    adb shell cd /data \; dalvikvm $DEX_VERIFY $DEX_OPTIMIZE $DEX_DEBUG \
113        -cp test.jar "-Xint:${INTERP}" -ea Main "$@"
114fi
115