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 \ |
| 202 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH \ |
| 203 | PATH=$ANDROID_ROOT/bin:$PATH \ |
| 204 | LD_USE_LOAD_BIAS=1 \ |
| 205 | ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS \ |
| 206 | $DEX2OAT_BINARY_PATH \ |
| 207 | --runtime-arg -Xnorelocate \ |
| 208 | --boot-image=$DEX2OAT_BOOT_IMAGE \ |
| 209 | --instruction-set=$ISA \ |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 210 | --class-loader-context="PCL[$class_loader_context]" \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 211 | "${DEX2OAT_FLAGS[@]}" \ |
| 212 | --dex-file=$dex_file \ |
| 213 | --oat-file=$oat_file |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 214 | if [[ -n $class_loader_context ]]; then |
| 215 | class_loader_context+=":" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 216 | fi |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 217 | class_loader_context+="$dex_file" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 218 | done |
| 219 | } |
| 220 | |
| 221 | # Extract the dex2oat flags from the list of arguments. |
| 222 | # -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array |
| 223 | # -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH |
| 224 | # -Ximage argument is stored in DEX2OAT_BOOT_IMAGE |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame^] | 225 | # -Xbootclasspath argument is stored in DEX2OAT_BCP |
| 226 | # -Xbootclasspath-locations argument is stored in DEX2OAT_BCP_LOCS |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 227 | function extract_dex2oat_flags() { |
| 228 | while [ $# -gt 0 ]; do |
| 229 | case $1 in |
| 230 | -Xcompiler-option) |
| 231 | DEX2OAT_FLAGS+=("$2") |
| 232 | shift |
| 233 | ;; |
| 234 | -Ximage:*) |
Nicolas Geoffray | 686801f | 2018-08-26 16:00:53 +0100 | [diff] [blame] | 235 | DEX2OAT_BOOT_IMAGE=$1 |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 236 | # Remove '-Ximage:' from the argument. |
| 237 | DEX2OAT_BOOT_IMAGE=${DEX2OAT_BOOT_IMAGE##-Ximage:} |
| 238 | ;; |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame^] | 239 | -Xbootclasspath:*) |
| 240 | DEX2OAT_BCP=$1 |
| 241 | # Remove '-Xbootclasspath:' from the argument. |
| 242 | DEX2OAT_BCP=${DEX2OAT_BCP##-Xbootclasspath:} |
| 243 | ;; |
| 244 | -Xbootclasspath-locations:*) |
| 245 | DEX2OAT_BCP_LOCS=$1 |
| 246 | # Remove '-Xbootclasspath-locations:' from the argument. |
| 247 | DEX2OAT_BCP_LOCS=${DEX2OAT_BCP_LOCS##-Xbootclasspath-locations:} |
| 248 | ;; |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 249 | -cp) |
Nicolas Geoffray | 686801f | 2018-08-26 16:00:53 +0100 | [diff] [blame] | 250 | # Reset any previously parsed classpath, just like dalvikvm |
| 251 | # only supports one -cp argument. |
| 252 | DEX2OAT_CLASSPATH=() |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 253 | # TODO: support -classpath and CLASSPATH |
| 254 | local oifs=$IFS |
| 255 | IFS=':' |
| 256 | for classpath_elem in $2 |
| 257 | do |
| 258 | DEX2OAT_CLASSPATH+=("$classpath_elem") |
| 259 | done |
| 260 | shift |
| 261 | IFS=$oifs |
| 262 | ;; |
| 263 | esac |
| 264 | shift |
| 265 | done |
| 266 | } |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 267 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 268 | # Runs dalvikvm, returns its exit code. |
| 269 | # (Oat directories are cleaned up in between runs) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 270 | function run_art() { |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 271 | local ret |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 272 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 273 | # Run dalvikvm. |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 274 | verbose_run ANDROID_DATA="$ANDROID_DATA" \ |
| 275 | ANDROID_ROOT="$ANDROID_ROOT" \ |
Neil Fuller | 26c4377 | 2018-11-23 17:56:43 +0000 | [diff] [blame] | 276 | ANDROID_RUNTIME_ROOT="$ANDROID_RUNTIME_ROOT" \ |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 277 | LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \ |
| 278 | PATH="$ANDROID_ROOT/bin:$PATH" \ |
| 279 | LD_USE_LOAD_BIAS=1 \ |
| 280 | ANDROID_LOG_TAGS="$ANDROID_LOG_TAGS" \ |
| 281 | $LAUNCH_WRAPPER $ART_BINARY_PATH $lib \ |
| 282 | -XXlib:"$LIBART" \ |
| 283 | -Xnorelocate \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 284 | -Ximage:"$DEFAULT_IMAGE_LOCATION" \ |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 285 | "$@" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 286 | ret=$? |
| 287 | |
| 288 | # Avoid polluting disk with 'oat' files after dalvikvm has finished. |
| 289 | cleanup_oat_directory_for_classpath "$@" |
| 290 | |
| 291 | # Forward exit code of dalvikvm. |
| 292 | return $ret |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 293 | } |
| 294 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 295 | ###################################### |
| 296 | # Globals |
| 297 | ###################################### |
| 298 | ART_BINARY=dalvikvm |
| 299 | DEX2OAT_BINARY=dex2oat |
| 300 | DELETE_ANDROID_DATA="no" |
| 301 | LAUNCH_WRAPPER= |
| 302 | LIBART=libart.so |
| 303 | JIT_PROFILE="no" |
| 304 | ALLOW_DEFAULT_JDWP="no" |
| 305 | VERBOSE="no" |
| 306 | CLEAN_OAT_FILES="yes" |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 307 | RUN_DEX2OAT="yes" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 308 | EXTRA_OPTIONS=() |
| 309 | DEX2OAT_FLAGS=() |
| 310 | DEX2OAT_CLASSPATH=() |
| 311 | |
| 312 | # Parse arguments |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 313 | while [[ "$1" = "-"* ]]; do |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 314 | case "$1" in |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 315 | --) |
| 316 | # No more arguments for this script. |
| 317 | shift |
| 318 | break |
| 319 | ;; |
| 320 | --32) |
| 321 | ART_BINARY=dalvikvm32 |
| 322 | ;; |
| 323 | --64) |
| 324 | ART_BINARY=dalvikvm64 |
| 325 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 326 | -d) |
| 327 | ;& # Fallthrough |
| 328 | --debug) |
| 329 | LIBART="libartd.so" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 330 | DEX2OAT_BINARY=dex2oatd |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 331 | # Expect that debug mode wants all checks. |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 332 | EXTRA_OPTIONS+=(-XX:SlowDebug=true) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 333 | ;; |
Alex Light | 84b92e0 | 2017-09-29 13:46:14 -0700 | [diff] [blame] | 334 | --gdbserver) |
| 335 | LAUNCH_WRAPPER="gdbserver $2" |
| 336 | shift |
| 337 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 338 | --gdb) |
| 339 | LIBART="libartd.so" |
| 340 | LAUNCH_WRAPPER="gdb --args" |
| 341 | ;; |
| 342 | --help) |
| 343 | usage |
| 344 | exit 0 |
| 345 | ;; |
| 346 | --invoke-with) |
| 347 | LAUNCH_WRAPPER=$2 |
| 348 | shift |
| 349 | ;; |
| 350 | --perf) |
| 351 | PERF="record" |
| 352 | ;; |
| 353 | --perf-report) |
| 354 | PERF="report" |
| 355 | ;; |
| 356 | --profile) |
| 357 | JIT_PROFILE="yes" |
| 358 | ;; |
| 359 | --verbose) |
| 360 | VERBOSE="yes" |
| 361 | ;; |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 362 | --no-clean) |
| 363 | CLEAN_OAT_FILES="no" |
| 364 | ;; |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 365 | --no-compile) |
| 366 | CLEAN_OAT_FILES="no" |
| 367 | RUN_DEX2OAT="no" |
| 368 | ;; |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 369 | --allow-default-jdwp) |
| 370 | ALLOW_DEFAULT_JDWP="yes" |
| 371 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 372 | --*) |
| 373 | echo "unknown option: $1" 1>&2 |
| 374 | usage |
| 375 | exit 1 |
| 376 | ;; |
| 377 | *) |
| 378 | break |
| 379 | ;; |
| 380 | esac |
| 381 | shift |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 382 | done |
| 383 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 384 | if [ $# -eq 0 ]; then |
| 385 | usage |
| 386 | exit 1 |
| 387 | fi |
| 388 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 389 | # Follow all sym links to get the program name. |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 390 | if [[ -n "$BASH_SOURCE" ]]; then |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 391 | PROG_NAME="$BASH_SOURCE" |
| 392 | else |
| 393 | PROG_NAME="$0" |
| 394 | fi |
| 395 | while [ -h "$PROG_NAME" ]; do |
| 396 | # On Mac OS, readlink -f doesn't work. |
| 397 | PROG_NAME="$(readlink "$PROG_NAME")" |
| 398 | done |
| 399 | |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 400 | PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame^] | 401 | ANDROID_ROOT="$(cd $PROG_DIR/..; pwd -P)" |
Neil Fuller | 26c4377 | 2018-11-23 17:56:43 +0000 | [diff] [blame] | 402 | ANDROID_RUNTIME_ROOT=$ANDROID_ROOT/com.android.runtime |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 403 | ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 404 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 405 | if [ ! -x "$ART_BINARY_PATH" ]; then |
| 406 | cat 1>&2 <<EOF |
| 407 | Android Runtime not found: $ART_BINARY_PATH |
| 408 | This script should be in the same directory as the Android Runtime ($ART_BINARY). |
| 409 | EOF |
| 410 | exit 1 |
| 411 | fi |
| 412 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 413 | DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY |
| 414 | |
| 415 | if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then |
| 416 | echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH" |
| 417 | fi |
| 418 | |
| 419 | ###################################### |
| 420 | # Main program |
| 421 | ###################################### |
| 422 | |
| 423 | # If android logging is not explicitly set, only print warnings and errors. |
| 424 | if [ -z "$ANDROID_LOG_TAGS" ]; then |
| 425 | ANDROID_LOG_TAGS='*:w' |
| 426 | fi |
| 427 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 428 | LIBDIR="$(find_libdir $ART_BINARY_PATH)" |
| 429 | LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 430 | DEFAULT_IMAGE_LOCATION="$(detect_boot_image_location)" |
| 431 | DEX2OAT_BOOT_IMAGE="$DEFAULT_IMAGE_LOCATION" |
Nicolas Geoffray | 810a100 | 2018-08-28 17:40:49 +0100 | [diff] [blame] | 432 | 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] | 433 | |
| 434 | # Extract the dex2oat flags from the list of arguments. |
| 435 | # -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array |
| 436 | # -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH |
| 437 | # -Ximage argument is stored in DEX2OAT_BOOTIMAGE |
| 438 | extract_dex2oat_flags "$@" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 439 | |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 440 | # If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own, |
| 441 | # and ensure we delete it at the end. |
| 442 | if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 443 | if [[ $PWD != / ]]; then |
| 444 | ANDROID_DATA="$PWD/android-data$$" |
| 445 | else |
| 446 | # Use /data/local/tmp when running this from adb shell, since it starts out in / |
| 447 | # by default. |
| 448 | ANDROID_DATA="$ANDROID_DATA/local/tmp/android-data$$" |
| 449 | fi |
Nicolas Geoffray | b487c57 | 2018-09-17 12:17:09 +0000 | [diff] [blame] | 450 | mkdir -p "$ANDROID_DATA" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 451 | DELETE_ANDROID_DATA="yes" |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 452 | fi |
| 453 | |
Vladimir Marko | bf68e57 | 2018-12-21 11:45:35 +0000 | [diff] [blame^] | 454 | if [[ "$DEX2OAT_BCP" = "" && "$DEX2OAT_BCP_LOCS" != "" ]]; then |
| 455 | echo "Cannot use -Xbootclasspath-locations without -Xbootclasspath" |
| 456 | exit 1 |
| 457 | fi |
| 458 | |
| 459 | if [[ "$DEX2OAT_BOOT_IMAGE" = *core.art && "$DEX2OAT_BCP" = "" ]]; then |
| 460 | # Note: This must start with the CORE_IMG_JARS in Android.common_path.mk |
| 461 | # because that's what we use for compiling the core.art image. |
| 462 | # It may contain additional modules from TEST_CORE_JARS. |
| 463 | core_jars_list="core-oj core-libart core-simple okhttp bouncycastle apache-xml conscrypt" |
| 464 | core_jars_suffix= |
| 465 | if [[ -e $ANDROID_ROOT/framework/core-oj-hostdex.jar ]]; then |
| 466 | core_jars_suffix=-hostdex |
| 467 | core_locations_dir=$ANDROID_ROOT/framework |
| 468 | prefix=$PWD/ |
| 469 | if [[ ${core_locations_dir:0:${#prefix}} = $prefix ]]; then |
| 470 | core_locations_dir="${core_locations_dir##$prefix}" |
| 471 | fi |
| 472 | elif [[ -e $ANDROID_ROOT/framework/core-oj-testdex.jar ]]; then |
| 473 | core_jars_suffix=-testdex |
| 474 | core_locations_dir=/system/framework |
| 475 | fi |
| 476 | if [[ $core_jars_suffix != "" ]]; then |
| 477 | boot_separator="" |
| 478 | for boot_module in ${core_jars_list}; do |
| 479 | DEX_FILENAME="$boot_module$core_jars_suffix.jar" |
| 480 | DEX2OAT_BCP+="$boot_separator$ANDROID_ROOT/framework/${DEX_FILENAME}" |
| 481 | DEX2OAT_BCP_LOCS+="$boot_separator$core_locations_dir/${DEX_FILENAME}" |
| 482 | boot_separator=":" |
| 483 | done |
| 484 | if [ "$VERBOSE" = "yes" ]; then |
| 485 | echo "Using predefined -Xbootclasspath for image $DEX2OAT_BOOT_IMAGE:" |
| 486 | echo DEX2OAT_BOOT_IMAGE=$DEX2OAT_BOOT_IMAGE |
| 487 | echo DEX2OAT_BCP=$DEX2OAT_BCP |
| 488 | echo DEX2OAT_BCP_LOCS=$DEX2OAT_BCP_LOCS |
| 489 | fi |
| 490 | fi |
| 491 | fi |
| 492 | |
| 493 | if [ "$DEX2OAT_BCP" != "" ]; then |
| 494 | EXTRA_OPTIONS+=("-Xbootclasspath:$DEX2OAT_BCP") |
| 495 | DEX2OAT_FLAGS+=("--runtime-arg" "-Xbootclasspath:$DEX2OAT_BCP") |
| 496 | if [ "$DEX2OAT_BCP_LOCS" != "" ]; then |
| 497 | EXTRA_OPTIONS+=("-Xbootclasspath-locations:$DEX2OAT_BCP_LOCS") |
| 498 | DEX2OAT_FLAGS+=("--runtime-arg" \ |
| 499 | "-Xbootclasspath-locations:$DEX2OAT_BCP_LOCS") |
| 500 | fi |
| 501 | fi |
| 502 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 503 | if [ "$PERF" != "" ]; then |
David Srbecky | 0dcb17f | 2018-08-13 12:41:47 +0100 | [diff] [blame] | 504 | 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] | 505 | DEX2OAT_FLAGS+=(--generate-debug-info) |
Nicolas Geoffray | e099a61 | 2014-12-12 13:52:00 +0000 | [diff] [blame] | 506 | fi |
| 507 | |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 508 | if [ "$ALLOW_DEFAULT_JDWP" = "no" ]; then |
| 509 | EXTRA_OPTIONS+=(-XjdwpProvider:none) |
| 510 | fi |
| 511 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 512 | # First cleanup any left-over 'oat' files from the last time dalvikvm was run. |
| 513 | cleanup_oat_directory_for_classpath "$@" |
| 514 | |
| 515 | # Protect additional arguments in quotes to preserve whitespaces (used by |
| 516 | # run-jdwp-test.sh when running on device), '$' (may be used as part of |
| 517 | # classpath) and other special characters when evaluated. |
| 518 | EXTRA_OPTIONS+=("$@") |
| 519 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 520 | if [ "$JIT_PROFILE" = "yes" ]; then |
| 521 | # Create the profile. The runtime expects profiles to be created before |
| 522 | # execution. |
| 523 | PROFILE_PATH="$ANDROID_DATA/primary.prof" |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 524 | touch "$PROFILE_PATH" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 525 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 526 | run_art -Xjitsaveprofilinginfo \ |
| 527 | -Xps-min-methods-to-save:1 \ |
| 528 | -Xps-min-classes-to-save:1 \ |
| 529 | -Xps-min-notification-before-wake:10 \ |
| 530 | -Xps-profile-path:$PROFILE_PATH \ |
| 531 | -Xusejit:true \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 532 | ${EXTRA_OPTIONS[@]} \ |
Igor Murashkin | 1194244 | 2017-07-20 11:08:34 -0700 | [diff] [blame] | 533 | &> "$ANDROID_DATA/profile_gen.log" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 534 | EXIT_STATUS=$? |
| 535 | |
| 536 | if [ $EXIT_STATUS != 0 ]; then |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 537 | echo "Profile run failed: " >&2 |
| 538 | cat "$ANDROID_DATA/profile_gen.log" >&2 |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 539 | clean_android_data |
| 540 | exit $EXIT_STATUS |
| 541 | fi |
| 542 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 543 | # Wipe dalvik-cache so that a subsequent run_art must regenerate it. |
| 544 | # Leave $ANDROID_DATA intact since it contains our profile file. |
Nicolas Geoffray | b487c57 | 2018-09-17 12:17:09 +0000 | [diff] [blame] | 545 | rm -rf "$ANDROID_DATA/dalvik-cache" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 546 | |
| 547 | # Append arguments so next invocation of run_art uses the profile. |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 548 | DEX2OAT_FLAGS+=(--profile-file="$PROFILE_PATH") |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 549 | fi |
| 550 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 551 | if [ -x "$DEX2OAT_BINARY_PATH" ]; then |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 552 | if [ "$RUN_DEX2OAT" = "yes" ]; then |
| 553 | # Run dex2oat before launching ART to generate the oat files for the classpath. |
| 554 | run_dex2oat |
| 555 | fi |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 556 | fi |
| 557 | |
| 558 | # Do not continue if the dex2oat failed. |
| 559 | EXIT_STATUS=$? |
| 560 | if [ $EXIT_STATUS != 0 ]; then |
| 561 | echo "Failed dex2oat invocation" >&2 |
| 562 | exit $EXIT_STATUS |
| 563 | fi |
Calin Juravle | 64f45cb | 2017-03-16 19:58:26 -0700 | [diff] [blame] | 564 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 565 | run_art "${EXTRA_OPTIONS[@]}" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 566 | EXIT_STATUS=$? |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 567 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 568 | if [ "$PERF" != "" ]; then |
| 569 | if [ "$PERF" = report ]; then |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 570 | perf report -i $ANDROID_DATA/perf.data |
| 571 | fi |
| 572 | echo "Perf data saved in: $ANDROID_DATA/perf.data" |
| 573 | else |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 574 | # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used. |
| 575 | clean_android_data |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 576 | fi |
| 577 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 578 | exit $EXIT_STATUS |