blob: 6e43863407d08bf08a3da946ba806fd52d954e8a [file] [log] [blame]
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001# 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 Geoffray70a998c2014-12-04 17:05:22 +000015# 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 Geoffray335c4ce2018-08-24 18:27:31 +010019######################################
20# Functions
21######################################
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010022function find_libdir() {
Orion Hodson9763f2e2017-03-28 08:27:23 +010023 # Get the actual file, $1 is the ART_BINARY_PATH and may be a symbolic link.
Nicolas Geoffray70a998c2014-12-04 17:05:22 +000024 # Use realpath instead of readlink because Android does not have a readlink.
Orion Hodson9763f2e2017-03-28 08:27:23 +010025 if [[ "$(realpath "$1")" == *dalvikvm64 ]]; then
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010026 echo "lib64"
27 else
28 echo "lib"
29 fi
30}
31
Orion Hodson9763f2e2017-03-28 08:27:23 +010032function usage() {
33 cat 1>&2 <<EOF
34Usage: art [OPTIONS] [--] [ART_OPTIONS] CLASS
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010035
Orion Hodson9763f2e2017-03-28 08:27:23 +010036Supported OPTIONS include:
37 --32 Use the 32-bit Android Runtime.
38 --64 Use the 64-bit Android Runtime.
Orion Hodson9763f2e2017-03-28 08:27:23 +010039 -d Use the debug ART library (libartd.so).
40 --debug Equivalent to -d.
41 --gdb Launch the Android Runtime in gdb.
Alex Light84b92e02017-09-29 13:46:14 -070042 --gdbserver <comms> Launch the Android Runtime in gdbserver using the
43 supplied communication channel.
Orion Hodson9763f2e2017-03-28 08:27:23 +010044 --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 Geoffrayc0c07852017-08-08 09:44:15 +010051 --no-clean Don't cleanup oat directories.
Nicolas Geoffrayf983c732018-09-12 09:27:29 +010052 --no-compile Don't invoke dex2oat before running.
Alex Lighta4817fb2018-06-12 10:56:35 -070053 --allow-default-jdwp Don't automatically put in -XjdwpProvider:none.
54 You probably do not want this.
Orion Hodson9763f2e2017-03-28 08:27:23 +010055
56The ART_OPTIONS are passed directly to the Android Runtime.
57
58Example:
59 art --32 -cp my_classes.dex MainClass
60
61Common 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
66EOF
67}
68
69function clean_android_data() {
70 if [ "$DELETE_ANDROID_DATA" = "yes" ]; then
Nicolas Geoffrayb487c572018-09-17 12:17:09 +000071 rm -rf $ANDROID_DATA
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010072 fi
Orion Hodson9763f2e2017-03-28 08:27:23 +010073}
74
Vladimir Markoafd44ea2017-07-14 13:52:02 +010075# 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 Hodson9763f2e2017-03-28 08:27:23 +010079function verbose_run() {
80 if [ "$VERBOSE" = "yes" ]; then
81 echo "$@"
82 fi
Vladimir Markoafd44ea2017-07-14 13:52:02 +010083
Nicolas Geoffrayb487c572018-09-17 12:17:09 +000084 env "$@"
Orion Hodson9763f2e2017-03-28 08:27:23 +010085}
86
Nicolas Geoffray162a5702017-08-04 09:28:32 +000087# Parse a colon-separated list into an array (e.g. "foo.dex:bar.dex" -> (foo.dex bar.dex))
88PARSE_CLASSPATH_RESULT=() # Return value will be here due to shell limitations.
89parse_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)
107find_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.
127cleanup_oat_directory() {
128 local classpath
129 classpath=("$@")
130
131 local dirpath
132
133 for path in "${classpath[@]}"; do
Nicolas Geoffrayb487c572018-09-17 12:17:09 +0000134 dirpath="$(dirname "$path")"
135 [[ -d "$dirpath" ]] && verbose_run rm -rf "$dirpath/oat"
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000136 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.
143cleanup_oat_directory_for_classpath() {
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100144 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 Geoffray162a5702017-08-04 09:28:32 +0000149
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100150 cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}"
151 fi
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000152}
153
Igor Murashkind54ac262017-07-26 11:16:23 -0700154# Attempt to find $ANDROID_ROOT/framework/<isa>/core.art' without knowing what <isa> is.
155function 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 Murashkin7fef4eb2017-07-14 15:45:47 -0700168# 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.
170function detect_boot_image_location() {
171 local image_location_dir="$ANDROID_ROOT/framework"
172 local image_location_name="core.art"
173
Igor Murashkind54ac262017-07-26 11:16:23 -0700174 # 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 Murashkin7fef4eb2017-07-14 15:45:47 -0700179 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 Geoffray335c4ce2018-08-24 18:27:31 +0100186function run_dex2oat() {
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100187 local class_loader_context=
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100188 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 Geoffrayb487c572018-09-17 12:17:09 +0000195 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 Geoffray335c4ce2018-08-24 18:27:31 +0100198 # 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 Geoffray6b09b392018-08-29 13:29:01 +0100210 --class-loader-context="PCL[$class_loader_context]" \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100211 "${DEX2OAT_FLAGS[@]}" \
212 --dex-file=$dex_file \
213 --oat-file=$oat_file
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100214 if [[ -n $class_loader_context ]]; then
215 class_loader_context+=":"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100216 fi
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100217 class_loader_context+="$dex_file"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100218 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 Markobf68e572018-12-21 11:45:35 +0000225# -Xbootclasspath argument is stored in DEX2OAT_BCP
226# -Xbootclasspath-locations argument is stored in DEX2OAT_BCP_LOCS
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100227function 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 Geoffray686801f2018-08-26 16:00:53 +0100235 DEX2OAT_BOOT_IMAGE=$1
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100236 # Remove '-Ximage:' from the argument.
237 DEX2OAT_BOOT_IMAGE=${DEX2OAT_BOOT_IMAGE##-Ximage:}
238 ;;
Vladimir Markobf68e572018-12-21 11:45:35 +0000239 -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 Geoffray335c4ce2018-08-24 18:27:31 +0100249 -cp)
Nicolas Geoffray686801f2018-08-26 16:00:53 +0100250 # Reset any previously parsed classpath, just like dalvikvm
251 # only supports one -cp argument.
252 DEX2OAT_CLASSPATH=()
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100253 # 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 Geoffrayffda8b82017-10-06 13:48:08 +0100267
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000268# Runs dalvikvm, returns its exit code.
269# (Oat directories are cleaned up in between runs)
Orion Hodson9763f2e2017-03-28 08:27:23 +0100270function run_art() {
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000271 local ret
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700272
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000273 # Run dalvikvm.
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100274 verbose_run ANDROID_DATA="$ANDROID_DATA" \
275 ANDROID_ROOT="$ANDROID_ROOT" \
Neil Fuller26c43772018-11-23 17:56:43 +0000276 ANDROID_RUNTIME_ROOT="$ANDROID_RUNTIME_ROOT" \
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100277 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 Geoffray335c4ce2018-08-24 18:27:31 +0100284 -Ximage:"$DEFAULT_IMAGE_LOCATION" \
Orion Hodson9763f2e2017-03-28 08:27:23 +0100285 "$@"
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000286 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 Hodson9763f2e2017-03-28 08:27:23 +0100293}
294
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100295######################################
296# Globals
297######################################
298ART_BINARY=dalvikvm
299DEX2OAT_BINARY=dex2oat
300DELETE_ANDROID_DATA="no"
301LAUNCH_WRAPPER=
302LIBART=libart.so
303JIT_PROFILE="no"
304ALLOW_DEFAULT_JDWP="no"
305VERBOSE="no"
306CLEAN_OAT_FILES="yes"
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100307RUN_DEX2OAT="yes"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100308EXTRA_OPTIONS=()
309DEX2OAT_FLAGS=()
310DEX2OAT_CLASSPATH=()
311
312# Parse arguments
Orion Hodson9763f2e2017-03-28 08:27:23 +0100313while [[ "$1" = "-"* ]]; do
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100314 case "$1" in
Orion Hodson9763f2e2017-03-28 08:27:23 +0100315 --)
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 Hodson9763f2e2017-03-28 08:27:23 +0100326 -d)
327 ;& # Fallthrough
328 --debug)
329 LIBART="libartd.so"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100330 DEX2OAT_BINARY=dex2oatd
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700331 # Expect that debug mode wants all checks.
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100332 EXTRA_OPTIONS+=(-XX:SlowDebug=true)
Orion Hodson9763f2e2017-03-28 08:27:23 +0100333 ;;
Alex Light84b92e02017-09-29 13:46:14 -0700334 --gdbserver)
335 LAUNCH_WRAPPER="gdbserver $2"
336 shift
337 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100338 --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 Geoffrayc0c07852017-08-08 09:44:15 +0100362 --no-clean)
363 CLEAN_OAT_FILES="no"
364 ;;
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100365 --no-compile)
366 CLEAN_OAT_FILES="no"
367 RUN_DEX2OAT="no"
368 ;;
Alex Lighta4817fb2018-06-12 10:56:35 -0700369 --allow-default-jdwp)
370 ALLOW_DEFAULT_JDWP="yes"
371 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100372 --*)
373 echo "unknown option: $1" 1>&2
374 usage
375 exit 1
376 ;;
377 *)
378 break
379 ;;
380 esac
381 shift
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +0100382done
383
Orion Hodson9763f2e2017-03-28 08:27:23 +0100384if [ $# -eq 0 ]; then
385 usage
386 exit 1
387fi
388
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100389# Follow all sym links to get the program name.
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100390if [[ -n "$BASH_SOURCE" ]]; then
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100391 PROG_NAME="$BASH_SOURCE"
392else
393 PROG_NAME="$0"
394fi
395while [ -h "$PROG_NAME" ]; do
396 # On Mac OS, readlink -f doesn't work.
397 PROG_NAME="$(readlink "$PROG_NAME")"
398done
399
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700400PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
Vladimir Markobf68e572018-12-21 11:45:35 +0000401ANDROID_ROOT="$(cd $PROG_DIR/..; pwd -P)"
Neil Fuller26c43772018-11-23 17:56:43 +0000402ANDROID_RUNTIME_ROOT=$ANDROID_ROOT/com.android.runtime
Orion Hodson9763f2e2017-03-28 08:27:23 +0100403ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700404
Orion Hodson9763f2e2017-03-28 08:27:23 +0100405if [ ! -x "$ART_BINARY_PATH" ]; then
406 cat 1>&2 <<EOF
407Android Runtime not found: $ART_BINARY_PATH
408This script should be in the same directory as the Android Runtime ($ART_BINARY).
409EOF
410 exit 1
411fi
412
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100413DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY
414
415if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then
416 echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH"
417fi
418
419######################################
420# Main program
421######################################
422
423# If android logging is not explicitly set, only print warnings and errors.
424if [ -z "$ANDROID_LOG_TAGS" ]; then
425 ANDROID_LOG_TAGS='*:w'
426fi
427
Orion Hodson9763f2e2017-03-28 08:27:23 +0100428LIBDIR="$(find_libdir $ART_BINARY_PATH)"
429LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100430DEFAULT_IMAGE_LOCATION="$(detect_boot_image_location)"
431DEX2OAT_BOOT_IMAGE="$DEFAULT_IMAGE_LOCATION"
Nicolas Geoffray810a1002018-08-28 17:40:49 +0100432ISA=$(LD_LIBRARY_PATH=$LD_LIBRARY_PATH $ART_BINARY_PATH -showversion | (read art version number isa && echo $isa))
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100433
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
438extract_dex2oat_flags "$@"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100439
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000440# If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own,
441# and ensure we delete it at the end.
442if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700443 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 Geoffrayb487c572018-09-17 12:17:09 +0000450 mkdir -p "$ANDROID_DATA"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100451 DELETE_ANDROID_DATA="yes"
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000452fi
453
Vladimir Markobf68e572018-12-21 11:45:35 +0000454if [[ "$DEX2OAT_BCP" = "" && "$DEX2OAT_BCP_LOCS" != "" ]]; then
455 echo "Cannot use -Xbootclasspath-locations without -Xbootclasspath"
456 exit 1
457fi
458
459if [[ "$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
491fi
492
493if [ "$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
501fi
502
Orion Hodson9763f2e2017-03-28 08:27:23 +0100503if [ "$PERF" != "" ]; then
David Srbecky0dcb17f2018-08-13 12:41:47 +0100504 LAUNCH_WRAPPER="perf record -g --call-graph dwarf -F 10000 -o $ANDROID_DATA/perf.data -e cycles:u $LAUNCH_WRAPPER"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100505 DEX2OAT_FLAGS+=(--generate-debug-info)
Nicolas Geoffraye099a612014-12-12 13:52:00 +0000506fi
507
Alex Lighta4817fb2018-06-12 10:56:35 -0700508if [ "$ALLOW_DEFAULT_JDWP" = "no" ]; then
509 EXTRA_OPTIONS+=(-XjdwpProvider:none)
510fi
511
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100512# First cleanup any left-over 'oat' files from the last time dalvikvm was run.
513cleanup_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.
518EXTRA_OPTIONS+=("$@")
519
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000520if [ "$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 Murashkind54ac262017-07-26 11:16:23 -0700524 touch "$PROFILE_PATH"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000525
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000526 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 Geoffray335c4ce2018-08-24 18:27:31 +0100532 ${EXTRA_OPTIONS[@]} \
Igor Murashkin11942442017-07-20 11:08:34 -0700533 &> "$ANDROID_DATA/profile_gen.log"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000534 EXIT_STATUS=$?
535
536 if [ $EXIT_STATUS != 0 ]; then
Igor Murashkind54ac262017-07-26 11:16:23 -0700537 echo "Profile run failed: " >&2
538 cat "$ANDROID_DATA/profile_gen.log" >&2
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000539 clean_android_data
540 exit $EXIT_STATUS
541 fi
542
Igor Murashkind54ac262017-07-26 11:16:23 -0700543 # Wipe dalvik-cache so that a subsequent run_art must regenerate it.
544 # Leave $ANDROID_DATA intact since it contains our profile file.
Nicolas Geoffrayb487c572018-09-17 12:17:09 +0000545 rm -rf "$ANDROID_DATA/dalvik-cache"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000546
547 # Append arguments so next invocation of run_art uses the profile.
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100548 DEX2OAT_FLAGS+=(--profile-file="$PROFILE_PATH")
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000549fi
550
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100551if [ -x "$DEX2OAT_BINARY_PATH" ]; then
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100552 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 Geoffray335c4ce2018-08-24 18:27:31 +0100556fi
557
558# Do not continue if the dex2oat failed.
559EXIT_STATUS=$?
560if [ $EXIT_STATUS != 0 ]; then
561 echo "Failed dex2oat invocation" >&2
562 exit $EXIT_STATUS
563fi
Calin Juravle64f45cb2017-03-16 19:58:26 -0700564
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100565run_art "${EXTRA_OPTIONS[@]}"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100566EXIT_STATUS=$?
Calin Juravleaa980612014-10-20 15:58:57 +0100567
Orion Hodson9763f2e2017-03-28 08:27:23 +0100568if [ "$PERF" != "" ]; then
569 if [ "$PERF" = report ]; then
Calin Juravleaa980612014-10-20 15:58:57 +0100570 perf report -i $ANDROID_DATA/perf.data
571 fi
572 echo "Perf data saved in: $ANDROID_DATA/perf.data"
573else
Orion Hodson9763f2e2017-03-28 08:27:23 +0100574 # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used.
575 clean_android_data
Calin Juravleaa980612014-10-20 15:58:57 +0100576fi
577
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000578exit $EXIT_STATUS