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. |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 52 | --allow-default-jdwp Don't automatically put in -XjdwpProvider:none. |
| 53 | You probably do not want this. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 54 | |
| 55 | The ART_OPTIONS are passed directly to the Android Runtime. |
| 56 | |
| 57 | Example: |
| 58 | art --32 -cp my_classes.dex MainClass |
| 59 | |
| 60 | Common 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 |
| 65 | EOF |
| 66 | } |
| 67 | |
| 68 | function clean_android_data() { |
| 69 | if [ "$DELETE_ANDROID_DATA" = "yes" ]; then |
| 70 | rm -rf $ANDROID_DATA |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 71 | fi |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 72 | } |
| 73 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 74 | # 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 Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 78 | function verbose_run() { |
| 79 | if [ "$VERBOSE" = "yes" ]; then |
| 80 | echo "$@" |
| 81 | fi |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 82 | |
| 83 | env "$@" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 86 | # Parse a colon-separated list into an array (e.g. "foo.dex:bar.dex" -> (foo.dex bar.dex)) |
| 87 | PARSE_CLASSPATH_RESULT=() # Return value will be here due to shell limitations. |
| 88 | parse_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) |
| 106 | find_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. |
| 126 | cleanup_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. |
| 142 | cleanup_oat_directory_for_classpath() { |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 143 | 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 Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 148 | |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 149 | cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}" |
| 150 | fi |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 153 | # Attempt to find $ANDROID_ROOT/framework/<isa>/core.art' without knowing what <isa> is. |
| 154 | function 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 Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 167 | # 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. |
| 169 | function detect_boot_image_location() { |
| 170 | local image_location_dir="$ANDROID_ROOT/framework" |
| 171 | local image_location_name="core.art" |
| 172 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 173 | # 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 Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 178 | 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 Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 185 | function run_dex2oat() { |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 186 | local class_loader_context= |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 187 | 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 Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 209 | --class-loader-context="PCL[$class_loader_context]" \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 210 | "${DEX2OAT_FLAGS[@]}" \ |
| 211 | --dex-file=$dex_file \ |
| 212 | --oat-file=$oat_file |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 213 | if [[ -n $class_loader_context ]]; then |
| 214 | class_loader_context+=":" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 215 | fi |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 216 | class_loader_context+="$dex_file" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 217 | 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 |
| 224 | function 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 Geoffray | 686801f | 2018-08-26 16:00:53 +0100 | [diff] [blame] | 232 | DEX2OAT_BOOT_IMAGE=$1 |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 233 | # Remove '-Ximage:' from the argument. |
| 234 | DEX2OAT_BOOT_IMAGE=${DEX2OAT_BOOT_IMAGE##-Ximage:} |
| 235 | ;; |
| 236 | -cp) |
Nicolas Geoffray | 686801f | 2018-08-26 16:00:53 +0100 | [diff] [blame] | 237 | # Reset any previously parsed classpath, just like dalvikvm |
| 238 | # only supports one -cp argument. |
| 239 | DEX2OAT_CLASSPATH=() |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 240 | # 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 Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 254 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 255 | # Runs dalvikvm, returns its exit code. |
| 256 | # (Oat directories are cleaned up in between runs) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 257 | function run_art() { |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 258 | local ret |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 259 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 260 | # Run dalvikvm. |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 261 | 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 Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 270 | -Ximage:"$DEFAULT_IMAGE_LOCATION" \ |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 271 | "$@" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 272 | 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 Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 281 | ###################################### |
| 282 | # Globals |
| 283 | ###################################### |
| 284 | ART_BINARY=dalvikvm |
| 285 | DEX2OAT_BINARY=dex2oat |
| 286 | DELETE_ANDROID_DATA="no" |
| 287 | LAUNCH_WRAPPER= |
| 288 | LIBART=libart.so |
| 289 | JIT_PROFILE="no" |
| 290 | ALLOW_DEFAULT_JDWP="no" |
| 291 | VERBOSE="no" |
| 292 | CLEAN_OAT_FILES="yes" |
| 293 | EXTRA_OPTIONS=() |
| 294 | DEX2OAT_FLAGS=() |
| 295 | DEX2OAT_CLASSPATH=() |
| 296 | |
| 297 | # Parse arguments |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 298 | while [[ "$1" = "-"* ]]; do |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 299 | case "$1" in |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 300 | --) |
| 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 Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 311 | -d) |
| 312 | ;& # Fallthrough |
| 313 | --debug) |
| 314 | LIBART="libartd.so" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 315 | DEX2OAT_BINARY=dex2oatd |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 316 | # Expect that debug mode wants all checks. |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 317 | EXTRA_OPTIONS+=(-XX:SlowDebug=true) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 318 | ;; |
Alex Light | 84b92e0 | 2017-09-29 13:46:14 -0700 | [diff] [blame] | 319 | --gdbserver) |
| 320 | LAUNCH_WRAPPER="gdbserver $2" |
| 321 | shift |
| 322 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 323 | --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 Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 347 | --no-clean) |
| 348 | CLEAN_OAT_FILES="no" |
| 349 | ;; |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 350 | --allow-default-jdwp) |
| 351 | ALLOW_DEFAULT_JDWP="yes" |
| 352 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 353 | --*) |
| 354 | echo "unknown option: $1" 1>&2 |
| 355 | usage |
| 356 | exit 1 |
| 357 | ;; |
| 358 | *) |
| 359 | break |
| 360 | ;; |
| 361 | esac |
| 362 | shift |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 363 | done |
| 364 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 365 | if [ $# -eq 0 ]; then |
| 366 | usage |
| 367 | exit 1 |
| 368 | fi |
| 369 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 370 | # Follow all sym links to get the program name. |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 371 | if [[ -n "$BASH_SOURCE" ]]; then |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 372 | PROG_NAME="$BASH_SOURCE" |
| 373 | else |
| 374 | PROG_NAME="$0" |
| 375 | fi |
| 376 | while [ -h "$PROG_NAME" ]; do |
| 377 | # On Mac OS, readlink -f doesn't work. |
| 378 | PROG_NAME="$(readlink "$PROG_NAME")" |
| 379 | done |
| 380 | |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 381 | PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" |
| 382 | ANDROID_ROOT=$PROG_DIR/.. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 383 | ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 384 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 385 | if [ ! -x "$ART_BINARY_PATH" ]; then |
| 386 | cat 1>&2 <<EOF |
| 387 | Android Runtime not found: $ART_BINARY_PATH |
| 388 | This script should be in the same directory as the Android Runtime ($ART_BINARY). |
| 389 | EOF |
| 390 | exit 1 |
| 391 | fi |
| 392 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 393 | DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY |
| 394 | |
| 395 | if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then |
| 396 | echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH" |
| 397 | fi |
| 398 | |
| 399 | ###################################### |
| 400 | # Main program |
| 401 | ###################################### |
| 402 | |
| 403 | # If android logging is not explicitly set, only print warnings and errors. |
| 404 | if [ -z "$ANDROID_LOG_TAGS" ]; then |
| 405 | ANDROID_LOG_TAGS='*:w' |
| 406 | fi |
| 407 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 408 | LIBDIR="$(find_libdir $ART_BINARY_PATH)" |
| 409 | LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 410 | DEFAULT_IMAGE_LOCATION="$(detect_boot_image_location)" |
| 411 | DEX2OAT_BOOT_IMAGE="$DEFAULT_IMAGE_LOCATION" |
Nicolas Geoffray | 810a100 | 2018-08-28 17:40:49 +0100 | [diff] [blame] | 412 | 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] | 413 | |
| 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 |
| 418 | extract_dex2oat_flags "$@" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 419 | |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 420 | # If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own, |
| 421 | # and ensure we delete it at the end. |
| 422 | if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 423 | 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 Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 430 | mkdir -p "$ANDROID_DATA" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 431 | DELETE_ANDROID_DATA="yes" |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 432 | fi |
| 433 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 434 | if [ "$PERF" != "" ]; then |
David Srbecky | 0dcb17f | 2018-08-13 12:41:47 +0100 | [diff] [blame] | 435 | 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] | 436 | DEX2OAT_FLAGS+=(--generate-debug-info) |
Nicolas Geoffray | e099a61 | 2014-12-12 13:52:00 +0000 | [diff] [blame] | 437 | fi |
| 438 | |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 439 | if [ "$ALLOW_DEFAULT_JDWP" = "no" ]; then |
| 440 | EXTRA_OPTIONS+=(-XjdwpProvider:none) |
| 441 | fi |
| 442 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 443 | # First cleanup any left-over 'oat' files from the last time dalvikvm was run. |
| 444 | cleanup_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. |
| 449 | EXTRA_OPTIONS+=("$@") |
| 450 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 451 | if [ "$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 Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 455 | touch "$PROFILE_PATH" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 456 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 457 | 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 Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 463 | ${EXTRA_OPTIONS[@]} \ |
Igor Murashkin | 1194244 | 2017-07-20 11:08:34 -0700 | [diff] [blame] | 464 | &> "$ANDROID_DATA/profile_gen.log" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 465 | EXIT_STATUS=$? |
| 466 | |
| 467 | if [ $EXIT_STATUS != 0 ]; then |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 468 | echo "Profile run failed: " >&2 |
| 469 | cat "$ANDROID_DATA/profile_gen.log" >&2 |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 470 | clean_android_data |
| 471 | exit $EXIT_STATUS |
| 472 | fi |
| 473 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 474 | # 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 Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 477 | |
| 478 | # Append arguments so next invocation of run_art uses the profile. |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 479 | DEX2OAT_FLAGS+=(--profile-file="$PROFILE_PATH") |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 480 | fi |
| 481 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 482 | if [ -x "$DEX2OAT_BINARY_PATH" ]; then |
| 483 | # Run dex2oat before launching ART to generate the oat files for the classpath. |
| 484 | run_dex2oat |
| 485 | fi |
| 486 | |
| 487 | # Do not continue if the dex2oat failed. |
| 488 | EXIT_STATUS=$? |
| 489 | if [ $EXIT_STATUS != 0 ]; then |
| 490 | echo "Failed dex2oat invocation" >&2 |
| 491 | exit $EXIT_STATUS |
| 492 | fi |
Calin Juravle | 64f45cb | 2017-03-16 19:58:26 -0700 | [diff] [blame] | 493 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 494 | run_art "${EXTRA_OPTIONS[@]}" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 495 | EXIT_STATUS=$? |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 496 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 497 | if [ "$PERF" != "" ]; then |
| 498 | if [ "$PERF" = report ]; then |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 499 | perf report -i $ANDROID_DATA/perf.data |
| 500 | fi |
| 501 | echo "Perf data saved in: $ANDROID_DATA/perf.data" |
| 502 | else |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 503 | # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used. |
| 504 | clean_android_data |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 505 | fi |
| 506 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 507 | exit $EXIT_STATUS |