• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Run the code in test.jar on a host-local virtual machine. The jar should
4# contain a top-level 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#   --valgrind    -- use valgrind
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"
24GDB="n"
25VERIFY="y"
26OPTIMIZE="y"
27VALGRIND="n"
28DEV_MODE="n"
29QUIET="n"
30PRECISE="y"
31
32while true; do
33    if [ "x$1" = "x--quiet" ]; then
34        QUIET="y"
35        shift
36    elif [ "x$1" = "x--jit" ]; then
37        INTERP="jit"
38        msg "Using jit"
39        shift
40    elif [ "x$1" = "x--fast" ]; then
41        INTERP="fast"
42        msg "Using fast interpreter"
43        shift
44    elif [ "x$1" = "x--portable" ]; then
45        INTERP="portable"
46        msg "Using portable interpreter"
47        shift
48    elif [ "x$1" = "x--debug" ]; then
49        DEBUG="y"
50        shift
51    elif [ "x$1" = "x--gdb" ]; then
52        GDB="y"
53        shift
54    elif [ "x$1" = "x--valgrind" ]; then
55        VALGRIND="y"
56        shift
57    elif [ "x$1" = "x--dev" ]; then
58        DEV_MODE="y"
59        shift
60    elif [ "x$1" = "x--no-verify" ]; then
61        VERIFY="n"
62        shift
63    elif [ "x$1" = "x--no-optimize" ]; then
64        OPTIMIZE="n"
65        shift
66    elif [ "x$1" = "x--no-precise" ]; then
67        PRECISE="n"
68        shift
69    elif [ "x$1" = "x--" ]; then
70        shift
71        break
72    elif expr "x$1" : "x--" >/dev/null 2>&1; then
73        echo "unknown option: $1" 1>&2
74        exit 1
75    else
76        break
77    fi
78done
79
80if [ "x$INTERP" = "x" ]; then
81    INTERP="fast"
82    msg "Using fast interpreter by default"
83fi
84
85if [ "$OPTIMIZE" = "y" ]; then
86    if [ "$VERIFY" = "y" ]; then
87        DEX_OPTIMIZE="-Xdexopt:verified"
88    else
89        DEX_OPTIMIZE="-Xdexopt:all"
90    fi
91    msg "Performing optimizations"
92else
93    DEX_OPTIMIZE="-Xdexopt:none"
94    msg "Skipping optimizations"
95fi
96
97if [ "$VERIFY" = "y" ]; then
98    DEX_VERIFY=""
99    msg "Performing verification"
100else
101    DEX_VERIFY="-Xverify:none"
102    msg "Skipping verification"
103fi
104
105if [ "$VALGRIND" = "y" ]; then
106    msg "Running with valgrind"
107    valgrind_cmd="valgrind"
108    #valgrind_cmd="valgrind --leak-check=full"
109else
110    valgrind_cmd=""
111fi
112
113if [ "$PRECISE" = "y" ]; then
114    GC_OPTS="-Xgc:precise -Xgenregmap"
115else
116    GC_OPTS="-Xgc:noprecise"
117fi
118
119msg "------------------------------"
120
121BASE="$OUT" # from build environment
122DATA_DIR=/tmp
123DEBUG_OPTS="-Xcheck:jni -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
124
125export ANDROID_PRINTF_LOG=brief
126if [ "$DEV_MODE" = "y" ]; then
127    export ANDROID_LOG_TAGS='*:d'
128else
129    export ANDROID_LOG_TAGS='*:s'
130fi
131export ANDROID_DATA="$DATA_DIR"
132export ANDROID_ROOT="${BASE}/system"
133export LD_LIBRARY_PATH="${BASE}/system/lib"
134export DYLD_LIBRARY_PATH="${BASE}/system/lib"
135
136exe="${BASE}/system/bin/dalvikvm"
137framework="${BASE}/system/framework"
138bpath="${framework}/core.jar:${framework}/ext.jar:${framework}/framework.jar"
139
140if [ "$DEBUG" = "y" ]; then
141    PORT=8000
142    msg "Waiting for debugger to connect on localhost:$PORT"
143    DEX_DEBUG="-agentlib:jdwp=transport=dt_socket,addres=$PORT,server=y,suspend=y"
144fi
145
146if [ "$GDB" = "y" ]; then
147    gdb=gdb
148    gdbargs="--args $exe"
149fi
150
151$valgrind_cmd $gdb $exe $gdbargs "-Xbootclasspath:${bpath}" \
152    $DEX_VERIFY $DEX_OPTIMIZE $DEX_DEBUG $GC_OPTS "-Xint:${INTERP}" -ea \
153    -cp test.jar Main "$@"
154