blob: 574ae353b6a860d12eb0d7f69dc26b3d91652b06 [file] [log] [blame]
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001# Copyright (C) 2011 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Nicolas Geoffray70a998c2014-12-04 17:05:22 +000015# This script is used on host and device. It uses a common subset
16# shell dialect that should work on the host (e.g. bash), and
17# Android (e.g. mksh).
18
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +010019######################################
20# Functions
21######################################
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010022function find_libdir() {
Orion Hodson9763f2e2017-03-28 08:27:23 +010023 # Get the actual file, $1 is the ART_BINARY_PATH and may be a symbolic link.
Nicolas Geoffray70a998c2014-12-04 17:05:22 +000024 # Use realpath instead of readlink because Android does not have a readlink.
Orion Hodson9763f2e2017-03-28 08:27:23 +010025 if [[ "$(realpath "$1")" == *dalvikvm64 ]]; then
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010026 echo "lib64"
27 else
28 echo "lib"
29 fi
30}
31
Orion Hodson9763f2e2017-03-28 08:27:23 +010032function usage() {
33 cat 1>&2 <<EOF
34Usage: art [OPTIONS] [--] [ART_OPTIONS] CLASS
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010035
Orion Hodson9763f2e2017-03-28 08:27:23 +010036Supported OPTIONS include:
37 --32 Use the 32-bit Android Runtime.
38 --64 Use the 64-bit Android Runtime.
Orion Hodson9763f2e2017-03-28 08:27:23 +010039 -d Use the debug ART library (libartd.so).
40 --debug Equivalent to -d.
41 --gdb Launch the Android Runtime in gdb.
Alex Light84b92e02017-09-29 13:46:14 -070042 --gdbserver <comms> Launch the Android Runtime in gdbserver using the
43 supplied communication channel.
Orion Hodson9763f2e2017-03-28 08:27:23 +010044 --help Display usage message.
45 --invoke-with <program> Launch the Android Runtime in <program>.
46 --perf Launch the Android Runtime with perf recording.
47 --perf-report Launch the Android Runtime with perf recording with
48 report upon completion.
49 --profile Run with profiling, then run using profile data.
50 --verbose Run script verbosely.
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +010051 --no-clean Don't cleanup oat directories.
Nicolas Geoffrayf983c732018-09-12 09:27:29 +010052 --no-compile Don't invoke dex2oat before running.
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +010053 --toybox-path <path> Path for toybox executable. Provide this
54 path if your device does not have
55 'env', 'rm', 'dirname', 'basename', or 'mkdir'.
Alex Lighta4817fb2018-06-12 10:56:35 -070056 --allow-default-jdwp Don't automatically put in -XjdwpProvider:none.
57 You probably do not want this.
Orion Hodson9763f2e2017-03-28 08:27:23 +010058
59The ART_OPTIONS are passed directly to the Android Runtime.
60
61Example:
62 art --32 -cp my_classes.dex MainClass
63
64Common errors:
65 1) Not having core.art available (see $ANDROID_BUILD_TOP/art/Android.mk).
66 eg m -j32 build-art-host
67 2) Not having boot.art available (see $ANDROID_BUILD_TOP/build/make/core/dex_preopt_libart_boot.mk)
68 eg m -j32 out/target/product/generic_x86_64/dex_bootjars/system/framework/x86_64/boot.art
69EOF
70}
71
72function clean_android_data() {
73 if [ "$DELETE_ANDROID_DATA" = "yes" ]; then
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +010074 $TOYBOX rm -rf $ANDROID_DATA
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010075 fi
Orion Hodson9763f2e2017-03-28 08:27:23 +010076}
77
Vladimir Markoafd44ea2017-07-14 13:52:02 +010078# Given 'VAR1=VAL VAR2=VAL2 ... cmd arg1 arg2 ... argN' run the 'cmd' with the args
79# with the modified environment {VAR1=VAL,VAL2=,...}.
80#
81# Also prints the command to be run if verbose mode is enabled.
Orion Hodson9763f2e2017-03-28 08:27:23 +010082function verbose_run() {
83 if [ "$VERBOSE" = "yes" ]; then
84 echo "$@"
85 fi
Vladimir Markoafd44ea2017-07-14 13:52:02 +010086
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +010087 $TOYBOX env "$@"
Orion Hodson9763f2e2017-03-28 08:27:23 +010088}
89
Nicolas Geoffray162a5702017-08-04 09:28:32 +000090# Parse a colon-separated list into an array (e.g. "foo.dex:bar.dex" -> (foo.dex bar.dex))
91PARSE_CLASSPATH_RESULT=() # Return value will be here due to shell limitations.
92parse_classpath() {
93 local cp="$1"
94 local oldifs=$IFS
95
96 local cp_array
97 cp_array=()
98
99 IFS=":"
100 for part in $cp; do
101 cp_array+=("$part")
102 done
103 IFS=$oldifs
104
105 PARSE_CLASSPATH_RESULT=("${cp_array[@]}")
106}
107
108# Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files.
109# e.g. (-cp foo/classes.dex:bar/classes.dex) -> (foo/classes.dex bar/classes.dex)
110find_cp_in_args() {
111 local found="false"
112 local index=0
113 local what
114
115 while [[ $# -gt 0 ]]; do
116 case "$1" in
117 -cp|-classpath)
118 parse_classpath "$2"
119 # Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files.
120 # Subsequent parses will overwrite the preceding.
121 shift
122 ;;
123 esac
124 shift
125 done
126}
127
128# Delete the 'oat' directories relative to the classpath's dex files.
129# e.g. (foo/classes.dex bar/classes.dex) would delete (foo/oat bar/oat) directories.
130cleanup_oat_directory() {
131 local classpath
132 classpath=("$@")
133
134 local dirpath
135
136 for path in "${classpath[@]}"; do
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +0100137 dirpath="$($TOYBOX dirname "$path")"
138 [[ -d "$dirpath" ]] && verbose_run $TOYBOX rm -rf "$dirpath/oat"
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000139 done
140}
141
142# Parse -cp <CP>, -classpath <CP>, and $CLASSPATH to find the dex files.
143# Each dex file's directory will have an 'oat' file directory, delete it.
144# Input: Command line arguments to the art script.
145# e.g. -cp foo/classes.dex:bar/classes.dex would delete (foo/oat bar/oat) directories.
146cleanup_oat_directory_for_classpath() {
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100147 if [ "$CLEAN_OAT_FILES" = "yes" ]; then
148 # First try: Use $CLASSPATH environment variable.
149 parse_classpath "$CLASSPATH"
150 # Second try: Look for latest -cp or -classpath arg which will take precedence.
151 find_cp_in_args "$@"
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000152
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100153 cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}"
154 fi
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000155}
156
Igor Murashkind54ac262017-07-26 11:16:23 -0700157# Attempt to find $ANDROID_ROOT/framework/<isa>/core.art' without knowing what <isa> is.
158function check_if_boot_image_file_exists() {
159 local image_location_dir="$1"
160 local image_location_name="$2"
161
162 # Expand image_files to a list of existing image files on the disk.
163 # If no such files exist, it expands to single element 'dir/*/file' with a literal '*'.
164 local image_files
165 image_files=("$image_location_dir"/*/"$image_location_name") # avoid treating "*" as literal.
166
167 # Array always has at least 1 element. Test explicitly whether the file exists.
168 [[ -e "${image_files[0]}" ]]
169}
170
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700171# Automatically find the boot image location. It uses core.art by default.
172# On a real device, it might only have a boot.art, so use that instead when core.art does not exist.
173function detect_boot_image_location() {
174 local image_location_dir="$ANDROID_ROOT/framework"
175 local image_location_name="core.art"
176
Igor Murashkind54ac262017-07-26 11:16:23 -0700177 # If there are no existing core.art, try to find boot.art.
178 # If there is no boot.art then leave it as-is, assumes -Ximage is explicitly used.
179 # Otherwise let dalvikvm give the error message about an invalid image file.
180 if ! check_if_boot_image_file_exists "$image_location_dir" "core.art" && \
181 check_if_boot_image_file_exists "$image_location_dir" "boot.art"; then
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700182 image_location_name="boot.art"
183 fi
184
185 local image_location="$image_location_dir/$image_location_name"
186 echo "$image_location"
187}
188
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100189function run_dex2oat() {
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100190 local class_loader_context=
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100191 for dex_file in "${DEX2OAT_CLASSPATH[@]}"
192 do
193 while [ -h "$dex_file" ]; do
194 # On Mac OS, readlink -f doesn't work.
195 dex_file="$(readlink "$dex_file")"
196 done
197 # Create oat file directory.
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +0100198 verbose_run $TOYBOX mkdir -p $($TOYBOX dirname "$dex_file")/oat/$ISA
199 local oat_file=$($TOYBOX basename "$dex_file")
200 local oat_file=$($TOYBOX dirname "$dex_file")/oat/$ISA/${oat_file%.*}.odex
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100201 # When running dex2oat use the exact same context as when running dalvikvm.
202 # (see run_art function)
203 verbose_run ANDROID_DATA=$ANDROID_DATA \
204 ANDROID_ROOT=$ANDROID_ROOT \
205 LD_LIBRARY_PATH=$LD_LIBRARY_PATH \
206 PATH=$ANDROID_ROOT/bin:$PATH \
207 LD_USE_LOAD_BIAS=1 \
208 ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS \
209 $DEX2OAT_BINARY_PATH \
210 --runtime-arg -Xnorelocate \
211 --boot-image=$DEX2OAT_BOOT_IMAGE \
212 --instruction-set=$ISA \
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100213 --class-loader-context="PCL[$class_loader_context]" \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100214 "${DEX2OAT_FLAGS[@]}" \
215 --dex-file=$dex_file \
216 --oat-file=$oat_file
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100217 if [[ -n $class_loader_context ]]; then
218 class_loader_context+=":"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100219 fi
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100220 class_loader_context+="$dex_file"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100221 done
222}
223
224# Extract the dex2oat flags from the list of arguments.
225# -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array
226# -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH
227# -Ximage argument is stored in DEX2OAT_BOOT_IMAGE
228function extract_dex2oat_flags() {
229 while [ $# -gt 0 ]; do
230 case $1 in
231 -Xcompiler-option)
232 DEX2OAT_FLAGS+=("$2")
233 shift
234 ;;
235 -Ximage:*)
Nicolas Geoffray686801f2018-08-26 16:00:53 +0100236 DEX2OAT_BOOT_IMAGE=$1
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100237 # Remove '-Ximage:' from the argument.
238 DEX2OAT_BOOT_IMAGE=${DEX2OAT_BOOT_IMAGE##-Ximage:}
239 ;;
240 -cp)
Nicolas Geoffray686801f2018-08-26 16:00:53 +0100241 # Reset any previously parsed classpath, just like dalvikvm
242 # only supports one -cp argument.
243 DEX2OAT_CLASSPATH=()
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100244 # TODO: support -classpath and CLASSPATH
245 local oifs=$IFS
246 IFS=':'
247 for classpath_elem in $2
248 do
249 DEX2OAT_CLASSPATH+=("$classpath_elem")
250 done
251 shift
252 IFS=$oifs
253 ;;
254 esac
255 shift
256 done
257}
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100258
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000259# Runs dalvikvm, returns its exit code.
260# (Oat directories are cleaned up in between runs)
Orion Hodson9763f2e2017-03-28 08:27:23 +0100261function run_art() {
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000262 local ret
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700263
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000264 # Run dalvikvm.
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100265 verbose_run ANDROID_DATA="$ANDROID_DATA" \
266 ANDROID_ROOT="$ANDROID_ROOT" \
267 LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
268 PATH="$ANDROID_ROOT/bin:$PATH" \
269 LD_USE_LOAD_BIAS=1 \
270 ANDROID_LOG_TAGS="$ANDROID_LOG_TAGS" \
271 $LAUNCH_WRAPPER $ART_BINARY_PATH $lib \
272 -XXlib:"$LIBART" \
273 -Xnorelocate \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100274 -Ximage:"$DEFAULT_IMAGE_LOCATION" \
Orion Hodson9763f2e2017-03-28 08:27:23 +0100275 "$@"
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000276 ret=$?
277
278 # Avoid polluting disk with 'oat' files after dalvikvm has finished.
279 cleanup_oat_directory_for_classpath "$@"
280
281 # Forward exit code of dalvikvm.
282 return $ret
Orion Hodson9763f2e2017-03-28 08:27:23 +0100283}
284
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100285######################################
286# Globals
287######################################
288ART_BINARY=dalvikvm
289DEX2OAT_BINARY=dex2oat
290DELETE_ANDROID_DATA="no"
291LAUNCH_WRAPPER=
292LIBART=libart.so
293JIT_PROFILE="no"
294ALLOW_DEFAULT_JDWP="no"
295VERBOSE="no"
296CLEAN_OAT_FILES="yes"
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100297RUN_DEX2OAT="yes"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100298EXTRA_OPTIONS=()
299DEX2OAT_FLAGS=()
300DEX2OAT_CLASSPATH=()
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +0100301TOYBOX=
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100302
303# Parse arguments
Orion Hodson9763f2e2017-03-28 08:27:23 +0100304while [[ "$1" = "-"* ]]; do
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100305 case "$1" in
Orion Hodson9763f2e2017-03-28 08:27:23 +0100306 --)
307 # No more arguments for this script.
308 shift
309 break
310 ;;
311 --32)
312 ART_BINARY=dalvikvm32
313 ;;
314 --64)
315 ART_BINARY=dalvikvm64
316 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100317 -d)
318 ;& # Fallthrough
319 --debug)
320 LIBART="libartd.so"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100321 DEX2OAT_BINARY=dex2oatd
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700322 # Expect that debug mode wants all checks.
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100323 EXTRA_OPTIONS+=(-XX:SlowDebug=true)
Orion Hodson9763f2e2017-03-28 08:27:23 +0100324 ;;
Alex Light84b92e02017-09-29 13:46:14 -0700325 --gdbserver)
326 LAUNCH_WRAPPER="gdbserver $2"
327 shift
328 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100329 --gdb)
330 LIBART="libartd.so"
331 LAUNCH_WRAPPER="gdb --args"
332 ;;
333 --help)
334 usage
335 exit 0
336 ;;
337 --invoke-with)
338 LAUNCH_WRAPPER=$2
339 shift
340 ;;
341 --perf)
342 PERF="record"
343 ;;
344 --perf-report)
345 PERF="report"
346 ;;
347 --profile)
348 JIT_PROFILE="yes"
349 ;;
350 --verbose)
351 VERBOSE="yes"
352 ;;
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100353 --no-clean)
354 CLEAN_OAT_FILES="no"
355 ;;
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100356 --no-compile)
357 CLEAN_OAT_FILES="no"
358 RUN_DEX2OAT="no"
359 ;;
Alex Lighta4817fb2018-06-12 10:56:35 -0700360 --allow-default-jdwp)
361 ALLOW_DEFAULT_JDWP="yes"
362 ;;
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +0100363 --toybox-path)
364 TOYBOX=$2
365 shift
366 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100367 --*)
368 echo "unknown option: $1" 1>&2
369 usage
370 exit 1
371 ;;
372 *)
373 break
374 ;;
375 esac
376 shift
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +0100377done
378
Orion Hodson9763f2e2017-03-28 08:27:23 +0100379if [ $# -eq 0 ]; then
380 usage
381 exit 1
382fi
383
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100384# Follow all sym links to get the program name.
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100385if [[ -n "$BASH_SOURCE" ]]; then
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100386 PROG_NAME="$BASH_SOURCE"
387else
388 PROG_NAME="$0"
389fi
390while [ -h "$PROG_NAME" ]; do
391 # On Mac OS, readlink -f doesn't work.
392 PROG_NAME="$(readlink "$PROG_NAME")"
393done
394
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700395PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
396ANDROID_ROOT=$PROG_DIR/..
Orion Hodson9763f2e2017-03-28 08:27:23 +0100397ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700398
Orion Hodson9763f2e2017-03-28 08:27:23 +0100399if [ ! -x "$ART_BINARY_PATH" ]; then
400 cat 1>&2 <<EOF
401Android Runtime not found: $ART_BINARY_PATH
402This script should be in the same directory as the Android Runtime ($ART_BINARY).
403EOF
404 exit 1
405fi
406
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100407DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY
408
409if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then
410 echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH"
411fi
412
413######################################
414# Main program
415######################################
416
417# If android logging is not explicitly set, only print warnings and errors.
418if [ -z "$ANDROID_LOG_TAGS" ]; then
419 ANDROID_LOG_TAGS='*:w'
420fi
421
Orion Hodson9763f2e2017-03-28 08:27:23 +0100422LIBDIR="$(find_libdir $ART_BINARY_PATH)"
423LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100424DEFAULT_IMAGE_LOCATION="$(detect_boot_image_location)"
425DEX2OAT_BOOT_IMAGE="$DEFAULT_IMAGE_LOCATION"
Nicolas Geoffray810a1002018-08-28 17:40:49 +0100426ISA=$(LD_LIBRARY_PATH=$LD_LIBRARY_PATH $ART_BINARY_PATH -showversion | (read art version number isa && echo $isa))
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100427
428# Extract the dex2oat flags from the list of arguments.
429# -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array
430# -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH
431# -Ximage argument is stored in DEX2OAT_BOOTIMAGE
432extract_dex2oat_flags "$@"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100433
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000434# If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own,
435# and ensure we delete it at the end.
436if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700437 if [[ $PWD != / ]]; then
438 ANDROID_DATA="$PWD/android-data$$"
439 else
440 # Use /data/local/tmp when running this from adb shell, since it starts out in /
441 # by default.
442 ANDROID_DATA="$ANDROID_DATA/local/tmp/android-data$$"
443 fi
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +0100444 $TOYBOX mkdir -p "$ANDROID_DATA"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100445 DELETE_ANDROID_DATA="yes"
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000446fi
447
Orion Hodson9763f2e2017-03-28 08:27:23 +0100448if [ "$PERF" != "" ]; then
David Srbecky0dcb17f2018-08-13 12:41:47 +0100449 LAUNCH_WRAPPER="perf record -g --call-graph dwarf -F 10000 -o $ANDROID_DATA/perf.data -e cycles:u $LAUNCH_WRAPPER"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100450 DEX2OAT_FLAGS+=(--generate-debug-info)
Nicolas Geoffraye099a612014-12-12 13:52:00 +0000451fi
452
Alex Lighta4817fb2018-06-12 10:56:35 -0700453if [ "$ALLOW_DEFAULT_JDWP" = "no" ]; then
454 EXTRA_OPTIONS+=(-XjdwpProvider:none)
455fi
456
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100457# First cleanup any left-over 'oat' files from the last time dalvikvm was run.
458cleanup_oat_directory_for_classpath "$@"
459
460# Protect additional arguments in quotes to preserve whitespaces (used by
461# run-jdwp-test.sh when running on device), '$' (may be used as part of
462# classpath) and other special characters when evaluated.
463EXTRA_OPTIONS+=("$@")
464
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000465if [ "$JIT_PROFILE" = "yes" ]; then
466 # Create the profile. The runtime expects profiles to be created before
467 # execution.
468 PROFILE_PATH="$ANDROID_DATA/primary.prof"
Igor Murashkind54ac262017-07-26 11:16:23 -0700469 touch "$PROFILE_PATH"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000470
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000471 run_art -Xjitsaveprofilinginfo \
472 -Xps-min-methods-to-save:1 \
473 -Xps-min-classes-to-save:1 \
474 -Xps-min-notification-before-wake:10 \
475 -Xps-profile-path:$PROFILE_PATH \
476 -Xusejit:true \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100477 ${EXTRA_OPTIONS[@]} \
Igor Murashkin11942442017-07-20 11:08:34 -0700478 &> "$ANDROID_DATA/profile_gen.log"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000479 EXIT_STATUS=$?
480
481 if [ $EXIT_STATUS != 0 ]; then
Igor Murashkind54ac262017-07-26 11:16:23 -0700482 echo "Profile run failed: " >&2
483 cat "$ANDROID_DATA/profile_gen.log" >&2
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000484 clean_android_data
485 exit $EXIT_STATUS
486 fi
487
Igor Murashkind54ac262017-07-26 11:16:23 -0700488 # Wipe dalvik-cache so that a subsequent run_art must regenerate it.
489 # Leave $ANDROID_DATA intact since it contains our profile file.
Nicolas Geoffray4b1c75d2018-09-14 13:41:57 +0100490 $TOYBOX rm -rf "$ANDROID_DATA/dalvik-cache"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000491
492 # Append arguments so next invocation of run_art uses the profile.
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100493 DEX2OAT_FLAGS+=(--profile-file="$PROFILE_PATH")
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000494fi
495
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100496if [ -x "$DEX2OAT_BINARY_PATH" ]; then
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100497 if [ "$RUN_DEX2OAT" = "yes" ]; then
498 # Run dex2oat before launching ART to generate the oat files for the classpath.
499 run_dex2oat
500 fi
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100501fi
502
503# Do not continue if the dex2oat failed.
504EXIT_STATUS=$?
505if [ $EXIT_STATUS != 0 ]; then
506 echo "Failed dex2oat invocation" >&2
507 exit $EXIT_STATUS
508fi
Calin Juravle64f45cb2017-03-16 19:58:26 -0700509
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100510run_art "${EXTRA_OPTIONS[@]}"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100511EXIT_STATUS=$?
Calin Juravleaa980612014-10-20 15:58:57 +0100512
Orion Hodson9763f2e2017-03-28 08:27:23 +0100513if [ "$PERF" != "" ]; then
514 if [ "$PERF" = report ]; then
Calin Juravleaa980612014-10-20 15:58:57 +0100515 perf report -i $ANDROID_DATA/perf.data
516 fi
517 echo "Perf data saved in: $ANDROID_DATA/perf.data"
518else
Orion Hodson9763f2e2017-03-28 08:27:23 +0100519 # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used.
520 clean_android_data
Calin Juravleaa980612014-10-20 15:58:57 +0100521fi
522
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000523exit $EXIT_STATUS