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