Merge "Move art::Runtime::InitZygote logic from art into frameworks/base."
diff --git a/Android.bp b/Android.bp
index f7e909d..b9f1db5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -20,6 +20,7 @@
subdirs = [
"benchmark",
"build",
+ "cmdline",
"compiler",
"dalvikvm",
"dex2oat",
@@ -33,6 +34,7 @@
"profman",
"runtime",
"sigchainlib",
+ "test",
"tools/cpp-define-generator",
"tools/dmtracedump",
]
diff --git a/Android.mk b/Android.mk
index d43118c..a1479e1 100644
--- a/Android.mk
+++ b/Android.mk
@@ -434,6 +434,16 @@
build-art-target: $(TARGET_OUT_EXECUTABLES)/art $(ART_TARGET_DEPENDENCIES) $(TARGET_CORE_IMG_OUTS)
########################################################################
+# Phony target for only building what go/lem requires on target.
+.PHONY: build-art-target-golem
+build-art-target-golem: dex2oat dalvikvm patchoat linker \
+ $(TARGET_OUT)/etc/public.libraries.txt \
+ $(ART_TARGET_DEX_DEPENDENCIES) \
+ $(ART_TARGET_SHARED_LIBRARY_DEPENDENCIES) \
+ $(TARGET_CORE_IMG_OUT_BASE).art \
+ $(TARGET_CORE_IMG_OUT_BASE)-interpreter.art
+
+########################################################################
# Rules for building all dependencies for tests.
.PHONY: build-art-host-tests
diff --git a/build/Android.common_test.mk b/build/Android.common_test.mk
index 93e310e..6b7dc09 100644
--- a/build/Android.common_test.mk
+++ b/build/Android.common_test.mk
@@ -60,8 +60,8 @@
# Do you want to test the optimizing compiler with graph coloring register allocation?
ART_TEST_OPTIMIZING_GRAPH_COLOR ?= $(ART_TEST_FULL)
-# Do we want to test a PIC-compiled core image?
-ART_TEST_PIC_IMAGE ?= $(ART_TEST_FULL)
+# Do we want to test a non-PIC-compiled core image?
+ART_TEST_NPIC_IMAGE ?= $(ART_TEST_FULL)
# Do we want to test PIC-compiled tests ("apps")?
ART_TEST_PIC_TEST ?= $(ART_TEST_FULL)
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 76ee06e..b3836f3 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -65,6 +65,16 @@
cp $< $@
$(call dexpreopt-remove-classes.dex,$@)
+ART_TEST_GTEST_VerifierDeps_SRC := $(abspath $(wildcard $(LOCAL_PATH)/VerifierDeps/*.smali))
+ART_TEST_HOST_GTEST_VerifierDeps_DEX := $(dir $(ART_TEST_HOST_GTEST_Main_DEX))$(subst Main,VerifierDeps,$(basename $(notdir $(ART_TEST_HOST_GTEST_Main_DEX))))$(suffix $(ART_TEST_HOST_GTEST_Main_DEX))
+ART_TEST_TARGET_GTEST_VerifierDeps_DEX := $(dir $(ART_TEST_TARGET_GTEST_Main_DEX))$(subst Main,VerifierDeps,$(basename $(notdir $(ART_TEST_TARGET_GTEST_Main_DEX))))$(suffix $(ART_TEST_TARGET_GTEST_Main_DEX))
+
+$(ART_TEST_HOST_GTEST_VerifierDeps_DEX): $(ART_TEST_GTEST_VerifierDeps_SRC) $(HOST_OUT_EXECUTABLES)/smali
+ $(HOST_OUT_EXECUTABLES)/smali --output=$@ $(filter %.smali,$^)
+
+$(ART_TEST_TARGET_GTEST_VerifierDeps_DEX): $(ART_TEST_GTEST_VerifierDeps_SRC) $(HOST_OUT_EXECUTABLES)/smali
+ $(HOST_OUT_EXECUTABLES)/smali --output=$@ $(filter %.smali,$^)
+
# Dex file dependencies for each gtest.
ART_GTEST_dex2oat_environment_tests_DEX_DEPS := Main MainStripped MultiDex MultiDexModifiedSecondary Nested
@@ -88,18 +98,19 @@
ART_GTEST_stub_test_DEX_DEPS := AllFields
ART_GTEST_transaction_test_DEX_DEPS := Transaction
ART_GTEST_type_lookup_table_test_DEX_DEPS := Lookup
+ART_GTEST_verifier_deps_test_DEX_DEPS := VerifierDeps
# The elf writer test has dependencies on core.oat.
-ART_GTEST_elf_writer_test_HOST_DEPS := $(HOST_CORE_IMAGE_default_no-pic_64) $(HOST_CORE_IMAGE_default_no-pic_32)
-ART_GTEST_elf_writer_test_TARGET_DEPS := $(TARGET_CORE_IMAGE_default_no-pic_64) $(TARGET_CORE_IMAGE_default_no-pic_32)
+ART_GTEST_elf_writer_test_HOST_DEPS := $(HOST_CORE_IMAGE_optimizing_no-pic_64) $(HOST_CORE_IMAGE_optimizing_no-pic_32)
+ART_GTEST_elf_writer_test_TARGET_DEPS := $(TARGET_CORE_IMAGE_optimizing_no-pic_64) $(TARGET_CORE_IMAGE_optimizing_no-pic_32)
ART_GTEST_dex2oat_environment_tests_HOST_DEPS := \
- $(HOST_CORE_IMAGE_default_no-pic_64) \
- $(HOST_CORE_IMAGE_default_no-pic_32) \
+ $(HOST_CORE_IMAGE_optimizing_pic_64) \
+ $(HOST_CORE_IMAGE_optimizing_pic_32) \
$(HOST_OUT_EXECUTABLES)/patchoatd
ART_GTEST_dex2oat_environment_tests_TARGET_DEPS := \
- $(TARGET_CORE_IMAGE_default_no-pic_64) \
- $(TARGET_CORE_IMAGE_default_no-pic_32) \
+ $(TARGET_CORE_IMAGE_optimizing_pic_64) \
+ $(TARGET_CORE_IMAGE_optimizing_pic_32) \
$(TARGET_OUT_EXECUTABLES)/patchoatd
ART_GTEST_oat_file_assistant_test_HOST_DEPS := \
@@ -114,62 +125,62 @@
$(ART_GTEST_dex2oat_environment_tests_TARGET_DEPS)
# TODO: document why this is needed.
-ART_GTEST_proxy_test_HOST_DEPS := $(HOST_CORE_IMAGE_default_no-pic_64) $(HOST_CORE_IMAGE_default_no-pic_32)
+ART_GTEST_proxy_test_HOST_DEPS := $(HOST_CORE_IMAGE_optimizing_no-pic_64) $(HOST_CORE_IMAGE_optimizing_no-pic_32)
# The dexdump test requires an image and the dexdump utility.
# TODO: rename into dexdump when migration completes
ART_GTEST_dexdump_test_HOST_DEPS := \
- $(HOST_CORE_IMAGE_default_no-pic_64) \
- $(HOST_CORE_IMAGE_default_no-pic_32) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_64) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_32) \
$(HOST_OUT_EXECUTABLES)/dexdump2
ART_GTEST_dexdump_test_TARGET_DEPS := \
- $(TARGET_CORE_IMAGE_default_no-pic_64) \
- $(TARGET_CORE_IMAGE_default_no-pic_32) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_64) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_32) \
dexdump2
# The dexlayout test requires an image and the dexlayout utility.
# TODO: rename into dexdump when migration completes
ART_GTEST_dexlayout_test_HOST_DEPS := \
- $(HOST_CORE_IMAGE_default_no-pic_64) \
- $(HOST_CORE_IMAGE_default_no-pic_32) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_64) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_32) \
$(HOST_OUT_EXECUTABLES)/dexlayout \
$(HOST_OUT_EXECUTABLES)/dexdump2
ART_GTEST_dexlayout_test_TARGET_DEPS := \
- $(TARGET_CORE_IMAGE_default_no-pic_64) \
- $(TARGET_CORE_IMAGE_default_no-pic_32) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_64) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_32) \
dexlayout \
dexdump2
# The dexlist test requires an image and the dexlist utility.
ART_GTEST_dexlist_test_HOST_DEPS := \
- $(HOST_CORE_IMAGE_default_no-pic_64) \
- $(HOST_CORE_IMAGE_default_no-pic_32) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_64) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_32) \
$(HOST_OUT_EXECUTABLES)/dexlist
ART_GTEST_dexlist_test_TARGET_DEPS := \
- $(TARGET_CORE_IMAGE_default_no-pic_64) \
- $(TARGET_CORE_IMAGE_default_no-pic_32) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_64) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_32) \
dexlist
# The imgdiag test has dependencies on core.oat since it needs to load it during the test.
# For the host, also add the installed tool (in the base size, that should suffice). For the
# target, just the module is fine, the sync will happen late enough.
ART_GTEST_imgdiag_test_HOST_DEPS := \
- $(HOST_CORE_IMAGE_default_no-pic_64) \
- $(HOST_CORE_IMAGE_default_no-pic_32) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_64) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_32) \
$(HOST_OUT_EXECUTABLES)/imgdiagd
ART_GTEST_imgdiag_test_TARGET_DEPS := \
- $(TARGET_CORE_IMAGE_default_no-pic_64) \
- $(TARGET_CORE_IMAGE_default_no-pic_32) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_64) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_32) \
imgdiagd
# Oatdump test requires an image and oatfile to dump.
ART_GTEST_oatdump_test_HOST_DEPS := \
- $(HOST_CORE_IMAGE_default_no-pic_64) \
- $(HOST_CORE_IMAGE_default_no-pic_32) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_64) \
+ $(HOST_CORE_IMAGE_optimizing_no-pic_32) \
$(HOST_OUT_EXECUTABLES)/oatdumpd
ART_GTEST_oatdump_test_TARGET_DEPS := \
- $(TARGET_CORE_IMAGE_default_no-pic_64) \
- $(TARGET_CORE_IMAGE_default_no-pic_32) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_64) \
+ $(TARGET_CORE_IMAGE_optimizing_no-pic_32) \
oatdump
# Profile assistant tests requires profman utility.
@@ -181,275 +192,28 @@
# The path for which all the source files are relative, not actually the current directory.
LOCAL_PATH := art
-RUNTIME_GTEST_COMMON_SRC_FILES := \
- cmdline/cmdline_parser_test.cc \
- dexdump/dexdump_test.cc \
- dexlayout/dexlayout_test.cc \
- dexlist/dexlist_test.cc \
- dex2oat/dex2oat_test.cc \
- imgdiag/imgdiag_test.cc \
- oatdump/oatdump_test.cc \
- profman/profile_assistant_test.cc \
- runtime/arch/arch_test.cc \
- runtime/arch/instruction_set_test.cc \
- runtime/arch/instruction_set_features_test.cc \
- runtime/arch/memcmp16_test.cc \
- runtime/arch/stub_test.cc \
- runtime/arch/arm/instruction_set_features_arm_test.cc \
- runtime/arch/arm64/instruction_set_features_arm64_test.cc \
- runtime/arch/mips/instruction_set_features_mips_test.cc \
- runtime/arch/mips64/instruction_set_features_mips64_test.cc \
- runtime/arch/x86/instruction_set_features_x86_test.cc \
- runtime/arch/x86_64/instruction_set_features_x86_64_test.cc \
- runtime/barrier_test.cc \
- runtime/base/arena_allocator_test.cc \
- runtime/base/bit_field_test.cc \
- runtime/base/bit_utils_test.cc \
- runtime/base/bit_vector_test.cc \
- runtime/base/hash_set_test.cc \
- runtime/base/hex_dump_test.cc \
- runtime/base/histogram_test.cc \
- runtime/base/mutex_test.cc \
- runtime/base/scoped_flock_test.cc \
- runtime/base/stringprintf_test.cc \
- runtime/base/time_utils_test.cc \
- runtime/base/timing_logger_test.cc \
- runtime/base/variant_map_test.cc \
- runtime/base/unix_file/fd_file_test.cc \
- runtime/class_linker_test.cc \
- runtime/compiler_filter_test.cc \
- runtime/dex_file_test.cc \
- runtime/dex_file_verifier_test.cc \
- runtime/dex_instruction_test.cc \
- runtime/dex_instruction_visitor_test.cc \
- runtime/dex_method_iterator_test.cc \
- runtime/entrypoints/math_entrypoints_test.cc \
- runtime/entrypoints/quick/quick_trampoline_entrypoints_test.cc \
- runtime/entrypoints_order_test.cc \
- runtime/gc/accounting/card_table_test.cc \
- runtime/gc/accounting/mod_union_table_test.cc \
- runtime/gc/accounting/space_bitmap_test.cc \
- runtime/gc/collector/immune_spaces_test.cc \
- runtime/gc/heap_test.cc \
- runtime/gc/reference_queue_test.cc \
- runtime/gc/space/dlmalloc_space_static_test.cc \
- runtime/gc/space/dlmalloc_space_random_test.cc \
- runtime/gc/space/large_object_space_test.cc \
- runtime/gc/space/rosalloc_space_static_test.cc \
- runtime/gc/space/rosalloc_space_random_test.cc \
- runtime/gc/space/space_create_test.cc \
- runtime/gc/system_weak_test.cc \
- runtime/gc/task_processor_test.cc \
- runtime/gtest_test.cc \
- runtime/handle_scope_test.cc \
- runtime/indenter_test.cc \
- runtime/indirect_reference_table_test.cc \
- runtime/instrumentation_test.cc \
- runtime/intern_table_test.cc \
- runtime/interpreter/safe_math_test.cc \
- runtime/interpreter/unstarted_runtime_test.cc \
- runtime/java_vm_ext_test.cc \
- runtime/jit/profile_compilation_info_test.cc \
- runtime/leb128_test.cc \
- runtime/mem_map_test.cc \
- runtime/memory_region_test.cc \
- runtime/mirror/dex_cache_test.cc \
- runtime/mirror/object_test.cc \
- runtime/monitor_pool_test.cc \
- runtime/monitor_test.cc \
- runtime/oat_file_test.cc \
- runtime/oat_file_assistant_test.cc \
- runtime/parsed_options_test.cc \
- runtime/prebuilt_tools_test.cc \
- runtime/reference_table_test.cc \
- runtime/thread_pool_test.cc \
- runtime/transaction_test.cc \
- runtime/type_lookup_table_test.cc \
- runtime/utf_test.cc \
- runtime/utils_test.cc \
- runtime/verifier/method_verifier_test.cc \
- runtime/verifier/reg_type_test.cc \
- runtime/zip_archive_test.cc
+ART_TEST_MODULES := \
+ art_cmdline_tests \
+ art_compiler_tests \
+ art_compiler_host_tests \
+ art_dex2oat_tests \
+ art_dexdump_tests \
+ art_dexlayout_tests \
+ art_dexlist_tests \
+ art_imgdiag_tests \
+ art_oatdump_tests \
+ art_profman_tests \
+ art_runtime_tests \
+ art_runtime_compiler_tests \
-COMPILER_GTEST_COMMON_SRC_FILES := \
- runtime/jni_internal_test.cc \
- runtime/proxy_test.cc \
- runtime/reflection_test.cc \
- compiler/compiled_method_test.cc \
- compiler/debug/dwarf/dwarf_test.cc \
- compiler/driver/compiled_method_storage_test.cc \
- compiler/driver/compiler_driver_test.cc \
- compiler/elf_writer_test.cc \
- compiler/exception_test.cc \
- compiler/image_test.cc \
- compiler/jni/jni_compiler_test.cc \
- compiler/linker/multi_oat_relative_patcher_test.cc \
- compiler/linker/output_stream_test.cc \
- compiler/oat_test.cc \
- compiler/optimizing/bounds_check_elimination_test.cc \
- compiler/optimizing/dominator_test.cc \
- compiler/optimizing/find_loops_test.cc \
- compiler/optimizing/graph_checker_test.cc \
- compiler/optimizing/graph_test.cc \
- compiler/optimizing/gvn_test.cc \
- compiler/optimizing/induction_var_analysis_test.cc \
- compiler/optimizing/induction_var_range_test.cc \
- compiler/optimizing/licm_test.cc \
- compiler/optimizing/live_interval_test.cc \
- compiler/optimizing/nodes_test.cc \
- compiler/optimizing/parallel_move_test.cc \
- compiler/optimizing/pretty_printer_test.cc \
- compiler/optimizing/reference_type_propagation_test.cc \
- compiler/optimizing/side_effects_test.cc \
- compiler/optimizing/ssa_test.cc \
- compiler/optimizing/stack_map_test.cc \
- compiler/optimizing/suspend_check_test.cc \
- compiler/utils/dedupe_set_test.cc \
- compiler/utils/intrusive_forward_list_test.cc \
- compiler/utils/string_reference_test.cc \
- compiler/utils/swap_space_test.cc \
- compiler/utils/test_dex_file_builder_test.cc \
- compiler/utils/transform_array_ref_test.cc \
- compiler/utils/transform_iterator_test.cc \
+ART_TARGET_GTEST_FILES := $(foreach m,$(ART_TEST_MODULES),\
+ $(ART_TEST_LIST_device_$(TARGET_ARCH)_$(m)))
-COMPILER_GTEST_COMMON_SRC_FILES_all := \
- compiler/jni/jni_cfi_test.cc \
- compiler/optimizing/codegen_test.cc \
- compiler/optimizing/optimizing_cfi_test.cc \
-
-COMPILER_GTEST_COMMON_SRC_FILES_arm := \
- compiler/linker/arm/relative_patcher_thumb2_test.cc \
- compiler/utils/arm/managed_register_arm_test.cc \
-
-COMPILER_GTEST_COMMON_SRC_FILES_arm64 := \
- compiler/linker/arm64/relative_patcher_arm64_test.cc \
- compiler/utils/arm64/managed_register_arm64_test.cc \
-
-COMPILER_GTEST_COMMON_SRC_FILES_mips := \
- compiler/linker/mips/relative_patcher_mips_test.cc \
- compiler/linker/mips/relative_patcher_mips32r6_test.cc \
-
-COMPILER_GTEST_COMMON_SRC_FILES_mips64 := \
-
-COMPILER_GTEST_COMMON_SRC_FILES_x86 := \
- compiler/linker/x86/relative_patcher_x86_test.cc \
- compiler/utils/x86/managed_register_x86_test.cc \
-
-# These tests are testing architecture-independent functionality, but happen
-# to use x86 codegen as part of the test.
-COMPILER_GTEST_COMMON_SRC_FILES_x86 += \
- compiler/optimizing/constant_folding_test.cc \
- compiler/optimizing/dead_code_elimination_test.cc \
- compiler/optimizing/linearize_test.cc \
- compiler/optimizing/live_ranges_test.cc \
- compiler/optimizing/liveness_test.cc \
- compiler/optimizing/register_allocator_test.cc \
-
-COMPILER_GTEST_COMMON_SRC_FILES_x86_64 := \
- compiler/linker/x86_64/relative_patcher_x86_64_test.cc \
-
-RUNTIME_GTEST_TARGET_SRC_FILES := \
- $(RUNTIME_GTEST_COMMON_SRC_FILES)
-
-RUNTIME_GTEST_HOST_SRC_FILES := \
- $(RUNTIME_GTEST_COMMON_SRC_FILES)
-
-COMPILER_GTEST_TARGET_SRC_FILES := \
- $(COMPILER_GTEST_COMMON_SRC_FILES)
-
-COMPILER_GTEST_TARGET_SRC_FILES_all := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_all) \
-
-COMPILER_GTEST_TARGET_SRC_FILES_arm := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_arm) \
-
-COMPILER_GTEST_TARGET_SRC_FILES_arm64 := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_arm64) \
-
-COMPILER_GTEST_TARGET_SRC_FILES_mips := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_mips) \
-
-COMPILER_GTEST_TARGET_SRC_FILES_mips64 := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_mips64) \
-
-COMPILER_GTEST_TARGET_SRC_FILES_x86 := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_x86) \
-
-COMPILER_GTEST_TARGET_SRC_FILES_x86_64 := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_x86_64) \
-
-$(foreach arch,$(ART_TARGET_CODEGEN_ARCHS),$(eval COMPILER_GTEST_TARGET_SRC_FILES += $$(COMPILER_GTEST_TARGET_SRC_FILES_$(arch))))
-COMPILER_GTEST_TARGET_SRC_FILES += $(COMPILER_GTEST_TARGET_SRC_FILES_all)
-
-COMPILER_GTEST_HOST_SRC_FILES := \
- $(COMPILER_GTEST_COMMON_SRC_FILES) \
-
-COMPILER_GTEST_HOST_SRC_FILES_all := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_all) \
-
-COMPILER_GTEST_HOST_SRC_FILES_arm := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_arm) \
- compiler/utils/arm/assembler_thumb2_test.cc \
- compiler/utils/assembler_thumb_test.cc \
-
-COMPILER_GTEST_HOST_SRC_FILES_arm64 := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_arm64) \
-
-COMPILER_GTEST_HOST_SRC_FILES_mips := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_mips) \
- compiler/utils/mips/assembler_mips_test.cc \
- compiler/utils/mips/assembler_mips32r6_test.cc \
-
-COMPILER_GTEST_HOST_SRC_FILES_mips64 := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_mips64) \
- compiler/utils/mips64/assembler_mips64_test.cc \
-
-COMPILER_GTEST_HOST_SRC_FILES_x86 := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_x86) \
- compiler/utils/x86/assembler_x86_test.cc \
-
-COMPILER_GTEST_HOST_SRC_FILES_x86_64 := \
- $(COMPILER_GTEST_COMMON_SRC_FILES_x86_64) \
- compiler/utils/x86_64/assembler_x86_64_test.cc
-
-$(foreach arch,$(ART_HOST_CODEGEN_ARCHS),$(eval COMPILER_GTEST_HOST_SRC_FILES += $$(COMPILER_GTEST_HOST_SRC_FILES_$(arch))))
-COMPILER_GTEST_HOST_SRC_FILES += $(COMPILER_GTEST_HOST_SRC_FILES_all)
+ART_HOST_GTEST_FILES := $(foreach m,$(ART_TEST_MODULES),\
+ $(ART_TEST_LIST_host_$(ART_HOST_ARCH)_$(m)))
ART_TEST_CFLAGS :=
-include $(CLEAR_VARS)
-LOCAL_MODULE := libart-gtest
-LOCAL_MODULE_TAGS := optional
-LOCAL_CPP_EXTENSION := cc
-LOCAL_SRC_FILES := runtime/common_runtime_test.cc compiler/common_compiler_test.cc
-LOCAL_C_INCLUDES := $(ART_C_INCLUDES) art/runtime art/cmdline art/compiler
-LOCAL_SHARED_LIBRARIES := libartd libartd-compiler libdl
-LOCAL_WHOLE_STATIC_LIBRARIES += libgtest
-LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_build.mk
-LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.gtest.mk
-$(eval LOCAL_CLANG := $(ART_TARGET_CLANG))
-$(eval $(call set-target-local-cflags-vars,debug))
-LOCAL_CFLAGS += -Wno-used-but-marked-unused -Wno-deprecated -Wno-missing-noreturn # gtest issue
-include $(BUILD_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libart-gtest
-LOCAL_MODULE_TAGS := optional
-LOCAL_CPP_EXTENSION := cc
-LOCAL_CFLAGS := $(ART_HOST_CFLAGS)
-LOCAL_ASFLAGS := $(ART_HOST_ASFLAGS)
-LOCAL_SRC_FILES := runtime/common_runtime_test.cc compiler/common_compiler_test.cc
-LOCAL_C_INCLUDES := $(ART_C_INCLUDES) art/runtime art/cmdline art/compiler
-LOCAL_SHARED_LIBRARIES := libartd libartd-compiler
-LOCAL_WHOLE_STATIC_LIBRARIES := libgtest
-LOCAL_LDLIBS += -ldl -lpthread
-LOCAL_MULTILIB := both
-LOCAL_CLANG := $(ART_HOST_CLANG)
-LOCAL_CFLAGS += -Wno-used-but-marked-unused -Wno-deprecated -Wno-missing-noreturn # gtest issue
-LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_build.mk
-LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.gtest.mk
-include $(BUILD_HOST_SHARED_LIBRARY)
-
# Variables holding collections of gtest pre-requisits used to run a number of gtests.
ART_TEST_HOST_GTEST$(ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
ART_TEST_HOST_GTEST$(2ND_ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
@@ -494,63 +258,70 @@
# Define a make rule for a target device gtest.
# $(1): gtest name - the name of the test we're building such as leb128_test.
-# $(2): 2ND_ or undefined - used to differentiate between the primary and secondary architecture.
-# $(3): LD_LIBRARY_PATH or undefined - used in case libartd.so is not in /system/lib/
+# $(2): path relative to $OUT to the test binary
+# $(3): 2ND_ or undefined - used to differentiate between the primary and secondary architecture.
+# $(4): LD_LIBRARY_PATH or undefined - used in case libartd.so is not in /system/lib/
define define-art-gtest-rule-target
- gtest_rule := test-art-target-gtest-$(1)$$($(2)ART_PHONY_TEST_TARGET_SUFFIX)
+ gtest_rule := test-art-target-gtest-$(1)$$($(3)ART_PHONY_TEST_TARGET_SUFFIX)
+ gtest_exe := $(OUT_DIR)/$(2)
+ gtest_target_exe := $$(patsubst $(PRODUCT_OUT)/%,/%,$$(gtest_exe))
# Add the test dependencies to test-art-target-sync, which will be a prerequisite for the test
# to ensure files are pushed to the device.
TEST_ART_TARGET_SYNC_DEPS += \
$$(ART_GTEST_$(1)_TARGET_DEPS) \
$(foreach file,$(ART_GTEST_$(1)_DEX_DEPS),$(ART_TEST_TARGET_GTEST_$(file)_DEX)) \
- $$(ART_TARGET_NATIVETEST_OUT)/$$(TARGET_$(2)ARCH)/$(1) \
- $$($(2)TARGET_OUT_SHARED_LIBRARIES)/libjavacore.so \
- $$($(2)TARGET_OUT_SHARED_LIBRARIES)/libopenjdkd.so \
+ $$(gtest_exe) \
+ $$($(3)TARGET_OUT_SHARED_LIBRARIES)/libjavacore.so \
+ $$($(3)TARGET_OUT_SHARED_LIBRARIES)/libopenjdkd.so \
$$(TARGET_OUT_JAVA_LIBRARIES)/core-libart-testdex.jar \
$$(TARGET_OUT_JAVA_LIBRARIES)/core-oj-testdex.jar \
$$(ART_TARGET_TEST_OUT)/valgrind-target-suppressions.txt
+$$(gtest_rule) valgrind-$$(gtest_rule): PRIVATE_TARGET_EXE := $$(gtest_target_exe)
+
.PHONY: $$(gtest_rule)
$$(gtest_rule): test-art-target-sync
- $(hide) adb shell touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID
- $(hide) adb shell rm $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID
- $(hide) adb shell chmod 755 $(ART_TARGET_NATIVETEST_DIR)/$(TARGET_$(2)ARCH)/$(1)
+ $(hide) adb shell touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(3)ARCH)/$$@-$$$$PPID
+ $(hide) adb shell rm $(ART_TARGET_TEST_DIR)/$(TARGET_$(3)ARCH)/$$@-$$$$PPID
+ $(hide) adb shell chmod 755 $$(PRIVATE_TARGET_EXE)
$(hide) $$(call ART_TEST_SKIP,$$@) && \
- (adb shell "$(GCOV_ENV) LD_LIBRARY_PATH=$(3) ANDROID_ROOT=$(ART_GTEST_TARGET_ANDROID_ROOT) \
- $(ART_TARGET_NATIVETEST_DIR)/$(TARGET_$(2)ARCH)/$(1) && touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID" \
- && (adb pull $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID /tmp/ \
+ (adb shell "$(GCOV_ENV) LD_LIBRARY_PATH=$(4) ANDROID_ROOT=$(ART_GTEST_TARGET_ANDROID_ROOT) \
+ $$(PRIVATE_TARGET_EXE) && touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(3)ARCH)/$$@-$$$$PPID" \
+ && (adb pull $(ART_TARGET_TEST_DIR)/$(TARGET_$(3)ARCH)/$$@-$$$$PPID /tmp/ \
&& $$(call ART_TEST_PASSED,$$@)) \
|| $$(call ART_TEST_FAILED,$$@))
$(hide) rm -f /tmp/$$@-$$$$PPID
- ART_TEST_TARGET_GTEST$($(2)ART_PHONY_TEST_TARGET_SUFFIX)_RULES += $$(gtest_rule)
+ ART_TEST_TARGET_GTEST$($(3)ART_PHONY_TEST_TARGET_SUFFIX)_RULES += $$(gtest_rule)
ART_TEST_TARGET_GTEST_RULES += $$(gtest_rule)
ART_TEST_TARGET_GTEST_$(1)_RULES += $$(gtest_rule)
.PHONY: valgrind-$$(gtest_rule)
valgrind-$$(gtest_rule): $(ART_VALGRIND_TARGET_DEPENDENCIES) test-art-target-sync
- $(hide) adb shell touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID
- $(hide) adb shell rm $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID
- $(hide) adb shell chmod 755 $(ART_TARGET_NATIVETEST_DIR)/$(TARGET_$(2)ARCH)/$(1)
+ $(hide) adb shell touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(3)ARCH)/$$@-$$$$PPID
+ $(hide) adb shell rm $(ART_TARGET_TEST_DIR)/$(TARGET_$(3)ARCH)/$$@-$$$$PPID
+ $(hide) adb shell chmod 755 $$(PRIVATE_TARGET_EXE)
$(hide) $$(call ART_TEST_SKIP,$$@) && \
- (adb shell "$(GCOV_ENV) LD_LIBRARY_PATH=$(3) ANDROID_ROOT=$(ART_GTEST_TARGET_ANDROID_ROOT) \
+ (adb shell "$(GCOV_ENV) LD_LIBRARY_PATH=$(4) ANDROID_ROOT=$(ART_GTEST_TARGET_ANDROID_ROOT) \
valgrind --leak-check=full --error-exitcode=1 --workaround-gcc296-bugs=yes \
--suppressions=$(ART_TARGET_TEST_DIR)/valgrind-target-suppressions.txt \
--num-callers=50 \
- $(ART_TARGET_NATIVETEST_DIR)/$(TARGET_$(2)ARCH)/$(1) && touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID" \
- && (adb pull $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID /tmp/ \
+ $$(PRIVATE_TARGET_EXE) && touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(3)ARCH)/$$@-$$$$PPID" \
+ && (adb pull $(ART_TARGET_TEST_DIR)/$(TARGET_$(3)ARCH)/$$@-$$$$PPID /tmp/ \
&& $$(call ART_TEST_PASSED,$$@)) \
|| $$(call ART_TEST_FAILED,$$@))
$(hide) rm -f /tmp/$$@-$$$$PPID
- ART_TEST_TARGET_VALGRIND_GTEST$$($(2)ART_PHONY_TEST_TARGET_SUFFIX)_RULES += valgrind-$$(gtest_rule)
+ ART_TEST_TARGET_VALGRIND_GTEST$$($(3)ART_PHONY_TEST_TARGET_SUFFIX)_RULES += valgrind-$$(gtest_rule)
ART_TEST_TARGET_VALGRIND_GTEST_RULES += valgrind-$$(gtest_rule)
ART_TEST_TARGET_VALGRIND_GTEST_$(1)_RULES += valgrind-$$(gtest_rule)
# Clear locally defined variables.
valgrind_gtest_rule :=
gtest_rule :=
+ gtest_exe :=
+ gtest_target_exe :=
endef # define-art-gtest-rule-target
ART_VALGRIND_DEPENDENCIES := \
@@ -565,14 +336,15 @@
# Define make rules for a host gtests.
# $(1): gtest name - the name of the test we're building such as leb128_test.
-# $(2): 2ND_ or undefined - used to differentiate between the primary and secondary architecture.
+# $(2): path relative to $OUT to the test binary
+# $(3): 2ND_ or undefined - used to differentiate between the primary and secondary architecture.
define define-art-gtest-rule-host
- gtest_rule := test-art-host-gtest-$(1)$$($(2)ART_PHONY_TEST_HOST_SUFFIX)
- gtest_exe := $$(HOST_OUT_EXECUTABLES)/$(1)$$($(2)ART_PHONY_TEST_HOST_SUFFIX)
+ gtest_rule := test-art-host-gtest-$(1)$$($(3)ART_PHONY_TEST_HOST_SUFFIX)
+ gtest_exe := $(OUT_DIR)/$(2)
# Dependencies for all host gtests.
gtest_deps := $$(HOST_CORE_DEX_LOCATIONS) \
- $$($(2)ART_HOST_OUT_SHARED_LIBRARIES)/libjavacore$$(ART_HOST_SHLIB_EXTENSION) \
- $$($(2)ART_HOST_OUT_SHARED_LIBRARIES)/libopenjdkd$$(ART_HOST_SHLIB_EXTENSION) \
+ $$($(3)ART_HOST_OUT_SHARED_LIBRARIES)/libjavacore$$(ART_HOST_SHLIB_EXTENSION) \
+ $$($(3)ART_HOST_OUT_SHARED_LIBRARIES)/libopenjdkd$$(ART_HOST_SHLIB_EXTENSION) \
$$(gtest_exe) \
$$(ART_GTEST_$(1)_HOST_DEPS) \
$(foreach file,$(ART_GTEST_$(1)_DEX_DEPS),$(ART_TEST_HOST_GTEST_$(file)_DEX))
@@ -584,7 +356,7 @@
$(hide) ($$(call ART_TEST_SKIP,$$@) && $$< && $$(call ART_TEST_PASSED,$$@)) \
|| $$(call ART_TEST_FAILED,$$@)
- ART_TEST_HOST_GTEST$$($(2)ART_PHONY_TEST_HOST_SUFFIX)_RULES += $$(gtest_rule)
+ ART_TEST_HOST_GTEST$$($(3)ART_PHONY_TEST_HOST_SUFFIX)_RULES += $$(gtest_rule)
ART_TEST_HOST_GTEST_RULES += $$(gtest_rule)
ART_TEST_HOST_GTEST_$(1)_RULES += $$(gtest_rule)
@@ -598,7 +370,7 @@
$$< && \
$$(call ART_TEST_PASSED,$$@) || $$(call ART_TEST_FAILED,$$@)
- ART_TEST_HOST_VALGRIND_GTEST$$($(2)ART_PHONY_TEST_HOST_SUFFIX)_RULES += valgrind-$$(gtest_rule)
+ ART_TEST_HOST_VALGRIND_GTEST$$($(3)ART_PHONY_TEST_HOST_SUFFIX)_RULES += valgrind-$$(gtest_rule)
ART_TEST_HOST_VALGRIND_GTEST_RULES += valgrind-$$(gtest_rule)
ART_TEST_HOST_VALGRIND_GTEST_$(1)_RULES += valgrind-$$(gtest_rule)
@@ -612,8 +384,6 @@
# Define the rules to build and run host and target gtests.
# $(1): target or host
# $(2): file name
-# $(3): extra C includes
-# $(4): extra shared libraries
define define-art-gtest
ifneq ($(1),target)
ifneq ($(1),host)
@@ -623,40 +393,11 @@
art_target_or_host := $(1)
art_gtest_filename := $(2)
- art_gtest_extra_c_includes := $(3)
- art_gtest_extra_shared_libraries := $(4)
include $$(CLEAR_VARS)
art_gtest_name := $$(notdir $$(basename $$(art_gtest_filename)))
- LOCAL_MODULE := $$(art_gtest_name)
+
ifeq ($$(art_target_or_host),target)
- LOCAL_MODULE_TAGS := tests
- endif
- LOCAL_CPP_EXTENSION := $$(ART_CPP_EXTENSION)
- LOCAL_SRC_FILES := $$(art_gtest_filename)
- LOCAL_C_INCLUDES += $$(ART_C_INCLUDES) art/runtime art/cmdline $$(art_gtest_extra_c_includes)
- LOCAL_SHARED_LIBRARIES += libartd $$(art_gtest_extra_shared_libraries) libart-gtest libartd-disassembler
- LOCAL_WHOLE_STATIC_LIBRARIES += libsigchain
-
- LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_build.mk
- LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.gtest.mk
-
- # Mac OS linker doesn't understand --export-dynamic.
- ifneq ($$(HOST_OS)-$$(art_target_or_host),darwin-host)
- # Allow jni_compiler_test to find Java_MyClassNatives_bar within itself using dlopen(NULL, ...).
- LOCAL_LDFLAGS := -Wl,--export-dynamic -Wl,-u,Java_MyClassNatives_bar -Wl,-u,Java_MyClassNatives_sbar
- endif
-
- LOCAL_CFLAGS := $$(ART_TEST_CFLAGS)
- ifeq ($$(art_target_or_host),target)
- $$(eval LOCAL_CLANG := $$(ART_TARGET_CLANG))
- $$(eval $$(call set-target-local-cflags-vars,debug))
- LOCAL_SHARED_LIBRARIES += libdl libicuuc libicui18n libnativehelper libz libcutils libvixld-arm libvixld-arm64
- LOCAL_MODULE_PATH_32 := $$(ART_TARGET_NATIVETEST_OUT)/$$(ART_TARGET_ARCH_32)
- LOCAL_MODULE_PATH_64 := $$(ART_TARGET_NATIVETEST_OUT)/$$(ART_TARGET_ARCH_64)
- LOCAL_MULTILIB := both
- LOCAL_CFLAGS += -Wno-used-but-marked-unused -Wno-deprecated -Wno-missing-noreturn # gtest issue
- include $$(BUILD_EXECUTABLE)
library_path :=
2nd_library_path :=
ifneq ($$(ART_TEST_ANDROID_ROOT),)
@@ -675,9 +416,9 @@
ART_TEST_TARGET_GTEST_$$(art_gtest_name)_RULES :=
ART_TEST_TARGET_VALGRIND_GTEST_$$(art_gtest_name)_RULES :=
ifdef TARGET_2ND_ARCH
- $$(eval $$(call define-art-gtest-rule-target,$$(art_gtest_name),2ND_,$$(2nd_library_path)))
+ $$(eval $$(call define-art-gtest-rule-target,$$(art_gtest_name),$$(art_gtest_filename),2ND_,$$(2nd_library_path)))
endif
- $$(eval $$(call define-art-gtest-rule-target,$$(art_gtest_name),,$$(library_path)))
+ $$(eval $$(call define-art-gtest-rule-target,$$(art_gtest_name),$$(art_gtest_filename),,$$(library_path)))
# A rule to run the different architecture versions of the gtest.
.PHONY: test-art-target-gtest-$$(art_gtest_name)
@@ -692,24 +433,12 @@
ART_TEST_TARGET_GTEST_$$(art_gtest_name)_RULES :=
ART_TEST_TARGET_VALGRIND_GTEST_$$(art_gtest_name)_RULES :=
else # host
- LOCAL_CLANG := $$(ART_HOST_CLANG)
- LOCAL_CFLAGS += $$(ART_HOST_CFLAGS) $$(ART_HOST_DEBUG_CFLAGS)
- LOCAL_ASFLAGS += $$(ART_HOST_ASFLAGS) $$(ART_HOST_DEBUG_ASFLAGS)
- LOCAL_SHARED_LIBRARIES += libicuuc libicui18n libnativehelper libziparchive libz-host libvixld-arm libvixld-arm64
- LOCAL_LDLIBS := -lpthread -ldl
- LOCAL_IS_HOST_MODULE := true
- LOCAL_MULTILIB := both
- LOCAL_MODULE_STEM_32 := $$(art_gtest_name)32
- LOCAL_MODULE_STEM_64 := $$(art_gtest_name)64
- LOCAL_CFLAGS += -Wno-used-but-marked-unused -Wno-deprecated -Wno-missing-noreturn # gtest issue
- include $$(BUILD_HOST_EXECUTABLE)
-
ART_TEST_HOST_GTEST_$$(art_gtest_name)_RULES :=
ART_TEST_HOST_VALGRIND_GTEST_$$(art_gtest_name)_RULES :=
ifneq ($$(HOST_PREFER_32_BIT),true)
- $$(eval $$(call define-art-gtest-rule-host,$$(art_gtest_name),2ND_))
+ $$(eval $$(call define-art-gtest-rule-host,$$(art_gtest_name),$$(art_gtest_filename),2ND_))
endif
- $$(eval $$(call define-art-gtest-rule-host,$$(art_gtest_name),))
+ $$(eval $$(call define-art-gtest-rule-host,$$(art_gtest_name),$$(art_gtest_filename),))
# Rules to run the different architecture versions of the gtest.
.PHONY: test-art-host-gtest-$$(art_gtest_name)
@@ -728,8 +457,6 @@
# Clear locally defined variables.
art_target_or_host :=
art_gtest_filename :=
- art_gtest_extra_c_includes :=
- art_gtest_extra_shared_libraries :=
art_gtest_name :=
library_path :=
2nd_library_path :=
@@ -737,19 +464,16 @@
ifeq ($(ART_BUILD_TARGET),true)
- $(foreach file,$(RUNTIME_GTEST_TARGET_SRC_FILES), $(eval $(call define-art-gtest,target,$(file),,libbacktrace)))
- $(foreach file,$(COMPILER_GTEST_TARGET_SRC_FILES), $(eval $(call define-art-gtest,target,$(file),art/compiler,libartd-compiler libbacktrace libnativeloader)))
+ $(foreach file,$(ART_TARGET_GTEST_FILES), $(eval $(call define-art-gtest,target,$(file))))
endif
ifeq ($(ART_BUILD_HOST),true)
- $(foreach file,$(RUNTIME_GTEST_HOST_SRC_FILES), $(eval $(call define-art-gtest,host,$(file),,libbacktrace)))
- $(foreach file,$(COMPILER_GTEST_HOST_SRC_FILES), $(eval $(call define-art-gtest,host,$(file),art/compiler,libartd-compiler libbacktrace libnativeloader)))
+ $(foreach file,$(ART_HOST_GTEST_FILES), $(eval $(call define-art-gtest,host,$(file))))
endif
# Used outside the art project to get a list of the current tests
RUNTIME_TARGET_GTEST_MAKE_TARGETS :=
-$(foreach file, $(RUNTIME_GTEST_TARGET_SRC_FILES), $(eval RUNTIME_TARGET_GTEST_MAKE_TARGETS += $$(notdir $$(basename $$(file)))))
+$(foreach file, $(ART_TARGET_GTEST_FILES), $(eval RUNTIME_TARGET_GTEST_MAKE_TARGETS += $$(notdir $$(basename $$(file)))))
COMPILER_TARGET_GTEST_MAKE_TARGETS :=
-$(foreach file, $(COMPILER_GTEST_TARGET_SRC_FILES), $(eval COMPILER_TARGET_GTEST_MAKE_TARGETS += $$(notdir $$(basename $$(file)))))
# Define all the combinations of host/target, valgrind and suffix such as:
# test-art-host-gtest or valgrind-test-art-host-gtest64
@@ -849,11 +573,15 @@
ART_GTEST_stub_test_DEX_DEPS :=
ART_GTEST_transaction_test_DEX_DEPS :=
ART_GTEST_dex2oat_environment_tests_DEX_DEPS :=
+ART_GTEST_verifier_deps_test_DEX_DEPS :=
ART_VALGRIND_DEPENDENCIES :=
ART_VALGRIND_TARGET_DEPENDENCIES :=
$(foreach dir,$(GTEST_DEX_DIRECTORIES), $(eval ART_TEST_TARGET_GTEST_$(dir)_DEX :=))
$(foreach dir,$(GTEST_DEX_DIRECTORIES), $(eval ART_TEST_HOST_GTEST_$(dir)_DEX :=))
ART_TEST_HOST_GTEST_MainStripped_DEX :=
ART_TEST_TARGET_GTEST_MainStripped_DEX :=
+ART_TEST_GTEST_VerifierDeps_SRC :=
+ART_TEST_HOST_GTEST_VerifierDeps_DEX :=
+ART_TEST_TARGET_GTEST_VerifierDeps_DEX :=
GTEST_DEX_DIRECTORIES :=
LOCAL_PATH :=
diff --git a/build/Android.oat.mk b/build/Android.oat.mk
index 884f698..c4887e6 100644
--- a/build/Android.oat.mk
+++ b/build/Android.oat.mk
@@ -37,7 +37,7 @@
endif
# Use dex2oat debug version for better error reporting
-# $(1): compiler - default, optimizing, jit, interpreter or interpreter-access-checks.
+# $(1): compiler - optimizing, interpreter or interpreter-access-checks.
# $(2): pic/no-pic
# $(3): 2ND_ or undefined, 2ND_ for 32-bit host builds.
# $(4): wrapper, e.g., valgrind.
@@ -53,13 +53,9 @@
core_pic_infix :=
core_dex2oat_dependency := $(DEX2OAT_DEPENDENCY)
- ifeq ($(1),default)
- core_compile_options += --compiler-backend=Quick
- endif
ifeq ($(1),optimizing)
core_compile_options += --compiler-backend=Optimizing
core_dex2oat_dependency := $(DEX2OAT)
- core_infix := -optimizing
endif
ifeq ($(1),interpreter)
core_compile_options += --compiler-filter=interpret-only
@@ -69,24 +65,16 @@
core_compile_options += --compiler-filter=verify-at-runtime --runtime-arg -Xverify:softfail
core_infix := -interp-ac
endif
- ifeq ($(1),jit)
- core_compile_options += --compiler-filter=verify-at-runtime
- core_infix := -jit
- endif
- ifeq ($(1),default)
- # Default has no infix, no compile options.
- endif
- ifneq ($(filter-out default interpreter interp-ac jit optimizing,$(1)),)
+ ifneq ($(filter-out interpreter interp-ac optimizing,$(1)),)
#Technically this test is not precise, but hopefully good enough.
- $$(error found $(1) expected default, interpreter, interpreter-access-checks, jit or optimizing)
+ $$(error found $(1) expected interpreter, interpreter-access-checks, or optimizing)
endif
ifeq ($(2),pic)
core_compile_options += --compile-pic
- core_pic_infix := -pic
endif
ifeq ($(2),no-pic)
- # No change for non-pic
+ core_pic_infix := -npic
endif
ifneq ($(filter-out pic no-pic,$(2)),)
# Technically this test is not precise, but hopefully good enough.
@@ -148,7 +136,7 @@
core_pic_infix :=
endef # create-core-oat-host-rules
-# $(1): compiler - default, optimizing, jit, interpreter or interpreter-access-checks.
+# $(1): compiler - optimizing, interpreter or interpreter-access-checks.
# $(2): wrapper.
# $(3): dex2oat suffix.
# $(4): multi-image.
@@ -162,24 +150,18 @@
endif
endef
-$(eval $(call create-core-oat-host-rule-combination,default,,,false))
$(eval $(call create-core-oat-host-rule-combination,optimizing,,,false))
$(eval $(call create-core-oat-host-rule-combination,interpreter,,,false))
$(eval $(call create-core-oat-host-rule-combination,interp-ac,,,false))
-$(eval $(call create-core-oat-host-rule-combination,jit,,,false))
-$(eval $(call create-core-oat-host-rule-combination,default,,,true))
$(eval $(call create-core-oat-host-rule-combination,optimizing,,,true))
$(eval $(call create-core-oat-host-rule-combination,interpreter,,,true))
$(eval $(call create-core-oat-host-rule-combination,interp-ac,,,true))
-$(eval $(call create-core-oat-host-rule-combination,jit,,,true))
valgrindHOST_CORE_IMG_OUTS :=
valgrindHOST_CORE_OAT_OUTS :=
-$(eval $(call create-core-oat-host-rule-combination,default,valgrind,32,false))
$(eval $(call create-core-oat-host-rule-combination,optimizing,valgrind,32,false))
$(eval $(call create-core-oat-host-rule-combination,interpreter,valgrind,32,false))
$(eval $(call create-core-oat-host-rule-combination,interp-ac,valgrind,32,false))
-$(eval $(call create-core-oat-host-rule-combination,jit,valgrind,32,false))
valgrind-test-art-host-dex2oat-host: $(valgrindHOST_CORE_IMG_OUTS)
@@ -193,15 +175,11 @@
core_pic_infix :=
core_dex2oat_dependency := $(DEX2OAT_DEPENDENCY)
- ifeq ($(1),default)
- core_compile_options += --compiler-backend=Quick
- endif
ifeq ($(1),optimizing)
core_compile_options += --compiler-backend=Optimizing
# With the optimizing compiler, we want to rerun dex2oat whenever there is
# a dex2oat change to catch regressions early.
core_dex2oat_dependency := $(DEX2OAT)
- core_infix := -optimizing
endif
ifeq ($(1),interpreter)
core_compile_options += --compiler-filter=interpret-only
@@ -211,24 +189,16 @@
core_compile_options += --compiler-filter=verify-at-runtime --runtime-arg -Xverify:softfail
core_infix := -interp-ac
endif
- ifeq ($(1),jit)
- core_compile_options += --compiler-filter=verify-at-runtime
- core_infix := -jit
- endif
- ifeq ($(1),default)
- # Default has no infix, no compile options.
- endif
- ifneq ($(filter-out default interpreter interp-ac jit optimizing,$(1)),)
+ ifneq ($(filter-out interpreter interp-ac optimizing,$(1)),)
# Technically this test is not precise, but hopefully good enough.
- $$(error found $(1) expected default, interpreter, interpreter-access-checks, jit or optimizing)
+ $$(error found $(1) expected interpreter, interpreter-access-checks, or optimizing)
endif
ifeq ($(2),pic)
core_compile_options += --compile-pic
- core_pic_infix := -pic
endif
ifeq ($(2),no-pic)
- # No change for non-pic
+ core_pic_infix := -npic
endif
ifneq ($(filter-out pic no-pic,$(2)),)
#Technically this test is not precise, but hopefully good enough.
@@ -283,7 +253,7 @@
core_pic_infix :=
endef # create-core-oat-target-rules
-# $(1): compiler - default, optimizing, jit, interpreter or interpreter-access-checks.
+# $(1): compiler - optimizing, interpreter or interpreter-access-checks.
# $(2): wrapper.
# $(3): dex2oat suffix.
define create-core-oat-target-rule-combination
@@ -296,19 +266,15 @@
endif
endef
-$(eval $(call create-core-oat-target-rule-combination,default,,))
$(eval $(call create-core-oat-target-rule-combination,optimizing,,))
$(eval $(call create-core-oat-target-rule-combination,interpreter,,))
$(eval $(call create-core-oat-target-rule-combination,interp-ac,,))
-$(eval $(call create-core-oat-target-rule-combination,jit,,))
valgrindTARGET_CORE_IMG_OUTS :=
valgrindTARGET_CORE_OAT_OUTS :=
-$(eval $(call create-core-oat-target-rule-combination,default,valgrind,32))
$(eval $(call create-core-oat-target-rule-combination,optimizing,valgrind,32))
$(eval $(call create-core-oat-target-rule-combination,interpreter,valgrind,32))
$(eval $(call create-core-oat-target-rule-combination,interp-ac,valgrind,32))
-$(eval $(call create-core-oat-target-rule-combination,jit,valgrind,32))
valgrind-test-art-host-dex2oat-target: $(valgrindTARGET_CORE_IMG_OUTS)
diff --git a/build/art.go b/build/art.go
index f694505..f2efbfe 100644
--- a/build/art.go
+++ b/build/art.go
@@ -19,6 +19,7 @@
"android/soong/android"
"android/soong/cc"
"fmt"
+ "sync"
"github.com/google/blueprint"
)
@@ -122,7 +123,7 @@
return cflags
}
-func (a *artGlobalDefaults) CustomizeProperties(ctx android.CustomizePropertiesContext) {
+func globalDefaults(ctx android.LoadHookContext) {
type props struct {
Target struct {
Android struct {
@@ -143,9 +144,7 @@
ctx.AppendProperties(p)
}
-type artGlobalDefaults struct{}
-
-func (a *artCustomLinkerCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
+func customLinker(ctx android.LoadHookContext) {
linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
if linker != "" {
type props struct {
@@ -158,9 +157,7 @@
}
}
-type artCustomLinkerCustomizer struct{}
-
-func (a *artPrefer32BitCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
+func prefer32Bit(ctx android.LoadHookContext) {
if envTrue(ctx, "HOST_PREFER_32_BIT") {
type props struct {
Target struct {
@@ -176,7 +173,32 @@
}
}
-type artPrefer32BitCustomizer struct{}
+func testMap(config android.Config) map[string][]string {
+ return config.Once("artTests", func() interface{} {
+ return make(map[string][]string)
+ }).(map[string][]string)
+}
+
+func testInstall(ctx android.InstallHookContext) {
+ testMap := testMap(ctx.AConfig())
+
+ var name string
+ if ctx.Host() {
+ name = "host_"
+ } else {
+ name = "device_"
+ }
+ name += ctx.Arch().ArchType.String() + "_" + ctx.ModuleName()
+
+ artTestMutex.Lock()
+ defer artTestMutex.Unlock()
+
+ tests := testMap[name]
+ tests = append(tests, ctx.Path().RelPathString())
+ testMap[name] = tests
+}
+
+var artTestMutex sync.Mutex
func init() {
soong.RegisterModuleType("art_cc_library", artLibrary)
@@ -187,17 +209,16 @@
}
func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
- c := &artGlobalDefaults{}
module, props := artDefaultsFactory()
- android.AddCustomizer(module.(android.Module), c)
+ android.AddLoadHook(module, globalDefaults)
return module, props
}
func artDefaultsFactory() (blueprint.Module, []interface{}) {
- c := &codegenCustomizer{}
- module, props := cc.DefaultsFactory(&c.codegenProperties)
- android.AddCustomizer(module.(android.Module), c)
+ c := &codegenProperties{}
+ module, props := cc.DefaultsFactory(c)
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, true) })
return module, props
}
@@ -206,9 +227,7 @@
library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
module, props := library.Init()
- c := &codegenCustomizer{}
- android.AddCustomizer(library, c)
- props = append(props, &c.codegenProperties)
+ props = installCodegenCustomizer(module, props, true)
return module, props
}
@@ -217,8 +236,8 @@
binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
module, props := binary.Init()
- android.AddCustomizer(binary, &artCustomLinkerCustomizer{})
- android.AddCustomizer(binary, &artPrefer32BitCustomizer{})
+ android.AddLoadHook(module, customLinker)
+ android.AddLoadHook(module, prefer32Bit)
return module, props
}
@@ -226,8 +245,11 @@
test := cc.NewTest(android.HostAndDeviceSupported)
module, props := test.Init()
- android.AddCustomizer(test, &artCustomLinkerCustomizer{})
- android.AddCustomizer(test, &artPrefer32BitCustomizer{})
+ props = installCodegenCustomizer(module, props, false)
+
+ android.AddLoadHook(module, customLinker)
+ android.AddLoadHook(module, prefer32Bit)
+ android.AddInstallHook(module, testInstall)
return module, props
}
diff --git a/build/codegen.go b/build/codegen.go
index fde9420..ba6f214 100644
--- a/build/codegen.go
+++ b/build/codegen.go
@@ -22,11 +22,11 @@
"android/soong/android"
"sort"
"strings"
+
+ "github.com/google/blueprint"
)
-func (a *codegenCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
- c := &a.codegenProperties.Codegen
-
+func codegen(ctx android.LoadHookContext, c *codegenProperties, library bool) {
var hostArches, deviceArches []string
e := envDefault(ctx, "ART_HOST_CODEGEN_ARCHS", "")
@@ -43,54 +43,77 @@
deviceArches = strings.Split(e, " ")
}
- type props struct {
- Target struct {
- Android *codegenArchProperties
- Host *codegenArchProperties
+ addCodegenArchProperties := func(host bool, archName string) {
+ type props struct {
+ Target struct {
+ Android *CodegenCommonArchProperties
+ Host *CodegenCommonArchProperties
+ }
}
- }
- addCodegenArchProperties := func(p *props, hod **codegenArchProperties, arch string) {
- switch arch {
+ type libraryProps struct {
+ Target struct {
+ Android *CodegenLibraryArchProperties
+ Host *CodegenLibraryArchProperties
+ }
+ }
+
+ var arch *codegenArchProperties
+ switch archName {
case "arm":
- *hod = &c.Arm
+ arch = &c.Codegen.Arm
case "arm64":
- *hod = &c.Arm64
+ arch = &c.Codegen.Arm64
case "mips":
- *hod = &c.Mips
+ arch = &c.Codegen.Mips
case "mips64":
- *hod = &c.Mips64
+ arch = &c.Codegen.Mips64
case "x86":
- *hod = &c.X86
+ arch = &c.Codegen.X86
case "x86_64":
- *hod = &c.X86_64
+ arch = &c.Codegen.X86_64
default:
- ctx.ModuleErrorf("Unknown codegen architecture %q", arch)
+ ctx.ModuleErrorf("Unknown codegen architecture %q", archName)
return
}
+
+ p := &props{}
+ l := &libraryProps{}
+ if host {
+ p.Target.Host = &arch.CodegenCommonArchProperties
+ l.Target.Host = &arch.CodegenLibraryArchProperties
+ } else {
+ p.Target.Android = &arch.CodegenCommonArchProperties
+ l.Target.Android = &arch.CodegenLibraryArchProperties
+ }
+
ctx.AppendProperties(p)
+ if library {
+ ctx.AppendProperties(l)
+ }
}
- for _, a := range deviceArches {
- p := &props{}
- addCodegenArchProperties(p, &p.Target.Android, a)
+ for _, arch := range deviceArches {
+ addCodegenArchProperties(false, arch)
if ctx.Failed() {
return
}
}
- for _, a := range hostArches {
- p := &props{}
- addCodegenArchProperties(p, &p.Target.Host, a)
+ for _, arch := range hostArches {
+ addCodegenArchProperties(true, arch)
if ctx.Failed() {
return
}
}
}
-type codegenArchProperties struct {
+type CodegenCommonArchProperties struct {
Srcs []string
Cflags []string
+}
+
+type CodegenLibraryArchProperties struct {
Static struct {
Whole_static_libs []string
}
@@ -99,6 +122,11 @@
}
}
+type codegenArchProperties struct {
+ CodegenCommonArchProperties
+ CodegenLibraryArchProperties
+}
+
type codegenProperties struct {
Codegen struct {
Arm, Arm64, Mips, Mips64, X86, X86_64 codegenArchProperties
@@ -106,10 +134,11 @@
}
type codegenCustomizer struct {
+ library bool
codegenProperties codegenProperties
}
-func defaultDeviceCodegenArches(ctx android.CustomizePropertiesContext) []string {
+func defaultDeviceCodegenArches(ctx android.LoadHookContext) []string {
arches := make(map[string]bool)
for _, a := range ctx.DeviceConfig().Arches() {
s := a.ArchType.String()
@@ -129,3 +158,11 @@
sort.Strings(ret)
return ret
}
+
+func installCodegenCustomizer(module blueprint.Module, props []interface{}, library bool) []interface{} {
+ c := &codegenProperties{}
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, library) })
+ props = append(props, c)
+
+ return props
+}
diff --git a/build/makevars.go b/build/makevars.go
index 5655c55..1faa0f6 100644
--- a/build/makevars.go
+++ b/build/makevars.go
@@ -14,7 +14,12 @@
package art
-import "android/soong/android"
+import (
+ "sort"
+ "strings"
+
+ "android/soong/android"
+)
var (
pctx = android.NewPackageContext("android/soong/art")
@@ -27,4 +32,16 @@
func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("LIBART_IMG_HOST_BASE_ADDRESS", ctx.Config().LibartImgHostBaseAddress())
ctx.Strict("LIBART_IMG_TARGET_BASE_ADDRESS", ctx.Config().LibartImgDeviceBaseAddress())
+
+ testMap := testMap(ctx.Config())
+ var testNames []string
+ for name := range testMap {
+ testNames = append(testNames, name)
+ }
+
+ sort.Strings(testNames)
+
+ for _, name := range testNames {
+ ctx.Strict("ART_TEST_LIST_"+name, strings.Join(testMap[name], " "))
+ }
}
diff --git a/cmdline/Android.bp b/cmdline/Android.bp
new file mode 100644
index 0000000..c9cd9dc
--- /dev/null
+++ b/cmdline/Android.bp
@@ -0,0 +1,23 @@
+//
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+art_cc_test {
+ name: "art_cmdline_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: ["cmdline_parser_test.cc"],
+}
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 595a824..4af43cc 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -279,3 +279,153 @@
},
shared_libs: ["libartd"],
}
+
+art_cc_library {
+ name: "libart-compiler-gtest",
+ defaults: ["libart-gtest-defaults"],
+ srcs: ["common_compiler_test.cc"],
+ shared_libs: [
+ "libartd-compiler",
+ "libart-runtime-gtest",
+ ],
+}
+
+art_cc_test {
+ name: "art_compiler_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: [
+ "compiled_method_test.cc",
+ "debug/dwarf/dwarf_test.cc",
+ "driver/compiled_method_storage_test.cc",
+ "driver/compiler_driver_test.cc",
+ "elf_writer_test.cc",
+ "exception_test.cc",
+ "image_test.cc",
+ "jni/jni_compiler_test.cc",
+ "linker/multi_oat_relative_patcher_test.cc",
+ "linker/output_stream_test.cc",
+ "oat_test.cc",
+ "optimizing/bounds_check_elimination_test.cc",
+ "optimizing/dominator_test.cc",
+ "optimizing/find_loops_test.cc",
+ "optimizing/graph_checker_test.cc",
+ "optimizing/graph_test.cc",
+ "optimizing/gvn_test.cc",
+ "optimizing/induction_var_analysis_test.cc",
+ "optimizing/induction_var_range_test.cc",
+ "optimizing/licm_test.cc",
+ "optimizing/live_interval_test.cc",
+ "optimizing/nodes_test.cc",
+ "optimizing/parallel_move_test.cc",
+ "optimizing/pretty_printer_test.cc",
+ "optimizing/reference_type_propagation_test.cc",
+ "optimizing/side_effects_test.cc",
+ "optimizing/ssa_test.cc",
+ "optimizing/stack_map_test.cc",
+ "optimizing/suspend_check_test.cc",
+ "utils/dedupe_set_test.cc",
+ "utils/intrusive_forward_list_test.cc",
+ "utils/string_reference_test.cc",
+ "utils/swap_space_test.cc",
+ "utils/test_dex_file_builder_test.cc",
+
+ "jni/jni_cfi_test.cc",
+ "optimizing/codegen_test.cc",
+ "optimizing/optimizing_cfi_test.cc",
+ ],
+
+ codegen: {
+ arm: {
+ srcs: [
+ "linker/arm/relative_patcher_thumb2_test.cc",
+ "utils/arm/managed_register_arm_test.cc",
+ ],
+ },
+ arm64: {
+ srcs: [
+ "linker/arm64/relative_patcher_arm64_test.cc",
+ "utils/arm64/managed_register_arm64_test.cc",
+ ],
+ },
+ mips: {
+ srcs: [
+ "linker/mips/relative_patcher_mips_test.cc",
+ "linker/mips/relative_patcher_mips32r6_test.cc",
+ ],
+ },
+ x86: {
+ srcs: [
+ "linker/x86/relative_patcher_x86_test.cc",
+ "utils/x86/managed_register_x86_test.cc",
+
+ // These tests are testing architecture-independent
+ // functionality, but happen to use x86 codegen as part of the
+ // test.
+ "optimizing/constant_folding_test.cc",
+ "optimizing/dead_code_elimination_test.cc",
+ "optimizing/linearize_test.cc",
+ "optimizing/live_ranges_test.cc",
+ "optimizing/liveness_test.cc",
+ "optimizing/register_allocator_test.cc",
+ ],
+ },
+ x86_64: {
+ srcs: [
+ "linker/x86_64/relative_patcher_x86_64_test.cc",
+ ],
+ },
+ },
+
+ shared_libs: [
+ "libartd-compiler",
+ "libvixld-arm",
+ "libvixld-arm64",
+
+ "libbacktrace",
+ "libnativeloader",
+ ],
+}
+
+art_cc_test {
+ name: "art_compiler_host_tests",
+ device_supported: false,
+ defaults: [
+ "art_test_defaults",
+ ],
+ codegen: {
+ arm: {
+ srcs: [
+ "utils/arm/assembler_thumb2_test.cc",
+ "utils/assembler_thumb_test.cc",
+ ],
+ },
+ mips: {
+ srcs: [
+ "utils/mips/assembler_mips_test.cc",
+ "utils/mips/assembler_mips32r6_test.cc",
+ ],
+ },
+ mips64: {
+ srcs: [
+ "utils/mips64/assembler_mips64_test.cc",
+ ],
+ },
+ x86: {
+ srcs: [
+ "utils/x86/assembler_x86_test.cc",
+ ],
+ },
+ x86_64: {
+ srcs: [
+ "utils/x86_64/assembler_x86_64_test.cc",
+ ],
+ },
+ },
+ shared_libs: [
+ "libartd-compiler",
+ "libvixld-arm",
+ "libvixld-arm64",
+ ],
+}
diff --git a/compiler/compiled_method.h b/compiler/compiled_method.h
index 2a81804..1a87448 100644
--- a/compiler/compiled_method.h
+++ b/compiler/compiled_method.h
@@ -23,10 +23,10 @@
#include <vector>
#include "arch/instruction_set.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/length_prefixed_array.h"
#include "method_reference.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/debug/dwarf/headers.h b/compiler/debug/dwarf/headers.h
index 146d9fd..28f1084 100644
--- a/compiler/debug/dwarf/headers.h
+++ b/compiler/debug/dwarf/headers.h
@@ -19,13 +19,13 @@
#include <cstdint>
+#include "base/array_ref.h"
#include "debug/dwarf/debug_frame_opcode_writer.h"
#include "debug/dwarf/debug_info_entry_writer.h"
#include "debug/dwarf/debug_line_opcode_writer.h"
#include "debug/dwarf/dwarf_constants.h"
#include "debug/dwarf/register.h"
#include "debug/dwarf/writer.h"
-#include "utils/array_ref.h"
namespace art {
namespace dwarf {
diff --git a/compiler/debug/elf_debug_writer.cc b/compiler/debug/elf_debug_writer.cc
index 5bfdd16..d1c10a9 100644
--- a/compiler/debug/elf_debug_writer.cc
+++ b/compiler/debug/elf_debug_writer.cc
@@ -18,6 +18,7 @@
#include <vector>
+#include "base/array_ref.h"
#include "debug/dwarf/dwarf_constants.h"
#include "debug/elf_compilation_unit.h"
#include "debug/elf_debug_frame_writer.h"
@@ -29,7 +30,6 @@
#include "debug/method_debug_info.h"
#include "elf_builder.h"
#include "linker/vector_output_stream.h"
-#include "utils/array_ref.h"
namespace art {
namespace debug {
diff --git a/compiler/debug/elf_debug_writer.h b/compiler/debug/elf_debug_writer.h
index b0542c7..07f7229 100644
--- a/compiler/debug/elf_debug_writer.h
+++ b/compiler/debug/elf_debug_writer.h
@@ -19,11 +19,11 @@
#include <vector>
+#include "base/array_ref.h"
#include "base/macros.h"
#include "base/mutex.h"
#include "debug/dwarf/dwarf_constants.h"
#include "elf_builder.h"
-#include "utils/array_ref.h"
namespace art {
class OatHeader;
diff --git a/compiler/dex/quick_compiler_callbacks.h b/compiler/dex/quick_compiler_callbacks.h
index 1f69686..824194c 100644
--- a/compiler/dex/quick_compiler_callbacks.h
+++ b/compiler/dex/quick_compiler_callbacks.h
@@ -29,8 +29,10 @@
QuickCompilerCallbacks(VerificationResults* verification_results,
DexFileToMethodInlinerMap* method_inliner_map,
CompilerCallbacks::CallbackMode mode)
- : CompilerCallbacks(mode), verification_results_(verification_results),
- method_inliner_map_(method_inliner_map) {
+ : CompilerCallbacks(mode),
+ verification_results_(verification_results),
+ method_inliner_map_(method_inliner_map),
+ verifier_deps_(nullptr) {
CHECK(verification_results != nullptr);
CHECK(method_inliner_map != nullptr);
}
@@ -47,9 +49,18 @@
return true;
}
+ verifier::VerifierDeps* GetVerifierDeps() const OVERRIDE {
+ return verifier_deps_;
+ }
+
+ void SetVerifierDeps(verifier::VerifierDeps* deps) {
+ verifier_deps_ = deps;
+ }
+
private:
VerificationResults* const verification_results_;
DexFileToMethodInlinerMap* const method_inliner_map_;
+ verifier::VerifierDeps* verifier_deps_;
};
} // namespace art
diff --git a/compiler/dex/verified_method.cc b/compiler/dex/verified_method.cc
index 4bcd59a..e19fb7b 100644
--- a/compiler/dex/verified_method.cc
+++ b/compiler/dex/verified_method.cc
@@ -231,7 +231,7 @@
inst->VRegA_21c()));
const verifier::RegType& cast_type =
method_verifier->ResolveCheckedClass(inst->VRegB_21c());
- is_safe_cast = cast_type.IsStrictlyAssignableFrom(reg_type);
+ is_safe_cast = cast_type.IsStrictlyAssignableFrom(reg_type, method_verifier);
} else {
const verifier::RegType& array_type(line->GetRegisterType(method_verifier,
inst->VRegB_23x()));
@@ -243,7 +243,7 @@
inst->VRegA_23x()));
const verifier::RegType& component_type = method_verifier->GetRegTypeCache()
->GetComponentType(array_type, method_verifier->GetClassLoader());
- is_safe_cast = component_type.IsStrictlyAssignableFrom(value_type);
+ is_safe_cast = component_type.IsStrictlyAssignableFrom(value_type, method_verifier);
}
}
if (is_safe_cast) {
diff --git a/compiler/driver/compiled_method_storage.h b/compiler/driver/compiled_method_storage.h
index 8674abf..124b5a6 100644
--- a/compiler/driver/compiled_method_storage.h
+++ b/compiler/driver/compiled_method_storage.h
@@ -20,9 +20,9 @@
#include <iosfwd>
#include <memory>
+#include "base/array_ref.h"
#include "base/length_prefixed_array.h"
#include "base/macros.h"
-#include "utils/array_ref.h"
#include "utils/dedupe_set.h"
#include "utils/swap_space.h"
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 53e068e..a149c07 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -26,6 +26,7 @@
#include "art_field-inl.h"
#include "art_method-inl.h"
+#include "base/array_ref.h"
#include "base/bit_vector.h"
#include "base/enums.h"
#include "base/stl_util.h"
@@ -67,7 +68,6 @@
#include "thread_pool.h"
#include "trampolines/trampoline_compiler.h"
#include "transaction.h"
-#include "utils/array_ref.h"
#include "utils/dex_cache_arrays_layout-inl.h"
#include "utils/swap_space.h"
#include "verifier/method_verifier.h"
@@ -2474,7 +2474,7 @@
// mode which prevents the GC from visiting objects modified during the transaction.
// Ensure GC is not run so don't access freed objects when aborting transaction.
- ScopedAssertNoThreadSuspension ants(soa.Self(), "Transaction end");
+ ScopedAssertNoThreadSuspension ants("Transaction end");
runtime->ExitTransactionMode();
if (!success) {
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index fbc1edd..ee21efa 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -24,6 +24,7 @@
#include "arch/instruction_set.h"
#include "base/arena_allocator.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/mutex.h"
#include "base/timing_logger.h"
@@ -39,7 +40,6 @@
#include "runtime.h"
#include "safe_map.h"
#include "thread_pool.h"
-#include "utils/array_ref.h"
#include "utils/dex_cache_arrays_layout.h"
namespace art {
diff --git a/compiler/elf_builder.h b/compiler/elf_builder.h
index 7f2e193..02831c9 100644
--- a/compiler/elf_builder.h
+++ b/compiler/elf_builder.h
@@ -21,13 +21,13 @@
#include "arch/instruction_set.h"
#include "arch/mips/instruction_set_features_mips.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/casts.h"
#include "base/unix_file/fd_file.h"
#include "elf_utils.h"
#include "leb128.h"
#include "linker/error_delaying_output_stream.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/elf_writer.h b/compiler/elf_writer.h
index c9ea0083..f8f9102 100644
--- a/compiler/elf_writer.h
+++ b/compiler/elf_writer.h
@@ -22,10 +22,10 @@
#include <string>
#include <vector>
+#include "base/array_ref.h"
#include "base/macros.h"
#include "base/mutex.h"
#include "os.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index 7634510..6d86f7d 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -868,7 +868,7 @@
// Clear references to removed classes from the DexCaches.
ArtMethod* resolution_method = runtime->GetResolutionMethod();
- ScopedAssertNoThreadSuspension sa(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension sa(__FUNCTION__);
ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_); // For ClassInClassTable
ReaderMutexLock mu2(self, *class_linker->DexLock());
for (const ClassLinker::DexCacheData& data : class_linker->GetDexCachesData()) {
diff --git a/compiler/jni/quick/calling_convention.h b/compiler/jni/quick/calling_convention.h
index 3d89146..f541d8f 100644
--- a/compiler/jni/quick/calling_convention.h
+++ b/compiler/jni/quick/calling_convention.h
@@ -18,11 +18,11 @@
#define ART_COMPILER_JNI_QUICK_CALLING_CONVENTION_H_
#include "base/arena_object.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "handle_scope.h"
#include "primitive.h"
#include "thread.h"
-#include "utils/array_ref.h"
#include "utils/managed_register.h"
namespace art {
diff --git a/compiler/linker/arm64/relative_patcher_arm64.h b/compiler/linker/arm64/relative_patcher_arm64.h
index 48ad105..a4a8018 100644
--- a/compiler/linker/arm64/relative_patcher_arm64.h
+++ b/compiler/linker/arm64/relative_patcher_arm64.h
@@ -17,8 +17,8 @@
#ifndef ART_COMPILER_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_
#define ART_COMPILER_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_
+#include "base/array_ref.h"
#include "linker/arm/relative_patcher_arm_base.h"
-#include "utils/array_ref.h"
namespace art {
namespace linker {
diff --git a/compiler/linker/relative_patcher.h b/compiler/linker/relative_patcher.h
index a22b9f2..15e955b 100644
--- a/compiler/linker/relative_patcher.h
+++ b/compiler/linker/relative_patcher.h
@@ -21,9 +21,9 @@
#include "arch/instruction_set.h"
#include "arch/instruction_set_features.h"
+#include "base/array_ref.h"
#include "base/macros.h"
#include "method_reference.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/linker/relative_patcher_test.h b/compiler/linker/relative_patcher_test.h
index d21f33e..304b31c 100644
--- a/compiler/linker/relative_patcher_test.h
+++ b/compiler/linker/relative_patcher_test.h
@@ -19,6 +19,7 @@
#include "arch/instruction_set.h"
#include "arch/instruction_set_features.h"
+#include "base/array_ref.h"
#include "base/macros.h"
#include "compiled_method.h"
#include "dex/quick/dex_file_to_method_inliner_map.h"
@@ -31,7 +32,6 @@
#include "method_reference.h"
#include "oat.h"
#include "oat_quick_method_header.h"
-#include "utils/array_ref.h"
#include "vector_output_stream.h"
namespace art {
diff --git a/compiler/oat_writer.cc b/compiler/oat_writer.cc
index 43e01d5..5e0c64b 100644
--- a/compiler/oat_writer.cc
+++ b/compiler/oat_writer.cc
@@ -994,7 +994,7 @@
out_(out),
file_offset_(file_offset),
soa_(Thread::Current()),
- no_thread_suspension_(soa_.Self(), "OatWriter patching"),
+ no_thread_suspension_("OatWriter patching"),
class_linker_(Runtime::Current()->GetClassLinker()),
dex_cache_(nullptr) {
patched_code_.reserve(16 * KB);
@@ -1036,7 +1036,7 @@
const CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index);
// No thread suspension since dex_cache_ that may get invalidated if that occurs.
- ScopedAssertNoThreadSuspension tsc(Thread::Current(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension tsc(__FUNCTION__);
if (compiled_method != nullptr) { // ie. not an abstract method
size_t file_offset = file_offset_;
OutputStream* out = out_;
diff --git a/compiler/oat_writer.h b/compiler/oat_writer.h
index 77525f1..dd7d699 100644
--- a/compiler/oat_writer.h
+++ b/compiler/oat_writer.h
@@ -21,6 +21,7 @@
#include <cstddef>
#include <memory>
+#include "base/array_ref.h"
#include "base/dchecked_vector.h"
#include "linker/relative_patcher.h" // For linker::RelativePatcherTargetProvider.
#include "mem_map.h"
@@ -29,7 +30,6 @@
#include "oat.h"
#include "os.h"
#include "safe_map.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/optimizing/bounds_check_elimination.cc b/compiler/optimizing/bounds_check_elimination.cc
index 8aefd9e..994d394 100644
--- a/compiler/optimizing/bounds_check_elimination.cc
+++ b/compiler/optimizing/bounds_check_elimination.cc
@@ -887,7 +887,7 @@
bool needs_finite_test = false;
bool needs_taken_test = false;
if (DynamicBCESeemsProfitable(loop, bounds_check->GetBlock()) &&
- induction_range_.CanGenerateCode(
+ induction_range_.CanGenerateRange(
bounds_check, index, &needs_finite_test, &needs_taken_test) &&
CanHandleInfiniteLoop(loop, index, needs_finite_test) &&
// Do this test last, since it may generate code.
@@ -1403,10 +1403,10 @@
// whether code generation on the original and, thus, related bounds check was possible.
// It handles either loop invariants (lower is not set) or unit strides.
if (other_c == max_c) {
- induction_range_.GenerateRangeCode(
+ induction_range_.GenerateRange(
other_bounds_check, other_index, GetGraph(), block, &max_lower, &max_upper);
} else if (other_c == min_c && base != nullptr) {
- induction_range_.GenerateRangeCode(
+ induction_range_.GenerateRange(
other_bounds_check, other_index, GetGraph(), block, &min_lower, &min_upper);
}
ReplaceInstruction(other_bounds_check, other_index);
@@ -1699,11 +1699,8 @@
// Insert the taken-test to see if the loop body is entered. If the
// loop isn't entered at all, it jumps around the deoptimization block.
if_block->AddInstruction(new (GetGraph()->GetArena()) HGoto()); // placeholder
- HInstruction* condition = nullptr;
- induction_range_.GenerateTakenTest(header->GetLastInstruction(),
- GetGraph(),
- if_block,
- &condition);
+ HInstruction* condition = induction_range_.GenerateTakenTest(
+ header->GetLastInstruction(), GetGraph(), if_block);
DCHECK(condition != nullptr);
if_block->RemoveInstruction(if_block->GetLastInstruction());
if_block->AddInstruction(new (GetGraph()->GetArena()) HIf(condition));
diff --git a/compiler/optimizing/code_generator_arm.h b/compiler/optimizing/code_generator_arm.h
index ce9d7e6..38a2410 100644
--- a/compiler/optimizing/code_generator_arm.h
+++ b/compiler/optimizing/code_generator_arm.h
@@ -556,10 +556,10 @@
// artReadBarrierForRootSlow.
void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
- void GenerateNop();
+ void GenerateNop() OVERRIDE;
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
private:
Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp);
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index c00ab56..599185a 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -448,7 +448,7 @@
}
const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; }
- bool IsFatal() const { return is_fatal_; }
+ bool IsFatal() const OVERRIDE { return is_fatal_; }
private:
const bool is_fatal_;
diff --git a/compiler/optimizing/code_generator_arm64.h b/compiler/optimizing/code_generator_arm64.h
index f0d7910..f1dc7ee 100644
--- a/compiler/optimizing/code_generator_arm64.h
+++ b/compiler/optimizing/code_generator_arm64.h
@@ -644,10 +644,10 @@
// artReadBarrierForRootSlow.
void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
- void GenerateNop();
+ void GenerateNop() OVERRIDE;
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
private:
using Uint64ToLiteralMap = ArenaSafeMap<uint64_t, vixl::aarch64::Literal<uint64_t>*>;
diff --git a/compiler/optimizing/code_generator_mips.h b/compiler/optimizing/code_generator_mips.h
index 956a466..a42374f 100644
--- a/compiler/optimizing/code_generator_mips.h
+++ b/compiler/optimizing/code_generator_mips.h
@@ -329,10 +329,10 @@
void SetupBlockedRegisters() const OVERRIDE;
- size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id);
- size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id);
- size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id);
- size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id);
+ size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
void ClobberRA() {
clobbered_ra_ = true;
}
@@ -363,7 +363,7 @@
void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE;
- void MoveConstant(Location destination, int32_t value);
+ void MoveConstant(Location destination, int32_t value) OVERRIDE;
void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
@@ -375,7 +375,7 @@
ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; }
- bool NeedsTwoRegisters(Primitive::Type type) const {
+ bool NeedsTwoRegisters(Primitive::Type type) const OVERRIDE {
return type == Primitive::kPrimLong;
}
@@ -403,9 +403,9 @@
UNIMPLEMENTED(FATAL) << "Not implemented on MIPS";
}
- void GenerateNop();
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateNop() OVERRIDE;
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
// The PcRelativePatchInfo is used for PC-relative addressing of dex cache arrays
// and boot image strings. The only difference is the interpretation of the offset_or_index.
diff --git a/compiler/optimizing/code_generator_mips64.h b/compiler/optimizing/code_generator_mips64.h
index 3910530..2dd409a 100644
--- a/compiler/optimizing/code_generator_mips64.h
+++ b/compiler/optimizing/code_generator_mips64.h
@@ -285,10 +285,10 @@
void SetupBlockedRegisters() const OVERRIDE;
- size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id);
- size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id);
- size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id);
- size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id);
+ size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
@@ -327,7 +327,7 @@
ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; }
- bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const { return false; }
+ bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { return false; }
// Check if the desired_string_load_kind is supported. If it is, return it,
// otherwise return a fall-back kind that should be used instead.
@@ -353,9 +353,9 @@
UNIMPLEMENTED(FATAL) << "Not implemented on MIPS64";
}
- void GenerateNop();
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateNop() OVERRIDE;
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
private:
// Labels for each block that will be compiled.
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index 28db29c..0518213 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -1069,15 +1069,11 @@
__ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>());
} else if (source.IsConstant()) {
HConstant* constant = source.GetConstant();
- int64_t value;
- if (constant->IsLongConstant()) {
- value = constant->AsLongConstant()->GetValue();
- } else {
- DCHECK(constant->IsDoubleConstant());
- value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue());
- }
+ DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant());
+ int64_t value = GetInt64ValueOf(constant);
__ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value)));
- __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value)));
+ __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)),
+ Immediate(High32Bits(value)));
} else {
DCHECK(source.IsDoubleStackSlot()) << source;
EmitParallelMoves(
@@ -1427,14 +1423,7 @@
Location lhs = condition->GetLocations()->InAt(0);
Location rhs = condition->GetLocations()->InAt(1);
// LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition).
- if (rhs.IsRegister()) {
- __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>());
- } else if (rhs.IsConstant()) {
- int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant());
- codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant);
- } else {
- __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex()));
- }
+ codegen_->GenerateIntCompare(lhs, rhs);
if (true_target == nullptr) {
__ j(X86Condition(condition->GetOppositeCondition()), false_target);
} else {
@@ -1528,18 +1517,6 @@
locations->SetOut(Location::SameAsFirstInput());
}
-void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) {
- Register lhs_reg = lhs.AsRegister<Register>();
- if (rhs.IsConstant()) {
- int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant());
- Compare32BitValue(lhs_reg, value);
- } else if (rhs.IsStackSlot()) {
- assembler_.cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex()));
- } else {
- assembler_.cmpl(lhs_reg, rhs.AsRegister<Register>());
- }
-}
-
void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) {
LocationSummary* locations = select->GetLocations();
DCHECK(locations->InAt(0).Equals(locations->Out()));
@@ -3621,7 +3598,7 @@
} else {
DCHECK(value.IsConstant()) << value;
if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
- __ jmp(slow_path->GetEntryLabel());
+ __ jmp(slow_path->GetEntryLabel());
}
}
break;
@@ -5033,56 +5010,31 @@
switch (type) {
case Primitive::kPrimBoolean: {
Register out = out_loc.AsRegister<Register>();
- if (index.IsConstant()) {
- __ movzxb(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
- } else {
- __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset));
- }
+ __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset));
break;
}
case Primitive::kPrimByte: {
Register out = out_loc.AsRegister<Register>();
- if (index.IsConstant()) {
- __ movsxb(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
- } else {
- __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset));
- }
+ __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset));
break;
}
case Primitive::kPrimShort: {
Register out = out_loc.AsRegister<Register>();
- if (index.IsConstant()) {
- __ movsxw(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
- } else {
- __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset));
- }
+ __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset));
break;
}
case Primitive::kPrimChar: {
Register out = out_loc.AsRegister<Register>();
- if (index.IsConstant()) {
- __ movzxw(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
- } else {
- __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset));
- }
+ __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset));
break;
}
case Primitive::kPrimInt: {
Register out = out_loc.AsRegister<Register>();
- if (index.IsConstant()) {
- __ movl(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
- } else {
- __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset));
- }
+ __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset));
break;
}
@@ -5099,21 +5051,16 @@
instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true);
} else {
Register out = out_loc.AsRegister<Register>();
+ __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset));
+ codegen_->MaybeRecordImplicitNullCheck(instruction);
+ // If read barriers are enabled, emit read barriers other than
+ // Baker's using a slow path (and also unpoison the loaded
+ // reference, if heap poisoning is enabled).
if (index.IsConstant()) {
uint32_t offset =
(index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
- __ movl(out, Address(obj, offset));
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- // If read barriers are enabled, emit read barriers other than
- // Baker's using a slow path (and also unpoison the loaded
- // reference, if heap poisoning is enabled).
codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
} else {
- __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset));
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- // If read barriers are enabled, emit read barriers other than
- // Baker's using a slow path (and also unpoison the loaded
- // reference, if heap poisoning is enabled).
codegen_->MaybeGenerateReadBarrierSlow(
instruction, out_loc, out_loc, obj_loc, data_offset, index);
}
@@ -5123,40 +5070,23 @@
case Primitive::kPrimLong: {
DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>());
- if (index.IsConstant()) {
- size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
- __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset));
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize));
- } else {
- __ movl(out_loc.AsRegisterPairLow<Register>(),
- Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset));
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- __ movl(out_loc.AsRegisterPairHigh<Register>(),
- Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize));
- }
+ __ movl(out_loc.AsRegisterPairLow<Register>(),
+ CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset));
+ codegen_->MaybeRecordImplicitNullCheck(instruction);
+ __ movl(out_loc.AsRegisterPairHigh<Register>(),
+ CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize));
break;
}
case Primitive::kPrimFloat: {
XmmRegister out = out_loc.AsFpuRegister<XmmRegister>();
- if (index.IsConstant()) {
- __ movss(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
- } else {
- __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset));
- }
+ __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset));
break;
}
case Primitive::kPrimDouble: {
XmmRegister out = out_loc.AsFpuRegister<XmmRegister>();
- if (index.IsConstant()) {
- __ movsd(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset));
- } else {
- __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset));
- }
+ __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset));
break;
}
@@ -5227,9 +5157,7 @@
case Primitive::kPrimBoolean:
case Primitive::kPrimByte: {
uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset)
- : Address(array, index.AsRegister<Register>(), TIMES_1, offset);
+ Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset);
if (value.IsRegister()) {
__ movb(address, value.AsRegister<ByteRegister>());
} else {
@@ -5242,9 +5170,7 @@
case Primitive::kPrimShort:
case Primitive::kPrimChar: {
uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset)
- : Address(array, index.AsRegister<Register>(), TIMES_2, offset);
+ Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset);
if (value.IsRegister()) {
__ movw(address, value.AsRegister<Register>());
} else {
@@ -5256,9 +5182,7 @@
case Primitive::kPrimNot: {
uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset)
- : Address(array, index.AsRegister<Register>(), TIMES_4, offset);
+ Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset);
if (!value.IsRegister()) {
// Just setting null.
@@ -5354,9 +5278,7 @@
case Primitive::kPrimInt: {
uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset)
- : Address(array, index.AsRegister<Register>(), TIMES_4, offset);
+ Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset);
if (value.IsRegister()) {
__ movl(address, value.AsRegister<Register>());
} else {
@@ -5370,44 +5292,27 @@
case Primitive::kPrimLong: {
uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
- if (index.IsConstant()) {
- size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
- if (value.IsRegisterPair()) {
- __ movl(Address(array, offset), value.AsRegisterPairLow<Register>());
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>());
- } else {
- DCHECK(value.IsConstant());
- int64_t val = value.GetConstant()->AsLongConstant()->GetValue();
- __ movl(Address(array, offset), Immediate(Low32Bits(val)));
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val)));
- }
+ if (value.IsRegisterPair()) {
+ __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset),
+ value.AsRegisterPairLow<Register>());
+ codegen_->MaybeRecordImplicitNullCheck(instruction);
+ __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize),
+ value.AsRegisterPairHigh<Register>());
} else {
- if (value.IsRegisterPair()) {
- __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset),
- value.AsRegisterPairLow<Register>());
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize),
- value.AsRegisterPairHigh<Register>());
- } else {
- DCHECK(value.IsConstant());
- int64_t val = value.GetConstant()->AsLongConstant()->GetValue();
- __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset),
- Immediate(Low32Bits(val)));
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize),
- Immediate(High32Bits(val)));
- }
+ DCHECK(value.IsConstant());
+ int64_t val = value.GetConstant()->AsLongConstant()->GetValue();
+ __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset),
+ Immediate(Low32Bits(val)));
+ codegen_->MaybeRecordImplicitNullCheck(instruction);
+ __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize),
+ Immediate(High32Bits(val)));
}
break;
}
case Primitive::kPrimFloat: {
uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset)
- : Address(array, index.AsRegister<Register>(), TIMES_4, offset);
+ Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset);
if (value.IsFpuRegister()) {
__ movss(address, value.AsFpuRegister<XmmRegister>());
} else {
@@ -5421,17 +5326,13 @@
case Primitive::kPrimDouble: {
uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset)
- : Address(array, index.AsRegister<Register>(), TIMES_8, offset);
+ Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset);
if (value.IsFpuRegister()) {
__ movsd(address, value.AsFpuRegister<XmmRegister>());
} else {
DCHECK(value.IsConstant());
- Address address_hi = index.IsConstant() ?
- Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) +
- offset + kX86WordSize) :
- Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize);
+ Address address_hi =
+ CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize);
int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue());
__ movl(address, Immediate(Low32Bits(v)));
codegen_->MaybeRecordImplicitNullCheck(instruction);
@@ -5525,13 +5426,7 @@
}
codegen_->MaybeRecordImplicitNullCheck(array_length);
} else {
- Register length = length_loc.AsRegister<Register>();
- if (index_loc.IsConstant()) {
- int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant());
- __ cmpl(length, Immediate(value));
- } else {
- __ cmpl(length, index_loc.AsRegister<Register>());
- }
+ codegen_->GenerateIntCompare(length_loc, index_loc);
}
codegen_->AddSlowPath(slow_path);
__ j(kBelowEqual, slow_path->GetEntryLabel());
@@ -6909,9 +6804,7 @@
"art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
// /* HeapReference<Object> */ ref =
// *(obj + data_offset + index * sizeof(HeapReference<Object>))
- Address src = index.IsConstant() ?
- Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) :
- Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset);
+ Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset);
GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check);
}
@@ -7392,6 +7285,27 @@
}
}
+void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) {
+ Register lhs_reg = lhs.AsRegister<Register>();
+ if (rhs.IsConstant()) {
+ int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant());
+ Compare32BitValue(lhs_reg, value);
+ } else if (rhs.IsStackSlot()) {
+ __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex()));
+ } else {
+ __ cmpl(lhs_reg, rhs.AsRegister<Register>());
+ }
+}
+
+Address CodeGeneratorX86::ArrayAddress(Register obj,
+ Location index,
+ ScaleFactor scale,
+ uint32_t data_offset) {
+ return index.IsConstant() ?
+ Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) :
+ Address(obj, index.AsRegister<Register>(), scale, data_offset);
+}
+
Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr,
Register reg,
Register value) {
diff --git a/compiler/optimizing/code_generator_x86.h b/compiler/optimizing/code_generator_x86.h
index e225098..5866e65 100644
--- a/compiler/optimizing/code_generator_x86.h
+++ b/compiler/optimizing/code_generator_x86.h
@@ -427,8 +427,6 @@
Register value,
bool value_can_be_null);
- void GenerateIntCompare(Location lhs, Location rhs);
-
void GenerateMemoryBarrier(MemBarrierKind kind);
Label* GetLabelOf(HBasicBlock* block) const {
@@ -474,6 +472,15 @@
// Compare a register with a 32-bit value in the most efficient manner.
void Compare32BitValue(Register dest, int32_t value);
+ // Compare int values. Supports only register locations for `lhs`.
+ void GenerateIntCompare(Location lhs, Location rhs);
+
+ // Construct address for array access.
+ static Address ArrayAddress(Register obj,
+ Location index,
+ ScaleFactor scale,
+ uint32_t data_offset);
+
Address LiteralCaseTable(HX86PackedSwitch* switch_instr, Register reg, Register value);
void Finalize(CodeAllocator* allocator) OVERRIDE;
@@ -561,9 +568,9 @@
}
}
- void GenerateNop();
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateNop() OVERRIDE;
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
// When we don't know the proper offset for the value, we use kDummy32BitOffset.
// The correct value will be inserted when processing Assembler fixups.
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index 88d98fc..506a7b1 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -1204,13 +1204,8 @@
source.AsFpuRegister<XmmRegister>());
} else if (source.IsConstant()) {
HConstant* constant = source.GetConstant();
- int64_t value;
- if (constant->IsDoubleConstant()) {
- value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue());
- } else {
- DCHECK(constant->IsLongConstant());
- value = constant->AsLongConstant()->GetValue();
- }
+ DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant());
+ int64_t value = GetInt64ValueOf(constant);
Store64BitValueToStack(destination, value);
} else {
DCHECK(source.IsDoubleStackSlot());
@@ -1309,31 +1304,11 @@
case Primitive::kPrimShort:
case Primitive::kPrimInt:
case Primitive::kPrimNot: {
- CpuRegister left_reg = left.AsRegister<CpuRegister>();
- if (right.IsConstant()) {
- int32_t value = CodeGenerator::GetInt32ValueOf(right.GetConstant());
- if (value == 0) {
- __ testl(left_reg, left_reg);
- } else {
- __ cmpl(left_reg, Immediate(value));
- }
- } else if (right.IsStackSlot()) {
- __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex()));
- } else {
- __ cmpl(left_reg, right.AsRegister<CpuRegister>());
- }
+ codegen_->GenerateIntCompare(left, right);
break;
}
case Primitive::kPrimLong: {
- CpuRegister left_reg = left.AsRegister<CpuRegister>();
- if (right.IsConstant()) {
- int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
- codegen_->Compare64BitValue(left_reg, value);
- } else if (right.IsDoubleStackSlot()) {
- __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex()));
- } else {
- __ cmpq(left_reg, right.AsRegister<CpuRegister>());
- }
+ codegen_->GenerateLongCompare(left, right);
break;
}
case Primitive::kPrimFloat: {
@@ -1488,15 +1463,7 @@
Location lhs = condition->GetLocations()->InAt(0);
Location rhs = condition->GetLocations()->InAt(1);
- if (rhs.IsRegister()) {
- __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>());
- } else if (rhs.IsConstant()) {
- int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant());
- codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant);
- } else {
- __ cmpl(lhs.AsRegister<CpuRegister>(),
- Address(CpuRegister(RSP), rhs.GetStackIndex()));
- }
+ codegen_->GenerateIntCompare(lhs, rhs);
if (true_target == nullptr) {
__ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target);
} else {
@@ -1696,28 +1663,14 @@
// Clear output register: setcc only sets the low byte.
__ xorl(reg, reg);
- if (rhs.IsRegister()) {
- __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>());
- } else if (rhs.IsConstant()) {
- int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant());
- codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant);
- } else {
- __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex()));
- }
+ codegen_->GenerateIntCompare(lhs, rhs);
__ setcc(X86_64IntegerCondition(cond->GetCondition()), reg);
return;
case Primitive::kPrimLong:
// Clear output register: setcc only sets the low byte.
__ xorl(reg, reg);
- if (rhs.IsRegister()) {
- __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>());
- } else if (rhs.IsConstant()) {
- int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue();
- codegen_->Compare64BitValue(lhs.AsRegister<CpuRegister>(), value);
- } else {
- __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex()));
- }
+ codegen_->GenerateLongCompare(lhs, rhs);
__ setcc(X86_64IntegerCondition(cond->GetCondition()), reg);
return;
case Primitive::kPrimFloat: {
@@ -1885,27 +1838,11 @@
case Primitive::kPrimShort:
case Primitive::kPrimChar:
case Primitive::kPrimInt: {
- CpuRegister left_reg = left.AsRegister<CpuRegister>();
- if (right.IsConstant()) {
- int32_t value = right.GetConstant()->AsIntConstant()->GetValue();
- codegen_->Compare32BitValue(left_reg, value);
- } else if (right.IsStackSlot()) {
- __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex()));
- } else {
- __ cmpl(left_reg, right.AsRegister<CpuRegister>());
- }
+ codegen_->GenerateIntCompare(left, right);
break;
}
case Primitive::kPrimLong: {
- CpuRegister left_reg = left.AsRegister<CpuRegister>();
- if (right.IsConstant()) {
- int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
- codegen_->Compare64BitValue(left_reg, value);
- } else if (right.IsDoubleStackSlot()) {
- __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex()));
- } else {
- __ cmpq(left_reg, right.AsRegister<CpuRegister>());
- }
+ codegen_->GenerateLongCompare(left, right);
break;
}
case Primitive::kPrimFloat: {
@@ -3714,7 +3651,7 @@
} else {
DCHECK(value.IsConstant()) << value;
if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
- __ jmp(slow_path->GetEntryLabel());
+ __ jmp(slow_path->GetEntryLabel());
}
}
break;
@@ -3729,7 +3666,7 @@
} else {
DCHECK(value.IsConstant()) << value;
if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
- __ jmp(slow_path->GetEntryLabel());
+ __ jmp(slow_path->GetEntryLabel());
}
}
break;
@@ -4538,56 +4475,31 @@
switch (type) {
case Primitive::kPrimBoolean: {
CpuRegister out = out_loc.AsRegister<CpuRegister>();
- if (index.IsConstant()) {
- __ movzxb(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
- } else {
- __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset));
- }
+ __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset));
break;
}
case Primitive::kPrimByte: {
CpuRegister out = out_loc.AsRegister<CpuRegister>();
- if (index.IsConstant()) {
- __ movsxb(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
- } else {
- __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset));
- }
+ __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset));
break;
}
case Primitive::kPrimShort: {
CpuRegister out = out_loc.AsRegister<CpuRegister>();
- if (index.IsConstant()) {
- __ movsxw(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
- } else {
- __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset));
- }
+ __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset));
break;
}
case Primitive::kPrimChar: {
CpuRegister out = out_loc.AsRegister<CpuRegister>();
- if (index.IsConstant()) {
- __ movzxw(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
- } else {
- __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset));
- }
+ __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset));
break;
}
case Primitive::kPrimInt: {
CpuRegister out = out_loc.AsRegister<CpuRegister>();
- if (index.IsConstant()) {
- __ movl(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
- } else {
- __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset));
- }
+ __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset));
break;
}
@@ -4604,21 +4516,16 @@
instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true);
} else {
CpuRegister out = out_loc.AsRegister<CpuRegister>();
+ __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset));
+ codegen_->MaybeRecordImplicitNullCheck(instruction);
+ // If read barriers are enabled, emit read barriers other than
+ // Baker's using a slow path (and also unpoison the loaded
+ // reference, if heap poisoning is enabled).
if (index.IsConstant()) {
uint32_t offset =
(index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
- __ movl(out, Address(obj, offset));
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- // If read barriers are enabled, emit read barriers other than
- // Baker's using a slow path (and also unpoison the loaded
- // reference, if heap poisoning is enabled).
codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
} else {
- __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset));
- codegen_->MaybeRecordImplicitNullCheck(instruction);
- // If read barriers are enabled, emit read barriers other than
- // Baker's using a slow path (and also unpoison the loaded
- // reference, if heap poisoning is enabled).
codegen_->MaybeGenerateReadBarrierSlow(
instruction, out_loc, out_loc, obj_loc, data_offset, index);
}
@@ -4628,34 +4535,19 @@
case Primitive::kPrimLong: {
CpuRegister out = out_loc.AsRegister<CpuRegister>();
- if (index.IsConstant()) {
- __ movq(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset));
- } else {
- __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset));
- }
+ __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset));
break;
}
case Primitive::kPrimFloat: {
XmmRegister out = out_loc.AsFpuRegister<XmmRegister>();
- if (index.IsConstant()) {
- __ movss(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
- } else {
- __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset));
- }
+ __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset));
break;
}
case Primitive::kPrimDouble: {
XmmRegister out = out_loc.AsFpuRegister<XmmRegister>();
- if (index.IsConstant()) {
- __ movsd(out, Address(obj,
- (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset));
- } else {
- __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset));
- }
+ __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset));
break;
}
@@ -4718,9 +4610,7 @@
case Primitive::kPrimBoolean:
case Primitive::kPrimByte: {
uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset)
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset);
+ Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset);
if (value.IsRegister()) {
__ movb(address, value.AsRegister<CpuRegister>());
} else {
@@ -4733,9 +4623,7 @@
case Primitive::kPrimShort:
case Primitive::kPrimChar: {
uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset)
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset);
+ Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset);
if (value.IsRegister()) {
__ movw(address, value.AsRegister<CpuRegister>());
} else {
@@ -4748,9 +4636,7 @@
case Primitive::kPrimNot: {
uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset)
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset);
+ Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset);
if (!value.IsRegister()) {
// Just setting null.
@@ -4846,9 +4732,7 @@
case Primitive::kPrimInt: {
uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset)
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset);
+ Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset);
if (value.IsRegister()) {
__ movl(address, value.AsRegister<CpuRegister>());
} else {
@@ -4862,18 +4746,14 @@
case Primitive::kPrimLong: {
uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset)
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset);
+ Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset);
if (value.IsRegister()) {
__ movq(address, value.AsRegister<CpuRegister>());
codegen_->MaybeRecordImplicitNullCheck(instruction);
} else {
int64_t v = value.GetConstant()->AsLongConstant()->GetValue();
- Address address_high = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) +
- offset + sizeof(int32_t))
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t));
+ Address address_high =
+ CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t));
codegen_->MoveInt64ToAddress(address, address_high, v, instruction);
}
break;
@@ -4881,15 +4761,12 @@
case Primitive::kPrimFloat: {
uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset)
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset);
+ Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset);
if (value.IsFpuRegister()) {
__ movss(address, value.AsFpuRegister<XmmRegister>());
} else {
DCHECK(value.IsConstant());
- int32_t v =
- bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue());
+ int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue());
__ movl(address, Immediate(v));
}
codegen_->MaybeRecordImplicitNullCheck(instruction);
@@ -4898,19 +4775,15 @@
case Primitive::kPrimDouble: {
uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
- Address address = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset)
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset);
+ Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset);
if (value.IsFpuRegister()) {
__ movsd(address, value.AsFpuRegister<XmmRegister>());
codegen_->MaybeRecordImplicitNullCheck(instruction);
} else {
int64_t v =
bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue());
- Address address_high = index.IsConstant()
- ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) +
- offset + sizeof(int32_t))
- : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t));
+ Address address_high =
+ CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t));
codegen_->MoveInt64ToAddress(address, address_high, v, instruction);
}
break;
@@ -5001,13 +4874,7 @@
}
codegen_->MaybeRecordImplicitNullCheck(array_length);
} else {
- CpuRegister length = length_loc.AsRegister<CpuRegister>();
- if (index_loc.IsConstant()) {
- int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant());
- __ cmpl(length, Immediate(value));
- } else {
- __ cmpl(length, index_loc.AsRegister<CpuRegister>());
- }
+ codegen_->GenerateIntCompare(length_loc, index_loc);
}
codegen_->AddSlowPath(slow_path);
__ j(kBelowEqual, slow_path->GetEntryLabel());
@@ -6361,9 +6228,7 @@
"art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
// /* HeapReference<Object> */ ref =
// *(obj + data_offset + index * sizeof(HeapReference<Object>))
- Address src = index.IsConstant() ?
- Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) :
- Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset);
+ Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset);
GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check);
}
@@ -6668,6 +6533,39 @@
}
}
+void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) {
+ CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>();
+ if (rhs.IsConstant()) {
+ int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant());
+ Compare32BitValue(lhs_reg, value);
+ } else if (rhs.IsStackSlot()) {
+ __ cmpl(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex()));
+ } else {
+ __ cmpl(lhs_reg, rhs.AsRegister<CpuRegister>());
+ }
+}
+
+void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) {
+ CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>();
+ if (rhs.IsConstant()) {
+ int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue();
+ Compare64BitValue(lhs_reg, value);
+ } else if (rhs.IsDoubleStackSlot()) {
+ __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex()));
+ } else {
+ __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>());
+ }
+}
+
+Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj,
+ Location index,
+ ScaleFactor scale,
+ uint32_t data_offset) {
+ return index.IsConstant() ?
+ Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) :
+ Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset);
+}
+
void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) {
DCHECK(dest.IsDoubleStackSlot());
if (IsInt<32>(value)) {
diff --git a/compiler/optimizing/code_generator_x86_64.h b/compiler/optimizing/code_generator_x86_64.h
index d939083..7108676 100644
--- a/compiler/optimizing/code_generator_x86_64.h
+++ b/compiler/optimizing/code_generator_x86_64.h
@@ -510,6 +510,18 @@
void Compare32BitValue(CpuRegister dest, int32_t value);
void Compare64BitValue(CpuRegister dest, int64_t value);
+ // Compare int values. Supports only register locations for `lhs`.
+ void GenerateIntCompare(Location lhs, Location rhs);
+
+ // Compare long values. Supports only register locations for `lhs`.
+ void GenerateLongCompare(Location lhs, Location rhs);
+
+ // Construct address for array access.
+ static Address ArrayAddress(CpuRegister obj,
+ Location index,
+ ScaleFactor scale,
+ uint32_t data_offset);
+
Address LiteralCaseTable(HPackedSwitch* switch_instr);
// Store a 64 bit value into a DoubleStackSlot in the most efficient manner.
@@ -533,9 +545,9 @@
}
}
- void GenerateNop();
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateNop() OVERRIDE;
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
// When we don't know the proper offset for the value, we use kDummy32BitOffset.
// We will fix this up in the linker later to have the right value.
diff --git a/compiler/optimizing/codegen_test.cc b/compiler/optimizing/codegen_test.cc
index d9347f6..070cbb3 100644
--- a/compiler/optimizing/codegen_test.cc
+++ b/compiler/optimizing/codegen_test.cc
@@ -1007,17 +1007,7 @@
}
TEST_F(CodegenTest, ComparisonsLong) {
- // TODO: make MIPS work for long
- if (kRuntimeISA == kMips || kRuntimeISA == kMips64) {
- return;
- }
-
for (CodegenTargetConfig target_config : GetTargetConfigs()) {
- if ((target_config.GetInstructionSet() == kMips) ||
- (target_config.GetInstructionSet() == kMips64)) {
- continue;
- }
-
for (int64_t i = -1; i <= 1; i++) {
for (int64_t j = -1; j <= 1; j++) {
for (int cond = kCondFirst; cond <= kCondLast; cond++) {
diff --git a/compiler/optimizing/dead_code_elimination.cc b/compiler/optimizing/dead_code_elimination.cc
index e1bde7c..aa3f268 100644
--- a/compiler/optimizing/dead_code_elimination.cc
+++ b/compiler/optimizing/dead_code_elimination.cc
@@ -16,7 +16,7 @@
#include "dead_code_elimination.h"
-#include "utils/array_ref.h"
+#include "base/array_ref.h"
#include "base/bit_vector-inl.h"
#include "ssa_phi_elimination.h"
diff --git a/compiler/optimizing/induction_var_range.cc b/compiler/optimizing/induction_var_range.cc
index 5e587e0..18e6f5c 100644
--- a/compiler/optimizing/induction_var_range.cc
+++ b/compiler/optimizing/induction_var_range.cc
@@ -143,42 +143,129 @@
// Find range.
chase_hint_ = chase_hint;
bool in_body = context->GetBlock() != loop->GetHeader();
+ int64_t stride_value = 0;
*min_val = GetVal(info, trip, in_body, /* is_min */ true);
*max_val = SimplifyMax(GetVal(info, trip, in_body, /* is_min */ false));
- *needs_finite_test = NeedsTripCount(info) && IsUnsafeTripCount(trip);
+ *needs_finite_test = NeedsTripCount(info, &stride_value) && IsUnsafeTripCount(trip);
return true;
}
-bool InductionVarRange::CanGenerateCode(HInstruction* context,
- HInstruction* instruction,
- /*out*/bool* needs_finite_test,
- /*out*/bool* needs_taken_test) {
+bool InductionVarRange::CanGenerateRange(HInstruction* context,
+ HInstruction* instruction,
+ /*out*/bool* needs_finite_test,
+ /*out*/bool* needs_taken_test) {
+ bool is_last_value = false;
+ int64_t stride_value = 0;
return GenerateCode(context,
instruction,
- nullptr, nullptr, nullptr, nullptr, nullptr, // nothing generated yet
+ is_last_value,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr, // nothing generated yet
+ &stride_value,
needs_finite_test,
- needs_taken_test);
+ needs_taken_test)
+ && (stride_value == -1 ||
+ stride_value == 0 ||
+ stride_value == 1); // avoid wrap-around anomalies.
}
-void InductionVarRange::GenerateRangeCode(HInstruction* context,
- HInstruction* instruction,
- HGraph* graph,
- HBasicBlock* block,
- /*out*/HInstruction** lower,
- /*out*/HInstruction** upper) {
+void InductionVarRange::GenerateRange(HInstruction* context,
+ HInstruction* instruction,
+ HGraph* graph,
+ HBasicBlock* block,
+ /*out*/HInstruction** lower,
+ /*out*/HInstruction** upper) {
+ bool is_last_value = false;
+ int64_t s = 0;
bool b1, b2; // unused
- if (!GenerateCode(context, instruction, graph, block, lower, upper, nullptr, &b1, &b2)) {
- LOG(FATAL) << "Failed precondition: GenerateCode()";
+ if (!GenerateCode(context,
+ instruction,
+ is_last_value,
+ graph,
+ block,
+ lower,
+ upper,
+ nullptr,
+ &s,
+ &b1,
+ &b2)) {
+ LOG(FATAL) << "Failed precondition: CanGenerateRange()";
}
}
-void InductionVarRange::GenerateTakenTest(HInstruction* context,
- HGraph* graph,
- HBasicBlock* block,
- /*out*/HInstruction** taken_test) {
+HInstruction* InductionVarRange::GenerateTakenTest(HInstruction* context,
+ HGraph* graph,
+ HBasicBlock* block) {
+ HInstruction* taken_test = nullptr;
+ bool is_last_value = false;
+ int64_t stride_value = 0;
bool b1, b2; // unused
- if (!GenerateCode(context, context, graph, block, nullptr, nullptr, taken_test, &b1, &b2)) {
- LOG(FATAL) << "Failed precondition: GenerateCode()";
+ if (!GenerateCode(context,
+ context,
+ is_last_value,
+ graph,
+ block,
+ nullptr,
+ nullptr,
+ &taken_test,
+ &stride_value,
+ &b1,
+ &b2)) {
+ LOG(FATAL) << "Failed precondition: CanGenerateRange()";
+ }
+ return taken_test;
+}
+
+bool InductionVarRange::CanGenerateLastValue(HInstruction* instruction) {
+ bool is_last_value = true;
+ int64_t stride_value = 0;
+ bool needs_finite_test = false;
+ bool needs_taken_test = false;
+ return GenerateCode(instruction,
+ instruction,
+ is_last_value,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr, // nothing generated yet
+ &stride_value, &needs_finite_test, &needs_taken_test)
+ && !needs_finite_test && !needs_taken_test;
+}
+
+HInstruction* InductionVarRange::GenerateLastValue(HInstruction* instruction,
+ HGraph* graph,
+ HBasicBlock* block) {
+ HInstruction* last_value = nullptr;
+ bool is_last_value = true;
+ int64_t stride_value = 0;
+ bool b1, b2; // unused
+ if (!GenerateCode(instruction,
+ instruction,
+ is_last_value,
+ graph,
+ block,
+ &last_value,
+ &last_value,
+ nullptr,
+ &stride_value,
+ &b1,
+ &b2)) {
+ LOG(FATAL) << "Failed precondition: CanGenerateLastValue()";
+ }
+ return last_value;
+}
+
+void InductionVarRange::Replace(HInstruction* instruction,
+ HInstruction* fetch,
+ HInstruction* replacement) {
+ for (HLoopInformation* lp = instruction->GetBlock()->GetLoopInformation(); // closest enveloping loop
+ lp != nullptr;
+ lp = lp->GetPreHeader()->GetLoopInformation()) {
+ ReplaceInduction(induction_analysis_->LookupInfo(lp, instruction), fetch, replacement);
}
}
@@ -260,12 +347,13 @@
return false;
}
-bool InductionVarRange::NeedsTripCount(HInductionVarAnalysis::InductionInfo* info) const {
+bool InductionVarRange::NeedsTripCount(HInductionVarAnalysis::InductionInfo* info,
+ int64_t* stride_value) const {
if (info != nullptr) {
if (info->induction_class == HInductionVarAnalysis::kLinear) {
- return true;
+ return IsConstant(info->op_a, kExact, stride_value);
} else if (info->induction_class == HInductionVarAnalysis::kWrapAround) {
- return NeedsTripCount(info->op_b);
+ return NeedsTripCount(info->op_b, stride_value);
}
}
return false;
@@ -618,11 +706,13 @@
bool InductionVarRange::GenerateCode(HInstruction* context,
HInstruction* instruction,
+ bool is_last_value,
HGraph* graph,
HBasicBlock* block,
/*out*/HInstruction** lower,
/*out*/HInstruction** upper,
/*out*/HInstruction** taken_test,
+ /*out*/int64_t* stride_value,
/*out*/bool* needs_finite_test,
/*out*/bool* needs_taken_test) const {
HLoopInformation* loop = nullptr;
@@ -637,8 +727,19 @@
// code does not use the trip-count explicitly (since there could be an implicit relation
// between e.g. an invariant subscript and a not-taken condition).
bool in_body = context->GetBlock() != loop->GetHeader();
- *needs_finite_test = NeedsTripCount(info) && IsUnsafeTripCount(trip);
+ *stride_value = 0;
+ *needs_finite_test = NeedsTripCount(info, stride_value) && IsUnsafeTripCount(trip);
*needs_taken_test = IsBodyTripCount(trip);
+ // Handle last value request.
+ if (is_last_value) {
+ if (info->induction_class != HInductionVarAnalysis::kLinear) {
+ return false;
+ } else if (*stride_value > 0) {
+ lower = nullptr;
+ } else {
+ upper = nullptr;
+ }
+ }
// Code generation for taken test: generate the code when requested or otherwise analyze
// if code generation is feasible when taken test is needed.
if (taken_test != nullptr) {
@@ -666,6 +767,10 @@
bool in_body,
bool is_min) const {
if (info != nullptr) {
+ // If during codegen, the result is not needed (nullptr), simply return success.
+ if (graph != nullptr && result == nullptr) {
+ return true;
+ }
// Verify type safety.
Primitive::Type type = Primitive::kPrimInt;
if (info->type != type) {
@@ -757,25 +862,28 @@
}
break;
case HInductionVarAnalysis::kLinear: {
- // Linear induction a * i + b, for normalized 0 <= i < TC. Restrict to unit stride only
- // to avoid arithmetic wrap-around situations that are hard to guard against.
+ // Linear induction a * i + b, for normalized 0 <= i < TC. For ranges, this should
+ // be restricted to a unit stride to avoid arithmetic wrap-around situations that
+ // are harder to guard against. For a last value, requesting min/max based on any
+ // stride yields right value.
int64_t stride_value = 0;
if (IsConstant(info->op_a, kExact, &stride_value)) {
- if (stride_value == 1 || stride_value == -1) {
- const bool is_min_a = stride_value == 1 ? is_min : !is_min;
- if (GenerateCode(trip, trip, graph, block, &opa, in_body, is_min_a) &&
- GenerateCode(info->op_b, trip, graph, block, &opb, in_body, is_min)) {
- if (graph != nullptr) {
- HInstruction* oper;
- if (stride_value == 1) {
- oper = new (graph->GetArena()) HAdd(type, opa, opb);
- } else {
- oper = new (graph->GetArena()) HSub(type, opb, opa);
- }
- *result = Insert(block, oper);
+ const bool is_min_a = stride_value >= 0 ? is_min : !is_min;
+ if (GenerateCode(trip, trip, graph, block, &opa, in_body, is_min_a) &&
+ GenerateCode(info->op_b, trip, graph, block, &opb, in_body, is_min)) {
+ if (graph != nullptr) {
+ HInstruction* oper;
+ if (stride_value == 1) {
+ oper = new (graph->GetArena()) HAdd(type, opa, opb);
+ } else if (stride_value == -1) {
+ oper = new (graph->GetArena()) HSub(type, opb, opa);
+ } else {
+ HInstruction* mul = new (graph->GetArena()) HMul(type, graph->GetIntConstant(stride_value), opa);
+ oper = new (graph->GetArena()) HAdd(type, Insert(block, mul), opb);
}
- return true;
+ *result = Insert(block, oper);
}
+ return true;
}
}
break;
@@ -800,4 +908,18 @@
return false;
}
+void InductionVarRange::ReplaceInduction(HInductionVarAnalysis::InductionInfo* info,
+ HInstruction* fetch,
+ HInstruction* replacement) {
+ if (info != nullptr) {
+ if (info->induction_class == HInductionVarAnalysis::kInvariant &&
+ info->operation == HInductionVarAnalysis::kFetch &&
+ info->fetch == fetch) {
+ info->fetch = replacement;
+ }
+ ReplaceInduction(info->op_a, fetch, replacement);
+ ReplaceInduction(info->op_b, fetch, replacement);
+ }
+}
+
} // namespace art
diff --git a/compiler/optimizing/induction_var_range.h b/compiler/optimizing/induction_var_range.h
index 00aaa16..63850b3 100644
--- a/compiler/optimizing/induction_var_range.h
+++ b/compiler/optimizing/induction_var_range.h
@@ -76,10 +76,10 @@
* and need_taken test flags denote if an additional finite-test and/or taken-test
* are needed to protect the range evaluation inside its loop.
*/
- bool CanGenerateCode(HInstruction* context,
- HInstruction* instruction,
- /*out*/ bool* needs_finite_test,
- /*out*/ bool* needs_taken_test);
+ bool CanGenerateRange(HInstruction* context,
+ HInstruction* instruction,
+ /*out*/ bool* needs_finite_test,
+ /*out*/ bool* needs_taken_test);
/**
* Generates the actual code in the HIR for the lower and upper bound expressions on the
@@ -94,25 +94,42 @@
* lower: add x, 0
* upper: add x, 5
*
- * Precondition: CanGenerateCode() returns true.
+ * Precondition: CanGenerateRange() returns true.
*/
- void GenerateRangeCode(HInstruction* context,
- HInstruction* instruction,
- HGraph* graph,
- HBasicBlock* block,
- /*out*/ HInstruction** lower,
- /*out*/ HInstruction** upper);
+ void GenerateRange(HInstruction* context,
+ HInstruction* instruction,
+ HGraph* graph,
+ HBasicBlock* block,
+ /*out*/ HInstruction** lower,
+ /*out*/ HInstruction** upper);
/**
* Generates explicit taken-test for the loop in the given context. Code is generated in
- * given block and graph. The taken-test is returned in parameter test.
+ * given block and graph. Returns generated taken-test.
*
- * Precondition: CanGenerateCode() returns true and needs_taken_test is set.
+ * Precondition: CanGenerateRange() returns true and needs_taken_test is set.
*/
- void GenerateTakenTest(HInstruction* context,
- HGraph* graph,
- HBasicBlock* block,
- /*out*/ HInstruction** taken_test);
+ HInstruction* GenerateTakenTest(HInstruction* context, HGraph* graph, HBasicBlock* block);
+
+ /**
+ * Returns true if induction analysis is able to generate code for last value of
+ * the given instruction inside the closest enveloping loop.
+ */
+ bool CanGenerateLastValue(HInstruction* instruction);
+
+ /**
+ * Generates last value of the given instruction in the closest enveloping loop.
+ * Code is generated in given block and graph. Returns generated last value.
+ *
+ * Precondition: CanGenerateLastValue() returns true.
+ */
+ HInstruction* GenerateLastValue(HInstruction* instruction, HGraph* graph, HBasicBlock* block);
+
+ /**
+ * Updates all matching fetches with the given replacement in all induction information
+ * that is associated with the given instruction.
+ */
+ void Replace(HInstruction* instruction, HInstruction* fetch, HInstruction* replacement);
private:
/*
@@ -140,7 +157,8 @@
/*out*/ HInductionVarAnalysis::InductionInfo** trip) const;
bool HasFetchInLoop(HInductionVarAnalysis::InductionInfo* info) const;
- bool NeedsTripCount(HInductionVarAnalysis::InductionInfo* info) const;
+ bool NeedsTripCount(HInductionVarAnalysis::InductionInfo* info,
+ /*out*/ int64_t* stride_value) const;
bool IsBodyTripCount(HInductionVarAnalysis::InductionInfo* trip) const;
bool IsUnsafeTripCount(HInductionVarAnalysis::InductionInfo* trip) const;
bool IsWellBehavedTripCount(HInductionVarAnalysis::InductionInfo* trip) const;
@@ -186,17 +204,19 @@
Value MergeVal(Value v1, Value v2, bool is_min) const;
/**
- * Generates code for lower/upper/taken-test in the HIR. Returns true on success.
- * With values nullptr, the method can be used to determine if code generation
+ * Generates code for lower/upper/taken-test or last value in the HIR. Returns true on
+ * success. With values nullptr, the method can be used to determine if code generation
* would be successful without generating actual code yet.
*/
bool GenerateCode(HInstruction* context,
HInstruction* instruction,
+ bool is_last_val,
HGraph* graph,
HBasicBlock* block,
/*out*/ HInstruction** lower,
/*out*/ HInstruction** upper,
/*out*/ HInstruction** taken_test,
+ /*out*/ int64_t* stride_value,
/*out*/ bool* needs_finite_test,
/*out*/ bool* needs_taken_test) const;
@@ -208,6 +228,10 @@
bool in_body,
bool is_min) const;
+ void ReplaceInduction(HInductionVarAnalysis::InductionInfo* info,
+ HInstruction* fetch,
+ HInstruction* replacement);
+
/** Results of prior induction variable analysis. */
HInductionVarAnalysis* induction_analysis_;
diff --git a/compiler/optimizing/induction_var_range_test.cc b/compiler/optimizing/induction_var_range_test.cc
index 4ea170f..8bbdd4a 100644
--- a/compiler/optimizing/induction_var_range_test.cc
+++ b/compiler/optimizing/induction_var_range_test.cc
@@ -75,34 +75,34 @@
// Control flow.
loop_preheader_ = new (&allocator_) HBasicBlock(graph_);
graph_->AddBlock(loop_preheader_);
- HBasicBlock* loop_header = new (&allocator_) HBasicBlock(graph_);
- graph_->AddBlock(loop_header);
- HBasicBlock* loop_body = new (&allocator_) HBasicBlock(graph_);
- graph_->AddBlock(loop_body);
+ loop_header_ = new (&allocator_) HBasicBlock(graph_);
+ graph_->AddBlock(loop_header_);
+ loop_body_ = new (&allocator_) HBasicBlock(graph_);
+ graph_->AddBlock(loop_body_);
HBasicBlock* return_block = new (&allocator_) HBasicBlock(graph_);
graph_->AddBlock(return_block);
entry_block_->AddSuccessor(loop_preheader_);
- loop_preheader_->AddSuccessor(loop_header);
- loop_header->AddSuccessor(loop_body);
- loop_header->AddSuccessor(return_block);
- loop_body->AddSuccessor(loop_header);
+ loop_preheader_->AddSuccessor(loop_header_);
+ loop_header_->AddSuccessor(loop_body_);
+ loop_header_->AddSuccessor(return_block);
+ loop_body_->AddSuccessor(loop_header_);
return_block->AddSuccessor(exit_block_);
// Instructions.
loop_preheader_->AddInstruction(new (&allocator_) HGoto());
HPhi* phi = new (&allocator_) HPhi(&allocator_, 0, 0, Primitive::kPrimInt);
- loop_header->AddPhi(phi);
+ loop_header_->AddPhi(phi);
phi->AddInput(graph_->GetIntConstant(lower)); // i = l
if (stride > 0) {
condition_ = new (&allocator_) HLessThan(phi, upper); // i < u
} else {
condition_ = new (&allocator_) HGreaterThan(phi, upper); // i > u
}
- loop_header->AddInstruction(condition_);
- loop_header->AddInstruction(new (&allocator_) HIf(condition_));
+ loop_header_->AddInstruction(condition_);
+ loop_header_->AddInstruction(new (&allocator_) HIf(condition_));
increment_ = new (&allocator_) HAdd(Primitive::kPrimInt, phi, graph_->GetIntConstant(stride));
- loop_body->AddInstruction(increment_); // i += s
+ loop_body_->AddInstruction(increment_); // i += s
phi->AddInput(increment_);
- loop_body->AddInstruction(new (&allocator_) HGoto());
+ loop_body_->AddInstruction(new (&allocator_) HGoto());
return_block->AddInstruction(new (&allocator_) HReturnVoid());
exit_block_->AddInstruction(new (&allocator_) HExit());
}
@@ -192,7 +192,8 @@
//
bool NeedsTripCount(HInductionVarAnalysis::InductionInfo* info) {
- return range_.NeedsTripCount(info);
+ int64_t s = 0;
+ return range_.NeedsTripCount(info, &s);
}
bool IsBodyTripCount(HInductionVarAnalysis::InductionInfo* trip) {
@@ -251,6 +252,8 @@
HBasicBlock* entry_block_;
HBasicBlock* exit_block_;
HBasicBlock* loop_preheader_;
+ HBasicBlock* loop_header_;
+ HBasicBlock* loop_body_;
HInductionVarAnalysis* iva_;
InductionVarRange range_;
@@ -600,15 +603,19 @@
Value v1, v2;
bool needs_finite_test = true;
+ bool needs_taken_test = true;
+
+ HInstruction* phi = condition_->InputAt(0);
+ HInstruction* exit = exit_block_->GetLastInstruction();
// In context of header: known.
- range_.GetInductionRange(condition_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test);
+ range_.GetInductionRange(condition_, phi, x_, &v1, &v2, &needs_finite_test);
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(0), v1);
ExpectEqual(Value(1000), v2);
// In context of loop-body: known.
- range_.GetInductionRange(increment_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test);
+ range_.GetInductionRange(increment_, phi, x_, &v1, &v2, &needs_finite_test);
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(0), v1);
ExpectEqual(Value(999), v2);
@@ -616,6 +623,20 @@
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(1), v1);
ExpectEqual(Value(1000), v2);
+
+ // Induction vs. no-induction.
+ EXPECT_TRUE(range_.CanGenerateRange(increment_, phi, &needs_finite_test, &needs_taken_test));
+ EXPECT_TRUE(range_.CanGenerateLastValue(phi));
+ EXPECT_FALSE(range_.CanGenerateRange(exit, exit, &needs_finite_test, &needs_taken_test));
+ EXPECT_FALSE(range_.CanGenerateLastValue(exit));
+
+ // Last value (unsimplified).
+ HInstruction* last = range_.GenerateLastValue(phi, graph_, loop_preheader_);
+ ASSERT_TRUE(last->IsAdd());
+ ASSERT_TRUE(last->InputAt(0)->IsIntConstant());
+ EXPECT_EQ(1000, last->InputAt(0)->AsIntConstant()->GetValue());
+ ASSERT_TRUE(last->InputAt(1)->IsIntConstant());
+ EXPECT_EQ(0, last->InputAt(1)->AsIntConstant()->GetValue());
}
TEST_F(InductionVarRangeTest, ConstantTripCountDown) {
@@ -624,15 +645,19 @@
Value v1, v2;
bool needs_finite_test = true;
+ bool needs_taken_test = true;
+
+ HInstruction* phi = condition_->InputAt(0);
+ HInstruction* exit = exit_block_->GetLastInstruction();
// In context of header: known.
- range_.GetInductionRange(condition_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test);
+ range_.GetInductionRange(condition_, phi, x_, &v1, &v2, &needs_finite_test);
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(0), v1);
ExpectEqual(Value(1000), v2);
// In context of loop-body: known.
- range_.GetInductionRange(increment_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test);
+ range_.GetInductionRange(increment_, phi, x_, &v1, &v2, &needs_finite_test);
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(1), v1);
ExpectEqual(Value(1000), v2);
@@ -640,6 +665,25 @@
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(0), v1);
ExpectEqual(Value(999), v2);
+
+ // Induction vs. no-induction.
+ EXPECT_TRUE(range_.CanGenerateRange(increment_, phi, &needs_finite_test, &needs_taken_test));
+ EXPECT_TRUE(range_.CanGenerateLastValue(phi));
+ EXPECT_FALSE(range_.CanGenerateRange(exit, exit, &needs_finite_test, &needs_taken_test));
+ EXPECT_FALSE(range_.CanGenerateLastValue(exit));
+
+ // Last value (unsimplified).
+ HInstruction* last = range_.GenerateLastValue(phi, graph_, loop_preheader_);
+ ASSERT_TRUE(last->IsSub());
+ ASSERT_TRUE(last->InputAt(0)->IsIntConstant());
+ EXPECT_EQ(1000, last->InputAt(0)->AsIntConstant()->GetValue());
+ ASSERT_TRUE(last->InputAt(1)->IsNeg());
+ last = last->InputAt(1)->InputAt(0);
+ ASSERT_TRUE(last->IsSub());
+ ASSERT_TRUE(last->InputAt(0)->IsIntConstant());
+ EXPECT_EQ(0, last->InputAt(0)->AsIntConstant()->GetValue());
+ ASSERT_TRUE(last->InputAt(1)->IsIntConstant());
+ EXPECT_EQ(1000, last->InputAt(1)->AsIntConstant()->GetValue());
}
TEST_F(InductionVarRangeTest, SymbolicTripCountUp) {
@@ -650,14 +694,16 @@
bool needs_finite_test = true;
bool needs_taken_test = true;
+ HInstruction* phi = condition_->InputAt(0);
+
// In context of header: upper unknown.
- range_.GetInductionRange(condition_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test);
+ range_.GetInductionRange(condition_, phi, x_, &v1, &v2, &needs_finite_test);
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(0), v1);
ExpectEqual(Value(), v2);
// In context of loop-body: known.
- range_.GetInductionRange(increment_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test);
+ range_.GetInductionRange(increment_, phi, x_, &v1, &v2, &needs_finite_test);
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(0), v1);
ExpectEqual(Value(x_, 1, -1), v2);
@@ -668,19 +714,15 @@
HInstruction* lower = nullptr;
HInstruction* upper = nullptr;
- HInstruction* taken = nullptr;
// Can generate code in context of loop-body only.
- EXPECT_FALSE(range_.CanGenerateCode(
- condition_, condition_->InputAt(0), &needs_finite_test, &needs_taken_test));
- ASSERT_TRUE(range_.CanGenerateCode(
- increment_, condition_->InputAt(0), &needs_finite_test, &needs_taken_test));
+ EXPECT_FALSE(range_.CanGenerateRange(condition_, phi, &needs_finite_test, &needs_taken_test));
+ ASSERT_TRUE(range_.CanGenerateRange(increment_, phi, &needs_finite_test, &needs_taken_test));
EXPECT_FALSE(needs_finite_test);
EXPECT_TRUE(needs_taken_test);
- // Generates code.
- range_.GenerateRangeCode(
- increment_, condition_->InputAt(0), graph_, loop_preheader_, &lower, &upper);
+ // Generates code (unsimplified).
+ range_.GenerateRange(increment_, phi, graph_, loop_preheader_, &lower, &upper);
// Verify lower is 0+0.
ASSERT_TRUE(lower != nullptr);
@@ -701,12 +743,19 @@
EXPECT_EQ(0, upper->InputAt(1)->AsIntConstant()->GetValue());
// Verify taken-test is 0<V.
- range_.GenerateTakenTest(increment_, graph_, loop_preheader_, &taken);
+ HInstruction* taken = range_.GenerateTakenTest(increment_, graph_, loop_preheader_);
ASSERT_TRUE(taken != nullptr);
ASSERT_TRUE(taken->IsLessThan());
ASSERT_TRUE(taken->InputAt(0)->IsIntConstant());
EXPECT_EQ(0, taken->InputAt(0)->AsIntConstant()->GetValue());
EXPECT_TRUE(taken->InputAt(1)->IsParameterValue());
+
+ // Replacement.
+ range_.Replace(loop_header_->GetLastInstruction(), x_, y_);
+ range_.GetInductionRange(increment_, increment_, x_, &v1, &v2, &needs_finite_test);
+ EXPECT_FALSE(needs_finite_test);
+ ExpectEqual(Value(1), v1);
+ ExpectEqual(Value(y_, 1, 0), v2);
}
TEST_F(InductionVarRangeTest, SymbolicTripCountDown) {
@@ -717,14 +766,16 @@
bool needs_finite_test = true;
bool needs_taken_test = true;
+ HInstruction* phi = condition_->InputAt(0);
+
// In context of header: lower unknown.
- range_.GetInductionRange(condition_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test);
+ range_.GetInductionRange(condition_, phi, x_, &v1, &v2, &needs_finite_test);
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(), v1);
ExpectEqual(Value(1000), v2);
// In context of loop-body: known.
- range_.GetInductionRange(increment_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test);
+ range_.GetInductionRange(increment_, phi, x_, &v1, &v2, &needs_finite_test);
EXPECT_FALSE(needs_finite_test);
ExpectEqual(Value(x_, 1, 1), v1);
ExpectEqual(Value(1000), v2);
@@ -735,19 +786,15 @@
HInstruction* lower = nullptr;
HInstruction* upper = nullptr;
- HInstruction* taken = nullptr;
// Can generate code in context of loop-body only.
- EXPECT_FALSE(range_.CanGenerateCode(
- condition_, condition_->InputAt(0), &needs_finite_test, &needs_taken_test));
- ASSERT_TRUE(range_.CanGenerateCode(
- increment_, condition_->InputAt(0), &needs_finite_test, &needs_taken_test));
+ EXPECT_FALSE(range_.CanGenerateRange(condition_, phi, &needs_finite_test, &needs_taken_test));
+ ASSERT_TRUE(range_.CanGenerateRange(increment_, phi, &needs_finite_test, &needs_taken_test));
EXPECT_FALSE(needs_finite_test);
EXPECT_TRUE(needs_taken_test);
- // Generates code.
- range_.GenerateRangeCode(
- increment_, condition_->InputAt(0), graph_, loop_preheader_, &lower, &upper);
+ // Generates code (unsimplified).
+ range_.GenerateRange(increment_, phi, graph_, loop_preheader_, &lower, &upper);
// Verify lower is 1000-((1000-V)-1).
ASSERT_TRUE(lower != nullptr);
@@ -773,12 +820,19 @@
EXPECT_EQ(0, upper->InputAt(1)->AsIntConstant()->GetValue());
// Verify taken-test is 1000>V.
- range_.GenerateTakenTest(increment_, graph_, loop_preheader_, &taken);
+ HInstruction* taken = range_.GenerateTakenTest(increment_, graph_, loop_preheader_);
ASSERT_TRUE(taken != nullptr);
ASSERT_TRUE(taken->IsGreaterThan());
ASSERT_TRUE(taken->InputAt(0)->IsIntConstant());
EXPECT_EQ(1000, taken->InputAt(0)->AsIntConstant()->GetValue());
EXPECT_TRUE(taken->InputAt(1)->IsParameterValue());
+
+ // Replacement.
+ range_.Replace(loop_header_->GetLastInstruction(), x_, y_);
+ range_.GetInductionRange(increment_, increment_, x_, &v1, &v2, &needs_finite_test);
+ EXPECT_FALSE(needs_finite_test);
+ ExpectEqual(Value(y_, 1, 0), v1);
+ ExpectEqual(Value(999), v2);
}
} // namespace art
diff --git a/compiler/optimizing/instruction_simplifier.h b/compiler/optimizing/instruction_simplifier.h
index 7905104..7fe1067 100644
--- a/compiler/optimizing/instruction_simplifier.h
+++ b/compiler/optimizing/instruction_simplifier.h
@@ -35,9 +35,9 @@
*/
class InstructionSimplifier : public HOptimization {
public:
- InstructionSimplifier(HGraph* graph,
- OptimizingCompilerStats* stats = nullptr,
- const char* name = kInstructionSimplifierPassName)
+ explicit InstructionSimplifier(HGraph* graph,
+ OptimizingCompilerStats* stats = nullptr,
+ const char* name = kInstructionSimplifierPassName)
: HOptimization(graph, name, stats) {}
static constexpr const char* kInstructionSimplifierPassName = "instruction_simplifier";
diff --git a/compiler/optimizing/locations.h b/compiler/optimizing/locations.h
index 4384042..c97c4a6 100644
--- a/compiler/optimizing/locations.h
+++ b/compiler/optimizing/locations.h
@@ -488,9 +488,9 @@
kCallOnMainOnly
};
- LocationSummary(HInstruction* instruction,
- CallKind call_kind = kNoCall,
- bool intrinsified = false);
+ explicit LocationSummary(HInstruction* instruction,
+ CallKind call_kind = kNoCall,
+ bool intrinsified = false);
void SetInAt(uint32_t at, Location location) {
inputs_[at] = location;
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 8f37236..9cfa89b 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -460,6 +460,113 @@
return kAnalysisSuccess;
}
+static bool InSameLoop(HLoopInformation* first_loop, HLoopInformation* second_loop) {
+ return first_loop == second_loop;
+}
+
+static bool IsLoop(HLoopInformation* info) {
+ return info != nullptr;
+}
+
+static bool IsInnerLoop(HLoopInformation* outer, HLoopInformation* inner) {
+ return (inner != outer)
+ && (inner != nullptr)
+ && (outer != nullptr)
+ && inner->IsIn(*outer);
+}
+
+// Helper method to update work list for linear order.
+static void AddToListForLinearization(ArenaVector<HBasicBlock*>* worklist, HBasicBlock* block) {
+ HLoopInformation* block_loop = block->GetLoopInformation();
+ auto insert_pos = worklist->rbegin(); // insert_pos.base() will be the actual position.
+ for (auto end = worklist->rend(); insert_pos != end; ++insert_pos) {
+ HBasicBlock* current = *insert_pos;
+ HLoopInformation* current_loop = current->GetLoopInformation();
+ if (InSameLoop(block_loop, current_loop)
+ || !IsLoop(current_loop)
+ || IsInnerLoop(current_loop, block_loop)) {
+ // The block can be processed immediately.
+ break;
+ }
+ }
+ worklist->insert(insert_pos.base(), block);
+}
+
+// Helper method to validate linear order.
+static bool IsLinearOrderWellFormed(const HGraph& graph) {
+ for (HBasicBlock* header : graph.GetBlocks()) {
+ if (header == nullptr || !header->IsLoopHeader()) {
+ continue;
+ }
+ HLoopInformation* loop = header->GetLoopInformation();
+ size_t num_blocks = loop->GetBlocks().NumSetBits();
+ size_t found_blocks = 0u;
+ for (HLinearOrderIterator it(graph); !it.Done(); it.Advance()) {
+ HBasicBlock* current = it.Current();
+ if (loop->Contains(*current)) {
+ found_blocks++;
+ if (found_blocks == 1u && current != header) {
+ // First block is not the header.
+ return false;
+ } else if (found_blocks == num_blocks && !loop->IsBackEdge(*current)) {
+ // Last block is not a back edge.
+ return false;
+ }
+ } else if (found_blocks != 0u && found_blocks != num_blocks) {
+ // Blocks are not adjacent.
+ return false;
+ }
+ }
+ DCHECK_EQ(found_blocks, num_blocks);
+ }
+ return true;
+}
+
+void HGraph::Linearize() {
+ // Create a reverse post ordering with the following properties:
+ // - Blocks in a loop are consecutive,
+ // - Back-edge is the last block before loop exits.
+
+ // (1): Record the number of forward predecessors for each block. This is to
+ // ensure the resulting order is reverse post order. We could use the
+ // current reverse post order in the graph, but it would require making
+ // order queries to a GrowableArray, which is not the best data structure
+ // for it.
+ ArenaVector<uint32_t> forward_predecessors(blocks_.size(),
+ arena_->Adapter(kArenaAllocSsaLiveness));
+ for (HReversePostOrderIterator it(*this); !it.Done(); it.Advance()) {
+ HBasicBlock* block = it.Current();
+ size_t number_of_forward_predecessors = block->GetPredecessors().size();
+ if (block->IsLoopHeader()) {
+ number_of_forward_predecessors -= block->GetLoopInformation()->NumberOfBackEdges();
+ }
+ forward_predecessors[block->GetBlockId()] = number_of_forward_predecessors;
+ }
+
+ // (2): Following a worklist approach, first start with the entry block, and
+ // iterate over the successors. When all non-back edge predecessors of a
+ // successor block are visited, the successor block is added in the worklist
+ // following an order that satisfies the requirements to build our linear graph.
+ linear_order_.reserve(GetReversePostOrder().size());
+ ArenaVector<HBasicBlock*> worklist(arena_->Adapter(kArenaAllocSsaLiveness));
+ worklist.push_back(GetEntryBlock());
+ do {
+ HBasicBlock* current = worklist.back();
+ worklist.pop_back();
+ linear_order_.push_back(current);
+ for (HBasicBlock* successor : current->GetSuccessors()) {
+ int block_id = successor->GetBlockId();
+ size_t number_of_remaining_predecessors = forward_predecessors[block_id];
+ if (number_of_remaining_predecessors == 1) {
+ AddToListForLinearization(&worklist, successor);
+ }
+ forward_predecessors[block_id] = number_of_remaining_predecessors - 1;
+ }
+ } while (!worklist.empty());
+
+ DCHECK(HasIrreducibleLoops() || IsLinearOrderWellFormed(*this));
+}
+
void HLoopInformation::Dump(std::ostream& os) {
os << "header: " << header_->GetBlockId() << std::endl;
os << "pre header: " << GetPreHeader()->GetBlockId() << std::endl;
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 119b62a..caecc57 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -24,7 +24,9 @@
#include "base/arena_bit_vector.h"
#include "base/arena_containers.h"
#include "base/arena_object.h"
+#include "base/array_ref.h"
#include "base/stl_util.h"
+#include "base/transform_array_ref.h"
#include "dex_file.h"
#include "entrypoints/quick/quick_entrypoints_enum.h"
#include "handle.h"
@@ -35,9 +37,7 @@
#include "mirror/class.h"
#include "offsets.h"
#include "primitive.h"
-#include "utils/array_ref.h"
#include "utils/intrusive_forward_list.h"
-#include "utils/transform_array_ref.h"
namespace art {
@@ -365,6 +365,13 @@
// is a throw-catch loop, i.e. the header is a catch block.
GraphAnalysisResult AnalyzeLoops() const;
+ // Computes the linear order (should be called before using HLinearOrderIterator).
+ // Linearizes the graph such that:
+ // (1): a block is always after its dominator,
+ // (2): blocks of loops are contiguous.
+ // This creates a natural and efficient ordering when visualizing live ranges.
+ void Linearize();
+
// Iterate over blocks to compute try block membership. Needs reverse post
// order and loop information.
void ComputeTryBlockInformation();
@@ -830,7 +837,7 @@
class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> {
public:
- HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc)
+ explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc)
: graph_(graph),
predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)),
successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)),
@@ -6275,7 +6282,7 @@
class HBoundType FINAL : public HExpression<1> {
public:
- HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc)
+ explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc)
: HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc),
upper_bound_(ReferenceTypeInfo::CreateInvalid()) {
SetPackedFlag<kFlagUpperCanBeNull>(true);
diff --git a/compiler/optimizing/register_allocation_resolver.h b/compiler/optimizing/register_allocation_resolver.h
index a70ceae..d48b1a0 100644
--- a/compiler/optimizing/register_allocation_resolver.h
+++ b/compiler/optimizing/register_allocation_resolver.h
@@ -18,9 +18,9 @@
#define ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/value_object.h"
#include "primitive.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/optimizing/ssa_liveness_analysis.cc b/compiler/optimizing/ssa_liveness_analysis.cc
index a4d52d7..9ce34aa 100644
--- a/compiler/optimizing/ssa_liveness_analysis.cc
+++ b/compiler/optimizing/ssa_liveness_analysis.cc
@@ -23,119 +23,11 @@
namespace art {
void SsaLivenessAnalysis::Analyze() {
- LinearizeGraph();
+ graph_->Linearize();
NumberInstructions();
ComputeLiveness();
}
-static bool IsLoop(HLoopInformation* info) {
- return info != nullptr;
-}
-
-static bool InSameLoop(HLoopInformation* first_loop, HLoopInformation* second_loop) {
- return first_loop == second_loop;
-}
-
-static bool IsInnerLoop(HLoopInformation* outer, HLoopInformation* inner) {
- return (inner != outer)
- && (inner != nullptr)
- && (outer != nullptr)
- && inner->IsIn(*outer);
-}
-
-static void AddToListForLinearization(ArenaVector<HBasicBlock*>* worklist, HBasicBlock* block) {
- HLoopInformation* block_loop = block->GetLoopInformation();
- auto insert_pos = worklist->rbegin(); // insert_pos.base() will be the actual position.
- for (auto end = worklist->rend(); insert_pos != end; ++insert_pos) {
- HBasicBlock* current = *insert_pos;
- HLoopInformation* current_loop = current->GetLoopInformation();
- if (InSameLoop(block_loop, current_loop)
- || !IsLoop(current_loop)
- || IsInnerLoop(current_loop, block_loop)) {
- // The block can be processed immediately.
- break;
- }
- }
- worklist->insert(insert_pos.base(), block);
-}
-
-static bool IsLinearOrderWellFormed(const HGraph& graph) {
- for (HBasicBlock* header : graph.GetBlocks()) {
- if (header == nullptr || !header->IsLoopHeader()) {
- continue;
- }
-
- HLoopInformation* loop = header->GetLoopInformation();
- size_t num_blocks = loop->GetBlocks().NumSetBits();
- size_t found_blocks = 0u;
-
- for (HLinearOrderIterator it(graph); !it.Done(); it.Advance()) {
- HBasicBlock* current = it.Current();
- if (loop->Contains(*current)) {
- found_blocks++;
- if (found_blocks == 1u && current != header) {
- // First block is not the header.
- return false;
- } else if (found_blocks == num_blocks && !loop->IsBackEdge(*current)) {
- // Last block is not a back edge.
- return false;
- }
- } else if (found_blocks != 0u && found_blocks != num_blocks) {
- // Blocks are not adjacent.
- return false;
- }
- }
- DCHECK_EQ(found_blocks, num_blocks);
- }
-
- return true;
-}
-
-void SsaLivenessAnalysis::LinearizeGraph() {
- // Create a reverse post ordering with the following properties:
- // - Blocks in a loop are consecutive,
- // - Back-edge is the last block before loop exits.
-
- // (1): Record the number of forward predecessors for each block. This is to
- // ensure the resulting order is reverse post order. We could use the
- // current reverse post order in the graph, but it would require making
- // order queries to a GrowableArray, which is not the best data structure
- // for it.
- ArenaVector<uint32_t> forward_predecessors(graph_->GetBlocks().size(),
- graph_->GetArena()->Adapter(kArenaAllocSsaLiveness));
- for (HReversePostOrderIterator it(*graph_); !it.Done(); it.Advance()) {
- HBasicBlock* block = it.Current();
- size_t number_of_forward_predecessors = block->GetPredecessors().size();
- if (block->IsLoopHeader()) {
- number_of_forward_predecessors -= block->GetLoopInformation()->NumberOfBackEdges();
- }
- forward_predecessors[block->GetBlockId()] = number_of_forward_predecessors;
- }
-
- // (2): Following a worklist approach, first start with the entry block, and
- // iterate over the successors. When all non-back edge predecessors of a
- // successor block are visited, the successor block is added in the worklist
- // following an order that satisfies the requirements to build our linear graph.
- graph_->linear_order_.reserve(graph_->GetReversePostOrder().size());
- ArenaVector<HBasicBlock*> worklist(graph_->GetArena()->Adapter(kArenaAllocSsaLiveness));
- worklist.push_back(graph_->GetEntryBlock());
- do {
- HBasicBlock* current = worklist.back();
- worklist.pop_back();
- graph_->linear_order_.push_back(current);
- for (HBasicBlock* successor : current->GetSuccessors()) {
- int block_id = successor->GetBlockId();
- size_t number_of_remaining_predecessors = forward_predecessors[block_id];
- if (number_of_remaining_predecessors == 1) {
- AddToListForLinearization(&worklist, successor);
- }
- forward_predecessors[block_id] = number_of_remaining_predecessors - 1;
- }
- } while (!worklist.empty());
-
- DCHECK(graph_->HasIrreducibleLoops() || IsLinearOrderWellFormed(*graph_));
-}
-
void SsaLivenessAnalysis::NumberInstructions() {
int ssa_index = 0;
size_t lifetime_position = 0;
diff --git a/compiler/optimizing/ssa_liveness_analysis.h b/compiler/optimizing/ssa_liveness_analysis.h
index 0be1611..b62bf4e 100644
--- a/compiler/optimizing/ssa_liveness_analysis.h
+++ b/compiler/optimizing/ssa_liveness_analysis.h
@@ -1186,12 +1186,6 @@
static constexpr const char* kLivenessPassName = "liveness";
private:
- // Linearize the graph so that:
- // (1): a block is always after its dominator,
- // (2): blocks of loops are contiguous.
- // This creates a natural and efficient ordering when visualizing live ranges.
- void LinearizeGraph();
-
// Give an SSA number to each instruction that defines a value used by another instruction,
// and setup the lifetime information of each instruction and block.
void NumberInstructions();
diff --git a/compiler/utils/arm/assembler_arm.h b/compiler/utils/arm/assembler_arm.h
index 3084e6e..aefbf26 100644
--- a/compiler/utils/arm/assembler_arm.h
+++ b/compiler/utils/arm/assembler_arm.h
@@ -246,7 +246,7 @@
NegPostIndex = (0|0|0) << 21 // negative post-indexed with writeback
};
- Address(Register rn, int32_t offset = 0, Mode am = Offset) : rn_(rn), rm_(R0),
+ explicit Address(Register rn, int32_t offset = 0, Mode am = Offset) : rn_(rn), rm_(R0),
offset_(offset),
am_(am), is_immed_offset_(true), shift_(LSL) {
}
diff --git a/compiler/utils/arm/assembler_thumb2.cc b/compiler/utils/arm/assembler_thumb2.cc
index ebdfc98..f5ccf40 100644
--- a/compiler/utils/arm/assembler_thumb2.cc
+++ b/compiler/utils/arm/assembler_thumb2.cc
@@ -2018,6 +2018,45 @@
return adjustment;
}
+bool Thumb2Assembler::Fixup::IsCandidateForEmitEarly() const {
+ DCHECK(size_ == original_size_);
+ if (target_ == kUnresolved) {
+ return false;
+ }
+ // GetOffset() does not depend on current_code_size for branches, only for literals.
+ constexpr uint32_t current_code_size = 0u;
+ switch (GetSize()) {
+ case kBranch16Bit:
+ return IsInt(cond_ != AL ? 9 : 12, GetOffset(current_code_size));
+ case kBranch32Bit:
+ // We don't support conditional branches beyond +-1MiB
+ // or unconditional branches beyond +-16MiB.
+ return true;
+
+ case kCbxz16Bit:
+ return IsUint<7>(GetOffset(current_code_size));
+ case kCbxz32Bit:
+ return IsInt<9>(GetOffset(current_code_size));
+ case kCbxz48Bit:
+ // We don't support conditional branches beyond +-1MiB.
+ return true;
+
+ case kLiteral1KiB:
+ case kLiteral4KiB:
+ case kLiteral64KiB:
+ case kLiteral1MiB:
+ case kLiteralFar:
+ case kLiteralAddr1KiB:
+ case kLiteralAddr4KiB:
+ case kLiteralAddr64KiB:
+ case kLiteralAddrFar:
+ case kLongOrFPLiteral1KiB:
+ case kLongOrFPLiteral64KiB:
+ case kLongOrFPLiteralFar:
+ return false;
+ }
+}
+
uint32_t Thumb2Assembler::Fixup::AdjustSizeIfNeeded(uint32_t current_code_size) {
uint32_t old_code_size = current_code_size;
switch (GetSize()) {
@@ -3343,6 +3382,30 @@
void Thumb2Assembler::Bind(Label* label) {
BindLabel(label, buffer_.Size());
+
+ // Try to emit some Fixups now to reduce the memory needed during the branch fixup later.
+ while (!fixups_.empty() && fixups_.back().IsCandidateForEmitEarly()) {
+ const Fixup& last_fixup = fixups_.back();
+ // Fixups are ordered by location, so the candidate can surely be emitted if it is
+ // a forward branch. If it's a backward branch, it may go over any number of other
+ // fixups. We could check for any number of emit early candidates but we want this
+ // heuristics to be quick, so check just one.
+ uint32_t target = last_fixup.GetTarget();
+ if (target < last_fixup.GetLocation() &&
+ fixups_.size() >= 2u &&
+ fixups_[fixups_.size() - 2u].GetLocation() >= target) {
+ const Fixup& prev_fixup = fixups_[fixups_.size() - 2u];
+ if (!prev_fixup.IsCandidateForEmitEarly()) {
+ break;
+ }
+ uint32_t min_target = std::min(target, prev_fixup.GetTarget());
+ if (fixups_.size() >= 3u && fixups_[fixups_.size() - 3u].GetLocation() >= min_target) {
+ break;
+ }
+ }
+ last_fixup.Emit(&buffer_, buffer_.Size());
+ fixups_.pop_back();
+ }
}
diff --git a/compiler/utils/arm/assembler_thumb2.h b/compiler/utils/arm/assembler_thumb2.h
index 13f3bec..917c947 100644
--- a/compiler/utils/arm/assembler_thumb2.h
+++ b/compiler/utils/arm/assembler_thumb2.h
@@ -22,11 +22,11 @@
#include <vector>
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/logging.h"
#include "constants_arm.h"
#include "utils/arm/managed_register_arm.h"
#include "utils/arm/assembler_arm.h"
-#include "utils/array_ref.h"
#include "offsets.h"
namespace art {
@@ -573,6 +573,10 @@
return location_;
}
+ uint32_t GetTarget() const {
+ return target_;
+ }
+
uint32_t GetAdjustment() const {
return adjustment_;
}
@@ -592,6 +596,11 @@
target_ = target;
}
+ // Branches with bound targets that are in range can be emitted early.
+ // However, the caller still needs to check if the branch doesn't go over
+ // another Fixup that's not ready to be emitted.
+ bool IsCandidateForEmitEarly() const;
+
// Check if the current size is OK for current location_, target_ and adjustment_.
// If not, increase the size. Return the size increase, 0 if unchanged.
// If the target if after this Fixup, also add the difference to adjustment_,
diff --git a/compiler/utils/arm/jni_macro_assembler_arm_vixl.cc b/compiler/utils/arm/jni_macro_assembler_arm_vixl.cc
index a03dd74..14d29c4 100644
--- a/compiler/utils/arm/jni_macro_assembler_arm_vixl.cc
+++ b/compiler/utils/arm/jni_macro_assembler_arm_vixl.cc
@@ -314,11 +314,21 @@
CHECK(src.IsCoreRegister()) << src;
___ Mov(dst.AsVIXLRegister(), src.AsVIXLRegister());
} else if (dst.IsDRegister()) {
- CHECK(src.IsDRegister()) << src;
- ___ Vmov(F64, dst.AsVIXLDRegister(), src.AsVIXLDRegister());
+ if (src.IsDRegister()) {
+ ___ Vmov(F64, dst.AsVIXLDRegister(), src.AsVIXLDRegister());
+ } else {
+ // VMOV Dn, Rlo, Rhi (Dn = {Rlo, Rhi})
+ CHECK(src.IsRegisterPair()) << src;
+ ___ Vmov(dst.AsVIXLDRegister(), src.AsVIXLRegisterPairLow(), src.AsVIXLRegisterPairHigh());
+ }
} else if (dst.IsSRegister()) {
- CHECK(src.IsSRegister()) << src;
- ___ Vmov(F32, dst.AsVIXLSRegister(), src.AsVIXLSRegister());
+ if (src.IsSRegister()) {
+ ___ Vmov(F32, dst.AsVIXLSRegister(), src.AsVIXLSRegister());
+ } else {
+ // VMOV Sn, Rn (Sn = Rn)
+ CHECK(src.IsCoreRegister()) << src;
+ ___ Vmov(dst.AsVIXLSRegister(), src.AsVIXLRegister());
+ }
} else {
CHECK(dst.IsRegisterPair()) << dst;
CHECK(src.IsRegisterPair()) << src;
diff --git a/compiler/utils/assembler.h b/compiler/utils/assembler.h
index b616057..314ff8c 100644
--- a/compiler/utils/assembler.h
+++ b/compiler/utils/assembler.h
@@ -24,6 +24,7 @@
#include "arm/constants_arm.h"
#include "base/arena_allocator.h"
#include "base/arena_object.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "base/logging.h"
#include "base/macros.h"
@@ -33,7 +34,6 @@
#include "memory_region.h"
#include "mips/constants_mips.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "x86/constants_x86.h"
#include "x86_64/constants_x86_64.h"
diff --git a/compiler/utils/dedupe_set_test.cc b/compiler/utils/dedupe_set_test.cc
index 60a891d..4c0979e 100644
--- a/compiler/utils/dedupe_set_test.cc
+++ b/compiler/utils/dedupe_set_test.cc
@@ -20,10 +20,10 @@
#include <cstdio>
#include <vector>
+#include "base/array_ref.h"
#include "dedupe_set-inl.h"
#include "gtest/gtest.h"
#include "thread-inl.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/utils/intrusive_forward_list.h b/compiler/utils/intrusive_forward_list.h
index ec2c087..b5fc2f2 100644
--- a/compiler/utils/intrusive_forward_list.h
+++ b/compiler/utils/intrusive_forward_list.h
@@ -59,7 +59,7 @@
// Conversion from iterator to const_iterator.
template <typename OtherT,
typename = typename std::enable_if<std::is_same<T, const OtherT>::value>::type>
- IntrusiveForwardListIterator(const IntrusiveForwardListIterator<OtherT, HookTraits>& src)
+ IntrusiveForwardListIterator(const IntrusiveForwardListIterator<OtherT, HookTraits>& src) // NOLINT, implicit
: hook_(src.hook_) { }
// Iteration.
diff --git a/compiler/utils/jni_macro_assembler.h b/compiler/utils/jni_macro_assembler.h
index 6f45bd6..0119ae9 100644
--- a/compiler/utils/jni_macro_assembler.h
+++ b/compiler/utils/jni_macro_assembler.h
@@ -22,12 +22,12 @@
#include "arch/instruction_set.h"
#include "base/arena_allocator.h"
#include "base/arena_object.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "base/logging.h"
#include "base/macros.h"
#include "managed_register.h"
#include "offsets.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/utils/swap_space.h b/compiler/utils/swap_space.h
index bf06675..9600907 100644
--- a/compiler/utils/swap_space.h
+++ b/compiler/utils/swap_space.h
@@ -114,7 +114,8 @@
explicit SwapAllocator(SwapSpace* swap_space) : swap_space_(swap_space) {}
template <typename U>
- SwapAllocator(const SwapAllocator<U>& other) : swap_space_(other.swap_space_) {}
+ SwapAllocator(const SwapAllocator<U>& other) // NOLINT, implicit
+ : swap_space_(other.swap_space_) {}
SwapAllocator(const SwapAllocator& other) = default;
SwapAllocator& operator=(const SwapAllocator& other) = default;
@@ -149,7 +150,8 @@
explicit SwapAllocator(SwapSpace* swap_space) : swap_space_(swap_space) {}
template <typename U>
- SwapAllocator(const SwapAllocator<U>& other) : swap_space_(other.swap_space_) {}
+ SwapAllocator(const SwapAllocator<U>& other) // NOLINT, implicit
+ : swap_space_(other.swap_space_) {}
SwapAllocator(const SwapAllocator& other) = default;
SwapAllocator& operator=(const SwapAllocator& other) = default;
diff --git a/compiler/utils/x86/assembler_x86.h b/compiler/utils/x86/assembler_x86.h
index 9738784..114986b 100644
--- a/compiler/utils/x86/assembler_x86.h
+++ b/compiler/utils/x86/assembler_x86.h
@@ -20,6 +20,7 @@
#include <vector>
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/enums.h"
#include "base/macros.h"
@@ -27,7 +28,6 @@
#include "globals.h"
#include "managed_register_x86.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "utils/assembler.h"
namespace art {
diff --git a/compiler/utils/x86/jni_macro_assembler_x86.h b/compiler/utils/x86/jni_macro_assembler_x86.h
index 3f07ede..015584c 100644
--- a/compiler/utils/x86/jni_macro_assembler_x86.h
+++ b/compiler/utils/x86/jni_macro_assembler_x86.h
@@ -21,10 +21,10 @@
#include "assembler_x86.h"
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "base/macros.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "utils/jni_macro_assembler.h"
namespace art {
diff --git a/compiler/utils/x86_64/assembler_x86_64.h b/compiler/utils/x86_64/assembler_x86_64.h
index fdd3aa9..acad86d 100644
--- a/compiler/utils/x86_64/assembler_x86_64.h
+++ b/compiler/utils/x86_64/assembler_x86_64.h
@@ -20,13 +20,13 @@
#include <vector>
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/macros.h"
#include "constants_x86_64.h"
#include "globals.h"
#include "managed_register_x86_64.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "utils/assembler.h"
#include "utils/jni_macro_assembler.h"
diff --git a/compiler/utils/x86_64/jni_macro_assembler_x86_64.h b/compiler/utils/x86_64/jni_macro_assembler_x86_64.h
index cc4e57c..9107f3c 100644
--- a/compiler/utils/x86_64/jni_macro_assembler_x86_64.h
+++ b/compiler/utils/x86_64/jni_macro_assembler_x86_64.h
@@ -21,10 +21,10 @@
#include "assembler_x86_64.h"
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "base/macros.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "utils/assembler.h"
#include "utils/jni_macro_assembler.h"
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index 43df6ae..d422734 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -120,3 +120,11 @@
"libvixld-arm64",
] + art_static_dependencies,
}
+
+art_cc_test {
+ name: "art_dex2oat_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: ["dex2oat_test.cc"],
+}
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 1dd9132..63f5e0c 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -77,6 +77,7 @@
#include "ScopedLocalRef.h"
#include "scoped_thread_state_change.h"
#include "utils.h"
+#include "verifier/verifier_deps.h"
#include "well_known_classes.h"
#include "zip_archive.h"
@@ -1472,6 +1473,12 @@
dex_files_ = MakeNonOwningPointerVector(opened_dex_files_);
+ if (!IsBootImage()) {
+ // Collect verification dependencies when compiling an app.
+ verifier_deps_.reset(new verifier::VerifierDeps(dex_files_));
+ callbacks_->SetVerifierDeps(verifier_deps_.get());
+ }
+
// We had to postpone the swap decision till now, as this is the point when we actually
// know about the dex files we're going to use.
@@ -2626,6 +2633,9 @@
std::vector<std::vector<const DexFile*>> dex_files_per_oat_file_;
std::unordered_map<const DexFile*, size_t> dex_file_oat_index_map_;
+ // Collector of verifier dependencies.
+ std::unique_ptr<verifier::VerifierDeps> verifier_deps_;
+
// Backing storage.
std::vector<std::string> char_backing_storage_;
@@ -2782,6 +2792,8 @@
return EXIT_FAILURE;
}
+ VLOG(compiler) << "Running dex2oat (parent PID = " << getppid() << ")";
+
bool result;
if (dex2oat->IsImage()) {
result = CompileImage(*dex2oat);
diff --git a/dexdump/Android.bp b/dexdump/Android.bp
index e77f809..74f7578 100644
--- a/dexdump/Android.bp
+++ b/dexdump/Android.bp
@@ -24,3 +24,11 @@
cflags: ["-Wall"],
shared_libs: ["libart"],
}
+
+art_cc_test {
+ name: "art_dexdump_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: ["dexdump_test.cc"],
+}
diff --git a/dexlayout/Android.bp b/dexlayout/Android.bp
index 852f6c2..9c4499f 100644
--- a/dexlayout/Android.bp
+++ b/dexlayout/Android.bp
@@ -23,3 +23,11 @@
cflags: ["-Wall"],
shared_libs: ["libart"],
}
+
+art_cc_test {
+ name: "art_dexlayout_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: ["dexlayout_test.cc"],
+}
diff --git a/dexlist/Android.bp b/dexlist/Android.bp
index 8e3c91d..ddf01db 100644
--- a/dexlist/Android.bp
+++ b/dexlist/Android.bp
@@ -19,3 +19,11 @@
cflags: ["-Wall"],
shared_libs: ["libart"],
}
+
+art_cc_test {
+ name: "art_dexlist_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: ["dexlist_test.cc"],
+}
diff --git a/dexlist/dexlist_test.cc b/dexlist/dexlist_test.cc
index 9a65ba6..da1dd7f 100644
--- a/dexlist/dexlist_test.cc
+++ b/dexlist/dexlist_test.cc
@@ -43,11 +43,7 @@
// Runs test with given arguments.
bool Exec(const std::vector<std::string>& args, std::string* error_msg) {
std::string file_path = GetTestAndroidRoot();
- if (IsHost()) {
- file_path += "/bin/dexlist";
- } else {
- file_path += "/xbin/dexlist";
- }
+ file_path += "/bin/dexlist";
EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path";
std::vector<std::string> exec_argv = { file_path };
exec_argv.insert(exec_argv.end(), args.begin(), args.end());
diff --git a/imgdiag/Android.bp b/imgdiag/Android.bp
index 4c0772d..639b8e8 100644
--- a/imgdiag/Android.bp
+++ b/imgdiag/Android.bp
@@ -69,3 +69,11 @@
"libartd-compiler",
],
}
+
+art_cc_test {
+ name: "art_imgdiag_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: ["imgdiag_test.cc"],
+}
diff --git a/oatdump/Android.bp b/oatdump/Android.bp
index b01bf51..02a51a6 100644
--- a/oatdump/Android.bp
+++ b/oatdump/Android.bp
@@ -87,3 +87,10 @@
] + art_static_dependencies,
}
+art_cc_test {
+ name: "art_oatdump_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: ["oatdump_test.cc"],
+}
diff --git a/profman/Android.bp b/profman/Android.bp
index f3b4e14..cd1aaab 100644
--- a/profman/Android.bp
+++ b/profman/Android.bp
@@ -52,3 +52,11 @@
"libartd",
],
}
+
+art_cc_test {
+ name: "art_profman_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: ["profile_assistant_test.cc"],
+}
diff --git a/runtime/Android.bp b/runtime/Android.bp
index eb7b0c8..c00689b 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -198,6 +198,7 @@
"verifier/reg_type.cc",
"verifier/reg_type_cache.cc",
"verifier/register_line.cc",
+ "verifier/verifier_deps.cc",
"well_known_classes.cc",
"zip_archive.cc",
@@ -462,6 +463,127 @@
],
}
+art_cc_library {
+ name: "libart-runtime-gtest",
+ defaults: ["libart-gtest-defaults"],
+ srcs: ["common_runtime_test.cc"],
+ shared_libs: [
+ "libartd",
+ ],
+}
+
+art_cc_test {
+ name: "art_runtime_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: [
+ "arch/arch_test.cc",
+ "arch/instruction_set_test.cc",
+ "arch/instruction_set_features_test.cc",
+ "arch/memcmp16_test.cc",
+ "arch/stub_test.cc",
+ "arch/arm/instruction_set_features_arm_test.cc",
+ "arch/arm64/instruction_set_features_arm64_test.cc",
+ "arch/mips/instruction_set_features_mips_test.cc",
+ "arch/mips64/instruction_set_features_mips64_test.cc",
+ "arch/x86/instruction_set_features_x86_test.cc",
+ "arch/x86_64/instruction_set_features_x86_64_test.cc",
+ "barrier_test.cc",
+ "base/arena_allocator_test.cc",
+ "base/bit_field_test.cc",
+ "base/bit_utils_test.cc",
+ "base/bit_vector_test.cc",
+ "base/hash_set_test.cc",
+ "base/hex_dump_test.cc",
+ "base/histogram_test.cc",
+ "base/mutex_test.cc",
+ "base/scoped_flock_test.cc",
+ "base/stringprintf_test.cc",
+ "base/time_utils_test.cc",
+ "base/timing_logger_test.cc",
+ "base/transform_array_ref_test.cc",
+ "base/transform_iterator_test.cc",
+ "base/variant_map_test.cc",
+ "base/unix_file/fd_file_test.cc",
+ "class_linker_test.cc",
+ "compiler_filter_test.cc",
+ "dex_file_test.cc",
+ "dex_file_verifier_test.cc",
+ "dex_instruction_test.cc",
+ "dex_instruction_visitor_test.cc",
+ "dex_method_iterator_test.cc",
+ "entrypoints/math_entrypoints_test.cc",
+ "entrypoints/quick/quick_trampoline_entrypoints_test.cc",
+ "entrypoints_order_test.cc",
+ "gc/accounting/card_table_test.cc",
+ "gc/accounting/mod_union_table_test.cc",
+ "gc/accounting/space_bitmap_test.cc",
+ "gc/collector/immune_spaces_test.cc",
+ "gc/heap_test.cc",
+ "gc/reference_queue_test.cc",
+ "gc/space/dlmalloc_space_static_test.cc",
+ "gc/space/dlmalloc_space_random_test.cc",
+ "gc/space/large_object_space_test.cc",
+ "gc/space/rosalloc_space_static_test.cc",
+ "gc/space/rosalloc_space_random_test.cc",
+ "gc/space/space_create_test.cc",
+ "gc/system_weak_test.cc",
+ "gc/task_processor_test.cc",
+ "gtest_test.cc",
+ "handle_scope_test.cc",
+ "indenter_test.cc",
+ "indirect_reference_table_test.cc",
+ "instrumentation_test.cc",
+ "intern_table_test.cc",
+ "interpreter/safe_math_test.cc",
+ "interpreter/unstarted_runtime_test.cc",
+ "java_vm_ext_test.cc",
+ "jit/profile_compilation_info_test.cc",
+ "leb128_test.cc",
+ "mem_map_test.cc",
+ "memory_region_test.cc",
+ "mirror/dex_cache_test.cc",
+ "mirror/object_test.cc",
+ "monitor_pool_test.cc",
+ "monitor_test.cc",
+ "oat_file_test.cc",
+ "oat_file_assistant_test.cc",
+ "parsed_options_test.cc",
+ "prebuilt_tools_test.cc",
+ "reference_table_test.cc",
+ "thread_pool_test.cc",
+ "transaction_test.cc",
+ "type_lookup_table_test.cc",
+ "utf_test.cc",
+ "utils_test.cc",
+ "verifier/method_verifier_test.cc",
+ "verifier/reg_type_test.cc",
+ "verifier/verifier_deps_test.cc",
+ "zip_archive_test.cc",
+ ],
+ shared_libs: [
+ "libbacktrace",
+ ],
+}
+
+art_cc_test {
+ name: "art_runtime_compiler_tests",
+ defaults: [
+ "art_test_defaults",
+ ],
+ srcs: [
+ "jni_internal_test.cc",
+ "proxy_test.cc",
+ "reflection_test.cc",
+ ],
+ shared_libs: [
+ "libartd-compiler",
+ "libvixld-arm",
+ "libvixld-arm64",
+ ],
+}
+
subdirs = [
"openjdkjvm",
"openjdkjvmti",
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index 78eea18..fd6c37a 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -108,7 +108,7 @@
}
bool ArtMethod::HasSameNameAndSignature(ArtMethod* other) {
- ScopedAssertNoThreadSuspension ants(Thread::Current(), "HasSameNameAndSignature");
+ ScopedAssertNoThreadSuspension ants("HasSameNameAndSignature");
const DexFile* dex_file = GetDexFile();
const DexFile::MethodId& mid = dex_file->GetMethodId(GetDexMethodIndex());
if (GetDexCache() == other->GetDexCache()) {
diff --git a/runtime/base/allocator.h b/runtime/base/allocator.h
index e48eca9..8d1c982 100644
--- a/runtime/base/allocator.h
+++ b/runtime/base/allocator.h
@@ -116,7 +116,8 @@
// Used internally by STL data structures.
template <class U>
- TrackingAllocatorImpl(const TrackingAllocatorImpl<U, kTag>& alloc ATTRIBUTE_UNUSED) noexcept {}
+ TrackingAllocatorImpl( // NOLINT, implicit
+ const TrackingAllocatorImpl<U, kTag>& alloc ATTRIBUTE_UNUSED) noexcept {}
// Used internally by STL data structures.
TrackingAllocatorImpl() noexcept {
diff --git a/runtime/base/arena_allocator.h b/runtime/base/arena_allocator.h
index 3fad96b..31dbb36 100644
--- a/runtime/base/arena_allocator.h
+++ b/runtime/base/arena_allocator.h
@@ -258,9 +258,9 @@
class ArenaPool {
public:
- ArenaPool(bool use_malloc = true,
- bool low_4gb = false,
- const char* name = "LinearAlloc");
+ explicit ArenaPool(bool use_malloc = true,
+ bool low_4gb = false,
+ const char* name = "LinearAlloc");
~ArenaPool();
Arena* AllocArena(size_t size) REQUIRES(!lock_);
void FreeArenaChain(Arena* first) REQUIRES(!lock_);
diff --git a/runtime/base/arena_containers.h b/runtime/base/arena_containers.h
index 68cacd5..2c8aa28 100644
--- a/runtime/base/arena_containers.h
+++ b/runtime/base/arena_containers.h
@@ -132,7 +132,7 @@
arena_allocator_(arena_allocator) {
}
template <typename U>
- ArenaAllocatorAdapter(const ArenaAllocatorAdapter<U>& other)
+ ArenaAllocatorAdapter(const ArenaAllocatorAdapter<U>& other) // NOLINT, implicit
: ArenaAllocatorAdapterKind(other),
arena_allocator_(other.arena_allocator_) {
}
@@ -168,7 +168,7 @@
arena_allocator_(arena_allocator) {
}
template <typename U>
- ArenaAllocatorAdapter(const ArenaAllocatorAdapter<U>& other)
+ ArenaAllocatorAdapter(const ArenaAllocatorAdapter<U>& other) // NOLINT, implicit
: ArenaAllocatorAdapterKind(other),
arena_allocator_(other.arena_allocator_) {
}
diff --git a/compiler/utils/array_ref.h b/runtime/base/array_ref.h
similarity index 97%
rename from compiler/utils/array_ref.h
rename to runtime/base/array_ref.h
index 8dc9ab4..00b9bad 100644
--- a/compiler/utils/array_ref.h
+++ b/runtime/base/array_ref.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ART_COMPILER_UTILS_ARRAY_REF_H_
-#define ART_COMPILER_UTILS_ARRAY_REF_H_
+#ifndef ART_RUNTIME_BASE_ARRAY_REF_H_
+#define ART_RUNTIME_BASE_ARRAY_REF_H_
#include <type_traits>
#include <vector>
@@ -197,4 +197,4 @@
} // namespace art
-#endif // ART_COMPILER_UTILS_ARRAY_REF_H_
+#endif // ART_RUNTIME_BASE_ARRAY_REF_H_
diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc
index fec918b..43c38c4 100644
--- a/runtime/base/mutex.cc
+++ b/runtime/base/mutex.cc
@@ -48,6 +48,7 @@
Mutex* Locks::modify_ldt_lock_ = nullptr;
MutatorMutex* Locks::mutator_lock_ = nullptr;
Mutex* Locks::profiler_lock_ = nullptr;
+Mutex* Locks::verifier_deps_lock_ = nullptr;
ReaderWriterMutex* Locks::oat_file_manager_lock_ = nullptr;
Mutex* Locks::host_dlopen_handles_lock_ = nullptr;
Mutex* Locks::reference_processor_lock_ = nullptr;
@@ -947,6 +948,7 @@
DCHECK(deoptimization_lock_ != nullptr);
DCHECK(heap_bitmap_lock_ != nullptr);
DCHECK(oat_file_manager_lock_ != nullptr);
+ DCHECK(verifier_deps_lock_ != nullptr);
DCHECK(host_dlopen_handles_lock_ != nullptr);
DCHECK(intern_table_lock_ != nullptr);
DCHECK(jni_libraries_lock_ != nullptr);
@@ -1035,6 +1037,10 @@
DCHECK(oat_file_manager_lock_ == nullptr);
oat_file_manager_lock_ = new ReaderWriterMutex("OatFile manager lock", current_lock_level);
+ UPDATE_CURRENT_LOCK_LEVEL(kVerifierDepsLock);
+ DCHECK(verifier_deps_lock_ == nullptr);
+ verifier_deps_lock_ = new Mutex("verifier deps lock", current_lock_level);
+
UPDATE_CURRENT_LOCK_LEVEL(kHostDlOpenHandlesLock);
DCHECK(host_dlopen_handles_lock_ == nullptr);
host_dlopen_handles_lock_ = new Mutex("host dlopen handles lock", current_lock_level);
diff --git a/runtime/base/mutex.h b/runtime/base/mutex.h
index d0dc886..8af9fa5 100644
--- a/runtime/base/mutex.h
+++ b/runtime/base/mutex.h
@@ -83,6 +83,7 @@
kInternTableLock,
kOatFileSecondaryLookupLock,
kHostDlOpenHandlesLock,
+ kVerifierDepsLock,
kOatFileManagerLock,
kTracingUniqueMethodsLock,
kTracingStreamingLock,
@@ -650,8 +651,11 @@
// Guards opened oat files in OatFileManager.
static ReaderWriterMutex* oat_file_manager_lock_ ACQUIRED_AFTER(modify_ldt_lock_);
+ // Guards verifier dependency collection in VerifierDeps.
+ static Mutex* verifier_deps_lock_ ACQUIRED_AFTER(oat_file_manager_lock_);
+
// Guards dlopen_handles_ in DlOpenOatFile.
- static Mutex* host_dlopen_handles_lock_ ACQUIRED_AFTER(oat_file_manager_lock_);
+ static Mutex* host_dlopen_handles_lock_ ACQUIRED_AFTER(verifier_deps_lock_);
// Guards intern table.
static Mutex* intern_table_lock_ ACQUIRED_AFTER(host_dlopen_handles_lock_);
diff --git a/runtime/base/scoped_arena_containers.h b/runtime/base/scoped_arena_containers.h
index bd19d00..7964705 100644
--- a/runtime/base/scoped_arena_containers.h
+++ b/runtime/base/scoped_arena_containers.h
@@ -87,7 +87,7 @@
arena_stack_(arena_allocator->arena_stack_) {
}
template <typename U>
- ScopedArenaAllocatorAdapter(const ScopedArenaAllocatorAdapter<U>& other)
+ ScopedArenaAllocatorAdapter(const ScopedArenaAllocatorAdapter<U>& other) // NOLINT, implicit
: DebugStackReference(other),
DebugStackIndirectTopRef(other),
ArenaAllocatorAdapterKind(other),
@@ -130,7 +130,7 @@
arena_stack_(arena_allocator->arena_stack_) {
}
template <typename U>
- ScopedArenaAllocatorAdapter(const ScopedArenaAllocatorAdapter<U>& other)
+ ScopedArenaAllocatorAdapter(const ScopedArenaAllocatorAdapter<U>& other) // NOLINT, implicit
: DebugStackReference(other),
DebugStackIndirectTopRef(other),
ArenaAllocatorAdapterKind(other),
diff --git a/compiler/utils/transform_array_ref.h b/runtime/base/transform_array_ref.h
similarity index 96%
rename from compiler/utils/transform_array_ref.h
rename to runtime/base/transform_array_ref.h
index a6da34f..b432f86 100644
--- a/compiler/utils/transform_array_ref.h
+++ b/runtime/base/transform_array_ref.h
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#ifndef ART_COMPILER_UTILS_TRANSFORM_ARRAY_REF_H_
-#define ART_COMPILER_UTILS_TRANSFORM_ARRAY_REF_H_
+#ifndef ART_RUNTIME_BASE_TRANSFORM_ARRAY_REF_H_
+#define ART_RUNTIME_BASE_TRANSFORM_ARRAY_REF_H_
#include <type_traits>
-#include "utils/array_ref.h"
-#include "utils/transform_iterator.h"
+#include "base/array_ref.h"
+#include "base/transform_iterator.h"
namespace art {
@@ -72,7 +72,7 @@
template <typename OtherBT,
typename = typename std::enable_if<std::is_same<BaseType, const OtherBT>::value>::type>
- TransformArrayRef(const TransformArrayRef<OtherBT, Function>& other)
+ TransformArrayRef(const TransformArrayRef<OtherBT, Function>& other) // NOLINT, implicit
: TransformArrayRef(other.base(), other.GetFunction()) { }
// Assignment operators.
@@ -193,4 +193,4 @@
} // namespace art
-#endif // ART_COMPILER_UTILS_TRANSFORM_ARRAY_REF_H_
+#endif // ART_RUNTIME_BASE_TRANSFORM_ARRAY_REF_H_
diff --git a/compiler/utils/transform_array_ref_test.cc b/runtime/base/transform_array_ref_test.cc
similarity index 99%
rename from compiler/utils/transform_array_ref_test.cc
rename to runtime/base/transform_array_ref_test.cc
index 8d71fd7..494dbb2 100644
--- a/compiler/utils/transform_array_ref_test.cc
+++ b/runtime/base/transform_array_ref_test.cc
@@ -19,7 +19,7 @@
#include "gtest/gtest.h"
-#include "utils/transform_array_ref.h"
+#include "base/transform_array_ref.h"
namespace art {
diff --git a/compiler/utils/transform_iterator.h b/runtime/base/transform_iterator.h
similarity index 96%
rename from compiler/utils/transform_iterator.h
rename to runtime/base/transform_iterator.h
index 3bc9046..f1a8a52 100644
--- a/compiler/utils/transform_iterator.h
+++ b/runtime/base/transform_iterator.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ART_COMPILER_UTILS_TRANSFORM_ITERATOR_H_
-#define ART_COMPILER_UTILS_TRANSFORM_ITERATOR_H_
+#ifndef ART_RUNTIME_BASE_TRANSFORM_ITERATOR_H_
+#define ART_RUNTIME_BASE_TRANSFORM_ITERATOR_H_
#include <iterator>
#include <type_traits>
@@ -62,7 +62,7 @@
: data_(base, fn) { }
template <typename OtherBI>
- TransformIterator(const TransformIterator<OtherBI, Function>& other)
+ TransformIterator(const TransformIterator<OtherBI, Function>& other) // NOLINT, implicit
: data_(other.base(), other.GetFunction()) {
}
@@ -175,4 +175,4 @@
} // namespace art
-#endif // ART_COMPILER_UTILS_TRANSFORM_ITERATOR_H_
+#endif // ART_RUNTIME_BASE_TRANSFORM_ITERATOR_H_
diff --git a/compiler/utils/transform_iterator_test.cc b/runtime/base/transform_iterator_test.cc
similarity index 99%
rename from compiler/utils/transform_iterator_test.cc
rename to runtime/base/transform_iterator_test.cc
index 57ff0a6..a85dda8 100644
--- a/compiler/utils/transform_iterator_test.cc
+++ b/runtime/base/transform_iterator_test.cc
@@ -22,7 +22,7 @@
#include "gtest/gtest.h"
-#include "utils/transform_iterator.h"
+#include "base/transform_iterator.h"
namespace art {
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index cf7942c..6d93736 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -1533,7 +1533,7 @@
bool ClassLinker::OpenImageDexFiles(gc::space::ImageSpace* space,
std::vector<std::unique_ptr<const DexFile>>* out_dex_files,
std::string* error_msg) {
- ScopedAssertNoThreadSuspension nts(Thread::Current(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension nts(__FUNCTION__);
const ImageHeader& header = space->GetImageHeader();
mirror::Object* dex_caches_object = header.GetImageRoot(ImageHeader::kDexCaches);
DCHECK(dex_caches_object != nullptr);
@@ -1923,7 +1923,7 @@
ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_);
// Not safe to have thread suspension when we are holding a lock.
if (self != nullptr) {
- ScopedAssertNoThreadSuspension nts(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension nts(__FUNCTION__);
VisitClassesInternal(visitor);
} else {
VisitClassesInternal(visitor);
@@ -1965,9 +1965,8 @@
void ClassLinker::VisitClassesWithoutClassesLock(ClassVisitor* visitor) {
// TODO: it may be possible to avoid secondary storage if we iterate over dex caches. The problem
// is avoiding duplicates.
- Thread* const self = Thread::Current();
if (!kMovingClasses) {
- ScopedAssertNoThreadSuspension nts(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension nts(__FUNCTION__);
GetClassesInToVector accumulator;
VisitClasses(&accumulator);
for (mirror::Class* klass : accumulator.classes_) {
@@ -1976,6 +1975,7 @@
}
}
} else {
+ Thread* const self = Thread::Current();
StackHandleScope<1> hs(self);
auto classes = hs.NewHandle<mirror::ObjectArray<mirror::Class>>(nullptr);
// We size the array assuming classes won't be added to the class table during the visit.
@@ -3047,7 +3047,7 @@
{
// Note: We cannot have thread suspension until the field and method arrays are setup or else
// Class::VisitFieldRoots may miss some fields or methods.
- ScopedAssertNoThreadSuspension nts(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension nts(__FUNCTION__);
// Load static fields.
// We allow duplicate definitions of the same field in a class_data_item
// but ignore the repeated indexes here, b/21868015.
@@ -3113,7 +3113,7 @@
// TODO These should really use the iterators.
for (size_t i = 0; it.HasNextDirectMethod(); i++, it.Next()) {
ArtMethod* method = klass->GetDirectMethodUnchecked(i, image_pointer_size_);
- LoadMethod(self, dex_file, it, klass, method);
+ LoadMethod(dex_file, it, klass, method);
LinkCode(method, oat_class, class_def_method_index);
uint32_t it_method_index = it.GetMemberIndex();
if (last_dex_method_index == it_method_index) {
@@ -3128,7 +3128,7 @@
}
for (size_t i = 0; it.HasNextVirtualMethod(); i++, it.Next()) {
ArtMethod* method = klass->GetVirtualMethodUnchecked(i, image_pointer_size_);
- LoadMethod(self, dex_file, it, klass, method);
+ LoadMethod(dex_file, it, klass, method);
DCHECK_EQ(class_def_method_index, it.NumDirectMethods() + i);
LinkCode(method, oat_class, class_def_method_index);
class_def_method_index++;
@@ -3149,8 +3149,7 @@
dst->SetAccessFlags(it.GetFieldAccessFlags());
}
-void ClassLinker::LoadMethod(Thread* self,
- const DexFile& dex_file,
+void ClassLinker::LoadMethod(const DexFile& dex_file,
const ClassDataItemIterator& it,
Handle<mirror::Class> klass,
ArtMethod* dst) {
@@ -3158,7 +3157,7 @@
const DexFile::MethodId& method_id = dex_file.GetMethodId(dex_method_idx);
const char* method_name = dex_file.StringDataByIdx(method_id.name_idx_);
- ScopedAssertNoThreadSuspension ants(self, "LoadMethod");
+ ScopedAssertNoThreadSuspension ants("LoadMethod");
dst->SetDexMethodIndex(dex_method_idx);
dst->SetDeclaringClass(klass.Get());
dst->SetCodeItemOffset(it.GetMethodCodeItemOffset());
@@ -3692,7 +3691,7 @@
mirror::ClassLoader* class_loader) {
Thread* self = Thread::Current();
WriterMutexLock mu(self, *Locks::classlinker_classes_lock_);
- ScopedAssertNoThreadSuspension ants(self, "Moving image classes to class table");
+ ScopedAssertNoThreadSuspension ants("Moving image classes to class table");
ClassTable* const class_table = InsertClassTableForClassLoader(class_loader);
@@ -3747,7 +3746,7 @@
}
mirror::Class* ClassLinker::LookupClassFromBootImage(const char* descriptor) {
- ScopedAssertNoThreadSuspension ants(Thread::Current(), "Image class lookup");
+ ScopedAssertNoThreadSuspension ants("Image class lookup");
std::vector<mirror::ObjectArray<mirror::DexCache>*> dex_caches_vector =
GetImageDexCaches(Runtime::Current()->GetHeap()->GetBootImageSpaces());
for (mirror::ObjectArray<mirror::DexCache>* dex_caches : dex_caches_vector) {
@@ -6508,7 +6507,7 @@
size_t new_ifcount;
{
- ScopedAssertNoThreadSuspension nts(self, "Copying mirror::Class*'s for FillIfTable");
+ ScopedAssertNoThreadSuspension nts("Copying mirror::Class*'s for FillIfTable");
std::vector<mirror::Class*> to_add;
for (size_t i = 0; i < num_interfaces; i++) {
mirror::Class* interface = have_interfaces ? interfaces->Get(i) :
@@ -8271,7 +8270,7 @@
std::set<DexCacheResolvedClasses> ClassLinker::GetResolvedClasses(bool ignore_boot_classes) {
ScopedTrace trace(__PRETTY_FUNCTION__);
ScopedObjectAccess soa(Thread::Current());
- ScopedAssertNoThreadSuspension ants(soa.Self(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
std::set<DexCacheResolvedClasses> ret;
VLOG(class_linker) << "Collecting resolved classes";
const uint64_t start_time = NanoTime();
@@ -8345,7 +8344,7 @@
Thread* const self = Thread::Current();
std::unordered_map<std::string, const DexFile*> location_to_dex_file;
ScopedObjectAccess soa(self);
- ScopedAssertNoThreadSuspension ants(soa.Self(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
ReaderMutexLock mu(self, *DexLock());
for (const ClassLinker::DexCacheData& data : GetDexCachesData()) {
if (!self->IsJWeakCleared(data.weak_root)) {
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 5e4ae03..0a46e2e 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -769,8 +769,7 @@
void LoadField(const ClassDataItemIterator& it, Handle<mirror::Class> klass, ArtField* dst)
REQUIRES_SHARED(Locks::mutator_lock_);
- void LoadMethod(Thread* self,
- const DexFile& dex_file,
+ void LoadMethod(const DexFile& dex_file,
const ClassDataItemIterator& it,
Handle<mirror::Class> klass, ArtMethod* dst)
REQUIRES_SHARED(Locks::mutator_lock_);
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index dba0a81..7234952 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -409,15 +409,6 @@
TearDownAndroidData(android_data_, true);
dalvik_cache_.clear();
- // icu4c has a fixed 10-element array "gCommonICUDataArray".
- // If we run > 10 tests, we fill that array and u_setCommonData fails.
- // There's a function to clear the array, but it's not public...
- typedef void (*IcuCleanupFn)();
- void* sym = dlsym(RTLD_DEFAULT, "u_cleanup_" U_ICU_VERSION_SHORT);
- CHECK(sym != nullptr) << dlerror();
- IcuCleanupFn icu_cleanup_fn = reinterpret_cast<IcuCleanupFn>(sym);
- (*icu_cleanup_fn)();
-
Runtime::Current()->GetHeap()->VerifyHeap(); // Check for heap corruption after the test
}
@@ -591,9 +582,9 @@
if (IsHost()) {
const char* host_dir = getenv("ANDROID_HOST_OUT");
CHECK(host_dir != nullptr);
- location = StringPrintf("%s/framework/core.%s", host_dir, suffix);
+ location = StringPrintf("%s/framework/core-npic.%s", host_dir, suffix);
} else {
- location = StringPrintf("/data/art-test/core.%s", suffix);
+ location = StringPrintf("/data/art-test/core-npic.%s", suffix);
}
return location;
diff --git a/runtime/compiler_callbacks.h b/runtime/compiler_callbacks.h
index ee797e0..00dedef 100644
--- a/runtime/compiler_callbacks.h
+++ b/runtime/compiler_callbacks.h
@@ -25,6 +25,7 @@
namespace verifier {
class MethodVerifier;
+class VerifierDeps;
} // namespace verifier
@@ -45,6 +46,8 @@
// done so. Return false if relocating in this way would be problematic.
virtual bool IsRelocationPossible() = 0;
+ virtual verifier::VerifierDeps* GetVerifierDeps() const = 0;
+
bool IsBootImage() {
return mode_ == CallbackMode::kCompileBootImage;
}
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index f8a11e5..b49c01c 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -1987,7 +1987,7 @@
if (error != JDWP::ERR_NONE) {
return JDWP::ERR_INVALID_OBJECT;
}
- ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroup");
+ ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroup");
// Okay, so it's an object, but is it actually a thread?
DecodeThread(soa, thread_id, &error);
if (error == JDWP::ERR_THREAD_NOT_ALIVE) {
@@ -2037,7 +2037,7 @@
if (error != JDWP::ERR_NONE) {
return error;
}
- ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroupName");
+ ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroupName");
ArtField* f = soa.DecodeField(WellKnownClasses::java_lang_ThreadGroup_name);
CHECK(f != nullptr);
mirror::String* s = reinterpret_cast<mirror::String*>(f->GetObject(thread_group));
@@ -2056,7 +2056,7 @@
}
mirror::Object* parent;
{
- ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroupParent");
+ ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroupParent");
ArtField* f = soa.DecodeField(WellKnownClasses::java_lang_ThreadGroup_parent);
CHECK(f != nullptr);
parent = f->GetObject(thread_group);
diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h
index d03a9d8..14110c2 100644
--- a/runtime/entrypoints/entrypoint_utils-inl.h
+++ b/runtime/entrypoints/entrypoint_utils-inl.h
@@ -48,7 +48,7 @@
// This method is being used by artQuickResolutionTrampoline, before it sets up
// the passed parameters in a GC friendly way. Therefore we must never be
// suspended while executing it.
- ScopedAssertNoThreadSuspension sants(Thread::Current(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension sants(__FUNCTION__);
uint32_t method_index = inline_info.GetMethodIndexAtDepth(encoding, inlining_depth);
InvokeType invoke_type = static_cast<InvokeType>(
@@ -120,8 +120,7 @@
return inlined_method;
}
-inline ArtMethod* GetCalleeSaveMethodCaller(Thread* self, Runtime::CalleeSaveType type)
- REQUIRES_SHARED(Locks::mutator_lock_) {
+inline ArtMethod* GetCalleeSaveMethodCaller(Thread* self, Runtime::CalleeSaveType type) {
return GetCalleeSaveMethodCaller(
self->GetManagedStack()->GetTopQuickFrame(), type, true /* do_caller_check */);
}
@@ -130,7 +129,8 @@
ALWAYS_INLINE
inline mirror::Class* CheckObjectAlloc(uint32_t type_idx,
ArtMethod* method,
- Thread* self, bool* slow_path) {
+ Thread* self,
+ bool* slow_path) {
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
PointerSize pointer_size = class_linker->GetImagePointerSize();
mirror::Class* klass = method->GetDexCacheResolvedType<false>(type_idx, pointer_size);
@@ -363,7 +363,7 @@
inline ArtField* FindFieldFromCode(uint32_t field_idx,
ArtMethod* referrer,
Thread* self,
- size_t expected_size) REQUIRES(!Roles::uninterruptible_) {
+ size_t expected_size) {
bool is_primitive;
bool is_set;
bool is_static;
@@ -444,8 +444,7 @@
return resolved_field;
} else {
StackHandleScope<1> hs(self);
- Handle<mirror::Class> h_class(hs.NewHandle(fields_class));
- if (LIKELY(class_linker->EnsureInitialized(self, h_class, true, true))) {
+ if (LIKELY(class_linker->EnsureInitialized(self, hs.NewHandle(fields_class), true, true))) {
// Otherwise let's ensure the class is initialized before resolving the field.
return resolved_field;
}
@@ -479,8 +478,10 @@
#undef EXPLICIT_FIND_FIELD_FROM_CODE_TEMPLATE_DECL
template<InvokeType type, bool access_check>
-inline ArtMethod* FindMethodFromCode(uint32_t method_idx, mirror::Object** this_object,
- ArtMethod* referrer, Thread* self) {
+inline ArtMethod* FindMethodFromCode(uint32_t method_idx,
+ mirror::Object** this_object,
+ ArtMethod* referrer,
+ Thread* self) {
ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
ArtMethod* resolved_method = class_linker->GetResolvedMethod(method_idx, referrer);
if (resolved_method == nullptr) {
@@ -554,8 +555,11 @@
// that will actually not be what we want in some cases where there are miranda methods or
// defaults. What we actually need is a GetContainingClass that says which classes virtuals
// this method is coming from.
- mirror::Class* referring_class = referrer->GetDeclaringClass();
- uint16_t method_type_idx = referring_class->GetDexFile().GetMethodId(method_idx).class_idx_;
+ StackHandleScope<2> hs2(self);
+ HandleWrapper<mirror::Object> h_this(hs2.NewHandleWrapper(this_object));
+ Handle<mirror::Class> h_referring_class(hs2.NewHandle(referrer->GetDeclaringClass()));
+ const uint16_t method_type_idx =
+ h_referring_class->GetDexFile().GetMethodId(method_idx).class_idx_;
mirror::Class* method_reference_class = class_linker->ResolveType(method_type_idx, referrer);
if (UNLIKELY(method_reference_class == nullptr)) {
// Bad type idx.
@@ -566,8 +570,8 @@
// referenced class in the bytecode, we use its super class. Otherwise, we throw
// a NoSuchMethodError.
mirror::Class* super_class = nullptr;
- if (method_reference_class->IsAssignableFrom(referring_class)) {
- super_class = referring_class->GetSuperClass();
+ if (method_reference_class->IsAssignableFrom(h_referring_class.Get())) {
+ super_class = h_referring_class->GetSuperClass();
}
uint16_t vtable_index = resolved_method->GetMethodIndex();
if (access_check) {
@@ -587,10 +591,10 @@
} else {
// It is an interface.
if (access_check) {
- if (!method_reference_class->IsAssignableFrom((*this_object)->GetClass())) {
+ if (!method_reference_class->IsAssignableFrom(h_this->GetClass())) {
ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(resolved_method,
method_reference_class,
- *this_object,
+ h_this.Get(),
referrer);
return nullptr; // Failure.
}
@@ -605,6 +609,7 @@
}
return result;
}
+ UNREACHABLE();
}
case kInterface: {
uint32_t imt_index = resolved_method->GetImtIndex();
@@ -661,6 +666,7 @@
// Fast path field resolution that can't initialize classes or throw exceptions.
inline ArtField* FindFieldFast(uint32_t field_idx, ArtMethod* referrer, FindFieldType type,
size_t expected_size) {
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
ArtField* resolved_field =
referrer->GetDeclaringClass()->GetDexCache()->GetResolvedField(field_idx,
kRuntimePointerSize);
@@ -713,6 +719,7 @@
// Fast path method resolution that can't throw exceptions.
inline ArtMethod* FindMethodFast(uint32_t method_idx, mirror::Object* this_object,
ArtMethod* referrer, bool access_check, InvokeType type) {
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
if (UNLIKELY(this_object == nullptr && type != kStatic)) {
return nullptr;
}
diff --git a/runtime/entrypoints/entrypoint_utils.cc b/runtime/entrypoints/entrypoint_utils.cc
index 4056ec5..fd9ffbd 100644
--- a/runtime/entrypoints/entrypoint_utils.cc
+++ b/runtime/entrypoints/entrypoint_utils.cc
@@ -43,7 +43,7 @@
ArtMethod* referrer,
Thread* self,
bool access_check)
- REQUIRES_SHARED(Locks::mutator_lock_) {
+ REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) {
if (UNLIKELY(component_count < 0)) {
ThrowNegativeArraySizeException(component_count);
return nullptr; // Failure
@@ -120,19 +120,19 @@
heap->GetCurrentAllocator());
}
-void CheckReferenceResult(mirror::Object* o, Thread* self) {
- if (o == nullptr) {
+void CheckReferenceResult(Handle<mirror::Object> o, Thread* self) {
+ if (o.Get() == nullptr) {
return;
}
// Make sure that the result is an instance of the type this method was expected to return.
- mirror::Class* return_type = self->GetCurrentMethod(nullptr)->GetReturnType(true /* resolve */,
- kRuntimePointerSize);
+ ArtMethod* method = self->GetCurrentMethod(nullptr);
+ mirror::Class* return_type = method->GetReturnType(true /* resolve */, kRuntimePointerSize);
if (!o->InstanceOf(return_type)) {
Runtime::Current()->GetJavaVM()->JniAbortF(nullptr,
"attempt to return an instance of %s from %s",
- PrettyTypeOf(o).c_str(),
- PrettyMethod(self->GetCurrentMethod(nullptr)).c_str());
+ PrettyTypeOf(o.Get()).c_str(),
+ PrettyMethod(method).c_str());
}
}
@@ -186,12 +186,11 @@
// Do nothing.
return zero;
} else {
- StackHandleScope<1> hs(soa.Self());
- auto h_interface_method(hs.NewHandle(soa.Decode<mirror::Method*>(interface_method_jobj)));
+ ArtMethod* interface_method =
+ soa.Decode<mirror::Method*>(interface_method_jobj)->GetArtMethod();
// This can cause thread suspension.
PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
- mirror::Class* result_type =
- h_interface_method->GetArtMethod()->GetReturnType(true /* resolve */, pointer_size);
+ mirror::Class* result_type = interface_method->GetReturnType(true /* resolve */, pointer_size);
mirror::Object* result_ref = soa.Decode<mirror::Object*>(result);
JValue result_unboxed;
if (!UnboxPrimitiveForResult(result_ref, result_type, &result_unboxed)) {
@@ -205,26 +204,29 @@
// a UndeclaredThrowableException.
mirror::Throwable* exception = soa.Self()->GetException();
if (exception->IsCheckedException()) {
- mirror::Object* rcvr = soa.Decode<mirror::Object*>(rcvr_jobj);
- mirror::Class* proxy_class = rcvr->GetClass();
- mirror::Method* interface_method = soa.Decode<mirror::Method*>(interface_method_jobj);
- ArtMethod* proxy_method = rcvr->GetClass()->FindVirtualMethodForInterface(
- interface_method->GetArtMethod(), kRuntimePointerSize);
- auto virtual_methods = proxy_class->GetVirtualMethodsSlice(kRuntimePointerSize);
- size_t num_virtuals = proxy_class->NumVirtualMethods();
- size_t method_size = ArtMethod::Size(kRuntimePointerSize);
- // Rely on the fact that the methods are contiguous to determine the index of the method in
- // the slice.
- int throws_index = (reinterpret_cast<uintptr_t>(proxy_method) -
- reinterpret_cast<uintptr_t>(&virtual_methods.At(0))) / method_size;
- CHECK_LT(throws_index, static_cast<int>(num_virtuals));
- mirror::ObjectArray<mirror::Class>* declared_exceptions =
- proxy_class->GetThrows()->Get(throws_index);
- mirror::Class* exception_class = exception->GetClass();
bool declares_exception = false;
- for (int32_t i = 0; i < declared_exceptions->GetLength() && !declares_exception; i++) {
- mirror::Class* declared_exception = declared_exceptions->Get(i);
- declares_exception = declared_exception->IsAssignableFrom(exception_class);
+ {
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
+ mirror::Object* rcvr = soa.Decode<mirror::Object*>(rcvr_jobj);
+ mirror::Class* proxy_class = rcvr->GetClass();
+ mirror::Method* interface_method = soa.Decode<mirror::Method*>(interface_method_jobj);
+ ArtMethod* proxy_method = rcvr->GetClass()->FindVirtualMethodForInterface(
+ interface_method->GetArtMethod(), kRuntimePointerSize);
+ auto virtual_methods = proxy_class->GetVirtualMethodsSlice(kRuntimePointerSize);
+ size_t num_virtuals = proxy_class->NumVirtualMethods();
+ size_t method_size = ArtMethod::Size(kRuntimePointerSize);
+ // Rely on the fact that the methods are contiguous to determine the index of the method in
+ // the slice.
+ int throws_index = (reinterpret_cast<uintptr_t>(proxy_method) -
+ reinterpret_cast<uintptr_t>(&virtual_methods.At(0))) / method_size;
+ CHECK_LT(throws_index, static_cast<int>(num_virtuals));
+ mirror::ObjectArray<mirror::Class>* declared_exceptions =
+ proxy_class->GetThrows()->Get(throws_index);
+ mirror::Class* exception_class = exception->GetClass();
+ for (int32_t i = 0; i < declared_exceptions->GetLength() && !declares_exception; i++) {
+ mirror::Class* declared_exception = declared_exceptions->Get(i);
+ declares_exception = declared_exception->IsAssignableFrom(exception_class);
+ }
}
if (!declares_exception) {
soa.Self()->ThrowNewWrappedException("Ljava/lang/reflect/UndeclaredThrowableException;",
@@ -260,6 +262,7 @@
Runtime::CalleeSaveType type,
bool do_caller_check)
REQUIRES_SHARED(Locks::mutator_lock_) {
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(type));
const size_t callee_frame_size = GetCalleeSaveFrameSize(kRuntimeISA, type);
diff --git a/runtime/entrypoints/entrypoint_utils.h b/runtime/entrypoints/entrypoint_utils.h
index f88e81d..20c8401 100644
--- a/runtime/entrypoints/entrypoint_utils.h
+++ b/runtime/entrypoints/entrypoint_utils.h
@@ -24,6 +24,7 @@
#include "base/mutex.h"
#include "dex_instruction.h"
#include "gc/allocator_type.h"
+#include "handle.h"
#include "invoke_type.h"
#include "jvalue.h"
#include "runtime.h"
@@ -46,13 +47,16 @@
template <const bool kAccessCheck>
ALWAYS_INLINE inline mirror::Class* CheckObjectAlloc(uint32_t type_idx,
ArtMethod* method,
- Thread* self, bool* slow_path)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ Thread* self,
+ bool* slow_path)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
ALWAYS_INLINE inline mirror::Class* CheckClassInitializedForObjectAlloc(mirror::Class* klass,
Thread* self,
bool* slow_path)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
// Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it
// cannot be resolved, throw an error. If it can, use it to create an instance.
@@ -63,21 +67,25 @@
ArtMethod* method,
Thread* self,
gc::AllocatorType allocator_type)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
// Given the context of a calling Method and a resolved class, create an instance.
template <bool kInstrumented>
ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
Thread* self,
gc::AllocatorType allocator_type)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
// Given the context of a calling Method and an initialized class, create an instance.
template <bool kInstrumented>
-ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeInitialized(mirror::Class* klass,
- Thread* self,
- gc::AllocatorType allocator_type)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeInitialized(
+ mirror::Class* klass,
+ Thread* self,
+ gc::AllocatorType allocator_type)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
template <bool kAccessCheck>
@@ -85,7 +93,8 @@
int32_t component_count,
ArtMethod* method,
bool* slow_path)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
// it cannot be resolved, throw an error. If it can, use it to create an array.
@@ -97,7 +106,8 @@
ArtMethod* method,
Thread* self,
gc::AllocatorType allocator_type)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
template <bool kAccessCheck, bool kInstrumented>
ALWAYS_INLINE inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
@@ -105,13 +115,15 @@
ArtMethod* method,
Thread* self,
gc::AllocatorType allocator_type)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
extern mirror::Array* CheckAndAllocArrayFromCode(uint32_t type_idx, int32_t component_count,
ArtMethod* method, Thread* self,
bool access_check,
gc::AllocatorType allocator_type)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
extern mirror::Array* CheckAndAllocArrayFromCodeInstrumented(uint32_t type_idx,
int32_t component_count,
@@ -119,7 +131,8 @@
Thread* self,
bool access_check,
gc::AllocatorType allocator_type)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
// Type of find field operation for fast and slow case.
enum FindFieldType {
@@ -134,54 +147,76 @@
};
template<FindFieldType type, bool access_check>
-inline ArtField* FindFieldFromCode(
- uint32_t field_idx, ArtMethod* referrer, Thread* self, size_t expected_size)
- REQUIRES_SHARED(Locks::mutator_lock_);
+inline ArtField* FindFieldFromCode(uint32_t field_idx,
+ ArtMethod* referrer,
+ Thread* self,
+ size_t expected_size)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
template<InvokeType type, bool access_check>
-inline ArtMethod* FindMethodFromCode(
- uint32_t method_idx, mirror::Object** this_object, ArtMethod* referrer, Thread* self)
- REQUIRES_SHARED(Locks::mutator_lock_);
+inline ArtMethod* FindMethodFromCode(uint32_t method_idx,
+ mirror::Object** this_object,
+ ArtMethod* referrer,
+ Thread* self)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
// Fast path field resolution that can't initialize classes or throw exceptions.
-inline ArtField* FindFieldFast(
- uint32_t field_idx, ArtMethod* referrer, FindFieldType type, size_t expected_size)
+inline ArtField* FindFieldFast(uint32_t field_idx,
+ ArtMethod* referrer,
+ FindFieldType type,
+ size_t expected_size)
REQUIRES_SHARED(Locks::mutator_lock_);
// Fast path method resolution that can't throw exceptions.
-inline ArtMethod* FindMethodFast(
- uint32_t method_idx, mirror::Object* this_object, ArtMethod* referrer, bool access_check,
- InvokeType type)
+inline ArtMethod* FindMethodFast(uint32_t method_idx,
+ mirror::Object* this_object,
+ ArtMethod* referrer,
+ bool access_check,
+ InvokeType type)
REQUIRES_SHARED(Locks::mutator_lock_);
-inline mirror::Class* ResolveVerifyAndClinit(
- uint32_t type_idx, ArtMethod* referrer, Thread* self, bool can_run_clinit, bool verify_access)
- REQUIRES_SHARED(Locks::mutator_lock_);
+inline mirror::Class* ResolveVerifyAndClinit(uint32_t type_idx,
+ ArtMethod* referrer,
+ Thread* self,
+ bool can_run_clinit,
+ bool verify_access)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, uint32_t string_idx)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
- NO_THREAD_SAFETY_ANALYSIS;
+ NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_);
-void CheckReferenceResult(mirror::Object* o, Thread* self)
- REQUIRES_SHARED(Locks::mutator_lock_);
+void CheckReferenceResult(Handle<mirror::Object> o, Thread* self)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
jobject rcvr_jobj, jobject interface_art_method_jobj,
std::vector<jvalue>& args)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
bool FillArrayData(mirror::Object* obj, const Instruction::ArrayDataPayload* payload)
- REQUIRES_SHARED(Locks::mutator_lock_);
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Roles::uninterruptible_);
template <typename INT_TYPE, typename FLOAT_TYPE>
inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp,
Runtime::CalleeSaveType type,
- bool do_caller_check = false);
+ bool do_caller_check = false)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+ArtMethod* GetCalleeSaveMethodCaller(Thread* self, Runtime::CalleeSaveType type)
+ REQUIRES_SHARED(Locks::mutator_lock_);
} // namespace art
diff --git a/runtime/entrypoints/quick/quick_jni_entrypoints.cc b/runtime/entrypoints/quick/quick_jni_entrypoints.cc
index 64f19af..76b5456 100644
--- a/runtime/entrypoints/quick/quick_jni_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_jni_entrypoints.cc
@@ -114,7 +114,8 @@
PopLocalReferences(saved_local_ref_cookie, self);
}
-extern void JniMethodEndSynchronized(uint32_t saved_local_ref_cookie, jobject locked,
+extern void JniMethodEndSynchronized(uint32_t saved_local_ref_cookie,
+ jobject locked,
Thread* self) {
GoToRunnable(self);
UnlockJniSynchronizedMethod(locked, self); // Must decode before pop.
@@ -135,13 +136,17 @@
PopLocalReferences(saved_local_ref_cookie, self);
// Process result.
if (UNLIKELY(self->GetJniEnv()->check_jni)) {
- CheckReferenceResult(o, self);
+ // CheckReferenceResult can resolve types.
+ StackHandleScope<1> hs(self);
+ HandleWrapper<mirror::Object> h_obj(hs.NewHandleWrapper(&o));
+ CheckReferenceResult(h_obj, self);
}
VerifyObject(o);
return o;
}
-extern mirror::Object* JniMethodEndWithReference(jobject result, uint32_t saved_local_ref_cookie,
+extern mirror::Object* JniMethodEndWithReference(jobject result,
+ uint32_t saved_local_ref_cookie,
Thread* self) {
GoToRunnable(self);
return JniMethodEndWithReferenceHandleResult(result, saved_local_ref_cookie, self);
@@ -149,7 +154,8 @@
extern mirror::Object* JniMethodEndWithReferenceSynchronized(jobject result,
uint32_t saved_local_ref_cookie,
- jobject locked, Thread* self) {
+ jobject locked,
+ Thread* self) {
GoToRunnable(self);
UnlockJniSynchronizedMethod(locked, self);
return JniMethodEndWithReferenceHandleResult(result, saved_local_ref_cookie, self);
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index 3043c83..3c6f807 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -1961,8 +1961,12 @@
// Run the visitor and update sp.
BuildGenericJniFrameVisitor visitor(self, called->IsStatic(), shorty, shorty_len, &sp);
- visitor.VisitArguments();
- visitor.FinalizeHandleScope(self);
+ {
+ ScopedAssertNoThreadSuspension sants(__FUNCTION__);
+ visitor.VisitArguments();
+ // FinalizeHandleScope pushes the handle scope on the thread.
+ visitor.FinalizeHandleScope(self);
+ }
// Fix up managed-stack things in Thread.
self->SetTopOfStack(sp);
diff --git a/runtime/experimental_flags.h b/runtime/experimental_flags.h
index 7faa2dc..54d2c35 100644
--- a/runtime/experimental_flags.h
+++ b/runtime/experimental_flags.h
@@ -31,7 +31,8 @@
};
constexpr ExperimentalFlags() : value_(0x0000) {}
- constexpr ExperimentalFlags(decltype(kNone) t) : value_(static_cast<uint32_t>(t)) {}
+ constexpr ExperimentalFlags(decltype(kNone) t) // NOLINT, implicit
+ : value_(static_cast<uint32_t>(t)) {}
constexpr operator decltype(kNone)() const {
return static_cast<decltype(kNone)>(value_);
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index e534369..247cb96 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -2043,13 +2043,23 @@
}
DCHECK(to_ref != nullptr);
+ // Copy the object excluding the lock word since that is handled in the loop.
+ to_ref->SetClass(from_ref->GetClass<kVerifyNone, kWithoutReadBarrier>());
+ const size_t kObjectHeaderSize = sizeof(mirror::Object);
+ DCHECK_GE(obj_size, kObjectHeaderSize);
+ static_assert(kObjectHeaderSize == sizeof(mirror::HeapReference<mirror::Class>) +
+ sizeof(LockWord),
+ "Object header size does not match");
+ // Memcpy can tear for words since it may do byte copy. It is only safe to do this since the
+ // object in the from space is immutable other than the lock word. b/31423258
+ memcpy(reinterpret_cast<uint8_t*>(to_ref) + kObjectHeaderSize,
+ reinterpret_cast<const uint8_t*>(from_ref) + kObjectHeaderSize,
+ obj_size - kObjectHeaderSize);
+
// Attempt to install the forward pointer. This is in a loop as the
// lock word atomic write can fail.
while (true) {
- // Copy the object. TODO: copy only the lockword in the second iteration and on?
- memcpy(to_ref, from_ref, obj_size);
-
- LockWord old_lock_word = to_ref->GetLockWord(false);
+ LockWord old_lock_word = from_ref->GetLockWord(false);
if (old_lock_word.GetState() == LockWord::kForwardingAddress) {
// Lost the race. Another thread (either GC or mutator) stored
@@ -2093,6 +2103,8 @@
return to_ref;
}
+ // Copy the old lock word over since we did not copy it yet.
+ to_ref->SetLockWord(old_lock_word, false);
// Set the gray ptr.
if (kUseBakerReadBarrier) {
to_ref->SetReadBarrierPointer(ReadBarrier::GrayPtr());
diff --git a/runtime/gc/collector/concurrent_copying.h b/runtime/gc/collector/concurrent_copying.h
index 1ef0aea..53473f0 100644
--- a/runtime/gc/collector/concurrent_copying.h
+++ b/runtime/gc/collector/concurrent_copying.h
@@ -61,9 +61,9 @@
// pages.
static constexpr bool kGrayDirtyImmuneObjects = true;
- ConcurrentCopying(Heap* heap,
- const std::string& name_prefix = "",
- bool measure_read_barrier_slow_path = false);
+ explicit ConcurrentCopying(Heap* heap,
+ const std::string& name_prefix = "",
+ bool measure_read_barrier_slow_path = false);
~ConcurrentCopying();
virtual void RunPhases() OVERRIDE
diff --git a/runtime/gc/collector/garbage_collector.h b/runtime/gc/collector/garbage_collector.h
index 6afe876..4ffa254 100644
--- a/runtime/gc/collector/garbage_collector.h
+++ b/runtime/gc/collector/garbage_collector.h
@@ -44,7 +44,7 @@
namespace collector {
struct ObjectBytePair {
- ObjectBytePair(uint64_t num_objects = 0, int64_t num_bytes = 0)
+ explicit ObjectBytePair(uint64_t num_objects = 0, int64_t num_bytes = 0)
: objects(num_objects), bytes(num_bytes) {}
void Add(const ObjectBytePair& other) {
objects += other.objects;
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 600aff1..cb5226b 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1011,7 +1011,7 @@
DecrementDisableMovingGC(self);
} else {
// GCs can move objects, so don't allow this.
- ScopedAssertNoThreadSuspension ants(self, "Visiting objects");
+ ScopedAssertNoThreadSuspension ants("Visiting objects");
DCHECK(region_space_ == nullptr);
VisitObjectsInternal(callback, arg);
}
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index 388561b..ff43389 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -966,7 +966,7 @@
ArtMethod* callee) const {
// We cannot have thread suspension since that would cause the this_object parameter to
// potentially become a dangling pointer. An alternative could be to put it in a handle instead.
- ScopedAssertNoThreadSuspension ants(thread, __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
for (InstrumentationListener* listener : invoke_virtual_or_interface_listeners_) {
if (listener != nullptr) {
listener->InvokeVirtualOrInterface(thread, this_object, caller, dex_pc, callee);
diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h
index 9d76685..814adf7 100644
--- a/runtime/interpreter/interpreter_common.h
+++ b/runtime/interpreter/interpreter_common.h
@@ -147,8 +147,7 @@
jit::Jit* jit = Runtime::Current()->GetJit();
if (jit != nullptr) {
if (type == kVirtual || type == kInterface) {
- jit->InvokeVirtualOrInterface(
- self, receiver, sf_method, shadow_frame.GetDexPC(), called_method);
+ jit->InvokeVirtualOrInterface(receiver, sf_method, shadow_frame.GetDexPC(), called_method);
}
jit->AddSamples(self, sf_method, 1, /*with_backedges*/false);
}
@@ -195,7 +194,7 @@
jit::Jit* jit = Runtime::Current()->GetJit();
if (jit != nullptr) {
jit->InvokeVirtualOrInterface(
- self, receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
+ receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
jit->AddSamples(self, shadow_frame.GetMethod(), 1, /*with_backedges*/false);
}
instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index cff2354..d984f45 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -431,7 +431,7 @@
const uint8_t* native_pc = nullptr;
{
- ScopedAssertNoThreadSuspension sts(thread, "Holding OSR method");
+ ScopedAssertNoThreadSuspension sts("Holding OSR method");
const OatQuickMethodHeader* osr_method = jit->GetCodeCache()->LookupOsrMethodHeader(method);
if (osr_method == nullptr) {
// No osr method yet, just return to the interpreter.
@@ -683,12 +683,11 @@
}
}
-void Jit::InvokeVirtualOrInterface(Thread* thread,
- mirror::Object* this_object,
+void Jit::InvokeVirtualOrInterface(mirror::Object* this_object,
ArtMethod* caller,
uint32_t dex_pc,
ArtMethod* callee ATTRIBUTE_UNUSED) {
- ScopedAssertNoThreadSuspension ants(thread, __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
DCHECK(this_object != nullptr);
ProfilingInfo* info = caller->GetProfilingInfo(kRuntimePointerSize);
if (info != nullptr) {
diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h
index 52c3843..35656cd 100644
--- a/runtime/jit/jit.h
+++ b/runtime/jit/jit.h
@@ -109,8 +109,7 @@
void AddSamples(Thread* self, ArtMethod* method, uint16_t samples, bool with_backedges)
REQUIRES_SHARED(Locks::mutator_lock_);
- void InvokeVirtualOrInterface(Thread* thread,
- mirror::Object* this_object,
+ void InvokeVirtualOrInterface(mirror::Object* this_object,
ArtMethod* caller,
uint32_t dex_pc,
ArtMethod* callee)
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index 2132978..f21baed 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -785,7 +785,7 @@
}
// Though GetDirectInterface() should not cause thread suspension when called
// from here, it takes a Handle as an argument, so we need to wrap `k`.
- ScopedAssertNoThreadSuspension ants(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
StackHandleScope<1> hs(self);
Handle<mirror::Class> h_k(hs.NewHandle(k));
// Is this field in any of this class' interfaces?
diff --git a/runtime/mirror/object_reference.h b/runtime/mirror/object_reference.h
index 583cfc3..f4a3580 100644
--- a/runtime/mirror/object_reference.h
+++ b/runtime/mirror/object_reference.h
@@ -55,7 +55,7 @@
}
protected:
- ObjectReference<kPoisonReferences, MirrorType>(MirrorType* mirror_ptr)
+ explicit ObjectReference(MirrorType* mirror_ptr)
REQUIRES_SHARED(Locks::mutator_lock_)
: reference_(Compress(mirror_ptr)) {
}
@@ -87,7 +87,7 @@
return HeapReference<MirrorType>(mirror_ptr);
}
private:
- HeapReference<MirrorType>(MirrorType* mirror_ptr) REQUIRES_SHARED(Locks::mutator_lock_)
+ explicit HeapReference(MirrorType* mirror_ptr) REQUIRES_SHARED(Locks::mutator_lock_)
: ObjectReference<kPoisonHeapReferences, MirrorType>(mirror_ptr) {}
};
@@ -104,7 +104,7 @@
}
private:
- CompressedReference<MirrorType>(MirrorType* p) REQUIRES_SHARED(Locks::mutator_lock_)
+ explicit CompressedReference(MirrorType* p) REQUIRES_SHARED(Locks::mutator_lock_)
: mirror::ObjectReference<false, MirrorType>(p) {}
};
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index 2b2fe0c..af9b68f 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -669,8 +669,7 @@
caller.Assign(GetCallingClass(soa.Self(), 1));
}
if (UNLIKELY(caller.Get() != nullptr && !VerifyAccess(
- soa.Self(), receiver.Get(), declaring_class, constructor->GetAccessFlags(),
- caller.Get()))) {
+ receiver.Get(), declaring_class, constructor->GetAccessFlags(), caller.Get()))) {
soa.Self()->ThrowNewExceptionF(
"Ljava/lang/IllegalAccessException;", "%s is not accessible from %s",
PrettyMethod(constructor).c_str(), PrettyClass(caller.Get()).c_str());
diff --git a/runtime/noop_compiler_callbacks.h b/runtime/noop_compiler_callbacks.h
index 02081cb..9c777cc 100644
--- a/runtime/noop_compiler_callbacks.h
+++ b/runtime/noop_compiler_callbacks.h
@@ -36,6 +36,8 @@
// to disable the relocation since both deal with writing out the images directly.
bool IsRelocationPossible() OVERRIDE { return false; }
+ verifier::VerifierDeps* GetVerifierDeps() const OVERRIDE { return nullptr; }
+
private:
DISALLOW_COPY_AND_ASSIGN(NoopCompilerCallbacks);
};
diff --git a/runtime/oat.h b/runtime/oat.h
index 35d0c92..12a8298 100644
--- a/runtime/oat.h
+++ b/runtime/oat.h
@@ -171,7 +171,7 @@
class PACKED(4) OatMethodOffsets {
public:
- OatMethodOffsets(uint32_t code_offset = 0);
+ explicit OatMethodOffsets(uint32_t code_offset = 0);
~OatMethodOffsets();
diff --git a/runtime/oat_quick_method_header.h b/runtime/oat_quick_method_header.h
index abddc6d..ee5002f 100644
--- a/runtime/oat_quick_method_header.h
+++ b/runtime/oat_quick_method_header.h
@@ -30,11 +30,11 @@
// OatQuickMethodHeader precedes the raw code chunk generated by the compiler.
class PACKED(4) OatQuickMethodHeader {
public:
- OatQuickMethodHeader(uint32_t vmap_table_offset = 0U,
- uint32_t frame_size_in_bytes = 0U,
- uint32_t core_spill_mask = 0U,
- uint32_t fp_spill_mask = 0U,
- uint32_t code_size = 0U);
+ explicit OatQuickMethodHeader(uint32_t vmap_table_offset = 0U,
+ uint32_t frame_size_in_bytes = 0U,
+ uint32_t core_spill_mask = 0U,
+ uint32_t fp_spill_mask = 0U,
+ uint32_t code_size = 0U);
~OatQuickMethodHeader();
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index f2af3da..67e3fe8 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -625,8 +625,12 @@
// If method is not set to be accessible, verify it can be accessed by the caller.
mirror::Class* calling_class = nullptr;
- if (!accessible && !VerifyAccess(soa.Self(), receiver, declaring_class, m->GetAccessFlags(),
- &calling_class, num_frames)) {
+ if (!accessible && !VerifyAccess(soa.Self(),
+ receiver,
+ declaring_class,
+ m->GetAccessFlags(),
+ &calling_class,
+ num_frames)) {
ThrowIllegalAccessException(
StringPrintf("Class %s cannot access %s method %s of class %s",
calling_class == nullptr ? "null" : PrettyClass(calling_class).c_str(),
@@ -857,15 +861,17 @@
return false;
}
*calling_class = klass;
- return VerifyAccess(self, obj, declaring_class, access_flags, klass);
+ return VerifyAccess(obj, declaring_class, access_flags, klass);
}
-bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class,
- uint32_t access_flags, mirror::Class* calling_class) {
+bool VerifyAccess(mirror::Object* obj,
+ mirror::Class* declaring_class,
+ uint32_t access_flags,
+ mirror::Class* calling_class) {
if (calling_class == declaring_class) {
return true;
}
- ScopedAssertNoThreadSuspension sants(self, "verify-access");
+ ScopedAssertNoThreadSuspension sants("verify-access");
if ((access_flags & kAccPrivate) != 0) {
return false;
}
diff --git a/runtime/reflection.h b/runtime/reflection.h
index 579c6b1..208b533 100644
--- a/runtime/reflection.h
+++ b/runtime/reflection.h
@@ -74,8 +74,10 @@
REQUIRES_SHARED(Locks::mutator_lock_);
// This version takes a known calling class.
-bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class,
- uint32_t access_flags, mirror::Class* calling_class)
+bool VerifyAccess(mirror::Object* obj,
+ mirror::Class* declaring_class,
+ uint32_t access_flags,
+ mirror::Class* calling_class)
REQUIRES_SHARED(Locks::mutator_lock_);
// Get the calling class by using a stack visitor, may return null for unattached native threads.
diff --git a/runtime/thread.h b/runtime/thread.h
index b53cc2e..016c2bc 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -1546,19 +1546,25 @@
class SCOPED_CAPABILITY ScopedAssertNoThreadSuspension {
public:
- ScopedAssertNoThreadSuspension(Thread* self, const char* cause) ACQUIRE(Roles::uninterruptible_)
- : self_(self), old_cause_(self->StartAssertNoThreadSuspension(cause)) {
+ ALWAYS_INLINE ScopedAssertNoThreadSuspension(const char* cause) ACQUIRE(Roles::uninterruptible_) {
+ if (kIsDebugBuild) {
+ self_ = Thread::Current();
+ old_cause_ = self_->StartAssertNoThreadSuspension(cause);
+ } else {
+ Roles::uninterruptible_.Acquire(); // No-op.
+ }
}
- ~ScopedAssertNoThreadSuspension() RELEASE(Roles::uninterruptible_) {
- self_->EndAssertNoThreadSuspension(old_cause_);
- }
- Thread* Self() {
- return self_;
+ ALWAYS_INLINE ~ScopedAssertNoThreadSuspension() RELEASE(Roles::uninterruptible_) {
+ if (kIsDebugBuild) {
+ self_->EndAssertNoThreadSuspension(old_cause_);
+ } else {
+ Roles::uninterruptible_.Release(); // No-op.
+ }
}
private:
- Thread* const self_;
- const char* const old_cause_;
+ Thread* self_;
+ const char* old_cause_;
};
class ScopedStackedShadowFramePusher {
diff --git a/runtime/thread_list.h b/runtime/thread_list.h
index 5880085..cef4ed1 100644
--- a/runtime/thread_list.h
+++ b/runtime/thread_list.h
@@ -209,7 +209,7 @@
// Helper for suspending all threads and
class ScopedSuspendAll : public ValueObject {
public:
- ScopedSuspendAll(const char* cause, bool long_suspend = false)
+ explicit ScopedSuspendAll(const char* cause, bool long_suspend = false)
EXCLUSIVE_LOCK_FUNCTION(Locks::mutator_lock_)
REQUIRES(!Locks::thread_list_lock_,
!Locks::thread_suspend_count_lock_,
diff --git a/runtime/utils.cc b/runtime/utils.cc
index d48edcf..6f10aaa 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -442,6 +442,12 @@
if ((access_flags & kAccStatic) != 0) {
result += "static ";
}
+ if ((access_flags & kAccAbstract) != 0) {
+ result += "abstract ";
+ }
+ if ((access_flags & kAccInterface) != 0) {
+ result += "interface ";
+ }
if ((access_flags & kAccTransient) != 0) {
result += "transient ";
}
diff --git a/runtime/verifier/method_resolution_kind.h b/runtime/verifier/method_resolution_kind.h
new file mode 100644
index 0000000..f72eb7a
--- /dev/null
+++ b/runtime/verifier/method_resolution_kind.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_VERIFIER_METHOD_RESOLUTION_KIND_H_
+#define ART_RUNTIME_VERIFIER_METHOD_RESOLUTION_KIND_H_
+
+namespace art {
+namespace verifier {
+
+// Values corresponding to the method resolution algorithms defined in mirror::Class.
+enum MethodResolutionKind {
+ kDirectMethodResolution,
+ kVirtualMethodResolution,
+ kInterfaceMethodResolution,
+};
+
+} // namespace verifier
+} // namespace art
+
+#endif // ART_RUNTIME_VERIFIER_METHOD_RESOLUTION_KIND_H_
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 6b1170b..f1d3189 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -37,6 +37,7 @@
#include "indenter.h"
#include "intern_table.h"
#include "leb128.h"
+#include "method_resolution_kind.h"
#include "mirror/class.h"
#include "mirror/class-inl.h"
#include "mirror/dex_cache-inl.h"
@@ -47,6 +48,7 @@
#include "runtime.h"
#include "scoped_thread_state_change.h"
#include "utils.h"
+#include "verifier_deps.h"
#include "handle_scope-inl.h"
namespace art {
@@ -2189,7 +2191,7 @@
// We really do expect a reference here.
Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "return-object returns a non-reference type "
<< reg_type;
- } else if (!return_type.IsAssignableFrom(reg_type)) {
+ } else if (!return_type.IsAssignableFrom(reg_type, this)) {
if (reg_type.IsUnresolvedTypes() || return_type.IsUnresolvedTypes()) {
Fail(VERIFY_ERROR_NO_CLASS) << " can't resolve returned type '" << return_type
<< "' or '" << reg_type << "'";
@@ -2198,7 +2200,7 @@
// Check whether arrays are involved. They will show a valid class status, even
// if their components are erroneous.
if (reg_type.IsArrayTypes() && return_type.IsArrayTypes()) {
- return_type.CanAssignArray(reg_type, reg_types_, class_loader_, &soft_error);
+ return_type.CanAssignArray(reg_type, reg_types_, class_loader_, this, &soft_error);
if (soft_error) {
Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "array with erroneous component type: "
<< reg_type << " vs " << return_type;
@@ -2486,7 +2488,7 @@
break;
case Instruction::THROW: {
const RegType& res_type = work_line_->GetRegisterType(this, inst->VRegA_11x());
- if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(res_type)) {
+ if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(res_type, this)) {
if (res_type.IsUninitializedTypes()) {
Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "thrown exception not initialized";
} else if (!res_type.IsReferenceTypes()) {
@@ -2639,7 +2641,8 @@
cast_type.HasClass() && // Could be conflict type, make sure it has a class.
!cast_type.GetClass()->IsInterface() &&
(orig_type.IsZero() ||
- orig_type.IsStrictlyAssignableFrom(cast_type.Merge(orig_type, ®_types_)))) {
+ orig_type.IsStrictlyAssignableFrom(
+ cast_type.Merge(orig_type, ®_types_, this), this))) {
RegisterLine* update_line = RegisterLine::Create(code_item_->registers_size_, this);
if (inst->Opcode() == Instruction::IF_EQZ) {
fallthrough_line.reset(update_line);
@@ -3636,8 +3639,13 @@
return *result;
}
if (klass == nullptr && !result->IsUnresolvedTypes()) {
- dex_cache_->SetResolvedType(class_idx, result->GetClass());
+ klass = result->GetClass();
+ dex_cache_->SetResolvedType(class_idx, klass);
}
+
+ // Record result of class resolution attempt.
+ VerifierDeps::MaybeRecordClassResolution(*dex_file_, class_idx, klass);
+
// Check if access is allowed. Unresolved types use xxxWithAccessCheck to
// check at runtime if access is allowed and so pass here. If result is
// primitive, skip the access check.
@@ -3664,7 +3672,7 @@
common_super = ®_types_.JavaLangThrowable(false);
} else {
const RegType& exception = ResolveClassAndCheckAccess(iterator.GetHandlerTypeIndex());
- if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(exception)) {
+ if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(exception, this)) {
DCHECK(!exception.IsUninitializedTypes()); // Comes from dex, shouldn't be uninit.
if (exception.IsUnresolvedTypes()) {
// We don't know enough about the type. Fail here and let runtime handle it.
@@ -3679,9 +3687,10 @@
} else if (common_super->Equals(exception)) {
// odd case, but nothing to do
} else {
- common_super = &common_super->Merge(exception, ®_types_);
+ common_super = &common_super->Merge(exception, ®_types_, this);
if (FailOrAbort(this,
- reg_types_.JavaLangThrowable(false).IsAssignableFrom(*common_super),
+ reg_types_.JavaLangThrowable(false).IsAssignableFrom(
+ *common_super, this),
"java.lang.Throwable is not assignable-from common_super at ",
work_insn_idx_)) {
break;
@@ -3701,6 +3710,20 @@
return *common_super;
}
+inline static MethodResolutionKind GetMethodResolutionKind(
+ MethodType method_type, bool is_interface) {
+ if (method_type == METHOD_DIRECT || method_type == METHOD_STATIC) {
+ return kDirectMethodResolution;
+ } else if (method_type == METHOD_INTERFACE) {
+ return kInterfaceMethodResolution;
+ } else if (method_type == METHOD_SUPER && is_interface) {
+ return kInterfaceMethodResolution;
+ } else {
+ DCHECK(method_type == METHOD_VIRTUAL || method_type == METHOD_SUPER);
+ return kVirtualMethodResolution;
+ }
+}
+
ArtMethod* MethodVerifier::ResolveMethodAndCheckAccess(
uint32_t dex_method_idx, MethodType method_type) {
const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx);
@@ -3718,6 +3741,7 @@
const RegType& referrer = GetDeclaringClass();
auto* cl = Runtime::Current()->GetClassLinker();
auto pointer_size = cl->GetImagePointerSize();
+ MethodResolutionKind res_kind = GetMethodResolutionKind(method_type, klass->IsInterface());
ArtMethod* res_method = dex_cache_->GetResolvedMethod(dex_method_idx, pointer_size);
bool stash_method = false;
@@ -3725,35 +3749,44 @@
const char* name = dex_file_->GetMethodName(method_id);
const Signature signature = dex_file_->GetMethodSignature(method_id);
- if (method_type == METHOD_DIRECT || method_type == METHOD_STATIC) {
+ if (res_kind == kDirectMethodResolution) {
res_method = klass->FindDirectMethod(name, signature, pointer_size);
- } else if (method_type == METHOD_INTERFACE) {
- res_method = klass->FindInterfaceMethod(name, signature, pointer_size);
- } else if (method_type == METHOD_SUPER && klass->IsInterface()) {
- res_method = klass->FindInterfaceMethod(name, signature, pointer_size);
- } else {
- DCHECK(method_type == METHOD_VIRTUAL || method_type == METHOD_SUPER);
+ } else if (res_kind == kVirtualMethodResolution) {
res_method = klass->FindVirtualMethod(name, signature, pointer_size);
+ } else {
+ DCHECK_EQ(res_kind, kInterfaceMethodResolution);
+ res_method = klass->FindInterfaceMethod(name, signature, pointer_size);
}
+
if (res_method != nullptr) {
stash_method = true;
} else {
// If a virtual or interface method wasn't found with the expected type, look in
// the direct methods. This can happen when the wrong invoke type is used or when
// a class has changed, and will be flagged as an error in later checks.
- if (method_type == METHOD_INTERFACE ||
- method_type == METHOD_VIRTUAL ||
- method_type == METHOD_SUPER) {
+ // Note that in this case, we do not put the resolved method in the Dex cache
+ // because it was not discovered using the expected type of method resolution.
+ if (res_kind != kDirectMethodResolution) {
+ // Record result of the initial resolution attempt.
+ VerifierDeps::MaybeRecordMethodResolution(*dex_file_, dex_method_idx, res_kind, nullptr);
+ // Change resolution type to 'direct' and try to resolve again.
+ res_kind = kDirectMethodResolution;
res_method = klass->FindDirectMethod(name, signature, pointer_size);
}
- if (res_method == nullptr) {
- Fail(VERIFY_ERROR_NO_METHOD) << "couldn't find method "
- << PrettyDescriptor(klass) << "." << name
- << " " << signature;
- return nullptr;
- }
}
}
+
+ // Record result of method resolution attempt.
+ VerifierDeps::MaybeRecordMethodResolution(*dex_file_, dex_method_idx, res_kind, res_method);
+
+ if (res_method == nullptr) {
+ Fail(VERIFY_ERROR_NO_METHOD) << "couldn't find method "
+ << PrettyDescriptor(klass) << "."
+ << dex_file_->GetMethodName(method_id) << " "
+ << dex_file_->GetMethodSignature(method_id);
+ return nullptr;
+ }
+
// Make sure calls to constructors are "direct". There are additional restrictions but we don't
// enforce them here.
if (res_method->IsConstructor() && method_type != METHOD_DIRECT) {
@@ -3897,7 +3930,7 @@
dex_file_->StringByTypeIdx(class_idx),
false);
}
- if (!res_method_class->IsAssignableFrom(adjusted_type)) {
+ if (!res_method_class->IsAssignableFrom(adjusted_type, this)) {
Fail(adjusted_type.IsUnresolvedTypes()
? VERIFY_ERROR_NO_CLASS
: VERIFY_ERROR_BAD_CLASS_SOFT)
@@ -4029,12 +4062,15 @@
// has a vtable entry for the target method. Or the target is on a interface.
if (method_type == METHOD_SUPER) {
uint16_t class_idx = dex_file_->GetMethodId(method_idx).class_idx_;
- mirror::Class* reference_class = dex_cache_->GetResolvedType(class_idx);
- if (reference_class == nullptr) {
+ const RegType& reference_type = reg_types_.FromDescriptor(
+ GetClassLoader(),
+ dex_file_->StringByTypeIdx(class_idx),
+ false);
+ if (reference_type.IsUnresolvedTypes()) {
Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "Unable to find referenced class from invoke-super";
return nullptr;
}
- if (reference_class->IsInterface()) {
+ if (reference_type.GetClass()->IsInterface()) {
// TODO Can we verify anything else.
if (class_idx == class_def_.class_idx_) {
Fail(VERIFY_ERROR_CLASS_CHANGE) << "Cannot invoke-super on self as interface";
@@ -4046,12 +4082,12 @@
Fail(VERIFY_ERROR_NO_CLASS) << "Unable to resolve the full class of 'this' used in an"
<< "interface invoke-super";
return nullptr;
- } else if (!reference_class->IsAssignableFrom(GetDeclaringClass().GetClass())) {
+ } else if (!reference_type.IsStrictlyAssignableFrom(GetDeclaringClass(), this)) {
Fail(VERIFY_ERROR_CLASS_CHANGE)
<< "invoke-super in " << PrettyClass(GetDeclaringClass().GetClass()) << " in method "
<< PrettyMethod(dex_method_idx_, *dex_file_) << " to method "
<< PrettyMethod(method_idx, *dex_file_) << " references "
- << "non-super-interface type " << PrettyClass(reference_class);
+ << "non-super-interface type " << PrettyClass(reference_type.GetClass());
return nullptr;
}
} else {
@@ -4062,7 +4098,7 @@
<< " to super " << PrettyMethod(res_method);
return nullptr;
}
- if (!reference_class->IsAssignableFrom(GetDeclaringClass().GetClass()) ||
+ if (!reference_type.IsStrictlyAssignableFrom(GetDeclaringClass(), this) ||
(res_method->GetMethodIndex() >= super.GetClass()->GetVTableLength())) {
Fail(VERIFY_ERROR_NO_METHOD) << "invalid invoke-super from "
<< PrettyMethod(dex_method_idx_, *dex_file_)
@@ -4177,7 +4213,7 @@
std::string temp;
const RegType& res_method_class =
FromClass(klass->GetDescriptor(&temp), klass, klass->CannotBeAssignedFromOtherTypes());
- if (!res_method_class.IsAssignableFrom(actual_arg_type)) {
+ if (!res_method_class.IsAssignableFrom(actual_arg_type, this)) {
Fail(actual_arg_type.IsUninitializedTypes() // Just overcautious - should have never
? VERIFY_ERROR_BAD_CLASS_HARD // quickened this.
: actual_arg_type.IsUnresolvedTypes()
@@ -4466,8 +4502,11 @@
return nullptr; // Can't resolve Class so no more to do here, will do checking at runtime.
}
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- ArtField* field = class_linker->ResolveFieldJLS(*dex_file_, field_idx, dex_cache_,
- class_loader_);
+ ArtField* field = class_linker->ResolveFieldJLS(*dex_file_, field_idx, dex_cache_, class_loader_);
+
+ // Record result of the field resolution attempt.
+ VerifierDeps::MaybeRecordFieldResolution(*dex_file_, field_idx, field);
+
if (field == nullptr) {
VLOG(verifier) << "Unable to resolve static field " << field_idx << " ("
<< dex_file_->GetFieldName(field_id) << ") in "
@@ -4501,8 +4540,11 @@
return nullptr; // Can't resolve Class so no more to do here
}
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- ArtField* field = class_linker->ResolveFieldJLS(*dex_file_, field_idx, dex_cache_,
- class_loader_);
+ ArtField* field = class_linker->ResolveFieldJLS(*dex_file_, field_idx, dex_cache_, class_loader_);
+
+ // Record result of the field resolution attempt.
+ VerifierDeps::MaybeRecordFieldResolution(*dex_file_, field_idx, field);
+
if (field == nullptr) {
VLOG(verifier) << "Unable to resolve instance field " << field_idx << " ("
<< dex_file_->GetFieldName(field_id) << ") in "
@@ -4536,7 +4578,7 @@
<< " of " << PrettyMethod(dex_method_idx_, *dex_file_);
return nullptr;
}
- } else if (!field_klass.IsAssignableFrom(obj_type)) {
+ } else if (!field_klass.IsAssignableFrom(obj_type, this)) {
// Trying to access C1.field1 using reference of type C2, which is neither C1 or a sub-class
// of C1. For resolution to occur the declared class of the field must be compatible with
// obj_type, we've discovered this wasn't so, so report the field didn't exist.
@@ -4643,7 +4685,7 @@
if (is_primitive) {
VerifyPrimitivePut(*field_type, insn_type, vregA);
} else {
- if (!insn_type.IsAssignableFrom(*field_type)) {
+ if (!insn_type.IsAssignableFrom(*field_type, this)) {
// If the field type is not a reference, this is a global failure rather than
// a class change failure as the instructions and the descriptors for the type
// should have been consistent within the same file at compile time.
@@ -4675,7 +4717,7 @@
return;
}
} else {
- if (!insn_type.IsAssignableFrom(*field_type)) {
+ if (!insn_type.IsAssignableFrom(*field_type, this)) {
// If the field type is not a reference, this is a global failure rather than
// a class change failure as the instructions and the descriptors for the type
// should have been consistent within the same file at compile time.
@@ -4806,7 +4848,7 @@
return;
}
} else {
- if (!insn_type.IsAssignableFrom(*field_type)) {
+ if (!insn_type.IsAssignableFrom(*field_type, this)) {
Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "expected field " << PrettyField(field)
<< " to be compatible with type '" << insn_type
<< "' but found type '" << *field_type
@@ -4832,7 +4874,7 @@
return;
}
} else {
- if (!insn_type.IsAssignableFrom(*field_type)) {
+ if (!insn_type.IsAssignableFrom(*field_type, this)) {
Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "expected field " << PrettyField(field)
<< " to be compatible with type '" << insn_type
<< "' but found type '" << *field_type
diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h
index c4b1c6e..eb8b7a6 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -180,6 +180,11 @@
uint8_t EncodePcToReferenceMapData() const;
+ const DexFile& GetDexFile() const {
+ DCHECK(dex_file_ != nullptr);
+ return *dex_file_;
+ }
+
uint32_t DexFileVersion() const {
return dex_file_->GetVersion();
}
@@ -353,7 +358,8 @@
* (3) Iterate through the method, checking type safety and looking
* for code flow problems.
*/
- static FailureData VerifyMethod(Thread* self, uint32_t method_idx,
+ static FailureData VerifyMethod(Thread* self,
+ uint32_t method_idx,
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
@@ -842,6 +848,7 @@
MethodVerifier* link_;
friend class art::Thread;
+ friend class VerifierDepsTest;
DISALLOW_COPY_AND_ASSIGN(MethodVerifier);
};
diff --git a/runtime/verifier/reg_type-inl.h b/runtime/verifier/reg_type-inl.h
index 861db3c..d93aaa1 100644
--- a/runtime/verifier/reg_type-inl.h
+++ b/runtime/verifier/reg_type-inl.h
@@ -22,6 +22,8 @@
#include "base/casts.h"
#include "base/scoped_arena_allocator.h"
#include "mirror/class.h"
+#include "method_verifier.h"
+#include "verifier_deps.h"
namespace art {
namespace verifier {
@@ -62,7 +64,10 @@
}
}
-inline bool RegType::AssignableFrom(const RegType& lhs, const RegType& rhs, bool strict) {
+inline bool RegType::AssignableFrom(const RegType& lhs,
+ const RegType& rhs,
+ bool strict,
+ MethodVerifier* verifier) {
if (lhs.Equals(rhs)) {
return true;
} else {
@@ -104,10 +109,15 @@
return true;
} else if (lhs.IsJavaLangObjectArray()) {
return rhs.IsObjectArrayTypes(); // All reference arrays may be assigned to Object[]
- } else if (lhs.HasClass() && rhs.HasClass() &&
- lhs.GetClass()->IsAssignableFrom(rhs.GetClass())) {
- // We're assignable from the Class point-of-view.
- return true;
+ } else if (lhs.HasClass() && rhs.HasClass()) {
+ // Test assignability from the Class point-of-view.
+ bool result = lhs.GetClass()->IsAssignableFrom(rhs.GetClass());
+ // Record assignability dependency. The `verifier` is null during unit tests.
+ if (verifier != nullptr) {
+ VerifierDeps::MaybeRecordAssignability(
+ verifier->GetDexFile(), lhs.GetClass(), rhs.GetClass(), strict, result);
+ }
+ return result;
} else {
// Unresolved types are only assignable for null and equality.
return false;
@@ -116,12 +126,12 @@
}
}
-inline bool RegType::IsAssignableFrom(const RegType& src) const {
- return AssignableFrom(*this, src, false);
+inline bool RegType::IsAssignableFrom(const RegType& src, MethodVerifier* verifier) const {
+ return AssignableFrom(*this, src, false, verifier);
}
-inline bool RegType::IsStrictlyAssignableFrom(const RegType& src) const {
- return AssignableFrom(*this, src, true);
+inline bool RegType::IsStrictlyAssignableFrom(const RegType& src, MethodVerifier* verifier) const {
+ return AssignableFrom(*this, src, true, verifier);
}
inline const DoubleHiType* DoubleHiType::GetInstance() {
diff --git a/runtime/verifier/reg_type.cc b/runtime/verifier/reg_type.cc
index 5c19969..3bc2acc 100644
--- a/runtime/verifier/reg_type.cc
+++ b/runtime/verifier/reg_type.cc
@@ -21,6 +21,7 @@
#include "base/casts.h"
#include "class_linker-inl.h"
#include "dex_file-inl.h"
+#include "method_verifier.h"
#include "mirror/class.h"
#include "mirror/class-inl.h"
#include "mirror/object-inl.h"
@@ -575,7 +576,9 @@
return a.IsConstantTypes() ? b : a;
}
-const RegType& RegType::Merge(const RegType& incoming_type, RegTypeCache* reg_types) const {
+const RegType& RegType::Merge(const RegType& incoming_type,
+ RegTypeCache* reg_types,
+ MethodVerifier* verifier) const {
DCHECK(!Equals(incoming_type)); // Trivial equality handled by caller
// Perform pointer equality tests for undefined and conflict to avoid virtual method dispatch.
const UndefinedType& undefined = reg_types->Undefined();
@@ -696,13 +699,21 @@
// have two sub-classes and don't know how to merge. Create a new string-based unresolved
// type that reflects our lack of knowledge and that allows the rest of the unresolved
// mechanics to continue.
- return reg_types->FromUnresolvedMerge(*this, incoming_type);
+ return reg_types->FromUnresolvedMerge(*this, incoming_type, verifier);
} else { // Two reference types, compute Join
mirror::Class* c1 = GetClass();
mirror::Class* c2 = incoming_type.GetClass();
DCHECK(c1 != nullptr && !c1->IsPrimitive());
DCHECK(c2 != nullptr && !c2->IsPrimitive());
mirror::Class* join_class = ClassJoin(c1, c2);
+ // Record the dependency that both `c1` and `c2` are assignable to `join_class`.
+ // The `verifier` is null during unit tests.
+ if (verifier != nullptr) {
+ VerifierDeps::MaybeRecordAssignability(
+ verifier->GetDexFile(), join_class, c1, true /* strict */, true /* is_assignable */);
+ VerifierDeps::MaybeRecordAssignability(
+ verifier->GetDexFile(), join_class, c2, true /* strict */, true /* is_assignable */);
+ }
if (c1 == join_class && !IsPreciseReference()) {
return *this;
} else if (c2 == join_class && !incoming_type.IsPreciseReference()) {
@@ -873,8 +884,11 @@
return os;
}
-bool RegType::CanAssignArray(const RegType& src, RegTypeCache& reg_types,
- Handle<mirror::ClassLoader> class_loader, bool* soft_error) const {
+bool RegType::CanAssignArray(const RegType& src,
+ RegTypeCache& reg_types,
+ Handle<mirror::ClassLoader> class_loader,
+ MethodVerifier* verifier,
+ bool* soft_error) const {
if (!IsArrayTypes() || !src.IsArrayTypes()) {
*soft_error = false;
return false;
@@ -891,7 +905,7 @@
const RegType& cmp1 = reg_types.GetComponentType(*this, class_loader.Get());
const RegType& cmp2 = reg_types.GetComponentType(src, class_loader.Get());
- if (cmp1.IsAssignableFrom(cmp2)) {
+ if (cmp1.IsAssignableFrom(cmp2, verifier)) {
return true;
}
if (cmp1.IsUnresolvedTypes()) {
@@ -914,7 +928,7 @@
*soft_error = false;
return false;
}
- return cmp1.CanAssignArray(cmp2, reg_types, class_loader, soft_error);
+ return cmp1.CanAssignArray(cmp2, reg_types, class_loader, verifier, soft_error);
}
diff --git a/runtime/verifier/reg_type.h b/runtime/verifier/reg_type.h
index c3ed77a..9170bb1 100644
--- a/runtime/verifier/reg_type.h
+++ b/runtime/verifier/reg_type.h
@@ -43,7 +43,9 @@
namespace verifier {
+class MethodVerifier;
class RegTypeCache;
+
/*
* RegType holds information about the "type" of data held in a register.
*/
@@ -210,7 +212,7 @@
// Note: Object and interface types may always be assigned to one another, see
// comment on
// ClassJoin.
- bool IsAssignableFrom(const RegType& src) const
+ bool IsAssignableFrom(const RegType& src, MethodVerifier* verifier) const
REQUIRES_SHARED(Locks::mutator_lock_);
// Can this array type potentially be assigned by src.
@@ -220,14 +222,17 @@
// will be set to true iff the assignment test failure should be treated as a soft-error, i.e.,
// when both array types have the same 'depth' and the 'final' component types may be assignable
// (both are reference types).
- bool CanAssignArray(const RegType& src, RegTypeCache& reg_types,
- Handle<mirror::ClassLoader> class_loader, bool* soft_error) const
+ bool CanAssignArray(const RegType& src,
+ RegTypeCache& reg_types,
+ Handle<mirror::ClassLoader> class_loader,
+ MethodVerifier* verifier,
+ bool* soft_error) const
REQUIRES_SHARED(Locks::mutator_lock_);
// Can this type be assigned by src? Variant of IsAssignableFrom that doesn't
// allow assignment to
// an interface from an Object.
- bool IsStrictlyAssignableFrom(const RegType& src) const
+ bool IsStrictlyAssignableFrom(const RegType& src, MethodVerifier* verifier) const
REQUIRES_SHARED(Locks::mutator_lock_);
// Are these RegTypes the same?
@@ -235,36 +240,21 @@
// Compute the merge of this register from one edge (path) with incoming_type
// from another.
- const RegType& Merge(const RegType& incoming_type, RegTypeCache* reg_types) const
+ const RegType& Merge(const RegType& incoming_type,
+ RegTypeCache* reg_types,
+ MethodVerifier* verifier) const
REQUIRES_SHARED(Locks::mutator_lock_);
// Same as above, but also handles the case where incoming_type == this.
- const RegType& SafeMerge(const RegType& incoming_type, RegTypeCache* reg_types) const
+ const RegType& SafeMerge(const RegType& incoming_type,
+ RegTypeCache* reg_types,
+ MethodVerifier* verifier) const
REQUIRES_SHARED(Locks::mutator_lock_) {
if (Equals(incoming_type)) {
return *this;
}
- return Merge(incoming_type, reg_types);
+ return Merge(incoming_type, reg_types, verifier);
}
- /*
- * A basic Join operation on classes. For a pair of types S and T the Join, written S v T = J, is
- * S <: J, T <: J and for-all U such that S <: U, T <: U then J <: U. That is J is the parent of
- * S and T such that there isn't a parent of both S and T that isn't also the parent of J (ie J
- * is the deepest (lowest upper bound) parent of S and T).
- *
- * This operation applies for regular classes and arrays, however, for interface types there
- * needn't be a partial ordering on the types. We could solve the problem of a lack of a partial
- * order by introducing sets of types, however, the only operation permissible on an interface is
- * invoke-interface. In the tradition of Java verifiers [1] we defer the verification of interface
- * types until an invoke-interface call on the interface typed reference at runtime and allow
- * the perversion of Object being assignable to an interface type (note, however, that we don't
- * allow assignment of Object or Interface to any concrete class and are therefore type safe).
- *
- * [1] Java bytecode verification: algorithms and formalizations, Xavier Leroy
- */
- static mirror::Class* ClassJoin(mirror::Class* s, mirror::Class* t)
- REQUIRES_SHARED(Locks::mutator_lock_);
-
virtual ~RegType() {}
void VisitRoots(RootVisitor* visitor, const RootInfo& root_info) const
@@ -298,7 +288,29 @@
friend class RegTypeCache;
private:
- static bool AssignableFrom(const RegType& lhs, const RegType& rhs, bool strict)
+ /*
+ * A basic Join operation on classes. For a pair of types S and T the Join, written S v T = J, is
+ * S <: J, T <: J and for-all U such that S <: U, T <: U then J <: U. That is J is the parent of
+ * S and T such that there isn't a parent of both S and T that isn't also the parent of J (ie J
+ * is the deepest (lowest upper bound) parent of S and T).
+ *
+ * This operation applies for regular classes and arrays, however, for interface types there
+ * needn't be a partial ordering on the types. We could solve the problem of a lack of a partial
+ * order by introducing sets of types, however, the only operation permissible on an interface is
+ * invoke-interface. In the tradition of Java verifiers [1] we defer the verification of interface
+ * types until an invoke-interface call on the interface typed reference at runtime and allow
+ * the perversion of Object being assignable to an interface type (note, however, that we don't
+ * allow assignment of Object or Interface to any concrete class and are therefore type safe).
+ *
+ * [1] Java bytecode verification: algorithms and formalizations, Xavier Leroy
+ */
+ static mirror::Class* ClassJoin(mirror::Class* s, mirror::Class* t)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+ static bool AssignableFrom(const RegType& lhs,
+ const RegType& rhs,
+ bool strict,
+ MethodVerifier* verifier)
REQUIRES_SHARED(Locks::mutator_lock_);
DISALLOW_COPY_AND_ASSIGN(RegType);
diff --git a/runtime/verifier/reg_type_cache.cc b/runtime/verifier/reg_type_cache.cc
index 4d4886e..d0493e5 100644
--- a/runtime/verifier/reg_type_cache.cc
+++ b/runtime/verifier/reg_type_cache.cc
@@ -342,7 +342,9 @@
}
}
-const RegType& RegTypeCache::FromUnresolvedMerge(const RegType& left, const RegType& right) {
+const RegType& RegTypeCache::FromUnresolvedMerge(const RegType& left,
+ const RegType& right,
+ MethodVerifier* verifier) {
ArenaBitVector types(&arena_,
kDefaultArenaBitVectorBytes * kBitsPerByte, // Allocate at least 8 bytes.
true); // Is expandable.
@@ -383,7 +385,7 @@
}
// Merge the resolved parts. Left and right might be equal, so use SafeMerge.
- const RegType& resolved_parts_merged = left_resolved->SafeMerge(*right_resolved, this);
+ const RegType& resolved_parts_merged = left_resolved->SafeMerge(*right_resolved, this, verifier);
// If we get a conflict here, the merge result is a conflict, not an unresolved merge type.
if (resolved_parts_merged.IsConflict()) {
return Conflict();
diff --git a/runtime/verifier/reg_type_cache.h b/runtime/verifier/reg_type_cache.h
index 14d9509..df0fe3d 100644
--- a/runtime/verifier/reg_type_cache.h
+++ b/runtime/verifier/reg_type_cache.h
@@ -75,7 +75,9 @@
REQUIRES_SHARED(Locks::mutator_lock_);
const RegType& FromDescriptor(mirror::ClassLoader* loader, const char* descriptor, bool precise)
REQUIRES_SHARED(Locks::mutator_lock_);
- const RegType& FromUnresolvedMerge(const RegType& left, const RegType& right)
+ const RegType& FromUnresolvedMerge(const RegType& left,
+ const RegType& right,
+ MethodVerifier* verifier)
REQUIRES_SHARED(Locks::mutator_lock_);
const RegType& FromUnresolvedSuperClass(const RegType& child)
REQUIRES_SHARED(Locks::mutator_lock_);
diff --git a/runtime/verifier/reg_type_test.cc b/runtime/verifier/reg_type_test.cc
index 42a74f8..f2411b5 100644
--- a/runtime/verifier/reg_type_test.cc
+++ b/runtime/verifier/reg_type_test.cc
@@ -79,8 +79,8 @@
EXPECT_FALSE(precise_lo.CheckWidePair(precise_const));
EXPECT_TRUE(precise_lo.CheckWidePair(precise_hi));
// Test Merging.
- EXPECT_TRUE((long_lo.Merge(precise_lo, &cache)).IsLongTypes());
- EXPECT_TRUE((long_hi.Merge(precise_hi, &cache)).IsLongHighTypes());
+ EXPECT_TRUE((long_lo.Merge(precise_lo, &cache, /* verifier */ nullptr)).IsLongTypes());
+ EXPECT_TRUE((long_hi.Merge(precise_hi, &cache, /* verifier */ nullptr)).IsLongHighTypes());
}
TEST_F(RegTypeTest, Primitives) {
@@ -427,7 +427,8 @@
const RegType& resolved_ref = cache.JavaLangString();
const RegType& resolved_unintialiesd = cache.Uninitialized(resolved_ref, 10);
const RegType& unresolved_unintialized = cache.Uninitialized(unresolved_ref, 12);
- const RegType& unresolved_merged = cache.FromUnresolvedMerge(unresolved_ref, unresolved_ref_another);
+ const RegType& unresolved_merged = cache.FromUnresolvedMerge(
+ unresolved_ref, unresolved_ref_another, /* verifier */ nullptr);
std::string expected = "Unresolved Reference: java.lang.DoesNotExist";
EXPECT_EQ(expected, unresolved_ref.Dump());
@@ -488,14 +489,14 @@
RegTypeCache cache_new(true, allocator);
const RegType& string = cache_new.JavaLangString();
const RegType& Object = cache_new.JavaLangObject(true);
- EXPECT_TRUE(string.Merge(Object, &cache_new).IsJavaLangObject());
+ EXPECT_TRUE(string.Merge(Object, &cache_new, /* verifier */ nullptr).IsJavaLangObject());
// Merge two unresolved types.
const RegType& ref_type_0 = cache_new.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true);
EXPECT_TRUE(ref_type_0.IsUnresolvedReference());
const RegType& ref_type_1 = cache_new.FromDescriptor(nullptr, "Ljava/lang/DoesNotExistToo;", true);
EXPECT_FALSE(ref_type_0.Equals(ref_type_1));
- const RegType& merged = ref_type_1.Merge(ref_type_0, &cache_new);
+ const RegType& merged = ref_type_1.Merge(ref_type_0, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsUnresolvedMergedReference());
RegType& merged_nonconst = const_cast<RegType&>(merged);
@@ -518,22 +519,22 @@
const RegType& imprecise_cst = cache_new.FromCat1Const(kTestConstantValue, false);
{
// float MERGE precise cst => float.
- const RegType& merged = float_type.Merge(precise_cst, &cache_new);
+ const RegType& merged = float_type.Merge(precise_cst, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsFloat());
}
{
// precise cst MERGE float => float.
- const RegType& merged = precise_cst.Merge(float_type, &cache_new);
+ const RegType& merged = precise_cst.Merge(float_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsFloat());
}
{
// float MERGE imprecise cst => float.
- const RegType& merged = float_type.Merge(imprecise_cst, &cache_new);
+ const RegType& merged = float_type.Merge(imprecise_cst, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsFloat());
}
{
// imprecise cst MERGE float => float.
- const RegType& merged = imprecise_cst.Merge(float_type, &cache_new);
+ const RegType& merged = imprecise_cst.Merge(float_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsFloat());
}
}
@@ -554,42 +555,46 @@
const RegType& imprecise_cst_hi = cache_new.FromCat2ConstHi(kTestConstantValue, false);
{
// lo MERGE precise cst lo => lo.
- const RegType& merged = long_lo_type.Merge(precise_cst_lo, &cache_new);
+ const RegType& merged = long_lo_type.Merge(precise_cst_lo, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsLongLo());
}
{
// precise cst lo MERGE lo => lo.
- const RegType& merged = precise_cst_lo.Merge(long_lo_type, &cache_new);
+ const RegType& merged = precise_cst_lo.Merge(long_lo_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsLongLo());
}
{
// lo MERGE imprecise cst lo => lo.
- const RegType& merged = long_lo_type.Merge(imprecise_cst_lo, &cache_new);
+ const RegType& merged = long_lo_type.Merge(
+ imprecise_cst_lo, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsLongLo());
}
{
// imprecise cst lo MERGE lo => lo.
- const RegType& merged = imprecise_cst_lo.Merge(long_lo_type, &cache_new);
+ const RegType& merged = imprecise_cst_lo.Merge(
+ long_lo_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsLongLo());
}
{
// hi MERGE precise cst hi => hi.
- const RegType& merged = long_hi_type.Merge(precise_cst_hi, &cache_new);
+ const RegType& merged = long_hi_type.Merge(precise_cst_hi, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsLongHi());
}
{
// precise cst hi MERGE hi => hi.
- const RegType& merged = precise_cst_hi.Merge(long_hi_type, &cache_new);
+ const RegType& merged = precise_cst_hi.Merge(long_hi_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsLongHi());
}
{
// hi MERGE imprecise cst hi => hi.
- const RegType& merged = long_hi_type.Merge(imprecise_cst_hi, &cache_new);
+ const RegType& merged = long_hi_type.Merge(
+ imprecise_cst_hi, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsLongHi());
}
{
// imprecise cst hi MERGE hi => hi.
- const RegType& merged = imprecise_cst_hi.Merge(long_hi_type, &cache_new);
+ const RegType& merged = imprecise_cst_hi.Merge(
+ long_hi_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsLongHi());
}
}
@@ -610,42 +615,50 @@
const RegType& imprecise_cst_hi = cache_new.FromCat2ConstHi(kTestConstantValue, false);
{
// lo MERGE precise cst lo => lo.
- const RegType& merged = double_lo_type.Merge(precise_cst_lo, &cache_new);
+ const RegType& merged = double_lo_type.Merge(
+ precise_cst_lo, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsDoubleLo());
}
{
// precise cst lo MERGE lo => lo.
- const RegType& merged = precise_cst_lo.Merge(double_lo_type, &cache_new);
+ const RegType& merged = precise_cst_lo.Merge(
+ double_lo_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsDoubleLo());
}
{
// lo MERGE imprecise cst lo => lo.
- const RegType& merged = double_lo_type.Merge(imprecise_cst_lo, &cache_new);
+ const RegType& merged = double_lo_type.Merge(
+ imprecise_cst_lo, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsDoubleLo());
}
{
// imprecise cst lo MERGE lo => lo.
- const RegType& merged = imprecise_cst_lo.Merge(double_lo_type, &cache_new);
+ const RegType& merged = imprecise_cst_lo.Merge(
+ double_lo_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsDoubleLo());
}
{
// hi MERGE precise cst hi => hi.
- const RegType& merged = double_hi_type.Merge(precise_cst_hi, &cache_new);
+ const RegType& merged = double_hi_type.Merge(
+ precise_cst_hi, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsDoubleHi());
}
{
// precise cst hi MERGE hi => hi.
- const RegType& merged = precise_cst_hi.Merge(double_hi_type, &cache_new);
+ const RegType& merged = precise_cst_hi.Merge(
+ double_hi_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsDoubleHi());
}
{
// hi MERGE imprecise cst hi => hi.
- const RegType& merged = double_hi_type.Merge(imprecise_cst_hi, &cache_new);
+ const RegType& merged = double_hi_type.Merge(
+ imprecise_cst_hi, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsDoubleHi());
}
{
// imprecise cst hi MERGE hi => hi.
- const RegType& merged = imprecise_cst_hi.Merge(double_hi_type, &cache_new);
+ const RegType& merged = imprecise_cst_hi.Merge(
+ double_hi_type, &cache_new, /* verifier */ nullptr);
EXPECT_TRUE(merged.IsDoubleHi());
}
}
diff --git a/runtime/verifier/register_line-inl.h b/runtime/verifier/register_line-inl.h
index d2f3485..3823143 100644
--- a/runtime/verifier/register_line-inl.h
+++ b/runtime/verifier/register_line-inl.h
@@ -131,7 +131,7 @@
const RegType& check_type) {
// Verify the src register type against the check type refining the type of the register
const RegType& src_type = GetRegisterType(verifier, vsrc);
- if (UNLIKELY(!check_type.IsAssignableFrom(src_type))) {
+ if (UNLIKELY(!check_type.IsAssignableFrom(src_type, verifier))) {
enum VerifyError fail_type;
if (!check_type.IsNonZeroReferenceTypes() || !src_type.IsNonZeroReferenceTypes()) {
// Hard fail if one of the types is primitive, since they are concretely known.
diff --git a/runtime/verifier/register_line.cc b/runtime/verifier/register_line.cc
index 71aa94e..823336c 100644
--- a/runtime/verifier/register_line.cc
+++ b/runtime/verifier/register_line.cc
@@ -73,7 +73,7 @@
DCHECK(check_type1.CheckWidePair(check_type2));
// Verify the src register type against the check type refining the type of the register
const RegType& src_type = GetRegisterType(verifier, vsrc);
- if (!check_type1.IsAssignableFrom(src_type)) {
+ if (!check_type1.IsAssignableFrom(src_type, verifier)) {
verifier->Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "register v" << vsrc << " has type " << src_type
<< " but expected " << check_type1;
return false;
@@ -433,7 +433,8 @@
if (line_[idx] != incoming_line->line_[idx]) {
const RegType& incoming_reg_type = incoming_line->GetRegisterType(verifier, idx);
const RegType& cur_type = GetRegisterType(verifier, idx);
- const RegType& new_type = cur_type.Merge(incoming_reg_type, verifier->GetRegTypeCache());
+ const RegType& new_type = cur_type.Merge(
+ incoming_reg_type, verifier->GetRegTypeCache(), verifier);
changed = changed || !cur_type.Equals(new_type);
line_[idx] = new_type.GetId();
}
diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc
new file mode 100644
index 0000000..350c838
--- /dev/null
+++ b/runtime/verifier/verifier_deps.cc
@@ -0,0 +1,469 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "verifier_deps.h"
+
+#include "compiler_callbacks.h"
+#include "leb128.h"
+#include "mirror/class-inl.h"
+#include "runtime.h"
+
+namespace art {
+namespace verifier {
+
+VerifierDeps::VerifierDeps(const std::vector<const DexFile*>& dex_files) {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ for (const DexFile* dex_file : dex_files) {
+ DCHECK(GetDexFileDeps(*dex_file) == nullptr);
+ std::unique_ptr<DexFileDeps> deps(new DexFileDeps());
+ dex_deps_.emplace(dex_file, std::move(deps));
+ }
+}
+
+VerifierDeps::DexFileDeps* VerifierDeps::GetDexFileDeps(const DexFile& dex_file) {
+ auto it = dex_deps_.find(&dex_file);
+ return (it == dex_deps_.end()) ? nullptr : it->second.get();
+}
+
+template <typename T>
+uint16_t VerifierDeps::GetAccessFlags(T* element) {
+ static_assert(kAccJavaFlagsMask == 0xFFFF, "Unexpected value of a constant");
+ if (element == nullptr) {
+ return VerifierDeps::kUnresolvedMarker;
+ } else {
+ uint16_t access_flags = Low16Bits(element->GetAccessFlags());
+ CHECK_NE(access_flags, VerifierDeps::kUnresolvedMarker);
+ return access_flags;
+ }
+}
+
+template <typename T>
+uint32_t VerifierDeps::GetDeclaringClassStringId(const DexFile& dex_file, T* element) {
+ static_assert(kAccJavaFlagsMask == 0xFFFF, "Unexpected value of a constant");
+ if (element == nullptr) {
+ return VerifierDeps::kUnresolvedMarker;
+ } else {
+ std::string temp;
+ uint32_t string_id = GetIdFromString(
+ dex_file, element->GetDeclaringClass()->GetDescriptor(&temp));
+ return string_id;
+ }
+}
+
+uint32_t VerifierDeps::GetIdFromString(const DexFile& dex_file, const std::string& str) {
+ const DexFile::StringId* string_id = dex_file.FindStringId(str.c_str());
+ if (string_id != nullptr) {
+ // String is in the DEX file. Return its ID.
+ return dex_file.GetIndexForStringId(*string_id);
+ }
+
+ // String is not in the DEX file. Assign a new ID to it which is higher than
+ // the number of strings in the DEX file.
+
+ DexFileDeps* deps = GetDexFileDeps(dex_file);
+ DCHECK(deps != nullptr);
+
+ uint32_t num_ids_in_dex = dex_file.NumStringIds();
+ uint32_t num_extra_ids = deps->strings_.size();
+
+ for (size_t i = 0; i < num_extra_ids; ++i) {
+ if (deps->strings_[i] == str) {
+ return num_ids_in_dex + i;
+ }
+ }
+
+ deps->strings_.push_back(str);
+
+ uint32_t new_id = num_ids_in_dex + num_extra_ids;
+ CHECK_GE(new_id, num_ids_in_dex); // check for overflows
+ DCHECK_EQ(str, GetStringFromId(dex_file, new_id));
+
+ return new_id;
+}
+
+std::string VerifierDeps::GetStringFromId(const DexFile& dex_file, uint32_t string_id) {
+ uint32_t num_ids_in_dex = dex_file.NumStringIds();
+ if (string_id < num_ids_in_dex) {
+ return std::string(dex_file.StringDataByIdx(string_id));
+ } else {
+ DexFileDeps* deps = GetDexFileDeps(dex_file);
+ DCHECK(deps != nullptr);
+ string_id -= num_ids_in_dex;
+ CHECK_LT(string_id, deps->strings_.size());
+ return deps->strings_[string_id];
+ }
+}
+
+bool VerifierDeps::IsInClassPath(mirror::Class* klass) {
+ DCHECK(klass != nullptr);
+
+ mirror::DexCache* dex_cache = klass->GetDexCache();
+ if (dex_cache == nullptr) {
+ // This is a synthesized class, in this case always an array. They are not
+ // defined in the compiled DEX files and therefore are part of the classpath.
+ // We could avoid recording dependencies on arrays with component types in
+ // the compiled DEX files but we choose to record them anyway so as to
+ // record the access flags VM sets for array classes.
+ DCHECK(klass->IsArrayClass()) << PrettyDescriptor(klass);
+ return true;
+ }
+
+ const DexFile* dex_file = dex_cache->GetDexFile();
+ DCHECK(dex_file != nullptr);
+
+ // Test if the `dex_deps_` contains an entry for `dex_file`. If not, the dex
+ // file was not registered as being compiled and we assume `klass` is in the
+ // classpath.
+ return (GetDexFileDeps(*dex_file) == nullptr);
+}
+
+void VerifierDeps::AddClassResolution(const DexFile& dex_file,
+ uint16_t type_idx,
+ mirror::Class* klass) {
+ DexFileDeps* dex_deps = GetDexFileDeps(dex_file);
+ if (dex_deps == nullptr) {
+ // This invocation is from verification of a dex file which is not being compiled.
+ return;
+ }
+
+ if (klass != nullptr && !IsInClassPath(klass)) {
+ // Class resolved into one of the DEX files which are being compiled.
+ // This is not a classpath dependency.
+ return;
+ }
+
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ dex_deps->classes_.emplace(ClassResolution(type_idx, GetAccessFlags(klass)));
+}
+
+void VerifierDeps::AddFieldResolution(const DexFile& dex_file,
+ uint32_t field_idx,
+ ArtField* field) {
+ DexFileDeps* dex_deps = GetDexFileDeps(dex_file);
+ if (dex_deps == nullptr) {
+ // This invocation is from verification of a dex file which is not being compiled.
+ return;
+ }
+
+ if (field != nullptr && !IsInClassPath(field->GetDeclaringClass())) {
+ // Field resolved into one of the DEX files which are being compiled.
+ // This is not a classpath dependency.
+ return;
+ }
+
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ dex_deps->fields_.emplace(FieldResolution(
+ field_idx, GetAccessFlags(field), GetDeclaringClassStringId(dex_file, field)));
+}
+
+void VerifierDeps::AddMethodResolution(const DexFile& dex_file,
+ uint32_t method_idx,
+ MethodResolutionKind resolution_kind,
+ ArtMethod* method) {
+ DexFileDeps* dex_deps = GetDexFileDeps(dex_file);
+ if (dex_deps == nullptr) {
+ // This invocation is from verification of a dex file which is not being compiled.
+ return;
+ }
+
+ if (method != nullptr && !IsInClassPath(method->GetDeclaringClass())) {
+ // Method resolved into one of the DEX files which are being compiled.
+ // This is not a classpath dependency.
+ return;
+ }
+
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ MethodResolution method_tuple(method_idx,
+ GetAccessFlags(method),
+ GetDeclaringClassStringId(dex_file, method));
+ if (resolution_kind == kDirectMethodResolution) {
+ dex_deps->direct_methods_.emplace(method_tuple);
+ } else if (resolution_kind == kVirtualMethodResolution) {
+ dex_deps->virtual_methods_.emplace(method_tuple);
+ } else {
+ DCHECK_EQ(resolution_kind, kInterfaceMethodResolution);
+ dex_deps->interface_methods_.emplace(method_tuple);
+ }
+}
+
+void VerifierDeps::AddAssignability(const DexFile& dex_file,
+ mirror::Class* destination,
+ mirror::Class* source,
+ bool is_strict,
+ bool is_assignable) {
+ // Test that the method is only called on reference types.
+ // Note that concurrent verification of `destination` and `source` may have
+ // set their status to erroneous. However, the tests performed below rely
+ // merely on no issues with linking (valid access flags, superclass and
+ // implemented interfaces). If the class at any point reached the IsResolved
+ // status, the requirement holds. This is guaranteed by RegTypeCache::ResolveClass.
+ DCHECK(destination != nullptr && !destination->IsPrimitive());
+ DCHECK(source != nullptr && !source->IsPrimitive());
+
+ if (destination == source ||
+ destination->IsObjectClass() ||
+ (!is_strict && destination->IsInterface())) {
+ // Cases when `destination` is trivially assignable from `source`.
+ DCHECK(is_assignable);
+ return;
+ }
+
+ DCHECK_EQ(is_assignable, destination->IsAssignableFrom(source));
+
+ if (destination->IsArrayClass() && source->IsArrayClass()) {
+ // Both types are arrays. Break down to component types and add recursively.
+ // This helps filter out destinations from compiled DEX files (see below)
+ // and deduplicate entries with the same canonical component type.
+ mirror::Class* destination_component = destination->GetComponentType();
+ mirror::Class* source_component = source->GetComponentType();
+
+ // Only perform the optimization if both types are resolved which guarantees
+ // that they linked successfully, as required at the top of this method.
+ if (destination_component->IsResolved() && source_component->IsResolved()) {
+ AddAssignability(dex_file,
+ destination_component,
+ source_component,
+ /* is_strict */ true,
+ is_assignable);
+ return;
+ }
+ }
+
+ DexFileDeps* dex_deps = GetDexFileDeps(dex_file);
+ if (dex_deps == nullptr) {
+ // This invocation is from verification of a DEX file which is not being compiled.
+ return;
+ }
+
+ if (!IsInClassPath(destination) && !IsInClassPath(source)) {
+ // Both `destination` and `source` are defined in the compiled DEX files.
+ // No need to record a dependency.
+ return;
+ }
+
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+
+ // Get string IDs for both descriptors and store in the appropriate set.
+
+ std::string temp1, temp2;
+ std::string destination_desc(destination->GetDescriptor(&temp1));
+ std::string source_desc(source->GetDescriptor(&temp2));
+ uint32_t destination_id = GetIdFromString(dex_file, destination_desc);
+ uint32_t source_id = GetIdFromString(dex_file, source_desc);
+
+ if (is_assignable) {
+ dex_deps->assignable_types_.emplace(TypeAssignability(destination_id, source_id));
+ } else {
+ dex_deps->unassignable_types_.emplace(TypeAssignability(destination_id, source_id));
+ }
+}
+
+static inline VerifierDeps* GetVerifierDepsSingleton() {
+ CompilerCallbacks* callbacks = Runtime::Current()->GetCompilerCallbacks();
+ if (callbacks == nullptr) {
+ return nullptr;
+ }
+ return callbacks->GetVerifierDeps();
+}
+
+void VerifierDeps::MaybeRecordClassResolution(const DexFile& dex_file,
+ uint16_t type_idx,
+ mirror::Class* klass) {
+ VerifierDeps* singleton = GetVerifierDepsSingleton();
+ if (singleton != nullptr) {
+ singleton->AddClassResolution(dex_file, type_idx, klass);
+ }
+}
+
+void VerifierDeps::MaybeRecordFieldResolution(const DexFile& dex_file,
+ uint32_t field_idx,
+ ArtField* field) {
+ VerifierDeps* singleton = GetVerifierDepsSingleton();
+ if (singleton != nullptr) {
+ singleton->AddFieldResolution(dex_file, field_idx, field);
+ }
+}
+
+void VerifierDeps::MaybeRecordMethodResolution(const DexFile& dex_file,
+ uint32_t method_idx,
+ MethodResolutionKind resolution_kind,
+ ArtMethod* method) {
+ VerifierDeps* singleton = GetVerifierDepsSingleton();
+ if (singleton != nullptr) {
+ singleton->AddMethodResolution(dex_file, method_idx, resolution_kind, method);
+ }
+}
+
+void VerifierDeps::MaybeRecordAssignability(const DexFile& dex_file,
+ mirror::Class* destination,
+ mirror::Class* source,
+ bool is_strict,
+ bool is_assignable) {
+ VerifierDeps* singleton = GetVerifierDepsSingleton();
+ if (singleton != nullptr) {
+ singleton->AddAssignability(dex_file, destination, source, is_strict, is_assignable);
+ }
+}
+
+static inline uint32_t DecodeUint32WithOverflowCheck(const uint8_t** in, const uint8_t* end) {
+ CHECK_LT(*in, end);
+ return DecodeUnsignedLeb128(in);
+}
+
+template<typename T1, typename T2>
+static inline void EncodeTuple(std::vector<uint8_t>* out, const std::tuple<T1, T2>& t) {
+ EncodeUnsignedLeb128(out, std::get<0>(t));
+ EncodeUnsignedLeb128(out, std::get<1>(t));
+}
+
+template<typename T1, typename T2>
+static inline void DecodeTuple(const uint8_t** in, const uint8_t* end, std::tuple<T1, T2>* t) {
+ T1 v1 = static_cast<T1>(DecodeUint32WithOverflowCheck(in, end));
+ T2 v2 = static_cast<T2>(DecodeUint32WithOverflowCheck(in, end));
+ *t = std::make_tuple(v1, v2);
+}
+
+template<typename T1, typename T2, typename T3>
+static inline void EncodeTuple(std::vector<uint8_t>* out, const std::tuple<T1, T2, T3>& t) {
+ EncodeUnsignedLeb128(out, std::get<0>(t));
+ EncodeUnsignedLeb128(out, std::get<1>(t));
+ EncodeUnsignedLeb128(out, std::get<2>(t));
+}
+
+template<typename T1, typename T2, typename T3>
+static inline void DecodeTuple(const uint8_t** in, const uint8_t* end, std::tuple<T1, T2, T3>* t) {
+ T1 v1 = static_cast<T1>(DecodeUint32WithOverflowCheck(in, end));
+ T2 v2 = static_cast<T2>(DecodeUint32WithOverflowCheck(in, end));
+ T3 v3 = static_cast<T2>(DecodeUint32WithOverflowCheck(in, end));
+ *t = std::make_tuple(v1, v2, v3);
+}
+
+template<typename T>
+static inline void EncodeSet(std::vector<uint8_t>* out, const std::set<T>& set) {
+ EncodeUnsignedLeb128(out, set.size());
+ for (const T& entry : set) {
+ EncodeTuple(out, entry);
+ }
+}
+
+template<typename T>
+static inline void DecodeSet(const uint8_t** in, const uint8_t* end, std::set<T>* set) {
+ DCHECK(set->empty());
+ size_t num_entries = DecodeUint32WithOverflowCheck(in, end);
+ for (size_t i = 0; i < num_entries; ++i) {
+ T tuple;
+ DecodeTuple(in, end, &tuple);
+ set->emplace(tuple);
+ }
+}
+
+static inline void EncodeStringVector(std::vector<uint8_t>* out,
+ const std::vector<std::string>& strings) {
+ EncodeUnsignedLeb128(out, strings.size());
+ for (const std::string& str : strings) {
+ const uint8_t* data = reinterpret_cast<const uint8_t*>(str.c_str());
+ size_t length = str.length() + 1;
+ out->insert(out->end(), data, data + length);
+ DCHECK_EQ(0u, out->back());
+ }
+}
+
+static inline void DecodeStringVector(const uint8_t** in,
+ const uint8_t* end,
+ std::vector<std::string>* strings) {
+ DCHECK(strings->empty());
+ size_t num_strings = DecodeUint32WithOverflowCheck(in, end);
+ strings->reserve(num_strings);
+ for (size_t i = 0; i < num_strings; ++i) {
+ CHECK_LT(*in, end);
+ const char* string_start = reinterpret_cast<const char*>(*in);
+ strings->emplace_back(std::string(string_start));
+ *in += strings->back().length() + 1;
+ }
+}
+
+void VerifierDeps::Encode(std::vector<uint8_t>* buffer) const {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ for (auto& entry : dex_deps_) {
+ EncodeStringVector(buffer, entry.second->strings_);
+ EncodeSet(buffer, entry.second->assignable_types_);
+ EncodeSet(buffer, entry.second->unassignable_types_);
+ EncodeSet(buffer, entry.second->classes_);
+ EncodeSet(buffer, entry.second->fields_);
+ EncodeSet(buffer, entry.second->direct_methods_);
+ EncodeSet(buffer, entry.second->virtual_methods_);
+ EncodeSet(buffer, entry.second->interface_methods_);
+ }
+}
+
+VerifierDeps::VerifierDeps(const std::vector<const DexFile*>& dex_files, ArrayRef<uint8_t> data)
+ : VerifierDeps(dex_files) {
+ const uint8_t* data_start = data.data();
+ const uint8_t* data_end = data_start + data.size();
+ for (auto& entry : dex_deps_) {
+ DecodeStringVector(&data_start, data_end, &entry.second->strings_);
+ DecodeSet(&data_start, data_end, &entry.second->assignable_types_);
+ DecodeSet(&data_start, data_end, &entry.second->unassignable_types_);
+ DecodeSet(&data_start, data_end, &entry.second->classes_);
+ DecodeSet(&data_start, data_end, &entry.second->fields_);
+ DecodeSet(&data_start, data_end, &entry.second->direct_methods_);
+ DecodeSet(&data_start, data_end, &entry.second->virtual_methods_);
+ DecodeSet(&data_start, data_end, &entry.second->interface_methods_);
+ }
+ CHECK_LE(data_start, data_end);
+}
+
+bool VerifierDeps::Equals(const VerifierDeps& rhs) const {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+
+ if (dex_deps_.size() != rhs.dex_deps_.size()) {
+ return false;
+ }
+
+ auto lhs_it = dex_deps_.begin();
+ auto rhs_it = rhs.dex_deps_.begin();
+
+ for (; (lhs_it != dex_deps_.end()) && (rhs_it != rhs.dex_deps_.end()); lhs_it++, rhs_it++) {
+ const DexFile* lhs_dex_file = lhs_it->first;
+ const DexFile* rhs_dex_file = rhs_it->first;
+ if (lhs_dex_file != rhs_dex_file) {
+ return false;
+ }
+
+ DexFileDeps* lhs_deps = lhs_it->second.get();
+ DexFileDeps* rhs_deps = rhs_it->second.get();
+ if (!lhs_deps->Equals(*rhs_deps)) {
+ return false;
+ }
+ }
+
+ DCHECK((lhs_it == dex_deps_.end()) && (rhs_it == rhs.dex_deps_.end()));
+ return true;
+}
+
+bool VerifierDeps::DexFileDeps::Equals(const VerifierDeps::DexFileDeps& rhs) const {
+ return (strings_ == rhs.strings_) &&
+ (assignable_types_ == rhs.assignable_types_) &&
+ (unassignable_types_ == rhs.unassignable_types_) &&
+ (classes_ == rhs.classes_) &&
+ (fields_ == rhs.fields_) &&
+ (direct_methods_ == rhs.direct_methods_) &&
+ (virtual_methods_ == rhs.virtual_methods_) &&
+ (interface_methods_ == rhs.interface_methods_);
+}
+
+} // namespace verifier
+} // namespace art
diff --git a/runtime/verifier/verifier_deps.h b/runtime/verifier/verifier_deps.h
new file mode 100644
index 0000000..dc8dfaf
--- /dev/null
+++ b/runtime/verifier/verifier_deps.h
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_VERIFIER_VERIFIER_DEPS_H_
+#define ART_RUNTIME_VERIFIER_VERIFIER_DEPS_H_
+
+#include <map>
+#include <set>
+#include <vector>
+
+#include "art_field.h"
+#include "art_method.h"
+#include "base/array_ref.h"
+#include "base/mutex.h"
+#include "method_resolution_kind.h"
+#include "os.h"
+
+namespace art {
+namespace verifier {
+
+// Verification dependencies collector class used by the MethodVerifier to record
+// resolution outcomes and type assignability tests of classes/methods/fields
+// not present in the set of compiled DEX files, that is classes/methods/fields
+// defined in the classpath.
+// The compilation driver initializes the class and registers all DEX files
+// which are being compiled. Classes defined in DEX files outside of this set
+// (or synthesized classes without associated DEX files) are considered being
+// in the classpath.
+// During code-flow verification, the MethodVerifier informs the VerifierDeps
+// singleton about the outcome of every resolution and assignability test, and
+// the singleton records them if their outcome may change with changes in the
+// classpath.
+class VerifierDeps {
+ public:
+ explicit VerifierDeps(const std::vector<const DexFile*>& dex_files)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ // Record the outcome `klass` of resolving type `type_idx` from `dex_file`.
+ // If `klass` is null, the class is assumed unresolved.
+ static void MaybeRecordClassResolution(const DexFile& dex_file,
+ uint16_t type_idx,
+ mirror::Class* klass)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ // Record the outcome `field` of resolving field `field_idx` from `dex_file`.
+ // If `field` is null, the field is assumed unresolved.
+ static void MaybeRecordFieldResolution(const DexFile& dex_file,
+ uint32_t field_idx,
+ ArtField* field)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ // Record the outcome `method` of resolving method `method_idx` from `dex_file`
+ // using `res_kind` kind of method resolution algorithm. If `method` is null,
+ // the method is assumed unresolved.
+ static void MaybeRecordMethodResolution(const DexFile& dex_file,
+ uint32_t method_idx,
+ MethodResolutionKind res_kind,
+ ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ // Record the outcome `is_assignable` of type assignability test from `source`
+ // to `destination` as defined by RegType::AssignableFrom. `dex_file` is the
+ // owner of the method for which MethodVerifier performed the assignability test.
+ static void MaybeRecordAssignability(const DexFile& dex_file,
+ mirror::Class* destination,
+ mirror::Class* source,
+ bool is_strict,
+ bool is_assignable)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ // Serialize the recorded dependencies and store the data into `buffer`.
+ void Encode(std::vector<uint8_t>* buffer) const
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ private:
+ static constexpr uint16_t kUnresolvedMarker = static_cast<uint16_t>(-1);
+
+ // Only used in tests to reconstruct the data structure from serialized data.
+ VerifierDeps(const std::vector<const DexFile*>& dex_files, ArrayRef<uint8_t> data)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ using ClassResolutionBase = std::tuple<uint32_t, uint16_t>;
+ struct ClassResolution : public ClassResolutionBase {
+ ClassResolution() = default;
+ ClassResolution(const ClassResolution&) = default;
+ ClassResolution(uint32_t type_idx, uint16_t access_flags)
+ : ClassResolutionBase(type_idx, access_flags) {}
+
+ bool IsResolved() const { return GetAccessFlags() != kUnresolvedMarker; }
+ uint32_t GetDexTypeIndex() const { return std::get<0>(*this); }
+ uint16_t GetAccessFlags() const { return std::get<1>(*this); }
+ };
+
+ using FieldResolutionBase = std::tuple<uint32_t, uint16_t, uint32_t>;
+ struct FieldResolution : public FieldResolutionBase {
+ FieldResolution() = default;
+ FieldResolution(const FieldResolution&) = default;
+ FieldResolution(uint32_t field_idx, uint16_t access_flags, uint32_t declaring_class_idx)
+ : FieldResolutionBase(field_idx, access_flags, declaring_class_idx) {}
+
+ bool IsResolved() const { return GetAccessFlags() != kUnresolvedMarker; }
+ uint32_t GetDexFieldIndex() const { return std::get<0>(*this); }
+ uint16_t GetAccessFlags() const { return std::get<1>(*this); }
+ uint32_t GetDeclaringClassIndex() const { return std::get<2>(*this); }
+ };
+
+ using MethodResolutionBase = std::tuple<uint32_t, uint16_t, uint32_t>;
+ struct MethodResolution : public MethodResolutionBase {
+ MethodResolution() = default;
+ MethodResolution(const MethodResolution&) = default;
+ MethodResolution(uint32_t method_idx, uint16_t access_flags, uint32_t declaring_class_idx)
+ : MethodResolutionBase(method_idx, access_flags, declaring_class_idx) {}
+
+ bool IsResolved() const { return GetAccessFlags() != kUnresolvedMarker; }
+ uint32_t GetDexMethodIndex() const { return std::get<0>(*this); }
+ uint16_t GetAccessFlags() const { return std::get<1>(*this); }
+ uint32_t GetDeclaringClassIndex() const { return std::get<2>(*this); }
+ };
+
+ using TypeAssignabilityBase = std::tuple<uint32_t, uint32_t>;
+ struct TypeAssignability : public std::tuple<uint32_t, uint32_t> {
+ TypeAssignability() = default;
+ TypeAssignability(const TypeAssignability&) = default;
+ TypeAssignability(uint32_t destination_idx, uint32_t source_idx)
+ : TypeAssignabilityBase(destination_idx, source_idx) {}
+
+ uint32_t GetDestination() const { return std::get<0>(*this); }
+ uint32_t GetSource() const { return std::get<1>(*this); }
+ };
+
+ // Data structure representing dependencies collected during verification of
+ // methods inside one DexFile.
+ struct DexFileDeps {
+ // Vector of strings which are not present in the corresponding DEX file.
+ // These are referred to with ids starting with `NumStringIds()` of that DexFile.
+ std::vector<std::string> strings_;
+
+ // Set of class pairs recording the outcome of assignability test from one
+ // of the two types to the other.
+ std::set<TypeAssignability> assignable_types_;
+ std::set<TypeAssignability> unassignable_types_;
+
+ // Sets of recorded class/field/method resolutions.
+ std::set<ClassResolution> classes_;
+ std::set<FieldResolution> fields_;
+ std::set<MethodResolution> direct_methods_;
+ std::set<MethodResolution> virtual_methods_;
+ std::set<MethodResolution> interface_methods_;
+
+ bool Equals(const DexFileDeps& rhs) const;
+ };
+
+ // Finds the DexFileDep instance associated with `dex_file`, or nullptr if
+ // `dex_file` is not reported as being compiled.
+ // We disable thread safety analysis. The method only reads the key set of
+ // `dex_deps_` which stays constant after initialization.
+ DexFileDeps* GetDexFileDeps(const DexFile& dex_file)
+ NO_THREAD_SAFETY_ANALYSIS;
+
+ // Returns true if `klass` is null or not defined in any of dex files which
+ // were reported as being compiled.
+ bool IsInClassPath(mirror::Class* klass)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+ // Returns the index of `str`. If it is defined in `dex_file_`, this is the dex
+ // string ID. If not, an ID is assigned to the string and cached in `strings_`
+ // of the corresponding DexFileDeps structure (either provided or inferred from
+ // `dex_file`).
+ uint32_t GetIdFromString(const DexFile& dex_file, const std::string& str)
+ REQUIRES(Locks::verifier_deps_lock_);
+
+ // Returns the string represented by `id`.
+ std::string GetStringFromId(const DexFile& dex_file, uint32_t string_id)
+ REQUIRES(Locks::verifier_deps_lock_);
+
+ // Returns the bytecode access flags of `element` (bottom 16 bits), or
+ // `kUnresolvedMarker` if `element` is null.
+ template <typename T>
+ uint16_t GetAccessFlags(T* element)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+ // Returns a string ID of the descriptor of the declaring class of `element`,
+ // or `kUnresolvedMarker` if `element` is null.
+ template <typename T>
+ uint32_t GetDeclaringClassStringId(const DexFile& dex_file, T* element)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(Locks::verifier_deps_lock_);
+
+ void AddClassResolution(const DexFile& dex_file,
+ uint16_t type_idx,
+ mirror::Class* klass)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ void AddFieldResolution(const DexFile& dex_file,
+ uint32_t field_idx,
+ ArtField* field)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ void AddMethodResolution(const DexFile& dex_file,
+ uint32_t method_idx,
+ MethodResolutionKind res_kind,
+ ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ void AddAssignability(const DexFile& dex_file,
+ mirror::Class* destination,
+ mirror::Class* source,
+ bool is_strict,
+ bool is_assignable)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ bool Equals(const VerifierDeps& rhs) const
+ REQUIRES(!Locks::verifier_deps_lock_);
+
+ // Map from DexFiles into dependencies collected from verification of their methods.
+ std::map<const DexFile*, std::unique_ptr<DexFileDeps>> dex_deps_
+ GUARDED_BY(Locks::verifier_deps_lock_);
+
+ friend class VerifierDepsTest;
+ ART_FRIEND_TEST(VerifierDepsTest, StringToId);
+ ART_FRIEND_TEST(VerifierDepsTest, EncodeDecode);
+};
+
+} // namespace verifier
+} // namespace art
+
+#endif // ART_RUNTIME_VERIFIER_VERIFIER_DEPS_H_
diff --git a/runtime/verifier/verifier_deps_test.cc b/runtime/verifier/verifier_deps_test.cc
new file mode 100644
index 0000000..bbaf59f
--- /dev/null
+++ b/runtime/verifier/verifier_deps_test.cc
@@ -0,0 +1,1060 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "verifier_deps.h"
+
+#include "class_linker.h"
+#include "common_runtime_test.h"
+#include "compiler_callbacks.h"
+#include "dex_file.h"
+#include "handle_scope-inl.h"
+#include "method_verifier-inl.h"
+#include "mirror/class_loader.h"
+#include "runtime.h"
+#include "thread.h"
+#include "scoped_thread_state_change.h"
+
+namespace art {
+namespace verifier {
+
+class VerifierDepsCompilerCallbacks : public CompilerCallbacks {
+ public:
+ explicit VerifierDepsCompilerCallbacks()
+ : CompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp),
+ deps_(nullptr) {}
+
+ void MethodVerified(verifier::MethodVerifier* verifier ATTRIBUTE_UNUSED) OVERRIDE {}
+ void ClassRejected(ClassReference ref ATTRIBUTE_UNUSED) OVERRIDE {}
+ bool IsRelocationPossible() OVERRIDE { return false; }
+
+ verifier::VerifierDeps* GetVerifierDeps() const OVERRIDE { return deps_; }
+ void SetVerifierDeps(verifier::VerifierDeps* deps) { deps_ = deps; }
+
+ private:
+ verifier::VerifierDeps* deps_;
+};
+
+class VerifierDepsTest : public CommonRuntimeTest {
+ public:
+ void SetUpRuntimeOptions(RuntimeOptions* options) {
+ CommonRuntimeTest::SetUpRuntimeOptions(options);
+ callbacks_.reset(new VerifierDepsCompilerCallbacks());
+ }
+
+ mirror::Class* FindClassByName(const std::string& name, ScopedObjectAccess* soa)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::ClassLoader> class_loader_handle(
+ hs.NewHandle(soa->Decode<mirror::ClassLoader*>(class_loader_)));
+ mirror::Class* klass = class_linker_->FindClass(Thread::Current(),
+ name.c_str(),
+ class_loader_handle);
+ if (klass == nullptr) {
+ DCHECK(Thread::Current()->IsExceptionPending());
+ Thread::Current()->ClearException();
+ }
+ return klass;
+ }
+
+ void SetVerifierDeps(const std::vector<const DexFile*>& dex_files) {
+ verifier_deps_.reset(new verifier::VerifierDeps(dex_files));
+ VerifierDepsCompilerCallbacks* callbacks =
+ reinterpret_cast<VerifierDepsCompilerCallbacks*>(callbacks_.get());
+ callbacks->SetVerifierDeps(verifier_deps_.get());
+ }
+
+ void LoadDexFile(ScopedObjectAccess* soa) REQUIRES_SHARED(Locks::mutator_lock_) {
+ class_loader_ = LoadDex("VerifierDeps");
+ std::vector<const DexFile*> dex_files = GetDexFiles(class_loader_);
+ CHECK_EQ(dex_files.size(), 1u);
+ dex_file_ = dex_files.front();
+
+ SetVerifierDeps(dex_files);
+
+ mirror::ClassLoader* loader = soa->Decode<mirror::ClassLoader*>(class_loader_);
+ class_linker_->RegisterDexFile(*dex_file_, loader);
+
+ klass_Main_ = FindClassByName("LMain;", soa);
+ CHECK(klass_Main_ != nullptr);
+ }
+
+ bool VerifyMethod(const std::string& method_name) {
+ ScopedObjectAccess soa(Thread::Current());
+ LoadDexFile(&soa);
+
+ StackHandleScope<2> hs(Thread::Current());
+ Handle<mirror::ClassLoader> class_loader_handle(
+ hs.NewHandle(soa.Decode<mirror::ClassLoader*>(class_loader_)));
+ Handle<mirror::DexCache> dex_cache_handle(hs.NewHandle(klass_Main_->GetDexCache()));
+
+ const DexFile::ClassDef* class_def = klass_Main_->GetClassDef();
+ const uint8_t* class_data = dex_file_->GetClassData(*class_def);
+ CHECK(class_data != nullptr);
+
+ ClassDataItemIterator it(*dex_file_, class_data);
+ while (it.HasNextStaticField() || it.HasNextInstanceField()) {
+ it.Next();
+ }
+
+ ArtMethod* method = nullptr;
+ while (it.HasNextDirectMethod()) {
+ ArtMethod* resolved_method = class_linker_->ResolveMethod<ClassLinker::kNoICCECheckForCache>(
+ *dex_file_,
+ it.GetMemberIndex(),
+ dex_cache_handle,
+ class_loader_handle,
+ nullptr,
+ it.GetMethodInvokeType(*class_def));
+ CHECK(resolved_method != nullptr);
+ if (method_name == resolved_method->GetName()) {
+ method = resolved_method;
+ break;
+ }
+ it.Next();
+ }
+ CHECK(method != nullptr);
+
+ MethodVerifier verifier(Thread::Current(),
+ dex_file_,
+ dex_cache_handle,
+ class_loader_handle,
+ *class_def,
+ it.GetMethodCodeItem(),
+ it.GetMemberIndex(),
+ method,
+ it.GetMethodAccessFlags(),
+ true /* can_load_classes */,
+ true /* allow_soft_failures */,
+ true /* need_precise_constants */,
+ false /* verify to dump */,
+ true /* allow_thread_suspension */);
+ verifier.Verify();
+ return !verifier.HasFailures();
+ }
+
+ void VerifyDexFile() {
+ std::string error_msg;
+ ScopedObjectAccess soa(Thread::Current());
+
+ LoadDexFile(&soa);
+ SetVerifierDeps({ dex_file_ });
+
+ for (size_t i = 0; i < dex_file_->NumClassDefs(); i++) {
+ const char* descriptor = dex_file_->GetClassDescriptor(dex_file_->GetClassDef(i));
+ mirror::Class* klass = FindClassByName(descriptor, &soa);
+ if (klass != nullptr) {
+ MethodVerifier::VerifyClass(Thread::Current(),
+ klass,
+ nullptr,
+ true,
+ HardFailLogMode::kLogWarning,
+ &error_msg);
+ }
+ }
+ }
+
+ bool TestAssignabilityRecording(const std::string& dst,
+ const std::string& src,
+ bool is_strict,
+ bool is_assignable) {
+ ScopedObjectAccess soa(Thread::Current());
+ LoadDexFile(&soa);
+ mirror::Class* klass_dst = FindClassByName(dst, &soa);
+ DCHECK(klass_dst != nullptr);
+ mirror::Class* klass_src = FindClassByName(src, &soa);
+ DCHECK(klass_src != nullptr);
+ verifier_deps_->AddAssignability(*dex_file_,
+ klass_dst,
+ klass_src,
+ is_strict,
+ is_assignable);
+ return true;
+ }
+
+ // Iterates over all assignability records and tries to find an entry which
+ // matches the expected destination/source pair.
+ bool HasAssignable(const std::string& expected_destination,
+ const std::string& expected_source,
+ bool expected_is_assignable) {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ for (auto& dex_dep : verifier_deps_->dex_deps_) {
+ const DexFile& dex_file = *dex_dep.first;
+ auto& storage = expected_is_assignable ? dex_dep.second->assignable_types_
+ : dex_dep.second->unassignable_types_;
+ for (auto& entry : storage) {
+ std::string actual_destination =
+ verifier_deps_->GetStringFromId(dex_file, entry.GetDestination());
+ std::string actual_source = verifier_deps_->GetStringFromId(dex_file, entry.GetSource());
+ if ((expected_destination == actual_destination) && (expected_source == actual_source)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ // Iterates over all class resolution records, finds an entry which matches
+ // the given class descriptor and tests its properties.
+ bool HasClass(const std::string& expected_klass,
+ bool expected_resolved,
+ const std::string& expected_access_flags = "") {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ for (auto& dex_dep : verifier_deps_->dex_deps_) {
+ for (auto& entry : dex_dep.second->classes_) {
+ if (expected_resolved != entry.IsResolved()) {
+ continue;
+ }
+
+ std::string actual_klass = dex_dep.first->StringByTypeIdx(entry.GetDexTypeIndex());
+ if (expected_klass != actual_klass) {
+ continue;
+ }
+
+ if (expected_resolved) {
+ // Test access flags. Note that PrettyJavaAccessFlags always appends
+ // a space after the modifiers. Add it to the expected access flags.
+ std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags());
+ if (expected_access_flags + " " != actual_access_flags) {
+ continue;
+ }
+ }
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Iterates over all field resolution records, finds an entry which matches
+ // the given field class+name+type and tests its properties.
+ bool HasField(const std::string& expected_klass,
+ const std::string& expected_name,
+ const std::string& expected_type,
+ bool expected_resolved,
+ const std::string& expected_access_flags = "",
+ const std::string& expected_decl_klass = "") {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ for (auto& dex_dep : verifier_deps_->dex_deps_) {
+ for (auto& entry : dex_dep.second->fields_) {
+ if (expected_resolved != entry.IsResolved()) {
+ continue;
+ }
+
+ const DexFile::FieldId& field_id = dex_dep.first->GetFieldId(entry.GetDexFieldIndex());
+
+ std::string actual_klass = dex_dep.first->StringByTypeIdx(field_id.class_idx_);
+ if (expected_klass != actual_klass) {
+ continue;
+ }
+
+ std::string actual_name = dex_dep.first->StringDataByIdx(field_id.name_idx_);
+ if (expected_name != actual_name) {
+ continue;
+ }
+
+ std::string actual_type = dex_dep.first->StringByTypeIdx(field_id.type_idx_);
+ if (expected_type != actual_type) {
+ continue;
+ }
+
+ if (expected_resolved) {
+ // Test access flags. Note that PrettyJavaAccessFlags always appends
+ // a space after the modifiers. Add it to the expected access flags.
+ std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags());
+ if (expected_access_flags + " " != actual_access_flags) {
+ continue;
+ }
+
+ std::string actual_decl_klass = verifier_deps_->GetStringFromId(
+ *dex_dep.first, entry.GetDeclaringClassIndex());
+ if (expected_decl_klass != actual_decl_klass) {
+ continue;
+ }
+ }
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Iterates over all method resolution records, finds an entry which matches
+ // the given field kind+class+name+signature and tests its properties.
+ bool HasMethod(const std::string& expected_kind,
+ const std::string& expected_klass,
+ const std::string& expected_name,
+ const std::string& expected_signature,
+ bool expected_resolved,
+ const std::string& expected_access_flags = "",
+ const std::string& expected_decl_klass = "") {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ for (auto& dex_dep : verifier_deps_->dex_deps_) {
+ auto& storage = (expected_kind == "direct") ? dex_dep.second->direct_methods_
+ : (expected_kind == "virtual") ? dex_dep.second->virtual_methods_
+ : dex_dep.second->interface_methods_;
+ for (auto& entry : storage) {
+ if (expected_resolved != entry.IsResolved()) {
+ continue;
+ }
+
+ const DexFile::MethodId& method_id = dex_dep.first->GetMethodId(entry.GetDexMethodIndex());
+
+ std::string actual_klass = dex_dep.first->StringByTypeIdx(method_id.class_idx_);
+ if (expected_klass != actual_klass) {
+ continue;
+ }
+
+ std::string actual_name = dex_dep.first->StringDataByIdx(method_id.name_idx_);
+ if (expected_name != actual_name) {
+ continue;
+ }
+
+ std::string actual_signature = dex_dep.first->GetMethodSignature(method_id).ToString();
+ if (expected_signature != actual_signature) {
+ continue;
+ }
+
+ if (expected_resolved) {
+ // Test access flags. Note that PrettyJavaAccessFlags always appends
+ // a space after the modifiers. Add it to the expected access flags.
+ std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags());
+ if (expected_access_flags + " " != actual_access_flags) {
+ continue;
+ }
+
+ std::string actual_decl_klass = verifier_deps_->GetStringFromId(
+ *dex_dep.first, entry.GetDeclaringClassIndex());
+ if (expected_decl_klass != actual_decl_klass) {
+ continue;
+ }
+ }
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ size_t NumberOfCompiledDexFiles() {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+ return verifier_deps_->dex_deps_.size();
+ }
+
+ size_t HasEachKindOfRecord() {
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+
+ bool has_strings = false;
+ bool has_assignability = false;
+ bool has_classes = false;
+ bool has_fields = false;
+ bool has_methods = false;
+
+ for (auto& entry : verifier_deps_->dex_deps_) {
+ has_strings |= !entry.second->strings_.empty();
+ has_assignability |= !entry.second->assignable_types_.empty();
+ has_assignability |= !entry.second->unassignable_types_.empty();
+ has_classes |= !entry.second->classes_.empty();
+ has_fields |= !entry.second->fields_.empty();
+ has_methods |= !entry.second->direct_methods_.empty();
+ has_methods |= !entry.second->virtual_methods_.empty();
+ has_methods |= !entry.second->interface_methods_.empty();
+ }
+
+ return has_strings && has_assignability && has_classes && has_fields && has_methods;
+ }
+
+ std::unique_ptr<verifier::VerifierDeps> verifier_deps_;
+ const DexFile* dex_file_;
+ jobject class_loader_;
+ mirror::Class* klass_Main_;
+};
+
+TEST_F(VerifierDepsTest, StringToId) {
+ ScopedObjectAccess soa(Thread::Current());
+ LoadDexFile(&soa);
+
+ MutexLock mu(Thread::Current(), *Locks::verifier_deps_lock_);
+
+ uint32_t id_Main1 = verifier_deps_->GetIdFromString(*dex_file_, "LMain;");
+ ASSERT_LT(id_Main1, dex_file_->NumStringIds());
+ ASSERT_EQ("LMain;", verifier_deps_->GetStringFromId(*dex_file_, id_Main1));
+
+ uint32_t id_Main2 = verifier_deps_->GetIdFromString(*dex_file_, "LMain;");
+ ASSERT_LT(id_Main2, dex_file_->NumStringIds());
+ ASSERT_EQ("LMain;", verifier_deps_->GetStringFromId(*dex_file_, id_Main2));
+
+ uint32_t id_Lorem1 = verifier_deps_->GetIdFromString(*dex_file_, "Lorem ipsum");
+ ASSERT_GE(id_Lorem1, dex_file_->NumStringIds());
+ ASSERT_EQ("Lorem ipsum", verifier_deps_->GetStringFromId(*dex_file_, id_Lorem1));
+
+ uint32_t id_Lorem2 = verifier_deps_->GetIdFromString(*dex_file_, "Lorem ipsum");
+ ASSERT_GE(id_Lorem2, dex_file_->NumStringIds());
+ ASSERT_EQ("Lorem ipsum", verifier_deps_->GetStringFromId(*dex_file_, id_Lorem2));
+
+ ASSERT_EQ(id_Main1, id_Main2);
+ ASSERT_EQ(id_Lorem1, id_Lorem2);
+ ASSERT_NE(id_Main1, id_Lorem1);
+}
+
+TEST_F(VerifierDepsTest, Assignable_BothInBoot) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/TimeZone;",
+ /* src */ "Ljava/util/SimpleTimeZone;",
+ /* is_strict */ true,
+ /* is_assignable */ true));
+ ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true));
+}
+
+TEST_F(VerifierDepsTest, Assignable_DestinationInBoot1) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/net/Socket;",
+ /* src */ "LMySSLSocket;",
+ /* is_strict */ true,
+ /* is_assignable */ true));
+ ASSERT_TRUE(HasAssignable("Ljava/net/Socket;", "LMySSLSocket;", true));
+}
+
+TEST_F(VerifierDepsTest, Assignable_DestinationInBoot2) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/TimeZone;",
+ /* src */ "LMySimpleTimeZone;",
+ /* is_strict */ true,
+ /* is_assignable */ true));
+ ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "LMySimpleTimeZone;", true));
+}
+
+TEST_F(VerifierDepsTest, Assignable_DestinationInBoot3) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/Collection;",
+ /* src */ "LMyThreadSet;",
+ /* is_strict */ true,
+ /* is_assignable */ true));
+ ASSERT_TRUE(HasAssignable("Ljava/util/Collection;", "LMyThreadSet;", true));
+}
+
+TEST_F(VerifierDepsTest, Assignable_BothArrays_Resolved) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[[Ljava/util/TimeZone;",
+ /* src */ "[[Ljava/util/SimpleTimeZone;",
+ /* is_strict */ true,
+ /* is_assignable */ true));
+ // If the component types of both arrays are resolved, we optimize the list of
+ // dependencies by recording a dependency on the component types.
+ ASSERT_FALSE(HasAssignable("[[Ljava/util/TimeZone;", "[[Ljava/util/SimpleTimeZone;", true));
+ ASSERT_FALSE(HasAssignable("[Ljava/util/TimeZone;", "[Ljava/util/SimpleTimeZone;", true));
+ ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true));
+}
+
+TEST_F(VerifierDepsTest, Assignable_BothArrays_Erroneous) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[[Ljava/util/TimeZone;",
+ /* src */ "[[LMyErroneousTimeZone;",
+ /* is_strict */ true,
+ /* is_assignable */ true));
+ // If the component type of an array is erroneous, we record the dependency on
+ // the array type.
+ ASSERT_FALSE(HasAssignable("[[Ljava/util/TimeZone;", "[[LMyErroneousTimeZone;", true));
+ ASSERT_TRUE(HasAssignable("[Ljava/util/TimeZone;", "[LMyErroneousTimeZone;", true));
+ ASSERT_FALSE(HasAssignable("Ljava/util/TimeZone;", "LMyErroneousTimeZone;", true));
+}
+
+ // We test that VerifierDeps does not try to optimize by storing assignability
+ // of the component types. This is due to the fact that the component type may
+ // be an erroneous class, even though the array type has resolved status.
+
+TEST_F(VerifierDepsTest, Assignable_ArrayToInterface1) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/io/Serializable;",
+ /* src */ "[Ljava/util/TimeZone;",
+ /* is_strict */ true,
+ /* is_assignable */ true));
+ ASSERT_TRUE(HasAssignable("Ljava/io/Serializable;", "[Ljava/util/TimeZone;", true));
+}
+
+TEST_F(VerifierDepsTest, Assignable_ArrayToInterface2) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/io/Serializable;",
+ /* src */ "[LMyThreadSet;",
+ /* is_strict */ true,
+ /* is_assignable */ true));
+ ASSERT_TRUE(HasAssignable("Ljava/io/Serializable;", "[LMyThreadSet;", true));
+}
+
+TEST_F(VerifierDepsTest, NotAssignable_BothInBoot) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;",
+ /* src */ "Ljava/util/SimpleTimeZone;",
+ /* is_strict */ true,
+ /* is_assignable */ false));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/util/SimpleTimeZone;", false));
+}
+
+TEST_F(VerifierDepsTest, NotAssignable_DestinationInBoot1) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;",
+ /* src */ "LMySSLSocket;",
+ /* is_strict */ true,
+ /* is_assignable */ false));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LMySSLSocket;", false));
+}
+
+TEST_F(VerifierDepsTest, NotAssignable_DestinationInBoot2) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;",
+ /* src */ "LMySimpleTimeZone;",
+ /* is_strict */ true,
+ /* is_assignable */ false));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LMySimpleTimeZone;", false));
+}
+
+TEST_F(VerifierDepsTest, NotAssignable_BothArrays) {
+ ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[Ljava/lang/Exception;",
+ /* src */ "[Ljava/util/SimpleTimeZone;",
+ /* is_strict */ true,
+ /* is_assignable */ false));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/util/SimpleTimeZone;", false));
+}
+
+TEST_F(VerifierDepsTest, ArgumentType_ResolvedClass) {
+ ASSERT_TRUE(VerifyMethod("ArgumentType_ResolvedClass"));
+ ASSERT_TRUE(HasClass("Ljava/lang/Thread;", true, "public"));
+}
+
+TEST_F(VerifierDepsTest, ArgumentType_ResolvedReferenceArray) {
+ ASSERT_TRUE(VerifyMethod("ArgumentType_ResolvedReferenceArray"));
+ ASSERT_TRUE(HasClass("[Ljava/lang/Thread;", true, "public final abstract"));
+}
+
+TEST_F(VerifierDepsTest, ArgumentType_ResolvedPrimitiveArray) {
+ ASSERT_TRUE(VerifyMethod("ArgumentType_ResolvedPrimitiveArray"));
+ ASSERT_TRUE(HasClass("[B", true, "public final abstract"));
+}
+
+TEST_F(VerifierDepsTest, ArgumentType_UnresolvedClass) {
+ ASSERT_TRUE(VerifyMethod("ArgumentType_UnresolvedClass"));
+ ASSERT_TRUE(HasClass("LUnresolvedClass;", false));
+}
+
+TEST_F(VerifierDepsTest, ArgumentType_UnresolvedSuper) {
+ ASSERT_TRUE(VerifyMethod("ArgumentType_UnresolvedSuper"));
+ ASSERT_TRUE(HasClass("LMySetWithUnresolvedSuper;", false));
+}
+
+TEST_F(VerifierDepsTest, ReturnType_Reference) {
+ ASSERT_TRUE(VerifyMethod("ReturnType_Reference"));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/lang/IllegalStateException;", true));
+}
+
+TEST_F(VerifierDepsTest, ReturnType_Array) {
+ ASSERT_FALSE(VerifyMethod("ReturnType_Array"));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Integer;", "Ljava/lang/IllegalStateException;", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeArgumentType) {
+ ASSERT_TRUE(VerifyMethod("InvokeArgumentType"));
+ ASSERT_TRUE(HasClass("Ljava/text/SimpleDateFormat;", true, "public"));
+ ASSERT_TRUE(HasClass("Ljava/util/SimpleTimeZone;", true, "public"));
+ ASSERT_TRUE(HasMethod("virtual",
+ "Ljava/text/SimpleDateFormat;",
+ "setTimeZone",
+ "(Ljava/util/TimeZone;)V",
+ true,
+ "public",
+ "Ljava/text/DateFormat;"));
+ ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true));
+}
+
+TEST_F(VerifierDepsTest, MergeTypes_RegisterLines) {
+ ASSERT_TRUE(VerifyMethod("MergeTypes_RegisterLines"));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LMySocketTimeoutException;", true));
+ ASSERT_TRUE(HasAssignable(
+ "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true));
+}
+
+TEST_F(VerifierDepsTest, MergeTypes_IfInstanceOf) {
+ ASSERT_TRUE(VerifyMethod("MergeTypes_IfInstanceOf"));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/net/SocketTimeoutException;", true));
+ ASSERT_TRUE(HasAssignable(
+ "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true));
+ ASSERT_TRUE(HasAssignable("Ljava/net/SocketTimeoutException;", "Ljava/lang/Exception;", false));
+}
+
+TEST_F(VerifierDepsTest, MergeTypes_Unresolved) {
+ ASSERT_TRUE(VerifyMethod("MergeTypes_Unresolved"));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/net/SocketTimeoutException;", true));
+ ASSERT_TRUE(HasAssignable(
+ "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true));
+}
+
+TEST_F(VerifierDepsTest, ConstClass_Resolved) {
+ ASSERT_TRUE(VerifyMethod("ConstClass_Resolved"));
+ ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public"));
+}
+
+TEST_F(VerifierDepsTest, ConstClass_Unresolved) {
+ ASSERT_TRUE(VerifyMethod("ConstClass_Unresolved"));
+ ASSERT_TRUE(HasClass("LUnresolvedClass;", false));
+}
+
+TEST_F(VerifierDepsTest, CheckCast_Resolved) {
+ ASSERT_TRUE(VerifyMethod("CheckCast_Resolved"));
+ ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public"));
+}
+
+TEST_F(VerifierDepsTest, CheckCast_Unresolved) {
+ ASSERT_TRUE(VerifyMethod("CheckCast_Unresolved"));
+ ASSERT_TRUE(HasClass("LUnresolvedClass;", false));
+}
+
+TEST_F(VerifierDepsTest, InstanceOf_Resolved) {
+ ASSERT_TRUE(VerifyMethod("InstanceOf_Resolved"));
+ ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public"));
+}
+
+TEST_F(VerifierDepsTest, InstanceOf_Unresolved) {
+ ASSERT_TRUE(VerifyMethod("InstanceOf_Unresolved"));
+ ASSERT_TRUE(HasClass("LUnresolvedClass;", false));
+}
+
+TEST_F(VerifierDepsTest, NewInstance_Resolved) {
+ ASSERT_TRUE(VerifyMethod("NewInstance_Resolved"));
+ ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public"));
+}
+
+TEST_F(VerifierDepsTest, NewInstance_Unresolved) {
+ ASSERT_TRUE(VerifyMethod("NewInstance_Unresolved"));
+ ASSERT_TRUE(HasClass("LUnresolvedClass;", false));
+}
+
+TEST_F(VerifierDepsTest, NewArray_Resolved) {
+ ASSERT_TRUE(VerifyMethod("NewArray_Resolved"));
+ ASSERT_TRUE(HasClass("[Ljava/lang/IllegalStateException;", true, "public final abstract"));
+}
+
+TEST_F(VerifierDepsTest, NewArray_Unresolved) {
+ ASSERT_TRUE(VerifyMethod("NewArray_Unresolved"));
+ ASSERT_TRUE(HasClass("[LUnresolvedClass;", false));
+}
+
+TEST_F(VerifierDepsTest, Throw) {
+ ASSERT_TRUE(VerifyMethod("Throw"));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/lang/IllegalStateException;", true));
+}
+
+TEST_F(VerifierDepsTest, MoveException_Resolved) {
+ ASSERT_TRUE(VerifyMethod("MoveException_Resolved"));
+ ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public"));
+ ASSERT_TRUE(HasClass("Ljava/net/SocketTimeoutException;", true, "public"));
+ ASSERT_TRUE(HasClass("Ljava/util/zip/ZipException;", true, "public"));
+
+ // Testing that all exception types are assignable to Throwable.
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/io/InterruptedIOException;", true));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/net/SocketTimeoutException;", true));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/util/zip/ZipException;", true));
+
+ // Testing that the merge type is assignable to Throwable.
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/io/IOException;", true));
+
+ // Merging of exception types.
+ ASSERT_TRUE(HasAssignable("Ljava/io/IOException;", "Ljava/io/InterruptedIOException;", true));
+ ASSERT_TRUE(HasAssignable("Ljava/io/IOException;", "Ljava/util/zip/ZipException;", true));
+ ASSERT_TRUE(HasAssignable(
+ "Ljava/io/InterruptedIOException;", "Ljava/net/SocketTimeoutException;", true));
+}
+
+TEST_F(VerifierDepsTest, MoveException_Unresolved) {
+ ASSERT_FALSE(VerifyMethod("MoveException_Unresolved"));
+ ASSERT_TRUE(HasClass("LUnresolvedException;", false));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInReferenced) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInReferenced"));
+ ASSERT_TRUE(HasClass("Ljava/lang/System;", true, "public final"));
+ ASSERT_TRUE(HasField("Ljava/lang/System;",
+ "out",
+ "Ljava/io/PrintStream;",
+ true,
+ "public final static",
+ "Ljava/lang/System;"));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInSuperclass1) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInSuperclass1"));
+ ASSERT_TRUE(HasClass("Ljava/util/SimpleTimeZone;", true, "public"));
+ ASSERT_TRUE(HasField(
+ "Ljava/util/SimpleTimeZone;", "LONG", "I", true, "public final static", "Ljava/util/TimeZone;"));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInSuperclass2) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInSuperclass2"));
+ ASSERT_TRUE(HasField(
+ "LMySimpleTimeZone;", "SHORT", "I", true, "public final static", "Ljava/util/TimeZone;"));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface1) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface1"));
+ ASSERT_TRUE(HasClass("Ljavax/xml/transform/dom/DOMResult;", true, "public"));
+ ASSERT_TRUE(HasField("Ljavax/xml/transform/dom/DOMResult;",
+ "PI_ENABLE_OUTPUT_ESCAPING",
+ "Ljava/lang/String;",
+ true,
+ "public final static",
+ "Ljavax/xml/transform/Result;"));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface2) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface2"));
+ ASSERT_TRUE(HasField("LMyDOMResult;",
+ "PI_ENABLE_OUTPUT_ESCAPING",
+ "Ljava/lang/String;",
+ true,
+ "public final static",
+ "Ljavax/xml/transform/Result;"));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface3) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface3"));
+ ASSERT_TRUE(HasField("LMyResult;",
+ "PI_ENABLE_OUTPUT_ESCAPING",
+ "Ljava/lang/String;",
+ true,
+ "public final static",
+ "Ljavax/xml/transform/Result;"));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface4) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface4"));
+ ASSERT_TRUE(HasField("LMyDocument;",
+ "ELEMENT_NODE",
+ "S",
+ true,
+ "public final static",
+ "Lorg/w3c/dom/Node;"));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Unresolved_ReferrerInBoot) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Unresolved_ReferrerInBoot"));
+ ASSERT_TRUE(HasClass("Ljava/util/TimeZone;", true, "public abstract"));
+ ASSERT_TRUE(HasField("Ljava/util/TimeZone;", "x", "I", false));
+}
+
+TEST_F(VerifierDepsTest, StaticField_Unresolved_ReferrerInDex) {
+ ASSERT_TRUE(VerifyMethod("StaticField_Unresolved_ReferrerInDex"));
+ ASSERT_TRUE(HasField("LMyThreadSet;", "x", "I", false));
+}
+
+TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInReferenced) {
+ ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInReferenced"));
+ ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public"));
+ ASSERT_TRUE(HasField("Ljava/io/InterruptedIOException;",
+ "bytesTransferred",
+ "I",
+ true,
+ "public",
+ "Ljava/io/InterruptedIOException;"));
+ ASSERT_TRUE(HasAssignable(
+ "Ljava/io/InterruptedIOException;", "LMySocketTimeoutException;", true));
+}
+
+TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInSuperclass1) {
+ ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInSuperclass1"));
+ ASSERT_TRUE(HasClass("Ljava/net/SocketTimeoutException;", true, "public"));
+ ASSERT_TRUE(HasField("Ljava/net/SocketTimeoutException;",
+ "bytesTransferred",
+ "I",
+ true,
+ "public",
+ "Ljava/io/InterruptedIOException;"));
+ ASSERT_TRUE(HasAssignable(
+ "Ljava/io/InterruptedIOException;", "LMySocketTimeoutException;", true));
+}
+
+TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInSuperclass2) {
+ ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInSuperclass2"));
+ ASSERT_TRUE(HasField("LMySocketTimeoutException;",
+ "bytesTransferred",
+ "I",
+ true,
+ "public",
+ "Ljava/io/InterruptedIOException;"));
+ ASSERT_TRUE(HasAssignable(
+ "Ljava/io/InterruptedIOException;", "LMySocketTimeoutException;", true));
+}
+
+TEST_F(VerifierDepsTest, InstanceField_Unresolved_ReferrerInBoot) {
+ ASSERT_TRUE(VerifyMethod("InstanceField_Unresolved_ReferrerInBoot"));
+ ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public"));
+ ASSERT_TRUE(HasField("Ljava/io/InterruptedIOException;", "x", "I", false));
+}
+
+TEST_F(VerifierDepsTest, InstanceField_Unresolved_ReferrerInDex) {
+ ASSERT_TRUE(VerifyMethod("InstanceField_Unresolved_ReferrerInDex"));
+ ASSERT_TRUE(HasField("LMyThreadSet;", "x", "I", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInReferenced) {
+ ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInReferenced"));
+ ASSERT_TRUE(HasClass("Ljava/net/Socket;", true, "public"));
+ ASSERT_TRUE(HasMethod("direct",
+ "Ljava/net/Socket;",
+ "setSocketImplFactory",
+ "(Ljava/net/SocketImplFactory;)V",
+ true,
+ "public static",
+ "Ljava/net/Socket;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInSuperclass1) {
+ ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInSuperclass1"));
+ ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public abstract"));
+ ASSERT_TRUE(HasMethod("direct",
+ "Ljavax/net/ssl/SSLSocket;",
+ "setSocketImplFactory",
+ "(Ljava/net/SocketImplFactory;)V",
+ true,
+ "public static",
+ "Ljava/net/Socket;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInSuperclass2) {
+ ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInSuperclass2"));
+ ASSERT_TRUE(HasMethod("direct",
+ "LMySSLSocket;",
+ "setSocketImplFactory",
+ "(Ljava/net/SocketImplFactory;)V",
+ true,
+ "public static",
+ "Ljava/net/Socket;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeStatic_DeclaredInInterface1) {
+ ASSERT_TRUE(VerifyMethod("InvokeStatic_DeclaredInInterface1"));
+ ASSERT_TRUE(HasClass("Ljava/util/Map$Entry;", true, "public abstract interface"));
+ ASSERT_TRUE(HasMethod("direct",
+ "Ljava/util/Map$Entry;",
+ "comparingByKey",
+ "()Ljava/util/Comparator;",
+ true,
+ "public static",
+ "Ljava/util/Map$Entry;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeStatic_DeclaredInInterface2) {
+ ASSERT_FALSE(VerifyMethod("InvokeStatic_DeclaredInInterface2"));
+ ASSERT_TRUE(HasClass("Ljava/util/AbstractMap$SimpleEntry;", true, "public"));
+ ASSERT_TRUE(HasMethod("direct",
+ "Ljava/util/AbstractMap$SimpleEntry;",
+ "comparingByKey",
+ "()Ljava/util/Comparator;",
+ false));
+}
+
+TEST_F(VerifierDepsTest, InvokeStatic_Unresolved1) {
+ ASSERT_FALSE(VerifyMethod("InvokeStatic_Unresolved1"));
+ ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public abstract"));
+ ASSERT_TRUE(HasMethod("direct", "Ljavax/net/ssl/SSLSocket;", "x", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeStatic_Unresolved2) {
+ ASSERT_FALSE(VerifyMethod("InvokeStatic_Unresolved2"));
+ ASSERT_TRUE(HasMethod("direct", "LMySSLSocket;", "x", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInReferenced) {
+ ASSERT_TRUE(VerifyMethod("InvokeDirect_Resolved_DeclaredInReferenced"));
+ ASSERT_TRUE(HasClass("Ljava/net/Socket;", true, "public"));
+ ASSERT_TRUE(HasMethod(
+ "direct", "Ljava/net/Socket;", "<init>", "()V", true, "public", "Ljava/net/Socket;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInSuperclass1) {
+ ASSERT_FALSE(VerifyMethod("InvokeDirect_Resolved_DeclaredInSuperclass1"));
+ ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public abstract"));
+ ASSERT_TRUE(HasMethod("direct",
+ "Ljavax/net/ssl/SSLSocket;",
+ "checkOldImpl",
+ "()V",
+ true,
+ "private",
+ "Ljava/net/Socket;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInSuperclass2) {
+ ASSERT_FALSE(VerifyMethod("InvokeDirect_Resolved_DeclaredInSuperclass2"));
+ ASSERT_TRUE(HasMethod(
+ "direct", "LMySSLSocket;", "checkOldImpl", "()V", true, "private", "Ljava/net/Socket;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeDirect_Unresolved1) {
+ ASSERT_FALSE(VerifyMethod("InvokeDirect_Unresolved1"));
+ ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public abstract"));
+ ASSERT_TRUE(HasMethod("direct", "Ljavax/net/ssl/SSLSocket;", "x", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeDirect_Unresolved2) {
+ ASSERT_FALSE(VerifyMethod("InvokeDirect_Unresolved2"));
+ ASSERT_TRUE(HasMethod("direct", "LMySSLSocket;", "x", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInReferenced) {
+ ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInReferenced"));
+ ASSERT_TRUE(HasClass("Ljava/lang/Throwable;", true, "public"));
+ ASSERT_TRUE(HasMethod("virtual",
+ "Ljava/lang/Throwable;",
+ "getMessage",
+ "()Ljava/lang/String;",
+ true,
+ "public",
+ "Ljava/lang/Throwable;"));
+ // Type dependency on `this` argument.
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "LMySocketTimeoutException;", true));
+}
+
+TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperclass1) {
+ ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperclass1"));
+ ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public"));
+ ASSERT_TRUE(HasMethod("virtual",
+ "Ljava/io/InterruptedIOException;",
+ "getMessage",
+ "()Ljava/lang/String;",
+ true,
+ "public",
+ "Ljava/lang/Throwable;"));
+ // Type dependency on `this` argument.
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "LMySocketTimeoutException;", true));
+}
+
+TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperclass2) {
+ ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperclass2"));
+ ASSERT_TRUE(HasMethod("virtual",
+ "LMySocketTimeoutException;",
+ "getMessage",
+ "()Ljava/lang/String;",
+ true,
+ "public",
+ "Ljava/lang/Throwable;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperinterface) {
+ ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperinterface"));
+ ASSERT_TRUE(HasMethod("virtual",
+ "LMyThreadSet;",
+ "size",
+ "()I",
+ true,
+ "public abstract",
+ "Ljava/util/Set;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeVirtual_Unresolved1) {
+ ASSERT_FALSE(VerifyMethod("InvokeVirtual_Unresolved1"));
+ ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public"));
+ ASSERT_TRUE(HasMethod("virtual", "Ljava/io/InterruptedIOException;", "x", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeVirtual_Unresolved2) {
+ ASSERT_FALSE(VerifyMethod("InvokeVirtual_Unresolved2"));
+ ASSERT_TRUE(HasMethod("virtual", "LMySocketTimeoutException;", "x", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeVirtual_ActuallyDirect) {
+ ASSERT_FALSE(VerifyMethod("InvokeVirtual_ActuallyDirect"));
+ ASSERT_TRUE(HasMethod("virtual", "LMyThread;", "activeCount", "()I", false));
+ ASSERT_TRUE(HasMethod("direct",
+ "LMyThread;",
+ "activeCount",
+ "()I",
+ true,
+ "public static",
+ "Ljava/lang/Thread;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInReferenced) {
+ ASSERT_TRUE(VerifyMethod("InvokeInterface_Resolved_DeclaredInReferenced"));
+ ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public abstract interface"));
+ ASSERT_TRUE(HasMethod("interface",
+ "Ljava/lang/Runnable;",
+ "run",
+ "()V",
+ true,
+ "public abstract",
+ "Ljava/lang/Runnable;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperclass) {
+ ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperclass"));
+ ASSERT_TRUE(HasMethod("interface", "LMyThread;", "join", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperinterface1) {
+ ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperinterface1"));
+ ASSERT_TRUE(HasMethod("interface",
+ "LMyThreadSet;",
+ "run",
+ "()V",
+ true,
+ "public abstract",
+ "Ljava/lang/Runnable;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperinterface2) {
+ ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperinterface2"));
+ ASSERT_TRUE(HasMethod("interface",
+ "LMyThreadSet;",
+ "isEmpty",
+ "()Z",
+ true,
+ "public abstract",
+ "Ljava/util/Set;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeInterface_Unresolved1) {
+ ASSERT_FALSE(VerifyMethod("InvokeInterface_Unresolved1"));
+ ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public abstract interface"));
+ ASSERT_TRUE(HasMethod("interface", "Ljava/lang/Runnable;", "x", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeInterface_Unresolved2) {
+ ASSERT_FALSE(VerifyMethod("InvokeInterface_Unresolved2"));
+ ASSERT_TRUE(HasMethod("interface", "LMyThreadSet;", "x", "()V", false));
+}
+
+TEST_F(VerifierDepsTest, InvokeSuper_ThisAssignable) {
+ ASSERT_TRUE(VerifyMethod("InvokeSuper_ThisAssignable"));
+ ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public abstract interface"));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Runnable;", "LMain;", true));
+ ASSERT_TRUE(HasMethod("interface",
+ "Ljava/lang/Runnable;",
+ "run",
+ "()V",
+ true,
+ "public abstract",
+ "Ljava/lang/Runnable;"));
+}
+
+TEST_F(VerifierDepsTest, InvokeSuper_ThisNotAssignable) {
+ ASSERT_FALSE(VerifyMethod("InvokeSuper_ThisNotAssignable"));
+ ASSERT_TRUE(HasClass("Ljava/lang/Integer;", true, "public final"));
+ ASSERT_TRUE(HasAssignable("Ljava/lang/Integer;", "LMain;", false));
+ ASSERT_TRUE(HasMethod(
+ "virtual", "Ljava/lang/Integer;", "intValue", "()I", true, "public", "Ljava/lang/Integer;"));
+}
+
+TEST_F(VerifierDepsTest, EncodeDecode) {
+ VerifyDexFile();
+
+ ASSERT_EQ(1u, NumberOfCompiledDexFiles());
+ ASSERT_TRUE(HasEachKindOfRecord());
+
+ std::vector<uint8_t> buffer;
+ verifier_deps_->Encode(&buffer);
+ ASSERT_FALSE(buffer.empty());
+
+ VerifierDeps decoded_deps({ dex_file_ }, ArrayRef<uint8_t>(buffer));
+ ASSERT_TRUE(verifier_deps_->Equals(decoded_deps));
+}
+
+} // namespace verifier
+} // namespace art
diff --git a/test/Android.bp b/test/Android.bp
new file mode 100644
index 0000000..54c85eb
--- /dev/null
+++ b/test/Android.bp
@@ -0,0 +1,188 @@
+//
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+art_cc_defaults {
+ name: "art_test_defaults",
+ host_supported: true,
+ test_per_src: true,
+ // These really are gtests, but the gtest library comes from libart-gtest.so
+ gtest: false,
+ defaults: [
+ "art_defaults",
+ "art_debug_defaults",
+ ],
+
+ shared_libs: [
+ "libartd",
+ "libartd-disassembler",
+ "libvixld-arm",
+ "libvixld-arm64",
+ "libart-gtest",
+
+ "libicuuc",
+ "libicui18n",
+ "libnativehelper",
+ ],
+ whole_static_libs: [
+ "libsigchain",
+ ],
+ include_dirs: [
+ "art",
+ "art/cmdline",
+ ],
+
+ target: {
+ linux: {
+ ldflags: [
+ // Allow jni_compiler_test to find Java_MyClassNatives_bar
+ // within itself using dlopen(NULL, ...).
+ // Mac OS linker doesn't understand --export-dynamic.
+ "-Wl,--export-dynamic",
+ "-Wl,-u,Java_MyClassNatives_bar",
+ "-Wl,-u,Java_MyClassNatives_sbar",
+ ],
+ shared_libs: [
+ "libziparchive",
+ "libz-host",
+ ],
+ host_ldlibs: [
+ "-ldl",
+ "-lpthread",
+ ],
+ cflags: [
+ // gtest issue
+ "-Wno-used-but-marked-unused",
+ "-Wno-deprecated",
+ "-Wno-missing-noreturn",
+ ],
+ },
+ darwin: {
+ enabled: false,
+ },
+ android: {
+ ldflags: [
+ // Allow jni_compiler_test to find Java_MyClassNatives_bar
+ // within itself using dlopen(NULL, ...).
+ "-Wl,--export-dynamic",
+ "-Wl,-u,Java_MyClassNatives_bar",
+ "-Wl,-u,Java_MyClassNatives_sbar",
+ ],
+ shared_libs: [
+ "libcutils",
+ "libdl",
+ "libz",
+ ],
+ cflags: [
+ // gtest issue
+ "-Wno-used-but-marked-unused",
+ "-Wno-deprecated",
+ "-Wno-missing-noreturn",
+ ],
+ },
+
+ android_arm: {
+ relative_install_path: "art/arm",
+ },
+ android_arm64: {
+ relative_install_path: "art/arm64",
+ },
+ android_mips: {
+ relative_install_path: "art/mips",
+ },
+ android_mips64: {
+ relative_install_path: "art/mips64",
+ },
+ android_x86: {
+ relative_install_path: "art/x86",
+ },
+ android_x86_64: {
+ relative_install_path: "art/x86_64",
+ },
+ },
+}
+
+art_cc_defaults {
+ name: "libart-gtest-defaults",
+ host_supported: true,
+ defaults: [
+ "art_defaults",
+ "art_debug_defaults",
+ ],
+ shared_libs: [
+ "libartd",
+ "libartd-compiler",
+ ],
+ static_libs: [
+ "libgtest",
+ ],
+ target: {
+ android32: {
+ cflags: ["-DART_TARGET_NATIVETEST_DIR=/data/nativetest/art"],
+ },
+ android64: {
+ cflags: ["-DART_TARGET_NATIVETEST_DIR=/data/nativetest64/art"],
+ },
+ android: {
+ cflags: [
+ // gtest issue
+ "-Wno-used-but-marked-unused",
+ "-Wno-deprecated",
+ "-Wno-missing-noreturn",
+ ],
+ },
+ linux: {
+ cflags: [
+ // gtest issue
+ "-Wno-used-but-marked-unused",
+ "-Wno-deprecated",
+ "-Wno-missing-noreturn",
+ ],
+ },
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+art_cc_library {
+ name: "libart-gtest",
+ host_supported: true,
+ whole_static_libs: [
+ "libart-compiler-gtest",
+ "libart-runtime-gtest",
+ "libgtest",
+ ],
+ shared_libs: [
+ "libartd",
+ "libartd-compiler",
+ ],
+ target: {
+ android: {
+ shared_libs: [
+ "libdl",
+ ],
+ },
+ host: {
+ host_ldlibs: [
+ "-ldl",
+ "-lpthread",
+ ],
+ },
+ darwin: {
+ enabled: false,
+ },
+ },
+}
diff --git a/test/Android.run-test.mk b/test/Android.run-test.mk
index d6957fc..e12fd28 100644
--- a/test/Android.run-test.mk
+++ b/test/Android.run-test.mk
@@ -153,17 +153,17 @@
ifeq ($(ART_TEST_JNI_FORCECOPY),true)
JNI_TYPES += forcecopy
endif
-IMAGE_TYPES := image
+IMAGE_TYPES := picimage
ifeq ($(ART_TEST_RUN_TEST_NO_IMAGE),true)
IMAGE_TYPES += no-image
endif
ifeq ($(ART_TEST_RUN_TEST_MULTI_IMAGE),true)
- IMAGE_TYPES := multiimage
+ IMAGE_TYPES := multipicimage
endif
-ifeq ($(ART_TEST_PIC_IMAGE),true)
- IMAGE_TYPES += picimage
+ifeq ($(ART_TEST_NPIC_IMAGE),true)
+ IMAGE_TYPES += npicimage
ifeq ($(ART_TEST_RUN_TEST_MULTI_IMAGE),true)
- IMAGE_TYPES := multipicimage
+ IMAGE_TYPES := multinpicimage
endif
endif
PICTEST_TYPES := npictest
@@ -896,6 +896,11 @@
ifeq ($(4),regalloc_gc)
# Graph coloring tests share the image_suffix with optimizing tests.
image_suffix := optimizing
+ else
+ ifeq ($(4),jit)
+ # JIT tests share the image_suffix with interpreter tests.
+ image_suffix := interpreter
+ endif
endif
ifeq ($(9),no-image)
test_groups += ART_RUN_TEST_$$(uc_host_or_target)_NO_IMAGE_RULES
@@ -907,8 +912,9 @@
prereq_rule += $$(TARGET_CORE_IMAGE_$$(image_suffix)_no-pic_$(13))
endif
else
- ifeq ($(9),image)
+ ifeq ($(9),npicimage)
test_groups += ART_RUN_TEST_$$(uc_host_or_target)_IMAGE_RULES
+ run_test_options += --npic-image
# Add the core dependency.
ifeq ($(1),host)
prereq_rule += $$(HOST_CORE_IMAGE_$$(image_suffix)_no-pic_$(13))
@@ -918,16 +924,15 @@
else
ifeq ($(9),picimage)
test_groups += ART_RUN_TEST_$$(uc_host_or_target)_PICIMAGE_RULES
- run_test_options += --pic-image
ifeq ($(1),host)
prereq_rule += $$(HOST_CORE_IMAGE_$$(image_suffix)_pic_$(13))
else
prereq_rule += $$(TARGET_CORE_IMAGE_$$(image_suffix)_pic_$(13))
endif
else
- ifeq ($(9),multiimage)
+ ifeq ($(9),multinpicimage)
test_groups += ART_RUN_TEST_$$(uc_host_or_target)_IMAGE_RULES
- run_test_options += --multi-image
+ run_test_options += --npic-image --multi-image
ifeq ($(1),host)
prereq_rule += $$(HOST_CORE_IMAGE_$$(image_suffix)_no-pic_multi_$(13))
else
@@ -936,7 +941,7 @@
else
ifeq ($(9),multipicimage)
test_groups += ART_RUN_TEST_$$(uc_host_or_target)_PICIMAGE_RULES
- run_test_options += --pic-image --multi-image
+ run_test_options += --multi-image
ifeq ($(1),host)
prereq_rule += $$(HOST_CORE_IMAGE_$$(image_suffix)_pic_multi_$(13))
else
diff --git a/test/VerifierDeps/Main.smali b/test/VerifierDeps/Main.smali
new file mode 100644
index 0000000..74c0d03
--- /dev/null
+++ b/test/VerifierDeps/Main.smali
@@ -0,0 +1,464 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMain;
+.super LMyThreadSet;
+
+.method public static ArgumentType_ResolvedClass(Ljava/lang/Thread;)V
+ .registers 1
+ return-void
+.end method
+
+.method public static ArgumentType_ResolvedReferenceArray([Ljava/lang/Thread;)V
+ .registers 1
+ return-void
+.end method
+
+.method public static ArgumentType_ResolvedPrimitiveArray([B)V
+ .registers 1
+ return-void
+.end method
+
+.method public static ArgumentType_UnresolvedClass(LUnresolvedClass;)V
+ .registers 1
+ return-void
+.end method
+
+.method public static ArgumentType_UnresolvedSuper(LMySetWithUnresolvedSuper;)V
+ .registers 1
+ return-void
+.end method
+
+.method public static ReturnType_Reference(Ljava/lang/IllegalStateException;)Ljava/lang/Throwable;
+ .registers 1
+ return-object p0
+.end method
+
+.method public static ReturnType_Array([Ljava/lang/IllegalStateException;)[Ljava/lang/Integer;
+ .registers 1
+ return-object p0
+.end method
+
+.method public static InvokeArgumentType(Ljava/text/SimpleDateFormat;Ljava/util/SimpleTimeZone;)V
+ .registers 2
+ invoke-virtual {p0, p1}, Ljava/text/SimpleDateFormat;->setTimeZone(Ljava/util/TimeZone;)V
+ return-void
+.end method
+
+.method public static MergeTypes_RegisterLines(Z)Ljava/lang/Object;
+ .registers 2
+ if-eqz p0, :else
+
+ new-instance v0, LMySocketTimeoutException;
+ invoke-direct {v0}, LMySocketTimeoutException;-><init>()V
+ goto :merge
+
+ :else
+ new-instance v0, Ljava/util/concurrent/TimeoutException;
+ invoke-direct {v0}, Ljava/util/concurrent/TimeoutException;-><init>()V
+ goto :merge
+
+ :merge
+ return-object v0
+.end method
+
+.method public static MergeTypes_IfInstanceOf(Ljava/net/SocketTimeoutException;)V
+ .registers 2
+ instance-of v0, p0, Ljava/util/concurrent/TimeoutException;
+ if-eqz v0, :else
+ return-void
+ :else
+ return-void
+.end method
+
+.method public static MergeTypes_Unresolved(ZZLUnresolvedClassA;)Ljava/lang/Object;
+ .registers 5
+ if-eqz p0, :else1
+
+ move-object v0, p2
+ goto :merge
+
+ :else1
+ if-eqz p1, :else2
+
+ new-instance v0, Ljava/util/concurrent/TimeoutException;
+ invoke-direct {v0}, Ljava/util/concurrent/TimeoutException;-><init>()V
+ goto :merge
+
+ :else2
+ new-instance v0, Ljava/net/SocketTimeoutException;
+ invoke-direct {v0}, Ljava/net/SocketTimeoutException;-><init>()V
+ goto :merge
+
+ :merge
+ return-object v0
+.end method
+
+.method public static ConstClass_Resolved()V
+ .registers 1
+ const-class v0, Ljava/lang/IllegalStateException;
+ return-void
+.end method
+
+.method public static ConstClass_Unresolved()V
+ .registers 1
+ const-class v0, LUnresolvedClass;
+ return-void
+.end method
+
+.method public static CheckCast_Resolved(Ljava/lang/Object;)V
+ .registers 1
+ check-cast p0, Ljava/lang/IllegalStateException;
+ return-void
+.end method
+
+.method public static CheckCast_Unresolved(Ljava/lang/Object;)V
+ .registers 1
+ check-cast p0, LUnresolvedClass;
+ return-void
+.end method
+
+.method public static InstanceOf_Resolved(Ljava/lang/Object;)Z
+ .registers 1
+ instance-of p0, p0, Ljava/lang/IllegalStateException;
+ return p0
+.end method
+
+.method public static InstanceOf_Unresolved(Ljava/lang/Object;)Z
+ .registers 1
+ instance-of p0, p0, LUnresolvedClass;
+ return p0
+.end method
+
+.method public static NewInstance_Resolved()V
+ .registers 1
+ new-instance v0, Ljava/lang/IllegalStateException;
+ return-void
+.end method
+
+.method public static NewInstance_Unresolved()V
+ .registers 1
+ new-instance v0, LUnresolvedClass;
+ return-void
+.end method
+
+.method public static NewArray_Resolved()V
+ .registers 1
+ const/4 v0, 0x1
+ new-array v0, v0, [Ljava/lang/IllegalStateException;
+ return-void
+.end method
+
+.method public static NewArray_Unresolved()V
+ .registers 2
+ const/4 v0, 0x1
+ new-array v0, v0, [LUnresolvedClass;
+ return-void
+.end method
+
+.method public static Throw(Ljava/lang/IllegalStateException;)V
+ .registers 2
+ throw p0
+.end method
+
+.method public static MoveException_Resolved()Ljava/lang/Object;
+ .registers 1
+ :try_start
+ invoke-static {}, Ljava/lang/System;->nanoTime()J
+ :try_end
+ .catch Ljava/net/SocketTimeoutException; {:try_start .. :try_end} :catch_block
+ .catch Ljava/io/InterruptedIOException; {:try_start .. :try_end} :catch_block
+ .catch Ljava/util/zip/ZipException; {:try_start .. :try_end} :catch_block
+ const/4 v0, 0x0
+ return-object v0
+
+ :catch_block
+ move-exception v0
+ return-object v0
+.end method
+
+.method public static MoveException_Unresolved()Ljava/lang/Object;
+ .registers 1
+ :try_start
+ invoke-static {}, Ljava/lang/System;->nanoTime()J
+ :try_end
+ .catch LUnresolvedException; {:try_start .. :try_end} :catch_block
+ const/4 v0, 0x0
+ return-object v0
+
+ :catch_block
+ move-exception v0
+ return-object v0
+.end method
+
+.method public static StaticField_Resolved_DeclaredInReferenced()V
+ .registers 1
+ sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
+ return-void
+.end method
+
+.method public static StaticField_Resolved_DeclaredInSuperclass1()V
+ .registers 1
+ sget v0, Ljava/util/SimpleTimeZone;->LONG:I
+ return-void
+.end method
+
+.method public static StaticField_Resolved_DeclaredInSuperclass2()V
+ .registers 1
+ sget v0, LMySimpleTimeZone;->SHORT:I
+ return-void
+.end method
+
+.method public static StaticField_Resolved_DeclaredInInterface1()V
+ .registers 1
+ # Case 1: DOMResult implements Result
+ sget-object v0, Ljavax/xml/transform/dom/DOMResult;->PI_ENABLE_OUTPUT_ESCAPING:Ljava/lang/String;
+ return-void
+.end method
+
+.method public static StaticField_Resolved_DeclaredInInterface2()V
+ .registers 1
+ # Case 2: MyDOMResult extends DOMResult, DOMResult implements Result
+ sget-object v0, LMyDOMResult;->PI_ENABLE_OUTPUT_ESCAPING:Ljava/lang/String;
+ return-void
+.end method
+
+.method public static StaticField_Resolved_DeclaredInInterface3()V
+ .registers 1
+ # Case 3: MyResult implements Result
+ sget-object v0, LMyResult;->PI_ENABLE_OUTPUT_ESCAPING:Ljava/lang/String;
+ return-void
+.end method
+
+.method public static StaticField_Resolved_DeclaredInInterface4()V
+ .registers 1
+ # Case 4: MyDocument implements Document, Document extends Node
+ sget-short v0, LMyDocument;->ELEMENT_NODE:S
+ return-void
+.end method
+
+.method public static StaticField_Unresolved_ReferrerInBoot()V
+ .registers 1
+ sget v0, Ljava/util/TimeZone;->x:I
+ return-void
+.end method
+
+.method public static StaticField_Unresolved_ReferrerInDex()V
+ .registers 1
+ sget v0, LMyThreadSet;->x:I
+ return-void
+.end method
+
+.method public static InstanceField_Resolved_DeclaredInReferenced(LMySocketTimeoutException;)V
+ .registers 1
+ iget v0, p0, Ljava/io/InterruptedIOException;->bytesTransferred:I
+ return-void
+.end method
+
+.method public static InstanceField_Resolved_DeclaredInSuperclass1(LMySocketTimeoutException;)V
+ .registers 1
+ iget v0, p0, Ljava/net/SocketTimeoutException;->bytesTransferred:I
+ return-void
+.end method
+
+.method public static InstanceField_Resolved_DeclaredInSuperclass2(LMySocketTimeoutException;)V
+ .registers 1
+ iget v0, p0, LMySocketTimeoutException;->bytesTransferred:I
+ return-void
+.end method
+
+.method public static InstanceField_Unresolved_ReferrerInBoot(LMySocketTimeoutException;)V
+ .registers 1
+ iget v0, p0, Ljava/io/InterruptedIOException;->x:I
+ return-void
+.end method
+
+.method public static InstanceField_Unresolved_ReferrerInDex(LMyThreadSet;)V
+ .registers 1
+ iget v0, p0, LMyThreadSet;->x:I
+ return-void
+.end method
+
+.method public static InvokeStatic_Resolved_DeclaredInReferenced()V
+ .registers 1
+ const v0, 0x0
+ invoke-static {v0}, Ljava/net/Socket;->setSocketImplFactory(Ljava/net/SocketImplFactory;)V
+ return-void
+.end method
+
+.method public static InvokeStatic_Resolved_DeclaredInSuperclass1()V
+ .registers 1
+ const v0, 0x0
+ invoke-static {v0}, Ljavax/net/ssl/SSLSocket;->setSocketImplFactory(Ljava/net/SocketImplFactory;)V
+ return-void
+.end method
+
+.method public static InvokeStatic_Resolved_DeclaredInSuperclass2()V
+ .registers 1
+ const v0, 0x0
+ invoke-static {v0}, LMySSLSocket;->setSocketImplFactory(Ljava/net/SocketImplFactory;)V
+ return-void
+.end method
+
+.method public static InvokeStatic_DeclaredInInterface1()V
+ .registers 1
+ invoke-static {}, Ljava/util/Map$Entry;->comparingByKey()Ljava/util/Comparator;
+ return-void
+.end method
+
+.method public static InvokeStatic_DeclaredInInterface2()V
+ .registers 1
+ # AbstractMap$SimpleEntry implements Map$Entry
+ # INVOKE_STATIC does not resolve to methods in superinterfaces. This will
+ # therefore result in an unresolved method.
+ invoke-static {}, Ljava/util/AbstractMap$SimpleEntry;->comparingByKey()Ljava/util/Comparator;
+ return-void
+.end method
+
+.method public static InvokeStatic_Unresolved1()V
+ .registers 1
+ invoke-static {}, Ljavax/net/ssl/SSLSocket;->x()V
+ return-void
+.end method
+
+.method public static InvokeStatic_Unresolved2()V
+ .registers 1
+ invoke-static {}, LMySSLSocket;->x()V
+ return-void
+.end method
+
+.method public static InvokeDirect_Resolved_DeclaredInReferenced()V
+ .registers 1
+ new-instance v0, Ljava/net/Socket;
+ invoke-direct {v0}, Ljava/net/Socket;-><init>()V
+ return-void
+.end method
+
+.method public static InvokeDirect_Resolved_DeclaredInSuperclass1(LMySSLSocket;)V
+ .registers 1
+ invoke-direct {p0}, Ljavax/net/ssl/SSLSocket;->checkOldImpl()V
+ return-void
+.end method
+
+.method public static InvokeDirect_Resolved_DeclaredInSuperclass2(LMySSLSocket;)V
+ .registers 1
+ invoke-direct {p0}, LMySSLSocket;->checkOldImpl()V
+ return-void
+.end method
+
+.method public static InvokeDirect_Unresolved1(LMySSLSocket;)V
+ .registers 1
+ invoke-direct {p0}, Ljavax/net/ssl/SSLSocket;->x()V
+ return-void
+.end method
+
+.method public static InvokeDirect_Unresolved2(LMySSLSocket;)V
+ .registers 1
+ invoke-direct {p0}, LMySSLSocket;->x()V
+ return-void
+.end method
+
+.method public static InvokeVirtual_Resolved_DeclaredInReferenced(LMySocketTimeoutException;)V
+ .registers 1
+ invoke-virtual {p0}, Ljava/lang/Throwable;->getMessage()Ljava/lang/String;
+ return-void
+.end method
+
+.method public static InvokeVirtual_Resolved_DeclaredInSuperclass1(LMySocketTimeoutException;)V
+ .registers 1
+ invoke-virtual {p0}, Ljava/io/InterruptedIOException;->getMessage()Ljava/lang/String;
+ return-void
+.end method
+
+.method public static InvokeVirtual_Resolved_DeclaredInSuperclass2(LMySocketTimeoutException;)V
+ .registers 1
+ invoke-virtual {p0}, LMySocketTimeoutException;->getMessage()Ljava/lang/String;
+ return-void
+.end method
+
+.method public static InvokeVirtual_Resolved_DeclaredInSuperinterface(LMyThreadSet;)V
+ .registers 1
+ invoke-virtual {p0}, LMyThreadSet;->size()I
+ return-void
+.end method
+
+.method public static InvokeVirtual_Unresolved1(LMySocketTimeoutException;)V
+ .registers 1
+ invoke-virtual {p0}, Ljava/io/InterruptedIOException;->x()V
+ return-void
+.end method
+
+.method public static InvokeVirtual_Unresolved2(LMySocketTimeoutException;)V
+ .registers 1
+ invoke-virtual {p0}, LMySocketTimeoutException;->x()V
+ return-void
+.end method
+
+.method public static InvokeVirtual_ActuallyDirect(LMyThread;)V
+ .registers 1
+ invoke-virtual {p0}, LMyThread;->activeCount()I
+ return-void
+.end method
+
+.method public static InvokeInterface_Resolved_DeclaredInReferenced(LMyThread;)V
+ .registers 1
+ invoke-interface {p0}, Ljava/lang/Runnable;->run()V
+ return-void
+.end method
+
+.method public static InvokeInterface_Resolved_DeclaredInSuperclass(LMyThread;)V
+ .registers 1
+ # Method join() is declared in the superclass of MyThread. As such, it should
+ # be called with invoke-virtual and will not be resolved here.
+ invoke-interface {p0}, LMyThread;->join()V
+ return-void
+.end method
+
+.method public static InvokeInterface_Resolved_DeclaredInSuperinterface1(LMyThreadSet;)V
+ .registers 1
+ # Verification will fail because the referring class is not an interface.
+ invoke-interface {p0}, LMyThreadSet;->run()V
+ return-void
+.end method
+
+.method public static InvokeInterface_Resolved_DeclaredInSuperinterface2(LMyThreadSet;)V
+ .registers 1
+ # Verification will fail because the referring class is not an interface.
+ invoke-interface {p0}, LMyThreadSet;->isEmpty()Z
+ return-void
+.end method
+
+.method public static InvokeInterface_Unresolved1(LMyThread;)V
+ .registers 1
+ invoke-interface {p0}, Ljava/lang/Runnable;->x()V
+ return-void
+.end method
+
+.method public static InvokeInterface_Unresolved2(LMyThread;)V
+ .registers 1
+ invoke-interface {p0}, LMyThreadSet;->x()V
+ return-void
+.end method
+
+.method public static InvokeSuper_ThisAssignable(Ljava/lang/Thread;)V
+ .registers 1
+ invoke-super {p0}, Ljava/lang/Runnable;->run()V
+ return-void
+.end method
+
+.method public static InvokeSuper_ThisNotAssignable(Ljava/lang/Integer;)V
+ .registers 1
+ invoke-super {p0}, Ljava/lang/Integer;->intValue()I
+ return-void
+.end method
diff --git a/test/VerifierDeps/MyDOMResult.smali b/test/VerifierDeps/MyDOMResult.smali
new file mode 100644
index 0000000..12f6243
--- /dev/null
+++ b/test/VerifierDeps/MyDOMResult.smali
@@ -0,0 +1,16 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMyDOMResult;
+.super Ljavax/xml/transform/dom/DOMResult;
diff --git a/test/VerifierDeps/MyDocument.smali b/test/VerifierDeps/MyDocument.smali
new file mode 100644
index 0000000..3ce042c
--- /dev/null
+++ b/test/VerifierDeps/MyDocument.smali
@@ -0,0 +1,17 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMyDocument;
+.super Ljava/lang/Object;
+.implements Lorg/w3c/dom/Document;
diff --git a/test/VerifierDeps/MyErroneousTimeZone.smali b/test/VerifierDeps/MyErroneousTimeZone.smali
new file mode 100644
index 0000000..5f23dd9
--- /dev/null
+++ b/test/VerifierDeps/MyErroneousTimeZone.smali
@@ -0,0 +1,22 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMyErroneousTimeZone;
+.super LMySimpleTimeZone;
+
+# Class is erroneous because foo() is defined final in the superclass.
+.method public foo()V
+ .registers 1
+ return-void
+.end method
diff --git a/test/VerifierDeps/MyResult.smali b/test/VerifierDeps/MyResult.smali
new file mode 100644
index 0000000..e00e750
--- /dev/null
+++ b/test/VerifierDeps/MyResult.smali
@@ -0,0 +1,17 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMyResult;
+.super Ljava/lang/Object;
+.implements Ljavax/xml/transform/Result;
diff --git a/test/VerifierDeps/MySSLSocket.smali b/test/VerifierDeps/MySSLSocket.smali
new file mode 100644
index 0000000..dd30081
--- /dev/null
+++ b/test/VerifierDeps/MySSLSocket.smali
@@ -0,0 +1,16 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMySSLSocket;
+.super Ljavax/net/ssl/SSLSocket;
diff --git a/test/VerifierDeps/MySimpleTimeZone.smali b/test/VerifierDeps/MySimpleTimeZone.smali
new file mode 100644
index 0000000..f7a1e05
--- /dev/null
+++ b/test/VerifierDeps/MySimpleTimeZone.smali
@@ -0,0 +1,24 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMySimpleTimeZone;
+.super Ljava/util/SimpleTimeZone;
+.implements Ljava/io/Serializable;
+
+# Define foo() as a final method. It is used by the MyErroneousTimeZone subclass
+# to generate a linkage error.
+.method public final foo()V
+ .registers 1
+ return-void
+.end method
diff --git a/test/VerifierDeps/MySocketTimeoutException.smali b/test/VerifierDeps/MySocketTimeoutException.smali
new file mode 100644
index 0000000..50e0762
--- /dev/null
+++ b/test/VerifierDeps/MySocketTimeoutException.smali
@@ -0,0 +1,16 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMySocketTimeoutException;
+.super Ljava/net/SocketTimeoutException;
diff --git a/test/VerifierDeps/MyThread.smali b/test/VerifierDeps/MyThread.smali
new file mode 100644
index 0000000..7fdb254
--- /dev/null
+++ b/test/VerifierDeps/MyThread.smali
@@ -0,0 +1,16 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMyThread;
+.super Ljava/lang/Thread;
diff --git a/test/VerifierDeps/MyThreadSet.smali b/test/VerifierDeps/MyThreadSet.smali
new file mode 100644
index 0000000..f331fcf
--- /dev/null
+++ b/test/VerifierDeps/MyThreadSet.smali
@@ -0,0 +1,17 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public abstract LMyThreadSet;
+.super Ljava/lang/Thread;
+.implements Ljava/util/Set;
diff --git a/test/run-test b/test/run-test
index 4c29420..8fb2adf 100755
--- a/test/run-test
+++ b/test/run-test
@@ -132,7 +132,7 @@
android_root="/system"
# By default we will use optimizing.
image_args=""
-image_suffix="-optimizing"
+image_suffix=""
while true; do
if [ "x$1" = "x--host" ]; then
@@ -180,8 +180,8 @@
elif [ "x$1" = "x--no-image" ]; then
have_image="no"
shift
- elif [ "x$1" = "x--pic-image" ]; then
- pic_image_suffix="-pic"
+ elif [ "x$1" = "x--npic-image" ]; then
+ pic_image_suffix="-npic"
shift
elif [ "x$1" = "x--multi-image" ]; then
multi_image_suffix="-multi"
@@ -258,11 +258,10 @@
shift
elif [ "x$1" = "x--jit" ]; then
image_args="--jit"
- image_suffix="-jit"
+ image_suffix="-interpreter"
shift
elif [ "x$1" = "x--optimizing" ]; then
image_args="-Xcompiler-option --compiler-backend=Optimizing"
- image_suffix="-optimizing"
shift
elif [ "x$1" = "x--no-verify" ]; then
run_args="${run_args} --no-verify"
@@ -608,8 +607,8 @@
echo " --dex2oat-swap Use a dex2oat swap file."
echo " --instruction-set-features [string]"
echo " Set instruction-set-features for compilation."
- echo " --pic-image Use an image compiled with position independent code for the"
- echo " boot class path."
+ echo " --npic-image Use an image compiled with non-position independent code "
+ echo " for the boot class path."
echo " --multi-image Use a set of images compiled with dex2oat multi-image for"
echo " the boot class path."
echo " --pic-test Compile the test code position independent."
@@ -678,7 +677,7 @@
# Tests named '<number>-checker-*' will also have their CFGs verified with
# Checker when compiled with Optimizing on host.
if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
- if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$USE_JACK" = "true" ]; then
+ if [ "$runtime" = "art" -a "$image_suffix" = "" -a "$USE_JACK" = "true" ]; then
# Optimizing has read barrier support for certain architectures
# only. On other architectures, compiling is disabled when read
# barriers are enabled, meaning that we do not produce a CFG file
diff --git a/tools/art b/tools/art
index 1a3bba7..1394a46 100644
--- a/tools/art
+++ b/tools/art
@@ -100,7 +100,7 @@
$invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \
-XXlib:$LIBART \
-Xnorelocate \
- -Ximage:$ANDROID_ROOT/framework/core-optimizing-pic.art \
+ -Ximage:$ANDROID_ROOT/framework/core.art \
$DEBUG_OPTION \
"$@"
diff --git a/tools/bisection_search/README.md b/tools/bisection_search/README.md
index a7485c2..64ccb20 100644
--- a/tools/bisection_search/README.md
+++ b/tools/bisection_search/README.md
@@ -15,29 +15,54 @@
How to run Bisection Bug Search
===============================
+There are two supported invocation modes:
+
+1. Regular invocation, dalvikvm command is constructed internally:
+
+ ./bisection_search.py -cp classes.dex --expected-output out_int --class Test
+
+2. Raw-cmd invocation, dalvikvm command is accepted as an argument. The command
+ has to start with an executable.
+
+ Extra dalvikvm arguments will be placed on second position in the command
+ by default. {ARGS} tag can be used to specify a custom position.
+
+ ./bisection_search.py --raw-cmd='run.sh -cp classes.dex Test' --expected-retcode SUCCESS
+ ./bisection_search.py --raw-cmd='/bin/sh art {ARGS} -cp classes.dex Test' --expected-retcode SUCCESS
+
+Help:
+
bisection_search.py [-h] [-cp CLASSPATH] [--class CLASSNAME] [--lib LIB]
- [--dalvikvm-option [OPT [OPT ...]]] [--arg [ARG [ARG ...]]]
- [--image IMAGE] [--raw-cmd RAW_CMD]
- [--64] [--device] [--expected-output EXPECTED_OUTPUT]
- [--check-script CHECK_SCRIPT] [--verbose]
+ [--dalvikvm-option [OPT [OPT ...]]] [--arg [ARG [ARG ...]]]
+ [--image IMAGE] [--raw-cmd RAW_CMD]
+ [--64] [--device] [--device-serial DEVICE_SERIAL]
+ [--expected-output EXPECTED_OUTPUT]
+ [--expected-retcode {SUCCESS,TIMEOUT,ERROR}]
+ [--check-script CHECK_SCRIPT] [--logfile LOGFILE] [--cleanup]
+ [--timeout TIMEOUT] [--verbose]
Tool for finding compiler bugs. Either --raw-cmd or both -cp and --class are required.
optional arguments:
- -h, --help show this help message and exit
+ -h, --help show this help message and exit
dalvikvm command options:
- -cp CLASSPATH, --classpath CLASSPATH classpath
- --class CLASSNAME name of main class
- --lib LIB lib to use, default: libart.so
- --dalvikvm-option [OPT [OPT ...]] additional dalvikvm option
- --arg [ARG [ARG ...]] argument passed to test
- --image IMAGE path to image
- --raw-cmd RAW_CMD bisect with this command, ignore other command options
+ -cp CLASSPATH, --classpath CLASSPATH classpath
+ --class CLASSNAME name of main class
+ --lib LIB lib to use, default: libart.so
+ --dalvikvm-option [OPT [OPT ...]] additional dalvikvm option
+ --arg [ARG [ARG ...]] argument passed to test
+ --image IMAGE path to image
+ --raw-cmd RAW_CMD bisect with this command, ignore other command options
bisection options:
- --64 x64 mode
- --device run on device
- --expected-output EXPECTED_OUTPUT file containing expected output
- --check-script CHECK_SCRIPT script comparing output and expected output
- --verbose enable verbose output
+ --64 x64 mode
+ --device run on device
+ --device-serial DEVICE_SERIAL device serial number, implies --device
+ --expected-output EXPECTED_OUTPUT file containing expected output
+ --expected-retcode {SUCCESS,TIMEOUT,ERROR} expected normalized return code
+ --check-script CHECK_SCRIPT script comparing output and expected output
+ --logfile LOGFILE custom logfile location
+ --cleanup clean up after bisecting
+ --timeout TIMEOUT if timeout seconds pass assume test failed
+ --verbose enable verbose output
diff --git a/tools/bisection_search/bisection_search.py b/tools/bisection_search/bisection_search.py
index 110ef82..0d36aa4 100755
--- a/tools/bisection_search/bisection_search.py
+++ b/tools/bisection_search/bisection_search.py
@@ -34,6 +34,7 @@
from common import FatalError
from common import GetEnvVariableOrError
from common import HostTestEnv
+from common import RetCode
# Passes that are never disabled during search process because disabling them
@@ -51,6 +52,10 @@
NON_PASSES = ['builder', 'prepare_for_register_allocation',
'liveness', 'register']
+# If present in raw cmd, this tag will be replaced with runtime arguments
+# controlling the bisection search. Otherwise arguments will be placed on second
+# position in the command.
+RAW_CMD_RUNTIME_ARGS_TAG = '{ARGS}'
class Dex2OatWrapperTestable(object):
"""Class representing a testable compilation.
@@ -58,21 +63,29 @@
Accepts filters on compiled methods and optimization passes.
"""
- def __init__(self, base_cmd, test_env, output_checker=None, verbose=False):
+ def __init__(self, base_cmd, test_env, expected_retcode=None,
+ output_checker=None, verbose=False):
"""Constructor.
Args:
base_cmd: list of strings, base command to run.
test_env: ITestEnv.
+ expected_retcode: RetCode, expected normalized return code.
output_checker: IOutputCheck, output checker.
verbose: bool, enable verbose output.
"""
self._base_cmd = base_cmd
self._test_env = test_env
+ self._expected_retcode = expected_retcode
self._output_checker = output_checker
self._compiled_methods_path = self._test_env.CreateFile('compiled_methods')
self._passes_to_run_path = self._test_env.CreateFile('run_passes')
self._verbose = verbose
+ if RAW_CMD_RUNTIME_ARGS_TAG in self._base_cmd:
+ self._arguments_position = self._base_cmd.index(RAW_CMD_RUNTIME_ARGS_TAG)
+ self._base_cmd.pop(self._arguments_position)
+ else:
+ self._arguments_position = 1
def Test(self, compiled_methods, passes_to_run=None):
"""Tests compilation with compiled_methods and run_passes switches active.
@@ -95,8 +108,11 @@
verbose_compiler=False)
(output, ret_code) = self._test_env.RunCommand(
cmd, {'ANDROID_LOG_TAGS': '*:e'})
- res = ((self._output_checker is None and ret_code == 0)
- or self._output_checker.Check(output))
+ res = True
+ if self._expected_retcode:
+ res = self._expected_retcode == ret_code
+ if self._output_checker:
+ res = res and self._output_checker.Check(output)
if self._verbose:
print('Test passed: {0}.'.format(res))
return res
@@ -142,8 +158,8 @@
def _PrepareCmd(self, compiled_methods=None, passes_to_run=None,
verbose_compiler=False):
"""Prepare command to run."""
- cmd = [self._base_cmd[0]]
- # insert additional arguments
+ cmd = self._base_cmd[0:self._arguments_position]
+ # insert additional arguments before the first argument
if compiled_methods is not None:
self._test_env.WriteLines(self._compiled_methods_path, compiled_methods)
cmd += ['-Xcompiler-option', '--compiled-methods={0}'.format(
@@ -155,7 +171,7 @@
if verbose_compiler:
cmd += ['-Xcompiler-option', '--runtime-arg', '-Xcompiler-option',
'-verbose:compiler', '-Xcompiler-option', '-j1']
- cmd += self._base_cmd[1:]
+ cmd += self._base_cmd[self._arguments_position:]
return cmd
@@ -299,7 +315,7 @@
command_opts.add_argument('-cp', '--classpath', type=str, help='classpath')
command_opts.add_argument('--class', dest='classname', type=str,
help='name of main class')
- command_opts.add_argument('--lib', dest='lib', type=str, default='libart.so',
+ command_opts.add_argument('--lib', type=str, default='libart.so',
help='lib to use, default: libart.so')
command_opts.add_argument('--dalvikvm-option', dest='dalvikvm_opts',
metavar='OPT', nargs='*', default=[],
@@ -307,7 +323,7 @@
command_opts.add_argument('--arg', dest='test_args', nargs='*', default=[],
metavar='ARG', help='argument passed to test')
command_opts.add_argument('--image', type=str, help='path to image')
- command_opts.add_argument('--raw-cmd', dest='raw_cmd', type=str,
+ command_opts.add_argument('--raw-cmd', type=str,
help='bisect with this command, ignore other '
'command options')
bisection_opts = parser.add_argument_group('bisection options')
@@ -315,11 +331,22 @@
default=False, help='x64 mode')
bisection_opts.add_argument(
'--device', action='store_true', default=False, help='run on device')
+ bisection_opts.add_argument(
+ '--device-serial', help='device serial number, implies --device')
bisection_opts.add_argument('--expected-output', type=str,
help='file containing expected output')
bisection_opts.add_argument(
- '--check-script', dest='check_script', type=str,
+ '--expected-retcode', type=str, help='expected normalized return code',
+ choices=[RetCode.SUCCESS.name, RetCode.TIMEOUT.name, RetCode.ERROR.name])
+ bisection_opts.add_argument(
+ '--check-script', type=str,
help='script comparing output and expected output')
+ bisection_opts.add_argument(
+ '--logfile', type=str, help='custom logfile location')
+ bisection_opts.add_argument('--cleanup', action='store_true',
+ default=False, help='clean up after bisecting')
+ bisection_opts.add_argument('--timeout', type=int, default=60,
+ help='if timeout seconds pass assume test failed')
bisection_opts.add_argument('--verbose', action='store_true',
default=False, help='enable verbose output')
return parser
@@ -351,15 +378,24 @@
args = parser.parse_args()
if not args.raw_cmd and (not args.classpath or not args.classname):
parser.error('Either --raw-cmd or both -cp and --class are required')
+ if args.device_serial:
+ args.device = True
+ if args.expected_retcode:
+ args.expected_retcode = RetCode[args.expected_retcode]
+ if not args.expected_retcode and not args.check_script:
+ args.expected_retcode = RetCode.SUCCESS
# Prepare environment
classpath = args.classpath
if args.device:
- test_env = DeviceTestEnv()
+ test_env = DeviceTestEnv(
+ 'bisection_search_', args.cleanup, args.logfile, args.timeout,
+ args.device_serial)
if classpath:
classpath = test_env.PushClasspath(classpath)
else:
- test_env = HostTestEnv(args.x64)
+ test_env = HostTestEnv(
+ 'bisection_search_', args.cleanup, args.logfile, args.timeout, args.x64)
base_cmd = PrepareBaseCommand(args, classpath)
output_checker = None
if args.expected_output:
@@ -372,11 +408,11 @@
# Perform the search
try:
- testable = Dex2OatWrapperTestable(base_cmd, test_env, output_checker,
- args.verbose)
+ testable = Dex2OatWrapperTestable(base_cmd, test_env, args.expected_retcode,
+ output_checker, args.verbose)
(method, opt_pass) = BugSearch(testable)
except Exception as e:
- print('Error. Refer to logfile: {0}'.format(test_env.logfile.name))
+ print('Error occurred.\nLogfile: {0}'.format(test_env.logfile.name))
test_env.logfile.write('Exception: {0}\n'.format(e))
raise
diff --git a/tools/bisection_search/common.py b/tools/bisection_search/common.py
index d5029bb..b69b606 100755
--- a/tools/bisection_search/common.py
+++ b/tools/bisection_search/common.py
@@ -18,7 +18,9 @@
import abc
import os
+import signal
import shlex
+import shutil
from subprocess import check_call
from subprocess import PIPE
@@ -29,6 +31,9 @@
from tempfile import mkdtemp
from tempfile import NamedTemporaryFile
+from enum import Enum
+from enum import unique
+
# Temporary directory path on device.
DEVICE_TMP_PATH = '/data/local/tmp'
@@ -36,6 +41,16 @@
DALVIK_CACHE_ARCHS = ['arm', 'arm64', 'x86', 'x86_64']
+@unique
+class RetCode(Enum):
+ """Enum representing normalized return codes."""
+ SUCCESS = 0
+ TIMEOUT = 1
+ ERROR = 2
+ NOTCOMPILED = 3
+ NOTRUN = 4
+
+
def GetEnvVariableOrError(variable_name):
"""Gets value of an environmental variable.
@@ -70,6 +85,37 @@
for arch in DALVIK_CACHE_ARCHS)
+def RunCommandForOutput(cmd, env, stdout, stderr, timeout=60):
+ """Runs command piping output to files, stderr or stdout.
+
+ Args:
+ cmd: list of strings, command to run.
+ env: shell environment to run the command with.
+ stdout: file handle or one of Subprocess.PIPE, Subprocess.STDOUT,
+ Subprocess.DEVNULL, see Popen.
+ stderr: file handle or one of Subprocess.PIPE, Subprocess.STDOUT,
+ Subprocess.DEVNULL, see Popen.
+ timeout: int, timeout in seconds.
+
+ Returns:
+ tuple (string, string, RetCode) stdout output, stderr output, normalized
+ return code.
+ """
+ proc = Popen(cmd, stdout=stdout, stderr=stderr, env=env,
+ universal_newlines=True, start_new_session=True)
+ try:
+ (output, stderr_output) = proc.communicate(timeout=timeout)
+ if proc.returncode == 0:
+ retcode = RetCode.SUCCESS
+ else:
+ retcode = RetCode.ERROR
+ except TimeoutExpired:
+ os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
+ (output, stderr_output) = proc.communicate()
+ retcode = RetCode.TIMEOUT
+ return (output, stderr_output, retcode)
+
+
def _RunCommandForOutputAndLog(cmd, env, logfile, timeout=60):
"""Runs command and logs its output. Returns the output.
@@ -77,28 +123,19 @@
cmd: list of strings, command to run.
env: shell environment to run the command with.
logfile: file handle to logfile.
- timeout: int, timeout in seconds
+ timeout: int, timeout in seconds.
Returns:
- tuple (string, string, int) stdout output, stderr output, return code.
+ tuple (string, string, RetCode) stdout output, stderr output, normalized
+ return code.
"""
- proc = Popen(cmd, stderr=STDOUT, stdout=PIPE, env=env,
- universal_newlines=True)
- timeouted = False
- try:
- (output, _) = proc.communicate(timeout=timeout)
- except TimeoutExpired:
- timeouted = True
- proc.kill()
- (output, _) = proc.communicate()
+ (output, _, retcode) = RunCommandForOutput(cmd, env, PIPE, STDOUT, timeout)
logfile.write('Command:\n{0}\n{1}\nReturn code: {2}\n'.format(
- _CommandListToCommandString(cmd), output,
- 'TIMEOUT' if timeouted else proc.returncode))
- ret_code = 1 if timeouted else proc.returncode
- return (output, ret_code)
+ CommandListToCommandString(cmd), output, retcode))
+ return (output, retcode)
-def _CommandListToCommandString(cmd):
+def CommandListToCommandString(cmd):
"""Converts shell command represented as list of strings to a single string.
Each element of the list is wrapped in double quotes.
@@ -109,7 +146,7 @@
Returns:
string, shell command.
"""
- return ' '.join(['"{0}"'.format(segment) for segment in cmd])
+ return ' '.join([shlex.quote(segment) for segment in cmd])
class FatalError(Exception):
@@ -175,14 +212,24 @@
For methods documentation see base class.
"""
- def __init__(self, x64):
+ def __init__(self, directory_prefix, cleanup=True, logfile_path=None,
+ timeout=60, x64=False):
"""Constructor.
Args:
+ directory_prefix: string, prefix for environment directory name.
+ cleanup: boolean, if True remove test directory in destructor.
+ logfile_path: string, can be used to specify custom logfile location.
+ timeout: int, seconds, time to wait for single test run to finish.
x64: boolean, whether to setup in x64 mode.
"""
- self._env_path = mkdtemp(dir='/tmp/', prefix='bisection_search_')
- self._logfile = open('{0}/log'.format(self._env_path), 'w+')
+ self._cleanup = cleanup
+ self._timeout = timeout
+ self._env_path = mkdtemp(dir='/tmp/', prefix=directory_prefix)
+ if logfile_path is None:
+ self._logfile = open('{0}/log'.format(self._env_path), 'w+')
+ else:
+ self._logfile = open(logfile_path, 'w+')
os.mkdir('{0}/dalvik-cache'.format(self._env_path))
for arch_cache_path in _DexArchCachePaths(self._env_path):
os.mkdir(arch_cache_path)
@@ -199,6 +246,10 @@
# Using dlopen requires load bias on the host.
self._shell_env['LD_USE_LOAD_BIAS'] = '1'
+ def __del__(self):
+ if self._cleanup:
+ shutil.rmtree(self._env_path)
+
def CreateFile(self, name=None):
if name is None:
f = NamedTemporaryFile(dir=self._env_path, delete=False)
@@ -217,7 +268,7 @@
self._EmptyDexCache()
env = self._shell_env.copy()
env.update(env_updates)
- return _RunCommandForOutputAndLog(cmd, env, self._logfile)
+ return _RunCommandForOutputAndLog(cmd, env, self._logfile, self._timeout)
@property
def logfile(self):
@@ -239,16 +290,28 @@
class DeviceTestEnv(ITestEnv):
"""Device test environment. Concrete implementation of ITestEnv.
- Makes use of HostTestEnv to maintain a test directory on host. Creates an
- on device test directory which is kept in sync with the host one.
-
For methods documentation see base class.
"""
- def __init__(self):
- """Constructor."""
- self._host_env_path = mkdtemp(dir='/tmp/', prefix='bisection_search_')
- self._logfile = open('{0}/log'.format(self._host_env_path), 'w+')
+ def __init__(self, directory_prefix, cleanup=True, logfile_path=None,
+ timeout=60, specific_device=None):
+ """Constructor.
+
+ Args:
+ directory_prefix: string, prefix for environment directory name.
+ cleanup: boolean, if True remove test directory in destructor.
+ logfile_path: string, can be used to specify custom logfile location.
+ timeout: int, seconds, time to wait for single test run to finish.
+ specific_device: string, serial number of device to use.
+ """
+ self._cleanup = cleanup
+ self._timeout = timeout
+ self._specific_device = specific_device
+ self._host_env_path = mkdtemp(dir='/tmp/', prefix=directory_prefix)
+ if logfile_path is None:
+ self._logfile = open('{0}/log'.format(self._host_env_path), 'w+')
+ else:
+ self._logfile = open(logfile_path, 'w+')
self._device_env_path = '{0}/{1}'.format(
DEVICE_TMP_PATH, os.path.basename(self._host_env_path))
self._shell_env = os.environ.copy()
@@ -257,6 +320,13 @@
for arch_cache_path in _DexArchCachePaths(self._device_env_path):
self._AdbMkdir(arch_cache_path)
+ def __del__(self):
+ if self._cleanup:
+ shutil.rmtree(self._host_env_path)
+ check_call(shlex.split(
+ 'adb shell if [ -d "{0}" ]; then rm -rf "{0}"; fi'
+ .format(self._device_env_path)))
+
def CreateFile(self, name=None):
with NamedTemporaryFile(mode='w') as temp_file:
self._AdbPush(temp_file.name, self._device_env_path)
@@ -279,11 +349,18 @@
env_updates['ANDROID_DATA'] = self._device_env_path
env_updates_cmd = ' '.join(['{0}={1}'.format(var, val) for var, val
in env_updates.items()])
- cmd = _CommandListToCommandString(cmd)
- cmd = ('adb shell "logcat -c && {0} {1} ; logcat -d -s dex2oat:* dex2oatd:*'
- '| grep -v "^---------" 1>&2"').format(env_updates_cmd, cmd)
- return _RunCommandForOutputAndLog(
- shlex.split(cmd), self._shell_env, self._logfile)
+ cmd = CommandListToCommandString(cmd)
+ adb = 'adb'
+ if self._specific_device:
+ adb += ' -s ' + self._specific_device
+ cmd = '{0} shell "logcat -c && {1} {2}"'.format(
+ adb, env_updates_cmd, cmd)
+ (output, retcode) = _RunCommandForOutputAndLog(
+ shlex.split(cmd), self._shell_env, self._logfile, self._timeout)
+ logcat_cmd = 'adb shell "logcat -d -s -b main dex2oat:* dex2oatd:*"'
+ (err_output, _) = _RunCommandForOutputAndLog(
+ shlex.split(logcat_cmd), self._shell_env, self._logfile)
+ return (output + err_output, retcode)
@property
def logfile(self):
diff --git a/tools/javafuzz/README.md b/tools/javafuzz/README.md
index 68fc171..b08075a 100644
--- a/tools/javafuzz/README.md
+++ b/tools/javafuzz/README.md
@@ -39,9 +39,10 @@
How to start the JavaFuzz tests
===============================
- run_java_fuzz_test.py [--num_tests]
- [--device]
- [--mode1=mode] [--mode2=mode]
+ run_java_fuzz_test.py
+ [--num_tests=#TESTS]
+ [--device=DEVICE]
+ [--mode1=MODE] [--mode2=MODE]
where
diff --git a/tools/javafuzz/run_java_fuzz_test.py b/tools/javafuzz/run_java_fuzz_test.py
index 5f527b8..51d00be 100755
--- a/tools/javafuzz/run_java_fuzz_test.py
+++ b/tools/javafuzz/run_java_fuzz_test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3.4
#
# Copyright (C) 2016 The Android Open Source Project
#
@@ -16,68 +16,71 @@
import abc
import argparse
+import filecmp
+
+from glob import glob
+
+import os
+import shlex
+import shutil
import subprocess
import sys
-import os
from tempfile import mkdtemp
-from threading import Timer
-# Normalized return codes.
-EXIT_SUCCESS = 0
-EXIT_TIMEOUT = 1
-EXIT_NOTCOMPILED = 2
-EXIT_NOTRUN = 3
+sys.path.append(os.path.dirname(os.path.dirname(
+ os.path.realpath(__file__))))
+
+from bisection_search.common import RetCode
+from bisection_search.common import CommandListToCommandString
+from bisection_search.common import FatalError
+from bisection_search.common import GetEnvVariableOrError
+from bisection_search.common import RunCommandForOutput
+from bisection_search.common import DeviceTestEnv
+
+# Return codes supported by bisection bug search.
+BISECTABLE_RET_CODES = (RetCode.SUCCESS, RetCode.ERROR, RetCode.TIMEOUT)
#
# Utility methods.
#
-def RunCommand(cmd, args, out, err, timeout = 5):
+
+def RunCommand(cmd, out, err, timeout=5):
"""Executes a command, and returns its return code.
Args:
- cmd: string, a command to execute
- args: string, arguments to pass to command (or None)
+ cmd: list of strings, a command to execute
out: string, file name to open for stdout (or None)
err: string, file name to open for stderr (or None)
timeout: int, time out in seconds
Returns:
- return code of running command (forced EXIT_TIMEOUT on timeout)
+ RetCode, return code of running command (forced RetCode.TIMEOUT
+ on timeout)
"""
- cmd = 'exec ' + cmd # preserve pid
- if args != None:
- cmd = cmd + ' ' + args
- outf = None
- if out != None:
+ devnull = subprocess.DEVNULL
+ outf = devnull
+ if out is not None:
outf = open(out, mode='w')
- errf = None
- if err != None:
+ errf = devnull
+ if err is not None:
errf = open(err, mode='w')
- proc = subprocess.Popen(cmd, stdout=outf, stderr=errf, shell=True)
- timer = Timer(timeout, proc.kill) # enforces timeout
- timer.start()
- proc.communicate()
- if timer.is_alive():
- timer.cancel()
- returncode = proc.returncode
- else:
- returncode = EXIT_TIMEOUT
- if outf != None:
+ (_, _, retcode) = RunCommandForOutput(cmd, None, outf, errf, timeout)
+ if outf != devnull:
outf.close()
- if errf != None:
+ if errf != devnull:
errf.close()
- return returncode
+ return retcode
+
def GetJackClassPath():
"""Returns Jack's classpath."""
- top = os.environ.get('ANDROID_BUILD_TOP')
- if top == None:
- raise FatalError('Cannot find AOSP build top')
+ top = GetEnvVariableOrError('ANDROID_BUILD_TOP')
libdir = top + '/out/host/common/obj/JAVA_LIBRARIES'
return libdir + '/core-libart-hostdex_intermediates/classes.jack:' \
+ libdir + '/core-oj-hostdex_intermediates/classes.jack'
+
def GetExecutionModeRunner(device, mode):
"""Returns a runner for the given execution mode.
@@ -92,49 +95,44 @@
if mode == 'ri':
return TestRunnerRIOnHost()
if mode == 'hint':
- return TestRunnerArtOnHost(True)
+ return TestRunnerArtIntOnHost()
if mode == 'hopt':
- return TestRunnerArtOnHost(False)
+ return TestRunnerArtOptOnHost()
if mode == 'tint':
- return TestRunnerArtOnTarget(device, True)
+ return TestRunnerArtIntOnTarget(device)
if mode == 'topt':
- return TestRunnerArtOnTarget(device, False)
+ return TestRunnerArtOptOnTarget(device)
raise FatalError('Unknown execution mode')
-def GetReturnCode(retc):
- """Returns a string representation of the given normalized return code.
- Args:
- retc: int, normalized return code
- Returns:
- string representation of normalized return code
- Raises:
- FatalError: error for unknown normalized return code
- """
- if retc == EXIT_SUCCESS:
- return 'SUCCESS'
- if retc == EXIT_TIMEOUT:
- return 'TIMED-OUT'
- if retc == EXIT_NOTCOMPILED:
- return 'NOT-COMPILED'
- if retc == EXIT_NOTRUN:
- return 'NOT-RUN'
- raise FatalError('Unknown normalized return code')
-
#
# Execution mode classes.
#
+
class TestRunner(object):
"""Abstraction for running a test in a particular execution mode."""
__meta_class__ = abc.ABCMeta
- def GetDescription(self):
+ @abc.abstractproperty
+ def description(self):
"""Returns a description string of the execution mode."""
- return self._description
- def GetId(self):
+ @abc.abstractproperty
+ def id(self):
"""Returns a short string that uniquely identifies the execution mode."""
- return self._id
+
+ @property
+ def output_file(self):
+ return self.id + '_out.txt'
+
+ @abc.abstractmethod
+ def GetBisectionSearchArgs(self):
+ """Get arguments to pass to bisection search tool.
+
+ Returns:
+ list of strings - arguments for bisection search tool, or None if
+ runner is not bisectable
+ """
@abc.abstractmethod
def CompileAndRunTest(self):
@@ -142,8 +140,7 @@
Ensures that the current Test.java in the temporary directory is compiled
and executed under the current execution mode. On success, transfers the
- generated output to the file GetId()_out.txt in the temporary directory.
- Cleans up after itself.
+ generated output to the file self.output_file in the temporary directory.
Most nonzero return codes are assumed non-divergent, since systems may
exit in different ways. This is enforced by normalizing return codes.
@@ -151,112 +148,196 @@
Returns:
normalized return code
"""
- pass
+
class TestRunnerRIOnHost(TestRunner):
"""Concrete test runner of the reference implementation on host."""
- def __init__(self):
- """Constructor for the RI tester."""
- self._description = 'RI on host'
- self._id = 'RI'
+ @property
+ def description(self):
+ return 'RI on host'
+
+ @property
+ def id(self):
+ return 'RI'
def CompileAndRunTest(self):
- if RunCommand('javac', 'Test.java',
- out=None, err=None, timeout=30) == EXIT_SUCCESS:
- retc = RunCommand('java', 'Test', 'RI_run_out.txt', err=None)
- if retc != EXIT_SUCCESS and retc != EXIT_TIMEOUT:
- retc = EXIT_NOTRUN
+ if RunCommand(['javac', 'Test.java'],
+ out=None, err=None, timeout=30) == RetCode.SUCCESS:
+ retc = RunCommand(['java', 'Test'], self.output_file, err=None)
else:
- retc = EXIT_NOTCOMPILED
- # Cleanup and return.
- RunCommand('rm', '-f Test.class', out=None, err=None)
+ retc = RetCode.NOTCOMPILED
return retc
-class TestRunnerArtOnHost(TestRunner):
- """Concrete test runner of Art on host (interpreter or optimizing)."""
+ def GetBisectionSearchArgs(self):
+ return None
- def __init__(self, interpreter):
+
+class TestRunnerArtOnHost(TestRunner):
+ """Abstract test runner of Art on host."""
+
+ def __init__(self, extra_args=None):
"""Constructor for the Art on host tester.
Args:
- interpreter: boolean, selects between interpreter or optimizing
+ extra_args: list of strings, extra arguments for dalvikvm
"""
- self._art_args = '-cp classes.dex Test'
- if interpreter:
- self._description = 'Art interpreter on host'
- self._id = 'HInt'
- self._art_args = '-Xint ' + self._art_args
- else:
- self._description = 'Art optimizing on host'
- self._id = 'HOpt'
- self._jack_args = '-cp ' + GetJackClassPath() + ' --output-dex . Test.java'
+ self._art_cmd = ['/bin/bash', 'art', '-cp', 'classes.dex']
+ if extra_args is not None:
+ self._art_cmd += extra_args
+ self._art_cmd.append('Test')
+ self._jack_args = ['-cp', GetJackClassPath(), '--output-dex', '.',
+ 'Test.java']
def CompileAndRunTest(self):
- if RunCommand('jack', self._jack_args,
- out=None, err='jackerr.txt', timeout=30) == EXIT_SUCCESS:
- out = self.GetId() + '_run_out.txt'
- retc = RunCommand('art', self._art_args, out, 'arterr.txt')
- if retc != EXIT_SUCCESS and retc != EXIT_TIMEOUT:
- retc = EXIT_NOTRUN
+ if RunCommand(['jack'] + self._jack_args, out=None, err='jackerr.txt',
+ timeout=30) == RetCode.SUCCESS:
+ retc = RunCommand(self._art_cmd, self.output_file, 'arterr.txt')
else:
- retc = EXIT_NOTCOMPILED
- # Cleanup and return.
- RunCommand('rm', '-rf classes.dex jackerr.txt arterr.txt android-data*',
- out=None, err=None)
+ retc = RetCode.NOTCOMPILED
return retc
-# TODO: very rough first version without proper cache,
-# reuse staszkiewicz' module for properly setting up dalvikvm on target.
-class TestRunnerArtOnTarget(TestRunner):
- """Concrete test runner of Art on target (interpreter or optimizing)."""
- def __init__(self, device, interpreter):
+class TestRunnerArtIntOnHost(TestRunnerArtOnHost):
+ """Concrete test runner of interpreter mode Art on host."""
+
+ def __init__(self):
+ """Constructor."""
+ super().__init__(['-Xint'])
+
+ @property
+ def description(self):
+ return 'Art interpreter on host'
+
+ @property
+ def id(self):
+ return 'HInt'
+
+ def GetBisectionSearchArgs(self):
+ return None
+
+
+class TestRunnerArtOptOnHost(TestRunnerArtOnHost):
+ """Concrete test runner of optimizing compiler mode Art on host."""
+
+ def __init__(self):
+ """Constructor."""
+ super().__init__(None)
+
+ @property
+ def description(self):
+ return 'Art optimizing on host'
+
+ @property
+ def id(self):
+ return 'HOpt'
+
+ def GetBisectionSearchArgs(self):
+ cmd_str = CommandListToCommandString(
+ self._art_cmd[0:2] + ['{ARGS}'] + self._art_cmd[2:])
+ return ['--raw-cmd={0}'.format(cmd_str), '--timeout', str(30)]
+
+
+class TestRunnerArtOnTarget(TestRunner):
+ """Abstract test runner of Art on target."""
+
+ def __init__(self, device, extra_args=None):
"""Constructor for the Art on target tester.
Args:
device: string, target device serial number (or None)
- interpreter: boolean, selects between interpreter or optimizing
+ extra_args: list of strings, extra arguments for dalvikvm
"""
- self._dalvik_args = 'shell dalvikvm -cp /data/local/tmp/classes.dex Test'
- if interpreter:
- self._description = 'Art interpreter on target'
- self._id = 'TInt'
- self._dalvik_args = '-Xint ' + self._dalvik_args
- else:
- self._description = 'Art optimizing on target'
- self._id = 'TOpt'
- self._adb = 'adb'
- if device != None:
- self._adb = self._adb + ' -s ' + device
- self._jack_args = '-cp ' + GetJackClassPath() + ' --output-dex . Test.java'
+ self._test_env = DeviceTestEnv('javafuzz_', specific_device=device)
+ self._dalvik_cmd = ['dalvikvm']
+ if extra_args is not None:
+ self._dalvik_cmd += extra_args
+ self._device = device
+ self._jack_args = ['-cp', GetJackClassPath(), '--output-dex', '.',
+ 'Test.java']
+ self._device_classpath = None
def CompileAndRunTest(self):
- if RunCommand('jack', self._jack_args,
- out=None, err='jackerr.txt', timeout=30) == EXIT_SUCCESS:
- if RunCommand(self._adb, 'push classes.dex /data/local/tmp/',
- 'adb.txt', err=None) != EXIT_SUCCESS:
- raise FatalError('Cannot push to target device')
- out = self.GetId() + '_run_out.txt'
- retc = RunCommand(self._adb, self._dalvik_args, out, err=None)
- if retc != EXIT_SUCCESS and retc != EXIT_TIMEOUT:
- retc = EXIT_NOTRUN
+ if RunCommand(['jack'] + self._jack_args, out=None, err='jackerr.txt',
+ timeout=30) == RetCode.SUCCESS:
+ self._device_classpath = self._test_env.PushClasspath('classes.dex')
+ cmd = self._dalvik_cmd + ['-cp', self._device_classpath, 'Test']
+ (output, retc) = self._test_env.RunCommand(
+ cmd, {'ANDROID_LOG_TAGS': '*:s'})
+ with open(self.output_file, 'w') as run_out:
+ run_out.write(output)
else:
- retc = EXIT_NOTCOMPILED
- # Cleanup and return.
- RunCommand('rm', '-f classes.dex jackerr.txt adb.txt',
- out=None, err=None)
- RunCommand(self._adb, 'shell rm -f /data/local/tmp/classes.dex',
- out=None, err=None)
+ retc = RetCode.NOTCOMPILED
return retc
+ def GetBisectionSearchArgs(self):
+ cmd_str = CommandListToCommandString(
+ self._dalvik_cmd + ['-cp',self._device_classpath, 'Test'])
+ cmd = ['--raw-cmd={0}'.format(cmd_str), '--timeout', str(30)]
+ if self._device:
+ cmd += ['--device-serial', self._device]
+ else:
+ cmd.append('--device')
+ return cmd
+
+
+class TestRunnerArtIntOnTarget(TestRunnerArtOnTarget):
+ """Concrete test runner of interpreter mode Art on target."""
+
+ def __init__(self, device):
+ """Constructor.
+
+ Args:
+ device: string, target device serial number (or None)
+ """
+ super().__init__(device, ['-Xint'])
+
+ @property
+ def description(self):
+ return 'Art interpreter on target'
+
+ @property
+ def id(self):
+ return 'TInt'
+
+ def GetBisectionSearchArgs(self):
+ return None
+
+
+class TestRunnerArtOptOnTarget(TestRunnerArtOnTarget):
+ """Concrete test runner of optimizing compiler mode Art on target."""
+
+ def __init__(self, device):
+ """Constructor.
+
+ Args:
+ device: string, target device serial number (or None)
+ """
+ super().__init__(device, None)
+
+ @property
+ def description(self):
+ return 'Art optimizing on target'
+
+ @property
+ def id(self):
+ return 'TOpt'
+
+ def GetBisectionSearchArgs(self):
+ cmd_str = CommandListToCommandString(
+ self._dalvik_cmd + ['-cp', self._device_classpath, 'Test'])
+ cmd = ['--raw-cmd={0}'.format(cmd_str), '--timeout', str(30)]
+ if self._device:
+ cmd += ['--device-serial', self._device]
+ else:
+ cmd.append('--device')
+ return cmd
+
+
#
# Tester classes.
#
-class FatalError(Exception):
- """Fatal error in the tester."""
- pass
class JavaFuzzTester(object):
"""Tester that runs JavaFuzz many times and report divergences."""
@@ -265,10 +346,10 @@
"""Constructor for the tester.
Args:
- num_tests: int, number of tests to run
- device: string, target device serial number (or None)
- mode1: string, execution mode for first runner
- mode2: string, execution mode for second runner
+ num_tests: int, number of tests to run
+ device: string, target device serial number (or None)
+ mode1: string, execution mode for first runner
+ mode2: string, execution mode for second runner
"""
self._num_tests = num_tests
self._device = device
@@ -291,8 +372,9 @@
FatalError: error when temp directory cannot be constructed
"""
self._save_dir = os.getcwd()
- self._tmp_dir = mkdtemp(dir="/tmp/")
- if self._tmp_dir == None:
+ self._results_dir = mkdtemp(dir='/tmp/')
+ self._tmp_dir = mkdtemp(dir=self._results_dir)
+ if self._tmp_dir is None or self._results_dir is None:
raise FatalError('Cannot obtain temp directory')
os.chdir(self._tmp_dir)
return self
@@ -300,37 +382,38 @@
def __exit__(self, etype, evalue, etraceback):
"""On exit, re-enters previously saved current directory and cleans up."""
os.chdir(self._save_dir)
+ shutil.rmtree(self._tmp_dir)
if self._num_divergences == 0:
- RunCommand('rm', '-rf ' + self._tmp_dir, out=None, err=None)
+ shutil.rmtree(self._results_dir)
def Run(self):
"""Runs JavaFuzz many times and report divergences."""
- print
- print '**\n**** JavaFuzz Testing\n**'
- print
- print '#Tests :', self._num_tests
- print 'Device :', self._device
- print 'Directory :', self._tmp_dir
- print 'Exec-mode1:', self._runner1.GetDescription()
- print 'Exec-mode2:', self._runner2.GetDescription()
- print
+ print()
+ print('**\n**** JavaFuzz Testing\n**')
+ print()
+ print('#Tests :', self._num_tests)
+ print('Device :', self._device)
+ print('Directory :', self._results_dir)
+ print('Exec-mode1:', self._runner1.description)
+ print('Exec-mode2:', self._runner2.description)
+ print()
self.ShowStats()
for self._test in range(1, self._num_tests + 1):
self.RunJavaFuzzTest()
self.ShowStats()
if self._num_divergences == 0:
- print '\n\nsuccess (no divergences)\n'
+ print('\n\nsuccess (no divergences)\n')
else:
- print '\n\nfailure (divergences)\n'
+ print('\n\nfailure (divergences)\n')
def ShowStats(self):
"""Shows current statistics (on same line) while tester is running."""
- print '\rTests:', self._test, \
- 'Success:', self._num_success, \
- 'Not-compiled:', self._num_not_compiled, \
- 'Not-run:', self._num_not_run, \
- 'Timed-out:', self._num_timed_out, \
- 'Divergences:', self._num_divergences,
+ print('\rTests:', self._test, \
+ 'Success:', self._num_success, \
+ 'Not-compiled:', self._num_not_compiled, \
+ 'Not-run:', self._num_not_run, \
+ 'Timed-out:', self._num_timed_out, \
+ 'Divergences:', self._num_divergences, end='')
sys.stdout.flush()
def RunJavaFuzzTest(self):
@@ -347,8 +430,7 @@
Raises:
FatalError: error when javafuzz fails
"""
- if RunCommand('javafuzz', args=None,
- out='Test.java', err=None) != EXIT_SUCCESS:
+ if RunCommand(['javafuzz'], out='Test.java', err=None) != RetCode.SUCCESS:
raise FatalError('Unexpected error while running JavaFuzz')
def CheckForDivergence(self, retc1, retc2):
@@ -360,38 +442,85 @@
"""
if retc1 == retc2:
# Non-divergent in return code.
- if retc1 == EXIT_SUCCESS:
+ if retc1 == RetCode.SUCCESS:
# Both compilations and runs were successful, inspect generated output.
- args = self._runner1.GetId() + '_run_out.txt ' \
- + self._runner2.GetId() + '_run_out.txt'
- if RunCommand('diff', args, out=None, err=None) != EXIT_SUCCESS:
- self.ReportDivergence('divergence in output')
+ runner1_out = self._runner1.output_file
+ runner2_out = self._runner2.output_file
+ if not filecmp.cmp(runner1_out, runner2_out, shallow=False):
+ self.ReportDivergence(retc1, retc2, is_output_divergence=True)
else:
self._num_success += 1
- elif retc1 == EXIT_TIMEOUT:
+ elif retc1 == RetCode.TIMEOUT:
self._num_timed_out += 1
- elif retc1 == EXIT_NOTCOMPILED:
+ elif retc1 == RetCode.NOTCOMPILED:
self._num_not_compiled += 1
else:
self._num_not_run += 1
else:
# Divergent in return code.
- self.ReportDivergence('divergence in return code: ' +
- GetReturnCode(retc1) + ' vs. ' +
- GetReturnCode(retc2))
+ self.ReportDivergence(retc1, retc2, is_output_divergence=False)
- def ReportDivergence(self, reason):
+ def GetCurrentDivergenceDir(self):
+ return self._results_dir + '/divergence' + str(self._num_divergences)
+
+ def ReportDivergence(self, retc1, retc2, is_output_divergence):
"""Reports and saves a divergence."""
self._num_divergences += 1
- print '\n', self._test, reason
+ print('\n' + str(self._num_divergences), end='')
+ if is_output_divergence:
+ print(' divergence in output')
+ else:
+ print(' divergence in return code: ' + retc1.name + ' vs. ' +
+ retc2.name)
# Save.
- ddir = 'divergence' + str(self._test)
- RunCommand('mkdir', ddir, out=None, err=None)
- RunCommand('mv', 'Test.java *.txt ' + ddir, out=None, err=None)
+ ddir = self.GetCurrentDivergenceDir()
+ os.mkdir(ddir)
+ for f in glob('*.txt') + ['Test.java']:
+ shutil.copy(f, ddir)
+ # Maybe run bisection bug search.
+ if retc1 in BISECTABLE_RET_CODES and retc2 in BISECTABLE_RET_CODES:
+ self.MaybeBisectDivergence(retc1, retc2, is_output_divergence)
+
+ def RunBisectionSearch(self, args, expected_retcode, expected_output,
+ runner_id):
+ ddir = self.GetCurrentDivergenceDir()
+ outfile_path = ddir + '/' + runner_id + '_bisection_out.txt'
+ logfile_path = ddir + '/' + runner_id + '_bisection_log.txt'
+ errfile_path = ddir + '/' + runner_id + '_bisection_err.txt'
+ args = list(args) + ['--logfile', logfile_path, '--cleanup']
+ args += ['--expected-retcode', expected_retcode.name]
+ if expected_output:
+ args += ['--expected-output', expected_output]
+ bisection_search_path = os.path.join(
+ GetEnvVariableOrError('ANDROID_BUILD_TOP'),
+ 'art/tools/bisection_search/bisection_search.py')
+ if RunCommand([bisection_search_path] + args, out=outfile_path,
+ err=errfile_path, timeout=300) == RetCode.TIMEOUT:
+ print('Bisection search TIMEOUT')
+
+ def MaybeBisectDivergence(self, retc1, retc2, is_output_divergence):
+ bisection_args1 = self._runner1.GetBisectionSearchArgs()
+ bisection_args2 = self._runner2.GetBisectionSearchArgs()
+ if is_output_divergence:
+ maybe_output1 = self._runner1.output_file
+ maybe_output2 = self._runner2.output_file
+ else:
+ maybe_output1 = maybe_output2 = None
+ if bisection_args1 is not None:
+ self.RunBisectionSearch(bisection_args1, retc2, maybe_output2,
+ self._runner1.id)
+ if bisection_args2 is not None:
+ self.RunBisectionSearch(bisection_args2, retc1, maybe_output1,
+ self._runner2.id)
def CleanupTest(self):
"""Cleans up after a single test run."""
- RunCommand('rm', '-f Test.java *.txt', out=None, err=None)
+ for file_name in os.listdir(self._tmp_dir):
+ file_path = os.path.join(self._tmp_dir, file_name)
+ if os.path.isfile(file_path):
+ os.unlink(file_path)
+ elif os.path.isdir(file_path):
+ shutil.rmtree(file_path)
def main():
@@ -406,11 +535,11 @@
help='execution mode 2 (default: hopt)')
args = parser.parse_args()
if args.mode1 == args.mode2:
- raise FatalError("Identical execution modes given")
+ raise FatalError('Identical execution modes given')
# Run the JavaFuzz tester.
with JavaFuzzTester(args.num_tests, args.device,
args.mode1, args.mode2) as fuzzer:
fuzzer.Run()
-if __name__ == "__main__":
+if __name__ == '__main__':
main()
diff --git a/tools/run-jdwp-tests.sh b/tools/run-jdwp-tests.sh
index 01dae43..74b0f16 100755
--- a/tools/run-jdwp-tests.sh
+++ b/tools/run-jdwp-tests.sh
@@ -43,7 +43,7 @@
image_compiler_option=""
debug="no"
verbose="no"
-image="-Ximage:/data/art-test/core-optimizing-pic.art"
+image="-Ximage:/data/art-test/core.art"
vm_args=""
# By default, we run the whole JDWP test suite.
test="org.apache.harmony.jpda.tests.share.AllTests"
diff --git a/tools/run-libcore-tests.sh b/tools/run-libcore-tests.sh
index 2a6e172..01c7f20 100755
--- a/tools/run-libcore-tests.sh
+++ b/tools/run-libcore-tests.sh
@@ -95,7 +95,7 @@
if [[ "$1" == "--mode=device" ]]; then
vogar_args="$vogar_args --device-dir=/data/local/tmp"
vogar_args="$vogar_args --vm-command=/data/local/tmp/system/bin/art"
- vogar_args="$vogar_args --vm-arg -Ximage:/data/art-test/core-optimizing.art"
+ vogar_args="$vogar_args --vm-arg -Ximage:/data/art-test/core.art"
shift
elif [[ "$1" == "--mode=host" ]]; then
# We explicitly give a wrong path for the image, to ensure vogar