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