blob: 9c032c0cb4e9e8e0bdf371af1f20847a6f372b73 [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.
Alex Lighta4817fb2018-06-12 10:56:35 -070052 --allow-default-jdwp Don't automatically put in -XjdwpProvider:none.
53 You probably do not want this.
Orion Hodson9763f2e2017-03-28 08:27:23 +010054
55The ART_OPTIONS are passed directly to the Android Runtime.
56
57Example:
58 art --32 -cp my_classes.dex MainClass
59
60Common errors:
61 1) Not having core.art available (see $ANDROID_BUILD_TOP/art/Android.mk).
62 eg m -j32 build-art-host
63 2) Not having boot.art available (see $ANDROID_BUILD_TOP/build/make/core/dex_preopt_libart_boot.mk)
64 eg m -j32 out/target/product/generic_x86_64/dex_bootjars/system/framework/x86_64/boot.art
65EOF
66}
67
68function clean_android_data() {
69 if [ "$DELETE_ANDROID_DATA" = "yes" ]; then
70 rm -rf $ANDROID_DATA
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010071 fi
Orion Hodson9763f2e2017-03-28 08:27:23 +010072}
73
Vladimir Markoafd44ea2017-07-14 13:52:02 +010074# Given 'VAR1=VAL VAR2=VAL2 ... cmd arg1 arg2 ... argN' run the 'cmd' with the args
75# with the modified environment {VAR1=VAL,VAL2=,...}.
76#
77# Also prints the command to be run if verbose mode is enabled.
Orion Hodson9763f2e2017-03-28 08:27:23 +010078function verbose_run() {
79 if [ "$VERBOSE" = "yes" ]; then
80 echo "$@"
81 fi
Vladimir Markoafd44ea2017-07-14 13:52:02 +010082
83 env "$@"
Orion Hodson9763f2e2017-03-28 08:27:23 +010084}
85
Nicolas Geoffray162a5702017-08-04 09:28:32 +000086# Parse a colon-separated list into an array (e.g. "foo.dex:bar.dex" -> (foo.dex bar.dex))
87PARSE_CLASSPATH_RESULT=() # Return value will be here due to shell limitations.
88parse_classpath() {
89 local cp="$1"
90 local oldifs=$IFS
91
92 local cp_array
93 cp_array=()
94
95 IFS=":"
96 for part in $cp; do
97 cp_array+=("$part")
98 done
99 IFS=$oldifs
100
101 PARSE_CLASSPATH_RESULT=("${cp_array[@]}")
102}
103
104# Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files.
105# e.g. (-cp foo/classes.dex:bar/classes.dex) -> (foo/classes.dex bar/classes.dex)
106find_cp_in_args() {
107 local found="false"
108 local index=0
109 local what
110
111 while [[ $# -gt 0 ]]; do
112 case "$1" in
113 -cp|-classpath)
114 parse_classpath "$2"
115 # Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files.
116 # Subsequent parses will overwrite the preceding.
117 shift
118 ;;
119 esac
120 shift
121 done
122}
123
124# Delete the 'oat' directories relative to the classpath's dex files.
125# e.g. (foo/classes.dex bar/classes.dex) would delete (foo/oat bar/oat) directories.
126cleanup_oat_directory() {
127 local classpath
128 classpath=("$@")
129
130 local dirpath
131
132 for path in "${classpath[@]}"; do
133 dirpath="$(dirname "$path")"
134 [[ -d "$dirpath" ]] && verbose_run rm -rf "$dirpath/oat"
135 done
136}
137
138# Parse -cp <CP>, -classpath <CP>, and $CLASSPATH to find the dex files.
139# Each dex file's directory will have an 'oat' file directory, delete it.
140# Input: Command line arguments to the art script.
141# e.g. -cp foo/classes.dex:bar/classes.dex would delete (foo/oat bar/oat) directories.
142cleanup_oat_directory_for_classpath() {
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100143 if [ "$CLEAN_OAT_FILES" = "yes" ]; then
144 # First try: Use $CLASSPATH environment variable.
145 parse_classpath "$CLASSPATH"
146 # Second try: Look for latest -cp or -classpath arg which will take precedence.
147 find_cp_in_args "$@"
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000148
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100149 cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}"
150 fi
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000151}
152
Igor Murashkind54ac262017-07-26 11:16:23 -0700153# Attempt to find $ANDROID_ROOT/framework/<isa>/core.art' without knowing what <isa> is.
154function check_if_boot_image_file_exists() {
155 local image_location_dir="$1"
156 local image_location_name="$2"
157
158 # Expand image_files to a list of existing image files on the disk.
159 # If no such files exist, it expands to single element 'dir/*/file' with a literal '*'.
160 local image_files
161 image_files=("$image_location_dir"/*/"$image_location_name") # avoid treating "*" as literal.
162
163 # Array always has at least 1 element. Test explicitly whether the file exists.
164 [[ -e "${image_files[0]}" ]]
165}
166
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700167# Automatically find the boot image location. It uses core.art by default.
168# On a real device, it might only have a boot.art, so use that instead when core.art does not exist.
169function detect_boot_image_location() {
170 local image_location_dir="$ANDROID_ROOT/framework"
171 local image_location_name="core.art"
172
Igor Murashkind54ac262017-07-26 11:16:23 -0700173 # If there are no existing core.art, try to find boot.art.
174 # If there is no boot.art then leave it as-is, assumes -Ximage is explicitly used.
175 # Otherwise let dalvikvm give the error message about an invalid image file.
176 if ! check_if_boot_image_file_exists "$image_location_dir" "core.art" && \
177 check_if_boot_image_file_exists "$image_location_dir" "boot.art"; then
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700178 image_location_name="boot.art"
179 fi
180
181 local image_location="$image_location_dir/$image_location_name"
182 echo "$image_location"
183}
184
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100185function run_dex2oat() {
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100186 local class_loader_context=
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100187 for dex_file in "${DEX2OAT_CLASSPATH[@]}"
188 do
189 while [ -h "$dex_file" ]; do
190 # On Mac OS, readlink -f doesn't work.
191 dex_file="$(readlink "$dex_file")"
192 done
193 # Create oat file directory.
194 verbose_run mkdir -p $(dirname "$dex_file")/oat/$ISA
195 local oat_file=$(basename "$dex_file")
196 local oat_file=$(dirname "$dex_file")/oat/$ISA/${oat_file%.*}.odex
197 # When running dex2oat use the exact same context as when running dalvikvm.
198 # (see run_art function)
199 verbose_run ANDROID_DATA=$ANDROID_DATA \
200 ANDROID_ROOT=$ANDROID_ROOT \
201 LD_LIBRARY_PATH=$LD_LIBRARY_PATH \
202 PATH=$ANDROID_ROOT/bin:$PATH \
203 LD_USE_LOAD_BIAS=1 \
204 ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS \
205 $DEX2OAT_BINARY_PATH \
206 --runtime-arg -Xnorelocate \
207 --boot-image=$DEX2OAT_BOOT_IMAGE \
208 --instruction-set=$ISA \
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100209 --class-loader-context="PCL[$class_loader_context]" \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100210 "${DEX2OAT_FLAGS[@]}" \
211 --dex-file=$dex_file \
212 --oat-file=$oat_file
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100213 if [[ -n $class_loader_context ]]; then
214 class_loader_context+=":"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100215 fi
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100216 class_loader_context+="$dex_file"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100217 done
218}
219
220# Extract the dex2oat flags from the list of arguments.
221# -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array
222# -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH
223# -Ximage argument is stored in DEX2OAT_BOOT_IMAGE
224function extract_dex2oat_flags() {
225 while [ $# -gt 0 ]; do
226 case $1 in
227 -Xcompiler-option)
228 DEX2OAT_FLAGS+=("$2")
229 shift
230 ;;
231 -Ximage:*)
Nicolas Geoffray686801f2018-08-26 16:00:53 +0100232 DEX2OAT_BOOT_IMAGE=$1
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100233 # Remove '-Ximage:' from the argument.
234 DEX2OAT_BOOT_IMAGE=${DEX2OAT_BOOT_IMAGE##-Ximage:}
235 ;;
236 -cp)
Nicolas Geoffray686801f2018-08-26 16:00:53 +0100237 # Reset any previously parsed classpath, just like dalvikvm
238 # only supports one -cp argument.
239 DEX2OAT_CLASSPATH=()
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100240 # TODO: support -classpath and CLASSPATH
241 local oifs=$IFS
242 IFS=':'
243 for classpath_elem in $2
244 do
245 DEX2OAT_CLASSPATH+=("$classpath_elem")
246 done
247 shift
248 IFS=$oifs
249 ;;
250 esac
251 shift
252 done
253}
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100254
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000255# Runs dalvikvm, returns its exit code.
256# (Oat directories are cleaned up in between runs)
Orion Hodson9763f2e2017-03-28 08:27:23 +0100257function run_art() {
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000258 local ret
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700259
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000260 # Run dalvikvm.
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100261 verbose_run ANDROID_DATA="$ANDROID_DATA" \
262 ANDROID_ROOT="$ANDROID_ROOT" \
263 LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
264 PATH="$ANDROID_ROOT/bin:$PATH" \
265 LD_USE_LOAD_BIAS=1 \
266 ANDROID_LOG_TAGS="$ANDROID_LOG_TAGS" \
267 $LAUNCH_WRAPPER $ART_BINARY_PATH $lib \
268 -XXlib:"$LIBART" \
269 -Xnorelocate \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100270 -Ximage:"$DEFAULT_IMAGE_LOCATION" \
Orion Hodson9763f2e2017-03-28 08:27:23 +0100271 "$@"
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000272 ret=$?
273
274 # Avoid polluting disk with 'oat' files after dalvikvm has finished.
275 cleanup_oat_directory_for_classpath "$@"
276
277 # Forward exit code of dalvikvm.
278 return $ret
Orion Hodson9763f2e2017-03-28 08:27:23 +0100279}
280
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100281######################################
282# Globals
283######################################
284ART_BINARY=dalvikvm
285DEX2OAT_BINARY=dex2oat
286DELETE_ANDROID_DATA="no"
287LAUNCH_WRAPPER=
288LIBART=libart.so
289JIT_PROFILE="no"
290ALLOW_DEFAULT_JDWP="no"
291VERBOSE="no"
292CLEAN_OAT_FILES="yes"
293EXTRA_OPTIONS=()
294DEX2OAT_FLAGS=()
295DEX2OAT_CLASSPATH=()
296
297# Parse arguments
Orion Hodson9763f2e2017-03-28 08:27:23 +0100298while [[ "$1" = "-"* ]]; do
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100299 case "$1" in
Orion Hodson9763f2e2017-03-28 08:27:23 +0100300 --)
301 # No more arguments for this script.
302 shift
303 break
304 ;;
305 --32)
306 ART_BINARY=dalvikvm32
307 ;;
308 --64)
309 ART_BINARY=dalvikvm64
310 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100311 -d)
312 ;& # Fallthrough
313 --debug)
314 LIBART="libartd.so"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100315 DEX2OAT_BINARY=dex2oatd
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700316 # Expect that debug mode wants all checks.
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100317 EXTRA_OPTIONS+=(-XX:SlowDebug=true)
Orion Hodson9763f2e2017-03-28 08:27:23 +0100318 ;;
Alex Light84b92e02017-09-29 13:46:14 -0700319 --gdbserver)
320 LAUNCH_WRAPPER="gdbserver $2"
321 shift
322 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100323 --gdb)
324 LIBART="libartd.so"
325 LAUNCH_WRAPPER="gdb --args"
326 ;;
327 --help)
328 usage
329 exit 0
330 ;;
331 --invoke-with)
332 LAUNCH_WRAPPER=$2
333 shift
334 ;;
335 --perf)
336 PERF="record"
337 ;;
338 --perf-report)
339 PERF="report"
340 ;;
341 --profile)
342 JIT_PROFILE="yes"
343 ;;
344 --verbose)
345 VERBOSE="yes"
346 ;;
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100347 --no-clean)
348 CLEAN_OAT_FILES="no"
349 ;;
Alex Lighta4817fb2018-06-12 10:56:35 -0700350 --allow-default-jdwp)
351 ALLOW_DEFAULT_JDWP="yes"
352 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100353 --*)
354 echo "unknown option: $1" 1>&2
355 usage
356 exit 1
357 ;;
358 *)
359 break
360 ;;
361 esac
362 shift
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +0100363done
364
Orion Hodson9763f2e2017-03-28 08:27:23 +0100365if [ $# -eq 0 ]; then
366 usage
367 exit 1
368fi
369
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100370# Follow all sym links to get the program name.
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100371if [[ -n "$BASH_SOURCE" ]]; then
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100372 PROG_NAME="$BASH_SOURCE"
373else
374 PROG_NAME="$0"
375fi
376while [ -h "$PROG_NAME" ]; do
377 # On Mac OS, readlink -f doesn't work.
378 PROG_NAME="$(readlink "$PROG_NAME")"
379done
380
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700381PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
382ANDROID_ROOT=$PROG_DIR/..
Orion Hodson9763f2e2017-03-28 08:27:23 +0100383ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700384
Orion Hodson9763f2e2017-03-28 08:27:23 +0100385if [ ! -x "$ART_BINARY_PATH" ]; then
386 cat 1>&2 <<EOF
387Android Runtime not found: $ART_BINARY_PATH
388This script should be in the same directory as the Android Runtime ($ART_BINARY).
389EOF
390 exit 1
391fi
392
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100393DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY
394
395if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then
396 echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH"
397fi
398
399######################################
400# Main program
401######################################
402
403# If android logging is not explicitly set, only print warnings and errors.
404if [ -z "$ANDROID_LOG_TAGS" ]; then
405 ANDROID_LOG_TAGS='*:w'
406fi
407
Orion Hodson9763f2e2017-03-28 08:27:23 +0100408LIBDIR="$(find_libdir $ART_BINARY_PATH)"
409LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100410DEFAULT_IMAGE_LOCATION="$(detect_boot_image_location)"
411DEX2OAT_BOOT_IMAGE="$DEFAULT_IMAGE_LOCATION"
Nicolas Geoffray810a1002018-08-28 17:40:49 +0100412ISA=$(LD_LIBRARY_PATH=$LD_LIBRARY_PATH $ART_BINARY_PATH -showversion | (read art version number isa && echo $isa))
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100413
414# Extract the dex2oat flags from the list of arguments.
415# -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array
416# -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH
417# -Ximage argument is stored in DEX2OAT_BOOTIMAGE
418extract_dex2oat_flags "$@"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100419
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000420# If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own,
421# and ensure we delete it at the end.
422if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700423 if [[ $PWD != / ]]; then
424 ANDROID_DATA="$PWD/android-data$$"
425 else
426 # Use /data/local/tmp when running this from adb shell, since it starts out in /
427 # by default.
428 ANDROID_DATA="$ANDROID_DATA/local/tmp/android-data$$"
429 fi
Igor Murashkind54ac262017-07-26 11:16:23 -0700430 mkdir -p "$ANDROID_DATA"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100431 DELETE_ANDROID_DATA="yes"
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000432fi
433
Orion Hodson9763f2e2017-03-28 08:27:23 +0100434if [ "$PERF" != "" ]; then
David Srbecky0dcb17f2018-08-13 12:41:47 +0100435 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 +0100436 DEX2OAT_FLAGS+=(--generate-debug-info)
Nicolas Geoffraye099a612014-12-12 13:52:00 +0000437fi
438
Alex Lighta4817fb2018-06-12 10:56:35 -0700439if [ "$ALLOW_DEFAULT_JDWP" = "no" ]; then
440 EXTRA_OPTIONS+=(-XjdwpProvider:none)
441fi
442
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100443# First cleanup any left-over 'oat' files from the last time dalvikvm was run.
444cleanup_oat_directory_for_classpath "$@"
445
446# Protect additional arguments in quotes to preserve whitespaces (used by
447# run-jdwp-test.sh when running on device), '$' (may be used as part of
448# classpath) and other special characters when evaluated.
449EXTRA_OPTIONS+=("$@")
450
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000451if [ "$JIT_PROFILE" = "yes" ]; then
452 # Create the profile. The runtime expects profiles to be created before
453 # execution.
454 PROFILE_PATH="$ANDROID_DATA/primary.prof"
Igor Murashkind54ac262017-07-26 11:16:23 -0700455 touch "$PROFILE_PATH"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000456
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000457 run_art -Xjitsaveprofilinginfo \
458 -Xps-min-methods-to-save:1 \
459 -Xps-min-classes-to-save:1 \
460 -Xps-min-notification-before-wake:10 \
461 -Xps-profile-path:$PROFILE_PATH \
462 -Xusejit:true \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100463 ${EXTRA_OPTIONS[@]} \
Igor Murashkin11942442017-07-20 11:08:34 -0700464 &> "$ANDROID_DATA/profile_gen.log"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000465 EXIT_STATUS=$?
466
467 if [ $EXIT_STATUS != 0 ]; then
Igor Murashkind54ac262017-07-26 11:16:23 -0700468 echo "Profile run failed: " >&2
469 cat "$ANDROID_DATA/profile_gen.log" >&2
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000470 clean_android_data
471 exit $EXIT_STATUS
472 fi
473
Igor Murashkind54ac262017-07-26 11:16:23 -0700474 # Wipe dalvik-cache so that a subsequent run_art must regenerate it.
475 # Leave $ANDROID_DATA intact since it contains our profile file.
476 rm -rf "$ANDROID_DATA/dalvik-cache"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000477
478 # Append arguments so next invocation of run_art uses the profile.
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100479 DEX2OAT_FLAGS+=(--profile-file="$PROFILE_PATH")
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000480fi
481
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100482if [ -x "$DEX2OAT_BINARY_PATH" ]; then
483 # Run dex2oat before launching ART to generate the oat files for the classpath.
484 run_dex2oat
485fi
486
487# Do not continue if the dex2oat failed.
488EXIT_STATUS=$?
489if [ $EXIT_STATUS != 0 ]; then
490 echo "Failed dex2oat invocation" >&2
491 exit $EXIT_STATUS
492fi
Calin Juravle64f45cb2017-03-16 19:58:26 -0700493
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100494run_art "${EXTRA_OPTIONS[@]}"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100495EXIT_STATUS=$?
Calin Juravleaa980612014-10-20 15:58:57 +0100496
Orion Hodson9763f2e2017-03-28 08:27:23 +0100497if [ "$PERF" != "" ]; then
498 if [ "$PERF" = report ]; then
Calin Juravleaa980612014-10-20 15:58:57 +0100499 perf report -i $ANDROID_DATA/perf.data
500 fi
501 echo "Perf data saved in: $ANDROID_DATA/perf.data"
502else
Orion Hodson9763f2e2017-03-28 08:27:23 +0100503 # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used.
504 clean_android_data
Calin Juravleaa980612014-10-20 15:58:57 +0100505fi
506
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000507exit $EXIT_STATUS