3 # Run the code in test.jar on the device. The jar should contain a top-level
4 # class named Main to run.
7 if [ "$QUIET" = "n" ]; then
12 ARCHITECTURES_32="(arm|x86|mips|none)"
13 ARCHITECTURES_64="(arm64|x86_64|none)"
14 ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
31 if [ "x$1" = "x--quiet" ]; then
34 elif [ "x$1" = "x--lib" ]; then
36 if [ "x$1" = "x" ]; then
37 echo "$0 missing argument to --lib" 1>&2
42 elif [ "x$1" = "x-Xcompiler-option" ]; then
45 FLAGS="${FLAGS} -Xcompiler-option $option"
46 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
48 elif [ "x$1" = "x--runtime-option" ]; then
51 FLAGS="${FLAGS} $option"
53 elif [ "x$1" = "x--boot" ]; then
56 BUILD_BOOT_OPT="--boot-image=${1#-Ximage:}"
58 elif [ "x$1" = "x--relocate" ]; then
61 elif [ "x$1" = "x--no-relocate" ]; then
64 elif [ "x$1" = "x--debug" ]; then
67 elif [ "x$1" = "x--gdb" ]; then
71 elif [ "x$1" = "x--zygote" ]; then
73 msg "Spawning from zygote"
75 elif [ "x$1" = "x--dev" ]; then
78 elif [ "x$1" = "x--interpreter" ]; then
81 elif [ "x$1" = "x--invoke-with" ]; then
83 if [ "x$1" = "x" ]; then
84 echo "$0 missing argument to --invoke-with" 1>&2
87 if [ "x$INVOKE_WITH" = "x" ]; then
90 INVOKE_WITH="$INVOKE_WITH $1"
93 elif [ "x$1" = "x--no-verify" ]; then
96 elif [ "x$1" = "x--no-optimize" ]; then
99 elif [ "x$1" = "x--" ]; then
102 elif [ "x$1" = "x--64" ]; then
104 GDB_TARGET_SUFFIX="64"
105 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
107 elif expr "x$1" : "x--" >/dev/null 2>&1; then
108 echo "unknown $0 option: $1" 1>&2
115 if [ "$ZYGOTE" = "" ]; then
116 if [ "$OPTIMIZE" = "y" ]; then
117 if [ "$VERIFY" = "y" ]; then
118 DEX_OPTIMIZE="-Xdexopt:verified"
120 DEX_OPTIMIZE="-Xdexopt:all"
122 msg "Performing optimizations"
124 DEX_OPTIMIZE="-Xdexopt:none"
125 msg "Skipping optimizations"
128 if [ "$VERIFY" = "y" ]; then
130 msg "Performing verification"
132 DEX_VERIFY="-Xverify:none"
133 msg "Skipping verification"
137 msg "------------------------------"
139 ARCH=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
140 if [ x"$ARCH" = "x" ]; then
141 echo "Unable to determine architecture"
145 if [ "$QUIET" = "n" ]; then
146 adb shell rm -r $DEX_LOCATION
147 adb shell mkdir -p $DEX_LOCATION
148 adb push $TEST_NAME.jar $DEX_LOCATION
149 adb push $TEST_NAME-ex.jar $DEX_LOCATION
151 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
152 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
153 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
154 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
157 if [ "$DEBUGGER" = "y" ]; then
158 # Use this instead for ddms and connect by running 'ddms':
159 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
160 # TODO: add a separate --ddms option?
163 msg "Waiting for jdb to connect:"
164 msg " adb forward tcp:$PORT tcp:$PORT"
165 msg " jdb -attach localhost:$PORT"
166 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
169 if [ "$GDB" = "y" ]; then
170 gdb="gdbserver$GDB_TARGET_SUFFIX :5039"
174 if [ "$INTERPRETER" = "y" ]; then
176 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
179 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
181 if [ "$RELOCATE" = "y" ]; then
182 RELOCATE_OPT="-Xrelocate"
183 BUILD_RELOCATE_OPT="--runtime-arg -Xnorelocate"
184 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information"
185 FLAGS="${FLAGS} -Xcompiler-option --include-patch-information"
187 RELOCATE_OPT="-Xnorelocate"
188 BUILD_RELOCATE_OPT="--runtime-arg -Xnorelocate"
191 # This is due to the fact this cmdline can get longer than the longest allowed
192 # adb command and there is no way to get the exit status from a adb shell
194 cmdline="cd $DEX_LOCATION && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
195 mkdir -p $DEX_LOCATION/dalvik-cache/$ARCH/ && \
196 $INVOKE_WITH /system/bin/dex2oatd $COMPILE_FLAGS $BUILD_BOOT_OPT $BUILD_RELOCATE_OPT --runtime-arg -classpath --runtime-arg $DEX_LOCATION/$TEST_NAME.jar --dex-file=$DEX_LOCATION/$TEST_NAME.jar --oat-file=$DEX_LOCATION/dalvik-cache/$ARCH/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") --instruction-set=$ARCH && \
197 $INVOKE_WITH $gdb /system/bin/dalvikvm$TARGET_SUFFIX $FLAGS $gdbargs -XXlib:$LIB $ZYGOTE $JNI_OPTS $RELOCATE_OPT $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main $@"
198 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
199 echo "$cmdline" > $cmdfile
201 if [ "$DEV_MODE" = "y" ]; then
205 if [ "$QUIET" = "n" ]; then
206 adb push $cmdfile $DEX_LOCATION/cmdline.sh
208 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
211 adb shell sh $DEX_LOCATION/cmdline.sh