Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 1 | # 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 Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 15 | # 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 Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 19 | ###################################### |
| 20 | # Functions |
| 21 | ###################################### |
Nicolas Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 22 | function find_libdir() { |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 23 | # Get the actual file, $1 is the ART_BINARY_PATH and may be a symbolic link. |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 24 | # Use realpath instead of readlink because Android does not have a readlink. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 25 | if [[ "$(realpath "$1")" == *dalvikvm64 ]]; then |
Nicolas Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 26 | echo "lib64" |
| 27 | else |
| 28 | echo "lib" |
| 29 | fi |
| 30 | } |
| 31 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 32 | function usage() { |
| 33 | cat 1>&2 <<EOF |
| 34 | Usage: art [OPTIONS] [--] [ART_OPTIONS] CLASS |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 35 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 36 | Supported OPTIONS include: |
| 37 | --32 Use the 32-bit Android Runtime. |
| 38 | --64 Use the 64-bit Android Runtime. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 39 | -d Use the debug ART library (libartd.so). |
| 40 | --debug Equivalent to -d. |
| 41 | --gdb Launch the Android Runtime in gdb. |
Alex Light | 84b92e0 | 2017-09-29 13:46:14 -0700 | [diff] [blame] | 42 | --gdbserver <comms> Launch the Android Runtime in gdbserver using the |
| 43 | supplied communication channel. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 44 | --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 Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 51 | --no-clean Don't cleanup oat directories. |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 52 | --no-compile Don't invoke dex2oat before running. |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 53 | --allow-default-jdwp Don't automatically put in -XjdwpProvider:none. |
| 54 | You probably do not want this. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 55 | |
| 56 | The ART_OPTIONS are passed directly to the Android Runtime. |
| 57 | |
| 58 | Example: |
| 59 | art --32 -cp my_classes.dex MainClass |
| 60 | |
| 61 | Common errors: |
| 62 | 1) Not having core.art available (see $ANDROID_BUILD_TOP/art/Android.mk). |
| 63 | eg m -j32 build-art-host |
| 64 | 2) Not having boot.art available (see $ANDROID_BUILD_TOP/build/make/core/dex_preopt_libart_boot.mk) |
| 65 | eg m -j32 out/target/product/generic_x86_64/dex_bootjars/system/framework/x86_64/boot.art |
| 66 | EOF |
| 67 | } |
| 68 | |
| 69 | function clean_android_data() { |
| 70 | if [ "$DELETE_ANDROID_DATA" = "yes" ]; then |
Nicolas Geoffray | b487c57 | 2018-09-17 12:17:09 +0000 | [diff] [blame] | 71 | rm -rf $ANDROID_DATA |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 72 | fi |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 75 | # Given 'VAR1=VAL VAR2=VAL2 ... cmd arg1 arg2 ... argN' run the 'cmd' with the args |
| 76 | # with the modified environment {VAR1=VAL,VAL2=,...}. |
| 77 | # |
| 78 | # Also prints the command to be run if verbose mode is enabled. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 79 | function verbose_run() { |
| 80 | if [ "$VERBOSE" = "yes" ]; then |
| 81 | echo "$@" |
| 82 | fi |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 83 | |
Nicolas Geoffray | b487c57 | 2018-09-17 12:17:09 +0000 | [diff] [blame] | 84 | env "$@" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 87 | # Parse a colon-separated list into an array (e.g. "foo.dex:bar.dex" -> (foo.dex bar.dex)) |
| 88 | PARSE_CLASSPATH_RESULT=() # Return value will be here due to shell limitations. |
| 89 | parse_classpath() { |
| 90 | local cp="$1" |
| 91 | local oldifs=$IFS |
| 92 | |
| 93 | local cp_array |
| 94 | cp_array=() |
| 95 | |
| 96 | IFS=":" |
| 97 | for part in $cp; do |
| 98 | cp_array+=("$part") |
| 99 | done |
| 100 | IFS=$oldifs |
| 101 | |
| 102 | PARSE_CLASSPATH_RESULT=("${cp_array[@]}") |
| 103 | } |
| 104 | |
| 105 | # Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files. |
| 106 | # e.g. (-cp foo/classes.dex:bar/classes.dex) -> (foo/classes.dex bar/classes.dex) |
| 107 | find_cp_in_args() { |
| 108 | local found="false" |
| 109 | local index=0 |
| 110 | local what |
| 111 | |
| 112 | while [[ $# -gt 0 ]]; do |
| 113 | case "$1" in |
| 114 | -cp|-classpath) |
| 115 | parse_classpath "$2" |
| 116 | # Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files. |
| 117 | # Subsequent parses will overwrite the preceding. |
| 118 | shift |
| 119 | ;; |
| 120 | esac |
| 121 | shift |
| 122 | done |
| 123 | } |
| 124 | |
| 125 | # Delete the 'oat' directories relative to the classpath's dex files. |
| 126 | # e.g. (foo/classes.dex bar/classes.dex) would delete (foo/oat bar/oat) directories. |
| 127 | cleanup_oat_directory() { |
| 128 | local classpath |
| 129 | classpath=("$@") |
| 130 | |
| 131 | local dirpath |
| 132 | |
| 133 | for path in "${classpath[@]}"; do |
Nicolas Geoffray | b487c57 | 2018-09-17 12:17:09 +0000 | [diff] [blame] | 134 | dirpath="$(dirname "$path")" |
| 135 | [[ -d "$dirpath" ]] && verbose_run rm -rf "$dirpath/oat" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 136 | done |
| 137 | } |
| 138 | |
| 139 | # Parse -cp <CP>, -classpath <CP>, and $CLASSPATH to find the dex files. |
| 140 | # Each dex file's directory will have an 'oat' file directory, delete it. |
| 141 | # Input: Command line arguments to the art script. |
| 142 | # e.g. -cp foo/classes.dex:bar/classes.dex would delete (foo/oat bar/oat) directories. |
| 143 | cleanup_oat_directory_for_classpath() { |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 144 | if [ "$CLEAN_OAT_FILES" = "yes" ]; then |
| 145 | # First try: Use $CLASSPATH environment variable. |
| 146 | parse_classpath "$CLASSPATH" |
| 147 | # Second try: Look for latest -cp or -classpath arg which will take precedence. |
| 148 | find_cp_in_args "$@" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 149 | |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 150 | cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}" |
| 151 | fi |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 154 | # Attempt to find $ANDROID_ROOT/framework/<isa>/core.art' without knowing what <isa> is. |
| 155 | function check_if_boot_image_file_exists() { |
| 156 | local image_location_dir="$1" |
| 157 | local image_location_name="$2" |
| 158 | |
| 159 | # Expand image_files to a list of existing image files on the disk. |
| 160 | # If no such files exist, it expands to single element 'dir/*/file' with a literal '*'. |
| 161 | local image_files |
| 162 | image_files=("$image_location_dir"/*/"$image_location_name") # avoid treating "*" as literal. |
| 163 | |
| 164 | # Array always has at least 1 element. Test explicitly whether the file exists. |
| 165 | [[ -e "${image_files[0]}" ]] |
| 166 | } |
| 167 | |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 168 | # Automatically find the boot image location. It uses core.art by default. |
| 169 | # On a real device, it might only have a boot.art, so use that instead when core.art does not exist. |
| 170 | function detect_boot_image_location() { |
| 171 | local image_location_dir="$ANDROID_ROOT/framework" |
| 172 | local image_location_name="core.art" |
| 173 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 174 | # If there are no existing core.art, try to find boot.art. |
| 175 | # If there is no boot.art then leave it as-is, assumes -Ximage is explicitly used. |
| 176 | # Otherwise let dalvikvm give the error message about an invalid image file. |
| 177 | if ! check_if_boot_image_file_exists "$image_location_dir" "core.art" && \ |
| 178 | check_if_boot_image_file_exists "$image_location_dir" "boot.art"; then |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 179 | image_location_name="boot.art" |
| 180 | fi |
| 181 | |
| 182 | local image_location="$image_location_dir/$image_location_name" |
| 183 | echo "$image_location" |
| 184 | } |
| 185 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 186 | function run_dex2oat() { |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 187 | local class_loader_context= |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 188 | for dex_file in "${DEX2OAT_CLASSPATH[@]}" |
| 189 | do |
| 190 | while [ -h "$dex_file" ]; do |
| 191 | # On Mac OS, readlink -f doesn't work. |
| 192 | dex_file="$(readlink "$dex_file")" |
| 193 | done |
| 194 | # Create oat file directory. |
Nicolas Geoffray | b487c57 | 2018-09-17 12:17:09 +0000 | [diff] [blame] | 195 | verbose_run mkdir -p $(dirname "$dex_file")/oat/$ISA |
| 196 | local oat_file=$(basename "$dex_file") |
| 197 | local oat_file=$(dirname "$dex_file")/oat/$ISA/${oat_file%.*}.odex |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 198 | # When running dex2oat use the exact same context as when running dalvikvm. |
| 199 | # (see run_art function) |
| 200 | verbose_run ANDROID_DATA=$ANDROID_DATA \ |
| 201 | ANDROID_ROOT=$ANDROID_ROOT \ |
Victor Chang | 6461124 | 2019-07-05 16:32:41 +0100 | [diff] [blame] | 202 | ANDROID_I18N_ROOT=$ANDROID_I18N_ROOT \ |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 203 | ANDROID_ART_ROOT=$ANDROID_ART_ROOT \ |
Neil Fuller | 26a5dd6 | 2019-03-13 15:16:35 +0000 | [diff] [blame] | 204 | ANDROID_TZDATA_ROOT=$ANDROID_TZDATA_ROOT \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 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 Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 213 | --class-loader-context="PCL[$class_loader_context]" \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 214 | "${DEX2OAT_FLAGS[@]}" \ |
| 215 | --dex-file=$dex_file \ |
| 216 | --oat-file=$oat_file |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 217 | if [[ -n $class_loader_context ]]; then |
| 218 | class_loader_context+=":" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 219 | fi |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 220 | class_loader_context+="$dex_file" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 221 | 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 |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 228 | # -Xbootclasspath argument is stored in DEX2OAT_BCP |
| 229 | # -Xbootclasspath-locations argument is stored in DEX2OAT_BCP_LOCS |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 230 | function extract_dex2oat_flags() { |
| 231 | while [ $# -gt 0 ]; do |
| 232 | case $1 in |
| 233 | -Xcompiler-option) |
| 234 | DEX2OAT_FLAGS+=("$2") |
| 235 | shift |
| 236 | ;; |
| 237 | -Ximage:*) |
Nicolas Geoffray | 686801f | 2018-08-26 16:00:53 +0100 | [diff] [blame] | 238 | DEX2OAT_BOOT_IMAGE=$1 |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 239 | # Remove '-Ximage:' from the argument. |
| 240 | DEX2OAT_BOOT_IMAGE=${DEX2OAT_BOOT_IMAGE##-Ximage:} |
| 241 | ;; |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 242 | -Xbootclasspath:*) |
| 243 | DEX2OAT_BCP=$1 |
| 244 | # Remove '-Xbootclasspath:' from the argument. |
| 245 | DEX2OAT_BCP=${DEX2OAT_BCP##-Xbootclasspath:} |
| 246 | ;; |
| 247 | -Xbootclasspath-locations:*) |
| 248 | DEX2OAT_BCP_LOCS=$1 |
| 249 | # Remove '-Xbootclasspath-locations:' from the argument. |
| 250 | DEX2OAT_BCP_LOCS=${DEX2OAT_BCP_LOCS##-Xbootclasspath-locations:} |
| 251 | ;; |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 252 | -cp) |
Nicolas Geoffray | 686801f | 2018-08-26 16:00:53 +0100 | [diff] [blame] | 253 | # Reset any previously parsed classpath, just like dalvikvm |
| 254 | # only supports one -cp argument. |
| 255 | DEX2OAT_CLASSPATH=() |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 256 | # TODO: support -classpath and CLASSPATH |
| 257 | local oifs=$IFS |
| 258 | IFS=':' |
| 259 | for classpath_elem in $2 |
| 260 | do |
| 261 | DEX2OAT_CLASSPATH+=("$classpath_elem") |
| 262 | done |
| 263 | shift |
| 264 | IFS=$oifs |
| 265 | ;; |
| 266 | esac |
| 267 | shift |
| 268 | done |
| 269 | } |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 270 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 271 | # Runs dalvikvm, returns its exit code. |
| 272 | # (Oat directories are cleaned up in between runs) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 273 | function run_art() { |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 274 | local ret |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 275 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 276 | # Run dalvikvm. |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 277 | verbose_run ANDROID_DATA="$ANDROID_DATA" \ |
| 278 | ANDROID_ROOT="$ANDROID_ROOT" \ |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 279 | ANDROID_I18N_ROOT="$ANDROID_I18N_ROOT" \ |
| 280 | ANDROID_ART_ROOT="$ANDROID_ART_ROOT" \ |
Neil Fuller | 26a5dd6 | 2019-03-13 15:16:35 +0000 | [diff] [blame] | 281 | ANDROID_TZDATA_ROOT="$ANDROID_TZDATA_ROOT" \ |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 282 | LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \ |
| 283 | PATH="$ANDROID_ROOT/bin:$PATH" \ |
| 284 | LD_USE_LOAD_BIAS=1 \ |
| 285 | ANDROID_LOG_TAGS="$ANDROID_LOG_TAGS" \ |
| 286 | $LAUNCH_WRAPPER $ART_BINARY_PATH $lib \ |
| 287 | -XXlib:"$LIBART" \ |
| 288 | -Xnorelocate \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 289 | -Ximage:"$DEFAULT_IMAGE_LOCATION" \ |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 290 | "$@" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 291 | ret=$? |
| 292 | |
| 293 | # Avoid polluting disk with 'oat' files after dalvikvm has finished. |
| 294 | cleanup_oat_directory_for_classpath "$@" |
| 295 | |
| 296 | # Forward exit code of dalvikvm. |
| 297 | return $ret |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 300 | ###################################### |
| 301 | # Globals |
| 302 | ###################################### |
| 303 | ART_BINARY=dalvikvm |
| 304 | DEX2OAT_BINARY=dex2oat |
Nicolas Geoffray | 745e45d | 2020-04-21 14:09:58 +0100 | [diff] [blame] | 305 | DEX2OAT_SUFFIX="" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 306 | DELETE_ANDROID_DATA="no" |
| 307 | LAUNCH_WRAPPER= |
| 308 | LIBART=libart.so |
| 309 | JIT_PROFILE="no" |
| 310 | ALLOW_DEFAULT_JDWP="no" |
| 311 | VERBOSE="no" |
| 312 | CLEAN_OAT_FILES="yes" |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 313 | RUN_DEX2OAT="yes" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 314 | EXTRA_OPTIONS=() |
| 315 | DEX2OAT_FLAGS=() |
| 316 | DEX2OAT_CLASSPATH=() |
| 317 | |
| 318 | # Parse arguments |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 319 | while [[ "$1" = "-"* ]]; do |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 320 | case "$1" in |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 321 | --) |
| 322 | # No more arguments for this script. |
| 323 | shift |
| 324 | break |
| 325 | ;; |
| 326 | --32) |
| 327 | ART_BINARY=dalvikvm32 |
Nicolas Geoffray | b0c6cb5 | 2020-04-20 15:12:42 +0100 | [diff] [blame] | 328 | DEX2OAT_SUFFIX=32 |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 329 | ;; |
| 330 | --64) |
| 331 | ART_BINARY=dalvikvm64 |
Nicolas Geoffray | b0c6cb5 | 2020-04-20 15:12:42 +0100 | [diff] [blame] | 332 | DEX2OAT_SUFFIX=64 |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 333 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 334 | -d) |
| 335 | ;& # Fallthrough |
| 336 | --debug) |
| 337 | LIBART="libartd.so" |
Nicolas Geoffray | b0c6cb5 | 2020-04-20 15:12:42 +0100 | [diff] [blame] | 338 | DEX2OAT_BINARY="dex2oatd" |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 339 | # Expect that debug mode wants all checks. |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 340 | EXTRA_OPTIONS+=(-XX:SlowDebug=true) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 341 | ;; |
Alex Light | 84b92e0 | 2017-09-29 13:46:14 -0700 | [diff] [blame] | 342 | --gdbserver) |
| 343 | LAUNCH_WRAPPER="gdbserver $2" |
| 344 | shift |
| 345 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 346 | --gdb) |
| 347 | LIBART="libartd.so" |
| 348 | LAUNCH_WRAPPER="gdb --args" |
| 349 | ;; |
| 350 | --help) |
| 351 | usage |
| 352 | exit 0 |
| 353 | ;; |
| 354 | --invoke-with) |
| 355 | LAUNCH_WRAPPER=$2 |
| 356 | shift |
| 357 | ;; |
| 358 | --perf) |
| 359 | PERF="record" |
| 360 | ;; |
| 361 | --perf-report) |
| 362 | PERF="report" |
| 363 | ;; |
| 364 | --profile) |
| 365 | JIT_PROFILE="yes" |
| 366 | ;; |
| 367 | --verbose) |
| 368 | VERBOSE="yes" |
| 369 | ;; |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 370 | --no-clean) |
| 371 | CLEAN_OAT_FILES="no" |
| 372 | ;; |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 373 | --no-compile) |
| 374 | CLEAN_OAT_FILES="no" |
| 375 | RUN_DEX2OAT="no" |
| 376 | ;; |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 377 | --allow-default-jdwp) |
| 378 | ALLOW_DEFAULT_JDWP="yes" |
| 379 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 380 | --*) |
| 381 | echo "unknown option: $1" 1>&2 |
| 382 | usage |
| 383 | exit 1 |
| 384 | ;; |
| 385 | *) |
| 386 | break |
| 387 | ;; |
| 388 | esac |
| 389 | shift |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 390 | done |
| 391 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 392 | if [ $# -eq 0 ]; then |
| 393 | usage |
| 394 | exit 1 |
| 395 | fi |
| 396 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 397 | # Follow all sym links to get the program name. |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 398 | if [[ -n "$BASH_SOURCE" ]]; then |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 399 | PROG_NAME="$BASH_SOURCE" |
| 400 | else |
| 401 | PROG_NAME="$0" |
| 402 | fi |
| 403 | while [ -h "$PROG_NAME" ]; do |
| 404 | # On Mac OS, readlink -f doesn't work. |
| 405 | PROG_NAME="$(readlink "$PROG_NAME")" |
| 406 | done |
| 407 | |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 408 | PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 409 | ANDROID_ROOT="$(cd $PROG_DIR/..; pwd -P)" |
Roland Levillain | 4280752 | 2019-01-15 12:49:36 +0000 | [diff] [blame] | 410 | |
Victor Chang | 6461124 | 2019-07-05 16:32:41 +0100 | [diff] [blame] | 411 | # If ANDROID_I18N_ROOT is not set, try to detect whether we are running on |
| 412 | # target or host and set that environment variable to the usual default value. |
| 413 | if [ -z "$ANDROID_I18N_ROOT" ]; then |
| 414 | # This script is used on host and target (device). However, the (expected) |
| 415 | # default value `ANDROID_I18N_ROOT` is not the same on host and target: |
| 416 | # - on host, `ANDROID_I18N_ROOT` is expected to be |
| 417 | # "$ANDROID_ROOT/com.android.i18n"; |
| 418 | # - on target, `ANDROID_I18N_ROOT` is expected to be |
| 419 | # "/apex/com.android.i18n". |
| 420 | # |
| 421 | # We use the presence/absence of the `$ANDROID_ROOT/../apex` directory to |
| 422 | # determine whether we are on target or host (this is brittle, but simple). |
| 423 | if [ -d "$ANDROID_ROOT/../apex" ]; then |
| 424 | # Target case. |
| 425 | ANDROID_I18N_ROOT="/apex/com.android.i18n" |
| 426 | else |
| 427 | # Host case. |
| 428 | ANDROID_I18N_ROOT="$ANDROID_ROOT/com.android.i18n" |
| 429 | fi |
| 430 | fi |
| 431 | |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 432 | # If ANDROID_ART_ROOT is not set, try to detect whether we are running on |
Roland Levillain | 4280752 | 2019-01-15 12:49:36 +0000 | [diff] [blame] | 433 | # target or host and set that environment variable to the usual default value. |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 434 | if [ -z "$ANDROID_ART_ROOT" ]; then |
Roland Levillain | 4280752 | 2019-01-15 12:49:36 +0000 | [diff] [blame] | 435 | # This script is used on host and target (device). However, the (expected) |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 436 | # default value `ANDROID_ART_ROOT` is not the same on host and target: |
| 437 | # - on host, `ANDROID_ART_ROOT` is expected to be |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 438 | # "$ANDROID_ROOT/com.android.art"; |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 439 | # - on target, `ANDROID_ART_ROOT` is expected to be |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 440 | # "/apex/com.android.art". |
Roland Levillain | 0163134 | 2019-01-10 18:07:24 +0000 | [diff] [blame] | 441 | # |
Roland Levillain | 4280752 | 2019-01-15 12:49:36 +0000 | [diff] [blame] | 442 | # We use the presence/absence of the `$ANDROID_ROOT/../apex` directory to |
| 443 | # determine whether we are on target or host (this is brittle, but simple). |
| 444 | if [ -d "$ANDROID_ROOT/../apex" ]; then |
| 445 | # Target case. |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 446 | ANDROID_ART_ROOT="/apex/com.android.art" |
Roland Levillain | 4280752 | 2019-01-15 12:49:36 +0000 | [diff] [blame] | 447 | else |
| 448 | # Host case. |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 449 | ANDROID_ART_ROOT="$ANDROID_ROOT/com.android.art" |
Roland Levillain | 4280752 | 2019-01-15 12:49:36 +0000 | [diff] [blame] | 450 | fi |
Roland Levillain | 0163134 | 2019-01-10 18:07:24 +0000 | [diff] [blame] | 451 | fi |
| 452 | |
Neil Fuller | 90ffe12 | 2019-06-06 17:25:48 +0100 | [diff] [blame] | 453 | # If ANDROID_TZDATA_ROOT is not set, try to detect whether we are running on |
| 454 | # target or host and set that environment variable to the usual default value. |
Neil Fuller | 26a5dd6 | 2019-03-13 15:16:35 +0000 | [diff] [blame] | 455 | if [ -z "$ANDROID_TZDATA_ROOT" ]; then |
Neil Fuller | 90ffe12 | 2019-06-06 17:25:48 +0100 | [diff] [blame] | 456 | # This script is used on host and target (device). However, the (expected) |
| 457 | # default value `ANDROID_TZDATA_ROOT` is not the same on host and target: |
| 458 | # - on host, `ANDROID_TZDATA_ROOT` is expected to be |
| 459 | # "$ANDROID_ROOT/com.android.tzdata"; |
| 460 | # - on target, `ANDROID_TZDATA_ROOT` is expected to be |
Roland Levillain | 2cd9437 | 2019-07-05 13:26:54 +0100 | [diff] [blame] | 461 | # "/apex/com.android.tzdata". |
Neil Fuller | 90ffe12 | 2019-06-06 17:25:48 +0100 | [diff] [blame] | 462 | # |
| 463 | # We use the presence/absence of the `$ANDROID_ROOT/../apex` directory to |
| 464 | # determine whether we are on target or host (this is brittle, but simple). |
| 465 | if [ -d "$ANDROID_ROOT/../apex" ]; then |
| 466 | # Target case. |
Roland Levillain | 2cd9437 | 2019-07-05 13:26:54 +0100 | [diff] [blame] | 467 | ANDROID_TZDATA_ROOT="/apex/com.android.tzdata" |
Neil Fuller | 90ffe12 | 2019-06-06 17:25:48 +0100 | [diff] [blame] | 468 | else |
| 469 | # Host case. |
| 470 | ANDROID_TZDATA_ROOT="$ANDROID_ROOT/com.android.tzdata" |
| 471 | fi |
Neil Fuller | 26a5dd6 | 2019-03-13 15:16:35 +0000 | [diff] [blame] | 472 | fi |
| 473 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 474 | ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 475 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 476 | if [ ! -x "$ART_BINARY_PATH" ]; then |
| 477 | cat 1>&2 <<EOF |
| 478 | Android Runtime not found: $ART_BINARY_PATH |
| 479 | This script should be in the same directory as the Android Runtime ($ART_BINARY). |
| 480 | EOF |
| 481 | exit 1 |
| 482 | fi |
| 483 | |
Nicolas Geoffray | b0c6cb5 | 2020-04-20 15:12:42 +0100 | [diff] [blame] | 484 | DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY$DEX2OAT_SUFFIX |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 485 | |
| 486 | if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then |
| 487 | echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH" |
| 488 | fi |
| 489 | |
| 490 | ###################################### |
| 491 | # Main program |
| 492 | ###################################### |
| 493 | |
| 494 | # If android logging is not explicitly set, only print warnings and errors. |
| 495 | if [ -z "$ANDROID_LOG_TAGS" ]; then |
| 496 | ANDROID_LOG_TAGS='*:w' |
| 497 | fi |
| 498 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 499 | LIBDIR="$(find_libdir $ART_BINARY_PATH)" |
| 500 | LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 501 | DEFAULT_IMAGE_LOCATION="$(detect_boot_image_location)" |
| 502 | DEX2OAT_BOOT_IMAGE="$DEFAULT_IMAGE_LOCATION" |
Nicolas Geoffray | 810a100 | 2018-08-28 17:40:49 +0100 | [diff] [blame] | 503 | ISA=$(LD_LIBRARY_PATH=$LD_LIBRARY_PATH $ART_BINARY_PATH -showversion | (read art version number isa && echo $isa)) |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 504 | |
| 505 | # Extract the dex2oat flags from the list of arguments. |
| 506 | # -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array |
| 507 | # -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH |
Nicolas Geoffray | 70cbbe9 | 2019-01-14 09:08:16 +0000 | [diff] [blame] | 508 | # -Ximage argument is stored in DEX2OAT_BOOT_IMAGE |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 509 | extract_dex2oat_flags "$@" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 510 | |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 511 | # If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own, |
| 512 | # and ensure we delete it at the end. |
| 513 | if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 514 | if [[ $PWD != / ]]; then |
| 515 | ANDROID_DATA="$PWD/android-data$$" |
| 516 | else |
| 517 | # Use /data/local/tmp when running this from adb shell, since it starts out in / |
| 518 | # by default. |
| 519 | ANDROID_DATA="$ANDROID_DATA/local/tmp/android-data$$" |
| 520 | fi |
Nicolas Geoffray | b487c57 | 2018-09-17 12:17:09 +0000 | [diff] [blame] | 521 | mkdir -p "$ANDROID_DATA" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 522 | DELETE_ANDROID_DATA="yes" |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 523 | fi |
| 524 | |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 525 | if [[ "$DEX2OAT_BCP" = "" && "$DEX2OAT_BCP_LOCS" != "" ]]; then |
| 526 | echo "Cannot use -Xbootclasspath-locations without -Xbootclasspath" |
| 527 | exit 1 |
| 528 | fi |
| 529 | |
Nicolas Geoffray | d41f64c | 2019-01-11 15:46:41 +0000 | [diff] [blame] | 530 | if [[ "$DEX2OAT_BOOT_IMAGE" = *core*.art && "$DEX2OAT_BCP" = "" ]]; then |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 531 | # Note: This must start with the CORE_IMG_JARS in Android.common_path.mk |
| 532 | # because that's what we use for compiling the core.art image. |
| 533 | # It may contain additional modules from TEST_CORE_JARS. |
David Srbecky | 5055e66 | 2020-04-22 11:49:06 +0100 | [diff] [blame^] | 534 | core_jars_list="core-oj core-libart core-icu4j okhttp bouncycastle apache-xml" |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 535 | core_jars_suffix= |
| 536 | if [[ -e $ANDROID_ROOT/framework/core-oj-hostdex.jar ]]; then |
| 537 | core_jars_suffix=-hostdex |
David Srbecky | 5055e66 | 2020-04-22 11:49:06 +0100 | [diff] [blame^] | 538 | core_filenames_dir=$ANDROID_ROOT/framework |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 539 | core_locations_dir=$ANDROID_ROOT/framework |
| 540 | prefix=$PWD/ |
| 541 | if [[ ${core_locations_dir:0:${#prefix}} = $prefix ]]; then |
| 542 | core_locations_dir="${core_locations_dir##$prefix}" |
| 543 | fi |
David Srbecky | 5055e66 | 2020-04-22 11:49:06 +0100 | [diff] [blame^] | 544 | elif [[ -e $ANDROID_ROOT/apex/com.android.art.debug/javalib/core-oj.jar ]]; then |
| 545 | core_jars_suffix= |
| 546 | core_filenames_dir=$ANDROID_ROOT/apex/com.android.art.debug/javalib |
| 547 | core_locations_dir=/apex/com.android.art/javalib |
| 548 | else |
| 549 | echo "Can not find jar files for boot image $DEX2OAT_BOOT_IMAGE" |
| 550 | exit 1 |
| 551 | fi |
| 552 | if [[ $core_locations_dir != "" ]]; then |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 553 | boot_separator="" |
| 554 | for boot_module in ${core_jars_list}; do |
| 555 | DEX_FILENAME="$boot_module$core_jars_suffix.jar" |
David Srbecky | 5055e66 | 2020-04-22 11:49:06 +0100 | [diff] [blame^] | 556 | DEX2OAT_BCP+="$boot_separator$core_filenames_dir/${DEX_FILENAME}" |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame] | 557 | DEX2OAT_BCP_LOCS+="$boot_separator$core_locations_dir/${DEX_FILENAME}" |
| 558 | boot_separator=":" |
| 559 | done |
| 560 | if [ "$VERBOSE" = "yes" ]; then |
| 561 | echo "Using predefined -Xbootclasspath for image $DEX2OAT_BOOT_IMAGE:" |
| 562 | echo DEX2OAT_BOOT_IMAGE=$DEX2OAT_BOOT_IMAGE |
| 563 | echo DEX2OAT_BCP=$DEX2OAT_BCP |
| 564 | echo DEX2OAT_BCP_LOCS=$DEX2OAT_BCP_LOCS |
| 565 | fi |
| 566 | fi |
| 567 | fi |
| 568 | |
| 569 | if [ "$DEX2OAT_BCP" != "" ]; then |
| 570 | EXTRA_OPTIONS+=("-Xbootclasspath:$DEX2OAT_BCP") |
| 571 | DEX2OAT_FLAGS+=("--runtime-arg" "-Xbootclasspath:$DEX2OAT_BCP") |
| 572 | if [ "$DEX2OAT_BCP_LOCS" != "" ]; then |
| 573 | EXTRA_OPTIONS+=("-Xbootclasspath-locations:$DEX2OAT_BCP_LOCS") |
| 574 | DEX2OAT_FLAGS+=("--runtime-arg" \ |
| 575 | "-Xbootclasspath-locations:$DEX2OAT_BCP_LOCS") |
| 576 | fi |
| 577 | fi |
| 578 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 579 | if [ "$PERF" != "" ]; then |
David Srbecky | 0dcb17f | 2018-08-13 12:41:47 +0100 | [diff] [blame] | 580 | LAUNCH_WRAPPER="perf record -g --call-graph dwarf -F 10000 -o $ANDROID_DATA/perf.data -e cycles:u $LAUNCH_WRAPPER" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 581 | DEX2OAT_FLAGS+=(--generate-debug-info) |
Nicolas Geoffray | e099a61 | 2014-12-12 13:52:00 +0000 | [diff] [blame] | 582 | fi |
| 583 | |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 584 | if [ "$ALLOW_DEFAULT_JDWP" = "no" ]; then |
| 585 | EXTRA_OPTIONS+=(-XjdwpProvider:none) |
| 586 | fi |
| 587 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 588 | # First cleanup any left-over 'oat' files from the last time dalvikvm was run. |
| 589 | cleanup_oat_directory_for_classpath "$@" |
| 590 | |
| 591 | # Protect additional arguments in quotes to preserve whitespaces (used by |
| 592 | # run-jdwp-test.sh when running on device), '$' (may be used as part of |
| 593 | # classpath) and other special characters when evaluated. |
| 594 | EXTRA_OPTIONS+=("$@") |
| 595 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 596 | if [ "$JIT_PROFILE" = "yes" ]; then |
| 597 | # Create the profile. The runtime expects profiles to be created before |
| 598 | # execution. |
| 599 | PROFILE_PATH="$ANDROID_DATA/primary.prof" |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 600 | touch "$PROFILE_PATH" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 601 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 602 | run_art -Xjitsaveprofilinginfo \ |
| 603 | -Xps-min-methods-to-save:1 \ |
| 604 | -Xps-min-classes-to-save:1 \ |
| 605 | -Xps-min-notification-before-wake:10 \ |
| 606 | -Xps-profile-path:$PROFILE_PATH \ |
| 607 | -Xusejit:true \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 608 | ${EXTRA_OPTIONS[@]} \ |
Igor Murashkin | 1194244 | 2017-07-20 11:08:34 -0700 | [diff] [blame] | 609 | &> "$ANDROID_DATA/profile_gen.log" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 610 | EXIT_STATUS=$? |
| 611 | |
| 612 | if [ $EXIT_STATUS != 0 ]; then |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 613 | echo "Profile run failed: " >&2 |
| 614 | cat "$ANDROID_DATA/profile_gen.log" >&2 |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 615 | clean_android_data |
| 616 | exit $EXIT_STATUS |
| 617 | fi |
| 618 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 619 | # Wipe dalvik-cache so that a subsequent run_art must regenerate it. |
| 620 | # Leave $ANDROID_DATA intact since it contains our profile file. |
Nicolas Geoffray | b487c57 | 2018-09-17 12:17:09 +0000 | [diff] [blame] | 621 | rm -rf "$ANDROID_DATA/dalvik-cache" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 622 | |
| 623 | # Append arguments so next invocation of run_art uses the profile. |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 624 | DEX2OAT_FLAGS+=(--profile-file="$PROFILE_PATH") |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 625 | fi |
| 626 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 627 | if [ -x "$DEX2OAT_BINARY_PATH" ]; then |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 628 | if [ "$RUN_DEX2OAT" = "yes" ]; then |
| 629 | # Run dex2oat before launching ART to generate the oat files for the classpath. |
| 630 | run_dex2oat |
| 631 | fi |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 632 | fi |
| 633 | |
| 634 | # Do not continue if the dex2oat failed. |
| 635 | EXIT_STATUS=$? |
| 636 | if [ $EXIT_STATUS != 0 ]; then |
| 637 | echo "Failed dex2oat invocation" >&2 |
| 638 | exit $EXIT_STATUS |
| 639 | fi |
Calin Juravle | 64f45cb | 2017-03-16 19:58:26 -0700 | [diff] [blame] | 640 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 641 | run_art "${EXTRA_OPTIONS[@]}" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 642 | EXIT_STATUS=$? |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 643 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 644 | if [ "$PERF" != "" ]; then |
| 645 | if [ "$PERF" = report ]; then |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 646 | perf report -i $ANDROID_DATA/perf.data |
| 647 | fi |
| 648 | echo "Perf data saved in: $ANDROID_DATA/perf.data" |
| 649 | else |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 650 | # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used. |
| 651 | clean_android_data |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 652 | fi |
| 653 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 654 | exit $EXIT_STATUS |