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