blob: 4d83c87fd519b9c2b76b7d5bb1c02969e395efb5 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/bin/sh
2#
3# Run the code in test.jar using the host-mode virtual machine. The jar should
4# contain a top-level class named Main to run.
jeffhao5d1ac922011-09-29 17:41:15 -07005
6msg() {
7 if [ "$QUIET" = "n" ]; then
8 echo "$@"
9 fi
10}
11
Brian Carlstromfa42b442013-06-17 12:53:45 -070012DEBUGGER="n"
Alex Lighta59dd802014-07-02 16:28:08 -070013PREBUILD="n"
jeffhao5d1ac922011-09-29 17:41:15 -070014GDB="n"
Alex Lighta59dd802014-07-02 16:28:08 -070015ISA="x86"
jeffhao0dff3f42012-11-20 15:13:43 -080016INTERPRETER="n"
jeffhao5d1ac922011-09-29 17:41:15 -070017VERIFY="y"
Alex Lighta59dd802014-07-02 16:28:08 -070018RELOCATE="y"
jeffhao5d1ac922011-09-29 17:41:15 -070019OPTIMIZE="y"
Elliott Hughes7c046102011-10-19 18:16:03 -070020INVOKE_WITH=""
jeffhao5d1ac922011-09-29 17:41:15 -070021DEV_MODE="n"
22QUIET="n"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070023FLAGS=""
Alex Lighta59dd802014-07-02 16:28:08 -070024COMPILER_FLAGS=""
25BUILD_BOOT_OPT=""
Ian Rogersafd9acc2014-06-17 08:21:54 -070026exe="${ANDROID_HOST_OUT}/bin/dalvikvm32"
jeffhao5d1ac922011-09-29 17:41:15 -070027
28while true; do
29 if [ "x$1" = "x--quiet" ]; then
30 QUIET="y"
31 shift
Alex Lighta59dd802014-07-02 16:28:08 -070032 elif [ "x$1" = "x--prebuild" ]; then
33 PREBUILD="y"
34 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070035 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070036 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070037 if [ "x$1" = "x" ]; then
38 echo "$0 missing argument to --lib" 1>&2
39 exit 1
40 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070041 LIB="$1"
Ian Rogers2a65d4b2014-06-16 22:16:21 -070042 if [ `uname` = "Darwin" ]; then
43 LIB=${LIB/%so/dylib}
44 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -070045 shift
46 elif [ "x$1" = "x--boot" ]; then
47 shift
Alex Lighta59dd802014-07-02 16:28:08 -070048 option="$1"
49 BOOT_OPT="$option"
50 BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
Ian Rogers6950e652012-08-28 18:20:00 -070051 shift
jeffhao5d1ac922011-09-29 17:41:15 -070052 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070053 DEBUGGER="y"
jeffhao5d1ac922011-09-29 17:41:15 -070054 shift
55 elif [ "x$1" = "x--gdb" ]; then
56 GDB="y"
Ian Rogers6030ef42013-02-20 14:15:53 -080057 DEV_MODE="y"
jeffhao5d1ac922011-09-29 17:41:15 -070058 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070059 elif [ "x$1" = "x--invoke-with" ]; then
60 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070061 if [ "x$1" = "x" ]; then
62 echo "$0 missing argument to --invoke-with" 1>&2
63 exit 1
64 fi
Ian Rogers0e033672013-04-19 10:22:46 -070065 if [ "x$INVOKE_WITH" = "x" ]; then
66 INVOKE_WITH="$1"
67 else
68 INVOKE_WITH="$INVOKE_WITH $1"
69 fi
jeffhao5d1ac922011-09-29 17:41:15 -070070 shift
71 elif [ "x$1" = "x--dev" ]; then
72 DEV_MODE="y"
73 shift
jeffhao0dff3f42012-11-20 15:13:43 -080074 elif [ "x$1" = "x--interpreter" ]; then
75 INTERPRETER="y"
76 shift
Ian Rogersafd9acc2014-06-17 08:21:54 -070077 elif [ "x$1" = "x--64" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -070078 ISA="x64"
Ian Rogersafd9acc2014-06-17 08:21:54 -070079 exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
80 shift
jeffhao5d1ac922011-09-29 17:41:15 -070081 elif [ "x$1" = "x--no-verify" ]; then
82 VERIFY="n"
83 shift
84 elif [ "x$1" = "x--no-optimize" ]; then
85 OPTIMIZE="n"
86 shift
Alex Lighta59dd802014-07-02 16:28:08 -070087 elif [ "x$1" = "x--no-relocate" ]; then
88 RELOCATE="n"
89 shift
90 elif [ "x$1" = "x--relocate" ]; then
91 RELOCATE="y"
92 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000093 elif [ "x$1" = "x-Xcompiler-option" ]; then
94 shift
95 option="$1"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070096 FLAGS="${FLAGS} -Xcompiler-option $option"
Alex Lighta59dd802014-07-02 16:28:08 -070097 COMPILER_FLAGS="${COMPILER_FLAGS} $option"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070098 shift
99 elif [ "x$1" = "x--runtime-option" ]; then
100 shift
101 option="$1"
102 FLAGS="${FLAGS} $option"
Alex Lighta59dd802014-07-02 16:28:08 -0700103 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg $option"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000104 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700105 elif [ "x$1" = "x--" ]; then
106 shift
107 break
108 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700109 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700110 exit 1
111 else
112 break
113 fi
114done
115
jeffhao5d1ac922011-09-29 17:41:15 -0700116msg "------------------------------"
117
jeffhao5d1ac922011-09-29 17:41:15 -0700118export ANDROID_PRINTF_LOG=brief
119if [ "$DEV_MODE" = "y" ]; then
120 export ANDROID_LOG_TAGS='*:d'
121else
122 export ANDROID_LOG_TAGS='*:s'
123fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700124export ANDROID_DATA="$DEX_LOCATION"
Elliott Hughese7fb2a62012-04-23 12:39:12 -0700125export ANDROID_ROOT="${ANDROID_HOST_OUT}"
jeffhao5d1ac922011-09-29 17:41:15 -0700126export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
127export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
128
Brian Carlstromfa42b442013-06-17 12:53:45 -0700129if [ "$DEBUGGER" = "y" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700130 PORT=8000
Elliott Hughes72395bf2012-04-24 13:45:26 -0700131 msg "Waiting for jdb to connect:"
132 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700133 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700134fi
135
136if [ "$GDB" = "y" ]; then
Ian Rogers2a65d4b2014-06-16 22:16:21 -0700137 if [ `uname` = "Darwin" ]; then
138 gdb=lldb
139 gdbargs="-- $exe"
140 exe=
141 else
142 gdb=gdb
143 gdbargs="--args $exe"
144 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
145 # gdbargs="--annotate=3 $gdbargs"
146 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700147fi
148
jeffhao0dff3f42012-11-20 15:13:43 -0800149if [ "$INTERPRETER" = "y" ]; then
150 INT_OPTS="-Xint"
Alex Lighta59dd802014-07-02 16:28:08 -0700151 COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only"
152fi
153
154if [ "$RELOCATE" = "y" ]; then
155 FLAGS="${FLAGS} -Xrelocate"
156 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information"
157 # Run test sets a fairly draconian ulimit that we will likely blow right over
158 # since we are relocating. Get the total size of the /system/framework directory
159 # in 512 byte blocks and set it as the ulimit. This should be more than enough
160 # room.
161 ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
162else
163 FLAGS="${FLAGS} -Xnorelocate"
164 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
165fi
166
167mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
168if [ "$PREBUILD" = "y" ]; then
169 prebuild_cmd="${ANDROID_HOST_OUT}/bin/dex2oatd $COMPILER_FLAGS --instruction-set=$ISA $BUILD_BOOT_OPT --dex-file=$DEX_LOCATION/$TEST_NAME.jar --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g")"
170else
171 prebuild_cmd="true"
jeffhao0dff3f42012-11-20 15:13:43 -0800172fi
173
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700174JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Alex Lighta59dd802014-07-02 16:28:08 -0700175cmdline="$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB $JNI_OPTS $FLAGS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700176if [ "$DEV_MODE" = "y" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700177 if [ "$PREBUILD" = "y" ]; then
178 echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
179 elif [ "$RELOCATE" = "y" ]; then
180 echo "$mkdir_cmd && $cmdline"
181 else
182 echo $cmdline
183 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700184fi
185
Brian Carlstrom4855cd52012-04-03 21:38:13 -0700186cd $ANDROID_BUILD_TOP
Alex Lighta59dd802014-07-02 16:28:08 -0700187$mkdir_cmd && $prebuild_cmd && $cmdline "$@"