blob: 58a815049e9baafbe8325bf3987c1d0b5b00dde2 [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 \
Roland Levillain01631342019-01-10 18:07:24 +0000202 ANDROID_RUNTIME_ROOT=$ANDROID_RUNTIME_ROOT \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100203 LD_LIBRARY_PATH=$LD_LIBRARY_PATH \
204 PATH=$ANDROID_ROOT/bin:$PATH \
205 LD_USE_LOAD_BIAS=1 \
206 ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS \
207 $DEX2OAT_BINARY_PATH \
208 --runtime-arg -Xnorelocate \
209 --boot-image=$DEX2OAT_BOOT_IMAGE \
210 --instruction-set=$ISA \
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100211 --class-loader-context="PCL[$class_loader_context]" \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100212 "${DEX2OAT_FLAGS[@]}" \
213 --dex-file=$dex_file \
214 --oat-file=$oat_file
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100215 if [[ -n $class_loader_context ]]; then
216 class_loader_context+=":"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100217 fi
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100218 class_loader_context+="$dex_file"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100219 done
220}
221
222# Extract the dex2oat flags from the list of arguments.
223# -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array
224# -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH
225# -Ximage argument is stored in DEX2OAT_BOOT_IMAGE
Vladimir Markobf68e572018-12-21 11:45:35 +0000226# -Xbootclasspath argument is stored in DEX2OAT_BCP
227# -Xbootclasspath-locations argument is stored in DEX2OAT_BCP_LOCS
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100228function 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 Geoffray686801f2018-08-26 16:00:53 +0100236 DEX2OAT_BOOT_IMAGE=$1
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100237 # Remove '-Ximage:' from the argument.
238 DEX2OAT_BOOT_IMAGE=${DEX2OAT_BOOT_IMAGE##-Ximage:}
239 ;;
Vladimir Markobf68e572018-12-21 11:45:35 +0000240 -Xbootclasspath:*)
241 DEX2OAT_BCP=$1
242 # Remove '-Xbootclasspath:' from the argument.
243 DEX2OAT_BCP=${DEX2OAT_BCP##-Xbootclasspath:}
244 ;;
245 -Xbootclasspath-locations:*)
246 DEX2OAT_BCP_LOCS=$1
247 # Remove '-Xbootclasspath-locations:' from the argument.
248 DEX2OAT_BCP_LOCS=${DEX2OAT_BCP_LOCS##-Xbootclasspath-locations:}
249 ;;
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100250 -cp)
Nicolas Geoffray686801f2018-08-26 16:00:53 +0100251 # Reset any previously parsed classpath, just like dalvikvm
252 # only supports one -cp argument.
253 DEX2OAT_CLASSPATH=()
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100254 # TODO: support -classpath and CLASSPATH
255 local oifs=$IFS
256 IFS=':'
257 for classpath_elem in $2
258 do
259 DEX2OAT_CLASSPATH+=("$classpath_elem")
260 done
261 shift
262 IFS=$oifs
263 ;;
264 esac
265 shift
266 done
267}
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100268
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000269# Runs dalvikvm, returns its exit code.
270# (Oat directories are cleaned up in between runs)
Orion Hodson9763f2e2017-03-28 08:27:23 +0100271function run_art() {
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000272 local ret
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700273
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000274 # Run dalvikvm.
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100275 verbose_run ANDROID_DATA="$ANDROID_DATA" \
276 ANDROID_ROOT="$ANDROID_ROOT" \
Neil Fuller26c43772018-11-23 17:56:43 +0000277 ANDROID_RUNTIME_ROOT="$ANDROID_RUNTIME_ROOT" \
Nicolas Geoffrayffda8b82017-10-06 13:48:08 +0100278 LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
279 PATH="$ANDROID_ROOT/bin:$PATH" \
280 LD_USE_LOAD_BIAS=1 \
281 ANDROID_LOG_TAGS="$ANDROID_LOG_TAGS" \
282 $LAUNCH_WRAPPER $ART_BINARY_PATH $lib \
283 -XXlib:"$LIBART" \
284 -Xnorelocate \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100285 -Ximage:"$DEFAULT_IMAGE_LOCATION" \
Orion Hodson9763f2e2017-03-28 08:27:23 +0100286 "$@"
Nicolas Geoffray162a5702017-08-04 09:28:32 +0000287 ret=$?
288
289 # Avoid polluting disk with 'oat' files after dalvikvm has finished.
290 cleanup_oat_directory_for_classpath "$@"
291
292 # Forward exit code of dalvikvm.
293 return $ret
Orion Hodson9763f2e2017-03-28 08:27:23 +0100294}
295
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100296######################################
297# Globals
298######################################
299ART_BINARY=dalvikvm
300DEX2OAT_BINARY=dex2oat
301DELETE_ANDROID_DATA="no"
302LAUNCH_WRAPPER=
303LIBART=libart.so
304JIT_PROFILE="no"
305ALLOW_DEFAULT_JDWP="no"
306VERBOSE="no"
307CLEAN_OAT_FILES="yes"
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100308RUN_DEX2OAT="yes"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100309EXTRA_OPTIONS=()
310DEX2OAT_FLAGS=()
311DEX2OAT_CLASSPATH=()
312
313# Parse arguments
Orion Hodson9763f2e2017-03-28 08:27:23 +0100314while [[ "$1" = "-"* ]]; do
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100315 case "$1" in
Orion Hodson9763f2e2017-03-28 08:27:23 +0100316 --)
317 # No more arguments for this script.
318 shift
319 break
320 ;;
321 --32)
322 ART_BINARY=dalvikvm32
323 ;;
324 --64)
325 ART_BINARY=dalvikvm64
326 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100327 -d)
328 ;& # Fallthrough
329 --debug)
330 LIBART="libartd.so"
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100331 DEX2OAT_BINARY=dex2oatd
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700332 # Expect that debug mode wants all checks.
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100333 EXTRA_OPTIONS+=(-XX:SlowDebug=true)
Orion Hodson9763f2e2017-03-28 08:27:23 +0100334 ;;
Alex Light84b92e02017-09-29 13:46:14 -0700335 --gdbserver)
336 LAUNCH_WRAPPER="gdbserver $2"
337 shift
338 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100339 --gdb)
340 LIBART="libartd.so"
341 LAUNCH_WRAPPER="gdb --args"
342 ;;
343 --help)
344 usage
345 exit 0
346 ;;
347 --invoke-with)
348 LAUNCH_WRAPPER=$2
349 shift
350 ;;
351 --perf)
352 PERF="record"
353 ;;
354 --perf-report)
355 PERF="report"
356 ;;
357 --profile)
358 JIT_PROFILE="yes"
359 ;;
360 --verbose)
361 VERBOSE="yes"
362 ;;
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100363 --no-clean)
364 CLEAN_OAT_FILES="no"
365 ;;
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100366 --no-compile)
367 CLEAN_OAT_FILES="no"
368 RUN_DEX2OAT="no"
369 ;;
Alex Lighta4817fb2018-06-12 10:56:35 -0700370 --allow-default-jdwp)
371 ALLOW_DEFAULT_JDWP="yes"
372 ;;
Orion Hodson9763f2e2017-03-28 08:27:23 +0100373 --*)
374 echo "unknown option: $1" 1>&2
375 usage
376 exit 1
377 ;;
378 *)
379 break
380 ;;
381 esac
382 shift
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +0100383done
384
Orion Hodson9763f2e2017-03-28 08:27:23 +0100385if [ $# -eq 0 ]; then
386 usage
387 exit 1
388fi
389
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100390# Follow all sym links to get the program name.
Nicolas Geoffray6b09b392018-08-29 13:29:01 +0100391if [[ -n "$BASH_SOURCE" ]]; then
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100392 PROG_NAME="$BASH_SOURCE"
393else
394 PROG_NAME="$0"
395fi
396while [ -h "$PROG_NAME" ]; do
397 # On Mac OS, readlink -f doesn't work.
398 PROG_NAME="$(readlink "$PROG_NAME")"
399done
400
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700401PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
Vladimir Markobf68e572018-12-21 11:45:35 +0000402ANDROID_ROOT="$(cd $PROG_DIR/..; pwd -P)"
Roland Levillain42807522019-01-15 12:49:36 +0000403
404# If ANDROID_RUNTIME_ROOT is not set, try to detect whether we are running on
405# target or host and set that environment variable to the usual default value.
406if [ -z "$ANDROID_RUNTIME_ROOT" ]; then
407 # This script is used on host and target (device). However, the (expected)
408 # default value `ANDROID_RUNTIME_ROOT` is not the same on host and target:
409 # - on host, `ANDROID_RUNTIME_ROOT` is expected to be "$ANDROID_ROOT/com.android.apex";
410 # - on target, `ANDROID_RUNTIME_ROOT` is expected to be "$ANDROID_ROOT/../apex/com.android.apex".
Roland Levillain01631342019-01-10 18:07:24 +0000411 #
Roland Levillain42807522019-01-15 12:49:36 +0000412 # We use the presence/absence of the `$ANDROID_ROOT/../apex` directory to
413 # determine whether we are on target or host (this is brittle, but simple).
414 if [ -d "$ANDROID_ROOT/../apex" ]; then
415 # Target case.
416 #
417 # We should be setting `ANDROID_RUNTIME_ROOT` to
418 # "$ANDROID_ROOT/../apex/com.android.runtime" here. However, the Runtime APEX
419 # is not (yet) supported by the ART Buildbot setup (see b/121117762); and yet
420 # ICU code depends on `ANDROID_RUNTIME_ROOT` to find ICU .dat files.
421 #
422 # As a temporary workaround, we:
423 # - make the ART Buildbot build script (art/tools/buildbot-build.sh) also
424 # generate the ICU .dat files in `/system/etc/icu` on device (these files
425 # are normally only put in the Runtime APEX on device);
426 # - set `ANDROID_RUNTIME_ROOT` to `$ANDROID_ROOT` (i.e. "/system") here.
427 #
428 # TODO(b/121117762): Set `ANDROID_RUNTIME_ROOT` to
429 # "$ANDROID_ROOT/../apex/com.android.runtime" when the Runtime APEX is fully
430 # supported on the ART Buildbot and Golem.
431 ANDROID_RUNTIME_ROOT=$ANDROID_ROOT
432 else
433 # Host case.
434 ANDROID_RUNTIME_ROOT="$ANDROID_ROOT/com.android.runtime"
435 fi
Roland Levillain01631342019-01-10 18:07:24 +0000436fi
437
Orion Hodson9763f2e2017-03-28 08:27:23 +0100438ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700439
Orion Hodson9763f2e2017-03-28 08:27:23 +0100440if [ ! -x "$ART_BINARY_PATH" ]; then
441 cat 1>&2 <<EOF
442Android Runtime not found: $ART_BINARY_PATH
443This script should be in the same directory as the Android Runtime ($ART_BINARY).
444EOF
445 exit 1
446fi
447
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100448DEX2OAT_BINARY_PATH=$ANDROID_ROOT/bin/$DEX2OAT_BINARY
449
450if [ ! -x "$DEX2OAT_BINARY_PATH" ]; then
451 echo "Warning: Android Compiler not found: $DEX2OAT_BINARY_PATH"
452fi
453
454######################################
455# Main program
456######################################
457
458# If android logging is not explicitly set, only print warnings and errors.
459if [ -z "$ANDROID_LOG_TAGS" ]; then
460 ANDROID_LOG_TAGS='*:w'
461fi
462
Orion Hodson9763f2e2017-03-28 08:27:23 +0100463LIBDIR="$(find_libdir $ART_BINARY_PATH)"
464LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100465DEFAULT_IMAGE_LOCATION="$(detect_boot_image_location)"
466DEX2OAT_BOOT_IMAGE="$DEFAULT_IMAGE_LOCATION"
Nicolas Geoffray810a1002018-08-28 17:40:49 +0100467ISA=$(LD_LIBRARY_PATH=$LD_LIBRARY_PATH $ART_BINARY_PATH -showversion | (read art version number isa && echo $isa))
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100468
469# Extract the dex2oat flags from the list of arguments.
470# -Xcompiler-options arguments are stored in DEX2OAT_FLAGS array
471# -cp argument is split by ':' and stored in DEX2OAT_CLASSPATH
Nicolas Geoffray70cbbe92019-01-14 09:08:16 +0000472# -Ximage argument is stored in DEX2OAT_BOOT_IMAGE
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100473extract_dex2oat_flags "$@"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100474
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000475# If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own,
476# and ensure we delete it at the end.
477if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then
Igor Murashkin7fef4eb2017-07-14 15:45:47 -0700478 if [[ $PWD != / ]]; then
479 ANDROID_DATA="$PWD/android-data$$"
480 else
481 # Use /data/local/tmp when running this from adb shell, since it starts out in /
482 # by default.
483 ANDROID_DATA="$ANDROID_DATA/local/tmp/android-data$$"
484 fi
Nicolas Geoffrayb487c572018-09-17 12:17:09 +0000485 mkdir -p "$ANDROID_DATA"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100486 DELETE_ANDROID_DATA="yes"
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000487fi
488
Vladimir Markobf68e572018-12-21 11:45:35 +0000489if [[ "$DEX2OAT_BCP" = "" && "$DEX2OAT_BCP_LOCS" != "" ]]; then
490 echo "Cannot use -Xbootclasspath-locations without -Xbootclasspath"
491 exit 1
492fi
493
Nicolas Geoffrayd41f64c2019-01-11 15:46:41 +0000494if [[ "$DEX2OAT_BOOT_IMAGE" = *core*.art && "$DEX2OAT_BCP" = "" ]]; then
Vladimir Markobf68e572018-12-21 11:45:35 +0000495 # Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
496 # because that's what we use for compiling the core.art image.
497 # It may contain additional modules from TEST_CORE_JARS.
Neil Fullerb4a70ce2018-11-09 15:49:05 +0000498 core_jars_list="core-oj core-libart okhttp bouncycastle apache-xml conscrypt"
Vladimir Markobf68e572018-12-21 11:45:35 +0000499 core_jars_suffix=
500 if [[ -e $ANDROID_ROOT/framework/core-oj-hostdex.jar ]]; then
501 core_jars_suffix=-hostdex
502 core_locations_dir=$ANDROID_ROOT/framework
503 prefix=$PWD/
504 if [[ ${core_locations_dir:0:${#prefix}} = $prefix ]]; then
505 core_locations_dir="${core_locations_dir##$prefix}"
506 fi
507 elif [[ -e $ANDROID_ROOT/framework/core-oj-testdex.jar ]]; then
508 core_jars_suffix=-testdex
509 core_locations_dir=/system/framework
510 fi
511 if [[ $core_jars_suffix != "" ]]; then
512 boot_separator=""
513 for boot_module in ${core_jars_list}; do
514 DEX_FILENAME="$boot_module$core_jars_suffix.jar"
515 DEX2OAT_BCP+="$boot_separator$ANDROID_ROOT/framework/${DEX_FILENAME}"
516 DEX2OAT_BCP_LOCS+="$boot_separator$core_locations_dir/${DEX_FILENAME}"
517 boot_separator=":"
518 done
519 if [ "$VERBOSE" = "yes" ]; then
520 echo "Using predefined -Xbootclasspath for image $DEX2OAT_BOOT_IMAGE:"
521 echo DEX2OAT_BOOT_IMAGE=$DEX2OAT_BOOT_IMAGE
522 echo DEX2OAT_BCP=$DEX2OAT_BCP
523 echo DEX2OAT_BCP_LOCS=$DEX2OAT_BCP_LOCS
524 fi
525 fi
526fi
527
528if [ "$DEX2OAT_BCP" != "" ]; then
529 EXTRA_OPTIONS+=("-Xbootclasspath:$DEX2OAT_BCP")
530 DEX2OAT_FLAGS+=("--runtime-arg" "-Xbootclasspath:$DEX2OAT_BCP")
531 if [ "$DEX2OAT_BCP_LOCS" != "" ]; then
532 EXTRA_OPTIONS+=("-Xbootclasspath-locations:$DEX2OAT_BCP_LOCS")
533 DEX2OAT_FLAGS+=("--runtime-arg" \
534 "-Xbootclasspath-locations:$DEX2OAT_BCP_LOCS")
535 fi
536fi
537
Orion Hodson9763f2e2017-03-28 08:27:23 +0100538if [ "$PERF" != "" ]; then
David Srbecky0dcb17f2018-08-13 12:41:47 +0100539 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 +0100540 DEX2OAT_FLAGS+=(--generate-debug-info)
Nicolas Geoffraye099a612014-12-12 13:52:00 +0000541fi
542
Alex Lighta4817fb2018-06-12 10:56:35 -0700543if [ "$ALLOW_DEFAULT_JDWP" = "no" ]; then
544 EXTRA_OPTIONS+=(-XjdwpProvider:none)
545fi
546
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100547# First cleanup any left-over 'oat' files from the last time dalvikvm was run.
548cleanup_oat_directory_for_classpath "$@"
549
550# Protect additional arguments in quotes to preserve whitespaces (used by
551# run-jdwp-test.sh when running on device), '$' (may be used as part of
552# classpath) and other special characters when evaluated.
553EXTRA_OPTIONS+=("$@")
554
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000555if [ "$JIT_PROFILE" = "yes" ]; then
556 # Create the profile. The runtime expects profiles to be created before
557 # execution.
558 PROFILE_PATH="$ANDROID_DATA/primary.prof"
Igor Murashkind54ac262017-07-26 11:16:23 -0700559 touch "$PROFILE_PATH"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000560
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000561 run_art -Xjitsaveprofilinginfo \
562 -Xps-min-methods-to-save:1 \
563 -Xps-min-classes-to-save:1 \
564 -Xps-min-notification-before-wake:10 \
565 -Xps-profile-path:$PROFILE_PATH \
566 -Xusejit:true \
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100567 ${EXTRA_OPTIONS[@]} \
Igor Murashkin11942442017-07-20 11:08:34 -0700568 &> "$ANDROID_DATA/profile_gen.log"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000569 EXIT_STATUS=$?
570
571 if [ $EXIT_STATUS != 0 ]; then
Igor Murashkind54ac262017-07-26 11:16:23 -0700572 echo "Profile run failed: " >&2
573 cat "$ANDROID_DATA/profile_gen.log" >&2
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000574 clean_android_data
575 exit $EXIT_STATUS
576 fi
577
Igor Murashkind54ac262017-07-26 11:16:23 -0700578 # Wipe dalvik-cache so that a subsequent run_art must regenerate it.
579 # Leave $ANDROID_DATA intact since it contains our profile file.
Nicolas Geoffrayb487c572018-09-17 12:17:09 +0000580 rm -rf "$ANDROID_DATA/dalvik-cache"
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000581
582 # Append arguments so next invocation of run_art uses the profile.
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100583 DEX2OAT_FLAGS+=(--profile-file="$PROFILE_PATH")
Nicolas Geoffray9d7baf42017-04-19 09:01:29 +0000584fi
585
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100586if [ -x "$DEX2OAT_BINARY_PATH" ]; then
Nicolas Geoffrayf983c732018-09-12 09:27:29 +0100587 if [ "$RUN_DEX2OAT" = "yes" ]; then
588 # Run dex2oat before launching ART to generate the oat files for the classpath.
589 run_dex2oat
590 fi
Nicolas Geoffray335c4ce2018-08-24 18:27:31 +0100591fi
592
593# Do not continue if the dex2oat failed.
594EXIT_STATUS=$?
595if [ $EXIT_STATUS != 0 ]; then
596 echo "Failed dex2oat invocation" >&2
597 exit $EXIT_STATUS
598fi
Calin Juravle64f45cb2017-03-16 19:58:26 -0700599
Vladimir Markoafd44ea2017-07-14 13:52:02 +0100600run_art "${EXTRA_OPTIONS[@]}"
Orion Hodson9763f2e2017-03-28 08:27:23 +0100601EXIT_STATUS=$?
Calin Juravleaa980612014-10-20 15:58:57 +0100602
Orion Hodson9763f2e2017-03-28 08:27:23 +0100603if [ "$PERF" != "" ]; then
604 if [ "$PERF" = report ]; then
Calin Juravleaa980612014-10-20 15:58:57 +0100605 perf report -i $ANDROID_DATA/perf.data
606 fi
607 echo "Perf data saved in: $ANDROID_DATA/perf.data"
608else
Orion Hodson9763f2e2017-03-28 08:27:23 +0100609 # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used.
610 clean_android_data
Calin Juravleaa980612014-10-20 15:58:57 +0100611fi
612
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000613exit $EXIT_STATUS