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. |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 53 | --toybox-path <path> Path for toybox executable. Provide this |
| 54 | path if your device does not have |
| 55 | 'env', 'rm', 'dirname', 'basename', or 'mkdir'. |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 56 | --allow-default-jdwp Don't automatically put in -XjdwpProvider:none. |
| 57 | You probably do not want this. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 58 | |
| 59 | The ART_OPTIONS are passed directly to the Android Runtime. |
| 60 | |
| 61 | Example: |
| 62 | art --32 -cp my_classes.dex MainClass |
| 63 | |
| 64 | Common errors: |
| 65 | 1) Not having core.art available (see $ANDROID_BUILD_TOP/art/Android.mk). |
| 66 | eg m -j32 build-art-host |
| 67 | 2) Not having boot.art available (see $ANDROID_BUILD_TOP/build/make/core/dex_preopt_libart_boot.mk) |
| 68 | eg m -j32 out/target/product/generic_x86_64/dex_bootjars/system/framework/x86_64/boot.art |
| 69 | EOF |
| 70 | } |
| 71 | |
| 72 | function clean_android_data() { |
| 73 | if [ "$DELETE_ANDROID_DATA" = "yes" ]; then |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 74 | $TOYBOX rm -rf $ANDROID_DATA |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 75 | fi |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 78 | # Given 'VAR1=VAL VAR2=VAL2 ... cmd arg1 arg2 ... argN' run the 'cmd' with the args |
| 79 | # with the modified environment {VAR1=VAL,VAL2=,...}. |
| 80 | # |
| 81 | # Also prints the command to be run if verbose mode is enabled. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 82 | function verbose_run() { |
| 83 | if [ "$VERBOSE" = "yes" ]; then |
| 84 | echo "$@" |
| 85 | fi |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 86 | |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 87 | $TOYBOX env "$@" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 90 | # Parse a colon-separated list into an array (e.g. "foo.dex:bar.dex" -> (foo.dex bar.dex)) |
| 91 | PARSE_CLASSPATH_RESULT=() # Return value will be here due to shell limitations. |
| 92 | parse_classpath() { |
| 93 | local cp="$1" |
| 94 | local oldifs=$IFS |
| 95 | |
| 96 | local cp_array |
| 97 | cp_array=() |
| 98 | |
| 99 | IFS=":" |
| 100 | for part in $cp; do |
| 101 | cp_array+=("$part") |
| 102 | done |
| 103 | IFS=$oldifs |
| 104 | |
| 105 | PARSE_CLASSPATH_RESULT=("${cp_array[@]}") |
| 106 | } |
| 107 | |
| 108 | # Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files. |
| 109 | # e.g. (-cp foo/classes.dex:bar/classes.dex) -> (foo/classes.dex bar/classes.dex) |
| 110 | find_cp_in_args() { |
| 111 | local found="false" |
| 112 | local index=0 |
| 113 | local what |
| 114 | |
| 115 | while [[ $# -gt 0 ]]; do |
| 116 | case "$1" in |
| 117 | -cp|-classpath) |
| 118 | parse_classpath "$2" |
| 119 | # Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files. |
| 120 | # Subsequent parses will overwrite the preceding. |
| 121 | shift |
| 122 | ;; |
| 123 | esac |
| 124 | shift |
| 125 | done |
| 126 | } |
| 127 | |
| 128 | # Delete the 'oat' directories relative to the classpath's dex files. |
| 129 | # e.g. (foo/classes.dex bar/classes.dex) would delete (foo/oat bar/oat) directories. |
| 130 | cleanup_oat_directory() { |
| 131 | local classpath |
| 132 | classpath=("$@") |
| 133 | |
| 134 | local dirpath |
| 135 | |
| 136 | for path in "${classpath[@]}"; do |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 137 | dirpath="$($TOYBOX dirname "$path")" |
| 138 | [[ -d "$dirpath" ]] && verbose_run $TOYBOX rm -rf "$dirpath/oat" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 139 | done |
| 140 | } |
| 141 | |
| 142 | # Parse -cp <CP>, -classpath <CP>, and $CLASSPATH to find the dex files. |
| 143 | # Each dex file's directory will have an 'oat' file directory, delete it. |
| 144 | # Input: Command line arguments to the art script. |
| 145 | # e.g. -cp foo/classes.dex:bar/classes.dex would delete (foo/oat bar/oat) directories. |
| 146 | cleanup_oat_directory_for_classpath() { |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 147 | if [ "$CLEAN_OAT_FILES" = "yes" ]; then |
| 148 | # First try: Use $CLASSPATH environment variable. |
| 149 | parse_classpath "$CLASSPATH" |
| 150 | # Second try: Look for latest -cp or -classpath arg which will take precedence. |
| 151 | find_cp_in_args "$@" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 152 | |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 153 | cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}" |
| 154 | fi |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 157 | # Attempt to find $ANDROID_ROOT/framework/<isa>/core.art' without knowing what <isa> is. |
| 158 | function check_if_boot_image_file_exists() { |
| 159 | local image_location_dir="$1" |
| 160 | local image_location_name="$2" |
| 161 | |
| 162 | # Expand image_files to a list of existing image files on the disk. |
| 163 | # If no such files exist, it expands to single element 'dir/*/file' with a literal '*'. |
| 164 | local image_files |
| 165 | image_files=("$image_location_dir"/*/"$image_location_name") # avoid treating "*" as literal. |
| 166 | |
| 167 | # Array always has at least 1 element. Test explicitly whether the file exists. |
| 168 | [[ -e "${image_files[0]}" ]] |
| 169 | } |
| 170 | |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 171 | # Automatically find the boot image location. It uses core.art by default. |
| 172 | # On a real device, it might only have a boot.art, so use that instead when core.art does not exist. |
| 173 | function detect_boot_image_location() { |
| 174 | local image_location_dir="$ANDROID_ROOT/framework" |
| 175 | local image_location_name="core.art" |
| 176 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 177 | # If there are no existing core.art, try to find boot.art. |
| 178 | # If there is no boot.art then leave it as-is, assumes -Ximage is explicitly used. |
| 179 | # Otherwise let dalvikvm give the error message about an invalid image file. |
| 180 | if ! check_if_boot_image_file_exists "$image_location_dir" "core.art" && \ |
| 181 | check_if_boot_image_file_exists "$image_location_dir" "boot.art"; then |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 182 | image_location_name="boot.art" |
| 183 | fi |
| 184 | |
| 185 | local image_location="$image_location_dir/$image_location_name" |
| 186 | echo "$image_location" |
| 187 | } |
| 188 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 189 | function run_dex2oat() { |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 190 | local class_loader_context= |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 191 | for dex_file in "${DEX2OAT_CLASSPATH[@]}" |
| 192 | do |
| 193 | while [ -h "$dex_file" ]; do |
| 194 | # On Mac OS, readlink -f doesn't work. |
| 195 | dex_file="$(readlink "$dex_file")" |
| 196 | done |
| 197 | # Create oat file directory. |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 198 | verbose_run $TOYBOX mkdir -p $($TOYBOX dirname "$dex_file")/oat/$ISA |
| 199 | local oat_file=$($TOYBOX basename "$dex_file") |
| 200 | local oat_file=$($TOYBOX dirname "$dex_file")/oat/$ISA/${oat_file%.*}.odex |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 201 | # When running dex2oat use the exact same context as when running dalvikvm. |
| 202 | # (see run_art function) |
| 203 | verbose_run ANDROID_DATA=$ANDROID_DATA \ |
| 204 | ANDROID_ROOT=$ANDROID_ROOT \ |
| 205 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH \ |
| 206 | PATH=$ANDROID_ROOT/bin:$PATH \ |
| 207 | LD_USE_LOAD_BIAS=1 \ |
| 208 | ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS \ |
| 209 | $DEX2OAT_BINARY_PATH \ |
| 210 | --runtime-arg -Xnorelocate \ |
| 211 | --boot-image=$DEX2OAT_BOOT_IMAGE \ |
| 212 | --instruction-set=$ISA \ |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 213 | --class-loader-context="PCL[$class_loader_context]" \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 214 | "${DEX2OAT_FLAGS[@]}" \ |
| 215 | --dex-file=$dex_file \ |
| 216 | --oat-file=$oat_file |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 217 | if [[ -n $class_loader_context ]]; then |
| 218 | class_loader_context+=":" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 219 | fi |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 220 | class_loader_context+="$dex_file" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 221 | done |
| 222 | } |
| 223 | |
| 224 | # Extract the dex2oat flags from the list of arguments. |
| 225 | # -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array |
| 226 | # -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH |
| 227 | # -Ximage argument is stored in DEX2OAT_BOOT_IMAGE |
| 228 | function extract_dex2oat_flags() { |
| 229 | while [ $# -gt 0 ]; do |
| 230 | case $1 in |
| 231 | -Xcompiler-option) |
| 232 | DEX2OAT_FLAGS+=("$2") |
| 233 | shift |
| 234 | ;; |
| 235 | -Ximage:*) |
Nicolas Geoffray | 686801f | 2018-08-26 16:00:53 +0100 | [diff] [blame] | 236 | DEX2OAT_BOOT_IMAGE=$1 |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 237 | # Remove '-Ximage:' from the argument. |
| 238 | DEX2OAT_BOOT_IMAGE=${DEX2OAT_BOOT_IMAGE##-Ximage:} |
| 239 | ;; |
| 240 | -cp) |
Nicolas Geoffray | 686801f | 2018-08-26 16:00:53 +0100 | [diff] [blame] | 241 | # Reset any previously parsed classpath, just like dalvikvm |
| 242 | # only supports one -cp argument. |
| 243 | DEX2OAT_CLASSPATH=() |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 244 | # TODO: support -classpath and CLASSPATH |
| 245 | local oifs=$IFS |
| 246 | IFS=':' |
| 247 | for classpath_elem in $2 |
| 248 | do |
| 249 | DEX2OAT_CLASSPATH+=("$classpath_elem") |
| 250 | done |
| 251 | shift |
| 252 | IFS=$oifs |
| 253 | ;; |
| 254 | esac |
| 255 | shift |
| 256 | done |
| 257 | } |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 258 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 259 | # Runs dalvikvm, returns its exit code. |
| 260 | # (Oat directories are cleaned up in between runs) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 261 | function run_art() { |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 262 | local ret |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 263 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 264 | # Run dalvikvm. |
Nicolas Geoffray | ffda8b8 | 2017-10-06 13:48:08 +0100 | [diff] [blame] | 265 | verbose_run ANDROID_DATA="$ANDROID_DATA" \ |
| 266 | ANDROID_ROOT="$ANDROID_ROOT" \ |
| 267 | LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \ |
| 268 | PATH="$ANDROID_ROOT/bin:$PATH" \ |
| 269 | LD_USE_LOAD_BIAS=1 \ |
| 270 | ANDROID_LOG_TAGS="$ANDROID_LOG_TAGS" \ |
| 271 | $LAUNCH_WRAPPER $ART_BINARY_PATH $lib \ |
| 272 | -XXlib:"$LIBART" \ |
| 273 | -Xnorelocate \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 274 | -Ximage:"$DEFAULT_IMAGE_LOCATION" \ |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 275 | "$@" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 276 | ret=$? |
| 277 | |
| 278 | # Avoid polluting disk with 'oat' files after dalvikvm has finished. |
| 279 | cleanup_oat_directory_for_classpath "$@" |
| 280 | |
| 281 | # Forward exit code of dalvikvm. |
| 282 | return $ret |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 285 | ###################################### |
| 286 | # Globals |
| 287 | ###################################### |
| 288 | ART_BINARY=dalvikvm |
| 289 | DEX2OAT_BINARY=dex2oat |
| 290 | DELETE_ANDROID_DATA="no" |
| 291 | LAUNCH_WRAPPER= |
| 292 | LIBART=libart.so |
| 293 | JIT_PROFILE="no" |
| 294 | ALLOW_DEFAULT_JDWP="no" |
| 295 | VERBOSE="no" |
| 296 | CLEAN_OAT_FILES="yes" |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 297 | RUN_DEX2OAT="yes" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 298 | EXTRA_OPTIONS=() |
| 299 | DEX2OAT_FLAGS=() |
| 300 | DEX2OAT_CLASSPATH=() |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 301 | TOYBOX= |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 302 | |
| 303 | # Parse arguments |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 304 | while [[ "$1" = "-"* ]]; do |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 305 | case "$1" in |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 306 | --) |
| 307 | # No more arguments for this script. |
| 308 | shift |
| 309 | break |
| 310 | ;; |
| 311 | --32) |
| 312 | ART_BINARY=dalvikvm32 |
| 313 | ;; |
| 314 | --64) |
| 315 | ART_BINARY=dalvikvm64 |
| 316 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 317 | -d) |
| 318 | ;& # Fallthrough |
| 319 | --debug) |
| 320 | LIBART="libartd.so" |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 321 | DEX2OAT_BINARY=dex2oatd |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 322 | # Expect that debug mode wants all checks. |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 323 | EXTRA_OPTIONS+=(-XX:SlowDebug=true) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 324 | ;; |
Alex Light | 84b92e0 | 2017-09-29 13:46:14 -0700 | [diff] [blame] | 325 | --gdbserver) |
| 326 | LAUNCH_WRAPPER="gdbserver $2" |
| 327 | shift |
| 328 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 329 | --gdb) |
| 330 | LIBART="libartd.so" |
| 331 | LAUNCH_WRAPPER="gdb --args" |
| 332 | ;; |
| 333 | --help) |
| 334 | usage |
| 335 | exit 0 |
| 336 | ;; |
| 337 | --invoke-with) |
| 338 | LAUNCH_WRAPPER=$2 |
| 339 | shift |
| 340 | ;; |
| 341 | --perf) |
| 342 | PERF="record" |
| 343 | ;; |
| 344 | --perf-report) |
| 345 | PERF="report" |
| 346 | ;; |
| 347 | --profile) |
| 348 | JIT_PROFILE="yes" |
| 349 | ;; |
| 350 | --verbose) |
| 351 | VERBOSE="yes" |
| 352 | ;; |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame] | 353 | --no-clean) |
| 354 | CLEAN_OAT_FILES="no" |
| 355 | ;; |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 356 | --no-compile) |
| 357 | CLEAN_OAT_FILES="no" |
| 358 | RUN_DEX2OAT="no" |
| 359 | ;; |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 360 | --allow-default-jdwp) |
| 361 | ALLOW_DEFAULT_JDWP="yes" |
| 362 | ;; |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 363 | --toybox-path) |
| 364 | TOYBOX=$2 |
| 365 | shift |
| 366 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 367 | --*) |
| 368 | echo "unknown option: $1" 1>&2 |
| 369 | usage |
| 370 | exit 1 |
| 371 | ;; |
| 372 | *) |
| 373 | break |
| 374 | ;; |
| 375 | esac |
| 376 | shift |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 377 | done |
| 378 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 379 | if [ $# -eq 0 ]; then |
| 380 | usage |
| 381 | exit 1 |
| 382 | fi |
| 383 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 384 | # Follow all sym links to get the program name. |
Nicolas Geoffray | 6b09b39 | 2018-08-29 13:29:01 +0100 | [diff] [blame] | 385 | if [[ -n "$BASH_SOURCE" ]]; then |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 386 | PROG_NAME="$BASH_SOURCE" |
| 387 | else |
| 388 | PROG_NAME="$0" |
| 389 | fi |
| 390 | while [ -h "$PROG_NAME" ]; do |
| 391 | # On Mac OS, readlink -f doesn't work. |
| 392 | PROG_NAME="$(readlink "$PROG_NAME")" |
| 393 | done |
| 394 | |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 395 | PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" |
| 396 | ANDROID_ROOT=$PROG_DIR/.. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 397 | ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 398 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 399 | if [ ! -x "$ART_BINARY_PATH" ]; then |
| 400 | cat 1>&2 <<EOF |
| 401 | Android Runtime not found: $ART_BINARY_PATH |
| 402 | This script should be in the same directory as the Android Runtime ($ART_BINARY). |
| 403 | EOF |
| 404 | exit 1 |
| 405 | fi |
| 406 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 407 | DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY |
| 408 | |
| 409 | if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then |
| 410 | echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH" |
| 411 | fi |
| 412 | |
| 413 | ###################################### |
| 414 | # Main program |
| 415 | ###################################### |
| 416 | |
| 417 | # If android logging is not explicitly set, only print warnings and errors. |
| 418 | if [ -z "$ANDROID_LOG_TAGS" ]; then |
| 419 | ANDROID_LOG_TAGS='*:w' |
| 420 | fi |
| 421 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 422 | LIBDIR="$(find_libdir $ART_BINARY_PATH)" |
| 423 | LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 424 | DEFAULT_IMAGE_LOCATION="$(detect_boot_image_location)" |
| 425 | DEX2OAT_BOOT_IMAGE="$DEFAULT_IMAGE_LOCATION" |
Nicolas Geoffray | 810a100 | 2018-08-28 17:40:49 +0100 | [diff] [blame] | 426 | 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] | 427 | |
| 428 | # Extract the dex2oat flags from the list of arguments. |
| 429 | # -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array |
| 430 | # -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH |
| 431 | # -Ximage argument is stored in DEX2OAT_BOOTIMAGE |
| 432 | extract_dex2oat_flags "$@" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 433 | |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 434 | # If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own, |
| 435 | # and ensure we delete it at the end. |
| 436 | if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 437 | if [[ $PWD != / ]]; then |
| 438 | ANDROID_DATA="$PWD/android-data$$" |
| 439 | else |
| 440 | # Use /data/local/tmp when running this from adb shell, since it starts out in / |
| 441 | # by default. |
| 442 | ANDROID_DATA="$ANDROID_DATA/local/tmp/android-data$$" |
| 443 | fi |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 444 | $TOYBOX mkdir -p "$ANDROID_DATA" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 445 | DELETE_ANDROID_DATA="yes" |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 446 | fi |
| 447 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 448 | if [ "$PERF" != "" ]; then |
David Srbecky | 0dcb17f | 2018-08-13 12:41:47 +0100 | [diff] [blame] | 449 | 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] | 450 | DEX2OAT_FLAGS+=(--generate-debug-info) |
Nicolas Geoffray | e099a61 | 2014-12-12 13:52:00 +0000 | [diff] [blame] | 451 | fi |
| 452 | |
Alex Light | a4817fb | 2018-06-12 10:56:35 -0700 | [diff] [blame] | 453 | if [ "$ALLOW_DEFAULT_JDWP" = "no" ]; then |
| 454 | EXTRA_OPTIONS+=(-XjdwpProvider:none) |
| 455 | fi |
| 456 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 457 | # First cleanup any left-over 'oat' files from the last time dalvikvm was run. |
| 458 | cleanup_oat_directory_for_classpath "$@" |
| 459 | |
| 460 | # Protect additional arguments in quotes to preserve whitespaces (used by |
| 461 | # run-jdwp-test.sh when running on device), '$' (may be used as part of |
| 462 | # classpath) and other special characters when evaluated. |
| 463 | EXTRA_OPTIONS+=("$@") |
| 464 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 465 | if [ "$JIT_PROFILE" = "yes" ]; then |
| 466 | # Create the profile. The runtime expects profiles to be created before |
| 467 | # execution. |
| 468 | PROFILE_PATH="$ANDROID_DATA/primary.prof" |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 469 | touch "$PROFILE_PATH" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 470 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 471 | run_art -Xjitsaveprofilinginfo \ |
| 472 | -Xps-min-methods-to-save:1 \ |
| 473 | -Xps-min-classes-to-save:1 \ |
| 474 | -Xps-min-notification-before-wake:10 \ |
| 475 | -Xps-profile-path:$PROFILE_PATH \ |
| 476 | -Xusejit:true \ |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 477 | ${EXTRA_OPTIONS[@]} \ |
Igor Murashkin | 1194244 | 2017-07-20 11:08:34 -0700 | [diff] [blame] | 478 | &> "$ANDROID_DATA/profile_gen.log" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 479 | EXIT_STATUS=$? |
| 480 | |
| 481 | if [ $EXIT_STATUS != 0 ]; then |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 482 | echo "Profile run failed: " >&2 |
| 483 | cat "$ANDROID_DATA/profile_gen.log" >&2 |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 484 | clean_android_data |
| 485 | exit $EXIT_STATUS |
| 486 | fi |
| 487 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 488 | # Wipe dalvik-cache so that a subsequent run_art must regenerate it. |
| 489 | # Leave $ANDROID_DATA intact since it contains our profile file. |
Nicolas Geoffray | 4b1c75d | 2018-09-14 13:41:57 +0100 | [diff] [blame^] | 490 | $TOYBOX rm -rf "$ANDROID_DATA/dalvik-cache" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 491 | |
| 492 | # Append arguments so next invocation of run_art uses the profile. |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 493 | DEX2OAT_FLAGS+=(--profile-file="$PROFILE_PATH") |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 494 | fi |
| 495 | |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 496 | if [ -x "$DEX2OAT_BINARY_PATH" ]; then |
Nicolas Geoffray | f983c73 | 2018-09-12 09:27:29 +0100 | [diff] [blame] | 497 | if [ "$RUN_DEX2OAT" = "yes" ]; then |
| 498 | # Run dex2oat before launching ART to generate the oat files for the classpath. |
| 499 | run_dex2oat |
| 500 | fi |
Nicolas Geoffray | 335c4ce | 2018-08-24 18:27:31 +0100 | [diff] [blame] | 501 | fi |
| 502 | |
| 503 | # Do not continue if the dex2oat failed. |
| 504 | EXIT_STATUS=$? |
| 505 | if [ $EXIT_STATUS != 0 ]; then |
| 506 | echo "Failed dex2oat invocation" >&2 |
| 507 | exit $EXIT_STATUS |
| 508 | fi |
Calin Juravle | 64f45cb | 2017-03-16 19:58:26 -0700 | [diff] [blame] | 509 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 510 | run_art "${EXTRA_OPTIONS[@]}" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 511 | EXIT_STATUS=$? |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 512 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 513 | if [ "$PERF" != "" ]; then |
| 514 | if [ "$PERF" = report ]; then |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 515 | perf report -i $ANDROID_DATA/perf.data |
| 516 | fi |
| 517 | echo "Perf data saved in: $ANDROID_DATA/perf.data" |
| 518 | else |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 519 | # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used. |
| 520 | clean_android_data |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 521 | fi |
| 522 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 523 | exit $EXIT_STATUS |