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