diff options
113 files changed, 2696 insertions, 2215 deletions
diff --git a/Android.mk b/Android.mk index 6139cb9ae2..4351be9875 100644 --- a/Android.mk +++ b/Android.mk @@ -99,6 +99,8 @@ include $(art_path)/dalvikvm/Android.mk include $(art_path)/tools/Android.mk include $(art_build_path)/Android.oat.mk + + # ART_HOST_DEPENDENCIES depends on Android.executable.mk above for ART_HOST_EXECUTABLES ART_HOST_DEPENDENCIES := $(ART_HOST_EXECUTABLES) $(HOST_OUT_JAVA_LIBRARIES)/core-libart-hostdex.jar ART_HOST_DEPENDENCIES += $(HOST_OUT_SHARED_LIBRARIES)/libjavacore$(ART_HOST_SHLIB_EXTENSION) @@ -110,11 +112,18 @@ ART_TARGET_DEPENDENCIES := $(ART_TARGET_EXECUTABLES) $(TARGET_OUT_JAVA_LIBRARIES include $(art_path)/test/Android.mk include $(art_build_path)/Android.gtest.mk +$(eval $(call combine-art-multi-target-var,ART_TARGET_GTEST_TARGETS)) +$(eval $(call combine-art-multi-target-var,ART_TARGET_GTEST_EXECUTABLES)) + # The ART_*_TEST_DEPENDENCIES definitions: # - depend on Android.oattest.mk above for ART_TEST_*_DEX_FILES # - depend on Android.gtest.mk above for ART_*_GTEST_EXECUTABLES ART_HOST_TEST_DEPENDENCIES := $(ART_HOST_DEPENDENCIES) $(ART_HOST_GTEST_EXECUTABLES) $(ART_TEST_HOST_DEX_FILES) $(HOST_CORE_IMG_OUT) -ART_TARGET_TEST_DEPENDENCIES := $(ART_TARGET_DEPENDENCIES) $(ART_TARGET_GTEST_EXECUTABLES) $(ART_TEST_TARGET_DEX_FILES) $(TARGET_CORE_IMG_OUT) + +define declare-art-target-test-dependencies-var +ART_TARGET_TEST_DEPENDENCIES$(1) := $(ART_TARGET_DEPENDENCIES) $(ART_TARGET_GTEST_EXECUTABLES$(1)) $(ART_TEST_TARGET_DEX_FILES$(1)) $(TARGET_CORE_IMG_OUT$(1)) +endef +$(eval $(call call-art-multi-target-var,declare-art-target-test-dependencies-var,ART_TARGET_TEST_DEPENDENCIES)) include $(art_build_path)/Android.libarttest.mk @@ -209,46 +218,70 @@ test-art-host-run-test: test-art-host-run-test-default test-art-host-run-test-in # target test targets # "mm test-art-target" to build and run all target tests -.PHONY: test-art-target -test-art-target: test-art-target-gtest test-art-target-oat test-art-target-run-test - @echo test-art-target PASSED +define declare-test-art-target +.PHONY: test-art-target$(1) +test-art-target$(1): test-art-target-gtest$(1) test-art-target-oat$(1) test-art-target-run-test$(1) + @echo test-art-target$(1) PASSED +endef +$(eval $(call call-art-multi-target-rule,declare-test-art-target,test-art-target)) + + +define declare-test-art-target-dependencies +.PHONY: test-art-target-dependencies$(1) +test-art-target-dependencies$(1): $(ART_TARGET_TEST_DEPENDENCIES$(1)) $(ART_TEST_OUT)/libarttest.so +endef +$(eval $(call call-art-multi-target-rule,declare-test-art-target-dependencies,test-art-target-dependencies)) -.PHONY: test-art-target-dependencies -test-art-target-dependencies: $(ART_TARGET_TEST_DEPENDENCIES) $(ART_TEST_OUT)/libarttest.so .PHONY: test-art-target-sync -test-art-target-sync: test-art-target-dependencies +test-art-target-sync: test-art-target-dependencies$(ART_PHONY_TEST_TARGET_SUFFIX) test-art-target-dependencies$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) adb remount adb sync adb shell mkdir -p $(ART_TEST_DIR) -.PHONY: test-art-target-gtest -test-art-target-gtest: $(ART_TARGET_GTEST_TARGETS) -.PHONY: test-art-target-oat -test-art-target-oat: $(ART_TEST_TARGET_OAT_TARGETS) - @echo test-art-target-oat PASSED +define declare-test-art-target-gtest +.PHONY: test-art-target-gtest$(1) +test-art-target-gtest$(1): $(ART_TARGET_GTEST_TARGETS$(1)) + @echo test-art-target-gtest$(1) PASSED +endef +$(eval $(call call-art-multi-target-rule,declare-test-art-target-gtest,test-art-target-gtest)) + + +define declare-test-art-target-oat +.PHONY: test-art-target-oat$(1) +test-art-target-oat$(1): $(ART_TEST_TARGET_OAT_TARGETS$(1)) + @echo test-art-target-oat$(1) PASSED +endef +$(eval $(call call-art-multi-target-rule,declare-test-art-target-oat,test-art-target-oat)) + define declare-test-art-target-run-test-impl +$(2)run_test_$(1) := +ifeq ($($(2)ART_PHONY_TEST_TARGET_SUFFIX),64) + $(2)run_test_$(1) := --64 +endif .PHONY: test-art-target-run-test-$(1)$($(2)ART_PHONY_TEST_TARGET_SUFFIX) test-art-target-run-test-$(1)$($(2)ART_PHONY_TEST_TARGET_SUFFIX): test-art-target-sync $(DX) $(HOST_OUT_EXECUTABLES)/jasmin - DX=$(abspath $(DX)) JASMIN=$(abspath $(HOST_OUT_EXECUTABLES)/jasmin) art/test/run-test $(DALVIKVM_FLAGS) $(1) $(3) + DX=$(abspath $(DX)) JASMIN=$(abspath $(HOST_OUT_EXECUTABLES)/jasmin) art/test/run-test $(DALVIKVM_FLAGS) $$($(2)run_test_$(1)) $(1) @echo test-art-target-run-test-$(1)$($(2)ART_PHONY_TEST_TARGET_SUFFIX) PASSED endef define declare-test-art-target-run-test ifdef TARGET_2ND_ARCH - $(call declare-test-art-target-run-test-impl,$(1),2ND_,) + $(call declare-test-art-target-run-test-impl,$(1),2ND_) + + TEST_ART_TARGET_RUN_TEST_TARGETS$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) += test-art-target-run-test-$(1)$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),) # Link primary to non-suffix test-art-target-run-test-$(1): test-art-target-run-test-$(1)$(ART_PHONY_TEST_TARGET_SUFFIX) endif endif - $(call declare-test-art-target-run-test-impl,$(1),,--$(ART_TARGET_BINARY_SUFFIX)) + $(call declare-test-art-target-run-test-impl,$(1),) - TEST_ART_TARGET_RUN_TEST_TARGETS += test-art-target-run-test-$(1) + TEST_ART_TARGET_RUN_TEST_TARGETS$(ART_PHONY_TEST_TARGET_SUFFIX) += test-art-target-run-test-$(1)$(ART_PHONY_TEST_TARGET_SUFFIX) test-art-run-test-$(1): test-art-host-run-test-$(1) test-art-target-run-test-$(1) @@ -256,9 +289,14 @@ endef $(foreach test, $(TEST_ART_RUN_TESTS), $(eval $(call declare-test-art-target-run-test,$(test)))) -.PHONY: test-art-target-run-test -test-art-target-run-test: $(TEST_ART_TARGET_RUN_TEST_TARGETS) - @echo test-art-target-run-test PASSED + +define declare-test-art-target-run-test +.PHONY: test-art-target-run-test$(1) +test-art-target-run-test$(1): $(TEST_ART_TARGET_RUN_TEST_TARGETS$(1)) + @echo test-art-target-run-test$(1) PASSED +endef +$(eval $(call call-art-multi-target-rule,declare-test-art-target-run-test,test-art-target-run-test)) + ######################################################################## # oat-target and oat-target-sync targets @@ -286,7 +324,12 @@ oat-target-$(1): $$(OUT_OAT_FILE) $$(OUT_OAT_FILE): $(PRODUCT_OUT)/$(1) $(DEFAULT_DEX_PREOPT_BUILT_IMAGE) $(DEX2OATD_DEPENDENCY) @mkdir -p $$(dir $$@) - $(DEX2OATD) --runtime-arg -Xms64m --runtime-arg -Xmx64m --boot-image=$(DEFAULT_DEX_PREOPT_BUILT_IMAGE) --dex-file=$(PRODUCT_OUT)/$(1) --dex-location=/$(1) --oat-file=$$@ --instruction-set=$(TARGET_ARCH) --instruction-set-features=$(TARGET_INSTRUCTION_SET_FEATURES) --android-root=$(PRODUCT_OUT)/system + $(DEX2OATD) --runtime-arg -Xms64m --runtime-arg -Xmx64m \ + --boot-image=$(DEFAULT_DEX_PREOPT_BUILT_IMAGE) --dex-file=$(PRODUCT_OUT)/$(1) \ + --dex-location=/$(1) --oat-file=$$@ \ + --instruction-set=$(DEX2OAT_TARGET_ARCH) \ + --instruction-set-features=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \ + --android-root=$(PRODUCT_OUT)/system endif diff --git a/build/Android.common.mk b/build/Android.common.mk index b9a297b3c7..c95b1c6239 100644 --- a/build/Android.common.mk +++ b/build/Android.common.mk @@ -291,4 +291,71 @@ ifeq ($(ART_BUILD_HOST_DEBUG),true) ART_BUILD_DEBUG := true endif +# Helper function to call a function twice with a target suffix +# $(1): The generator function for the rules +# Has one argument, the suffix +define call-art-multi-target + $(call $(1),$(ART_PHONY_TEST_TARGET_SUFFIX)) + + ifdef TARGET_2ND_ARCH + $(call $(1),$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)) + endif +endef + +# Helper function to combine two variables with suffixes together. +# $(1): The base name. +define combine-art-multi-target-var + ifdef TARGET_2ND_ARCH + ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),) + ifneq ($(2ND_ART_PHONY_TEST_TARGET_SUFFIX),) +$(1) := $($(1)$(ART_PHONY_TEST_TARGET_SUFFIX)) $($(1)$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)) + endif + endif + endif +endef + + +# Helper function to define a variable twice with a target suffix. Assume the name generated is +# derived from $(2) so we can create a combined var. +# $(1): The generator function for the rules +# Has one argument, the suffix +define call-art-multi-target-var + $(call $(1),$(ART_PHONY_TEST_TARGET_SUFFIX)) + + ifdef TARGET_2ND_ARCH + $(call $(1),$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)) + + # Link both together, if it makes sense + ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),) + ifneq ($(2ND_ART_PHONY_TEST_TARGET_SUFFIX),) +$(2) := $(2)$(ART_PHONY_TEST_TARGET_SUFFIX) $(2)$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) + endif + endif + + endif +endef + +# Helper function to call a function twice with a target suffix. Assume it generates make rules +# with the given name, and link them. +# $(1): The generator function for the rules +# Has one argument, the suffix +# $(2): The base rule name, necessary for the link +# We assume we can link the names together easily... +define call-art-multi-target-rule + $(call $(1),$(ART_PHONY_TEST_TARGET_SUFFIX)) + + ifdef TARGET_2ND_ARCH + $(call $(1),$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)) + + # Link both together, if it makes sense + ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),) + ifneq ($(2ND_ART_PHONY_TEST_TARGET_SUFFIX),) +.PHONY: $(2) +$(2): $(2)$(ART_PHONY_TEST_TARGET_SUFFIX) $(2)$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) + endif + endif + endif +endef + + endif # ANDROID_COMMON_MK diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk index b6e6fac9be..4b655b5ba9 100644 --- a/build/Android.gtest.mk +++ b/build/Android.gtest.mk @@ -105,10 +105,12 @@ COMPILER_GTEST_HOST_SRC_FILES := \ compiler/utils/x86/assembler_x86_test.cc ART_HOST_GTEST_EXECUTABLES := -ART_TARGET_GTEST_EXECUTABLES := +ART_TARGET_GTEST_EXECUTABLES$(ART_PHONY_TEST_TARGET_SUFFIX) := +ART_TARGET_GTEST_EXECUTABLES$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) := ART_HOST_GTEST_TARGETS := ART_HOST_VALGRIND_GTEST_TARGETS := -ART_TARGET_GTEST_TARGETS := +ART_TARGET_GTEST_TARGETS$(ART_PHONY_TEST_TARGET_SUFFIX) := +ART_TARGET_GTEST_TARGETS$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) := ART_TEST_CFLAGS := ifeq ($(ART_USE_PORTABLE_COMPILER),true) @@ -127,7 +129,7 @@ $$(art_gtest_target)$($(1)ART_PHONY_TEST_TARGET_SUFFIX): $($(1)ART_NATIVETEST_OU $(hide) (adb pull $($(1)ART_TEST_DIR)/$$@ /tmp/ && echo $$@ PASSED) || (echo $$@ FAILED && exit 1) $(hide) rm /tmp/$$@ - ART_TARGET_GTEST_TARGETS += $$(art_gtest_target)$($(1)ART_PHONY_TEST_TARGET_SUFFIX) + ART_TARGET_GTEST_TARGETS$($(1)ART_PHONY_TEST_TARGET_SUFFIX) += $$(art_gtest_target)$($(1)ART_PHONY_TEST_TARGET_SUFFIX) endef @@ -182,12 +184,15 @@ define build-art-test LOCAL_MULTILIB := both include art/build/Android.libcxx.mk include $(BUILD_EXECUTABLE) - ART_TARGET_GTEST_EXECUTABLES += $$(art_gtest_exe) + + ART_TARGET_GTEST_EXECUTABLES$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_NATIVETEST_OUT)/$$(LOCAL_MODULE) art_gtest_target := test-art-$$(art_target_or_host)-gtest-$$(art_gtest_name) ifdef TARGET_2ND_ARCH $(call build-art-test-make-target,2ND_) + ART_TARGET_GTEST_EXECUTABLES$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) += $(2ND_ART_NATIVETEST_OUT)/$$(LOCAL_MODULE) + # Bind the primary to the non-suffix rule ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),) $$(art_gtest_target): $$(art_gtest_target)$(ART_PHONY_TEST_TARGET_SUFFIX) diff --git a/build/Android.oat.mk b/build/Android.oat.mk index cb45a8529e..9d7579de93 100644 --- a/build/Android.oat.mk +++ b/build/Android.oat.mk @@ -63,6 +63,9 @@ $$($(1)TARGET_CORE_IMG_OUT): $$($(1)TARGET_CORE_DEX_FILES) $$(DEX2OATD_DEPENDENC --oat-location=$$($(1)TARGET_CORE_OAT) --image=$$($(1)TARGET_CORE_IMG_OUT) --base=$$(LIBART_IMG_TARGET_BASE_ADDRESS) \ --instruction-set=$$($(1)TARGET_ARCH) --instruction-set-features=$$(TARGET_INSTRUCTION_SET_FEATURES) --android-root=$$(PRODUCT_OUT)/system +# This "renaming" eases declaration in art/Android.mk +TARGET_CORE_IMG_OUT$($(1)ART_PHONY_TEST_TARGET_SUFFIX) := $($(1)TARGET_CORE_IMG_OUT) + $$($(1)TARGET_CORE_OAT_OUT): $$($(1)TARGET_CORE_IMG_OUT) endef diff --git a/compiler/dex/compiler_enums.h b/compiler/dex/compiler_enums.h index 8a88d618cc..ba4b5c356a 100644 --- a/compiler/dex/compiler_enums.h +++ b/compiler/dex/compiler_enums.h @@ -159,8 +159,10 @@ enum AssemblerStatus { }; enum OpSize { - kWord, - kLong, + kWord, // Natural word size of target (32/64). + k32, + k64, + kReference, // Object reference; compressed on 64-bit targets. kSingle, kDouble, kUnsignedHalf, @@ -323,8 +325,6 @@ enum X86ConditionCode { std::ostream& operator<<(std::ostream& os, const X86ConditionCode& kind); enum ThrowKind { - kThrowArrayBounds, - kThrowConstantArrayBounds, kThrowNoSuchMethod, }; diff --git a/compiler/dex/frontend.cc b/compiler/dex/frontend.cc index 1bf5fce989..ed2ecace36 100644 --- a/compiler/dex/frontend.cc +++ b/compiler/dex/frontend.cc @@ -181,6 +181,17 @@ static CompiledMethod* CompileMethod(CompilerDriver& driver, (cu.enable_debug & (1 << kDebugVerbose)); } + if (gVerboseMethods.size() != 0) { + cu.verbose = false; + for (size_t i = 0; i < gVerboseMethods.size(); ++i) { + if (PrettyMethod(method_idx, dex_file).find(gVerboseMethods[i]) + != std::string::npos) { + cu.verbose = true; + break; + } + } + } + /* * TODO: rework handling of optimization and debug flags. Should we split out * MIR and backend flags? Need command-line setting as well. diff --git a/compiler/dex/quick/arm/call_arm.cc b/compiler/dex/quick/arm/call_arm.cc index d0d0e6b3a7..b374ed861e 100644 --- a/compiler/dex/quick/arm/call_arm.cc +++ b/compiler/dex/quick/arm/call_arm.cc @@ -128,7 +128,7 @@ void ArmMir2Lir::GenPackedSwitch(MIR* mir, uint32_t table_offset, // Load the displacement from the switch table RegStorage disp_reg = AllocTemp(); - LoadBaseIndexed(table_base, keyReg, disp_reg, 2, kWord); + LoadBaseIndexed(table_base, keyReg, disp_reg, 2, k32); // ..and go! NOTE: No instruction set switch here - must stay Thumb2 LIR* switch_branch = NewLIR1(kThumb2AddPCR, disp_reg.GetReg()); @@ -180,6 +180,7 @@ void ArmMir2Lir::GenFillArrayData(uint32_t table_offset, RegLocation rl_src) { */ void ArmMir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) { FlushAllRegs(); + // FIXME: need separate LoadValues for object references. LoadValueDirectFixed(rl_src, rs_r0); // Get obj LockCallTemps(); // Prepare for explicit register usage constexpr bool kArchVariantHasGoodBranchPredictor = false; // TODO: true if cortex-A15. @@ -193,7 +194,7 @@ void ArmMir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) { null_check_branch = OpCmpImmBranch(kCondEq, rs_r0, 0, NULL); } } - LoadWordDisp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2); + Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2); NewLIR3(kThumb2Ldrex, r1, r0, mirror::Object::MonitorOffset().Int32Value() >> 2); MarkPossibleNullPointerException(opt_flags); LIR* not_unlocked_branch = OpCmpImmBranch(kCondNe, rs_r1, 0, NULL); @@ -219,7 +220,7 @@ void ArmMir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) { } else { // Explicit null-check as slow-path is entered using an IT. GenNullCheck(rs_r0, opt_flags); - LoadWordDisp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2); + Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2); NewLIR3(kThumb2Ldrex, r1, r0, mirror::Object::MonitorOffset().Int32Value() >> 2); MarkPossibleNullPointerException(opt_flags); OpRegImm(kOpCmp, rs_r1, 0); @@ -248,7 +249,7 @@ void ArmMir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) { LoadValueDirectFixed(rl_src, rs_r0); // Get obj LockCallTemps(); // Prepare for explicit register usage LIR* null_check_branch = nullptr; - LoadWordDisp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2); + Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2); constexpr bool kArchVariantHasGoodBranchPredictor = false; // TODO: true if cortex-A15. if (kArchVariantHasGoodBranchPredictor) { if ((opt_flags & MIR_IGNORE_NULL_CHECK) && !(cu_->disable_opt & (1 << kNullCheckElimination))) { @@ -259,11 +260,11 @@ void ArmMir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) { null_check_branch = OpCmpImmBranch(kCondEq, rs_r0, 0, NULL); } } - LoadWordDisp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1); + Load32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1); MarkPossibleNullPointerException(opt_flags); LoadConstantNoClobber(rs_r3, 0); LIR* slow_unlock_branch = OpCmpBranch(kCondNe, rs_r1, rs_r2, NULL); - StoreWordDisp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r3); + Store32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r3); LIR* unlock_success_branch = OpUnconditionalBranch(NULL); LIR* slow_path_target = NewLIR0(kPseudoTargetLabel); @@ -284,14 +285,14 @@ void ArmMir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) { } else { // Explicit null-check as slow-path is entered using an IT. GenNullCheck(rs_r0, opt_flags); - LoadWordDisp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1); // Get lock + Load32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1); // Get lock MarkPossibleNullPointerException(opt_flags); - LoadWordDisp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2); + Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2); LoadConstantNoClobber(rs_r3, 0); // Is lock unheld on lock or held by us (==thread_id) on unlock? OpRegReg(kOpCmp, rs_r1, rs_r2); LIR* it = OpIT(kCondEq, "EE"); - StoreWordDisp/*eq*/(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r3); + Store32Disp/*eq*/(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r3); // Go expensive route - UnlockObjectFromCode(obj); LoadWordDisp/*ne*/(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject).Int32Value(), rs_rARM_LR); @@ -307,9 +308,9 @@ void ArmMir2Lir::GenMoveException(RegLocation rl_dest) { int ex_offset = Thread::ExceptionOffset<4>().Int32Value(); RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); RegStorage reset_reg = AllocTemp(); - LoadWordDisp(rs_rARM_SELF, ex_offset, rl_result.reg); + Load32Disp(rs_rARM_SELF, ex_offset, rl_result.reg); LoadConstant(reset_reg, 0); - StoreWordDisp(rs_rARM_SELF, ex_offset, reset_reg); + Store32Disp(rs_rARM_SELF, ex_offset, reset_reg); FreeTemp(reset_reg); StoreValue(rl_dest, rl_result); } @@ -354,7 +355,7 @@ void ArmMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { if (!skip_overflow_check) { if (Runtime::Current()->ExplicitStackOverflowChecks()) { /* Load stack limit */ - LoadWordDisp(rs_rARM_SELF, Thread::StackEndOffset<4>().Int32Value(), rs_r12); + Load32Disp(rs_rARM_SELF, Thread::StackEndOffset<4>().Int32Value(), rs_r12); } } /* Spill core callee saves */ @@ -391,6 +392,7 @@ void ArmMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pThrowStackOverflow); // Load the entrypoint directly into the pc instead of doing a load + branch. Assumes // codegen and target are in thumb2 mode. + // NOTE: native pointer. m2l_->LoadWordDisp(rs_rARM_SELF, func_offset.Int32Value(), rs_rARM_PC); } @@ -421,7 +423,7 @@ void ArmMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { // a sub instruction. Otherwise we will get a temp allocation and the // code size will increase. OpRegRegImm(kOpSub, rs_r12, rs_rARM_SP, Thread::kStackOverflowReservedBytes); - LoadWordDisp(rs_r12, 0, rs_r12); + Load32Disp(rs_r12, 0, rs_r12); MarkPossibleStackOverflowException(); OpRegImm(kOpSub, rs_rARM_SP, frame_size_without_spills); } diff --git a/compiler/dex/quick/arm/codegen_arm.h b/compiler/dex/quick/arm/codegen_arm.h index b0bc11d458..a89b307d60 100644 --- a/compiler/dex/quick/arm/codegen_arm.h +++ b/compiler/dex/quick/arm/codegen_arm.h @@ -126,8 +126,6 @@ class ArmMir2Lir FINAL : public Mir2Lir { RegLocation rl_src2); void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); - LIR* GenRegMemCheck(ConditionCode c_code, RegStorage reg1, RegStorage base, int offset, - ThrowKind kind); RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div); RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div); void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); diff --git a/compiler/dex/quick/arm/int_arm.cc b/compiler/dex/quick/arm/int_arm.cc index c876b3ac69..f47e693e4d 100644 --- a/compiler/dex/quick/arm/int_arm.cc +++ b/compiler/dex/quick/arm/int_arm.cc @@ -314,11 +314,11 @@ LIR* ArmMir2Lir::OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_va /* * A common use of OpCmpImmBranch is for null checks, and using the Thumb 16-bit * compare-and-branch if zero is ideal if it will reach. However, because null checks - * branch forward to a launch pad, they will frequently not reach - and thus have to + * branch forward to a slow path, they will frequently not reach - and thus have to * be converted to a long form during assembly (which will trigger another assembly * pass). Here we estimate the branch distance for checks, and if large directly * generate the long form in an attempt to avoid an extra assembly pass. - * TODO: consider interspersing launchpads in code following unconditional branches. + * TODO: consider interspersing slowpaths in code following unconditional branches. */ bool skip = ((target != NULL) && (target->opcode == kPseudoThrowTarget)); skip &= ((cu_->code_item->insns_size_in_code_units_ - current_dalvik_offset_) > 64); @@ -608,12 +608,6 @@ bool ArmMir2Lir::EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) return true; } -LIR* ArmMir2Lir::GenRegMemCheck(ConditionCode c_code, RegStorage reg1, RegStorage base, - int offset, ThrowKind kind) { - LOG(FATAL) << "Unexpected use of GenRegMemCheck for Arm"; - return NULL; -} - RegLocation ArmMir2Lir::GenDivRem(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2, bool is_div, bool check_zero) { LOG(FATAL) << "Unexpected use of GenDivRem for Arm"; @@ -684,18 +678,18 @@ bool ArmMir2Lir::GenInlinedPeek(CallInfo* info, OpSize size) { RegLocation rl_dest = InlineTarget(info); RegLocation rl_address = LoadValue(rl_src_address, kCoreReg); RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); - if (size == kLong) { + if (size == k64) { // Fake unaligned LDRD by two unaligned LDR instructions on ARMv7 with SCTLR.A set to 0. if (rl_address.reg.GetReg() != rl_result.reg.GetLowReg()) { - LoadWordDisp(rl_address.reg, 0, rl_result.reg.GetLow()); - LoadWordDisp(rl_address.reg, 4, rl_result.reg.GetHigh()); + Load32Disp(rl_address.reg, 0, rl_result.reg.GetLow()); + Load32Disp(rl_address.reg, 4, rl_result.reg.GetHigh()); } else { - LoadWordDisp(rl_address.reg, 4, rl_result.reg.GetHigh()); - LoadWordDisp(rl_address.reg, 0, rl_result.reg.GetLow()); + Load32Disp(rl_address.reg, 4, rl_result.reg.GetHigh()); + Load32Disp(rl_address.reg, 0, rl_result.reg.GetLow()); } StoreValueWide(rl_dest, rl_result); } else { - DCHECK(size == kSignedByte || size == kSignedHalf || size == kWord); + DCHECK(size == kSignedByte || size == kSignedHalf || size == k32); // Unaligned load with LDR and LDRSH is allowed on ARMv7 with SCTLR.A set to 0. LoadBaseDisp(rl_address.reg, 0, rl_result.reg, size, INVALID_SREG); StoreValue(rl_dest, rl_result); @@ -708,13 +702,13 @@ bool ArmMir2Lir::GenInlinedPoke(CallInfo* info, OpSize size) { rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1] RegLocation rl_src_value = info->args[2]; // [size] value RegLocation rl_address = LoadValue(rl_src_address, kCoreReg); - if (size == kLong) { + if (size == k64) { // Fake unaligned STRD by two unaligned STR instructions on ARMv7 with SCTLR.A set to 0. RegLocation rl_value = LoadValueWide(rl_src_value, kCoreReg); - StoreBaseDisp(rl_address.reg, 0, rl_value.reg.GetLow(), kWord); - StoreBaseDisp(rl_address.reg, 4, rl_value.reg.GetHigh(), kWord); + StoreBaseDisp(rl_address.reg, 0, rl_value.reg.GetLow(), k32); + StoreBaseDisp(rl_address.reg, 4, rl_value.reg.GetHigh(), k32); } else { - DCHECK(size == kSignedByte || size == kSignedHalf || size == kWord); + DCHECK(size == kSignedByte || size == kSignedHalf || size == k32); // Unaligned store with STR and STRSH is allowed on ARMv7 with SCTLR.A set to 0. RegLocation rl_value = LoadValue(rl_src_value, kCoreReg); StoreBaseDisp(rl_address.reg, 0, rl_value.reg, size); @@ -1148,7 +1142,7 @@ void ArmMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, if (needs_range_check) { reg_len = AllocTemp(); /* Get len */ - LoadWordDisp(rl_array.reg, len_offset, reg_len); + Load32Disp(rl_array.reg, len_offset, reg_len); MarkPossibleNullPointerException(opt_flags); } else { ForceImplicitNullCheck(rl_array.reg, opt_flags); @@ -1167,9 +1161,9 @@ void ArmMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, if (needs_range_check) { if (constant_index) { - GenImmedCheck(kCondLs, reg_len, mir_graph_->ConstantValue(rl_index), kThrowConstantArrayBounds); + GenArrayBoundsCheck(mir_graph_->ConstantValue(rl_index), reg_len); } else { - GenRegRegCheck(kCondLs, reg_len, rl_index.reg, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, reg_len); } FreeTemp(reg_len); } @@ -1196,7 +1190,7 @@ void ArmMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, rl_result = EvalLoc(rl_dest, reg_class, true); if (needs_range_check) { - GenRegRegCheck(kCondUge, rl_index.reg, reg_len, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, reg_len); FreeTemp(reg_len); } LoadBaseIndexed(reg_ptr, rl_index.reg, rl_result.reg, scale, size); @@ -1217,7 +1211,7 @@ void ArmMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, bool constant_index = rl_index.is_const; int data_offset; - if (size == kLong || size == kDouble) { + if (size == k64 || size == kDouble) { data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value(); } else { data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value(); @@ -1254,7 +1248,7 @@ void ArmMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, reg_len = AllocTemp(); // NOTE: max live temps(4) here. /* Get len */ - LoadWordDisp(rl_array.reg, len_offset, reg_len); + Load32Disp(rl_array.reg, len_offset, reg_len); MarkPossibleNullPointerException(opt_flags); } else { ForceImplicitNullCheck(rl_array.reg, opt_flags); @@ -1271,9 +1265,9 @@ void ArmMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, } if (needs_range_check) { if (constant_index) { - GenImmedCheck(kCondLs, reg_len, mir_graph_->ConstantValue(rl_index), kThrowConstantArrayBounds); + GenArrayBoundsCheck(mir_graph_->ConstantValue(rl_index), reg_len); } else { - GenRegRegCheck(kCondLs, reg_len, rl_index.reg, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, reg_len); } FreeTemp(reg_len); } @@ -1289,7 +1283,7 @@ void ArmMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, OpRegRegImm(kOpAdd, reg_ptr, rl_array.reg, data_offset); rl_src = LoadValue(rl_src, reg_class); if (needs_range_check) { - GenRegRegCheck(kCondUge, rl_index.reg, reg_len, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, reg_len); FreeTemp(reg_len); } StoreBaseIndexed(reg_ptr, rl_index.reg, rl_src.reg, scale, size); diff --git a/compiler/dex/quick/arm/target_arm.cc b/compiler/dex/quick/arm/target_arm.cc index 1053a8fc41..305e89ba92 100644 --- a/compiler/dex/quick/arm/target_arm.cc +++ b/compiler/dex/quick/arm/target_arm.cc @@ -656,7 +656,7 @@ void ArmMir2Lir::FlushReg(RegStorage reg) { if (info->live && info->dirty) { info->dirty = false; int v_reg = mir_graph_->SRegToVReg(info->s_reg); - StoreBaseDisp(rs_rARM_SP, VRegOffset(v_reg), reg, kWord); + StoreBaseDisp(rs_rARM_SP, VRegOffset(v_reg), reg, k32); } } @@ -738,8 +738,8 @@ RegStorage ArmMir2Lir::LoadHelper(ThreadOffset<4> offset) { LIR* ArmMir2Lir::CheckSuspendUsingLoad() { RegStorage tmp = rs_r0; - LoadWordDisp(rs_rARM_SELF, Thread::ThreadSuspendTriggerOffset<4>().Int32Value(), tmp); - LIR* load2 = LoadWordDisp(tmp, 0, tmp); + Load32Disp(rs_rARM_SELF, Thread::ThreadSuspendTriggerOffset<4>().Int32Value(), tmp); + LIR* load2 = Load32Disp(tmp, 0, tmp); return load2; } diff --git a/compiler/dex/quick/arm/utility_arm.cc b/compiler/dex/quick/arm/utility_arm.cc index 70cbdd2e31..6879ffc08a 100644 --- a/compiler/dex/quick/arm/utility_arm.cc +++ b/compiler/dex/quick/arm/utility_arm.cc @@ -699,23 +699,24 @@ LIR* ArmMir2Lir::LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStora if (ARM_FPREG(r_dest.GetReg())) { if (ARM_SINGLEREG(r_dest.GetReg())) { - DCHECK((size == kWord) || (size == kSingle)); + DCHECK((size == k32) || (size == kSingle)); opcode = kThumb2Vldrs; size = kSingle; } else { DCHECK(ARM_DOUBLEREG(r_dest.GetReg())); - DCHECK((size == kLong) || (size == kDouble)); + DCHECK((size == k64) || (size == kDouble)); DCHECK_EQ((r_dest.GetReg() & 0x1), 0); opcode = kThumb2Vldrd; size = kDouble; } } else { if (size == kSingle) - size = kWord; + size = k32; } switch (size) { case kDouble: // fall-through + // Intentional fall-though. case kSingle: reg_ptr = AllocTemp(); if (scale) { @@ -727,7 +728,9 @@ LIR* ArmMir2Lir::LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStora load = NewLIR3(opcode, r_dest.GetReg(), reg_ptr.GetReg(), 0); FreeTemp(reg_ptr); return load; - case kWord: + case k32: + // Intentional fall-though. + case kReference: opcode = (thumb_form) ? kThumbLdrRRR : kThumb2LdrRRR; break; case kUnsignedHalf: @@ -764,23 +767,24 @@ LIR* ArmMir2Lir::StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStor if (ARM_FPREG(r_src.GetReg())) { if (ARM_SINGLEREG(r_src.GetReg())) { - DCHECK((size == kWord) || (size == kSingle)); + DCHECK((size == k32) || (size == kSingle)); opcode = kThumb2Vstrs; size = kSingle; } else { DCHECK(ARM_DOUBLEREG(r_src.GetReg())); - DCHECK((size == kLong) || (size == kDouble)); + DCHECK((size == k64) || (size == kDouble)); DCHECK_EQ((r_src.GetReg() & 0x1), 0); opcode = kThumb2Vstrd; size = kDouble; } } else { if (size == kSingle) - size = kWord; + size = k32; } switch (size) { case kDouble: // fall-through + // Intentional fall-though. case kSingle: reg_ptr = AllocTemp(); if (scale) { @@ -792,14 +796,18 @@ LIR* ArmMir2Lir::StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStor store = NewLIR3(opcode, r_src.GetReg(), reg_ptr.GetReg(), 0); FreeTemp(reg_ptr); return store; - case kWord: + case k32: + // Intentional fall-though. + case kReference: opcode = (thumb_form) ? kThumbStrRRR : kThumb2StrRRR; break; case kUnsignedHalf: + // Intentional fall-though. case kSignedHalf: opcode = (thumb_form) ? kThumbStrhRRR : kThumb2StrhRRR; break; case kUnsignedByte: + // Intentional fall-though. case kSignedByte: opcode = (thumb_form) ? kThumbStrbRRR : kThumb2StrbRRR; break; @@ -832,7 +840,8 @@ LIR* ArmMir2Lir::LoadBaseDispBody(RegStorage r_base, int displacement, RegStorag bool null_pointer_safepoint = false; switch (size) { case kDouble: - case kLong: + // Intentional fall-though. + case k64: if (ARM_FPREG(dest_low_reg)) { // Note: following change to avoid using pairs for doubles, replace conversion w/ DCHECK. if (r_dest.IsPair()) { @@ -849,15 +858,18 @@ LIR* ArmMir2Lir::LoadBaseDispBody(RegStorage r_base, int displacement, RegStorag load = NewLIR4(kThumb2LdrdI8, r_dest.GetLowReg(), r_dest.GetHighReg(), r_base.GetReg(), displacement >> 2); } else { - load = LoadBaseDispBody(r_base, displacement, r_dest.GetLow(), kWord, s_reg); + load = LoadBaseDispBody(r_base, displacement, r_dest.GetLow(), k32, s_reg); null_pointer_safepoint = true; - LoadBaseDispBody(r_base, displacement + 4, r_dest.GetHigh(), kWord, INVALID_SREG); + LoadBaseDispBody(r_base, displacement + 4, r_dest.GetHigh(), k32, INVALID_SREG); } already_generated = true; } break; case kSingle: - case kWord: + // Intentional fall-though. + case k32: + // Intentional fall-though. + case kReference: if (ARM_FPREG(r_dest.GetReg())) { opcode = kThumb2Vldrs; if (displacement <= 1020) { @@ -953,13 +965,17 @@ LIR* ArmMir2Lir::LoadBaseDispBody(RegStorage r_base, int displacement, RegStorag LIR* ArmMir2Lir::LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size, int s_reg) { - DCHECK(!((size == kLong) || (size == kDouble))); + DCHECK(!((size == k64) || (size == kDouble))); + // TODO: base this on target. + if (size == kWord) { + size = k32; + } return LoadBaseDispBody(r_base, displacement, r_dest, size, s_reg); } LIR* ArmMir2Lir::LoadBaseDispWide(RegStorage r_base, int displacement, RegStorage r_dest, int s_reg) { - return LoadBaseDispBody(r_base, displacement, r_dest, kLong, s_reg); + return LoadBaseDispBody(r_base, displacement, r_dest, k64, s_reg); } @@ -975,16 +991,16 @@ LIR* ArmMir2Lir::StoreBaseDispBody(RegStorage r_base, int displacement, RegStora int src_low_reg = r_src.IsPair() ? r_src.GetLowReg() : r_src.GetReg(); bool null_pointer_safepoint = false; switch (size) { - case kLong: + case k64: case kDouble: if (!ARM_FPREG(src_low_reg)) { if (displacement <= 1020) { store = NewLIR4(kThumb2StrdI8, r_src.GetLowReg(), r_src.GetHighReg(), r_base.GetReg(), displacement >> 2); } else { - store = StoreBaseDispBody(r_base, displacement, r_src.GetLow(), kWord); + store = StoreBaseDispBody(r_base, displacement, r_src.GetLow(), k32); null_pointer_safepoint = true; - StoreBaseDispBody(r_base, displacement + 4, r_src.GetHigh(), kWord); + StoreBaseDispBody(r_base, displacement + 4, r_src.GetHigh(), k32); } already_generated = true; } else { @@ -1001,7 +1017,8 @@ LIR* ArmMir2Lir::StoreBaseDispBody(RegStorage r_base, int displacement, RegStora } break; case kSingle: - case kWord: + case k32: + case kReference: if (ARM_FPREG(r_src.GetReg())) { DCHECK(ARM_SINGLEREG(r_src.GetReg())); opcode = kThumb2Vstrs; @@ -1082,12 +1099,16 @@ LIR* ArmMir2Lir::StoreBaseDispBody(RegStorage r_base, int displacement, RegStora LIR* ArmMir2Lir::StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size) { - DCHECK(!((size == kLong) || (size == kDouble))); + // TODO: base this on target. + if (size == kWord) { + size = k32; + } + DCHECK(!((size == k64) || (size == kDouble))); return StoreBaseDispBody(r_base, displacement, r_src, size); } LIR* ArmMir2Lir::StoreBaseDispWide(RegStorage r_base, int displacement, RegStorage r_src) { - return StoreBaseDispBody(r_base, displacement, r_src, kLong); + return StoreBaseDispBody(r_base, displacement, r_src, k64); } LIR* ArmMir2Lir::OpFpRegCopy(RegStorage r_dest, RegStorage r_src) { diff --git a/compiler/dex/quick/codegen_util.cc b/compiler/dex/quick/codegen_util.cc index 6e6b8f0a30..677ee15462 100644 --- a/compiler/dex/quick/codegen_util.cc +++ b/compiler/dex/quick/codegen_util.cc @@ -926,7 +926,6 @@ Mir2Lir::Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena mir_graph_(mir_graph), switch_tables_(arena, 4, kGrowableArraySwitchTables), fill_array_data_(arena, 4, kGrowableArrayFillArrayData), - throw_launchpads_(arena, 2048, kGrowableArrayThrowLaunchPads), suspend_launchpads_(arena, 4, kGrowableArraySuspendLaunchPads), tempreg_info_(arena, 20, kGrowableArrayMisc), reginfo_map_(arena, 64, kGrowableArrayMisc), @@ -1118,7 +1117,7 @@ bool Mir2Lir::BadOverlap(RegLocation rl_src, RegLocation rl_dest) { LIR *Mir2Lir::OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg, int offset, int check_value, LIR* target) { // Handle this for architectures that can't compare to memory. - LoadWordDisp(base_reg, offset, temp_reg); + Load32Disp(base_reg, offset, temp_reg); LIR* branch = OpCmpImmBranch(cond, temp_reg, check_value, target); return branch; } diff --git a/compiler/dex/quick/dex_file_method_inliner.cc b/compiler/dex/quick/dex_file_method_inliner.cc index 8806e68b93..3ec31ba7d9 100644 --- a/compiler/dex/quick/dex_file_method_inliner.cc +++ b/compiler/dex/quick/dex_file_method_inliner.cc @@ -212,8 +212,8 @@ const DexFileMethodInliner::IntrinsicDef DexFileMethodInliner::kIntrinsicMethods INTRINSIC(JavaLangFloat, FloatToRawIntBits, F_I, kIntrinsicFloatCvt, 0), INTRINSIC(JavaLangFloat, IntBitsToFloat, I_F, kIntrinsicFloatCvt, 0), - INTRINSIC(JavaLangInteger, ReverseBytes, I_I, kIntrinsicReverseBytes, kWord), - INTRINSIC(JavaLangLong, ReverseBytes, J_J, kIntrinsicReverseBytes, kLong), + INTRINSIC(JavaLangInteger, ReverseBytes, I_I, kIntrinsicReverseBytes, k32), + INTRINSIC(JavaLangLong, ReverseBytes, J_J, kIntrinsicReverseBytes, k64), INTRINSIC(JavaLangShort, ReverseBytes, S_S, kIntrinsicReverseBytes, kSignedHalf), INTRINSIC(JavaLangMath, Abs, I_I, kIntrinsicAbsInt, 0), @@ -241,12 +241,12 @@ const DexFileMethodInliner::IntrinsicDef DexFileMethodInliner::kIntrinsicMethods INTRINSIC(JavaLangThread, CurrentThread, _Thread, kIntrinsicCurrentThread, 0), INTRINSIC(LibcoreIoMemory, PeekByte, J_B, kIntrinsicPeek, kSignedByte), - INTRINSIC(LibcoreIoMemory, PeekIntNative, J_I, kIntrinsicPeek, kWord), - INTRINSIC(LibcoreIoMemory, PeekLongNative, J_J, kIntrinsicPeek, kLong), + INTRINSIC(LibcoreIoMemory, PeekIntNative, J_I, kIntrinsicPeek, k32), + INTRINSIC(LibcoreIoMemory, PeekLongNative, J_J, kIntrinsicPeek, k64), INTRINSIC(LibcoreIoMemory, PeekShortNative, J_S, kIntrinsicPeek, kSignedHalf), INTRINSIC(LibcoreIoMemory, PokeByte, JB_V, kIntrinsicPoke, kSignedByte), - INTRINSIC(LibcoreIoMemory, PokeIntNative, JI_V, kIntrinsicPoke, kWord), - INTRINSIC(LibcoreIoMemory, PokeLongNative, JJ_V, kIntrinsicPoke, kLong), + INTRINSIC(LibcoreIoMemory, PokeIntNative, JI_V, kIntrinsicPoke, k32), + INTRINSIC(LibcoreIoMemory, PokeLongNative, JJ_V, kIntrinsicPoke, k64), INTRINSIC(LibcoreIoMemory, PokeShortNative, JS_V, kIntrinsicPoke, kSignedHalf), INTRINSIC(SunMiscUnsafe, CompareAndSwapInt, ObjectJII_Z, kIntrinsicCas, diff --git a/compiler/dex/quick/gen_common.cc b/compiler/dex/quick/gen_common.cc index 1847921ccb..aa9b2a491a 100644 --- a/compiler/dex/quick/gen_common.cc +++ b/compiler/dex/quick/gen_common.cc @@ -42,22 +42,6 @@ void Mir2Lir::GenBarrier() { barrier->u.m.def_mask = ENCODE_ALL; } -LIR* Mir2Lir::GenImmedCheck(ConditionCode c_code, RegStorage reg, int imm_val, ThrowKind kind) { - LIR* tgt; - LIR* branch; - if (c_code == kCondAl) { - tgt = RawLIR(0, kPseudoThrowTarget, kind, current_dalvik_offset_, RegStorage::kInvalidRegVal, - imm_val); - branch = OpUnconditionalBranch(tgt); - } else { - tgt = RawLIR(0, kPseudoThrowTarget, kind, current_dalvik_offset_, reg.GetReg(), imm_val); - branch = OpCmpImmBranch(c_code, reg, imm_val, tgt); - } - // Remember branch target - will process later - throw_launchpads_.Insert(tgt); - return branch; -} - void Mir2Lir::GenDivZeroException() { LIR* branch = OpUnconditionalBranch(nullptr); AddDivZeroCheckSlowPath(branch); @@ -91,6 +75,59 @@ void Mir2Lir::AddDivZeroCheckSlowPath(LIR* branch) { AddSlowPath(new (arena_) DivZeroCheckSlowPath(this, branch)); } +void Mir2Lir::GenArrayBoundsCheck(RegStorage index, RegStorage length) { + class ArrayBoundsCheckSlowPath : public Mir2Lir::LIRSlowPath { + public: + ArrayBoundsCheckSlowPath(Mir2Lir* m2l, LIR* branch, RegStorage index, RegStorage length) + : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch), + index_(index), length_(length) { + } + + void Compile() OVERRIDE { + m2l_->ResetRegPool(); + m2l_->ResetDefTracking(); + GenerateTargetLabel(); + m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pThrowArrayBounds), + index_, length_, true); + } + + private: + const RegStorage index_; + const RegStorage length_; + }; + + LIR* branch = OpCmpBranch(kCondUge, index, length, nullptr); + AddSlowPath(new (arena_) ArrayBoundsCheckSlowPath(this, branch, index, length)); +} + +void Mir2Lir::GenArrayBoundsCheck(int index, RegStorage length) { + class ArrayBoundsCheckSlowPath : public Mir2Lir::LIRSlowPath { + public: + ArrayBoundsCheckSlowPath(Mir2Lir* m2l, LIR* branch, int index, RegStorage length) + : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch), + index_(index), length_(length) { + } + + void Compile() OVERRIDE { + m2l_->ResetRegPool(); + m2l_->ResetDefTracking(); + GenerateTargetLabel(); + + m2l_->OpRegCopy(m2l_->TargetReg(kArg1), length_); + m2l_->LoadConstant(m2l_->TargetReg(kArg0), index_); + m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pThrowArrayBounds), + m2l_->TargetReg(kArg0), m2l_->TargetReg(kArg1), true); + } + + private: + const int32_t index_; + const RegStorage length_; + }; + + LIR* branch = OpCmpImmBranch(kCondLs, length, index, nullptr); + AddSlowPath(new (arena_) ArrayBoundsCheckSlowPath(this, branch, index, length)); +} + LIR* Mir2Lir::GenNullCheck(RegStorage reg) { class NullCheckSlowPath : public Mir2Lir::LIRSlowPath { public: @@ -151,23 +188,12 @@ void Mir2Lir::ForceImplicitNullCheck(RegStorage reg, int opt_flags) { // register with offset 0. This will cause a signal if the register contains 0 (null). RegStorage tmp = AllocTemp(); // TODO: for Mips, would be best to use rZERO as the bogus register target. - LIR* load = LoadWordDisp(reg, 0, tmp); + LIR* load = Load32Disp(reg, 0, tmp); FreeTemp(tmp); MarkSafepointPC(load); } } -/* Perform check on two registers */ -LIR* Mir2Lir::GenRegRegCheck(ConditionCode c_code, RegStorage reg1, RegStorage reg2, - ThrowKind kind) { - LIR* tgt = RawLIR(0, kPseudoThrowTarget, kind, current_dalvik_offset_, reg1.GetReg(), - reg2.GetReg()); - LIR* branch = OpCmpBranch(c_code, reg1, reg2, tgt); - // Remember branch target - will process later - throw_launchpads_.Insert(tgt); - return branch; -} - void Mir2Lir::GenCompareAndBranch(Instruction::Code opcode, RegLocation rl_src1, RegLocation rl_src2, LIR* taken, LIR* fall_through) { @@ -373,7 +399,7 @@ void Mir2Lir::GenFilledNewArray(CallInfo* info) { for (int i = 0; i < elems; i++) { RegLocation loc = UpdateLoc(info->args[i]); if (loc.location == kLocPhysReg) { - StoreBaseDisp(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, kWord); + Store32Disp(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg); } } /* @@ -410,8 +436,8 @@ void Mir2Lir::GenFilledNewArray(CallInfo* info) { // Generate the copy loop. Going backwards for convenience LIR* target = NewLIR0(kPseudoTargetLabel); // Copy next element - LoadBaseIndexed(r_src, r_idx, r_val, 2, kWord); - StoreBaseIndexed(r_dst, r_idx, r_val, 2, kWord); + LoadBaseIndexed(r_src, r_idx, r_val, 2, k32); + StoreBaseIndexed(r_dst, r_idx, r_val, 2, k32); FreeTemp(r_val); OpDecAndBranch(kCondGe, r_idx, target); if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { @@ -423,9 +449,8 @@ void Mir2Lir::GenFilledNewArray(CallInfo* info) { // TUNING: interleave for (int i = 0; i < elems; i++) { RegLocation rl_arg = LoadValue(info->args[i], kCoreReg); - StoreBaseDisp(TargetReg(kRet0), - mirror::Array::DataOffset(component_size).Int32Value() + i * 4, - rl_arg.reg, kWord); + Store32Disp(TargetReg(kRet0), + mirror::Array::DataOffset(component_size).Int32Value() + i * 4, rl_arg.reg); // If the LoadValue caused a temp to be allocated, free it if (IsTemp(rl_arg.reg)) { FreeTemp(rl_arg.reg); @@ -476,7 +501,7 @@ void Mir2Lir::GenSput(MIR* mir, RegLocation rl_src, bool is_long_or_double, // Fast path, static storage base is this method's class RegLocation rl_method = LoadCurrMethod(); r_base = AllocTemp(); - LoadWordDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base); + LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base); if (IsTemp(rl_method.reg)) { FreeTemp(rl_method.reg); } @@ -493,8 +518,8 @@ void Mir2Lir::GenSput(MIR* mir, RegLocation rl_src, bool is_long_or_double, LoadCurrMethodDirect(r_method); r_base = TargetReg(kArg0); LockTemp(r_base); - LoadWordDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base); - LoadWordDisp(r_base, mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + + LoadRefDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base); + LoadRefDisp(r_base, mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + sizeof(int32_t*) * field_info.StorageIndex(), r_base); // r_base now points at static storage (Class*) or NULL if the type is not yet resolved. if (!field_info.IsInitialized() && @@ -535,8 +560,10 @@ void Mir2Lir::GenSput(MIR* mir, RegLocation rl_src, bool is_long_or_double, } if (is_long_or_double) { StoreBaseDispWide(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); + } else if (rl_src.ref) { + StoreRefDisp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); } else { - StoreWordDisp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); + Store32Disp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); } if (field_info.IsVolatile()) { // A load might follow the volatile store so insert a StoreLoad barrier. @@ -567,7 +594,7 @@ void Mir2Lir::GenSget(MIR* mir, RegLocation rl_dest, // Fast path, static storage base is this method's class RegLocation rl_method = LoadCurrMethod(); r_base = AllocTemp(); - LoadWordDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base); + LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base); } else { // Medium path, static storage base in a different class which requires checks that the other // class is initialized @@ -580,9 +607,9 @@ void Mir2Lir::GenSget(MIR* mir, RegLocation rl_dest, LoadCurrMethodDirect(r_method); r_base = TargetReg(kArg0); LockTemp(r_base); - LoadWordDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base); - LoadWordDisp(r_base, mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + - sizeof(int32_t*) * field_info.StorageIndex(), r_base); + LoadRefDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base); + LoadRefDisp(r_base, mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + + sizeof(int32_t*) * field_info.StorageIndex(), r_base); // r_base now points at static storage (Class*) or NULL if the type is not yet resolved. if (!field_info.IsInitialized() && (mir->optimization_flags & MIR_IGNORE_CLINIT_CHECK) == 0) { @@ -615,8 +642,10 @@ void Mir2Lir::GenSget(MIR* mir, RegLocation rl_dest, if (is_long_or_double) { LoadBaseDispWide(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg, INVALID_SREG); + } else if (rl_result.ref) { + LoadRefDisp(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg); } else { - LoadWordDisp(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg); + Load32Disp(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg); } FreeTemp(r_base); @@ -675,82 +704,6 @@ void Mir2Lir::HandleSuspendLaunchPads() { } } -void Mir2Lir::HandleThrowLaunchPads() { - int num_elems = throw_launchpads_.Size(); - for (int i = 0; i < num_elems; i++) { - ResetRegPool(); - ResetDefTracking(); - LIR* lab = throw_launchpads_.Get(i); - current_dalvik_offset_ = lab->operands[1]; - AppendLIR(lab); - ThreadOffset<4> func_offset(-1); - int v1 = lab->operands[2]; - int v2 = lab->operands[3]; - const bool target_x86 = cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64; - switch (lab->operands[0]) { - case kThrowConstantArrayBounds: // v1 is length reg (for Arm/Mips), v2 constant index - // v1 holds the constant array index. Mips/Arm uses v2 for length, x86 reloads. - if (target_x86) { - OpRegMem(kOpMov, TargetReg(kArg1), RegStorage::Solo32(v1), - mirror::Array::LengthOffset().Int32Value()); - } else { - OpRegCopy(TargetReg(kArg1), RegStorage::Solo32(v1)); - } - // Make sure the following LoadConstant doesn't mess with kArg1. - LockTemp(TargetReg(kArg1)); - LoadConstant(TargetReg(kArg0), v2); - func_offset = QUICK_ENTRYPOINT_OFFSET(4, pThrowArrayBounds); - break; - case kThrowArrayBounds: - // Move v1 (array index) to kArg0 and v2 (array length) to kArg1 - if (v2 != TargetReg(kArg0).GetReg()) { - OpRegCopy(TargetReg(kArg0), RegStorage::Solo32(v1)); - if (target_x86) { - // x86 leaves the array pointer in v2, so load the array length that the handler expects - OpRegMem(kOpMov, TargetReg(kArg1), RegStorage::Solo32(v2), - mirror::Array::LengthOffset().Int32Value()); - } else { - OpRegCopy(TargetReg(kArg1), RegStorage::Solo32(v2)); - } - } else { - if (v1 == TargetReg(kArg1).GetReg()) { - // Swap v1 and v2, using kArg2 as a temp - OpRegCopy(TargetReg(kArg2), RegStorage::Solo32(v1)); - if (target_x86) { - // x86 leaves the array pointer in v2; load the array length that the handler expects - OpRegMem(kOpMov, TargetReg(kArg1), RegStorage::Solo32(v2), - mirror::Array::LengthOffset().Int32Value()); - } else { - OpRegCopy(TargetReg(kArg1), RegStorage::Solo32(v2)); - } - OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); - } else { - if (target_x86) { - // x86 leaves the array pointer in v2; load the array length that the handler expects - OpRegMem(kOpMov, TargetReg(kArg1), RegStorage::Solo32(v2), - mirror::Array::LengthOffset().Int32Value()); - } else { - OpRegCopy(TargetReg(kArg1), RegStorage::Solo32(v2)); - } - OpRegCopy(TargetReg(kArg0), RegStorage::Solo32(v1)); - } - } - func_offset = QUICK_ENTRYPOINT_OFFSET(4, pThrowArrayBounds); - break; - case kThrowNoSuchMethod: - OpRegCopy(TargetReg(kArg0), RegStorage::Solo32(v1)); - func_offset = - QUICK_ENTRYPOINT_OFFSET(4, pThrowNoSuchMethod); - break; - default: - LOG(FATAL) << "Unexpected throw kind: " << lab->operands[0]; - } - ClobberCallerSave(); - RegStorage r_tgt = CallHelperSetup(func_offset); - CallHelper(r_tgt, func_offset, true /* MarkSafepointPC */, true /* UseLink */); - } -} - void Mir2Lir::GenIGet(MIR* mir, int opt_flags, OpSize size, RegLocation rl_dest, RegLocation rl_obj, bool is_long_or_double, bool is_object) { @@ -798,7 +751,7 @@ void Mir2Lir::GenIGet(MIR* mir, int opt_flags, OpSize size, } else { rl_result = EvalLoc(rl_dest, reg_class, true); GenNullCheck(rl_obj.reg, opt_flags); - LoadBaseDisp(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_result.reg, kWord, + LoadBaseDisp(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_result.reg, k32, rl_obj.s_reg_low); MarkPossibleNullPointerException(opt_flags); if (field_info.IsVolatile()) { @@ -862,7 +815,7 @@ void Mir2Lir::GenIPut(MIR* mir, int opt_flags, OpSize size, // There might have been a store before this volatile one so insert StoreStore barrier. GenMemBarrier(kStoreStore); } - StoreBaseDisp(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_src.reg, kWord); + Store32Disp(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_src.reg); MarkPossibleNullPointerException(opt_flags); if (field_info.IsVolatile()) { // A load might follow the volatile store so insert a StoreLoad barrier. @@ -911,11 +864,11 @@ void Mir2Lir::GenConstClass(uint32_t type_idx, RegLocation rl_dest) { // We're don't need access checks, load type from dex cache int32_t dex_cache_offset = mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(); - LoadWordDisp(rl_method.reg, dex_cache_offset, res_reg); + Load32Disp(rl_method.reg, dex_cache_offset, res_reg); int32_t offset_of_type = mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*) * type_idx); - LoadWordDisp(res_reg, offset_of_type, rl_result.reg); + Load32Disp(res_reg, offset_of_type, rl_result.reg); if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx) || SLOW_TYPE_PATH) { // Slow path, at runtime test if type is null and if so initialize @@ -980,11 +933,11 @@ void Mir2Lir::GenConstString(uint32_t string_idx, RegLocation rl_dest) { r_method = TargetReg(kArg2); LoadCurrMethodDirect(r_method); } - LoadWordDisp(r_method, mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), - TargetReg(kArg0)); + LoadRefDisp(r_method, mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), + TargetReg(kArg0)); // Might call out to helper, which will return resolved string in kRet0 - LoadWordDisp(TargetReg(kArg0), offset_of_string, TargetReg(kRet0)); + Load32Disp(TargetReg(kArg0), offset_of_string, TargetReg(kRet0)); if (cu_->instruction_set == kThumb2 || cu_->instruction_set == kMips) { // OpRegImm(kOpCmp, TargetReg(kRet0), 0); // Is resolved? @@ -1034,8 +987,8 @@ void Mir2Lir::GenConstString(uint32_t string_idx, RegLocation rl_dest) { RegLocation rl_method = LoadCurrMethod(); RegStorage res_reg = AllocTemp(); RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); - LoadWordDisp(rl_method.reg, mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), res_reg); - LoadWordDisp(res_reg, offset_of_string, rl_result.reg); + LoadRefDisp(rl_method.reg, mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), res_reg); + Load32Disp(res_reg, offset_of_string, rl_result.reg); StoreValue(rl_dest, rl_result); } } @@ -1120,19 +1073,20 @@ void Mir2Lir::GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, Re LoadCurrMethodDirect(check_class); if (use_declaring_class) { - LoadWordDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), check_class); - LoadWordDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class); + LoadRefDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), check_class); + LoadRefDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class); } else { - LoadWordDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), - check_class); - LoadWordDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class); + LoadRefDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), + check_class); + LoadRefDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class); int32_t offset_of_type = mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*) * type_idx); - LoadWordDisp(check_class, offset_of_type, check_class); + LoadRefDisp(check_class, offset_of_type, check_class); } LIR* ne_branchover = NULL; + // FIXME: what should we be comparing here? compressed or decompressed references? if (cu_->instruction_set == kThumb2) { OpRegReg(kOpCmp, check_class, object_class); // Same? LIR* it = OpIT(kCondEq, ""); // if-convert the test @@ -1178,17 +1132,17 @@ void Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_know LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref } else if (use_declaring_class) { LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref - LoadWordDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), + LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), class_reg); } else { // Load dex cache entry into class_reg (kArg2) LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref - LoadWordDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), - class_reg); + LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), + class_reg); int32_t offset_of_type = mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*) * type_idx); - LoadWordDisp(class_reg, offset_of_type, class_reg); + LoadRefDisp(class_reg, offset_of_type, class_reg); if (!can_assume_type_is_in_dex_cache) { // Need to test presence of type in dex cache at runtime LIR* hop_branch = OpCmpImmBranch(kCondNe, class_reg, 0, NULL); @@ -1212,7 +1166,7 @@ void Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_know /* load object->klass_ */ DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0); - LoadWordDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); + LoadRefDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); /* kArg0 is ref, kArg1 is ref->klass_, kArg2 is class */ LIR* branchover = NULL; if (type_known_final) { @@ -1315,16 +1269,16 @@ void Mir2Lir::GenCheckCast(uint32_t insn_idx, uint32_t type_idx, RegLocation rl_ type_idx, TargetReg(kArg1), true); OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path } else if (use_declaring_class) { - LoadWordDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), - class_reg); + LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), + class_reg); } else { // Load dex cache entry into class_reg (kArg2) - LoadWordDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), - class_reg); + LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), + class_reg); int32_t offset_of_type = mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*) * type_idx); - LoadWordDisp(class_reg, offset_of_type, class_reg); + LoadRefDisp(class_reg, offset_of_type, class_reg); if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx)) { // Need to test presence of type in dex cache at runtime LIR* hop_branch = OpCmpImmBranch(kCondEq, class_reg, 0, NULL); @@ -1372,8 +1326,8 @@ void Mir2Lir::GenCheckCast(uint32_t insn_idx, uint32_t type_idx, RegLocation rl_ GenerateTargetLabel(); if (load_) { - m2l_->LoadWordDisp(m2l_->TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), - m2l_->TargetReg(kArg1)); + m2l_->LoadRefDisp(m2l_->TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), + m2l_->TargetReg(kArg1)); } m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pCheckCast), m2l_->TargetReg(kArg2), m2l_->TargetReg(kArg1), true); @@ -1399,7 +1353,7 @@ void Mir2Lir::GenCheckCast(uint32_t insn_idx, uint32_t type_idx, RegLocation rl_ LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL); /* load object->klass_ */ DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0); - LoadWordDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); + LoadRefDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); LIR* branch2 = OpCmpBranch(kCondNe, TargetReg(kArg1), class_reg, NULL); LIR* cont = NewLIR0(kPseudoTargetLabel); diff --git a/compiler/dex/quick/gen_invoke.cc b/compiler/dex/quick/gen_invoke.cc index 4aae16d103..53b6ed420e 100644 --- a/compiler/dex/quick/gen_invoke.cc +++ b/compiler/dex/quick/gen_invoke.cc @@ -34,10 +34,10 @@ namespace art { * and "op" calls may be used here. */ -void Mir2Lir::AddIntrinsicLaunchpad(CallInfo* info, LIR* branch, LIR* resume) { - class IntrinsicLaunchpadPath : public Mir2Lir::LIRSlowPath { +void Mir2Lir::AddIntrinsicSlowPath(CallInfo* info, LIR* branch, LIR* resume) { + class IntrinsicSlowPathPath : public Mir2Lir::LIRSlowPath { public: - IntrinsicLaunchpadPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr) + IntrinsicSlowPathPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr) : LIRSlowPath(m2l, info->offset, branch, resume), info_(info) { } @@ -57,7 +57,7 @@ void Mir2Lir::AddIntrinsicLaunchpad(CallInfo* info, LIR* branch, LIR* resume) { CallInfo* const info_; }; - AddSlowPath(new (arena_) IntrinsicLaunchpadPath(this, info, branch, resume)); + AddSlowPath(new (arena_) IntrinsicSlowPathPath(this, info, branch, resume)); } /* @@ -255,12 +255,27 @@ void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(ThreadOffset<4> helper_off CallHelper(r_tgt, helper_offset, safepoint_pc); } +void Mir2Lir::CopyToArgumentRegs(RegStorage arg0, RegStorage arg1) { + if (arg1.GetReg() == TargetReg(kArg0).GetReg()) { + if (arg0.GetReg() == TargetReg(kArg1).GetReg()) { + // Swap kArg0 and kArg1 with kArg2 as temp. + OpRegCopy(TargetReg(kArg2), arg1); + OpRegCopy(TargetReg(kArg0), arg0); + OpRegCopy(TargetReg(kArg1), TargetReg(kArg2)); + } else { + OpRegCopy(TargetReg(kArg1), arg1); + OpRegCopy(TargetReg(kArg0), arg0); + } + } else { + OpRegCopy(TargetReg(kArg0), arg0); + OpRegCopy(TargetReg(kArg1), arg1); + } +} + void Mir2Lir::CallRuntimeHelperRegReg(ThreadOffset<4> helper_offset, RegStorage arg0, RegStorage arg1, bool safepoint_pc) { RegStorage r_tgt = CallHelperSetup(helper_offset); - DCHECK_NE(TargetReg(kArg0).GetReg(), arg1.GetReg()); // check copy into arg0 won't clobber arg1 - OpRegCopy(TargetReg(kArg0), arg0); - OpRegCopy(TargetReg(kArg1), arg1); + CopyToArgumentRegs(arg0, arg1); ClobberCallerSave(); CallHelper(r_tgt, helper_offset, safepoint_pc); } @@ -268,9 +283,7 @@ void Mir2Lir::CallRuntimeHelperRegReg(ThreadOffset<4> helper_offset, RegStorage void Mir2Lir::CallRuntimeHelperRegRegImm(ThreadOffset<4> helper_offset, RegStorage arg0, RegStorage arg1, int arg2, bool safepoint_pc) { RegStorage r_tgt = CallHelperSetup(helper_offset); - DCHECK_NE(TargetReg(kArg0).GetReg(), arg1.GetReg()); // check copy into arg0 won't clobber arg1 - OpRegCopy(TargetReg(kArg0), arg0); - OpRegCopy(TargetReg(kArg1), arg1); + CopyToArgumentRegs(arg0, arg1); LoadConstant(TargetReg(kArg2), arg2); ClobberCallerSave(); CallHelper(r_tgt, helper_offset, safepoint_pc); @@ -347,7 +360,11 @@ void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) { rl_src.reg = TargetReg(kArg0); rl_src.home = false; MarkLive(rl_src.reg, rl_src.s_reg_low); - StoreValue(rl_method, rl_src); + if (rl_method.wide) { + StoreValueWide(rl_method, rl_src); + } else { + StoreValue(rl_method, rl_src); + } // If Method* has been promoted, explicitly flush if (rl_method.location == kLocPhysReg) { StoreWordDisp(TargetReg(kSp), 0, TargetReg(kArg0)); @@ -412,16 +429,15 @@ void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) { } } if (need_flush) { - StoreBaseDisp(TargetReg(kSp), SRegOffset(start_vreg + i), reg, kWord); + Store32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), reg); } } else { // If arriving in frame & promoted if (v_map->core_location == kLocPhysReg) { - LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i), - RegStorage::Solo32(v_map->core_reg)); + Load32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->core_reg)); } if (v_map->fp_location == kLocPhysReg) { - LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->FpReg)); + Load32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->FpReg)); } } } @@ -463,9 +479,9 @@ static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info, cg->LoadCurrMethodDirect(cg->TargetReg(kArg0)); break; case 1: // Get method->dex_cache_resolved_methods_ - cg->LoadWordDisp(cg->TargetReg(kArg0), - mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(), - cg->TargetReg(kArg0)); + cg->LoadRefDisp(cg->TargetReg(kArg0), + mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(), + cg->TargetReg(kArg0)); // Set up direct code if known. if (direct_code != 0) { if (direct_code != static_cast<unsigned int>(-1)) { @@ -478,9 +494,9 @@ static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info, break; case 2: // Grab target method* CHECK_EQ(cu->dex_file, target_method.dex_file); - cg->LoadWordDisp(cg->TargetReg(kArg0), - mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + - (target_method.dex_method_index * 4), cg->TargetReg(kArg0)); + cg->LoadRefDisp(cg->TargetReg(kArg0), + mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + + (target_method.dex_method_index * 4), cg->TargetReg(kArg0)); break; case 3: // Grab the code from the method* if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { @@ -524,18 +540,18 @@ static int NextVCallInsn(CompilationUnit* cu, CallInfo* info, case 1: // Is "this" null? [use kArg1] cg->GenNullCheck(cg->TargetReg(kArg1), info->opt_flags); // get this->klass_ [use kArg1, set kInvokeTgt] - cg->LoadWordDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(), - cg->TargetReg(kInvokeTgt)); + cg->LoadRefDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(), + cg->TargetReg(kInvokeTgt)); cg->MarkPossibleNullPointerException(info->opt_flags); break; case 2: // Get this->klass_->vtable [usr kInvokeTgt, set kInvokeTgt] - cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), mirror::Class::VTableOffset().Int32Value(), - cg->TargetReg(kInvokeTgt)); + cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), mirror::Class::VTableOffset().Int32Value(), + cg->TargetReg(kInvokeTgt)); break; case 3: // Get target method [use kInvokeTgt, set kArg0] - cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), (method_idx * 4) + - mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(), - cg->TargetReg(kArg0)); + cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), (method_idx * 4) + + mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(), + cg->TargetReg(kArg0)); break; case 4: // Get the compiled code address [uses kArg0, sets kInvokeTgt] if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { @@ -579,15 +595,17 @@ static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state, case 2: // Is "this" null? [use kArg1] cg->GenNullCheck(cg->TargetReg(kArg1), info->opt_flags); // Get this->klass_ [use kArg1, set kInvokeTgt] - cg->LoadWordDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(), - cg->TargetReg(kInvokeTgt)); + cg->LoadRefDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(), + cg->TargetReg(kInvokeTgt)); cg->MarkPossibleNullPointerException(info->opt_flags); break; case 3: // Get this->klass_->imtable [use kInvokeTgt, set kInvokeTgt] - cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), mirror::Class::ImTableOffset().Int32Value(), - cg->TargetReg(kInvokeTgt)); + // NOTE: native pointer. + cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), mirror::Class::ImTableOffset().Int32Value(), + cg->TargetReg(kInvokeTgt)); break; case 4: // Get target method [use kInvokeTgt, set kArg0] + // NOTE: native pointer. cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), ((method_idx % ClassLinker::kImtSize) * 4) + mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(), cg->TargetReg(kArg0)); @@ -740,11 +758,11 @@ int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info, } else { // kArg2 & rArg3 can safely be used here reg = TargetReg(kArg3); - LoadWordDisp(TargetReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg); + Load32Disp(TargetReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg); call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, direct_code, direct_method, type); } - StoreBaseDisp(TargetReg(kSp), (next_use + 1) * 4, reg, kWord); + Store32Disp(TargetReg(kSp), (next_use + 1) * 4, reg); call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, direct_code, direct_method, type); next_use++; @@ -778,7 +796,7 @@ int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info, StoreBaseDispWide(TargetReg(kSp), outs_offset, RegStorage::MakeRegPair(low_reg, high_reg)); next_use += 2; } else { - StoreWordDisp(TargetReg(kSp), outs_offset, low_reg); + Store32Disp(TargetReg(kSp), outs_offset, low_reg); next_use++; } call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, @@ -798,7 +816,7 @@ int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info, // In lieu of generating a check for kArg1 being null, we need to // perform a load when doing implicit checks. RegStorage tmp = AllocTemp(); - LoadWordDisp(TargetReg(kArg1), 0, tmp); + Load32Disp(TargetReg(kArg1), 0, tmp); MarkPossibleNullPointerException(info->opt_flags); FreeTemp(tmp); } @@ -849,7 +867,7 @@ int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state, } else { loc = UpdateLoc(loc); if ((next_arg >= 3) && (loc.location == kLocPhysReg)) { - StoreBaseDisp(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, kWord); + Store32Disp(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg); } next_arg++; } @@ -984,8 +1002,8 @@ int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state, RegStorage temp = TargetReg(kArg3); // Now load the argument VR and store to the outs. - LoadWordDisp(TargetReg(kSp), current_src_offset, temp); - StoreWordDisp(TargetReg(kSp), current_dest_offset, temp); + Load32Disp(TargetReg(kSp), current_src_offset, temp); + Store32Disp(TargetReg(kSp), current_dest_offset, temp); } current_src_offset += bytes_to_move; @@ -1014,7 +1032,7 @@ int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state, // In lieu of generating a check for kArg1 being null, we need to // perform a load when doing implicit checks. RegStorage tmp = AllocTemp(); - LoadWordDisp(TargetReg(kArg1), 0, tmp); + Load32Disp(TargetReg(kArg1), 0, tmp); MarkPossibleNullPointerException(info->opt_flags); FreeTemp(tmp); } @@ -1074,14 +1092,14 @@ bool Mir2Lir::GenInlinedCharAt(CallInfo* info) { reg_ptr = AllocTemp(); if (range_check) { reg_max = AllocTemp(); - LoadWordDisp(rl_obj.reg, count_offset, reg_max); + Load32Disp(rl_obj.reg, count_offset, reg_max); MarkPossibleNullPointerException(info->opt_flags); } - LoadWordDisp(rl_obj.reg, offset_offset, reg_off); + Load32Disp(rl_obj.reg, offset_offset, reg_off); MarkPossibleNullPointerException(info->opt_flags); - LoadWordDisp(rl_obj.reg, value_offset, reg_ptr); + Load32Disp(rl_obj.reg, value_offset, reg_ptr); if (range_check) { - // Set up a launch pad to allow retry in case of bounds violation */ + // Set up a slow path to allow retry in case of bounds violation */ OpRegReg(kOpCmp, rl_idx.reg, reg_max); FreeTemp(reg_max); range_check_branch = OpCondBranch(kCondUge, nullptr); @@ -1102,8 +1120,8 @@ bool Mir2Lir::GenInlinedCharAt(CallInfo* info) { } reg_off = AllocTemp(); reg_ptr = AllocTemp(); - LoadWordDisp(rl_obj.reg, offset_offset, reg_off); - LoadWordDisp(rl_obj.reg, value_offset, reg_ptr); + Load32Disp(rl_obj.reg, offset_offset, reg_off); + Load32Disp(rl_obj.reg, value_offset, reg_ptr); } if (rl_idx.is_const) { OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg)); @@ -1128,7 +1146,7 @@ bool Mir2Lir::GenInlinedCharAt(CallInfo* info) { if (range_check) { DCHECK(range_check_branch != nullptr); info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked. - AddIntrinsicLaunchpad(info, range_check_branch); + AddIntrinsicSlowPath(info, range_check_branch); } return true; } @@ -1145,7 +1163,7 @@ bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) { RegLocation rl_dest = InlineTarget(info); RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); GenNullCheck(rl_obj.reg, info->opt_flags); - LoadWordDisp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg); + Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg); MarkPossibleNullPointerException(info->opt_flags); if (is_empty) { // dst = (dst == 0); @@ -1169,9 +1187,9 @@ bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) { return false; } RegLocation rl_src_i = info->args[0]; - RegLocation rl_dest = (size == kLong) ? InlineTargetWide(info) : InlineTarget(info); // result reg + RegLocation rl_dest = (size == k64) ? InlineTargetWide(info) : InlineTarget(info); // result reg RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); - if (size == kLong) { + if (size == k64) { RegLocation rl_i = LoadValueWide(rl_src_i, kCoreReg); RegStorage r_i_low = rl_i.reg.GetLow(); if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) { @@ -1186,8 +1204,8 @@ bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) { } StoreValueWide(rl_dest, rl_result); } else { - DCHECK(size == kWord || size == kSignedHalf); - OpKind op = (size == kWord) ? kOpRev : kOpRevsh; + DCHECK(size == k32 || size == kSignedHalf); + OpKind op = (size == k32) ? kOpRev : kOpRevsh; RegLocation rl_i = LoadValue(rl_src_i, kCoreReg); OpRegReg(op, rl_result.reg, rl_i.reg); StoreValue(rl_dest, rl_result); @@ -1339,7 +1357,7 @@ bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { DCHECK(high_code_point_branch != nullptr); LIR* resume_tgt = NewLIR0(kPseudoTargetLabel); info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked. - AddIntrinsicLaunchpad(info, high_code_point_branch, resume_tgt); + AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt); } else { DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0); DCHECK(high_code_point_branch == nullptr); @@ -1371,7 +1389,7 @@ bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) { info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked. // TUNING: check if rl_cmp.s_reg_low is already null checked LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr); - AddIntrinsicLaunchpad(info, cmp_null_check_branch); + AddIntrinsicSlowPath(info, cmp_null_check_branch); // NOTE: not a safepoint if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { OpReg(kOpBlx, r_tgt); @@ -1389,7 +1407,7 @@ bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) { RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); ThreadOffset<4> offset = Thread::PeerOffset<4>(); if (cu_->instruction_set == kThumb2 || cu_->instruction_set == kMips) { - LoadWordDisp(TargetReg(kSelf), offset.Int32Value(), rl_result.reg); + Load32Disp(TargetReg(kSelf), offset.Int32Value(), rl_result.reg); } else { CHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64); reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg.GetReg(), offset); @@ -1416,7 +1434,7 @@ bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info, if (is_long) { if (cu_->instruction_set == kX86) { LoadBaseIndexedDisp(rl_object.reg, rl_offset.reg, 0, 0, rl_result.reg.GetLow(), - rl_result.reg.GetHigh(), kLong, INVALID_SREG); + rl_result.reg.GetHigh(), k64, INVALID_SREG); } else { RegStorage rl_temp_offset = AllocTemp(); OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg); @@ -1424,7 +1442,7 @@ bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info, FreeTemp(rl_temp_offset.GetReg()); } } else { - LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, kWord); + LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32); } if (is_volatile) { @@ -1464,7 +1482,7 @@ bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long, rl_value = LoadValueWide(rl_src_value, kCoreReg); if (cu_->instruction_set == kX86) { StoreBaseIndexedDisp(rl_object.reg, rl_offset.reg, 0, 0, rl_value.reg.GetLow(), - rl_value.reg.GetHigh(), kLong, INVALID_SREG); + rl_value.reg.GetHigh(), k64, INVALID_SREG); } else { RegStorage rl_temp_offset = AllocTemp(); OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg); @@ -1473,7 +1491,7 @@ bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long, } } else { rl_value = LoadValue(rl_src_value, kCoreReg); - StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, kWord); + StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32); } // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard. diff --git a/compiler/dex/quick/gen_loadstore.cc b/compiler/dex/quick/gen_loadstore.cc index 208eadde12..9808f7f36f 100644 --- a/compiler/dex/quick/gen_loadstore.cc +++ b/compiler/dex/quick/gen_loadstore.cc @@ -65,7 +65,7 @@ void Mir2Lir::Workaround7250540(RegLocation rl_dest, RegStorage zero_reg) { OpRegCopy(RegStorage::Solo32(promotion_map_[pmap_index].core_reg), temp_reg); } else { // Lives in the frame, need to store. - StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), temp_reg, kWord); + StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), temp_reg, k32); } if (!zero_reg.Valid()) { FreeTemp(temp_reg); @@ -74,15 +74,6 @@ void Mir2Lir::Workaround7250540(RegLocation rl_dest, RegStorage zero_reg) { } } -/* Load a word at base + displacement. Displacement must be word multiple */ -LIR* Mir2Lir::LoadWordDisp(RegStorage r_base, int displacement, RegStorage r_dest) { - return LoadBaseDisp(r_base, displacement, r_dest, kWord, INVALID_SREG); -} - -LIR* Mir2Lir::StoreWordDisp(RegStorage r_base, int displacement, RegStorage r_src) { - return StoreBaseDisp(r_base, displacement, r_src, kWord); -} - /* * Load a Dalvik register into a physical register. Take care when * using this routine, as it doesn't perform any bookkeeping regarding @@ -93,11 +84,17 @@ void Mir2Lir::LoadValueDirect(RegLocation rl_src, RegStorage r_dest) { if (rl_src.location == kLocPhysReg) { OpRegCopy(r_dest, rl_src.reg); } else if (IsInexpensiveConstant(rl_src)) { + // On 64-bit targets, will sign extend. Make sure constant reference is always NULL. + DCHECK(!rl_src.ref || (mir_graph_->ConstantValue(rl_src) == 0)); LoadConstantNoClobber(r_dest, mir_graph_->ConstantValue(rl_src)); } else { DCHECK((rl_src.location == kLocDalvikFrame) || (rl_src.location == kLocCompilerTemp)); - LoadWordDisp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest); + if (rl_src.ref) { + LoadRefDisp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest); + } else { + Load32Disp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest); + } } } @@ -194,7 +191,7 @@ void Mir2Lir::StoreValue(RegLocation rl_dest, RegLocation rl_src) { ResetDefLoc(rl_dest); if (IsDirty(rl_dest.reg) && oat_live_out(rl_dest.s_reg_low)) { def_start = last_lir_insn_; - StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg, kWord); + Store32Disp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg); MarkClean(rl_dest); def_end = last_lir_insn_; if (!rl_dest.ref) { @@ -306,7 +303,7 @@ void Mir2Lir::StoreFinalValue(RegLocation rl_dest, RegLocation rl_src) { if (IsDirty(rl_dest.reg) && oat_live_out(rl_dest.s_reg_low)) { LIR *def_start = last_lir_insn_; - StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg, kWord); + Store32Disp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg); MarkClean(rl_dest); LIR *def_end = last_lir_insn_; if (!rl_dest.ref) { diff --git a/compiler/dex/quick/mips/call_mips.cc b/compiler/dex/quick/mips/call_mips.cc index a938478b3d..a237ac76b0 100644 --- a/compiler/dex/quick/mips/call_mips.cc +++ b/compiler/dex/quick/mips/call_mips.cc @@ -112,11 +112,11 @@ void MipsMir2Lir::GenSparseSwitch(MIR* mir, DexOffset table_offset, RegStorage r_key = AllocTemp(); LIR* loop_label = NewLIR0(kPseudoTargetLabel); LIR* exit_branch = OpCmpBranch(kCondEq, r_base, r_end, NULL); - LoadWordDisp(r_base, 0, r_key); + Load32Disp(r_base, 0, r_key); OpRegImm(kOpAdd, r_base, 8); OpCmpBranch(kCondNe, rl_src.reg, r_key, loop_label); RegStorage r_disp = AllocTemp(); - LoadWordDisp(r_base, -4, r_disp); + Load32Disp(r_base, -4, r_disp); OpRegRegReg(kOpAdd, rs_rRA, rs_rRA, r_disp); OpReg(kOpBx, rs_rRA); @@ -200,7 +200,7 @@ void MipsMir2Lir::GenPackedSwitch(MIR* mir, DexOffset table_offset, // Load the displacement from the switch table RegStorage r_disp = AllocTemp(); - LoadBaseIndexed(r_base, r_key, r_disp, 2, kWord); + LoadBaseIndexed(r_base, r_key, r_disp, 2, k32); // Add to rAP and go OpRegRegReg(kOpAdd, rs_rRA, rs_rRA, r_disp); @@ -263,9 +263,9 @@ void MipsMir2Lir::GenMoveException(RegLocation rl_dest) { int ex_offset = Thread::ExceptionOffset<4>().Int32Value(); RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); RegStorage reset_reg = AllocTemp(); - LoadWordDisp(rs_rMIPS_SELF, ex_offset, rl_result.reg); + Load32Disp(rs_rMIPS_SELF, ex_offset, rl_result.reg); LoadConstant(reset_reg, 0); - StoreWordDisp(rs_rMIPS_SELF, ex_offset, reset_reg); + Store32Disp(rs_rMIPS_SELF, ex_offset, reset_reg); FreeTemp(reset_reg); StoreValue(rl_dest, rl_result); } @@ -277,6 +277,7 @@ void MipsMir2Lir::MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg) { RegStorage reg_card_base = AllocTemp(); RegStorage reg_card_no = AllocTemp(); LIR* branch_over = OpCmpImmBranch(kCondEq, val_reg, 0, NULL); + // NOTE: native pointer. LoadWordDisp(rs_rMIPS_SELF, Thread::CardTableOffset<4>().Int32Value(), reg_card_base); OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift); StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte); @@ -310,7 +311,7 @@ void MipsMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) RegStorage new_sp = AllocTemp(); if (!skip_overflow_check) { /* Load stack limit */ - LoadWordDisp(rs_rMIPS_SELF, Thread::StackEndOffset<4>().Int32Value(), check_reg); + Load32Disp(rs_rMIPS_SELF, Thread::StackEndOffset<4>().Int32Value(), check_reg); } /* Spill core callee saves */ SpillCoreRegs(); @@ -328,7 +329,7 @@ void MipsMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) m2l_->ResetDefTracking(); GenerateTargetLabel(); // LR is offset 0 since we push in reverse order. - m2l_->LoadWordDisp(rs_rMIPS_SP, 0, rs_rRA); + m2l_->Load32Disp(rs_rMIPS_SP, 0, rs_rRA); m2l_->OpRegImm(kOpAdd, rs_rMIPS_SP, sp_displace_); m2l_->ClobberCallerSave(); ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pThrowStackOverflow); diff --git a/compiler/dex/quick/mips/codegen_mips.h b/compiler/dex/quick/mips/codegen_mips.h index 40641d670d..da65f3424f 100644 --- a/compiler/dex/quick/mips/codegen_mips.h +++ b/compiler/dex/quick/mips/codegen_mips.h @@ -126,8 +126,6 @@ class MipsMir2Lir FINAL : public Mir2Lir { RegLocation rl_src2); void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); - LIR* GenRegMemCheck(ConditionCode c_code, RegStorage reg1, RegStorage base, int offset, - ThrowKind kind); RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div); RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div); void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); diff --git a/compiler/dex/quick/mips/int_mips.cc b/compiler/dex/quick/mips/int_mips.cc index 60358b495c..88d5d2bc41 100644 --- a/compiler/dex/quick/mips/int_mips.cc +++ b/compiler/dex/quick/mips/int_mips.cc @@ -221,12 +221,6 @@ void MipsMir2Lir::GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) { UNIMPLEMENTED(FATAL) << "Need codegen for fused long cmp branch"; } -LIR* MipsMir2Lir::GenRegMemCheck(ConditionCode c_code, RegStorage reg1, RegStorage base, - int offset, ThrowKind kind) { - LOG(FATAL) << "Unexpected use of GenRegMemCheck for Arm"; - return NULL; -} - RegLocation MipsMir2Lir::GenDivRem(RegLocation rl_dest, RegStorage reg1, RegStorage reg2, bool is_div) { NewLIR2(kMipsDiv, reg1.GetReg(), reg2.GetReg()); @@ -480,7 +474,7 @@ void MipsMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, rl_array = LoadValue(rl_array, kCoreReg); rl_index = LoadValue(rl_index, kCoreReg); - if (size == kLong || size == kDouble) { + if (size == k64 || size == kDouble) { data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value(); } else { data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value(); @@ -495,12 +489,12 @@ void MipsMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, if (needs_range_check) { reg_len = AllocTemp(); /* Get len */ - LoadWordDisp(rl_array.reg, len_offset, reg_len); + Load32Disp(rl_array.reg, len_offset, reg_len); } /* reg_ptr -> array data */ OpRegRegImm(kOpAdd, reg_ptr, rl_array.reg, data_offset); FreeTemp(rl_array.reg.GetReg()); - if ((size == kLong) || (size == kDouble)) { + if ((size == k64) || (size == kDouble)) { if (scale) { RegStorage r_new_index = AllocTemp(); OpRegRegImm(kOpLsl, r_new_index, rl_index.reg, scale); @@ -513,7 +507,7 @@ void MipsMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, rl_result = EvalLoc(rl_dest, reg_class, true); if (needs_range_check) { - GenRegRegCheck(kCondUge, rl_index.reg, reg_len, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, reg_len); FreeTemp(reg_len); } LoadBaseDispWide(reg_ptr, 0, rl_result.reg, INVALID_SREG); @@ -524,7 +518,7 @@ void MipsMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, rl_result = EvalLoc(rl_dest, reg_class, true); if (needs_range_check) { - GenRegRegCheck(kCondUge, rl_index.reg, reg_len, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, reg_len); FreeTemp(reg_len); } LoadBaseIndexed(reg_ptr, rl_index.reg, rl_result.reg, scale, size); @@ -544,7 +538,7 @@ void MipsMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, int len_offset = mirror::Array::LengthOffset().Int32Value(); int data_offset; - if (size == kLong || size == kDouble) { + if (size == k64 || size == kDouble) { data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value(); } else { data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value(); @@ -572,12 +566,12 @@ void MipsMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, reg_len = AllocTemp(); // NOTE: max live temps(4) here. /* Get len */ - LoadWordDisp(rl_array.reg, len_offset, reg_len); + Load32Disp(rl_array.reg, len_offset, reg_len); } /* reg_ptr -> array data */ OpRegImm(kOpAdd, reg_ptr, data_offset); /* at this point, reg_ptr points to array, 2 live temps */ - if ((size == kLong) || (size == kDouble)) { + if ((size == k64) || (size == kDouble)) { // TUNING: specific wide routine that can handle fp regs if (scale) { RegStorage r_new_index = AllocTemp(); @@ -590,7 +584,7 @@ void MipsMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, rl_src = LoadValueWide(rl_src, reg_class); if (needs_range_check) { - GenRegRegCheck(kCondUge, rl_index.reg, reg_len, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, reg_len); FreeTemp(reg_len); } @@ -598,7 +592,7 @@ void MipsMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, } else { rl_src = LoadValue(rl_src, reg_class); if (needs_range_check) { - GenRegRegCheck(kCondUge, rl_index.reg, reg_len, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, reg_len); FreeTemp(reg_len); } StoreBaseIndexed(reg_ptr, rl_index.reg, rl_src.reg, scale, size); diff --git a/compiler/dex/quick/mips/target_mips.cc b/compiler/dex/quick/mips/target_mips.cc index 3e02faed55..7f4cd5e242 100644 --- a/compiler/dex/quick/mips/target_mips.cc +++ b/compiler/dex/quick/mips/target_mips.cc @@ -369,7 +369,7 @@ void MipsMir2Lir::FlushReg(RegStorage reg) { if (info->live && info->dirty) { info->dirty = false; int v_reg = mir_graph_->SRegToVReg(info->s_reg); - StoreBaseDisp(rs_rMIPS_SP, VRegOffset(v_reg), reg, kWord); + Store32Disp(rs_rMIPS_SP, VRegOffset(v_reg), reg); } } @@ -531,12 +531,14 @@ void MipsMir2Lir::FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free) { * there is a trap in the shadow. Allocate a temp register. */ RegStorage MipsMir2Lir::LoadHelper(ThreadOffset<4> offset) { + // NOTE: native pointer. LoadWordDisp(rs_rMIPS_SELF, offset.Int32Value(), rs_rT9); return rs_rT9; } LIR* MipsMir2Lir::CheckSuspendUsingLoad() { RegStorage tmp = AllocTemp(); + // NOTE: native pointer. LoadWordDisp(rs_rMIPS_SELF, Thread::ThreadSuspendTriggerOffset<4>().Int32Value(), tmp); LIR *inst = LoadWordDisp(tmp, 0, tmp); FreeTemp(tmp); @@ -553,7 +555,7 @@ void MipsMir2Lir::SpillCoreRegs() { for (int reg = 0; mask; mask >>= 1, reg++) { if (mask & 0x1) { offset -= 4; - StoreWordDisp(rs_rMIPS_SP, offset, RegStorage::Solo32(reg)); + Store32Disp(rs_rMIPS_SP, offset, RegStorage::Solo32(reg)); } } } @@ -567,7 +569,7 @@ void MipsMir2Lir::UnSpillCoreRegs() { for (int reg = 0; mask; mask >>= 1, reg++) { if (mask & 0x1) { offset -= 4; - LoadWordDisp(rs_rMIPS_SP, offset, RegStorage::Solo32(reg)); + Load32Disp(rs_rMIPS_SP, offset, RegStorage::Solo32(reg)); } } OpRegImm(kOpAdd, rs_rSP, frame_size_); diff --git a/compiler/dex/quick/mips/utility_mips.cc b/compiler/dex/quick/mips/utility_mips.cc index c959510025..12775e1a9e 100644 --- a/compiler/dex/quick/mips/utility_mips.cc +++ b/compiler/dex/quick/mips/utility_mips.cc @@ -357,11 +357,11 @@ LIR* MipsMir2Lir::LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStor if (MIPS_FPREG(r_dest.GetReg())) { DCHECK(MIPS_SINGLEREG(r_dest.GetReg())); - DCHECK((size == kWord) || (size == kSingle)); + DCHECK((size == k32) || (size == kSingle)); size = kSingle; } else { if (size == kSingle) - size = kWord; + size = k32; } if (!scale) { @@ -375,7 +375,8 @@ LIR* MipsMir2Lir::LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStor case kSingle: opcode = kMipsFlwc1; break; - case kWord: + case k32: + case kReference: opcode = kMipsLw; break; case kUnsignedHalf: @@ -408,11 +409,11 @@ LIR* MipsMir2Lir::StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegSto if (MIPS_FPREG(r_src.GetReg())) { DCHECK(MIPS_SINGLEREG(r_src.GetReg())); - DCHECK((size == kWord) || (size == kSingle)); + DCHECK((size == k32) || (size == kSingle)); size = kSingle; } else { if (size == kSingle) - size = kWord; + size = k32; } if (!scale) { @@ -426,7 +427,8 @@ LIR* MipsMir2Lir::StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegSto case kSingle: opcode = kMipsFswc1; break; - case kWord: + case k32: + case kReference: opcode = kMipsSw; break; case kUnsignedHalf: @@ -463,7 +465,7 @@ LIR* MipsMir2Lir::LoadBaseDispBody(RegStorage r_base, int displacement, RegStora bool pair = false; switch (size) { - case kLong: + case k64: case kDouble: pair = true; opcode = kMipsLw; @@ -481,8 +483,9 @@ LIR* MipsMir2Lir::LoadBaseDispBody(RegStorage r_base, int displacement, RegStora short_form = IS_SIMM16_2WORD(displacement); DCHECK_EQ((displacement & 0x3), 0); break; - case kWord: + case k32: case kSingle: + case kReference: opcode = kMipsLw; if (MIPS_FPREG(r_dest.GetReg())) { opcode = kMipsFlwc1; @@ -544,13 +547,17 @@ LIR* MipsMir2Lir::LoadBaseDispBody(RegStorage r_base, int displacement, RegStora LIR* MipsMir2Lir::LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size, int s_reg) { + // TODO: base this on target. + if (size == kWord) { + size = k32; + } return LoadBaseDispBody(r_base, displacement, r_dest, RegStorage::InvalidReg(), size, s_reg); } LIR* MipsMir2Lir::LoadBaseDispWide(RegStorage r_base, int displacement, RegStorage r_dest, int s_reg) { - return LoadBaseDispBody(r_base, displacement, r_dest.GetLow(), r_dest.GetHigh(), kLong, s_reg); + return LoadBaseDispBody(r_base, displacement, r_dest.GetLow(), r_dest.GetHigh(), k64, s_reg); } LIR* MipsMir2Lir::StoreBaseDispBody(RegStorage r_base, int displacement, @@ -563,7 +570,7 @@ LIR* MipsMir2Lir::StoreBaseDispBody(RegStorage r_base, int displacement, bool pair = false; switch (size) { - case kLong: + case k64: case kDouble: pair = true; opcode = kMipsSw; @@ -580,8 +587,9 @@ LIR* MipsMir2Lir::StoreBaseDispBody(RegStorage r_base, int displacement, short_form = IS_SIMM16_2WORD(displacement); DCHECK_EQ((displacement & 0x3), 0); break; - case kWord: + case k32: case kSingle: + case kReference: opcode = kMipsSw; if (MIPS_FPREG(r_src.GetReg())) { opcode = kMipsFswc1; @@ -635,11 +643,15 @@ LIR* MipsMir2Lir::StoreBaseDispBody(RegStorage r_base, int displacement, LIR* MipsMir2Lir::StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size) { + // TODO: base this on target. + if (size == kWord) { + size = k32; + } return StoreBaseDispBody(r_base, displacement, r_src, RegStorage::InvalidReg(), size); } LIR* MipsMir2Lir::StoreBaseDispWide(RegStorage r_base, int displacement, RegStorage r_src) { - return StoreBaseDispBody(r_base, displacement, r_src.GetLow(), r_src.GetHigh(), kLong); + return StoreBaseDispBody(r_base, displacement, r_src.GetLow(), r_src.GetHigh(), k64); } LIR* MipsMir2Lir::OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) { diff --git a/compiler/dex/quick/mir_to_lir.cc b/compiler/dex/quick/mir_to_lir.cc index 6fcdf70b12..6d3848841a 100644 --- a/compiler/dex/quick/mir_to_lir.cc +++ b/compiler/dex/quick/mir_to_lir.cc @@ -63,14 +63,14 @@ RegStorage Mir2Lir::LoadArg(int in_position, bool wide) { } else { reg_arg_high = AllocTemp(); int offset_high = offset + sizeof(uint32_t); - LoadWordDisp(TargetReg(kSp), offset_high, reg_arg_high); + Load32Disp(TargetReg(kSp), offset_high, reg_arg_high); } } // If the low part is not in a register yet, we need to load it. if (!reg_arg_low.Valid()) { reg_arg_low = AllocTemp(); - LoadWordDisp(TargetReg(kSp), offset, reg_arg_low); + Load32Disp(TargetReg(kSp), offset, reg_arg_low); } if (wide) { @@ -96,7 +96,7 @@ void Mir2Lir::LoadArgDirect(int in_position, RegLocation rl_dest) { if (reg.Valid()) { OpRegCopy(rl_dest.reg, reg); } else { - LoadWordDisp(TargetReg(kSp), offset, rl_dest.reg); + Load32Disp(TargetReg(kSp), offset, rl_dest.reg); } } else { RegStorage reg_arg_low = GetArgMappingToPhysicalReg(in_position); @@ -107,10 +107,10 @@ void Mir2Lir::LoadArgDirect(int in_position, RegLocation rl_dest) { } else if (reg_arg_low.Valid() && !reg_arg_high.Valid()) { OpRegCopy(rl_dest.reg, reg_arg_low); int offset_high = offset + sizeof(uint32_t); - LoadWordDisp(TargetReg(kSp), offset_high, rl_dest.reg.GetHigh()); + Load32Disp(TargetReg(kSp), offset_high, rl_dest.reg.GetHigh()); } else if (!reg_arg_low.Valid() && reg_arg_high.Valid()) { OpRegCopy(rl_dest.reg.GetHigh(), reg_arg_high); - LoadWordDisp(TargetReg(kSp), offset, rl_dest.reg.GetLow()); + Load32Disp(TargetReg(kSp), offset, rl_dest.reg.GetLow()); } else { LoadBaseDispWide(TargetReg(kSp), offset, rl_dest.reg, INVALID_SREG); } @@ -137,7 +137,7 @@ bool Mir2Lir::GenSpecialIGet(MIR* mir, const InlineMethod& special) { if (wide) { LoadBaseDispWide(reg_obj, data.field_offset, rl_dest.reg, INVALID_SREG); } else { - LoadWordDisp(reg_obj, data.field_offset, rl_dest.reg); + Load32Disp(reg_obj, data.field_offset, rl_dest.reg); } if (data.is_volatile) { // Without context sensitive analysis, we must issue the most conservative barriers. @@ -175,7 +175,7 @@ bool Mir2Lir::GenSpecialIPut(MIR* mir, const InlineMethod& special) { if (wide) { StoreBaseDispWide(reg_obj, data.field_offset, reg_src); } else { - StoreBaseDisp(reg_obj, data.field_offset, reg_src, kWord); + Store32Disp(reg_obj, data.field_offset, reg_src); } if (data.is_volatile) { // A load might follow the volatile store so insert a StoreLoad barrier. @@ -449,7 +449,7 @@ void Mir2Lir::CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list rl_src[0] = LoadValue(rl_src[0], kCoreReg); GenNullCheck(rl_src[0].reg, opt_flags); rl_result = EvalLoc(rl_dest, kCoreReg, true); - LoadWordDisp(rl_src[0].reg, len_offset, rl_result.reg); + Load32Disp(rl_src[0].reg, len_offset, rl_result.reg); MarkPossibleNullPointerException(opt_flags); StoreValue(rl_dest, rl_result); break; @@ -562,11 +562,13 @@ void Mir2Lir::CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list } case Instruction::AGET_WIDE: - GenArrayGet(opt_flags, kLong, rl_src[0], rl_src[1], rl_dest, 3); + GenArrayGet(opt_flags, k64, rl_src[0], rl_src[1], rl_dest, 3); break; - case Instruction::AGET: case Instruction::AGET_OBJECT: - GenArrayGet(opt_flags, kWord, rl_src[0], rl_src[1], rl_dest, 2); + GenArrayGet(opt_flags, kReference, rl_src[0], rl_src[1], rl_dest, 2); + break; + case Instruction::AGET: + GenArrayGet(opt_flags, k32, rl_src[0], rl_src[1], rl_dest, 2); break; case Instruction::AGET_BOOLEAN: GenArrayGet(opt_flags, kUnsignedByte, rl_src[0], rl_src[1], rl_dest, 0); @@ -581,10 +583,10 @@ void Mir2Lir::CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list GenArrayGet(opt_flags, kSignedHalf, rl_src[0], rl_src[1], rl_dest, 1); break; case Instruction::APUT_WIDE: - GenArrayPut(opt_flags, kLong, rl_src[1], rl_src[2], rl_src[0], 3, false); + GenArrayPut(opt_flags, k64, rl_src[1], rl_src[2], rl_src[0], 3, false); break; case Instruction::APUT: - GenArrayPut(opt_flags, kWord, rl_src[1], rl_src[2], rl_src[0], 2, false); + GenArrayPut(opt_flags, k32, rl_src[1], rl_src[2], rl_src[0], 2, false); break; case Instruction::APUT_OBJECT: { bool is_null = mir_graph_->IsConstantNullRef(rl_src[0]); @@ -597,7 +599,7 @@ void Mir2Lir::CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list if (is_null || is_safe) { // Store of constant null doesn't require an assignability test and can be generated inline // without fixed register usage or a card mark. - GenArrayPut(opt_flags, kWord, rl_src[1], rl_src[2], rl_src[0], 2, !is_null); + GenArrayPut(opt_flags, kReference, rl_src[1], rl_src[2], rl_src[0], 2, !is_null); } else { GenArrayObjPut(opt_flags, rl_src[1], rl_src[2], rl_src[0]); } @@ -613,15 +615,15 @@ void Mir2Lir::CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list break; case Instruction::IGET_OBJECT: - GenIGet(mir, opt_flags, kWord, rl_dest, rl_src[0], false, true); + GenIGet(mir, opt_flags, kReference, rl_dest, rl_src[0], false, true); break; case Instruction::IGET_WIDE: - GenIGet(mir, opt_flags, kLong, rl_dest, rl_src[0], true, false); + GenIGet(mir, opt_flags, k64, rl_dest, rl_src[0], true, false); break; case Instruction::IGET: - GenIGet(mir, opt_flags, kWord, rl_dest, rl_src[0], false, false); + GenIGet(mir, opt_flags, k32, rl_dest, rl_src[0], false, false); break; case Instruction::IGET_CHAR: @@ -638,15 +640,15 @@ void Mir2Lir::CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list break; case Instruction::IPUT_WIDE: - GenIPut(mir, opt_flags, kLong, rl_src[0], rl_src[1], true, false); + GenIPut(mir, opt_flags, k64, rl_src[0], rl_src[1], true, false); break; case Instruction::IPUT_OBJECT: - GenIPut(mir, opt_flags, kWord, rl_src[0], rl_src[1], false, true); + GenIPut(mir, opt_flags, kReference, rl_src[0], rl_src[1], false, true); break; case Instruction::IPUT: - GenIPut(mir, opt_flags, kWord, rl_src[0], rl_src[1], false, false); + GenIPut(mir, opt_flags, k32, rl_src[0], rl_src[1], false, false); break; case Instruction::IPUT_BOOLEAN: @@ -1097,8 +1099,6 @@ void Mir2Lir::MethodMIR2LIR() { cu_->NewTimingSplit("Launchpads"); HandleSuspendLaunchPads(); - - HandleThrowLaunchPads(); } // diff --git a/compiler/dex/quick/mir_to_lir.h b/compiler/dex/quick/mir_to_lir.h index 65910e9eb8..8d593ae664 100644 --- a/compiler/dex/quick/mir_to_lir.h +++ b/compiler/dex/quick/mir_to_lir.h @@ -109,6 +109,11 @@ typedef uint32_t CodeOffset; // Native code offset in bytes. #define REG_USE23 (REG_USE2 | REG_USE3) #define REG_USE123 (REG_USE1 | REG_USE2 | REG_USE3) +// TODO: #includes need a cleanup +#ifndef INVALID_SREG +#define INVALID_SREG (-1) +#endif + struct BasicBlock; struct CallInfo; struct CompilationUnit; @@ -554,12 +559,11 @@ class Mir2Lir : public Backend { RegisterInfo* GetRegInfo(int reg); // Shared by all targets - implemented in gen_common.cc. - void AddIntrinsicLaunchpad(CallInfo* info, LIR* branch, LIR* resume = nullptr); + void AddIntrinsicSlowPath(CallInfo* info, LIR* branch, LIR* resume = nullptr); bool HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div, RegLocation rl_src, RegLocation rl_dest, int lit); bool HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit); void HandleSuspendLaunchPads(); - void HandleThrowLaunchPads(); void HandleSlowPaths(); void GenBarrier(); void GenDivZeroException(); @@ -567,6 +571,8 @@ class Mir2Lir : public Backend { void GenDivZeroCheck(ConditionCode c_code); // reg holds divisor. void GenDivZeroCheck(RegStorage reg); + void GenArrayBoundsCheck(RegStorage index, RegStorage length); + void GenArrayBoundsCheck(int32_t index, RegStorage length); LIR* GenNullCheck(RegStorage reg); void MarkPossibleNullPointerException(int opt_flags); void MarkPossibleStackOverflowException(); @@ -574,7 +580,6 @@ class Mir2Lir : public Backend { LIR* GenImmedCheck(ConditionCode c_code, RegStorage reg, int imm_val, ThrowKind kind); LIR* GenNullCheck(RegStorage m_reg, int opt_flags); LIR* GenExplicitNullCheck(RegStorage m_reg, int opt_flags); - LIR* GenRegRegCheck(ConditionCode c_code, RegStorage reg1, RegStorage reg2, ThrowKind kind); void GenCompareAndBranch(Instruction::Code opcode, RegLocation rl_src1, RegLocation rl_src2, LIR* taken, LIR* fall_through); void GenCompareZeroAndBranch(Instruction::Code opcode, RegLocation rl_src, @@ -723,14 +728,42 @@ class Mir2Lir : public Backend { RegLocation LoadCurrMethod(); void LoadCurrMethodDirect(RegStorage r_tgt); LIR* LoadConstant(RegStorage r_dest, int value); - LIR* LoadWordDisp(RegStorage r_base, int displacement, RegStorage r_dest); + // Natural word size. + LIR* LoadWordDisp(RegStorage r_base, int displacement, RegStorage r_dest) { + return LoadBaseDisp(r_base, displacement, r_dest, kWord, INVALID_SREG); + } + // Load 32 bits, regardless of target. + LIR* Load32Disp(RegStorage r_base, int displacement, RegStorage r_dest) { + return LoadBaseDisp(r_base, displacement, r_dest, k32, INVALID_SREG); + } + // Load a reference at base + displacement and decompress into register. + LIR* LoadRefDisp(RegStorage r_base, int displacement, RegStorage r_dest) { + return LoadBaseDisp(r_base, displacement, r_dest, kReference, INVALID_SREG); + } + // Load Dalvik value with 32-bit memory storage. If compressed object reference, decompress. RegLocation LoadValue(RegLocation rl_src, RegisterClass op_kind); + // Load Dalvik value with 64-bit memory storage. RegLocation LoadValueWide(RegLocation rl_src, RegisterClass op_kind); + // Load Dalvik value with 32-bit memory storage. If compressed object reference, decompress. void LoadValueDirect(RegLocation rl_src, RegStorage r_dest); + // Load Dalvik value with 32-bit memory storage. If compressed object reference, decompress. void LoadValueDirectFixed(RegLocation rl_src, RegStorage r_dest); + // Load Dalvik value with 64-bit memory storage. void LoadValueDirectWide(RegLocation rl_src, RegStorage r_dest); + // Load Dalvik value with 64-bit memory storage. void LoadValueDirectWideFixed(RegLocation rl_src, RegStorage r_dest); - LIR* StoreWordDisp(RegStorage r_base, int displacement, RegStorage r_src); + // Store an item of natural word size. + LIR* StoreWordDisp(RegStorage r_base, int displacement, RegStorage r_src) { + return StoreBaseDisp(r_base, displacement, r_src, kWord); + } + // Store an uncompressed reference into a compressed 32-bit container. + LIR* StoreRefDisp(RegStorage r_base, int displacement, RegStorage r_src) { + return StoreBaseDisp(r_base, displacement, r_src, kReference); + } + // Store 32 bits, regardless of target. + LIR* Store32Disp(RegStorage r_base, int displacement, RegStorage r_src) { + return StoreBaseDisp(r_base, displacement, r_src, k32); + } /** * @brief Used to do the final store in the destination as per bytecode semantics. @@ -933,8 +966,6 @@ class Mir2Lir : public Backend { RegLocation rl_src2) = 0; virtual void GenXorLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) = 0; - virtual LIR* GenRegMemCheck(ConditionCode c_code, RegStorage reg1, RegStorage base, - int offset, ThrowKind kind) = 0; virtual RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div) = 0; virtual RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, @@ -1227,6 +1258,10 @@ class Mir2Lir : public Backend { void AddDivZeroCheckSlowPath(LIR* branch); + // Copy arg0 and arg1 to kArg0 and kArg1 safely, possibly using + // kArg2 as temp. + void CopyToArgumentRegs(RegStorage arg0, RegStorage arg1); + public: // TODO: add accessors for these. LIR* literal_list_; // Constants. @@ -1240,7 +1275,6 @@ class Mir2Lir : public Backend { MIRGraph* const mir_graph_; GrowableArray<SwitchTable*> switch_tables_; GrowableArray<FillArrayData*> fill_array_data_; - GrowableArray<LIR*> throw_launchpads_; GrowableArray<LIR*> suspend_launchpads_; GrowableArray<RegisterInfo*> tempreg_info_; GrowableArray<RegisterInfo*> reginfo_map_; diff --git a/compiler/dex/quick/x86/call_x86.cc b/compiler/dex/quick/x86/call_x86.cc index 729b30d621..00831099fc 100644 --- a/compiler/dex/quick/x86/call_x86.cc +++ b/compiler/dex/quick/x86/call_x86.cc @@ -239,7 +239,7 @@ void X86Mir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { // mov esp, ebp // in case a signal comes in that's not using an alternate signal stack and the large frame may // have moved us outside of the reserved area at the end of the stack. - // cmp rX86_SP, fs:[stack_end_]; jcc throw_launchpad + // cmp rX86_SP, fs:[stack_end_]; jcc throw_slowpath OpRegThreadMem(kOpCmp, rX86_SP, Thread::StackEndOffset<4>()); LIR* branch = OpCondBranch(kCondUlt, nullptr); AddSlowPath(new(arena_)StackOverflowSlowPath(this, branch, frame_size_ - 4)); @@ -251,7 +251,8 @@ void X86Mir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { // We have been asked to save the address of the method start for later use. setup_method_address_[0] = NewLIR1(kX86StartOfMethod, rX86_ARG0); int displacement = SRegOffset(base_of_code_->s_reg_low); - setup_method_address_[1] = StoreBaseDisp(rs_rX86_SP, displacement, rs_rX86_ARG0, kWord); + // Native pointer - must be natural word size. + setup_method_address_[1] = StoreWordDisp(rs_rX86_SP, displacement, rs_rX86_ARG0); } FreeTemp(rX86_ARG0); diff --git a/compiler/dex/quick/x86/codegen_x86.h b/compiler/dex/quick/x86/codegen_x86.h index 0b9823d667..fb61627c9e 100644 --- a/compiler/dex/quick/x86/codegen_x86.h +++ b/compiler/dex/quick/x86/codegen_x86.h @@ -127,15 +127,13 @@ class X86Mir2Lir FINAL : public Mir2Lir { RegLocation rl_src2); void GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); - LIR* GenRegMemCheck(ConditionCode c_code, RegStorage reg1, RegStorage base, int offset, - ThrowKind kind); - LIR* GenMemImmedCheck(ConditionCode c_code, RegStorage base, int offset, int check_value, - ThrowKind kind); // TODO: collapse reg_lo, reg_hi RegLocation GenDivRem(RegLocation rl_dest, RegStorage reg_lo, RegStorage reg_hi, bool is_div); RegLocation GenDivRemLit(RegLocation rl_dest, RegStorage reg_lo, int lit, bool is_div); void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2); void GenDivZeroCheckWide(RegStorage reg); + void GenArrayBoundsCheck(RegStorage index, RegStorage array_base, int32_t len_offset); + void GenArrayBoundsCheck(int32_t index, RegStorage array_base, int32_t len_offset); void GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method); void GenExitSequence(); void GenSpecialExitSequence(); diff --git a/compiler/dex/quick/x86/fp_x86.cc b/compiler/dex/quick/x86/fp_x86.cc index ee5387f050..f7b0c9d892 100644 --- a/compiler/dex/quick/x86/fp_x86.cc +++ b/compiler/dex/quick/x86/fp_x86.cc @@ -193,7 +193,7 @@ void X86Mir2Lir::GenLongToFP(RegLocation rl_dest, RegLocation rl_src, bool is_do } else { rl_result = EvalLoc(rl_dest, kFPReg, true); - LoadWordDisp(TargetReg(kSp), dest_v_reg_offset, rl_result.reg); + Load32Disp(TargetReg(kSp), dest_v_reg_offset, rl_result.reg); StoreFinalValue(rl_dest, rl_result); } diff --git a/compiler/dex/quick/x86/int_x86.cc b/compiler/dex/quick/x86/int_x86.cc index 4ffb9a4c38..5ba9709187 100644 --- a/compiler/dex/quick/x86/int_x86.cc +++ b/compiler/dex/quick/x86/int_x86.cc @@ -24,34 +24,6 @@ namespace art { /* - * Perform register memory operation. - */ -LIR* X86Mir2Lir::GenRegMemCheck(ConditionCode c_code, RegStorage reg1, RegStorage base, - int offset, ThrowKind kind) { - LIR* tgt = RawLIR(0, kPseudoThrowTarget, kind, - current_dalvik_offset_, reg1.GetReg(), base.GetReg(), offset); - OpRegMem(kOpCmp, reg1, base, offset); - LIR* branch = OpCondBranch(c_code, tgt); - // Remember branch target - will process later - throw_launchpads_.Insert(tgt); - return branch; -} - -/* - * Perform a compare of memory to immediate value - */ -LIR* X86Mir2Lir::GenMemImmedCheck(ConditionCode c_code, RegStorage base, int offset, - int check_value, ThrowKind kind) { - LIR* tgt = RawLIR(0, kPseudoThrowTarget, kind, - current_dalvik_offset_, base.GetReg(), check_value, 0); - NewLIR3(IS_SIMM8(check_value) ? kX86Cmp32MI8 : kX86Cmp32MI, base.GetReg(), offset, check_value); - LIR* branch = OpCondBranch(c_code, tgt); - // Remember branch target - will process later - throw_launchpads_.Insert(tgt); - return branch; -} - -/* * Compare two 64-bit values * x = y return 0 * x < y return -1 @@ -704,15 +676,15 @@ bool X86Mir2Lir::GenInlinedMinMaxInt(CallInfo* info, bool is_min) { bool X86Mir2Lir::GenInlinedPeek(CallInfo* info, OpSize size) { RegLocation rl_src_address = info->args[0]; // long address rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1] - RegLocation rl_dest = size == kLong ? InlineTargetWide(info) : InlineTarget(info); + RegLocation rl_dest = size == k64 ? InlineTargetWide(info) : InlineTarget(info); RegLocation rl_address = LoadValue(rl_src_address, kCoreReg); RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); - if (size == kLong) { + if (size == k64) { // Unaligned access is allowed on x86. LoadBaseDispWide(rl_address.reg, 0, rl_result.reg, INVALID_SREG); StoreValueWide(rl_dest, rl_result); } else { - DCHECK(size == kSignedByte || size == kSignedHalf || size == kWord); + DCHECK(size == kSignedByte || size == kSignedHalf || size == k32); // Unaligned access is allowed on x86. LoadBaseDisp(rl_address.reg, 0, rl_result.reg, size, INVALID_SREG); StoreValue(rl_dest, rl_result); @@ -725,12 +697,12 @@ bool X86Mir2Lir::GenInlinedPoke(CallInfo* info, OpSize size) { rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1] RegLocation rl_src_value = info->args[2]; // [size] value RegLocation rl_address = LoadValue(rl_src_address, kCoreReg); - if (size == kLong) { + if (size == k64) { // Unaligned access is allowed on x86. RegLocation rl_value = LoadValueWide(rl_src_value, kCoreReg); StoreBaseDispWide(rl_address.reg, 0, rl_value.reg); } else { - DCHECK(size == kSignedByte || size == kSignedHalf || size == kWord); + DCHECK(size == kSignedByte || size == kSignedHalf || size == k32); // Unaligned access is allowed on x86. RegLocation rl_value = LoadValue(rl_src_value, kCoreReg); StoreBaseDisp(rl_address.reg, 0, rl_value.reg, size); @@ -780,6 +752,7 @@ bool X86Mir2Lir::GenInlinedCas(CallInfo* info, bool is_long, bool is_object) { int srcObjSp = IsInReg(this, rl_src_obj, rs_rSI) ? 0 : (IsInReg(this, rl_src_obj, rs_rDI) ? 4 : (SRegOffset(rl_src_obj.s_reg_low) + push_offset)); + // FIXME: needs 64-bit update. LoadWordDisp(TargetReg(kSp), srcObjSp, rs_rDI); int srcOffsetSp = IsInReg(this, rl_src_offset, rs_rSI) ? 0 : (IsInReg(this, rl_src_offset, rs_rDI) ? 4 @@ -891,6 +864,86 @@ void X86Mir2Lir::GenDivZeroCheckWide(RegStorage reg) { FreeTemp(t_reg); } +void X86Mir2Lir::GenArrayBoundsCheck(RegStorage index, + RegStorage array_base, + int len_offset) { + class ArrayBoundsCheckSlowPath : public Mir2Lir::LIRSlowPath { + public: + ArrayBoundsCheckSlowPath(Mir2Lir* m2l, LIR* branch, + RegStorage index, RegStorage array_base, int32_t len_offset) + : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch), + index_(index), array_base_(array_base), len_offset_(len_offset) { + } + + void Compile() OVERRIDE { + m2l_->ResetRegPool(); + m2l_->ResetDefTracking(); + GenerateTargetLabel(); + + RegStorage new_index = index_; + // Move index out of kArg1, either directly to kArg0, or to kArg2. + if (index_.GetReg() == m2l_->TargetReg(kArg1).GetReg()) { + if (array_base_.GetReg() == m2l_->TargetReg(kArg0).GetReg()) { + m2l_->OpRegCopy(m2l_->TargetReg(kArg2), index_); + new_index = m2l_->TargetReg(kArg2); + } else { + m2l_->OpRegCopy(m2l_->TargetReg(kArg0), index_); + new_index = m2l_->TargetReg(kArg0); + } + } + // Load array length to kArg1. + m2l_->OpRegMem(kOpMov, m2l_->TargetReg(kArg1), array_base_, len_offset_); + m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pThrowArrayBounds), + new_index, m2l_->TargetReg(kArg1), true); + } + + private: + const RegStorage index_; + const RegStorage array_base_; + const int32_t len_offset_; + }; + + OpRegMem(kOpCmp, index, array_base, len_offset); + LIR* branch = OpCondBranch(kCondUge, nullptr); + AddSlowPath(new (arena_) ArrayBoundsCheckSlowPath(this, branch, + index, array_base, len_offset)); +} + +void X86Mir2Lir::GenArrayBoundsCheck(int32_t index, + RegStorage array_base, + int32_t len_offset) { + class ArrayBoundsCheckSlowPath : public Mir2Lir::LIRSlowPath { + public: + ArrayBoundsCheckSlowPath(Mir2Lir* m2l, LIR* branch, + int32_t index, RegStorage array_base, int32_t len_offset) + : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch), + index_(index), array_base_(array_base), len_offset_(len_offset) { + } + + void Compile() OVERRIDE { + m2l_->ResetRegPool(); + m2l_->ResetDefTracking(); + GenerateTargetLabel(); + + // Load array length to kArg1. + m2l_->OpRegMem(kOpMov, m2l_->TargetReg(kArg1), array_base_, len_offset_); + m2l_->LoadConstant(m2l_->TargetReg(kArg0), index_); + m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pThrowArrayBounds), + m2l_->TargetReg(kArg0), m2l_->TargetReg(kArg1), true); + } + + private: + const int32_t index_; + const RegStorage array_base_; + const int32_t len_offset_; + }; + + NewLIR3(IS_SIMM8(index) ? kX86Cmp32MI8 : kX86Cmp32MI, array_base.GetReg(), len_offset, index); + LIR* branch = OpCondBranch(kCondLs, nullptr); + AddSlowPath(new (arena_) ArrayBoundsCheckSlowPath(this, branch, + index, array_base, len_offset)); +} + // Test suspend flag, return target of taken suspend branch LIR* X86Mir2Lir::OpTestSuspend(LIR* target) { OpTlsCmp(Thread::ThreadFlagsOffset<4>(), 0); @@ -944,7 +997,7 @@ void X86Mir2Lir::GenImulMemImm(RegStorage dest, int sreg, int displacement, int NewLIR2(kX86Xor32RR, dest.GetReg(), dest.GetReg()); break; case 1: - LoadBaseDisp(rs_rX86_SP, displacement, dest, kWord, sreg); + LoadBaseDisp(rs_rX86_SP, displacement, dest, k32, sreg); break; default: m = NewLIR4(IS_SIMM8(val) ? kX86Imul32RMI8 : kX86Imul32RMI, dest.GetReg(), rX86_SP, @@ -1050,7 +1103,7 @@ void X86Mir2Lir::GenMulLong(Instruction::Code, RegLocation rl_dest, RegLocation NewLIR2(kX86Mov32RR, r1, rl_src1.reg.GetHighReg()); } else { LoadBaseDisp(rs_rX86_SP, SRegOffset(rl_src1.s_reg_low) + HIWORD_OFFSET, rs_r1, - kWord, GetSRegHi(rl_src1.s_reg_low)); + k32, GetSRegHi(rl_src1.s_reg_low)); } if (is_square) { @@ -1073,7 +1126,7 @@ void X86Mir2Lir::GenMulLong(Instruction::Code, RegLocation rl_dest, RegLocation NewLIR2(kX86Mov32RR, r0, rl_src2.reg.GetHighReg()); } else { LoadBaseDisp(rs_rX86_SP, SRegOffset(rl_src2.s_reg_low) + HIWORD_OFFSET, rs_r0, - kWord, GetSRegHi(rl_src2.s_reg_low)); + k32, GetSRegHi(rl_src2.s_reg_low)); } // EAX <- EAX * 1L (2H * 1L) @@ -1105,7 +1158,7 @@ void X86Mir2Lir::GenMulLong(Instruction::Code, RegLocation rl_dest, RegLocation NewLIR2(kX86Mov32RR, r0, rl_src2.reg.GetLowReg()); } else { LoadBaseDisp(rs_rX86_SP, SRegOffset(rl_src2.s_reg_low) + LOWORD_OFFSET, rs_r0, - kWord, rl_src2.s_reg_low); + k32, rl_src2.s_reg_low); } // EDX:EAX <- 2L * 1L (double precision) @@ -1325,7 +1378,7 @@ void X86Mir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, rl_array = LoadValue(rl_array, kCoreReg); int data_offset; - if (size == kLong || size == kDouble) { + if (size == k64 || size == kDouble) { data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value(); } else { data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value(); @@ -1348,14 +1401,13 @@ void X86Mir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, if (!(opt_flags & MIR_IGNORE_RANGE_CHECK)) { if (constant_index) { - GenMemImmedCheck(kCondLs, rl_array.reg, len_offset, - constant_index_value, kThrowConstantArrayBounds); + GenArrayBoundsCheck(constant_index_value, rl_array.reg, len_offset); } else { - GenRegMemCheck(kCondUge, rl_index.reg, rl_array.reg, len_offset, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, rl_array.reg, len_offset); } } rl_result = EvalLoc(rl_dest, reg_class, true); - if ((size == kLong) || (size == kDouble)) { + if ((size == k64) || (size == kDouble)) { LoadBaseIndexedDisp(rl_array.reg, rl_index.reg, scale, data_offset, rl_result.reg.GetLow(), rl_result.reg.GetHigh(), size, INVALID_SREG); StoreValueWide(rl_dest, rl_result); @@ -1376,7 +1428,7 @@ void X86Mir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, int len_offset = mirror::Array::LengthOffset().Int32Value(); int data_offset; - if (size == kLong || size == kDouble) { + if (size == k64 || size == kDouble) { data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value(); } else { data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value(); @@ -1400,13 +1452,12 @@ void X86Mir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, if (!(opt_flags & MIR_IGNORE_RANGE_CHECK)) { if (constant_index) { - GenMemImmedCheck(kCondLs, rl_array.reg, len_offset, - constant_index_value, kThrowConstantArrayBounds); + GenArrayBoundsCheck(constant_index_value, rl_array.reg, len_offset); } else { - GenRegMemCheck(kCondUge, rl_index.reg, rl_array.reg, len_offset, kThrowArrayBounds); + GenArrayBoundsCheck(rl_index.reg, rl_array.reg, len_offset); } } - if ((size == kLong) || (size == kDouble)) { + if ((size == k64) || (size == kDouble)) { rl_src = LoadValueWide(rl_src, reg_class); } else { rl_src = LoadValue(rl_src, reg_class); @@ -1793,22 +1844,22 @@ void X86Mir2Lir::GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, if (rl_method.location == kLocPhysReg) { if (use_declaring_class) { - LoadWordDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), + LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), check_class); } else { - LoadWordDisp(rl_method.reg, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), + LoadRefDisp(rl_method.reg, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), check_class); - LoadWordDisp(check_class, offset_of_type, check_class); + LoadRefDisp(check_class, offset_of_type, check_class); } } else { LoadCurrMethodDirect(check_class); if (use_declaring_class) { - LoadWordDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), + LoadRefDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), check_class); } else { - LoadWordDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), + LoadRefDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), check_class); - LoadWordDisp(check_class, offset_of_type, check_class); + LoadRefDisp(check_class, offset_of_type, check_class); } } @@ -1849,17 +1900,17 @@ void X86Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_k LoadValueDirectFixed(rl_src, TargetReg(kArg0)); } else if (use_declaring_class) { LoadValueDirectFixed(rl_src, TargetReg(kArg0)); - LoadWordDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), + LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), class_reg); } else { // Load dex cache entry into class_reg (kArg2). LoadValueDirectFixed(rl_src, TargetReg(kArg0)); - LoadWordDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), + LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), class_reg); int32_t offset_of_type = mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*) * type_idx); - LoadWordDisp(class_reg, offset_of_type, class_reg); + LoadRefDisp(class_reg, offset_of_type, class_reg); if (!can_assume_type_is_in_dex_cache) { // Need to test presence of type in dex cache at runtime. LIR* hop_branch = OpCmpImmBranch(kCondNe, class_reg, 0, NULL); @@ -1883,7 +1934,7 @@ void X86Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_k /* Load object->klass_. */ DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0); - LoadWordDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); + LoadRefDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); /* kArg0 is ref, kArg1 is ref->klass_, kArg2 is class. */ LIR* branchover = nullptr; if (type_known_final) { @@ -2056,6 +2107,8 @@ void X86Mir2Lir::GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, // Can we do this directly into memory? rl_result = UpdateLoc(rl_dest); if (rl_result.location == kLocPhysReg) { + // Ensure res is in a core reg + rl_result = EvalLoc(rl_dest, kCoreReg, true); // Can we do this from memory directly? rl_rhs = UpdateLoc(rl_rhs); if (rl_rhs.location != kLocPhysReg) { diff --git a/compiler/dex/quick/x86/target_x86.cc b/compiler/dex/quick/x86/target_x86.cc index 5a8ad7a2b4..3e3fa72150 100644 --- a/compiler/dex/quick/x86/target_x86.cc +++ b/compiler/dex/quick/x86/target_x86.cc @@ -369,12 +369,13 @@ void X86Mir2Lir::FlushRegWide(RegStorage reg) { } void X86Mir2Lir::FlushReg(RegStorage reg) { + // FIXME: need to handle 32 bits in 64-bit register as well as wide values held in single reg. DCHECK(!reg.IsPair()); RegisterInfo* info = GetRegInfo(reg.GetReg()); if (info->live && info->dirty) { info->dirty = false; int v_reg = mir_graph_->SRegToVReg(info->s_reg); - StoreBaseDisp(rs_rX86_SP, VRegOffset(v_reg), reg, kWord); + StoreBaseDisp(rs_rX86_SP, VRegOffset(v_reg), reg, k32); } } @@ -1033,14 +1034,14 @@ bool X86Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked. // Does the character fit in 16 bits? - LIR* launchpad_branch = nullptr; + LIR* slowpath_branch = nullptr; if (rl_char.is_const) { // We need the value in EAX. LoadConstantNoClobber(rs_rAX, char_value); } else { // Character is not a constant; compare at runtime. LoadValueDirectFixed(rl_char, rs_rAX); - launchpad_branch = OpCmpImmBranch(kCondGt, rs_rAX, 0xFFFF, nullptr); + slowpath_branch = OpCmpImmBranch(kCondGt, rs_rAX, 0xFFFF, nullptr); } // From here down, we know that we are looking for a char that fits in 16 bits. @@ -1061,7 +1062,7 @@ bool X86Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { NewLIR1(kX86Push32R, rDI); // Compute the number of words to search in to rCX. - LoadWordDisp(rs_rDX, count_offset, rs_rCX); + Load32Disp(rs_rDX, count_offset, rs_rCX); LIR *length_compare = nullptr; int start_value = 0; bool is_index_on_stack = false; @@ -1101,7 +1102,7 @@ bool X86Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { } else { // Load the start index from stack, remembering that we pushed EDI. int displacement = SRegOffset(rl_start.s_reg_low) + sizeof(uint32_t); - LoadWordDisp(rs_rX86_SP, displacement, rs_rBX); + Load32Disp(rs_rX86_SP, displacement, rs_rBX); OpRegReg(kOpXor, rs_rDI, rs_rDI); OpRegReg(kOpCmp, rs_rBX, rs_rDI); OpCondRegReg(kOpCmov, kCondLt, rs_rBX, rs_rDI); @@ -1120,8 +1121,8 @@ bool X86Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { // Load the address of the string into EBX. // The string starts at VALUE(String) + 2 * OFFSET(String) + DATA_OFFSET. - LoadWordDisp(rs_rDX, value_offset, rs_rDI); - LoadWordDisp(rs_rDX, offset_offset, rs_rBX); + Load32Disp(rs_rDX, value_offset, rs_rDI); + Load32Disp(rs_rDX, offset_offset, rs_rBX); OpLea(rs_rBX, rs_rDI, rs_rBX, 1, data_offset); // Now compute into EDI where the search will start. @@ -1167,9 +1168,9 @@ bool X86Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { NewLIR1(kX86Pop32R, rDI); // Out of line code returns here. - if (launchpad_branch != nullptr) { + if (slowpath_branch != nullptr) { LIR *return_point = NewLIR0(kPseudoTargetLabel); - AddIntrinsicLaunchpad(info, launchpad_branch, return_point); + AddIntrinsicSlowPath(info, slowpath_branch, return_point); } StoreValue(rl_dest, rl_return); diff --git a/compiler/dex/quick/x86/utility_x86.cc b/compiler/dex/quick/x86/utility_x86.cc index e9faa7ff53..00bebd2983 100644 --- a/compiler/dex/quick/x86/utility_x86.cc +++ b/compiler/dex/quick/x86/utility_x86.cc @@ -554,7 +554,7 @@ LIR* X86Mir2Lir::LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int bool is64bit = false; X86OpCode opcode = kX86Nop; switch (size) { - case kLong: + case k64: case kDouble: // TODO: use regstorage attributes here. is64bit = true; @@ -567,8 +567,9 @@ LIR* X86Mir2Lir::LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int // TODO: double store is to unaligned address DCHECK_EQ((displacement & 0x3), 0); break; - case kWord: + case k32: case kSingle: + case kReference: // TODO: update for reference decompression on 64-bit targets. opcode = is_array ? kX86Mov32RA : kX86Mov32RM; if (X86_FPREG(r_dest.GetReg())) { opcode = is_array ? kX86MovssRA : kX86MovssRM; @@ -669,6 +670,10 @@ LIR* X86Mir2Lir::LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStora LIR* X86Mir2Lir::LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, OpSize size, int s_reg) { + // TODO: base this on target. + if (size == kWord) { + size = k32; + } return LoadBaseIndexedDisp(r_base, RegStorage::InvalidReg(), 0, displacement, r_dest, RegStorage::InvalidReg(), size, s_reg); } @@ -676,7 +681,7 @@ LIR* X86Mir2Lir::LoadBaseDisp(RegStorage r_base, int displacement, LIR* X86Mir2Lir::LoadBaseDispWide(RegStorage r_base, int displacement, RegStorage r_dest, int s_reg) { return LoadBaseIndexedDisp(r_base, RegStorage::InvalidReg(), 0, displacement, - r_dest.GetLow(), r_dest.GetHigh(), kLong, s_reg); + r_dest.GetLow(), r_dest.GetHigh(), k64, s_reg); } LIR* X86Mir2Lir::StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, @@ -690,7 +695,7 @@ LIR* X86Mir2Lir::StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int bool is64bit = false; X86OpCode opcode = kX86Nop; switch (size) { - case kLong: + case k64: case kDouble: is64bit = true; if (X86_FPREG(r_src.GetReg())) { @@ -702,8 +707,9 @@ LIR* X86Mir2Lir::StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int // TODO: double store is to unaligned address DCHECK_EQ((displacement & 0x3), 0); break; - case kWord: + case k32: case kSingle: + case kReference: opcode = is_array ? kX86Mov32AR : kX86Mov32MR; if (X86_FPREG(r_src.GetReg())) { opcode = is_array ? kX86MovssAR : kX86MovssMR; @@ -763,13 +769,17 @@ LIR* X86Mir2Lir::StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStor LIR* X86Mir2Lir::StoreBaseDisp(RegStorage r_base, int displacement, RegStorage r_src, OpSize size) { - return StoreBaseIndexedDisp(r_base, RegStorage::InvalidReg(), 0, displacement, r_src, - RegStorage::InvalidReg(), size, INVALID_SREG); + // TODO: base this on target. + if (size == kWord) { + size = k32; + } + return StoreBaseIndexedDisp(r_base, RegStorage::InvalidReg(), 0, displacement, r_src, + RegStorage::InvalidReg(), size, INVALID_SREG); } LIR* X86Mir2Lir::StoreBaseDispWide(RegStorage r_base, int displacement, RegStorage r_src) { return StoreBaseIndexedDisp(r_base, RegStorage::InvalidReg(), 0, displacement, - r_src.GetLow(), r_src.GetHigh(), kLong, INVALID_SREG); + r_src.GetLow(), r_src.GetHigh(), k64, INVALID_SREG); } /* diff --git a/compiler/elf_writer_test.cc b/compiler/elf_writer_test.cc index 8175c35077..864dadc963 100644 --- a/compiler/elf_writer_test.cc +++ b/compiler/elf_writer_test.cc @@ -50,7 +50,11 @@ TEST_F(ElfWriterTest, dlsym) { CHECK(host_dir != NULL); elf_filename = StringPrintf("%s/framework/core.oat", host_dir); } else { +#ifdef __LP64__ + elf_filename = "/data/art-test64/core.oat"; +#else elf_filename = "/data/art-test/core.oat"; +#endif } LOG(INFO) << "elf_filename=" << elf_filename; diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc index 9cfef12b26..766ef7b135 100644 --- a/compiler/oat_test.cc +++ b/compiler/oat_test.cc @@ -155,19 +155,19 @@ TEST_F(OatTest, WriteRead) { SirtRef<mirror::ClassLoader> loader(soa.Self(), nullptr); mirror::Class* klass = class_linker->FindClass(soa.Self(), descriptor, loader); - UniquePtr<const OatFile::OatClass> oat_class(oat_dex_file->GetOatClass(i)); - CHECK_EQ(mirror::Class::Status::kStatusNotReady, oat_class->GetStatus()) << descriptor; + const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(i); + CHECK_EQ(mirror::Class::Status::kStatusNotReady, oat_class.GetStatus()) << descriptor; CHECK_EQ(kCompile ? OatClassType::kOatClassAllCompiled : OatClassType::kOatClassNoneCompiled, - oat_class->GetType()) << descriptor; + oat_class.GetType()) << descriptor; size_t method_index = 0; for (size_t i = 0; i < klass->NumDirectMethods(); i++, method_index++) { CheckMethod(klass->GetDirectMethod(i), - oat_class->GetOatMethod(method_index), dex_file); + oat_class.GetOatMethod(method_index), dex_file); } for (size_t i = 0; i < num_virtual_methods; i++, method_index++) { CheckMethod(klass->GetVirtualMethod(i), - oat_class->GetOatMethod(method_index), dex_file); + oat_class.GetOatMethod(method_index), dex_file); } } } diff --git a/compiler/oat_writer.cc b/compiler/oat_writer.cc index dc66e9c108..2114fe921d 100644 --- a/compiler/oat_writer.cc +++ b/compiler/oat_writer.cc @@ -38,6 +38,14 @@ namespace art { +#define DCHECK_OFFSET() \ + DCHECK_EQ(static_cast<off_t>(file_offset + relative_offset), out->Seek(0, kSeekCurrent)) \ + << "file_offset=" << file_offset << " relative_offset=" << relative_offset + +#define DCHECK_OFFSET_() \ + DCHECK_EQ(static_cast<off_t>(file_offset + offset_), out->Seek(0, kSeekCurrent)) \ + << "file_offset=" << file_offset << " offset_=" << offset_ + OatWriter::OatWriter(const std::vector<const DexFile*>& dex_files, uint32_t image_file_location_oat_checksum, uintptr_t image_file_location_oat_begin, @@ -66,7 +74,7 @@ OatWriter::OatWriter(const std::vector<const DexFile*>& dex_files, size_quick_resolution_trampoline_(0), size_quick_to_interpreter_bridge_(0), size_trampoline_alignment_(0), - size_code_size_(0), + size_method_header_(0), size_code_(0), size_code_alignment_(0), size_mapping_table_(0), @@ -99,6 +107,10 @@ OatWriter::OatWriter(const std::vector<const DexFile*>& dex_files, offset = InitOatClasses(offset); } { + TimingLogger::ScopedSplit split("InitOatMaps", timings); + offset = InitOatMaps(offset); + } + { TimingLogger::ScopedSplit split("InitOatCode", timings); offset = InitOatCode(offset); } @@ -118,6 +130,585 @@ OatWriter::~OatWriter() { STLDeleteElements(&oat_classes_); } +struct OatWriter::GcMapDataAccess { + static const std::vector<uint8_t>* GetData(const CompiledMethod* compiled_method) ALWAYS_INLINE { + return &compiled_method->GetGcMap(); + } + + static uint32_t GetOffset(OatClass* oat_class, size_t method_offsets_index) ALWAYS_INLINE { + return oat_class->method_offsets_[method_offsets_index].gc_map_offset_; + } + + static void SetOffset(OatClass* oat_class, size_t method_offsets_index, uint32_t offset) + ALWAYS_INLINE { + oat_class->method_offsets_[method_offsets_index].gc_map_offset_ = offset; + } + + static const char* Name() ALWAYS_INLINE { + return "GC map"; + } +}; + +struct OatWriter::MappingTableDataAccess { + static const std::vector<uint8_t>* GetData(const CompiledMethod* compiled_method) ALWAYS_INLINE { + return &compiled_method->GetMappingTable(); + } + + static uint32_t GetOffset(OatClass* oat_class, size_t method_offsets_index) ALWAYS_INLINE { + return oat_class->method_offsets_[method_offsets_index].mapping_table_offset_; + } + + static void SetOffset(OatClass* oat_class, size_t method_offsets_index, uint32_t offset) + ALWAYS_INLINE { + oat_class->method_offsets_[method_offsets_index].mapping_table_offset_ = offset; + } + + static const char* Name() ALWAYS_INLINE { + return "mapping table"; + } +}; + +struct OatWriter::VmapTableDataAccess { + static const std::vector<uint8_t>* GetData(const CompiledMethod* compiled_method) ALWAYS_INLINE { + return &compiled_method->GetVmapTable(); + } + + static uint32_t GetOffset(OatClass* oat_class, size_t method_offsets_index) ALWAYS_INLINE { + return oat_class->method_offsets_[method_offsets_index].vmap_table_offset_; + } + + static void SetOffset(OatClass* oat_class, size_t method_offsets_index, uint32_t offset) + ALWAYS_INLINE { + oat_class->method_offsets_[method_offsets_index].vmap_table_offset_ = offset; + } + + static const char* Name() ALWAYS_INLINE { + return "vmap table"; + } +}; + +class OatWriter::DexMethodVisitor { + public: + DexMethodVisitor(OatWriter* writer, size_t offset) + : writer_(writer), + offset_(offset), + dex_file_(nullptr), + class_def_index_(DexFile::kDexNoIndex) { + } + + virtual bool StartClass(const DexFile* dex_file, size_t class_def_index) { + DCHECK(dex_file_ == nullptr); + DCHECK_EQ(class_def_index_, DexFile::kDexNoIndex); + dex_file_ = dex_file; + class_def_index_ = class_def_index; + return true; + } + + virtual bool VisitMethod(size_t class_def_method_index, const ClassDataItemIterator& it) = 0; + + virtual bool EndClass() { + if (kIsDebugBuild) { + dex_file_ = nullptr; + class_def_index_ = DexFile::kDexNoIndex; + } + return true; + } + + size_t GetOffset() const { + return offset_; + } + + protected: + virtual ~DexMethodVisitor() { } + + OatWriter* const writer_; + + // The offset is usually advanced for each visited method by the derived class. + size_t offset_; + + // The dex file and class def index are set in StartClass(). + const DexFile* dex_file_; + size_t class_def_index_; +}; + +class OatWriter::OatDexMethodVisitor : public DexMethodVisitor { + public: + OatDexMethodVisitor(OatWriter* writer, size_t offset) + : DexMethodVisitor(writer, offset), + oat_class_index_(0u), + method_offsets_index_(0u) { + } + + bool StartClass(const DexFile* dex_file, size_t class_def_index) { + DexMethodVisitor::StartClass(dex_file, class_def_index); + DCHECK_LT(oat_class_index_, writer_->oat_classes_.size()); + method_offsets_index_ = 0u; + return true; + } + + bool EndClass() { + ++oat_class_index_; + return DexMethodVisitor::EndClass(); + } + + protected: + size_t oat_class_index_; + size_t method_offsets_index_; +}; + +class OatWriter::InitOatClassesMethodVisitor : public DexMethodVisitor { + public: + InitOatClassesMethodVisitor(OatWriter* writer, size_t offset) + : DexMethodVisitor(writer, offset), + compiled_methods_(), + num_non_null_compiled_methods_(0u) { + compiled_methods_.reserve(256u); + } + + bool StartClass(const DexFile* dex_file, size_t class_def_index) { + DexMethodVisitor::StartClass(dex_file, class_def_index); + compiled_methods_.clear(); + num_non_null_compiled_methods_ = 0u; + return true; + } + + bool VisitMethod(size_t class_def_method_index, const ClassDataItemIterator& it) { + // Fill in the compiled_methods_ array for methods that have a + // CompiledMethod. We track the number of non-null entries in + // num_non_null_compiled_methods_ since we only want to allocate + // OatMethodOffsets for the compiled methods. + uint32_t method_idx = it.GetMemberIndex(); + CompiledMethod* compiled_method = + writer_->compiler_driver_->GetCompiledMethod(MethodReference(dex_file_, method_idx)); + compiled_methods_.push_back(compiled_method); + if (compiled_method != nullptr) { + ++num_non_null_compiled_methods_; + } + return true; + } + + bool EndClass() { + ClassReference class_ref(dex_file_, class_def_index_); + CompiledClass* compiled_class = writer_->compiler_driver_->GetCompiledClass(class_ref); + mirror::Class::Status status; + if (compiled_class != NULL) { + status = compiled_class->GetStatus(); + } else if (writer_->compiler_driver_->GetVerificationResults()->IsClassRejected(class_ref)) { + status = mirror::Class::kStatusError; + } else { + status = mirror::Class::kStatusNotReady; + } + + OatClass* oat_class = new OatClass(offset_, compiled_methods_, + num_non_null_compiled_methods_, status); + writer_->oat_classes_.push_back(oat_class); + offset_ += oat_class->SizeOf(); + return DexMethodVisitor::EndClass(); + } + + private: + std::vector<CompiledMethod*> compiled_methods_; + size_t num_non_null_compiled_methods_; +}; + +class OatWriter::InitCodeMethodVisitor : public OatDexMethodVisitor { + public: + InitCodeMethodVisitor(OatWriter* writer, size_t offset) + : OatDexMethodVisitor(writer, offset) { + } + + bool VisitMethod(size_t class_def_method_index, const ClassDataItemIterator& it) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + OatClass* oat_class = writer_->oat_classes_[oat_class_index_]; + CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index); + + if (compiled_method != nullptr) { + // Derived from CompiledMethod. + uint32_t quick_code_offset = 0; + uint32_t frame_size_in_bytes = kStackAlignment; + uint32_t core_spill_mask = 0; + uint32_t fp_spill_mask = 0; + + const std::vector<uint8_t>* portable_code = compiled_method->GetPortableCode(); + const std::vector<uint8_t>* quick_code = compiled_method->GetQuickCode(); + if (portable_code != nullptr) { + CHECK(quick_code == nullptr); + size_t oat_method_offsets_offset = + oat_class->GetOatMethodOffsetsOffsetFromOatHeader(class_def_method_index); + compiled_method->AddOatdataOffsetToCompliledCodeOffset( + oat_method_offsets_offset + OFFSETOF_MEMBER(OatMethodOffsets, code_offset_)); + } else { + CHECK(quick_code != nullptr); + offset_ = compiled_method->AlignCode(offset_); + DCHECK_ALIGNED_PARAM(offset_, + GetInstructionSetAlignment(compiled_method->GetInstructionSet())); + uint32_t code_size = quick_code->size() * sizeof(uint8_t); + CHECK_NE(code_size, 0U); + uint32_t thumb_offset = compiled_method->CodeDelta(); + quick_code_offset = offset_ + sizeof(OatMethodHeader) + thumb_offset; + + std::vector<uint8_t>* cfi_info = writer_->compiler_driver_->GetCallFrameInformation(); + if (cfi_info != nullptr) { + // Copy in the FDE, if present + const std::vector<uint8_t>* fde = compiled_method->GetCFIInfo(); + if (fde != nullptr) { + // Copy the information into cfi_info and then fix the address in the new copy. + int cur_offset = cfi_info->size(); + cfi_info->insert(cfi_info->end(), fde->begin(), fde->end()); + + // Set the 'initial_location' field to address the start of the method. + uint32_t new_value = quick_code_offset - writer_->oat_header_->GetExecutableOffset(); + uint32_t offset_to_update = cur_offset + 2*sizeof(uint32_t); + (*cfi_info)[offset_to_update+0] = new_value; + (*cfi_info)[offset_to_update+1] = new_value >> 8; + (*cfi_info)[offset_to_update+2] = new_value >> 16; + (*cfi_info)[offset_to_update+3] = new_value >> 24; + std::string name = PrettyMethod(it.GetMemberIndex(), *dex_file_, false); + writer_->method_info_.push_back(DebugInfo(name, new_value, new_value + code_size)); + } + } + + // Deduplicate code arrays. + auto code_iter = dedupe_map_.find(quick_code); + if (code_iter != dedupe_map_.end()) { + quick_code_offset = code_iter->second; + } else { + dedupe_map_.Put(quick_code, quick_code_offset); + OatMethodHeader method_header(code_size); + offset_ += sizeof(method_header); // Method header is prepended before code. + writer_->oat_header_->UpdateChecksum(&method_header, sizeof(method_header)); + offset_ += code_size; + writer_->oat_header_->UpdateChecksum(&(*quick_code)[0], code_size); + } + } + frame_size_in_bytes = compiled_method->GetFrameSizeInBytes(); + core_spill_mask = compiled_method->GetCoreSpillMask(); + fp_spill_mask = compiled_method->GetFpSpillMask(); + + if (kIsDebugBuild) { + // We expect GC maps except when the class hasn't been verified or the method is native. + const CompilerDriver* compiler_driver = writer_->compiler_driver_; + ClassReference class_ref(dex_file_, class_def_index_); + CompiledClass* compiled_class = compiler_driver->GetCompiledClass(class_ref); + mirror::Class::Status status; + if (compiled_class != NULL) { + status = compiled_class->GetStatus(); + } else if (compiler_driver->GetVerificationResults()->IsClassRejected(class_ref)) { + status = mirror::Class::kStatusError; + } else { + status = mirror::Class::kStatusNotReady; + } + const std::vector<uint8_t>& gc_map = compiled_method->GetGcMap(); + size_t gc_map_size = gc_map.size() * sizeof(gc_map[0]); + bool is_native = (it.GetMemberAccessFlags() & kAccNative) != 0; + CHECK(gc_map_size != 0 || is_native || status < mirror::Class::kStatusVerified) + << &gc_map << " " << gc_map_size << " " << (is_native ? "true" : "false") << " " + << (status < mirror::Class::kStatusVerified) << " " << status << " " + << PrettyMethod(it.GetMemberIndex(), *dex_file_); + } + + DCHECK_LT(method_offsets_index_, oat_class->method_offsets_.size()); + OatMethodOffsets* offsets = &oat_class->method_offsets_[method_offsets_index_]; + offsets->code_offset_ = quick_code_offset; + offsets->frame_size_in_bytes_ = frame_size_in_bytes; + offsets->core_spill_mask_ = core_spill_mask; + offsets->fp_spill_mask_ = fp_spill_mask; + ++method_offsets_index_; + } + + return true; + } + + private: + // Deduplication is already done on a pointer basis by the compiler driver, + // so we can simply compare the pointers to find out if things are duplicated. + SafeMap<const std::vector<uint8_t>*, uint32_t> dedupe_map_; +}; + +template <typename DataAccess> +class OatWriter::InitMapMethodVisitor : public OatDexMethodVisitor { + public: + InitMapMethodVisitor(OatWriter* writer, size_t offset) + : OatDexMethodVisitor(writer, offset) { + } + + bool VisitMethod(size_t class_def_method_index, const ClassDataItemIterator& it) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + OatClass* oat_class = writer_->oat_classes_[oat_class_index_]; + CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index); + + if (compiled_method != nullptr) { + DCHECK_LT(method_offsets_index_, oat_class->method_offsets_.size()); + DCHECK_EQ(DataAccess::GetOffset(oat_class, method_offsets_index_), 0u); + + const std::vector<uint8_t>* map = DataAccess::GetData(compiled_method); + uint32_t map_size = map->size() * sizeof((*map)[0]); + if (map_size != 0u) { + auto it = dedupe_map_.find(map); + if (it != dedupe_map_.end()) { + DataAccess::SetOffset(oat_class, method_offsets_index_, it->second); + } else { + DataAccess::SetOffset(oat_class, method_offsets_index_, offset_); + dedupe_map_.Put(map, offset_); + offset_ += map_size; + writer_->oat_header_->UpdateChecksum(&(*map)[0], map_size); + } + } + ++method_offsets_index_; + } + + return true; + } + + private: + // Deduplication is already done on a pointer basis by the compiler driver, + // so we can simply compare the pointers to find out if things are duplicated. + SafeMap<const std::vector<uint8_t>*, uint32_t> dedupe_map_; +}; + +class OatWriter::InitImageMethodVisitor : public OatDexMethodVisitor { + public: + InitImageMethodVisitor(OatWriter* writer, size_t offset) + : OatDexMethodVisitor(writer, offset) { + } + + bool VisitMethod(size_t class_def_method_index, const ClassDataItemIterator& it) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + OatClass* oat_class = writer_->oat_classes_[oat_class_index_]; + CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index); + + OatMethodOffsets offsets(0u, kStackAlignment, 0u, 0u, 0u, 0u, 0u); + if (compiled_method != nullptr) { + DCHECK_LT(method_offsets_index_, oat_class->method_offsets_.size()); + offsets = oat_class->method_offsets_[method_offsets_index_]; + ++method_offsets_index_; + } + + // Derive frame size and spill masks for native methods without code: + // These are generic JNI methods... + uint32_t method_idx = it.GetMemberIndex(); + bool is_native = (it.GetMemberAccessFlags() & kAccNative) != 0; + if (is_native && compiled_method == nullptr) { + // Compute Sirt size as putting _every_ reference into it, even null ones. + uint32_t s_len; + const char* shorty = dex_file_->GetMethodShorty(dex_file_->GetMethodId(method_idx), + &s_len); + DCHECK(shorty != nullptr); + uint32_t refs = 1; // Native method always has "this" or class. + for (uint32_t i = 1; i < s_len; ++i) { + if (shorty[i] == 'L') { + refs++; + } + } + size_t pointer_size = GetInstructionSetPointerSize( + writer_->compiler_driver_->GetInstructionSet()); + size_t sirt_size = StackIndirectReferenceTable::GetAlignedSirtSizeTarget(pointer_size, refs); + + // Get the generic spill masks and base frame size. + mirror::ArtMethod* callee_save_method = + Runtime::Current()->GetCalleeSaveMethod(Runtime::kRefsAndArgs); + + offsets.frame_size_in_bytes_ = callee_save_method->GetFrameSizeInBytes() + sirt_size; + offsets.core_spill_mask_ = callee_save_method->GetCoreSpillMask(); + offsets.fp_spill_mask_ = callee_save_method->GetFpSpillMask(); + DCHECK_EQ(offsets.mapping_table_offset_, 0u); + DCHECK_EQ(offsets.vmap_table_offset_, 0u); + DCHECK_EQ(offsets.gc_map_offset_, 0u); + } + + ClassLinker* linker = Runtime::Current()->GetClassLinker(); + InvokeType invoke_type = it.GetMethodInvokeType(dex_file_->GetClassDef(class_def_index_)); + // Unchecked as we hold mutator_lock_ on entry. + ScopedObjectAccessUnchecked soa(Thread::Current()); + SirtRef<mirror::DexCache> dex_cache(soa.Self(), linker->FindDexCache(*dex_file_)); + SirtRef<mirror::ClassLoader> class_loader(soa.Self(), nullptr); + mirror::ArtMethod* method = linker->ResolveMethod(*dex_file_, method_idx, dex_cache, + class_loader, nullptr, invoke_type); + CHECK(method != NULL); + method->SetFrameSizeInBytes(offsets.frame_size_in_bytes_); + method->SetCoreSpillMask(offsets.core_spill_mask_); + method->SetFpSpillMask(offsets.fp_spill_mask_); + method->SetOatMappingTableOffset(offsets.mapping_table_offset_); + // Portable code offsets are set by ElfWriterMclinker::FixupCompiledCodeOffset after linking. + method->SetQuickOatCodeOffset(offsets.code_offset_); + method->SetOatVmapTableOffset(offsets.vmap_table_offset_); + method->SetOatNativeGcMapOffset(offsets.gc_map_offset_); + + return true; + } +}; + +class OatWriter::WriteCodeMethodVisitor : public OatDexMethodVisitor { + public: + WriteCodeMethodVisitor(OatWriter* writer, OutputStream* out, const size_t file_offset, + size_t relative_offset) + : OatDexMethodVisitor(writer, relative_offset), + out_(out), + file_offset_(file_offset) { + } + + bool VisitMethod(size_t class_def_method_index, const ClassDataItemIterator& it) { + OatClass* oat_class = writer_->oat_classes_[oat_class_index_]; + const CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index); + + if (compiled_method != NULL) { // ie. not an abstract method + size_t file_offset = file_offset_; + OutputStream* out = out_; + + const std::vector<uint8_t>* quick_code = compiled_method->GetQuickCode(); + if (quick_code != nullptr) { + CHECK(compiled_method->GetPortableCode() == nullptr); + uint32_t aligned_offset = compiled_method->AlignCode(offset_); + uint32_t aligned_code_delta = aligned_offset - offset_; + if (aligned_code_delta != 0) { + static const uint8_t kPadding[] = { + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u + }; + DCHECK_LE(aligned_code_delta, sizeof(kPadding)); + if (UNLIKELY(!out->WriteFully(kPadding, aligned_code_delta))) { + ReportWriteFailure("code alignment padding", it); + return false; + } + writer_->size_code_alignment_ += aligned_code_delta; + offset_ += aligned_code_delta; + DCHECK_OFFSET_(); + } + DCHECK_ALIGNED_PARAM(offset_, + GetInstructionSetAlignment(compiled_method->GetInstructionSet())); + uint32_t code_size = quick_code->size() * sizeof(uint8_t); + CHECK_NE(code_size, 0U); + + // Deduplicate code arrays. + const OatMethodOffsets& method_offsets = oat_class->method_offsets_[method_offsets_index_]; + DCHECK(method_offsets.code_offset_ < offset_ || method_offsets.code_offset_ == + offset_ + sizeof(OatMethodHeader) + compiled_method->CodeDelta()) + << PrettyMethod(it.GetMemberIndex(), *dex_file_); + if (method_offsets.code_offset_ >= offset_) { + OatMethodHeader method_header(code_size); + if (!out->WriteFully(&method_header, sizeof(method_header))) { + ReportWriteFailure("method header", it); + return false; + } + writer_->size_method_header_ += sizeof(method_header); + offset_ += sizeof(method_header); + DCHECK_OFFSET_(); + if (!out->WriteFully(&(*quick_code)[0], code_size)) { + ReportWriteFailure("method code", it); + return false; + } + writer_->size_code_ += code_size; + offset_ += code_size; + } + DCHECK_OFFSET_(); + } + ++method_offsets_index_; + } + + return true; + } + + private: + OutputStream* const out_; + size_t const file_offset_; + + void ReportWriteFailure(const char* what, const ClassDataItemIterator& it) { + PLOG(ERROR) << "Failed to write " << what << " for " + << PrettyMethod(it.GetMemberIndex(), *dex_file_) << " to " << out_->GetLocation(); + } +}; + +template <typename DataAccess> +class OatWriter::WriteMapMethodVisitor : public OatDexMethodVisitor { + public: + WriteMapMethodVisitor(OatWriter* writer, OutputStream* out, const size_t file_offset, + size_t relative_offset) + : OatDexMethodVisitor(writer, relative_offset), + out_(out), + file_offset_(file_offset) { + } + + bool VisitMethod(size_t class_def_method_index, const ClassDataItemIterator& it) { + OatClass* oat_class = writer_->oat_classes_[oat_class_index_]; + const CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index); + + if (compiled_method != NULL) { // ie. not an abstract method + size_t file_offset = file_offset_; + OutputStream* out = out_; + + uint32_t map_offset = DataAccess::GetOffset(oat_class, method_offsets_index_); + ++method_offsets_index_; + + // Write deduplicated map. + const std::vector<uint8_t>* map = DataAccess::GetData(compiled_method); + size_t map_size = map->size() * sizeof((*map)[0]); + DCHECK((map_size == 0u && map_offset == 0u) || + (map_size != 0u && map_offset != 0u && map_offset <= offset_)) + << PrettyMethod(it.GetMemberIndex(), *dex_file_); + if (map_size != 0u && map_offset == offset_) { + if (UNLIKELY(!out->WriteFully(&(*map)[0], map_size))) { + ReportWriteFailure(it); + return false; + } + offset_ += map_size; + } + DCHECK_OFFSET_(); + } + + return true; + } + + private: + OutputStream* const out_; + size_t const file_offset_; + + void ReportWriteFailure(const ClassDataItemIterator& it) { + PLOG(ERROR) << "Failed to write " << DataAccess::Name() << " for " + << PrettyMethod(it.GetMemberIndex(), *dex_file_) << " to " << out_->GetLocation(); + } +}; + +// Visit all methods from all classes in all dex files with the specified visitor. +bool OatWriter::VisitDexMethods(DexMethodVisitor* visitor) { + for (const DexFile* dex_file : *dex_files_) { + const size_t class_def_count = dex_file->NumClassDefs(); + for (size_t class_def_index = 0; class_def_index != class_def_count; ++class_def_index) { + if (UNLIKELY(!visitor->StartClass(dex_file, class_def_index))) { + return false; + } + const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); + const byte* class_data = dex_file->GetClassData(class_def); + if (class_data != NULL) { // ie not an empty class, such as a marker interface + ClassDataItemIterator it(*dex_file, class_data); + while (it.HasNextStaticField()) { + it.Next(); + } + while (it.HasNextInstanceField()) { + it.Next(); + } + size_t class_def_method_index = 0u; + while (it.HasNextDirectMethod()) { + if (!visitor->VisitMethod(class_def_method_index, it)) { + return false; + } + ++class_def_method_index; + it.Next(); + } + while (it.HasNextVirtualMethod()) { + if (UNLIKELY(!visitor->VisitMethod(class_def_method_index, it))) { + return false; + } + ++class_def_method_index; + it.Next(); + } + } + if (UNLIKELY(!visitor->EndClass())) { + return false; + } + } + } + return true; +} + size_t OatWriter::InitOatHeader() { // create the OatHeader oat_header_ = new OatHeader(compiler_driver_->GetInstructionSet(), @@ -161,78 +752,42 @@ size_t OatWriter::InitDexFiles(size_t offset) { } size_t OatWriter::InitOatClasses(size_t offset) { - // create the OatClasses // calculate the offsets within OatDexFiles to OatClasses - for (size_t i = 0; i != dex_files_->size(); ++i) { - const DexFile* dex_file = (*dex_files_)[i]; - for (size_t class_def_index = 0; - class_def_index < dex_file->NumClassDefs(); - class_def_index++) { - oat_dex_files_[i]->methods_offsets_[class_def_index] = offset; - const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); - const byte* class_data = dex_file->GetClassData(class_def); - uint32_t num_non_null_compiled_methods = 0; - UniquePtr<std::vector<CompiledMethod*> > compiled_methods(new std::vector<CompiledMethod*>()); - if (class_data != NULL) { // ie not an empty class, such as a marker interface - ClassDataItemIterator it(*dex_file, class_data); - size_t num_direct_methods = it.NumDirectMethods(); - size_t num_virtual_methods = it.NumVirtualMethods(); - size_t num_methods = num_direct_methods + num_virtual_methods; - - // Fill in the compiled_methods_ array for methods that have a - // CompiledMethod. We track the number of non-null entries in - // num_non_null_compiled_methods since we only want to allocate - // OatMethodOffsets for the compiled methods. - compiled_methods->reserve(num_methods); - while (it.HasNextStaticField()) { - it.Next(); - } - while (it.HasNextInstanceField()) { - it.Next(); - } - size_t class_def_method_index = 0; - while (it.HasNextDirectMethod()) { - uint32_t method_idx = it.GetMemberIndex(); - CompiledMethod* compiled_method = - compiler_driver_->GetCompiledMethod(MethodReference(dex_file, method_idx)); - compiled_methods->push_back(compiled_method); - if (compiled_method != NULL) { - num_non_null_compiled_methods++; - } - class_def_method_index++; - it.Next(); - } - while (it.HasNextVirtualMethod()) { - uint32_t method_idx = it.GetMemberIndex(); - CompiledMethod* compiled_method = - compiler_driver_->GetCompiledMethod(MethodReference(dex_file, method_idx)); - compiled_methods->push_back(compiled_method); - if (compiled_method != NULL) { - num_non_null_compiled_methods++; - } - class_def_method_index++; - it.Next(); - } - } - - ClassReference class_ref(dex_file, class_def_index); - CompiledClass* compiled_class = compiler_driver_->GetCompiledClass(class_ref); - mirror::Class::Status status; - if (compiled_class != NULL) { - status = compiled_class->GetStatus(); - } else if (compiler_driver_->GetVerificationResults()->IsClassRejected(class_ref)) { - status = mirror::Class::kStatusError; - } else { - status = mirror::Class::kStatusNotReady; - } - - OatClass* oat_class = new OatClass(offset, compiled_methods.release(), - num_non_null_compiled_methods, status); - oat_classes_.push_back(oat_class); - offset += oat_class->SizeOf(); + InitOatClassesMethodVisitor visitor(this, offset); + bool success = VisitDexMethods(&visitor); + CHECK(success); + offset = visitor.GetOffset(); + + // Update oat_dex_files_. + auto oat_class_it = oat_classes_.begin(); + for (OatDexFile* oat_dex_file : oat_dex_files_) { + for (uint32_t& offset : oat_dex_file->methods_offsets_) { + DCHECK(oat_class_it != oat_classes_.end()); + offset = (*oat_class_it)->offset_; + ++oat_class_it; } - oat_dex_files_[i]->UpdateChecksum(oat_header_); + oat_dex_file->UpdateChecksum(oat_header_); } + CHECK(oat_class_it == oat_classes_.end()); + + return offset; +} + +size_t OatWriter::InitOatMaps(size_t offset) { + #define VISIT(VisitorType) \ + do { \ + VisitorType visitor(this, offset); \ + bool success = VisitDexMethods(&visitor); \ + DCHECK(success); \ + offset = visitor.GetOffset(); \ + } while (false) + + VISIT(InitMapMethodVisitor<GcMapDataAccess>); + VISIT(InitMapMethodVisitor<MappingTableDataAccess>); + VISIT(InitMapMethodVisitor<VmapTableDataAccess>); + + #undef VISIT + return offset; } @@ -280,280 +835,24 @@ size_t OatWriter::InitOatCode(size_t offset) { } size_t OatWriter::InitOatCodeDexFiles(size_t offset) { - size_t oat_class_index = 0; - for (size_t i = 0; i != dex_files_->size(); ++i) { - const DexFile* dex_file = (*dex_files_)[i]; - CHECK(dex_file != NULL); - offset = InitOatCodeDexFile(offset, &oat_class_index, *dex_file); - } - return offset; -} - -size_t OatWriter::InitOatCodeDexFile(size_t offset, - size_t* oat_class_index, - const DexFile& dex_file) { - for (size_t class_def_index = 0; - class_def_index < dex_file.NumClassDefs(); - class_def_index++, (*oat_class_index)++) { - const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); - offset = InitOatCodeClassDef(offset, *oat_class_index, class_def_index, dex_file, class_def); - oat_classes_[*oat_class_index]->UpdateChecksum(oat_header_); - } - return offset; -} - -size_t OatWriter::InitOatCodeClassDef(size_t offset, - size_t oat_class_index, size_t class_def_index, - const DexFile& dex_file, - const DexFile::ClassDef& class_def) { - const byte* class_data = dex_file.GetClassData(class_def); - if (class_data == NULL) { - // empty class, such as a marker interface - return offset; - } - ClassDataItemIterator it(dex_file, class_data); - CHECK_LE(oat_classes_[oat_class_index]->method_offsets_.size(), - it.NumDirectMethods() + it.NumVirtualMethods()); - // Skip fields - while (it.HasNextStaticField()) { - it.Next(); - } - while (it.HasNextInstanceField()) { - it.Next(); - } - // Process methods - size_t class_def_method_index = 0; - size_t method_offsets_index = 0; - while (it.HasNextDirectMethod()) { - bool is_native = (it.GetMemberAccessFlags() & kAccNative) != 0; - offset = InitOatCodeMethod(offset, oat_class_index, class_def_index, class_def_method_index, - &method_offsets_index, is_native, - it.GetMethodInvokeType(class_def), it.GetMemberIndex(), dex_file); - class_def_method_index++; - it.Next(); - } - while (it.HasNextVirtualMethod()) { - bool is_native = (it.GetMemberAccessFlags() & kAccNative) != 0; - offset = InitOatCodeMethod(offset, oat_class_index, class_def_index, class_def_method_index, - &method_offsets_index, is_native, - it.GetMethodInvokeType(class_def), it.GetMemberIndex(), dex_file); - class_def_method_index++; - it.Next(); - } - DCHECK(!it.HasNext()); - CHECK_LE(method_offsets_index, class_def_method_index); - return offset; -} - -size_t OatWriter::InitOatCodeMethod(size_t offset, size_t oat_class_index, - size_t __attribute__((unused)) class_def_index, - size_t class_def_method_index, - size_t* method_offsets_index, - bool __attribute__((unused)) is_native, - InvokeType invoke_type, - uint32_t method_idx, const DexFile& dex_file) { - // Derived from CompiledMethod if available. - uint32_t quick_code_offset = 0; - uint32_t frame_size_in_bytes = kStackAlignment; - uint32_t core_spill_mask = 0; - uint32_t fp_spill_mask = 0; - uint32_t mapping_table_offset = 0; - uint32_t vmap_table_offset = 0; - uint32_t gc_map_offset = 0; - - OatClass* oat_class = oat_classes_[oat_class_index]; - CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index); - - if (compiled_method != nullptr) { - const std::vector<uint8_t>* portable_code = compiled_method->GetPortableCode(); - const std::vector<uint8_t>* quick_code = compiled_method->GetQuickCode(); - if (portable_code != nullptr) { - CHECK(quick_code == nullptr); - size_t oat_method_offsets_offset = - oat_class->GetOatMethodOffsetsOffsetFromOatHeader(class_def_method_index); - compiled_method->AddOatdataOffsetToCompliledCodeOffset( - oat_method_offsets_offset + OFFSETOF_MEMBER(OatMethodOffsets, code_offset_)); - } else { - CHECK(quick_code != nullptr); - offset = compiled_method->AlignCode(offset); - DCHECK_ALIGNED_PARAM(offset, - GetInstructionSetAlignment(compiled_method->GetInstructionSet())); - - uint32_t code_size = quick_code->size() * sizeof(uint8_t); - CHECK_NE(code_size, 0U); - uint32_t thumb_offset = compiled_method->CodeDelta(); - quick_code_offset = offset + sizeof(code_size) + thumb_offset; - - std::vector<uint8_t>* cfi_info = compiler_driver_->GetCallFrameInformation(); - if (cfi_info != nullptr) { - // Copy in the FDE, if present - const std::vector<uint8_t>* fde = compiled_method->GetCFIInfo(); - if (fde != nullptr) { - // Copy the information into cfi_info and then fix the address in the new copy. - int cur_offset = cfi_info->size(); - cfi_info->insert(cfi_info->end(), fde->begin(), fde->end()); - - // Set the 'initial_location' field to address the start of the method. - uint32_t new_value = quick_code_offset - oat_header_->GetExecutableOffset(); - uint32_t offset_to_update = cur_offset + 2*sizeof(uint32_t); - (*cfi_info)[offset_to_update+0] = new_value; - (*cfi_info)[offset_to_update+1] = new_value >> 8; - (*cfi_info)[offset_to_update+2] = new_value >> 16; - (*cfi_info)[offset_to_update+3] = new_value >> 24; - method_info_.push_back(DebugInfo(PrettyMethod(method_idx, dex_file, false), - new_value, new_value + code_size)); - } - } - - // Deduplicate code arrays - SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator code_iter = - code_offsets_.find(quick_code); - if (code_iter != code_offsets_.end()) { - quick_code_offset = code_iter->second; - } else { - code_offsets_.Put(quick_code, quick_code_offset); - offset += sizeof(code_size); // code size is prepended before code - offset += code_size; - oat_header_->UpdateChecksum(&(*quick_code)[0], code_size); - } - } - frame_size_in_bytes = compiled_method->GetFrameSizeInBytes(); - core_spill_mask = compiled_method->GetCoreSpillMask(); - fp_spill_mask = compiled_method->GetFpSpillMask(); - - const std::vector<uint8_t>& mapping_table = compiled_method->GetMappingTable(); - size_t mapping_table_size = mapping_table.size() * sizeof(mapping_table[0]); - mapping_table_offset = (mapping_table_size == 0) ? 0 : offset; - - // Deduplicate mapping tables - SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator mapping_iter = - mapping_table_offsets_.find(&mapping_table); - if (mapping_iter != mapping_table_offsets_.end()) { - mapping_table_offset = mapping_iter->second; - } else { - mapping_table_offsets_.Put(&mapping_table, mapping_table_offset); - offset += mapping_table_size; - oat_header_->UpdateChecksum(&mapping_table[0], mapping_table_size); - } - - const std::vector<uint8_t>& vmap_table = compiled_method->GetVmapTable(); - size_t vmap_table_size = vmap_table.size() * sizeof(vmap_table[0]); - vmap_table_offset = (vmap_table_size == 0) ? 0 : offset; - - // Deduplicate vmap tables - SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator vmap_iter = - vmap_table_offsets_.find(&vmap_table); - if (vmap_iter != vmap_table_offsets_.end()) { - vmap_table_offset = vmap_iter->second; - } else { - vmap_table_offsets_.Put(&vmap_table, vmap_table_offset); - offset += vmap_table_size; - oat_header_->UpdateChecksum(&vmap_table[0], vmap_table_size); - } - - const std::vector<uint8_t>& gc_map = compiled_method->GetGcMap(); - size_t gc_map_size = gc_map.size() * sizeof(gc_map[0]); - gc_map_offset = (gc_map_size == 0) ? 0 : offset; - - if (kIsDebugBuild) { - // We expect GC maps except when the class hasn't been verified or the method is native - ClassReference class_ref(&dex_file, class_def_index); - CompiledClass* compiled_class = compiler_driver_->GetCompiledClass(class_ref); - mirror::Class::Status status; - if (compiled_class != NULL) { - status = compiled_class->GetStatus(); - } else if (compiler_driver_->GetVerificationResults()->IsClassRejected(class_ref)) { - status = mirror::Class::kStatusError; - } else { - status = mirror::Class::kStatusNotReady; - } - CHECK(gc_map_size != 0 || is_native || status < mirror::Class::kStatusVerified) - << &gc_map << " " << gc_map_size << " " << (is_native ? "true" : "false") << " " - << (status < mirror::Class::kStatusVerified) << " " << status << " " - << PrettyMethod(method_idx, dex_file); - } - - // Deduplicate GC maps - SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator gc_map_iter = - gc_map_offsets_.find(&gc_map); - if (gc_map_iter != gc_map_offsets_.end()) { - gc_map_offset = gc_map_iter->second; - } else { - gc_map_offsets_.Put(&gc_map, gc_map_offset); - offset += gc_map_size; - oat_header_->UpdateChecksum(&gc_map[0], gc_map_size); - } - - oat_class->method_offsets_[*method_offsets_index] = - OatMethodOffsets(quick_code_offset, - frame_size_in_bytes, - core_spill_mask, - fp_spill_mask, - mapping_table_offset, - vmap_table_offset, - gc_map_offset); - (*method_offsets_index)++; - } - - + #define VISIT(VisitorType) \ + do { \ + VisitorType visitor(this, offset); \ + bool success = VisitDexMethods(&visitor); \ + DCHECK(success); \ + offset = visitor.GetOffset(); \ + } while (false) + + VISIT(InitCodeMethodVisitor); if (compiler_driver_->IsImage()) { - // Derive frame size and spill masks for native methods without code: - // These are generic JNI methods... - if (is_native && compiled_method == nullptr) { - // Compute Sirt size as putting _every_ reference into it, even null ones. - uint32_t s_len; - const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx), &s_len); - DCHECK(shorty != nullptr); - uint32_t refs = 1; // Native method always has "this" or class. - for (uint32_t i = 1; i < s_len; ++i) { - if (shorty[i] == 'L') { - refs++; - } - } - size_t pointer_size = GetInstructionSetPointerSize(compiler_driver_->GetInstructionSet()); - size_t sirt_size = StackIndirectReferenceTable::GetAlignedSirtSizeTarget(pointer_size, refs); - - // Get the generic spill masks and base frame size. - mirror::ArtMethod* callee_save_method = - Runtime::Current()->GetCalleeSaveMethod(Runtime::kRefsAndArgs); - - frame_size_in_bytes = callee_save_method->GetFrameSizeInBytes() + sirt_size; - core_spill_mask = callee_save_method->GetCoreSpillMask(); - fp_spill_mask = callee_save_method->GetFpSpillMask(); - mapping_table_offset = 0; - vmap_table_offset = 0; - gc_map_offset = 0; - } - - ClassLinker* linker = Runtime::Current()->GetClassLinker(); - // Unchecked as we hold mutator_lock_ on entry. - ScopedObjectAccessUnchecked soa(Thread::Current()); - SirtRef<mirror::DexCache> dex_cache(soa.Self(), linker->FindDexCache(dex_file)); - SirtRef<mirror::ClassLoader> class_loader(soa.Self(), nullptr); - mirror::ArtMethod* method = linker->ResolveMethod(dex_file, method_idx, dex_cache, - class_loader, nullptr, invoke_type); - CHECK(method != NULL); - method->SetFrameSizeInBytes(frame_size_in_bytes); - method->SetCoreSpillMask(core_spill_mask); - method->SetFpSpillMask(fp_spill_mask); - method->SetOatMappingTableOffset(mapping_table_offset); - // Portable code offsets are set by ElfWriterMclinker::FixupCompiledCodeOffset after linking. - method->SetQuickOatCodeOffset(quick_code_offset); - method->SetOatVmapTableOffset(vmap_table_offset); - method->SetOatNativeGcMapOffset(gc_map_offset); + VISIT(InitImageMethodVisitor); } + #undef VISIT + return offset; } -#define DCHECK_OFFSET() \ - DCHECK_EQ(static_cast<off_t>(file_offset + relative_offset), out->Seek(0, kSeekCurrent)) \ - << "file_offset=" << file_offset << " relative_offset=" << relative_offset - -#define DCHECK_OFFSET_() \ - DCHECK_EQ(static_cast<off_t>(file_offset + offset_), out->Seek(0, kSeekCurrent)) \ - << "file_offset=" << file_offset << " offset_=" << offset_ - bool OatWriter::Write(OutputStream* out) { const size_t file_offset = out->Seek(0, kSeekCurrent); @@ -574,7 +873,14 @@ bool OatWriter::Write(OutputStream* out) { return false; } - size_t relative_offset = WriteCode(out, file_offset); + size_t relative_offset = out->Seek(0, kSeekCurrent) - file_offset; + relative_offset = WriteMaps(out, file_offset, relative_offset); + if (relative_offset == 0) { + LOG(ERROR) << "Failed to write oat code to " << out->GetLocation(); + return false; + } + + relative_offset = WriteCode(out, file_offset, relative_offset); if (relative_offset == 0) { LOG(ERROR) << "Failed to write oat code to " << out->GetLocation(); return false; @@ -608,7 +914,7 @@ bool OatWriter::Write(OutputStream* out) { DO_STAT(size_quick_resolution_trampoline_); DO_STAT(size_quick_to_interpreter_bridge_); DO_STAT(size_trampoline_alignment_); - DO_STAT(size_code_size_); + DO_STAT(size_method_header_); DO_STAT(size_code_); DO_STAT(size_code_alignment_); DO_STAT(size_mapping_table_); @@ -669,9 +975,37 @@ bool OatWriter::WriteTables(OutputStream* out, const size_t file_offset) { return true; } -size_t OatWriter::WriteCode(OutputStream* out, const size_t file_offset) { - size_t relative_offset = oat_header_->GetExecutableOffset(); +size_t OatWriter::WriteMaps(OutputStream* out, const size_t file_offset, size_t relative_offset) { + #define VISIT(VisitorType) \ + do { \ + VisitorType visitor(this, out, file_offset, relative_offset); \ + if (UNLIKELY(!VisitDexMethods(&visitor))) { \ + return 0; \ + } \ + relative_offset = visitor.GetOffset(); \ + } while (false) + + size_t gc_maps_offset = relative_offset; + VISIT(WriteMapMethodVisitor<GcMapDataAccess>); + size_gc_map_ = relative_offset - gc_maps_offset; + + size_t mapping_tables_offset = relative_offset; + VISIT(WriteMapMethodVisitor<MappingTableDataAccess>); + size_mapping_table_ = relative_offset - mapping_tables_offset; + + size_t vmap_tables_offset = relative_offset; + VISIT(WriteMapMethodVisitor<VmapTableDataAccess>); + size_vmap_table_ = relative_offset - vmap_tables_offset; + + #undef VISIT + + return relative_offset; +} + +size_t OatWriter::WriteCode(OutputStream* out, const size_t file_offset, size_t relative_offset) { off_t new_offset = out->Seek(size_executable_offset_alignment_, kSeekCurrent); + relative_offset += size_executable_offset_alignment_; + DCHECK_EQ(relative_offset, oat_header_->GetExecutableOffset()); size_t expected_file_offset = file_offset + relative_offset; if (static_cast<uint32_t>(new_offset) != expected_file_offset) { PLOG(ERROR) << "Failed to seek to oat code section. Actual: " << new_offset @@ -715,218 +1049,18 @@ size_t OatWriter::WriteCode(OutputStream* out, const size_t file_offset) { size_t OatWriter::WriteCodeDexFiles(OutputStream* out, const size_t file_offset, size_t relative_offset) { - size_t oat_class_index = 0; - for (size_t i = 0; i != oat_dex_files_.size(); ++i) { - const DexFile* dex_file = (*dex_files_)[i]; - CHECK(dex_file != NULL); - relative_offset = WriteCodeDexFile(out, file_offset, relative_offset, &oat_class_index, - *dex_file); - if (relative_offset == 0) { - return 0; - } - } - return relative_offset; -} - -size_t OatWriter::WriteCodeDexFile(OutputStream* out, const size_t file_offset, - size_t relative_offset, size_t* oat_class_index, - const DexFile& dex_file) { - for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); - class_def_index++, (*oat_class_index)++) { - const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); - relative_offset = WriteCodeClassDef(out, file_offset, relative_offset, *oat_class_index, - dex_file, class_def); - if (relative_offset == 0) { - return 0; - } - } - return relative_offset; -} - -void OatWriter::ReportWriteFailure(const char* what, uint32_t method_idx, - const DexFile& dex_file, const OutputStream& out) const { - PLOG(ERROR) << "Failed to write " << what << " for " << PrettyMethod(method_idx, dex_file) - << " to " << out.GetLocation(); -} + #define VISIT(VisitorType) \ + do { \ + VisitorType visitor(this, out, file_offset, relative_offset); \ + if (UNLIKELY(!VisitDexMethods(&visitor))) { \ + return 0; \ + } \ + relative_offset = visitor.GetOffset(); \ + } while (false) -size_t OatWriter::WriteCodeClassDef(OutputStream* out, - const size_t file_offset, - size_t relative_offset, - size_t oat_class_index, - const DexFile& dex_file, - const DexFile::ClassDef& class_def) { - const byte* class_data = dex_file.GetClassData(class_def); - if (class_data == NULL) { - // ie. an empty class such as a marker interface - return relative_offset; - } - ClassDataItemIterator it(dex_file, class_data); - // Skip fields - while (it.HasNextStaticField()) { - it.Next(); - } - while (it.HasNextInstanceField()) { - it.Next(); - } - // Process methods - size_t class_def_method_index = 0; - size_t method_offsets_index = 0; - while (it.HasNextDirectMethod()) { - bool is_static = (it.GetMemberAccessFlags() & kAccStatic) != 0; - relative_offset = WriteCodeMethod(out, file_offset, relative_offset, oat_class_index, - class_def_method_index, &method_offsets_index, is_static, - it.GetMemberIndex(), dex_file); - if (relative_offset == 0) { - return 0; - } - class_def_method_index++; - it.Next(); - } - while (it.HasNextVirtualMethod()) { - relative_offset = WriteCodeMethod(out, file_offset, relative_offset, oat_class_index, - class_def_method_index, &method_offsets_index, false, - it.GetMemberIndex(), dex_file); - if (relative_offset == 0) { - return 0; - } - class_def_method_index++; - it.Next(); - } - DCHECK(!it.HasNext()); - CHECK_LE(method_offsets_index, class_def_method_index); - return relative_offset; -} + VISIT(WriteCodeMethodVisitor); -size_t OatWriter::WriteCodeMethod(OutputStream* out, const size_t file_offset, - size_t relative_offset, size_t oat_class_index, - size_t class_def_method_index, size_t* method_offsets_index, - bool is_static, uint32_t method_idx, const DexFile& dex_file) { - OatClass* oat_class = oat_classes_[oat_class_index]; - const CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index); - - if (compiled_method != NULL) { // ie. not an abstract method - const OatMethodOffsets method_offsets = oat_class->method_offsets_[*method_offsets_index]; - (*method_offsets_index)++; - const std::vector<uint8_t>* quick_code = compiled_method->GetQuickCode(); - if (quick_code != nullptr) { - CHECK(compiled_method->GetPortableCode() == nullptr); - uint32_t aligned_offset = compiled_method->AlignCode(relative_offset); - uint32_t aligned_code_delta = aligned_offset - relative_offset; - if (aligned_code_delta != 0) { - off_t new_offset = out->Seek(aligned_code_delta, kSeekCurrent); - size_code_alignment_ += aligned_code_delta; - uint32_t expected_offset = file_offset + aligned_offset; - if (static_cast<uint32_t>(new_offset) != expected_offset) { - PLOG(ERROR) << "Failed to seek to align oat code. Actual: " << new_offset - << " Expected: " << expected_offset << " File: " << out->GetLocation(); - return 0; - } - relative_offset += aligned_code_delta; - DCHECK_OFFSET(); - } - DCHECK_ALIGNED_PARAM(relative_offset, - GetInstructionSetAlignment(compiled_method->GetInstructionSet())); - - uint32_t code_size = quick_code->size() * sizeof(uint8_t); - CHECK_NE(code_size, 0U); - - // Deduplicate code arrays - size_t code_offset = relative_offset + sizeof(code_size) + compiled_method->CodeDelta(); - SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator code_iter = - code_offsets_.find(quick_code); - if (code_iter != code_offsets_.end() && code_offset != method_offsets.code_offset_) { - DCHECK(code_iter->second == method_offsets.code_offset_) - << PrettyMethod(method_idx, dex_file); - } else { - DCHECK(code_offset == method_offsets.code_offset_) << PrettyMethod(method_idx, dex_file); - if (!out->WriteFully(&code_size, sizeof(code_size))) { - ReportWriteFailure("method code size", method_idx, dex_file, *out); - return 0; - } - size_code_size_ += sizeof(code_size); - relative_offset += sizeof(code_size); - DCHECK_OFFSET(); - if (!out->WriteFully(&(*quick_code)[0], code_size)) { - ReportWriteFailure("method code", method_idx, dex_file, *out); - return 0; - } - size_code_ += code_size; - relative_offset += code_size; - } - DCHECK_OFFSET(); - } - const std::vector<uint8_t>& mapping_table = compiled_method->GetMappingTable(); - size_t mapping_table_size = mapping_table.size() * sizeof(mapping_table[0]); - - // Deduplicate mapping tables - SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator mapping_iter = - mapping_table_offsets_.find(&mapping_table); - if (mapping_iter != mapping_table_offsets_.end() && - relative_offset != method_offsets.mapping_table_offset_) { - DCHECK((mapping_table_size == 0 && method_offsets.mapping_table_offset_ == 0) - || mapping_iter->second == method_offsets.mapping_table_offset_) - << PrettyMethod(method_idx, dex_file); - } else { - DCHECK((mapping_table_size == 0 && method_offsets.mapping_table_offset_ == 0) - || relative_offset == method_offsets.mapping_table_offset_) - << PrettyMethod(method_idx, dex_file); - if (!out->WriteFully(&mapping_table[0], mapping_table_size)) { - ReportWriteFailure("mapping table", method_idx, dex_file, *out); - return 0; - } - size_mapping_table_ += mapping_table_size; - relative_offset += mapping_table_size; - } - DCHECK_OFFSET(); - - const std::vector<uint8_t>& vmap_table = compiled_method->GetVmapTable(); - size_t vmap_table_size = vmap_table.size() * sizeof(vmap_table[0]); - - // Deduplicate vmap tables - SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator vmap_iter = - vmap_table_offsets_.find(&vmap_table); - if (vmap_iter != vmap_table_offsets_.end() && - relative_offset != method_offsets.vmap_table_offset_) { - DCHECK((vmap_table_size == 0 && method_offsets.vmap_table_offset_ == 0) - || vmap_iter->second == method_offsets.vmap_table_offset_) - << PrettyMethod(method_idx, dex_file); - } else { - DCHECK((vmap_table_size == 0 && method_offsets.vmap_table_offset_ == 0) - || relative_offset == method_offsets.vmap_table_offset_) - << PrettyMethod(method_idx, dex_file); - if (!out->WriteFully(&vmap_table[0], vmap_table_size)) { - ReportWriteFailure("vmap table", method_idx, dex_file, *out); - return 0; - } - size_vmap_table_ += vmap_table_size; - relative_offset += vmap_table_size; - } - DCHECK_OFFSET(); - - const std::vector<uint8_t>& gc_map = compiled_method->GetGcMap(); - size_t gc_map_size = gc_map.size() * sizeof(gc_map[0]); - - // Deduplicate GC maps - SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator gc_map_iter = - gc_map_offsets_.find(&gc_map); - if (gc_map_iter != gc_map_offsets_.end() && - relative_offset != method_offsets.gc_map_offset_) { - DCHECK((gc_map_size == 0 && method_offsets.gc_map_offset_ == 0) - || gc_map_iter->second == method_offsets.gc_map_offset_) - << PrettyMethod(method_idx, dex_file); - } else { - DCHECK((gc_map_size == 0 && method_offsets.gc_map_offset_ == 0) - || relative_offset == method_offsets.gc_map_offset_) - << PrettyMethod(method_idx, dex_file); - if (!out->WriteFully(&gc_map[0], gc_map_size)) { - ReportWriteFailure("GC map", method_idx, dex_file, *out); - return 0; - } - size_gc_map_ += gc_map_size; - relative_offset += gc_map_size; - } - DCHECK_OFFSET(); - } + #undef VISIT return relative_offset; } @@ -993,15 +1127,14 @@ bool OatWriter::OatDexFile::Write(OatWriter* oat_writer, } OatWriter::OatClass::OatClass(size_t offset, - std::vector<CompiledMethod*>* compiled_methods, + const std::vector<CompiledMethod*>& compiled_methods, uint32_t num_non_null_compiled_methods, - mirror::Class::Status status) { - CHECK(compiled_methods != NULL); - uint32_t num_methods = compiled_methods->size(); + mirror::Class::Status status) + : compiled_methods_(compiled_methods) { + uint32_t num_methods = compiled_methods.size(); CHECK_LE(num_non_null_compiled_methods, num_methods); offset_ = offset; - compiled_methods_ = compiled_methods; oat_method_offsets_offsets_from_oat_class_.resize(num_methods); // Since both kOatClassNoneCompiled and kOatClassAllCompiled could @@ -1033,7 +1166,7 @@ OatWriter::OatClass::OatClass(size_t offset, } for (size_t i = 0; i < num_methods; i++) { - CompiledMethod* compiled_method = (*compiled_methods_)[i]; + CompiledMethod* compiled_method = compiled_methods_[i]; if (compiled_method == NULL) { oat_method_offsets_offsets_from_oat_class_[i] = 0; } else { @@ -1048,7 +1181,6 @@ OatWriter::OatClass::OatClass(size_t offset, OatWriter::OatClass::~OatClass() { delete method_bitmap_; - delete compiled_methods_; } size_t OatWriter::OatClass::GetOatMethodOffsetsOffsetFromOatHeader( diff --git a/compiler/oat_writer.h b/compiler/oat_writer.h index bab1a26d44..1abacd831a 100644 --- a/compiler/oat_writer.h +++ b/compiler/oat_writer.h @@ -50,16 +50,30 @@ class OutputStream; // ... // OatClass[C] // +// GcMap one variable sized blob with GC map. +// GcMap GC maps are deduplicated. +// ... +// GcMap +// +// VmapTable one variable sized VmapTable blob (quick compiler only). +// VmapTable VmapTables are deduplicated. +// ... +// VmapTable +// +// MappingTable one variable sized blob with MappingTable (quick compiler only). +// MappingTable MappingTables are deduplicated. +// ... +// MappingTable +// // padding if necessary so that the following code will be page aligned // -// CompiledMethod one variable sized blob with the contents of each CompiledMethod -// CompiledMethod -// CompiledMethod -// CompiledMethod -// CompiledMethod -// CompiledMethod +// OatMethodHeader fixed size header for a CompiledMethod including the size of the MethodCode. +// MethodCode one variable sized blob with the code of a CompiledMethod. +// OatMethodHeader (OatMethodHeader, MethodCode) pairs are deduplicated. +// MethodCode // ... -// CompiledMethod +// OatMethodHeader +// MethodCode // class OatWriter { public: @@ -96,43 +110,47 @@ class OatWriter { } private: + // The DataAccess classes are helper classes that provide access to members related to + // a given map, i.e. GC map, mapping table or vmap table. By abstracting these away + // we can share a lot of code for processing the maps with template classes below. + struct GcMapDataAccess; + struct MappingTableDataAccess; + struct VmapTableDataAccess; + + // The function VisitDexMethods() below iterates through all the methods in all + // the compiled dex files in order of their definitions. The method visitor + // classes provide individual bits of processing for each of the passes we need to + // first collect the data we want to write to the oat file and then, in later passes, + // to actually write it. + class DexMethodVisitor; + class OatDexMethodVisitor; + class InitOatClassesMethodVisitor; + class InitCodeMethodVisitor; + template <typename DataAccess> + class InitMapMethodVisitor; + class InitImageMethodVisitor; + class WriteCodeMethodVisitor; + template <typename DataAccess> + class WriteMapMethodVisitor; + + // Visit all the methods in all the compiled dex files in their definition order + // with a given DexMethodVisitor. + bool VisitDexMethods(DexMethodVisitor* visitor); + size_t InitOatHeader(); size_t InitOatDexFiles(size_t offset); size_t InitDexFiles(size_t offset); size_t InitOatClasses(size_t offset); + size_t InitOatMaps(size_t offset); size_t InitOatCode(size_t offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); size_t InitOatCodeDexFiles(size_t offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - size_t InitOatCodeDexFile(size_t offset, - size_t* oat_class_index, - const DexFile& dex_file) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - size_t InitOatCodeClassDef(size_t offset, - size_t oat_class_index, size_t class_def_index, - const DexFile& dex_file, - const DexFile::ClassDef& class_def) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - size_t InitOatCodeMethod(size_t offset, size_t oat_class_index, size_t class_def_index, - size_t class_def_method_index, size_t* method_offsets_index, - bool is_native, InvokeType type, uint32_t method_idx, const DexFile&) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); bool WriteTables(OutputStream* out, const size_t file_offset); - size_t WriteCode(OutputStream* out, const size_t file_offset); + size_t WriteMaps(OutputStream* out, const size_t file_offset, size_t relative_offset); + size_t WriteCode(OutputStream* out, const size_t file_offset, size_t relative_offset); size_t WriteCodeDexFiles(OutputStream* out, const size_t file_offset, size_t relative_offset); - size_t WriteCodeDexFile(OutputStream* out, const size_t file_offset, size_t relative_offset, - size_t* oat_class_index, const DexFile& dex_file); - size_t WriteCodeClassDef(OutputStream* out, const size_t file_offset, size_t relative_offset, - size_t oat_class_index, const DexFile& dex_file, - const DexFile::ClassDef& class_def); - size_t WriteCodeMethod(OutputStream* out, const size_t file_offset, size_t relative_offset, - size_t oat_class_index, size_t class_def_method_index, - size_t* method_offsets_index, bool is_static, uint32_t method_idx, - const DexFile& dex_file); - - void ReportWriteFailure(const char* what, uint32_t method_idx, const DexFile& dex_file, - const OutputStream& out) const; class OatDexFile { public: @@ -159,7 +177,7 @@ class OatWriter { class OatClass { public: explicit OatClass(size_t offset, - std::vector<CompiledMethod*>* compiled_methods, + const std::vector<CompiledMethod*>& compiled_methods, uint32_t num_non_null_compiled_methods, mirror::Class::Status status); ~OatClass(); @@ -170,8 +188,8 @@ class OatWriter { bool Write(OatWriter* oat_writer, OutputStream* out, const size_t file_offset) const; CompiledMethod* GetCompiledMethod(size_t class_def_method_index) const { - DCHECK(compiled_methods_ != NULL); - return (*compiled_methods_)[class_def_method_index]; + DCHECK_LT(class_def_method_index, compiled_methods_.size()); + return compiled_methods_[class_def_method_index]; } // Offset of start of OatClass from beginning of OatHeader. It is @@ -182,7 +200,7 @@ class OatWriter { size_t offset_; // CompiledMethods for each class_def_method_index, or NULL if no method is available. - std::vector<CompiledMethod*>* compiled_methods_; + std::vector<CompiledMethod*> compiled_methods_; // Offset from OatClass::offset_ to the OatMethodOffsets for the // class_def_method_index. If 0, it means the corresponding @@ -265,7 +283,7 @@ class OatWriter { uint32_t size_quick_resolution_trampoline_; uint32_t size_quick_to_interpreter_bridge_; uint32_t size_trampoline_alignment_; - uint32_t size_code_size_; + uint32_t size_method_header_; uint32_t size_code_; uint32_t size_code_alignment_; uint32_t size_mapping_table_; @@ -281,13 +299,6 @@ class OatWriter { uint32_t size_oat_class_method_bitmaps_; uint32_t size_oat_class_method_offsets_; - // Code mappings for deduplication. Deduplication is already done on a pointer basis by the - // compiler driver, so we can simply compare the pointers to find out if things are duplicated. - SafeMap<const std::vector<uint8_t>*, uint32_t> code_offsets_; - SafeMap<const std::vector<uint8_t>*, uint32_t> vmap_table_offsets_; - SafeMap<const std::vector<uint8_t>*, uint32_t> mapping_table_offsets_; - SafeMap<const std::vector<uint8_t>*, uint32_t> gc_map_offsets_; - DISALLOW_COPY_AND_ASSIGN(OatWriter); }; diff --git a/compiler/utils/growable_array.h b/compiler/utils/growable_array.h index a7d1f0e5a5..b33a62e67f 100644 --- a/compiler/utils/growable_array.h +++ b/compiler/utils/growable_array.h @@ -31,7 +31,6 @@ enum OatListKind { kGrowableArrayDfsOrder, kGrowableArrayDfsPostOrder, kGrowableArrayDomPostOrderTraversal, - kGrowableArrayThrowLaunchPads, kGrowableArraySuspendLaunchPads, kGrowableArraySwitchTables, kGrowableArrayFillArrayData, diff --git a/compiler/utils/x86_64/assembler_x86_64.cc b/compiler/utils/x86_64/assembler_x86_64.cc index 7d02c7c8a8..9507e1207a 100644 --- a/compiler/utils/x86_64/assembler_x86_64.cc +++ b/compiler/utils/x86_64/assembler_x86_64.cc @@ -1493,7 +1493,7 @@ void X86_64Assembler::EmitOptionalRex(bool force, bool w, bool r, bool x, bool b } void X86_64Assembler::EmitOptionalRex32(CpuRegister reg) { - EmitOptionalRex(false, false, reg.NeedsRex(), false, false); + EmitOptionalRex(false, false, false, false, reg.NeedsRex()); } void X86_64Assembler::EmitOptionalRex32(CpuRegister dst, CpuRegister src) { @@ -1540,8 +1540,9 @@ void X86_64Assembler::EmitOptionalRex32(XmmRegister dst, const Operand& operand) } void X86_64Assembler::EmitRex64(CpuRegister reg) { - EmitOptionalRex(false, true, reg.NeedsRex(), false, false); + EmitOptionalRex(false, true, false, false, reg.NeedsRex()); } + void X86_64Assembler::EmitRex64(CpuRegister dst, CpuRegister src) { EmitOptionalRex(false, true, dst.NeedsRex(), false, src.NeedsRex()); } diff --git a/disassembler/disassembler_x86.cc b/disassembler/disassembler_x86.cc index 68e77d44e4..1b96a2bf01 100644 --- a/disassembler/disassembler_x86.cc +++ b/disassembler/disassembler_x86.cc @@ -735,7 +735,7 @@ DISASSEMBLER_ENTRY(cmp, std::ostringstream args; if (reg_in_opcode) { DCHECK(!has_modrm); - DumpReg(args, rex, *instr & 0x7, false, prefix[2], GPR); + DumpBaseReg(args, rex, *instr & 0x7); } instr++; uint32_t address_bits = 0; diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc index 915c415c6a..5054f96a88 100644 --- a/oatdump/oatdump.cc +++ b/oatdump/oatdump.cc @@ -215,10 +215,9 @@ class OatDumper { dex_file->FindClassDef(mh.GetDeclaringClassDescriptor()); if (class_def != NULL) { uint16_t class_def_index = dex_file->GetIndexForClassDef(*class_def); - const OatFile::OatClass* oat_class = oat_dex_file->GetOatClass(class_def_index); - CHECK(oat_class != NULL); + const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); size_t method_index = m->GetMethodIndex(); - return oat_class->GetOatMethod(method_index).GetQuickCode(); + return oat_class.GetOatMethod(method_index).GetQuickCode(); } } } @@ -246,18 +245,18 @@ class OatDumper { class_def_index < dex_file->NumClassDefs(); class_def_index++) { const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); - UniquePtr<const OatFile::OatClass> oat_class(oat_dex_file->GetOatClass(class_def_index)); + const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); const byte* class_data = dex_file->GetClassData(class_def); if (class_data != NULL) { ClassDataItemIterator it(*dex_file, class_data); SkipAllFields(it); uint32_t class_method_index = 0; while (it.HasNextDirectMethod()) { - AddOffsets(oat_class->GetOatMethod(class_method_index++)); + AddOffsets(oat_class.GetOatMethod(class_method_index++)); it.Next(); } while (it.HasNextVirtualMethod()) { - AddOffsets(oat_class->GetOatMethod(class_method_index++)); + AddOffsets(oat_class.GetOatMethod(class_method_index++)); it.Next(); } } @@ -299,15 +298,14 @@ class OatDumper { class_def_index++) { const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); const char* descriptor = dex_file->GetClassDescriptor(class_def); - UniquePtr<const OatFile::OatClass> oat_class(oat_dex_file.GetOatClass(class_def_index)); - CHECK(oat_class.get() != NULL); + const OatFile::OatClass oat_class = oat_dex_file.GetOatClass(class_def_index); os << StringPrintf("%zd: %s (type_idx=%d)", class_def_index, descriptor, class_def.class_idx_) - << " (" << oat_class->GetStatus() << ")" - << " (" << oat_class->GetType() << ")\n"; - // TODO: include bitmap here if type is kOatClassBitmap? + << " (" << oat_class.GetStatus() << ")" + << " (" << oat_class.GetType() << ")\n"; + // TODO: include bitmap here if type is kOatClassSomeCompiled? Indenter indent_filter(os.rdbuf(), kIndentChar, kIndentBy1Count); std::ostream indented_os(&indent_filter); - DumpOatClass(indented_os, *oat_class.get(), *(dex_file.get()), class_def); + DumpOatClass(indented_os, oat_class, *(dex_file.get()), class_def); } os << std::flush; @@ -864,7 +862,7 @@ class ImageDumper { } } // Dump the large objects separately. - heap->GetLargeObjectsSpace()->GetLiveObjects()->Walk(ImageDumper::Callback, this); + heap->GetLargeObjectsSpace()->GetLiveBitmap()->Walk(ImageDumper::Callback, this); indent_os << "\n"; os_ = saved_os; } diff --git a/runtime/arch/arm/jni_entrypoints_arm.S b/runtime/arch/arm/jni_entrypoints_arm.S index 4a69644b6c..1be34ba80e 100644 --- a/runtime/arch/arm/jni_entrypoints_arm.S +++ b/runtime/arch/arm/jni_entrypoints_arm.S @@ -41,27 +41,3 @@ ENTRY art_jni_dlsym_lookup_stub pop {r0, r1, r2, r3, pc} @ restore regs and return to caller to handle exception .cfi_adjust_cfa_offset -20 END art_jni_dlsym_lookup_stub - - /* - * Entry point of native methods when JNI bug compatibility is enabled. - */ - .extern artWorkAroundAppJniBugs -ENTRY art_work_around_app_jni_bugs - @ save registers that may contain arguments and LR that will be crushed by a call - push {r0-r3, lr} - .save {r0-r3, lr} - .cfi_adjust_cfa_offset 16 - .cfi_rel_offset r0, 0 - .cfi_rel_offset r1, 4 - .cfi_rel_offset r2, 8 - .cfi_rel_offset r3, 12 - sub sp, #12 @ 3 words of space for alignment - mov r0, r9 @ pass Thread::Current - mov r1, sp @ pass SP - bl artWorkAroundAppJniBugs @ (Thread*, SP) - add sp, #12 @ rewind stack - mov r12, r0 @ save target address - pop {r0-r3, lr} @ restore possibly modified argument registers - .cfi_adjust_cfa_offset -16 - bx r12 @ tail call into JNI routine -END art_work_around_app_jni_bugs diff --git a/runtime/arch/arm64/jni_entrypoints_arm64.S b/runtime/arch/arm64/jni_entrypoints_arm64.S index ba783ab820..c59a304fae 100644 --- a/runtime/arch/arm64/jni_entrypoints_arm64.S +++ b/runtime/arch/arm64/jni_entrypoints_arm64.S @@ -55,41 +55,3 @@ ENTRY art_jni_dlsym_lookup_stub 1: ret // restore regs and return to caller to handle exception. END art_jni_dlsym_lookup_stub - - /* - * Entry point of native methods when JNI bug compatibility is enabled. - */ - .extern artWorkAroundAppJniBugs -ENTRY art_work_around_app_jni_bugs - // spill regs. - stp x29, x30, [sp, #-16]! - mov x29, sp - stp d6, d7, [sp, #-16]! - stp d4, d5, [sp, #-16]! - stp d2, d3, [sp, #-16]! - stp d0, d1, [sp, #-16]! - stp x6, x7, [sp, #-16]! - stp x4, x5, [sp, #-16]! - stp x2, x3, [sp, #-16]! - stp x0, x1, [sp, #-16]! - - mov x0, x19 // Thread::Current. - mov x1, sp // SP. - bl artWorkAroundAppJniBugs // (Thread*, SP). - mov x17, x0 // save target return. - - // load spill regs. - ldp x0, x1, [sp], #16 - ldp x2, x3, [sp], #16 - ldp x4, x5, [sp], #16 - ldp x6, x7, [sp], #16 - ldp d0, d1, [sp], #16 - ldp d2, d3, [sp], #16 - ldp d4, d5, [sp], #16 - ldp d6, d7, [sp], #16 - ldp x29, x30, [sp], #16 - - //tail call into JNI routine. - br x17 -END art_work_around_app_jni_bugs - diff --git a/runtime/arch/mips/jni_entrypoints_mips.S b/runtime/arch/mips/jni_entrypoints_mips.S index f9ca7df763..e5f4a79237 100644 --- a/runtime/arch/mips/jni_entrypoints_mips.S +++ b/runtime/arch/mips/jni_entrypoints_mips.S @@ -54,36 +54,3 @@ ENTRY art_jni_dlsym_lookup_stub jr $ra nop END art_jni_dlsym_lookup_stub - - /* - * Entry point of native methods when JNI bug compatibility is enabled. - */ - .extern artWorkAroundAppJniBugs -ENTRY art_work_around_app_jni_bugs - GENERATE_GLOBAL_POINTER - # save registers that may contain arguments and LR that will be crushed by a call - addiu $sp, $sp, -32 - .cfi_adjust_cfa_offset 32 - sw $ra, 28($sp) - .cfi_rel_offset 31, 28 - sw $a3, 24($sp) - .cfi_rel_offset 7, 28 - sw $a2, 20($sp) - .cfi_rel_offset 6, 28 - sw $a1, 16($sp) - .cfi_rel_offset 5, 28 - sw $a0, 12($sp) - .cfi_rel_offset 4, 28 - move $a0, rSELF # pass Thread::Current - jal artWorkAroundAppJniBugs # (Thread*, $sp) - move $a1, $sp # pass $sp - move $t9, $v0 # save target address - lw $a0, 12($sp) - lw $a1, 16($sp) - lw $a2, 20($sp) - lw $a3, 24($sp) - lw $ra, 28($sp) - jr $t9 # tail call into JNI routine - addiu $sp, $sp, 32 - .cfi_adjust_cfa_offset -32 -END art_work_around_app_jni_bugs diff --git a/runtime/base/bit_vector.cc b/runtime/base/bit_vector.cc index 590835e059..d8ef962524 100644 --- a/runtime/base/bit_vector.cc +++ b/runtime/base/bit_vector.cc @@ -65,8 +65,7 @@ bool BitVector::IsBitSet(uint32_t num) const { return false; } - uint32_t val = storage_[num >> 5] & check_masks[num & 0x1f]; - return (val != 0); + return IsBitSet(storage_, num); } // Mark all bits bit as "clear". @@ -213,27 +212,10 @@ uint32_t BitVector::NumSetBits() const { return count; } -// Count the number of bits that are set up through and including num. -uint32_t BitVector::NumSetBits(uint32_t num) const { - DCHECK_LT(num, storage_size_ * sizeof(*storage_) * 8); - uint32_t last_word = num >> 5; - uint32_t partial_word_bits = num & 0x1f; - - // partial_word_bits | # | | | partial_word_mask - // 00000 | 0 | 0xffffffff >> (31 - 0) | (1 << (0 + 1)) - 1 | 0x00000001 - // 00001 | 1 | 0xffffffff >> (31 - 1) | (1 << (1 + 1)) - 1 | 0x00000003 - // 00010 | 2 | 0xffffffff >> (31 - 2) | (1 << (2 + 1)) - 1 | 0x00000007 - // ..... | - // 11110 | 30 | 0xffffffff >> (31 - 30) | (1 << (30 + 1)) - 1 | 0x7fffffff - // 11111 | 31 | 0xffffffff >> (31 - 31) | last_full_word++ | 0xffffffff - uint32_t partial_word_mask = 0xffffffff >> (0x1f - partial_word_bits); - - uint32_t count = 0; - for (uint32_t word = 0; word < last_word; word++) { - count += __builtin_popcount(storage_[word]); - } - count += __builtin_popcount(storage_[last_word] & partial_word_mask); - return count; +// Count the number of bits that are set in range [0, end). +uint32_t BitVector::NumSetBits(uint32_t end) const { + DCHECK_LE(end, storage_size_ * sizeof(*storage_) * 8); + return NumSetBits(storage_, end); } BitVector::Iterator* BitVector::GetIterator() const { @@ -327,4 +309,23 @@ void BitVector::Copy(const BitVector *src) { } } +bool BitVector::IsBitSet(const uint32_t* storage, uint32_t num) { + uint32_t val = storage[num >> 5] & check_masks[num & 0x1f]; + return (val != 0); +} + +uint32_t BitVector::NumSetBits(const uint32_t* storage, uint32_t end) { + uint32_t word_end = end >> 5; + uint32_t partial_word_bits = end & 0x1f; + + uint32_t count = 0u; + for (uint32_t word = 0u; word < word_end; word++) { + count += __builtin_popcount(storage[word]); + } + if (partial_word_bits != 0u) { + count += __builtin_popcount(storage[word_end] & ~(0xffffffffu << partial_word_bits)); + } + return count; +} + } // namespace art diff --git a/runtime/base/bit_vector.h b/runtime/base/bit_vector.h index c8f285e879..a496dbd4d4 100644 --- a/runtime/base/bit_vector.h +++ b/runtime/base/bit_vector.h @@ -119,7 +119,9 @@ class BitVector { bool SameBitsSet(const BitVector *src); uint32_t NumSetBits() const; - uint32_t NumSetBits(uint32_t num) const; + + // Number of bits set in range [0, end). + uint32_t NumSetBits(uint32_t end) const; Iterator* GetIterator() const; @@ -135,6 +137,11 @@ class BitVector { */ int GetHighestBitSet() const; + // Is bit set in storage. (No range check.) + static bool IsBitSet(const uint32_t* storage, uint32_t num); + // Number of bits set in range [0, end) in storage. (No range check.) + static uint32_t NumSetBits(const uint32_t* storage, uint32_t end); + private: Allocator* const allocator_; const bool expandable_; // expand bitmap if we run out? diff --git a/runtime/base/bit_vector_test.cc b/runtime/base/bit_vector_test.cc index a67fb332b1..2ff55cbb3e 100644 --- a/runtime/base/bit_vector_test.cc +++ b/runtime/base/bit_vector_test.cc @@ -29,8 +29,8 @@ TEST(BitVector, Test) { EXPECT_FALSE(bv.IsExpandable()); EXPECT_EQ(0U, bv.NumSetBits()); - EXPECT_EQ(0U, bv.NumSetBits(0)); - EXPECT_EQ(0U, bv.NumSetBits(kBits - 1)); + EXPECT_EQ(0U, bv.NumSetBits(1)); + EXPECT_EQ(0U, bv.NumSetBits(kBits)); for (size_t i = 0; i < kBits; i++) { EXPECT_FALSE(bv.IsBitSet(i)); } @@ -46,8 +46,8 @@ TEST(BitVector, Test) { bv.SetBit(0); bv.SetBit(kBits - 1); EXPECT_EQ(2U, bv.NumSetBits()); - EXPECT_EQ(1U, bv.NumSetBits(0)); - EXPECT_EQ(2U, bv.NumSetBits(kBits - 1)); + EXPECT_EQ(1U, bv.NumSetBits(1)); + EXPECT_EQ(2U, bv.NumSetBits(kBits)); EXPECT_TRUE(bv.IsBitSet(0)); for (size_t i = 1; i < kBits - 1; i++) { EXPECT_FALSE(bv.IsBitSet(i)); @@ -98,25 +98,25 @@ TEST(BitVector, NoopAllocator) { EXPECT_EQ(0x00010001U, bv.GetRawStorageWord(1)); EXPECT_EQ(4U, bv.NumSetBits()); - EXPECT_EQ(0U, bv.NumSetBits(0)); + EXPECT_EQ(0U, bv.NumSetBits(1)); - EXPECT_EQ(0U, bv.NumSetBits(7)); - EXPECT_EQ(1U, bv.NumSetBits(8)); + EXPECT_EQ(0U, bv.NumSetBits(8)); EXPECT_EQ(1U, bv.NumSetBits(9)); + EXPECT_EQ(1U, bv.NumSetBits(10)); - EXPECT_EQ(1U, bv.NumSetBits(15)); - EXPECT_EQ(2U, bv.NumSetBits(16)); + EXPECT_EQ(1U, bv.NumSetBits(16)); EXPECT_EQ(2U, bv.NumSetBits(17)); + EXPECT_EQ(2U, bv.NumSetBits(18)); - EXPECT_EQ(2U, bv.NumSetBits(31)); - EXPECT_EQ(3U, bv.NumSetBits(32)); + EXPECT_EQ(2U, bv.NumSetBits(32)); EXPECT_EQ(3U, bv.NumSetBits(33)); + EXPECT_EQ(3U, bv.NumSetBits(34)); - EXPECT_EQ(3U, bv.NumSetBits(47)); - EXPECT_EQ(4U, bv.NumSetBits(48)); + EXPECT_EQ(3U, bv.NumSetBits(48)); EXPECT_EQ(4U, bv.NumSetBits(49)); + EXPECT_EQ(4U, bv.NumSetBits(50)); - EXPECT_EQ(4U, bv.NumSetBits(63)); + EXPECT_EQ(4U, bv.NumSetBits(64)); } TEST(BitVector, SetInitialBits) { diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc index 46b8ff28fe..730a2c2cb4 100644 --- a/runtime/base/logging.cc +++ b/runtime/base/logging.cc @@ -26,6 +26,8 @@ namespace art { LogVerbosity gLogVerbosity; +std::vector<std::string> gVerboseMethods; + unsigned int gAborting = 0; static LogSeverity gMinimumLogSeverity = INFO; diff --git a/runtime/base/logging.h b/runtime/base/logging.h index fcec733868..bd5ae85f5c 100644 --- a/runtime/base/logging.h +++ b/runtime/base/logging.h @@ -22,6 +22,7 @@ #include <iostream> // NOLINT #include <sstream> #include <signal.h> +#include <vector> #include "base/macros.h" #include "log_severity.h" #include "UniquePtr.h" @@ -299,6 +300,8 @@ struct LogVerbosity { extern LogVerbosity gLogVerbosity; +extern std::vector<std::string> gVerboseMethods; + // Used on fatal exit. Prevents recursive aborts. Allows us to disable // some error checking to ensure fatal shutdown makes forward progress. extern unsigned int gAborting; diff --git a/runtime/catch_block_stack_visitor.cc b/runtime/catch_block_stack_visitor.cc index f9acffbbf6..410fff9f96 100644 --- a/runtime/catch_block_stack_visitor.cc +++ b/runtime/catch_block_stack_visitor.cc @@ -53,7 +53,9 @@ bool CatchBlockStackVisitor::HandleTryItems(mirror::ArtMethod* method) { } if (dex_pc != DexFile::kDexNoIndex) { bool clear_exception = false; - uint32_t found_dex_pc = method->FindCatchBlock(to_find_, dex_pc, &clear_exception); + SirtRef<mirror::Class> sirt_method_to_find(Thread::Current(), to_find_); + uint32_t found_dex_pc = method->FindCatchBlock(sirt_method_to_find, dex_pc, &clear_exception); + to_find_ = sirt_method_to_find.get(); catch_finder_->SetClearException(clear_exception); if (found_dex_pc != DexFile::kDexNoIndex) { catch_finder_->SetHandlerDexPc(found_dex_pc); diff --git a/runtime/catch_block_stack_visitor.h b/runtime/catch_block_stack_visitor.h index 175ad7dd94..ce67e276b9 100644 --- a/runtime/catch_block_stack_visitor.h +++ b/runtime/catch_block_stack_visitor.h @@ -45,7 +45,7 @@ class CatchBlockStackVisitor : public StackVisitor { Thread* const self_; const bool is_deoptimization_; // The type of the exception catch block to find. - mirror::Class* const to_find_; + mirror::Class* to_find_; CatchFinder* const catch_finder_; // Number of native methods passed in crawl (equates to number of SIRTs to pop) uint32_t native_method_count_; diff --git a/runtime/check_jni.cc b/runtime/check_jni.cc index 960c26dfde..b52941b258 100644 --- a/runtime/check_jni.cc +++ b/runtime/check_jni.cc @@ -765,14 +765,9 @@ class ScopedCheck { // Verify that the current thread is (a) attached and (b) associated with // this particular instance of JNIEnv. if (soa_.Env() != threadEnv) { - if (soa_.Vm()->work_around_app_jni_bugs) { - // If we're keeping broken code limping along, we need to suppress the abort... - LOG(ERROR) << "APP BUG DETECTED: thread " << *self << " using JNIEnv* from thread " << *soa_.Self(); - } else { - JniAbortF(function_name_, "thread %s using JNIEnv* from thread %s", - ToStr<Thread>(*self).c_str(), ToStr<Thread>(*soa_.Self()).c_str()); - return; - } + JniAbortF(function_name_, "thread %s using JNIEnv* from thread %s", + ToStr<Thread>(*self).c_str(), ToStr<Thread>(*soa_.Self()).c_str()); + return; } // Verify that, if this thread previously made a critical "get" call, we diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index e690b30783..58b82f00ee 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -1523,7 +1523,7 @@ uint32_t ClassLinker::SizeOfClass(const DexFile& dex_file, return size; } -const OatFile::OatClass* ClassLinker::GetOatClass(const DexFile& dex_file, uint16_t class_def_idx) { +OatFile::OatClass ClassLinker::GetOatClass(const DexFile& dex_file, uint16_t class_def_idx) { DCHECK_NE(class_def_idx, DexFile::kDexNoIndex16); const OatFile* oat_file = FindOpenedOatFileForDexFile(dex_file); CHECK(oat_file != NULL) << dex_file.GetLocation(); @@ -1531,9 +1531,7 @@ const OatFile::OatClass* ClassLinker::GetOatClass(const DexFile& dex_file, uint1 const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_file.GetLocation().c_str(), &dex_location_checksum); CHECK(oat_dex_file != NULL) << dex_file.GetLocation(); - const OatFile::OatClass* oat_class = oat_dex_file->GetOatClass(class_def_idx); - CHECK(oat_class != NULL) << dex_file.GetLocation() << " " << class_def_idx; - return oat_class; + return oat_dex_file->GetOatClass(class_def_idx); } static uint32_t GetOatMethodIndexFromMethodIndex(const DexFile& dex_file, uint16_t class_def_idx, @@ -1593,16 +1591,14 @@ const OatFile::OatMethod ClassLinker::GetOatMethodFor(mirror::ArtMethod* method) } CHECK(found) << "Didn't find oat method index for virtual method: " << PrettyMethod(method); } - UniquePtr<const OatFile::OatClass> - oat_class(GetOatClass(*declaring_class->GetDexCache()->GetDexFile(), - declaring_class->GetDexClassDefIndex())); - CHECK(oat_class.get() != NULL); DCHECK_EQ(oat_method_index, GetOatMethodIndexFromMethodIndex(*declaring_class->GetDexCache()->GetDexFile(), method->GetDeclaringClass()->GetDexClassDefIndex(), method->GetDexMethodIndex())); + const OatFile::OatClass oat_class = GetOatClass(*declaring_class->GetDexCache()->GetDexFile(), + declaring_class->GetDexClassDefIndex()); - return oat_class->GetOatMethod(oat_method_index); + return oat_class.GetOatMethod(oat_method_index); } // Special case to get oat code without overwriting a trampoline. @@ -1634,9 +1630,10 @@ const void* ClassLinker::GetPortableOatCodeFor(mirror::ArtMethod* method, if (method->IsProxyMethod()) { return GetPortableProxyInvokeHandler(); } - const void* result = GetOatMethodFor(method).GetPortableCode(); + const OatFile::OatMethod oat_method = GetOatMethodFor(method); + const void* result = oat_method.GetPortableCode(); if (result == nullptr) { - if (GetOatMethodFor(method).GetQuickCode() == nullptr) { + if (oat_method.GetQuickCode() == nullptr) { // No code? You must mean to go into the interpreter. result = GetPortableToInterpreterBridge(); } else { @@ -1651,18 +1648,16 @@ const void* ClassLinker::GetPortableOatCodeFor(mirror::ArtMethod* method, const void* ClassLinker::GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx) { - UniquePtr<const OatFile::OatClass> oat_class(GetOatClass(dex_file, class_def_idx)); - CHECK(oat_class.get() != nullptr); + const OatFile::OatClass oat_class = GetOatClass(dex_file, class_def_idx); uint32_t oat_method_idx = GetOatMethodIndexFromMethodIndex(dex_file, class_def_idx, method_idx); - return oat_class->GetOatMethod(oat_method_idx).GetQuickCode(); + return oat_class.GetOatMethod(oat_method_idx).GetQuickCode(); } const void* ClassLinker::GetPortableOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx) { - UniquePtr<const OatFile::OatClass> oat_class(GetOatClass(dex_file, class_def_idx)); - CHECK(oat_class.get() != nullptr); + const OatFile::OatClass oat_class = GetOatClass(dex_file, class_def_idx); uint32_t oat_method_idx = GetOatMethodIndexFromMethodIndex(dex_file, class_def_idx, method_idx); - return oat_class->GetOatMethod(oat_method_idx).GetPortableCode(); + return oat_class.GetOatMethod(oat_method_idx).GetPortableCode(); } // Returns true if the method must run with interpreter, false otherwise. @@ -1703,8 +1698,7 @@ void ClassLinker::FixupStaticTrampolines(mirror::Class* klass) { const byte* class_data = dex_file.GetClassData(*dex_class_def); // There should always be class data if there were direct methods. CHECK(class_data != nullptr) << PrettyDescriptor(klass); - UniquePtr<const OatFile::OatClass> oat_class(GetOatClass(dex_file, klass->GetDexClassDefIndex())); - CHECK(oat_class.get() != nullptr); + const OatFile::OatClass oat_class = GetOatClass(dex_file, klass->GetDexClassDefIndex()); ClassDataItemIterator it(dex_file, class_data); // Skip fields while (it.HasNextStaticField()) { @@ -1720,8 +1714,8 @@ void ClassLinker::FixupStaticTrampolines(mirror::Class* klass) { // Only update static methods. continue; } - const void* portable_code = oat_class->GetOatMethod(method_index).GetPortableCode(); - const void* quick_code = oat_class->GetOatMethod(method_index).GetQuickCode(); + const void* portable_code = oat_class.GetOatMethod(method_index).GetPortableCode(); + const void* quick_code = oat_class.GetOatMethod(method_index).GetQuickCode(); const bool enter_interpreter = NeedsInterpreter(method, quick_code, portable_code); bool have_portable_code = false; if (enter_interpreter) { @@ -1869,11 +1863,25 @@ void ClassLinker::LoadClass(const DexFile& dex_file, klass->SetDexClassDefIndex(dex_file.GetIndexForClassDef(dex_class_def)); klass->SetDexTypeIndex(dex_class_def.class_idx_); - // Load fields fields. const byte* class_data = dex_file.GetClassData(dex_class_def); if (class_data == NULL) { return; // no fields or methods - for example a marker interface } + + if (Runtime::Current()->IsStarted() && !Runtime::Current()->UseCompileTimeClassPath()) { + const OatFile::OatClass oat_class = GetOatClass(dex_file, klass->GetDexClassDefIndex()); + LoadClassMembers(dex_file, class_data, klass, class_loader, &oat_class); + } else { + LoadClassMembers(dex_file, class_data, klass, class_loader, nullptr); + } +} + +void ClassLinker::LoadClassMembers(const DexFile& dex_file, + const byte* class_data, + const SirtRef<mirror::Class>& klass, + mirror::ClassLoader* class_loader, + const OatFile::OatClass* oat_class) { + // Load fields. ClassDataItemIterator it(dex_file, class_data); Thread* self = Thread::Current(); if (it.NumStaticFields() != 0) { @@ -1912,11 +1920,6 @@ void ClassLinker::LoadClass(const DexFile& dex_file, LoadField(dex_file, it, klass, ifield); } - UniquePtr<const OatFile::OatClass> oat_class; - if (Runtime::Current()->IsStarted() && !Runtime::Current()->UseCompileTimeClassPath()) { - oat_class.reset(GetOatClass(dex_file, klass->GetDexClassDefIndex())); - } - // Load methods. if (it.NumDirectMethods() != 0) { // TODO: append direct methods to class object @@ -1946,8 +1949,8 @@ void ClassLinker::LoadClass(const DexFile& dex_file, return; } klass->SetDirectMethod(i, method.get()); - if (oat_class.get() != NULL) { - LinkCode(method, oat_class.get(), dex_file, it.GetMemberIndex(), class_def_method_index); + if (oat_class != nullptr) { + LinkCode(method, oat_class, dex_file, it.GetMemberIndex(), class_def_method_index); } method->SetMethodIndex(class_def_method_index); class_def_method_index++; @@ -1960,8 +1963,8 @@ void ClassLinker::LoadClass(const DexFile& dex_file, } klass->SetVirtualMethod(i, method.get()); DCHECK_EQ(class_def_method_index, it.NumDirectMethods() + i); - if (oat_class.get() != NULL) { - LinkCode(method, oat_class.get(), dex_file, it.GetMemberIndex(), class_def_method_index); + if (oat_class != nullptr) { + LinkCode(method, oat_class, dex_file, it.GetMemberIndex(), class_def_method_index); } class_def_method_index++; } @@ -2691,11 +2694,7 @@ bool ClassLinker::VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class &dex_location_checksum); CHECK(oat_dex_file != NULL) << dex_file.GetLocation() << " " << PrettyClass(klass); uint16_t class_def_index = klass->GetDexClassDefIndex(); - UniquePtr<const OatFile::OatClass> oat_class(oat_dex_file->GetOatClass(class_def_index)); - CHECK(oat_class.get() != NULL) - << dex_file.GetLocation() << " " << PrettyClass(klass) << " " - << ClassHelper(klass).GetDescriptor(); - oat_file_class_status = oat_class->GetStatus(); + oat_file_class_status = oat_dex_file->GetOatClass(class_def_index).GetStatus(); if (oat_file_class_status == mirror::Class::kStatusVerified || oat_file_class_status == mirror::Class::kStatusInitialized) { return true; diff --git a/runtime/class_linker.h b/runtime/class_linker.h index d684ad5689..a14d1d12e0 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -433,6 +433,12 @@ class ClassLinker { const SirtRef<mirror::Class>& klass, mirror::ClassLoader* class_loader) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + void LoadClassMembers(const DexFile& dex_file, + const byte* class_data, + const SirtRef<mirror::Class>& klass, + mirror::ClassLoader* class_loader, + const OatFile::OatClass* oat_class) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it, const SirtRef<mirror::Class>& klass, const SirtRef<mirror::ArtField>& dst) @@ -446,7 +452,7 @@ class ClassLinker { void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Finds the associated oat class for a dex_file and descriptor - const OatFile::OatClass* GetOatClass(const DexFile& dex_file, uint16_t class_def_idx) + OatFile::OatClass GetOatClass(const DexFile& dex_file, uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void RegisterDexFileLocked(const DexFile& dex_file, const SirtRef<mirror::DexCache>& dex_cache) diff --git a/runtime/debugger.cc b/runtime/debugger.cc index c52a5887aa..9012f006af 100644 --- a/runtime/debugger.cc +++ b/runtime/debugger.cc @@ -225,6 +225,7 @@ size_t Dbg::alloc_record_count_ = 0; Mutex* Dbg::deoptimization_lock_ = nullptr; std::vector<DeoptimizationRequest> Dbg::deoptimization_requests_; size_t Dbg::full_deoptimization_event_count_ = 0; +size_t Dbg::delayed_full_undeoptimization_count_ = 0; // Breakpoints. static std::vector<Breakpoint> gBreakpoints GUARDED_BY(Locks::breakpoint_lock_); @@ -665,6 +666,7 @@ void Dbg::GoActive() { MutexLock mu(Thread::Current(), *deoptimization_lock_); CHECK_EQ(deoptimization_requests_.size(), 0U); CHECK_EQ(full_deoptimization_event_count_, 0U); + CHECK_EQ(delayed_full_undeoptimization_count_, 0U); } Runtime* runtime = Runtime::Current(); @@ -703,6 +705,7 @@ void Dbg::Disconnected() { MutexLock mu(Thread::Current(), *deoptimization_lock_); deoptimization_requests_.clear(); full_deoptimization_event_count_ = 0U; + delayed_full_undeoptimization_count_ = 0U; } runtime->GetInstrumentation()->RemoveListener(&gDebugInstrumentationListener, kListenerEvents); runtime->GetInstrumentation()->DisableDeoptimization(); @@ -2668,20 +2671,24 @@ void Dbg::ProcessDeoptimizationRequest(const DeoptimizationRequest& request) { LOG(WARNING) << "Ignoring empty deoptimization request."; break; case DeoptimizationRequest::kFullDeoptimization: - VLOG(jdwp) << "Deoptimize the world"; + VLOG(jdwp) << "Deoptimize the world ..."; instrumentation->DeoptimizeEverything(); + VLOG(jdwp) << "Deoptimize the world DONE"; break; case DeoptimizationRequest::kFullUndeoptimization: - VLOG(jdwp) << "Undeoptimize the world"; + VLOG(jdwp) << "Undeoptimize the world ..."; instrumentation->UndeoptimizeEverything(); + VLOG(jdwp) << "Undeoptimize the world DONE"; break; case DeoptimizationRequest::kSelectiveDeoptimization: - VLOG(jdwp) << "Deoptimize method " << PrettyMethod(request.method); + VLOG(jdwp) << "Deoptimize method " << PrettyMethod(request.method) << " ..."; instrumentation->Deoptimize(request.method); + VLOG(jdwp) << "Deoptimize method " << PrettyMethod(request.method) << " DONE"; break; case DeoptimizationRequest::kSelectiveUndeoptimization: - VLOG(jdwp) << "Undeoptimize method " << PrettyMethod(request.method); + VLOG(jdwp) << "Undeoptimize method " << PrettyMethod(request.method) << " ..."; instrumentation->Undeoptimize(request.method); + VLOG(jdwp) << "Undeoptimize method " << PrettyMethod(request.method) << " DONE"; break; default: LOG(FATAL) << "Unsupported deoptimization request kind " << request.kind; @@ -2689,17 +2696,43 @@ void Dbg::ProcessDeoptimizationRequest(const DeoptimizationRequest& request) { } } +void Dbg::DelayFullUndeoptimization() { + MutexLock mu(Thread::Current(), *deoptimization_lock_); + ++delayed_full_undeoptimization_count_; + DCHECK_LE(delayed_full_undeoptimization_count_, full_deoptimization_event_count_); +} + +void Dbg::ProcessDelayedFullUndeoptimizations() { + // TODO: avoid taking the lock twice (once here and once in ManageDeoptimization). + { + MutexLock mu(Thread::Current(), *deoptimization_lock_); + while (delayed_full_undeoptimization_count_ > 0) { + DeoptimizationRequest req; + req.kind = DeoptimizationRequest::kFullUndeoptimization; + req.method = nullptr; + RequestDeoptimizationLocked(req); + --delayed_full_undeoptimization_count_; + } + } + ManageDeoptimization(); +} + void Dbg::RequestDeoptimization(const DeoptimizationRequest& req) { if (req.kind == DeoptimizationRequest::kNothing) { // Nothing to do. return; } MutexLock mu(Thread::Current(), *deoptimization_lock_); + RequestDeoptimizationLocked(req); +} + +void Dbg::RequestDeoptimizationLocked(const DeoptimizationRequest& req) { switch (req.kind) { case DeoptimizationRequest::kFullDeoptimization: { DCHECK(req.method == nullptr); if (full_deoptimization_event_count_ == 0) { - VLOG(jdwp) << "Request full deoptimization"; + VLOG(jdwp) << "Queue request #" << deoptimization_requests_.size() + << " for full deoptimization"; deoptimization_requests_.push_back(req); } ++full_deoptimization_event_count_; @@ -2710,20 +2743,23 @@ void Dbg::RequestDeoptimization(const DeoptimizationRequest& req) { DCHECK_GT(full_deoptimization_event_count_, 0U); --full_deoptimization_event_count_; if (full_deoptimization_event_count_ == 0) { - VLOG(jdwp) << "Request full undeoptimization"; + VLOG(jdwp) << "Queue request #" << deoptimization_requests_.size() + << " for full undeoptimization"; deoptimization_requests_.push_back(req); } break; } case DeoptimizationRequest::kSelectiveDeoptimization: { DCHECK(req.method != nullptr); - VLOG(jdwp) << "Request deoptimization of " << PrettyMethod(req.method); + VLOG(jdwp) << "Queue request #" << deoptimization_requests_.size() + << " for deoptimization of " << PrettyMethod(req.method); deoptimization_requests_.push_back(req); break; } case DeoptimizationRequest::kSelectiveUndeoptimization: { DCHECK(req.method != nullptr); - VLOG(jdwp) << "Request undeoptimization of " << PrettyMethod(req.method); + VLOG(jdwp) << "Queue request #" << deoptimization_requests_.size() + << " for undeoptimization of " << PrettyMethod(req.method); deoptimization_requests_.push_back(req); break; } @@ -2751,7 +2787,9 @@ void Dbg::ManageDeoptimization() { const ThreadState old_state = self->SetStateUnsafe(kRunnable); { MutexLock mu(self, *deoptimization_lock_); + size_t req_index = 0; for (const DeoptimizationRequest& request : deoptimization_requests_) { + VLOG(jdwp) << "Process deoptimization request #" << req_index++; ProcessDeoptimizationRequest(request); } deoptimization_requests_.clear(); diff --git a/runtime/debugger.h b/runtime/debugger.h index b3e94c35b2..bef708cdc3 100644 --- a/runtime/debugger.h +++ b/runtime/debugger.h @@ -448,6 +448,13 @@ class Dbg { LOCKS_EXCLUDED(deoptimization_lock_) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + // Support delayed full undeoptimization requests. This is currently only used for single-step + // events. + static void DelayFullUndeoptimization() LOCKS_EXCLUDED(deoptimization_lock_); + static void ProcessDelayedFullUndeoptimizations() + LOCKS_EXCLUDED(deoptimization_lock_) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each // request and finally resumes all threads. static void ManageDeoptimization() @@ -560,6 +567,10 @@ class Dbg { static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request) EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); + static void RequestDeoptimizationLocked(const DeoptimizationRequest& req) + EXCLUSIVE_LOCKS_REQUIRED(deoptimization_lock_) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + static Mutex* alloc_tracker_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(alloc_tracker_lock_); @@ -581,6 +592,10 @@ class Dbg { // undeoptimize when the last event is unregistered (when the counter is set to 0). static size_t full_deoptimization_event_count_ GUARDED_BY(deoptimization_lock_); + // Count the number of full undeoptimization requests delayed to next resume or end of debug + // session. + static size_t delayed_full_undeoptimization_count_ GUARDED_BY(deoptimization_lock_); + DISALLOW_COPY_AND_ASSIGN(Dbg); }; diff --git a/runtime/gc/accounting/heap_bitmap-inl.h b/runtime/gc/accounting/heap_bitmap-inl.h index ed7b427a5f..c67542f484 100644 --- a/runtime/gc/accounting/heap_bitmap-inl.h +++ b/runtime/gc/accounting/heap_bitmap-inl.h @@ -30,9 +30,8 @@ inline void HeapBitmap::Visit(const Visitor& visitor) { for (const auto& bitmap : continuous_space_bitmaps_) { bitmap->VisitMarkedRange(bitmap->HeapBegin(), bitmap->HeapLimit(), visitor); } - DCHECK(!discontinuous_space_sets_.empty()); - for (const auto& space_set : discontinuous_space_sets_) { - space_set->Visit(visitor); + for (const auto& bitmap : large_object_bitmaps_) { + bitmap->VisitMarkedRange(bitmap->HeapBegin(), bitmap->HeapLimit(), visitor); } } @@ -40,46 +39,67 @@ inline bool HeapBitmap::Test(const mirror::Object* obj) { ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj); if (LIKELY(bitmap != nullptr)) { return bitmap->Test(obj); - } else { - return GetDiscontinuousSpaceObjectSet(obj) != nullptr; } + for (const auto& bitmap : large_object_bitmaps_) { + if (LIKELY(bitmap->HasAddress(obj))) { + return bitmap->Test(obj); + } + } + LOG(FATAL) << "Invalid object " << obj; + return false; } inline void HeapBitmap::Clear(const mirror::Object* obj) { ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj); if (LIKELY(bitmap != nullptr)) { bitmap->Clear(obj); - } else { - ObjectSet* set = GetDiscontinuousSpaceObjectSet(obj); - DCHECK(set != NULL); - set->Clear(obj); + return; + } + for (const auto& bitmap : large_object_bitmaps_) { + if (LIKELY(bitmap->HasAddress(obj))) { + bitmap->Clear(obj); + } } + LOG(FATAL) << "Invalid object " << obj; } -inline void HeapBitmap::Set(const mirror::Object* obj) { +template<typename LargeObjectSetVisitor> +inline bool HeapBitmap::Set(const mirror::Object* obj, const LargeObjectSetVisitor& visitor) { ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj); - if (LIKELY(bitmap != NULL)) { - bitmap->Set(obj); - } else { - ObjectSet* set = GetDiscontinuousSpaceObjectSet(obj); - DCHECK(set != NULL); - set->Set(obj); + if (LIKELY(bitmap != nullptr)) { + return bitmap->Set(obj); + } + visitor(obj); + for (const auto& bitmap : large_object_bitmaps_) { + if (LIKELY(bitmap->HasAddress(obj))) { + return bitmap->Set(obj); + } } + LOG(FATAL) << "Invalid object " << obj; + return false; } -inline ContinuousSpaceBitmap* HeapBitmap::GetContinuousSpaceBitmap(const mirror::Object* obj) const { - for (const auto& bitmap : continuous_space_bitmaps_) { - if (bitmap->HasAddress(obj)) { - return bitmap; +template<typename LargeObjectSetVisitor> +inline bool HeapBitmap::AtomicTestAndSet(const mirror::Object* obj, + const LargeObjectSetVisitor& visitor) { + ContinuousSpaceBitmap* bitmap = GetContinuousSpaceBitmap(obj); + if (LIKELY(bitmap != nullptr)) { + return bitmap->AtomicTestAndSet(obj); + } + visitor(obj); + for (const auto& bitmap : large_object_bitmaps_) { + if (LIKELY(bitmap->HasAddress(obj))) { + return bitmap->AtomicTestAndSet(obj); } } - return nullptr; + LOG(FATAL) << "Invalid object " << obj; + return false; } -inline ObjectSet* HeapBitmap::GetDiscontinuousSpaceObjectSet(const mirror::Object* obj) const { - for (const auto& space_set : discontinuous_space_sets_) { - if (space_set->Test(obj)) { - return space_set; +inline ContinuousSpaceBitmap* HeapBitmap::GetContinuousSpaceBitmap(const mirror::Object* obj) const { + for (const auto& bitmap : continuous_space_bitmaps_) { + if (bitmap->HasAddress(obj)) { + return bitmap; } } return nullptr; diff --git a/runtime/gc/accounting/heap_bitmap.cc b/runtime/gc/accounting/heap_bitmap.cc index 1db886c06a..a5d59bfec2 100644 --- a/runtime/gc/accounting/heap_bitmap.cc +++ b/runtime/gc/accounting/heap_bitmap.cc @@ -25,61 +25,58 @@ namespace accounting { void HeapBitmap::ReplaceBitmap(ContinuousSpaceBitmap* old_bitmap, ContinuousSpaceBitmap* new_bitmap) { - for (auto& bitmap : continuous_space_bitmaps_) { - if (bitmap == old_bitmap) { - bitmap = new_bitmap; - return; - } - } - LOG(FATAL) << "bitmap " << static_cast<const void*>(old_bitmap) << " not found"; + auto it = std::find(continuous_space_bitmaps_.begin(), continuous_space_bitmaps_.end(), + old_bitmap); + CHECK(it != continuous_space_bitmaps_.end()) << " continuous space bitmap " << old_bitmap + << " not found"; + *it = new_bitmap; } -void HeapBitmap::ReplaceObjectSet(ObjectSet* old_set, ObjectSet* new_set) { - for (auto& space_set : discontinuous_space_sets_) { - if (space_set == old_set) { - space_set = new_set; - return; - } - } - LOG(FATAL) << "object set " << static_cast<const void*>(old_set) << " not found"; +void HeapBitmap::ReplaceLargeObjectBitmap(LargeObjectBitmap* old_bitmap, + LargeObjectBitmap* new_bitmap) { + auto it = std::find(large_object_bitmaps_.begin(), large_object_bitmaps_.end(), old_bitmap); + CHECK(it != large_object_bitmaps_.end()) << " large object bitmap " << old_bitmap + << " not found"; + *it = new_bitmap; } void HeapBitmap::AddContinuousSpaceBitmap(accounting::ContinuousSpaceBitmap* bitmap) { - DCHECK(bitmap != NULL); - - // Check for interval overlap. + DCHECK(bitmap != nullptr); + // Check that there is no bitmap overlap. for (const auto& cur_bitmap : continuous_space_bitmaps_) { - CHECK(!( - bitmap->HeapBegin() < cur_bitmap->HeapLimit() && - bitmap->HeapLimit() > cur_bitmap->HeapBegin())) - << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap " << cur_bitmap->Dump(); + CHECK(bitmap->HeapBegin() >= cur_bitmap->HeapLimit() || + bitmap->HeapLimit() <= cur_bitmap->HeapBegin()) + << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap " + << cur_bitmap->Dump(); } continuous_space_bitmaps_.push_back(bitmap); } void HeapBitmap::RemoveContinuousSpaceBitmap(accounting::ContinuousSpaceBitmap* bitmap) { + DCHECK(bitmap != nullptr); auto it = std::find(continuous_space_bitmaps_.begin(), continuous_space_bitmaps_.end(), bitmap); DCHECK(it != continuous_space_bitmaps_.end()); continuous_space_bitmaps_.erase(it); } -void HeapBitmap::AddDiscontinuousObjectSet(ObjectSet* set) { - DCHECK(set != nullptr); - discontinuous_space_sets_.push_back(set); +void HeapBitmap::AddLargeObjectBitmap(LargeObjectBitmap* bitmap) { + DCHECK(bitmap != nullptr); + large_object_bitmaps_.push_back(bitmap); } -void HeapBitmap::RemoveDiscontinuousObjectSet(ObjectSet* set) { - auto it = std::find(discontinuous_space_sets_.begin(), discontinuous_space_sets_.end(), set); - DCHECK(it != discontinuous_space_sets_.end()); - discontinuous_space_sets_.erase(it); +void HeapBitmap::RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap) { + DCHECK(bitmap != nullptr); + auto it = std::find(large_object_bitmaps_.begin(), large_object_bitmaps_.end(), bitmap); + DCHECK(it != large_object_bitmaps_.end()); + large_object_bitmaps_.erase(it); } void HeapBitmap::Walk(ObjectCallback* callback, void* arg) { for (const auto& bitmap : continuous_space_bitmaps_) { bitmap->Walk(callback, arg); } - for (const auto& space_set : discontinuous_space_sets_) { - space_set->Walk(callback, arg); + for (const auto& bitmap : large_object_bitmaps_) { + bitmap->Walk(callback, arg); } } diff --git a/runtime/gc/accounting/heap_bitmap.h b/runtime/gc/accounting/heap_bitmap.h index 61a24298d7..814dc0632b 100644 --- a/runtime/gc/accounting/heap_bitmap.h +++ b/runtime/gc/accounting/heap_bitmap.h @@ -33,9 +33,13 @@ class HeapBitmap { public: bool Test(const mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); void Clear(const mirror::Object* obj) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); - void Set(const mirror::Object* obj) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); + template<typename LargeObjectSetVisitor> + bool Set(const mirror::Object* obj, const LargeObjectSetVisitor& visitor) + EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) ALWAYS_INLINE; + template<typename LargeObjectSetVisitor> + bool AtomicTestAndSet(const mirror::Object* obj, const LargeObjectSetVisitor& visitor) + EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) ALWAYS_INLINE; ContinuousSpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) const; - ObjectSet* GetDiscontinuousSpaceObjectSet(const mirror::Object* obj) const; void Walk(ObjectCallback* callback, void* arg) SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); @@ -50,7 +54,7 @@ class HeapBitmap { EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); // Find and replace a object set pointer, this is used by for the bitmap swapping in the GC. - void ReplaceObjectSet(ObjectSet* old_set, ObjectSet* new_set) + void ReplaceLargeObjectBitmap(LargeObjectBitmap* old_bitmap, LargeObjectBitmap* new_bitmap) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); explicit HeapBitmap(Heap* heap) : heap_(heap) {} @@ -60,15 +64,15 @@ class HeapBitmap { void AddContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap); void RemoveContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap); - void AddDiscontinuousObjectSet(ObjectSet* set); - void RemoveDiscontinuousObjectSet(ObjectSet* set); + void AddLargeObjectBitmap(LargeObjectBitmap* bitmap); + void RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap); // Bitmaps covering continuous spaces. std::vector<ContinuousSpaceBitmap*, GcAllocator<ContinuousSpaceBitmap*>> continuous_space_bitmaps_; // Sets covering discontinuous spaces. - std::vector<ObjectSet*, GcAllocator<ObjectSet*>> discontinuous_space_sets_; + std::vector<LargeObjectBitmap*, GcAllocator<LargeObjectBitmap*>> large_object_bitmaps_; friend class art::gc::Heap; }; diff --git a/runtime/gc/accounting/space_bitmap.cc b/runtime/gc/accounting/space_bitmap.cc index 7eed05a339..31a153778d 100644 --- a/runtime/gc/accounting/space_bitmap.cc +++ b/runtime/gc/accounting/space_bitmap.cc @@ -25,22 +25,35 @@ SpaceBitmap<kAlignment>* SpaceBitmap<kAlignment>::CreateFromMemMap( const std::string& name, MemMap* mem_map, byte* heap_begin, size_t heap_capacity) { CHECK(mem_map != nullptr); uword* bitmap_begin = reinterpret_cast<uword*>(mem_map->Begin()); - size_t bitmap_size = OffsetToIndex(RoundUp(heap_capacity, kAlignment * kBitsPerWord)) * kWordSize; + const uint64_t kBytesCoveredPerWord = kAlignment * kBitsPerWord; + size_t bitmap_size = (RoundUp(static_cast<uint64_t>(heap_capacity), kBytesCoveredPerWord) / + kBytesCoveredPerWord) * kWordSize; return new SpaceBitmap(name, mem_map, bitmap_begin, bitmap_size, heap_begin); } template<size_t kAlignment> +SpaceBitmap<kAlignment>::SpaceBitmap(const std::string& name, MemMap* mem_map, uword* bitmap_begin, + size_t bitmap_size, const void* heap_begin) + : mem_map_(mem_map), bitmap_begin_(bitmap_begin), bitmap_size_(bitmap_size), + heap_begin_(reinterpret_cast<uintptr_t>(heap_begin)), + name_(name) { + CHECK(bitmap_begin_ != nullptr); + CHECK_NE(bitmap_size, 0U); +} + +template<size_t kAlignment> SpaceBitmap<kAlignment>* SpaceBitmap<kAlignment>::Create( const std::string& name, byte* heap_begin, size_t heap_capacity) { - CHECK(heap_begin != NULL); // Round up since heap_capacity is not necessarily a multiple of kAlignment * kBitsPerWord. - size_t bitmap_size = OffsetToIndex(RoundUp(heap_capacity, kAlignment * kBitsPerWord)) * kWordSize; + const uint64_t kBytesCoveredPerWord = kAlignment * kBitsPerWord; + size_t bitmap_size = (RoundUp(static_cast<uint64_t>(heap_capacity), kBytesCoveredPerWord) / + kBytesCoveredPerWord) * kWordSize; std::string error_msg; - UniquePtr<MemMap> mem_map(MemMap::MapAnonymous(name.c_str(), NULL, bitmap_size, + UniquePtr<MemMap> mem_map(MemMap::MapAnonymous(name.c_str(), nullptr, bitmap_size, PROT_READ | PROT_WRITE, false, &error_msg)); if (UNLIKELY(mem_map.get() == nullptr)) { LOG(ERROR) << "Failed to allocate bitmap " << name << ": " << error_msg; - return NULL; + return nullptr; } return CreateFromMemMap(name, mem_map.release(), heap_begin, heap_capacity); } @@ -68,13 +81,13 @@ void SpaceBitmap<kAlignment>::Clear() { } template<size_t kAlignment> -inline void SpaceBitmap<kAlignment>::CopyFrom(SpaceBitmap* source_bitmap) { +void SpaceBitmap<kAlignment>::CopyFrom(SpaceBitmap* source_bitmap) { DCHECK_EQ(Size(), source_bitmap->Size()); std::copy(source_bitmap->Begin(), source_bitmap->Begin() + source_bitmap->Size() / kWordSize, Begin()); } template<size_t kAlignment> -inline void SpaceBitmap<kAlignment>::Walk(ObjectCallback* callback, void* arg) { +void SpaceBitmap<kAlignment>::Walk(ObjectCallback* callback, void* arg) { CHECK(bitmap_begin_ != NULL); CHECK(callback != NULL); @@ -96,11 +109,11 @@ inline void SpaceBitmap<kAlignment>::Walk(ObjectCallback* callback, void* arg) { template<size_t kAlignment> void SpaceBitmap<kAlignment>::SweepWalk(const SpaceBitmap<kAlignment>& live_bitmap, - const SpaceBitmap<kAlignment>& mark_bitmap, - uintptr_t sweep_begin, uintptr_t sweep_end, - SpaceBitmap::SweepCallback* callback, void* arg) { - CHECK(live_bitmap.bitmap_begin_ != NULL); - CHECK(mark_bitmap.bitmap_begin_ != NULL); + const SpaceBitmap<kAlignment>& mark_bitmap, + uintptr_t sweep_begin, uintptr_t sweep_end, + SpaceBitmap::SweepCallback* callback, void* arg) { + CHECK(live_bitmap.bitmap_begin_ != nullptr); + CHECK(mark_bitmap.bitmap_begin_ != nullptr); CHECK_EQ(live_bitmap.heap_begin_, mark_bitmap.heap_begin_); CHECK_EQ(live_bitmap.bitmap_size_, mark_bitmap.bitmap_size_); CHECK(callback != NULL); @@ -170,8 +183,8 @@ void SpaceBitmap<kAlignment>::WalkInstanceFields(SpaceBitmap<kAlignment>* visite template<size_t kAlignment> void SpaceBitmap<kAlignment>::WalkFieldsInOrder(SpaceBitmap<kAlignment>* visited, - ObjectCallback* callback, - mirror::Object* obj, void* arg) { + ObjectCallback* callback, mirror::Object* obj, + void* arg) { if (visited->Test(obj)) { return; } @@ -232,12 +245,6 @@ void SpaceBitmap<kAlignment>::InOrderWalk(ObjectCallback* callback, void* arg) { } } -void ObjectSet::Walk(ObjectCallback* callback, void* arg) { - for (const mirror::Object* obj : contained_) { - callback(const_cast<mirror::Object*>(obj), arg); - } -} - template class SpaceBitmap<kObjectAlignment>; template class SpaceBitmap<kPageSize>; diff --git a/runtime/gc/accounting/space_bitmap.h b/runtime/gc/accounting/space_bitmap.h index b90a7998a3..df3fd37c93 100644 --- a/runtime/gc/accounting/space_bitmap.h +++ b/runtime/gc/accounting/space_bitmap.h @@ -198,10 +198,7 @@ class SpaceBitmap { // TODO: heap_end_ is initialized so that the heap bitmap is empty, this doesn't require the -1, // however, we document that this is expected on heap_end_ SpaceBitmap(const std::string& name, MemMap* mem_map, uword* bitmap_begin, size_t bitmap_size, - const void* heap_begin) - : mem_map_(mem_map), bitmap_begin_(bitmap_begin), bitmap_size_(bitmap_size), - heap_begin_(reinterpret_cast<uintptr_t>(heap_begin)), - name_(name) {} + const void* heap_begin); template<bool kSetBit> bool Modify(const mirror::Object* obj); @@ -232,71 +229,7 @@ class SpaceBitmap { std::string name_; }; -// Like a bitmap except it keeps track of objects using sets. -class ObjectSet { - public: - typedef std::set< - const mirror::Object*, std::less<const mirror::Object*>, - GcAllocator<const mirror::Object*> > Objects; - - bool IsEmpty() const { - return contained_.empty(); - } - - inline void Set(const mirror::Object* obj) { - contained_.insert(obj); - } - - inline void Clear(const mirror::Object* obj) { - Objects::iterator found = contained_.find(obj); - if (found != contained_.end()) { - contained_.erase(found); - } - } - - void Clear() { - contained_.clear(); - } - - inline bool Test(const mirror::Object* obj) const { - return contained_.find(obj) != contained_.end(); - } - - const std::string& GetName() const { - return name_; - } - - void SetName(const std::string& name) { - name_ = name; - } - - void CopyFrom(const ObjectSet& space_set) { - contained_ = space_set.contained_; - } - - void Walk(ObjectCallback* callback, void* arg) SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); - - template <typename Visitor> - void Visit(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS { - for (const mirror::Object* obj : contained_) { - visitor(const_cast<mirror::Object*>(obj)); - } - } - - explicit ObjectSet(const std::string& name) : name_(name) {} - ~ObjectSet() {} - - Objects& GetObjects() { - return contained_; - } - - private: - std::string name_; - Objects contained_; -}; - typedef SpaceBitmap<kObjectAlignment> ContinuousSpaceBitmap; -// TODO: Replace usage of ObjectSet with LargeObjectBitmap. typedef SpaceBitmap<kLargeObjectAlignment> LargeObjectBitmap; template<size_t kAlignment> diff --git a/runtime/gc/accounting/space_bitmap_test.cc b/runtime/gc/accounting/space_bitmap_test.cc index 7c180527d0..972f94d6db 100644 --- a/runtime/gc/accounting/space_bitmap_test.cc +++ b/runtime/gc/accounting/space_bitmap_test.cc @@ -110,7 +110,8 @@ class RandGen { uint32_t val_; }; -void compat_test() NO_THREAD_SAFETY_ANALYSIS { +template <size_t kAlignment> +void RunTest() NO_THREAD_SAFETY_ANALYSIS { byte* heap_begin = reinterpret_cast<byte*>(0x10000000); size_t heap_capacity = 16 * MB; @@ -123,7 +124,7 @@ void compat_test() NO_THREAD_SAFETY_ANALYSIS { ContinuousSpaceBitmap::Create("test bitmap", heap_begin, heap_capacity)); for (int j = 0; j < 10000; ++j) { - size_t offset = (r.next() % heap_capacity) & ~(0x7); + size_t offset = RoundDown(r.next() % heap_capacity, kAlignment); bool set = r.next() % 2 == 1; if (set) { @@ -137,15 +138,15 @@ void compat_test() NO_THREAD_SAFETY_ANALYSIS { size_t count = 0; SimpleCounter c(&count); - size_t offset = (r.next() % heap_capacity) & ~(0x7); + size_t offset = RoundDown(r.next() % heap_capacity, kAlignment); size_t remain = heap_capacity - offset; - size_t end = offset + ((r.next() % (remain + 1)) & ~(0x7)); + size_t end = offset + RoundDown(r.next() % (remain + 1), kAlignment); space_bitmap->VisitMarkedRange(reinterpret_cast<uintptr_t>(heap_begin) + offset, reinterpret_cast<uintptr_t>(heap_begin) + end, c); size_t manual = 0; - for (uintptr_t k = offset; k < end; k += kObjectAlignment) { + for (uintptr_t k = offset; k < end; k += kAlignment) { if (space_bitmap->Test(reinterpret_cast<mirror::Object*>(heap_begin + k))) { manual++; } @@ -156,8 +157,12 @@ void compat_test() NO_THREAD_SAFETY_ANALYSIS { } } -TEST_F(SpaceBitmapTest, Visitor) { - compat_test(); +TEST_F(SpaceBitmapTest, VisitorObjectAlignment) { + RunTest<kObjectAlignment>(); +} + +TEST_F(SpaceBitmapTest, VisitorPageAlignment) { + RunTest<kPageSize>(); } } // namespace accounting diff --git a/runtime/gc/allocator/rosalloc.cc b/runtime/gc/allocator/rosalloc.cc index cbefa6aec2..0f2d6a9fe3 100644 --- a/runtime/gc/allocator/rosalloc.cc +++ b/runtime/gc/allocator/rosalloc.cc @@ -279,7 +279,7 @@ void* RosAlloc::AllocPages(Thread* self, size_t num_pages, byte page_map_type) { return nullptr; } -void RosAlloc::FreePages(Thread* self, void* ptr) { +size_t RosAlloc::FreePages(Thread* self, void* ptr) { lock_.AssertHeld(self); size_t pm_idx = ToPageMapIndex(ptr); DCHECK_LT(pm_idx, page_map_size_); @@ -298,7 +298,7 @@ void RosAlloc::FreePages(Thread* self, void* ptr) { LOG(FATAL) << "Unreachable - RosAlloc::FreePages() : " << "pm_idx=" << pm_idx << ", pm_type=" << static_cast<int>(pm_type) << ", ptr=" << std::hex << reinterpret_cast<intptr_t>(ptr); - return; + return 0; } // Update the page map and count the number of pages. size_t num_pages = 1; @@ -422,6 +422,7 @@ void RosAlloc::FreePages(Thread* self, void* ptr) { LOG(INFO) << "RosAlloc::FreePages() : Inserted run 0x" << std::hex << reinterpret_cast<intptr_t>(fpr) << " into free_page_runs_"; } + return num_pages; } void* RosAlloc::AllocLargeObject(Thread* self, size_t size, size_t* bytes_allocated) { @@ -460,12 +461,11 @@ void* RosAlloc::AllocLargeObject(Thread* self, size_t size, size_t* bytes_alloca return r; } -void RosAlloc::FreeInternal(Thread* self, void* ptr) { +size_t RosAlloc::FreeInternal(Thread* self, void* ptr) { DCHECK_LE(base_, ptr); DCHECK_LT(ptr, base_ + footprint_); size_t pm_idx = RoundDownToPageMapIndex(ptr); - bool free_from_run = false; - Run* run = NULL; + Run* run = nullptr; { MutexLock mu(self, lock_); DCHECK_LT(pm_idx, page_map_size_); @@ -477,16 +477,14 @@ void RosAlloc::FreeInternal(Thread* self, void* ptr) { switch (page_map_[pm_idx]) { case kPageMapEmpty: LOG(FATAL) << "Unreachable - page map type: " << page_map_[pm_idx]; - return; + return 0; case kPageMapLargeObject: - FreePages(self, ptr); - return; + return FreePages(self, ptr) * kPageSize; case kPageMapLargeObjectPart: LOG(FATAL) << "Unreachable - page map type: " << page_map_[pm_idx]; - return; + return 0; case kPageMapRun: case kPageMapRunPart: { - free_from_run = true; size_t pi = pm_idx; DCHECK(page_map_[pi] == kPageMapRun || page_map_[pi] == kPageMapRunPart); // Find the beginning of the run. @@ -501,18 +499,18 @@ void RosAlloc::FreeInternal(Thread* self, void* ptr) { } default: LOG(FATAL) << "Unreachable - page map type: " << page_map_[pm_idx]; - return; + return 0; } } - if (LIKELY(free_from_run)) { - DCHECK(run != NULL); - FreeFromRun(self, ptr, run); - } + DCHECK(run != nullptr); + const size_t size = IndexToBracketSize(run->size_bracket_idx_); + FreeFromRun(self, ptr, run); + return size; } -void RosAlloc::Free(Thread* self, void* ptr) { +size_t RosAlloc::Free(Thread* self, void* ptr) { ReaderMutexLock rmu(self, bulk_free_lock_); - FreeInternal(self, ptr); + return FreeInternal(self, ptr); } RosAlloc::Run* RosAlloc::RefillRun(Thread* self, size_t idx) { @@ -1077,13 +1075,14 @@ void RosAlloc::Run::InspectAllSlots(void (*handler)(void* start, void* end, size // the page map entry won't change. Disabled for now. static constexpr bool kReadPageMapEntryWithoutLockInBulkFree = false; -void RosAlloc::BulkFree(Thread* self, void** ptrs, size_t num_ptrs) { +size_t RosAlloc::BulkFree(Thread* self, void** ptrs, size_t num_ptrs) { + size_t freed_bytes = 0; if (false) { // Used only to test Free() as GC uses only BulkFree(). for (size_t i = 0; i < num_ptrs; ++i) { - FreeInternal(self, ptrs[i]); + freed_bytes += FreeInternal(self, ptrs[i]); } - return; + return freed_bytes; } WriterMutexLock wmu(self, bulk_free_lock_); @@ -1126,14 +1125,15 @@ void RosAlloc::BulkFree(Thread* self, void** ptrs, size_t num_ptrs) { DCHECK_EQ(run->magic_num_, kMagicNum); } else if (page_map_entry == kPageMapLargeObject) { MutexLock mu(self, lock_); - FreePages(self, ptr); + freed_bytes += FreePages(self, ptr) * kPageSize; continue; } else { LOG(FATAL) << "Unreachable - page map type: " << page_map_entry; } - DCHECK(run != NULL); + DCHECK(run != nullptr); // Set the bit in the bulk free bit map. run->MarkBulkFreeBitMap(ptr); + freed_bytes += IndexToBracketSize(run->size_bracket_idx_); #ifdef HAVE_ANDROID_OS if (!run->to_be_bulk_freed_) { run->to_be_bulk_freed_ = true; @@ -1171,7 +1171,7 @@ void RosAlloc::BulkFree(Thread* self, void** ptrs, size_t num_ptrs) { run = reinterpret_cast<Run*>(base_ + pi * kPageSize); DCHECK_EQ(run->magic_num_, kMagicNum); } else if (page_map_entry == kPageMapLargeObject) { - FreePages(self, ptr); + freed_bytes += FreePages(self, ptr) * kPageSize; } else { LOG(FATAL) << "Unreachable - page map type: " << page_map_entry; } @@ -1180,6 +1180,7 @@ void RosAlloc::BulkFree(Thread* self, void** ptrs, size_t num_ptrs) { DCHECK(run != NULL); // Set the bit in the bulk free bit map. run->MarkBulkFreeBitMap(ptr); + freed_bytes += IndexToBracketSize(run->size_bracket_idx_); #ifdef HAVE_ANDROID_OS if (!run->to_be_bulk_freed_) { run->to_be_bulk_freed_ = true; @@ -1306,6 +1307,7 @@ void RosAlloc::BulkFree(Thread* self, void** ptrs, size_t num_ptrs) { } } } + return freed_bytes; } std::string RosAlloc::DumpPageMap() { diff --git a/runtime/gc/allocator/rosalloc.h b/runtime/gc/allocator/rosalloc.h index 5d9d75c22a..0c508b78a8 100644 --- a/runtime/gc/allocator/rosalloc.h +++ b/runtime/gc/allocator/rosalloc.h @@ -493,7 +493,8 @@ class RosAlloc { // Page-granularity alloc/free void* AllocPages(Thread* self, size_t num_pages, byte page_map_type) EXCLUSIVE_LOCKS_REQUIRED(lock_); - void FreePages(Thread* self, void* ptr) EXCLUSIVE_LOCKS_REQUIRED(lock_); + // Returns how many pages were freed. + size_t FreePages(Thread* self, void* ptr) EXCLUSIVE_LOCKS_REQUIRED(lock_); // Allocate/free a run slot. void* AllocFromRun(Thread* self, size_t size, size_t* bytes_allocated) @@ -506,7 +507,7 @@ class RosAlloc { Run* RefillRun(Thread* self, size_t idx) LOCKS_EXCLUDED(lock_); // The internal of non-bulk Free(). - void FreeInternal(Thread* self, void* ptr) LOCKS_EXCLUDED(lock_); + size_t FreeInternal(Thread* self, void* ptr) LOCKS_EXCLUDED(lock_); // Allocates large objects. void* AllocLargeObject(Thread* self, size_t size, size_t* bytes_allocated) LOCKS_EXCLUDED(lock_); @@ -518,9 +519,9 @@ class RosAlloc { ~RosAlloc(); void* Alloc(Thread* self, size_t size, size_t* bytes_allocated) LOCKS_EXCLUDED(lock_); - void Free(Thread* self, void* ptr) + size_t Free(Thread* self, void* ptr) LOCKS_EXCLUDED(bulk_free_lock_); - void BulkFree(Thread* self, void** ptrs, size_t num_ptrs) + size_t BulkFree(Thread* self, void** ptrs, size_t num_ptrs) LOCKS_EXCLUDED(bulk_free_lock_); // Returns the size of the allocated slot for a given allocated memory chunk. size_t UsableSize(void* ptr); diff --git a/runtime/gc/collector/garbage_collector.cc b/runtime/gc/collector/garbage_collector.cc index d99136a4ef..6380cbaaeb 100644 --- a/runtime/gc/collector/garbage_collector.cc +++ b/runtime/gc/collector/garbage_collector.cc @@ -185,12 +185,12 @@ void GarbageCollector::SwapBitmaps() { } } for (const auto& disc_space : GetHeap()->GetDiscontinuousSpaces()) { - space::LargeObjectSpace* space = down_cast<space::LargeObjectSpace*>(disc_space); - accounting::ObjectSet* live_set = space->GetLiveObjects(); - accounting::ObjectSet* mark_set = space->GetMarkObjects(); - heap_->GetLiveBitmap()->ReplaceObjectSet(live_set, mark_set); - heap_->GetMarkBitmap()->ReplaceObjectSet(mark_set, live_set); - down_cast<space::LargeObjectSpace*>(space)->SwapBitmaps(); + space::LargeObjectSpace* space = disc_space->AsLargeObjectSpace(); + accounting::LargeObjectBitmap* live_set = space->GetLiveBitmap(); + accounting::LargeObjectBitmap* mark_set = space->GetMarkBitmap(); + heap_->GetLiveBitmap()->ReplaceLargeObjectBitmap(live_set, mark_set); + heap_->GetMarkBitmap()->ReplaceLargeObjectBitmap(mark_set, live_set); + space->SwapBitmaps(); } } diff --git a/runtime/gc/collector/mark_sweep.cc b/runtime/gc/collector/mark_sweep.cc index f07e6f1c3a..8af4fd8c9c 100644 --- a/runtime/gc/collector/mark_sweep.cc +++ b/runtime/gc/collector/mark_sweep.cc @@ -99,7 +99,6 @@ MarkSweep::MarkSweep(Heap* heap, bool is_concurrent, const std::string& name_pre name_prefix + (is_concurrent ? "concurrent mark sweep": "mark sweep")), gc_barrier_(new Barrier(0)), - large_object_lock_("mark sweep large object lock", kMarkSweepLargeObjectLock), mark_stack_lock_("mark sweep mark stack lock", kMarkSweepMarkStackLock), is_concurrent_(is_concurrent) { } @@ -293,14 +292,20 @@ void MarkSweep::FindDefaultSpaceBitmap() { TimingLogger::ScopedSplit split("FindDefaultMarkBitmap", &timings_); for (const auto& space : GetHeap()->GetContinuousSpaces()) { accounting::ContinuousSpaceBitmap* bitmap = space->GetMarkBitmap(); + // We want to have the main space instead of non moving if possible. if (bitmap != nullptr && space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect) { current_space_bitmap_ = bitmap; - return; + // If we are not the non moving space exit the loop early since this will be good enough. + if (space != heap_->GetNonMovingSpace()) { + break; + } } } - GetHeap()->DumpSpaces(); - LOG(FATAL) << "Could not find a default mark bitmap"; + if (current_space_bitmap_ == nullptr) { + heap_->DumpSpaces(); + LOG(FATAL) << "Could not find a default mark bitmap"; + } } void MarkSweep::ExpandMarkStack() { @@ -322,7 +327,7 @@ void MarkSweep::ResizeMarkStack(size_t new_size) { } inline void MarkSweep::MarkObjectNonNullParallel(Object* obj) { - DCHECK(obj != NULL); + DCHECK(obj != nullptr); if (MarkObjectParallel(obj)) { MutexLock mu(Thread::Current(), mark_stack_lock_); if (UNLIKELY(mark_stack_->Size() >= mark_stack_->Capacity())) { @@ -343,6 +348,31 @@ void MarkSweep::MarkHeapReferenceCallback(mirror::HeapReference<mirror::Object>* reinterpret_cast<MarkSweep*>(arg)->MarkObject(ref->AsMirrorPtr()); } +class MarkSweepMarkObjectSlowPath { + public: + explicit MarkSweepMarkObjectSlowPath(MarkSweep* mark_sweep) : mark_sweep_(mark_sweep) { + } + + void operator()(const Object* obj) const ALWAYS_INLINE { + if (kProfileLargeObjects) { + // TODO: Differentiate between marking and testing somehow. + ++mark_sweep_->large_object_test_; + ++mark_sweep_->large_object_mark_; + } + space::LargeObjectSpace* large_object_space = mark_sweep_->GetHeap()->GetLargeObjectsSpace(); + if (UNLIKELY(!IsAligned<kPageSize>(obj) || + (kIsDebugBuild && !large_object_space->Contains(obj)))) { + LOG(ERROR) << "Tried to mark " << obj << " not contained by any spaces"; + LOG(ERROR) << "Attempting see if it's a bad root"; + mark_sweep_->VerifyRoots(); + LOG(FATAL) << "Can't mark invalid object"; + } + } + + private: + MarkSweep* const mark_sweep_; +}; + inline void MarkSweep::MarkObjectNonNull(Object* obj) { DCHECK(obj != nullptr); if (kUseBakerOrBrooksReadBarrier) { @@ -353,27 +383,24 @@ inline void MarkSweep::MarkObjectNonNull(Object* obj) { if (kCountMarkedObjects) { ++mark_immune_count_; } - DCHECK(IsMarked(obj)); - return; - } - // Try to take advantage of locality of references within a space, failing this find the space - // the hard way. - accounting::ContinuousSpaceBitmap* object_bitmap = current_space_bitmap_; - if (UNLIKELY(!object_bitmap->HasAddress(obj))) { - object_bitmap = mark_bitmap_->GetContinuousSpaceBitmap(obj); + DCHECK(mark_bitmap_->Test(obj)); + } else if (LIKELY(current_space_bitmap_->HasAddress(obj))) { + if (kCountMarkedObjects) { + ++mark_fastpath_count_; + } + if (UNLIKELY(!current_space_bitmap_->Set(obj))) { + PushOnMarkStack(obj); // This object was not previously marked. + } + } else { if (kCountMarkedObjects) { ++mark_slowpath_count_; } - if (UNLIKELY(object_bitmap == nullptr)) { - MarkLargeObject(obj, true); - return; + MarkSweepMarkObjectSlowPath visitor(this); + // TODO: We already know that the object is not in the current_space_bitmap_ but MarkBitmap::Set + // will check again. + if (!mark_bitmap_->Set(obj, visitor)) { + PushOnMarkStack(obj); // Was not already marked, push. } - } else if (kCountMarkedObjects) { - ++mark_fastpath_count_; - } - // This object was not previously marked. - if (!object_bitmap->Set(obj)) { - PushOnMarkStack(obj); } } @@ -387,34 +414,6 @@ inline void MarkSweep::PushOnMarkStack(Object* obj) { mark_stack_->PushBack(obj); } -// Rare case, probably not worth inlining since it will increase instruction cache miss rate. -bool MarkSweep::MarkLargeObject(const Object* obj, bool set) { - // TODO: support >1 discontinuous space. - space::LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); - accounting::ObjectSet* large_objects = large_object_space->GetMarkObjects(); - if (kProfileLargeObjects) { - ++large_object_test_; - } - if (UNLIKELY(!large_objects->Test(obj))) { - if (!large_object_space->Contains(obj)) { - LOG(ERROR) << "Tried to mark " << obj << " not contained by any spaces"; - LOG(ERROR) << "Attempting see if it's a bad root"; - VerifyRoots(); - LOG(FATAL) << "Can't mark bad root"; - } - if (kProfileLargeObjects) { - ++large_object_mark_; - } - if (set) { - large_objects->Set(obj); - } else { - large_objects->Clear(obj); - } - return true; - } - return false; -} - inline bool MarkSweep::MarkObjectParallel(const Object* obj) { DCHECK(obj != nullptr); if (kUseBakerOrBrooksReadBarrier) { @@ -428,19 +427,11 @@ inline bool MarkSweep::MarkObjectParallel(const Object* obj) { // Try to take advantage of locality of references within a space, failing this find the space // the hard way. accounting::ContinuousSpaceBitmap* object_bitmap = current_space_bitmap_; - if (UNLIKELY(!object_bitmap->HasAddress(obj))) { - accounting::ContinuousSpaceBitmap* new_bitmap = mark_bitmap_->GetContinuousSpaceBitmap(obj); - if (new_bitmap != NULL) { - object_bitmap = new_bitmap; - } else { - // TODO: Remove the Thread::Current here? - // TODO: Convert this to some kind of atomic marking? - MutexLock mu(Thread::Current(), large_object_lock_); - return MarkLargeObject(obj, true); - } + if (LIKELY(object_bitmap->HasAddress(obj))) { + return !object_bitmap->AtomicTestAndSet(obj); } - // Return true if the object was not previously marked. - return !object_bitmap->AtomicTestAndSet(obj); + MarkSweepMarkObjectSlowPath visitor(this); + return !mark_bitmap_->AtomicTestAndSet(obj, visitor); } // Used to mark objects when processing the mark stack. If an object is null, it is not marked. @@ -719,7 +710,7 @@ class CardScanTask : public MarkStackTask<false> { size_t MarkSweep::GetThreadCount(bool paused) const { if (heap_->GetThreadPool() == nullptr || !heap_->CareAboutPauseTimes()) { - return 0; + return 1; } if (paused) { return heap_->GetParallelGCThreadCount() + 1; @@ -733,7 +724,7 @@ void MarkSweep::ScanGrayObjects(bool paused, byte minimum_age) { ThreadPool* thread_pool = GetHeap()->GetThreadPool(); size_t thread_count = GetThreadCount(paused); // The parallel version with only one thread is faster for card scanning, TODO: fix. - if (kParallelCardScan && thread_count > 0) { + if (kParallelCardScan && thread_count > 1) { Thread* self = Thread::Current(); // Can't have a different split for each space since multiple spaces can have their cards being // scanned at the same time. @@ -944,14 +935,11 @@ mirror::Object* MarkSweep::VerifySystemWeakIsLiveCallback(Object* obj, void* arg void MarkSweep::VerifyIsLive(const Object* obj) { if (!heap_->GetLiveBitmap()->Test(obj)) { - space::LargeObjectSpace* large_object_space = heap_->GetLargeObjectsSpace(); - if (!large_object_space->GetLiveObjects()->Test(obj)) { - if (std::find(heap_->allocation_stack_->Begin(), heap_->allocation_stack_->End(), obj) == - heap_->allocation_stack_->End()) { - // Object not found! - heap_->DumpSpaces(); - LOG(FATAL) << "Found dead object " << obj; - } + if (std::find(heap_->allocation_stack_->Begin(), heap_->allocation_stack_->End(), obj) == + heap_->allocation_stack_->End()) { + // Object not found! + heap_->DumpSpaces(); + LOG(FATAL) << "Found dead object " << obj; } } } @@ -1086,8 +1074,8 @@ void MarkSweep::SweepArray(accounting::ObjectStack* allocations, bool swap_bitma } // Handle the large object space. space::LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); - accounting::ObjectSet* large_live_objects = large_object_space->GetLiveObjects(); - accounting::ObjectSet* large_mark_objects = large_object_space->GetMarkObjects(); + accounting::LargeObjectBitmap* large_live_objects = large_object_space->GetLiveBitmap(); + accounting::LargeObjectBitmap* large_mark_objects = large_object_space->GetMarkBitmap(); if (swap_bitmaps) { std::swap(large_live_objects, large_mark_objects); } @@ -1131,7 +1119,6 @@ void MarkSweep::Sweep(bool swap_bitmaps) { timings_.EndSplit(); DCHECK(mark_stack_->IsEmpty()); - TimingLogger::ScopedSplit("Sweep", &timings_); for (const auto& space : GetHeap()->GetContinuousSpaces()) { if (space->IsContinuousMemMapAllocSpace()) { space::ContinuousMemMapAllocSpace* alloc_space = space->AsContinuousMemMapAllocSpace(); @@ -1149,13 +1136,13 @@ void MarkSweep::Sweep(bool swap_bitmaps) { } void MarkSweep::SweepLargeObjects(bool swap_bitmaps) { - TimingLogger::ScopedSplit("SweepLargeObjects", &timings_); + TimingLogger::ScopedSplit split("SweepLargeObjects", &timings_); size_t freed_objects = 0; size_t freed_bytes = 0; - GetHeap()->GetLargeObjectsSpace()->Sweep(swap_bitmaps, &freed_objects, &freed_bytes); + heap_->GetLargeObjectsSpace()->Sweep(swap_bitmaps, &freed_objects, &freed_bytes); freed_large_objects_.FetchAndAdd(freed_objects); freed_large_object_bytes_.FetchAndAdd(freed_bytes); - GetHeap()->RecordFree(freed_objects, freed_bytes); + heap_->RecordFree(freed_objects, freed_bytes); } // Process the "referent" field in a java.lang.ref.Reference. If the referent has not yet been diff --git a/runtime/gc/collector/mark_sweep.h b/runtime/gc/collector/mark_sweep.h index 6dbb2709d2..41a7764ca8 100644 --- a/runtime/gc/collector/mark_sweep.h +++ b/runtime/gc/collector/mark_sweep.h @@ -227,11 +227,6 @@ class MarkSweep : public GarbageCollector { // Marks an object atomically, safe to use from multiple threads. void MarkObjectNonNullParallel(mirror::Object* obj); - // Marks or unmarks a large object based on whether or not set is true. If set is true, then we - // mark, otherwise we unmark. - bool MarkLargeObject(const mirror::Object* obj, bool set) - EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) LOCKS_EXCLUDED(large_object_lock_); - // Returns true if we need to add obj to a mark stack. bool MarkObjectParallel(const mirror::Object* obj) NO_THREAD_SAFETY_ANALYSIS; @@ -315,7 +310,6 @@ class MarkSweep : public GarbageCollector { size_t live_stack_freeze_size_; UniquePtr<Barrier> gc_barrier_; - Mutex large_object_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; Mutex mark_stack_lock_ ACQUIRED_AFTER(Locks::classlinker_classes_lock_); const bool is_concurrent_; @@ -326,8 +320,6 @@ class MarkSweep : public GarbageCollector { friend class CheckBitmapVisitor; friend class CheckReferenceVisitor; friend class art::gc::Heap; - friend class InternTableEntryIsUnmarked; - friend class MarkIfReachesAllocspaceVisitor; friend class MarkObjectVisitor; friend class ModUnionCheckReferences; friend class ModUnionClearCardVisitor; @@ -336,10 +328,9 @@ class MarkSweep : public GarbageCollector { friend class ModUnionTableBitmap; friend class ModUnionTableReferenceCache; friend class ModUnionScanImageRootVisitor; - friend class ScanBitmapVisitor; - friend class ScanImageRootVisitor; template<bool kUseFinger> friend class MarkStackTask; friend class FifoMarkStackChunk; + friend class MarkSweepMarkObjectSlowPath; DISALLOW_COPY_AND_ASSIGN(MarkSweep); }; diff --git a/runtime/gc/collector/semi_space-inl.h b/runtime/gc/collector/semi_space-inl.h index d03baf143c..55140f613a 100644 --- a/runtime/gc/collector/semi_space-inl.h +++ b/runtime/gc/collector/semi_space-inl.h @@ -26,6 +26,21 @@ namespace art { namespace gc { namespace collector { +class BitmapSetSlowPathVisitor { + public: + explicit BitmapSetSlowPathVisitor(SemiSpace* semi_space) : semi_space_(semi_space) { + } + + void operator()(const mirror::Object* obj) const { + CHECK(!semi_space_->to_space_->HasAddress(obj)) << "Marking " << obj << " in to_space_"; + // Marking a large object, make sure its aligned as a sanity check. + CHECK(IsAligned<kPageSize>(obj)); + } + + private: + SemiSpace* const semi_space_; +}; + inline mirror::Object* SemiSpace::GetForwardingAddressInFromSpace(mirror::Object* obj) const { DCHECK(from_space_->HasAddress(obj)); LockWord lock_word = obj->GetLockWord(false); @@ -53,7 +68,7 @@ inline void SemiSpace::MarkObject( if (from_space_->HasAddress(obj)) { mirror::Object* forward_address = GetForwardingAddressInFromSpace(obj); // If the object has already been moved, return the new forward address. - if (forward_address == nullptr) { + if (UNLIKELY(forward_address == nullptr)) { forward_address = MarkNonForwardedObject(obj); DCHECK(forward_address != nullptr); // Make sure to only update the forwarding address AFTER you copy the object so that the @@ -65,25 +80,17 @@ inline void SemiSpace::MarkObject( } obj_ptr->Assign(forward_address); } else { - accounting::ContinuousSpaceBitmap* object_bitmap = - heap_->GetMarkBitmap()->GetContinuousSpaceBitmap(obj); - if (LIKELY(object_bitmap != nullptr)) { - if (generational_) { - // If a bump pointer space only collection, we should not - // reach here as we don't/won't mark the objects in the - // non-moving space (except for the promoted objects.) Note - // the non-moving space is added to the immune space. - DCHECK(whole_heap_collection_); - } - if (!object_bitmap->Set(obj)) { - // This object was not previously marked. - MarkStackPush(obj); - } - } else { - CHECK(!to_space_->HasAddress(obj)) << "Marking " << obj << " in to_space_"; - if (MarkLargeObject(obj)) { - MarkStackPush(obj); - } + BitmapSetSlowPathVisitor visitor(this); + if (kIsDebugBuild && mark_bitmap_->GetContinuousSpaceBitmap(obj) != nullptr) { + // If a bump pointer space only collection, we should not + // reach here as we don't/won't mark the objects in the + // non-moving space (except for the promoted objects.) Note + // the non-moving space is added to the immune space. + DCHECK(!generational_ || whole_heap_collection_); + } + if (!mark_bitmap_->Set(obj, visitor)) { + // This object was not previously marked. + MarkStackPush(obj); } } } diff --git a/runtime/gc/collector/semi_space.cc b/runtime/gc/collector/semi_space.cc index 4a1bf18b48..b67bbb12fe 100644 --- a/runtime/gc/collector/semi_space.cc +++ b/runtime/gc/collector/semi_space.cc @@ -126,6 +126,11 @@ void SemiSpace::InitializePhase() { CHECK(from_space_->CanMoveObjects()) << "Attempting to move from " << *from_space_; // Set the initial bitmap. to_space_live_bitmap_ = to_space_->GetLiveBitmap(); + { + // TODO: I don't think we should need heap bitmap lock to get the mark bitmap. + ReaderMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_); + mark_bitmap_ = heap_->GetMarkBitmap(); + } } void SemiSpace::ProcessReferences(Thread* self) { @@ -314,8 +319,8 @@ void SemiSpace::MarkReachableObjects() { accounting::ObjectStack* live_stack = heap_->GetLiveStack(); heap_->MarkAllocStackAsLive(live_stack); live_stack->Reset(); - timings_.EndSplit(); + timings_.NewSplit("UpdateAndMarkRememberedSets"); for (auto& space : heap_->GetContinuousSpaces()) { // If the space is immune and has no mod union table (the // non-moving space when the bump pointer space only collection is @@ -353,6 +358,7 @@ void SemiSpace::MarkReachableObjects() { } if (is_large_object_space_immune_) { + timings_.NewSplit("VisitLargeObjects"); DCHECK(generational_ && !whole_heap_collection_); // Delay copying the live set to the marked set until here from // BindBitmaps() as the large objects on the allocation stack may @@ -364,13 +370,13 @@ void SemiSpace::MarkReachableObjects() { // classes (primitive array classes) that could move though they // don't contain any other references. space::LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); - accounting::ObjectSet* large_live_objects = large_object_space->GetLiveObjects(); + accounting::LargeObjectBitmap* large_live_bitmap = large_object_space->GetLiveBitmap(); SemiSpaceScanObjectVisitor visitor(this); - for (const Object* obj : large_live_objects->GetObjects()) { - visitor(const_cast<Object*>(obj)); - } + large_live_bitmap->VisitMarkedRange(reinterpret_cast<uintptr_t>(large_object_space->Begin()), + reinterpret_cast<uintptr_t>(large_object_space->End()), + visitor); } - + timings_.EndSplit(); // Recursively process the mark stack. ProcessMarkStack(); } @@ -452,19 +458,6 @@ inline void SemiSpace::MarkStackPush(Object* obj) { mark_stack_->PushBack(obj); } -// Rare case, probably not worth inlining since it will increase instruction cache miss rate. -bool SemiSpace::MarkLargeObject(const Object* obj) { - // TODO: support >1 discontinuous space. - space::LargeObjectSpace* large_object_space = GetHeap()->GetLargeObjectsSpace(); - DCHECK(large_object_space->Contains(obj)); - accounting::ObjectSet* large_objects = large_object_space->GetMarkObjects(); - if (UNLIKELY(!large_objects->Test(obj))) { - large_objects->Set(obj); - return true; - } - return false; -} - static inline size_t CopyAvoidingDirtyingPages(void* dest, const void* src, size_t size) { if (LIKELY(size <= static_cast<size_t>(kPageSize))) { // We will dirty the current page and somewhere in the middle of the next page. This means diff --git a/runtime/gc/collector/semi_space.h b/runtime/gc/collector/semi_space.h index b6726b2c11..3d635f0af4 100644 --- a/runtime/gc/collector/semi_space.h +++ b/runtime/gc/collector/semi_space.h @@ -201,6 +201,8 @@ class SemiSpace : public GarbageCollector { // Cached live bitmap as an optimization. accounting::ContinuousSpaceBitmap* to_space_live_bitmap_; space::ContinuousMemMapAllocSpace* from_space_; + // Cached mark bitmap as an optimization. + accounting::HeapBitmap* mark_bitmap_; Thread* self_; @@ -248,6 +250,7 @@ class SemiSpace : public GarbageCollector { static constexpr int kDefaultWholeHeapCollectionInterval = 5; private: + friend class BitmapSetSlowPathVisitor; DISALLOW_COPY_AND_ASSIGN(SemiSpace); }; diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index de7d0b85b0..517c748771 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -355,15 +355,15 @@ void Heap::CreateMainMallocSpace(MemMap* mem_map, size_t initial_size, size_t gr } if (kUseRosAlloc) { main_space_ = space::RosAllocSpace::CreateFromMemMap(mem_map, "main rosalloc space", - kDefaultStartingSize, initial_size, - growth_limit, capacity, low_memory_mode_, - can_move_objects); + kDefaultStartingSize, initial_size, + growth_limit, capacity, low_memory_mode_, + can_move_objects); CHECK(main_space_ != nullptr) << "Failed to create rosalloc space"; } else { main_space_ = space::DlMallocSpace::CreateFromMemMap(mem_map, "main dlmalloc space", - kDefaultStartingSize, initial_size, - growth_limit, capacity, - can_move_objects); + kDefaultStartingSize, initial_size, + growth_limit, capacity, + can_move_objects); CHECK(main_space_ != nullptr) << "Failed to create dlmalloc space"; } main_space_->SetFootprintLimit(main_space_->Capacity()); @@ -569,7 +569,7 @@ void Heap::MarkAllocStackAsLive(accounting::ObjectStack* stack) { space2 = space1; } MarkAllocStack(space1->GetLiveBitmap(), space2->GetLiveBitmap(), - large_object_space_->GetLiveObjects(), stack); + large_object_space_->GetLiveBitmap(), stack); } void Heap::DeleteThreadPool() { @@ -606,10 +606,8 @@ void Heap::AddSpace(space::Space* space, bool set_as_default) { } else { DCHECK(space->IsDiscontinuousSpace()); space::DiscontinuousSpace* discontinuous_space = space->AsDiscontinuousSpace(); - DCHECK(discontinuous_space->GetLiveObjects() != nullptr); - live_bitmap_->AddDiscontinuousObjectSet(discontinuous_space->GetLiveObjects()); - DCHECK(discontinuous_space->GetMarkObjects() != nullptr); - mark_bitmap_->AddDiscontinuousObjectSet(discontinuous_space->GetMarkObjects()); + live_bitmap_->AddLargeObjectBitmap(discontinuous_space->GetLiveBitmap()); + mark_bitmap_->AddLargeObjectBitmap(discontinuous_space->GetMarkBitmap()); discontinuous_spaces_.push_back(discontinuous_space); } if (space->IsAllocSpace()) { @@ -649,10 +647,8 @@ void Heap::RemoveSpace(space::Space* space) { } else { DCHECK(space->IsDiscontinuousSpace()); space::DiscontinuousSpace* discontinuous_space = space->AsDiscontinuousSpace(); - DCHECK(discontinuous_space->GetLiveObjects() != nullptr); - live_bitmap_->RemoveDiscontinuousObjectSet(discontinuous_space->GetLiveObjects()); - DCHECK(discontinuous_space->GetMarkObjects() != nullptr); - mark_bitmap_->RemoveDiscontinuousObjectSet(discontinuous_space->GetMarkObjects()); + live_bitmap_->RemoveLargeObjectBitmap(discontinuous_space->GetLiveBitmap()); + mark_bitmap_->RemoveLargeObjectBitmap(discontinuous_space->GetMarkBitmap()); auto it = std::find(discontinuous_spaces_.begin(), discontinuous_spaces_.end(), discontinuous_space); DCHECK(it != discontinuous_spaces_.end()); @@ -1050,7 +1046,7 @@ bool Heap::IsLiveObjectLocked(mirror::Object* obj, bool search_allocation_stack, return temp_space_->Contains(obj); } space::ContinuousSpace* c_space = FindContinuousSpaceFromObject(obj, true); - space::DiscontinuousSpace* d_space = NULL; + space::DiscontinuousSpace* d_space = nullptr; if (c_space != nullptr) { if (c_space->GetLiveBitmap()->Test(obj)) { return true; @@ -1058,7 +1054,7 @@ bool Heap::IsLiveObjectLocked(mirror::Object* obj, bool search_allocation_stack, } else { d_space = FindDiscontinuousSpaceFromObject(obj, true); if (d_space != nullptr) { - if (d_space->GetLiveObjects()->Test(obj)) { + if (d_space->GetLiveBitmap()->Test(obj)) { return true; } } @@ -1096,7 +1092,7 @@ bool Heap::IsLiveObjectLocked(mirror::Object* obj, bool search_allocation_stack, } } else { d_space = FindDiscontinuousSpaceFromObject(obj, true); - if (d_space != nullptr && d_space->GetLiveObjects()->Test(obj)) { + if (d_space != nullptr && d_space->GetLiveBitmap()->Test(obj)) { return true; } } @@ -1436,6 +1432,11 @@ void Heap::TransitionCollector(CollectorType collector_type) { if (collector_type == collector_type_) { return; } + if (Runtime::Current()->IsShuttingDown(self)) { + // Don't allow heap transitions to happen if the runtime is shutting down since these can + // cause objects to get finalized. + return; + } // GC can be disabled if someone has a used GetPrimitiveArrayCritical but not yet released. if (!copying_transition || disable_moving_gc_count_ == 0) { // TODO: Not hard code in semi-space collector? @@ -1761,7 +1762,7 @@ void Heap::FlushAllocStack() { void Heap::MarkAllocStack(accounting::ContinuousSpaceBitmap* bitmap1, accounting::ContinuousSpaceBitmap* bitmap2, - accounting::ObjectSet* large_objects, + accounting::LargeObjectBitmap* large_objects, accounting::ObjectStack* stack) { DCHECK(bitmap1 != nullptr); DCHECK(bitmap2 != nullptr); @@ -2888,7 +2889,7 @@ void Heap::ClearMarkedObjects() { } // Clear the marked objects in the discontinous space object sets. for (const auto& space : GetDiscontinuousSpaces()) { - space->GetMarkObjects()->Clear(); + space->GetMarkBitmap()->Clear(); } } diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h index 35724e3b5f..ceba8b6834 100644 --- a/runtime/gc/heap.h +++ b/runtime/gc/heap.h @@ -55,7 +55,6 @@ namespace gc { namespace accounting { class HeapBitmap; class ModUnionTable; - class ObjectSet; class RememberedSet; } // namespace accounting @@ -477,7 +476,8 @@ class Heap { // TODO: Refactor? void MarkAllocStack(accounting::SpaceBitmap<kObjectAlignment>* bitmap1, accounting::SpaceBitmap<kObjectAlignment>* bitmap2, - accounting::ObjectSet* large_objects, accounting::ObjectStack* stack) + accounting::SpaceBitmap<kLargeObjectAlignment>* large_objects, + accounting::ObjectStack* stack) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); // Mark the specified allocation stack as live. diff --git a/runtime/gc/space/large_object_space.cc b/runtime/gc/space/large_object_space.cc index 0b353c7f17..ce11b3d72c 100644 --- a/runtime/gc/space/large_object_space.cc +++ b/runtime/gc/space/large_object_space.cc @@ -16,12 +16,14 @@ #include "large_object_space.h" +#include "gc/accounting/space_bitmap-inl.h" #include "base/logging.h" #include "base/mutex-inl.h" #include "base/stl_util.h" #include "UniquePtr.h" #include "image.h" #include "os.h" +#include "space-inl.h" #include "thread-inl.h" #include "utils.h" @@ -74,26 +76,27 @@ class ValgrindLargeObjectMapSpace FINAL : public LargeObjectMapSpace { }; void LargeObjectSpace::SwapBitmaps() { - live_objects_.swap(mark_objects_); + live_bitmap_.swap(mark_bitmap_); // Swap names to get more descriptive diagnostics. - std::string temp_name = live_objects_->GetName(); - live_objects_->SetName(mark_objects_->GetName()); - mark_objects_->SetName(temp_name); + std::string temp_name = live_bitmap_->GetName(); + live_bitmap_->SetName(mark_bitmap_->GetName()); + mark_bitmap_->SetName(temp_name); } -LargeObjectSpace::LargeObjectSpace(const std::string& name) +LargeObjectSpace::LargeObjectSpace(const std::string& name, byte* begin, byte* end) : DiscontinuousSpace(name, kGcRetentionPolicyAlwaysCollect), num_bytes_allocated_(0), num_objects_allocated_(0), total_bytes_allocated_(0), - total_objects_allocated_(0) { + total_objects_allocated_(0), begin_(begin), end_(end) { } void LargeObjectSpace::CopyLiveToMarked() { - mark_objects_->CopyFrom(*live_objects_.get()); + mark_bitmap_->CopyFrom(live_bitmap_.get()); } +// TODO: Use something cleaner than 0xFFFFFFFF. LargeObjectMapSpace::LargeObjectMapSpace(const std::string& name) - : LargeObjectSpace(name), + : LargeObjectSpace(name, reinterpret_cast<byte*>(0xFFFFFFFF), nullptr), lock_("large object map space lock", kAllocSpaceLock) {} LargeObjectMapSpace* LargeObjectMapSpace::Create(const std::string& name) { @@ -118,7 +121,9 @@ mirror::Object* LargeObjectMapSpace::Alloc(Thread* self, size_t num_bytes, large_objects_.push_back(obj); mem_maps_.Put(obj, mem_map); size_t allocation_size = mem_map->Size(); - DCHECK(bytes_allocated != NULL); + DCHECK(bytes_allocated != nullptr); + begin_ = std::min(begin_, reinterpret_cast<byte*>(obj)); + end_ = std::max(end_, reinterpret_cast<byte*>(obj) + allocation_size); *bytes_allocated = allocation_size; if (usable_size != nullptr) { *usable_size = allocation_size; @@ -191,9 +196,7 @@ FreeListSpace* FreeListSpace::Create(const std::string& name, byte* requested_be } FreeListSpace::FreeListSpace(const std::string& name, MemMap* mem_map, byte* begin, byte* end) - : LargeObjectSpace(name), - begin_(begin), - end_(end), + : LargeObjectSpace(name, begin, end), mem_map_(mem_map), lock_("free list space lock", kAllocSpaceLock) { free_end_ = end - begin; @@ -389,27 +392,41 @@ void FreeListSpace::Dump(std::ostream& os) const { } } -void LargeObjectSpace::Sweep(bool swap_bitmaps, size_t* freed_objects, size_t* freed_bytes) { - // Sweep large objects - accounting::ObjectSet* large_live_objects = GetLiveObjects(); - accounting::ObjectSet* large_mark_objects = GetMarkObjects(); - if (swap_bitmaps) { - std::swap(large_live_objects, large_mark_objects); - } - DCHECK(freed_objects != nullptr); - DCHECK(freed_bytes != nullptr); - // O(n*log(n)) but hopefully there are not too many large objects. - size_t objects = 0; - size_t bytes = 0; - Thread* self = Thread::Current(); - for (const mirror::Object* obj : large_live_objects->GetObjects()) { - if (!large_mark_objects->Test(obj)) { - bytes += Free(self, const_cast<mirror::Object*>(obj)); - ++objects; +void LargeObjectSpace::SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg) { + SweepCallbackContext* context = static_cast<SweepCallbackContext*>(arg); + space::LargeObjectSpace* space = context->space->AsLargeObjectSpace(); + Thread* self = context->self; + Locks::heap_bitmap_lock_->AssertExclusiveHeld(self); + // If the bitmaps aren't swapped we need to clear the bits since the GC isn't going to re-swap + // the bitmaps as an optimization. + if (!context->swap_bitmaps) { + accounting::LargeObjectBitmap* bitmap = space->GetLiveBitmap(); + for (size_t i = 0; i < num_ptrs; ++i) { + bitmap->Clear(ptrs[i]); } } - *freed_objects += objects; - *freed_bytes += bytes; + context->freed_objects += num_ptrs; + context->freed_bytes += space->FreeList(self, num_ptrs, ptrs); +} + +void LargeObjectSpace::Sweep(bool swap_bitmaps, size_t* out_freed_objects, + size_t* out_freed_bytes) { + if (Begin() >= End()) { + return; + } + accounting::LargeObjectBitmap* live_bitmap = GetLiveBitmap(); + accounting::LargeObjectBitmap* mark_bitmap = GetMarkBitmap(); + if (swap_bitmaps) { + std::swap(live_bitmap, mark_bitmap); + } + DCHECK(out_freed_objects != nullptr); + DCHECK(out_freed_bytes != nullptr); + SweepCallbackContext scc(swap_bitmaps, this); + accounting::LargeObjectBitmap::SweepWalk(*live_bitmap, *mark_bitmap, + reinterpret_cast<uintptr_t>(Begin()), + reinterpret_cast<uintptr_t>(End()), SweepCallback, &scc); + *out_freed_objects += scc.freed_objects; + *out_freed_bytes += scc.freed_bytes; } } // namespace space diff --git a/runtime/gc/space/large_object_space.h b/runtime/gc/space/large_object_space.h index 18e518f4cd..0daefba0d9 100644 --- a/runtime/gc/space/large_object_space.h +++ b/runtime/gc/space/large_object_space.h @@ -49,11 +49,11 @@ class LargeObjectSpace : public DiscontinuousSpace, public AllocSpace { return num_objects_allocated_; } - uint64_t GetTotalBytesAllocated() { + uint64_t GetTotalBytesAllocated() const { return total_bytes_allocated_; } - uint64_t GetTotalObjectsAllocated() { + uint64_t GetTotalObjectsAllocated() const { return total_objects_allocated_; } @@ -73,20 +73,36 @@ class LargeObjectSpace : public DiscontinuousSpace, public AllocSpace { return this; } - void Sweep(bool swap_bitmaps, size_t* freed_objects, size_t* freed_bytes); + void Sweep(bool swap_bitmaps, size_t* out_freed_objects, size_t* out_freed_bytes); virtual bool CanMoveObjects() const OVERRIDE { return false; } + // Current address at which the space begins, which may vary as the space is filled. + byte* Begin() const { + return begin_; + } + + // Current address at which the space ends, which may vary as the space is filled. + byte* End() const { + return end_; + } + protected: - explicit LargeObjectSpace(const std::string& name); + explicit LargeObjectSpace(const std::string& name, byte* begin, byte* end); + + static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg); // Approximate number of bytes which have been allocated into the space. - size_t num_bytes_allocated_; - size_t num_objects_allocated_; - size_t total_bytes_allocated_; - size_t total_objects_allocated_; + uint64_t num_bytes_allocated_; + uint64_t num_objects_allocated_; + uint64_t total_bytes_allocated_; + uint64_t total_objects_allocated_; + + // Begin and end, may change as more large objects are allocated. + byte* begin_; + byte* end_; friend class Space; @@ -242,9 +258,6 @@ class FreeListSpace FINAL : public LargeObjectSpace { typedef std::set<AllocationHeader*, AllocationHeader::SortByPrevFree, accounting::GcAllocator<AllocationHeader*> > FreeBlocks; - byte* const begin_; - byte* const end_; - // There is not footer for any allocations at the end of the space, so we keep track of how much // free space there is at the end manually. UniquePtr<MemMap> mem_map_; diff --git a/runtime/gc/space/malloc_space.cc b/runtime/gc/space/malloc_space.cc index eaf14fb7d0..7493c19a94 100644 --- a/runtime/gc/space/malloc_space.cc +++ b/runtime/gc/space/malloc_space.cc @@ -226,7 +226,6 @@ void MallocSpace::Dump(std::ostream& os) const { void MallocSpace::SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg) { SweepCallbackContext* context = static_cast<SweepCallbackContext*>(arg); - DCHECK(context->space->IsMallocSpace()); space::MallocSpace* space = context->space->AsMallocSpace(); Thread* self = context->self; Locks::heap_bitmap_lock_->AssertExclusiveHeld(self); diff --git a/runtime/gc/space/rosalloc_space.cc b/runtime/gc/space/rosalloc_space.cc index 5a7d941b4a..a5a6da0bdf 100644 --- a/runtime/gc/space/rosalloc_space.cc +++ b/runtime/gc/space/rosalloc_space.cc @@ -33,6 +33,10 @@ namespace gc { namespace space { static constexpr bool kPrefetchDuringRosAllocFreeList = true; +static constexpr size_t kPrefetchLookAhead = 8; +// Use this only for verification, it is not safe to use since the class of the object may have +// been freed. +static constexpr bool kVerifyFreedBytes = false; // TODO: Fix // template class ValgrindMallocSpace<RosAllocSpace, allocator::RosAlloc*>; @@ -172,27 +176,24 @@ size_t RosAllocSpace::Free(Thread* self, mirror::Object* ptr) { CHECK(ptr != NULL); CHECK(Contains(ptr)) << "Free (" << ptr << ") not in bounds of heap " << *this; } - const size_t bytes_freed = AllocationSizeNonvirtual(ptr, nullptr); if (kRecentFreeCount > 0) { MutexLock mu(self, lock_); RegisterRecentFree(ptr); } - rosalloc_->Free(self, ptr); - return bytes_freed; + return rosalloc_->Free(self, ptr); } size_t RosAllocSpace::FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) { - DCHECK(ptrs != NULL); + DCHECK(ptrs != nullptr); - // Don't need the lock to calculate the size of the freed pointers. - size_t bytes_freed = 0; + size_t verify_bytes = 0; for (size_t i = 0; i < num_ptrs; i++) { - mirror::Object* ptr = ptrs[i]; - const size_t look_ahead = 8; - if (kPrefetchDuringRosAllocFreeList && i + look_ahead < num_ptrs) { - __builtin_prefetch(reinterpret_cast<char*>(ptrs[i + look_ahead])); + if (kPrefetchDuringRosAllocFreeList && i + kPrefetchLookAhead < num_ptrs) { + __builtin_prefetch(reinterpret_cast<char*>(ptrs[i + kPrefetchLookAhead])); + } + if (kVerifyFreedBytes) { + verify_bytes += AllocationSizeNonvirtual(ptrs[i], nullptr); } - bytes_freed += AllocationSizeNonvirtual(ptr, nullptr); } if (kRecentFreeCount > 0) { @@ -216,7 +217,10 @@ size_t RosAllocSpace::FreeList(Thread* self, size_t num_ptrs, mirror::Object** p CHECK_EQ(num_broken_ptrs, 0u); } - rosalloc_->BulkFree(self, reinterpret_cast<void**>(ptrs), num_ptrs); + const size_t bytes_freed = rosalloc_->BulkFree(self, reinterpret_cast<void**>(ptrs), num_ptrs); + if (kVerifyFreedBytes) { + CHECK_EQ(verify_bytes, bytes_freed); + } return bytes_freed; } diff --git a/runtime/gc/space/space.cc b/runtime/gc/space/space.cc index 01e8b044ba..4e2841691e 100644 --- a/runtime/gc/space/space.cc +++ b/runtime/gc/space/space.cc @@ -70,9 +70,15 @@ ContinuousMemMapAllocSpace* Space::AsContinuousMemMapAllocSpace() { DiscontinuousSpace::DiscontinuousSpace(const std::string& name, GcRetentionPolicy gc_retention_policy) : - Space(name, gc_retention_policy), - live_objects_(new accounting::ObjectSet("large live objects")), - mark_objects_(new accounting::ObjectSet("large marked objects")) { + Space(name, gc_retention_policy) { + // TODO: Fix this if we ever support objects not in the low 32 bit. + const size_t capacity = static_cast<size_t>(std::numeric_limits<uint32_t>::max()); + live_bitmap_.reset(accounting::LargeObjectBitmap::Create("large live objects", nullptr, + capacity)); + CHECK(live_bitmap_.get() != nullptr); + mark_bitmap_.reset(accounting::LargeObjectBitmap::Create("large marked objects", nullptr, + capacity)); + CHECK(mark_bitmap_.get() != nullptr); } void ContinuousMemMapAllocSpace::Sweep(bool swap_bitmaps, size_t* freed_objects, size_t* freed_bytes) { @@ -84,13 +90,7 @@ void ContinuousMemMapAllocSpace::Sweep(bool swap_bitmaps, size_t* freed_objects, if (live_bitmap == mark_bitmap) { return; } - SweepCallbackContext scc; - scc.swap_bitmaps = swap_bitmaps; - scc.heap = Runtime::Current()->GetHeap(); - scc.self = Thread::Current(); - scc.space = this; - scc.freed_objects = 0; - scc.freed_bytes = 0; + SweepCallbackContext scc(swap_bitmaps, this); if (swap_bitmaps) { std::swap(live_bitmap, mark_bitmap); } @@ -136,6 +136,11 @@ void ContinuousMemMapAllocSpace::SwapBitmaps() { mark_bitmap_->SetName(temp_name); } +Space::SweepCallbackContext::SweepCallbackContext(bool swap_bitmaps, space::Space* space) + : swap_bitmaps(swap_bitmaps), space(space), self(Thread::Current()), freed_objects(0), + freed_bytes(0) { +} + } // namespace space } // namespace gc } // namespace art diff --git a/runtime/gc/space/space.h b/runtime/gc/space/space.h index 2b27f8747f..0a87a160b3 100644 --- a/runtime/gc/space/space.h +++ b/runtime/gc/space/space.h @@ -173,10 +173,11 @@ class Space { protected: struct SweepCallbackContext { - bool swap_bitmaps; - Heap* heap; - space::Space* space; - Thread* self; + public: + SweepCallbackContext(bool swap_bitmaps, space::Space* space); + const bool swap_bitmaps; + space::Space* const space; + Thread* const self; size_t freed_objects; size_t freed_bytes; }; @@ -313,15 +314,15 @@ class ContinuousSpace : public Space { // is suitable for use for large primitive arrays. class DiscontinuousSpace : public Space { public: - accounting::ObjectSet* GetLiveObjects() const { - return live_objects_.get(); + accounting::LargeObjectBitmap* GetLiveBitmap() const { + return live_bitmap_.get(); } - accounting::ObjectSet* GetMarkObjects() const { - return mark_objects_.get(); + accounting::LargeObjectBitmap* GetMarkBitmap() const { + return mark_bitmap_.get(); } - virtual bool IsDiscontinuousSpace() const { + virtual bool IsDiscontinuousSpace() const OVERRIDE { return true; } @@ -330,8 +331,8 @@ class DiscontinuousSpace : public Space { protected: DiscontinuousSpace(const std::string& name, GcRetentionPolicy gc_retention_policy); - UniquePtr<accounting::ObjectSet> live_objects_; - UniquePtr<accounting::ObjectSet> mark_objects_; + UniquePtr<accounting::LargeObjectBitmap> live_bitmap_; + UniquePtr<accounting::LargeObjectBitmap> mark_bitmap_; private: DISALLOW_COPY_AND_ASSIGN(DiscontinuousSpace); diff --git a/runtime/gc/space/zygote_space.cc b/runtime/gc/space/zygote_space.cc index 1b06b63afa..046641362d 100644 --- a/runtime/gc/space/zygote_space.cc +++ b/runtime/gc/space/zygote_space.cc @@ -101,7 +101,7 @@ void ZygoteSpace::SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* ar DCHECK(context->space->IsZygoteSpace()); ZygoteSpace* zygote_space = context->space->AsZygoteSpace(); Locks::heap_bitmap_lock_->AssertExclusiveHeld(context->self); - accounting::CardTable* card_table = context->heap->GetCardTable(); + accounting::CardTable* card_table = Runtime::Current()->GetHeap()->GetCardTable(); // If the bitmaps aren't swapped we need to clear the bits since the GC isn't going to re-swap // the bitmaps as an optimization. if (!context->swap_bitmaps) { diff --git a/runtime/indirect_reference_table.cc b/runtime/indirect_reference_table.cc index bbad88495e..987df91ead 100644 --- a/runtime/indirect_reference_table.cc +++ b/runtime/indirect_reference_table.cc @@ -254,20 +254,11 @@ bool IndirectReferenceTable::Remove(uint32_t cookie, IndirectRef iref) { int idx = ExtractIndex(iref); - JavaVMExt* vm = Runtime::Current()->GetJavaVM(); if (GetIndirectRefKind(iref) == kSirtOrInvalid && Thread::Current()->SirtContains(reinterpret_cast<jobject>(iref))) { LOG(WARNING) << "Attempt to remove local SIRT entry from IRT, ignoring"; return true; } - if (GetIndirectRefKind(iref) == kSirtOrInvalid && vm->work_around_app_jni_bugs) { - mirror::Object* direct_pointer = reinterpret_cast<mirror::Object*>(iref); - idx = Find(direct_pointer, bottomIndex, topIndex, table_); - if (idx == -1) { - LOG(WARNING) << "Trying to work around app JNI bugs, but didn't find " << iref << " in table!"; - return false; - } - } if (idx < bottomIndex) { // Wrong segment. @@ -285,7 +276,7 @@ bool IndirectReferenceTable::Remove(uint32_t cookie, IndirectRef iref) { if (idx == topIndex-1) { // Top-most entry. Scan up and consume holes. - if (!vm->work_around_app_jni_bugs && !CheckEntry("remove", iref, idx)) { + if (!CheckEntry("remove", iref, idx)) { return false; } @@ -321,7 +312,7 @@ bool IndirectReferenceTable::Remove(uint32_t cookie, IndirectRef iref) { LOG(INFO) << "--- WEIRD: removing null entry " << idx; return false; } - if (!vm->work_around_app_jni_bugs && !CheckEntry("remove", iref, idx)) { + if (!CheckEntry("remove", iref, idx)) { return false; } diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc index bcde9e5a2e..2cd7f49a30 100644 --- a/runtime/instrumentation.cc +++ b/runtime/instrumentation.cc @@ -256,7 +256,7 @@ static void InstrumentationInstallStack(Thread* thread, void* arg) visitor.WalkStack(true); CHECK_EQ(visitor.dex_pcs_.size(), thread->GetInstrumentationStack()->size()); - if (!instrumentation->ShouldNotifyMethodEnterExitEvents()) { + if (instrumentation->ShouldNotifyMethodEnterExitEvents()) { // Create method enter events for all methods currently on the thread's stack. We only do this // if no debugger is attached to prevent from posting events twice. typedef std::deque<InstrumentationStackFrame>::const_reverse_iterator It; @@ -303,8 +303,9 @@ static void InstrumentationRestoreStack(Thread* thread, void* arg) } bool removed_stub = false; // TODO: make this search more efficient? - for (InstrumentationStackFrame instrumentation_frame : *instrumentation_stack_) { - if (instrumentation_frame.frame_id_ == GetFrameId()) { + const size_t frameId = GetFrameId(); + for (const InstrumentationStackFrame& instrumentation_frame : *instrumentation_stack_) { + if (instrumentation_frame.frame_id_ == frameId) { if (kVerboseInstrumentation) { LOG(INFO) << " Removing exit stub in " << DescribeLocation(); } @@ -314,7 +315,7 @@ static void InstrumentationRestoreStack(Thread* thread, void* arg) CHECK(m == instrumentation_frame.method_) << PrettyMethod(m); } SetReturnPc(instrumentation_frame.return_pc_); - if (!instrumentation_->ShouldNotifyMethodEnterExitEvents()) { + if (instrumentation_->ShouldNotifyMethodEnterExitEvents()) { // Create the method exit events. As the methods didn't really exit the result is 0. // We only do this if no debugger is attached to prevent from posting events twice. instrumentation_->MethodExitEvent(thread_, instrumentation_frame.this_object_, m, @@ -464,7 +465,7 @@ void Instrumentation::ConfigureStubs(bool require_entry_exit_stubs, bool require // We're already set. return; } - Thread* self = Thread::Current(); + Thread* const self = Thread::Current(); Runtime* runtime = Runtime::Current(); Locks::thread_list_lock_->AssertNotHeld(self); if (desired_level > 0) { @@ -476,7 +477,7 @@ void Instrumentation::ConfigureStubs(bool require_entry_exit_stubs, bool require } runtime->GetClassLinker()->VisitClasses(InstallStubsClassVisitor, this); instrumentation_stubs_installed_ = true; - MutexLock mu(Thread::Current(), *Locks::thread_list_lock_); + MutexLock mu(self, *Locks::thread_list_lock_); runtime->GetThreadList()->ForEach(InstrumentationInstallStack, this); } else { interpreter_stubs_installed_ = false; @@ -682,7 +683,7 @@ void Instrumentation::DisableDeoptimization() { // Indicates if instrumentation should notify method enter/exit events to the listeners. bool Instrumentation::ShouldNotifyMethodEnterExitEvents() const { - return deoptimization_enabled_ || interpreter_stubs_installed_; + return !deoptimization_enabled_ && !interpreter_stubs_installed_; } void Instrumentation::DeoptimizeEverything() { @@ -799,7 +800,10 @@ void Instrumentation::ExceptionCaughtEvent(Thread* thread, const ThrowLocation& if (have_exception_caught_listeners_) { DCHECK_EQ(thread->GetException(NULL), exception_object); thread->ClearException(); - for (InstrumentationListener* listener : exception_caught_listeners_) { + // TODO: The copy below is due to the debug listener having an action where it can remove + // itself as a listener and break the iterator. The copy only works around the problem. + std::list<InstrumentationListener*> copy(exception_caught_listeners_); + for (InstrumentationListener* listener : copy) { listener->ExceptionCaught(thread, throw_location, catch_method, catch_dex_pc, exception_object); } thread->SetException(throw_location, exception_object); diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h index 21eeafa9d9..cc1fa0c94f 100644 --- a/runtime/interpreter/interpreter_common.h +++ b/runtime/interpreter/interpreter_common.h @@ -169,6 +169,13 @@ static inline bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, return false; } } + // Report this field access to instrumentation if needed. + instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); + if (UNLIKELY(instrumentation->HasFieldReadListeners())) { + Object* this_object = f->IsStatic() ? nullptr : obj; + instrumentation->FieldReadEvent(self, this_object, shadow_frame.GetMethod(), + shadow_frame.GetDexPC(), f); + } uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); switch (field_type) { case Primitive::kPrimBoolean: @@ -210,6 +217,17 @@ static inline bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* ins return false; } MemberOffset field_offset(inst->VRegC_22c()); + // Report this field access to instrumentation if needed. Since we only have the offset of + // the field from the base of the object, we need to look for it first. + instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); + if (UNLIKELY(instrumentation->HasFieldReadListeners())) { + ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), + field_offset.Uint32Value()); + DCHECK(f != nullptr); + DCHECK(!f->IsStatic()); + instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(), + shadow_frame.GetDexPC(), f); + } const bool is_volatile = false; // iget-x-quick only on non volatile fields. const uint32_t vregA = inst->VRegA_22c(inst_data); switch (field_type) { @@ -228,6 +246,39 @@ static inline bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* ins return true; } +template<Primitive::Type field_type> +static inline JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + JValue field_value; + switch (field_type) { + case Primitive::kPrimBoolean: + field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg))); + break; + case Primitive::kPrimByte: + field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg))); + break; + case Primitive::kPrimChar: + field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg))); + break; + case Primitive::kPrimShort: + field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg))); + break; + case Primitive::kPrimInt: + field_value.SetI(shadow_frame.GetVReg(vreg)); + break; + case Primitive::kPrimLong: + field_value.SetJ(shadow_frame.GetVRegLong(vreg)); + break; + case Primitive::kPrimNot: + field_value.SetL(shadow_frame.GetVRegReference(vreg)); + break; + default: + LOG(FATAL) << "Unreachable: " << field_type; + break; + } + return field_value; +} + // Handles iput-XXX and sput-XXX instructions. // Returns true on success, otherwise throws an exception and returns false. template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, bool transaction_active> @@ -254,6 +305,15 @@ static inline bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, } } uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); + // Report this field access to instrumentation if needed. Since we only have the offset of + // the field from the base of the object, we need to look for it first. + instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); + if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { + JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); + Object* this_object = f->IsStatic() ? nullptr : obj; + instrumentation->FieldWriteEvent(self, this_object, shadow_frame.GetMethod(), + shadow_frame.GetDexPC(), f, field_value); + } switch (field_type) { case Primitive::kPrimBoolean: f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA)); @@ -309,8 +369,20 @@ static inline bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instructio return false; } MemberOffset field_offset(inst->VRegC_22c()); - const bool is_volatile = false; // iput-x-quick only on non volatile fields. const uint32_t vregA = inst->VRegA_22c(inst_data); + // Report this field modification to instrumentation if needed. Since we only have the offset of + // the field from the base of the object, we need to look for it first. + instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); + if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { + ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), + field_offset.Uint32Value()); + DCHECK(f != nullptr); + DCHECK(!f->IsStatic()); + JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); + instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(), + shadow_frame.GetDexPC(), f, field_value); + } + const bool is_volatile = false; // iput-x-quick only on non volatile fields. switch (field_type) { case Primitive::kPrimInt: obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA), is_volatile); @@ -498,7 +570,8 @@ static inline uint32_t FindNextInstructionFollowingException(Thread* self, ThrowLocation throw_location; mirror::Throwable* exception = self->GetException(&throw_location); bool clear_exception = false; - uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception->GetClass(), dex_pc, + SirtRef<mirror::Class> exception_class(self, exception->GetClass()); + uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc, &clear_exception); if (found_dex_pc == DexFile::kDexNoIndex) { instrumentation->MethodUnwindEvent(self, this_object, diff --git a/runtime/jdwp/jdwp_event.cc b/runtime/jdwp/jdwp_event.cc index 69080477b0..223b7a1124 100644 --- a/runtime/jdwp/jdwp_event.cc +++ b/runtime/jdwp/jdwp_event.cc @@ -108,7 +108,7 @@ namespace JDWP { */ struct ModBasket { ModBasket() : pLoc(NULL), threadId(0), classId(0), excepClassId(0), - caught(false), field(0), thisPtr(0) { } + caught(false), fieldTypeID(0), fieldId(0), thisPtr(0) { } const JdwpLocation* pLoc; /* LocationOnly */ std::string className; /* ClassMatch/ClassExclude */ @@ -116,7 +116,8 @@ struct ModBasket { RefTypeId classId; /* ClassOnly */ RefTypeId excepClassId; /* ExceptionOnly */ bool caught; /* ExceptionOnly */ - FieldId field; /* FieldOnly */ + RefTypeId fieldTypeID; /* FieldOnly */ + FieldId fieldId; /* FieldOnly */ ObjectId thisPtr; /* InstanceOnly */ /* nothing for StepOnly -- handled differently */ }; @@ -233,7 +234,16 @@ void JdwpState::UnregisterEvent(JdwpEvent* pEvent) { Dbg::UnconfigureStep(pMod->step.threadId); } } - if (NeedsFullDeoptimization(pEvent->eventKind)) { + if (pEvent->eventKind == EK_SINGLE_STEP) { + // Special case for single-steps where we want to avoid the slow pattern deoptimize/undeoptimize + // loop between each single-step. In a IDE, this would happens each time the user click on the + // "single-step" button. Here we delay the full undeoptimization to the next resume + // (VM.Resume or ThreadReference.Resume) or the end of the debugging session (VM.Dispose or + // runtime shutdown). + // Therefore, in a singles-stepping sequence, only the first single-step will trigger a full + // deoptimization and only the last single-step will trigger a full undeoptimization. + Dbg::DelayFullUndeoptimization(); + } else if (NeedsFullDeoptimization(pEvent->eventKind)) { CHECK_EQ(req.kind, DeoptimizationRequest::kNothing); CHECK(req.method == nullptr); req.kind = DeoptimizationRequest::kFullUndeoptimization; @@ -448,7 +458,10 @@ static bool ModsMatch(JdwpEvent* pEvent, ModBasket* basket) } break; case MK_FIELD_ONLY: - if (!Dbg::MatchType(basket->classId, pMod->fieldOnly.refTypeId) || pMod->fieldOnly.fieldId != basket->field) { + if (pMod->fieldOnly.fieldId != basket->fieldId) { + return false; + } + if (!Dbg::MatchType(basket->fieldTypeID, pMod->fieldOnly.refTypeId)) { return false; } break; @@ -839,7 +852,8 @@ bool JdwpState::PostFieldEvent(const JdwpLocation* pLoc, RefTypeId typeId, Field basket.thisPtr = thisPtr; basket.threadId = Dbg::GetThreadSelfId(); basket.className = Dbg::GetClassName(pLoc->class_id); - basket.field = fieldId; + basket.fieldTypeID = typeId; + basket.fieldId = fieldId; if (InvokeInProgress()) { VLOG(jdwp) << "Not posting field event during invoke"; diff --git a/runtime/jdwp/jdwp_handler.cc b/runtime/jdwp/jdwp_handler.cc index 5ffe753dbb..4843c2b5ec 100644 --- a/runtime/jdwp/jdwp_handler.cc +++ b/runtime/jdwp/jdwp_handler.cc @@ -291,6 +291,7 @@ static JdwpError VM_Suspend(JdwpState*, Request&, ExpandBuf*) */ static JdwpError VM_Resume(JdwpState*, Request&, ExpandBuf*) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + Dbg::ProcessDelayedFullUndeoptimizations(); Dbg::ResumeVM(); return ERR_NONE; } @@ -353,8 +354,8 @@ static JdwpError VM_DisposeObjects(JdwpState*, Request& request, ExpandBuf*) static JdwpError VM_Capabilities(JdwpState*, Request&, ExpandBuf* reply) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - expandBufAdd1(reply, false); // canWatchFieldModification - expandBufAdd1(reply, false); // canWatchFieldAccess + expandBufAdd1(reply, true); // canWatchFieldModification + expandBufAdd1(reply, true); // canWatchFieldAccess expandBufAdd1(reply, true); // canGetBytecodes expandBufAdd1(reply, true); // canGetSyntheticAttribute expandBufAdd1(reply, true); // canGetOwnedMonitorInfo @@ -980,6 +981,8 @@ static JdwpError TR_Resume(JdwpState*, Request& request, ExpandBuf*) return ERR_NONE; } + Dbg::ProcessDelayedFullUndeoptimizations(); + Dbg::ResumeThread(thread_id); return ERR_NONE; } diff --git a/runtime/jdwp/jdwp_main.cc b/runtime/jdwp/jdwp_main.cc index 8e22c1df62..f480256b6a 100644 --- a/runtime/jdwp/jdwp_main.cc +++ b/runtime/jdwp/jdwp_main.cc @@ -318,6 +318,8 @@ void JdwpState::ResetState() { CHECK(event_list_ == NULL); } + Dbg::ProcessDelayedFullUndeoptimizations(); + /* * Should not have one of these in progress. If the debugger went away * mid-request, though, we could see this. diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc index f7aeffd36c..fd9c40be13 100644 --- a/runtime/jni_internal.cc +++ b/runtime/jni_internal.cc @@ -513,14 +513,16 @@ class Libraries { SafeMap<std::string, SharedLibrary*> libraries_; }; -#define CHECK_NON_NULL_ARGUMENT(fn, value) \ +#define CHECK_NON_NULL_ARGUMENT(value) CHECK_NON_NULL_ARGUMENT_FN_NAME(__FUNCTION__, value) + +#define CHECK_NON_NULL_ARGUMENT_FN_NAME(name, value) \ if (UNLIKELY(value == nullptr)) { \ - JniAbortF(#fn, #value " == null"); \ + JniAbortF(name, #value " == null"); \ } -#define CHECK_NON_NULL_MEMCPY_ARGUMENT(fn, length, value) \ +#define CHECK_NON_NULL_MEMCPY_ARGUMENT(length, value) \ if (UNLIKELY(length != 0 && value == nullptr)) { \ - JniAbortF(#fn, #value " == null"); \ + JniAbortF(__FUNCTION__, #value " == null"); \ } class JNI { @@ -535,7 +537,7 @@ class JNI { } static jclass FindClass(JNIEnv* env, const char* name) { - CHECK_NON_NULL_ARGUMENT(FindClass, name); + CHECK_NON_NULL_ARGUMENT(name); Runtime* runtime = Runtime::Current(); ClassLinker* class_linker = runtime->GetClassLinker(); std::string descriptor(NormalizeJniClassDescriptor(name)); @@ -551,19 +553,19 @@ class JNI { } static jmethodID FromReflectedMethod(JNIEnv* env, jobject jlr_method) { - CHECK_NON_NULL_ARGUMENT(FromReflectedMethod, jlr_method); + CHECK_NON_NULL_ARGUMENT(jlr_method); ScopedObjectAccess soa(env); return soa.EncodeMethod(mirror::ArtMethod::FromReflectedMethod(soa, jlr_method)); } static jfieldID FromReflectedField(JNIEnv* env, jobject jlr_field) { - CHECK_NON_NULL_ARGUMENT(FromReflectedField, jlr_field); + CHECK_NON_NULL_ARGUMENT(jlr_field); ScopedObjectAccess soa(env); return soa.EncodeField(mirror::ArtField::FromReflectedField(soa, jlr_field)); } static jobject ToReflectedMethod(JNIEnv* env, jclass, jmethodID mid, jboolean) { - CHECK_NON_NULL_ARGUMENT(ToReflectedMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); mirror::ArtMethod* m = soa.DecodeMethod(mid); CHECK(!kMovingMethods); @@ -578,7 +580,7 @@ class JNI { } static jobject ToReflectedField(JNIEnv* env, jclass, jfieldID fid, jboolean) { - CHECK_NON_NULL_ARGUMENT(ToReflectedField, fid); + CHECK_NON_NULL_ARGUMENT(fid); ScopedObjectAccess soa(env); mirror::ArtField* f = soa.DecodeField(fid); jobject art_field = soa.AddLocalReference<jobject>(f); @@ -592,22 +594,22 @@ class JNI { } static jclass GetObjectClass(JNIEnv* env, jobject java_object) { - CHECK_NON_NULL_ARGUMENT(GetObjectClass, java_object); + CHECK_NON_NULL_ARGUMENT(java_object); ScopedObjectAccess soa(env); mirror::Object* o = soa.Decode<mirror::Object*>(java_object); return soa.AddLocalReference<jclass>(o->GetClass()); } static jclass GetSuperclass(JNIEnv* env, jclass java_class) { - CHECK_NON_NULL_ARGUMENT(GetSuperclass, java_class); + CHECK_NON_NULL_ARGUMENT(java_class); ScopedObjectAccess soa(env); mirror::Class* c = soa.Decode<mirror::Class*>(java_class); return soa.AddLocalReference<jclass>(c->GetSuperClass()); } static jboolean IsAssignableFrom(JNIEnv* env, jclass java_class1, jclass java_class2) { - CHECK_NON_NULL_ARGUMENT(IsAssignableFrom, java_class1); - CHECK_NON_NULL_ARGUMENT(IsAssignableFrom, java_class2); + CHECK_NON_NULL_ARGUMENT(java_class1); + CHECK_NON_NULL_ARGUMENT(java_class2); ScopedObjectAccess soa(env); mirror::Class* c1 = soa.Decode<mirror::Class*>(java_class1); mirror::Class* c2 = soa.Decode<mirror::Class*>(java_class2); @@ -615,7 +617,7 @@ class JNI { } static jboolean IsInstanceOf(JNIEnv* env, jobject jobj, jclass java_class) { - CHECK_NON_NULL_ARGUMENT(IsInstanceOf, java_class); + CHECK_NON_NULL_ARGUMENT(java_class); if (jobj == nullptr) { // Note: JNI is different from regular Java instanceof in this respect return JNI_TRUE; @@ -639,7 +641,7 @@ class JNI { } static jint ThrowNew(JNIEnv* env, jclass c, const char* msg) { - CHECK_NON_NULL_ARGUMENT(ThrowNew, c); + CHECK_NON_NULL_ARGUMENT(c); return ThrowNewException(env, c, msg, nullptr); } @@ -797,7 +799,7 @@ class JNI { } static jobject AllocObject(JNIEnv* env, jclass java_class) { - CHECK_NON_NULL_ARGUMENT(AllocObject, java_class); + CHECK_NON_NULL_ARGUMENT(java_class); ScopedObjectAccess soa(env); mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); if (c == nullptr) { @@ -809,16 +811,16 @@ class JNI { static jobject NewObject(JNIEnv* env, jclass java_class, jmethodID mid, ...) { va_list args; va_start(args, mid); - CHECK_NON_NULL_ARGUMENT(NewObject, java_class); - CHECK_NON_NULL_ARGUMENT(NewObject, mid); + CHECK_NON_NULL_ARGUMENT(java_class); + CHECK_NON_NULL_ARGUMENT(mid); jobject result = NewObjectV(env, java_class, mid, args); va_end(args); return result; } static jobject NewObjectV(JNIEnv* env, jclass java_class, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(NewObjectV, java_class); - CHECK_NON_NULL_ARGUMENT(NewObjectV, mid); + CHECK_NON_NULL_ARGUMENT(java_class); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); if (c == nullptr) { @@ -837,8 +839,8 @@ class JNI { } static jobject NewObjectA(JNIEnv* env, jclass java_class, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(NewObjectA, java_class); - CHECK_NON_NULL_ARGUMENT(NewObjectA, mid); + CHECK_NON_NULL_ARGUMENT(java_class); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); mirror::Class* c = EnsureInitialized(soa.Self(), soa.Decode<mirror::Class*>(java_class)); if (c == nullptr) { @@ -857,18 +859,18 @@ class JNI { } static jmethodID GetMethodID(JNIEnv* env, jclass java_class, const char* name, const char* sig) { - CHECK_NON_NULL_ARGUMENT(GetMethodID, java_class); - CHECK_NON_NULL_ARGUMENT(GetMethodID, name); - CHECK_NON_NULL_ARGUMENT(GetMethodID, sig); + CHECK_NON_NULL_ARGUMENT(java_class); + CHECK_NON_NULL_ARGUMENT(name); + CHECK_NON_NULL_ARGUMENT(sig); ScopedObjectAccess soa(env); return FindMethodID(soa, java_class, name, sig, false); } static jmethodID GetStaticMethodID(JNIEnv* env, jclass java_class, const char* name, const char* sig) { - CHECK_NON_NULL_ARGUMENT(GetStaticMethodID, java_class); - CHECK_NON_NULL_ARGUMENT(GetStaticMethodID, name); - CHECK_NON_NULL_ARGUMENT(GetStaticMethodID, sig); + CHECK_NON_NULL_ARGUMENT(java_class); + CHECK_NON_NULL_ARGUMENT(name); + CHECK_NON_NULL_ARGUMENT(sig); ScopedObjectAccess soa(env); return FindMethodID(soa, java_class, name, sig, true); } @@ -876,8 +878,8 @@ class JNI { static jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallObjectMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallObjectMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -885,16 +887,16 @@ class JNI { } static jobject CallObjectMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallObjectMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallObjectMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args)); return soa.AddLocalReference<jobject>(result.GetL()); } static jobject CallObjectMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallObjectMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallObjectMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args)); @@ -904,8 +906,8 @@ class JNI { static jboolean CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallBooleanMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallBooleanMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -913,15 +915,15 @@ class JNI { } static jboolean CallBooleanMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallBooleanMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallBooleanMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetZ(); } static jboolean CallBooleanMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallBooleanMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallBooleanMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetZ(); @@ -930,8 +932,8 @@ class JNI { static jbyte CallByteMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallByteMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallByteMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -939,15 +941,15 @@ class JNI { } static jbyte CallByteMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallByteMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallByteMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetB(); } static jbyte CallByteMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallByteMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallByteMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetB(); @@ -956,8 +958,8 @@ class JNI { static jchar CallCharMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallCharMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallCharMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -965,15 +967,15 @@ class JNI { } static jchar CallCharMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallCharMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallCharMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetC(); } static jchar CallCharMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallCharMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallCharMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetC(); @@ -982,8 +984,8 @@ class JNI { static jdouble CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallDoubleMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallDoubleMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -991,15 +993,15 @@ class JNI { } static jdouble CallDoubleMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallDoubleMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallDoubleMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetD(); } static jdouble CallDoubleMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallDoubleMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallDoubleMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetD(); @@ -1008,8 +1010,8 @@ class JNI { static jfloat CallFloatMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallFloatMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallFloatMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1017,15 +1019,15 @@ class JNI { } static jfloat CallFloatMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallFloatMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallFloatMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetF(); } static jfloat CallFloatMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallFloatMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallFloatMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetF(); @@ -1034,8 +1036,8 @@ class JNI { static jint CallIntMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallIntMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallIntMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1043,15 +1045,15 @@ class JNI { } static jint CallIntMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallIntMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallIntMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetI(); } static jint CallIntMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallIntMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallIntMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetI(); @@ -1060,8 +1062,8 @@ class JNI { static jlong CallLongMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallLongMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallLongMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1069,15 +1071,15 @@ class JNI { } static jlong CallLongMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallLongMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallLongMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetJ(); } static jlong CallLongMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallLongMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallLongMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetJ(); @@ -1086,8 +1088,8 @@ class JNI { static jshort CallShortMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallShortMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallShortMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1095,15 +1097,15 @@ class JNI { } static jshort CallShortMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallShortMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallShortMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args).GetS(); } static jshort CallShortMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallShortMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallShortMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetS(); @@ -1112,23 +1114,23 @@ class JNI { static void CallVoidMethod(JNIEnv* env, jobject obj, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallVoidMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallVoidMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, ap); va_end(ap); } static void CallVoidMethodV(JNIEnv* env, jobject obj, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallVoidMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallVoidMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeVirtualOrInterfaceWithVarArgs(soa, obj, mid, args); } static void CallVoidMethodA(JNIEnv* env, jobject obj, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallVoidMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallVoidMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeVirtualOrInterfaceWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args); } @@ -1136,8 +1138,8 @@ class JNI { static jobject CallNonvirtualObjectMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualObjectMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualObjectMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); jobject local_result = soa.AddLocalReference<jobject>(result.GetL()); @@ -1147,8 +1149,8 @@ class JNI { static jobject CallNonvirtualObjectMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualObjectMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualObjectMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, args)); return soa.AddLocalReference<jobject>(result.GetL()); @@ -1156,8 +1158,8 @@ class JNI { static jobject CallNonvirtualObjectMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualObjectMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualObjectMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args)); return soa.AddLocalReference<jobject>(result.GetL()); @@ -1167,8 +1169,8 @@ class JNI { ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualBooleanMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualBooleanMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1177,16 +1179,16 @@ class JNI { static jboolean CallNonvirtualBooleanMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualBooleanMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualBooleanMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, obj, mid, args).GetZ(); } static jboolean CallNonvirtualBooleanMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualBooleanMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualBooleanMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetZ(); } @@ -1194,8 +1196,8 @@ class JNI { static jbyte CallNonvirtualByteMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualByteMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualByteMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1204,16 +1206,16 @@ class JNI { static jbyte CallNonvirtualByteMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualByteMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualByteMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, obj, mid, args).GetB(); } static jbyte CallNonvirtualByteMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualByteMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualByteMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetB(); } @@ -1221,8 +1223,8 @@ class JNI { static jchar CallNonvirtualCharMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualCharMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualCharMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1231,16 +1233,16 @@ class JNI { static jchar CallNonvirtualCharMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualCharMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualCharMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, obj, mid, args).GetC(); } static jchar CallNonvirtualCharMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualCharMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualCharMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetC(); } @@ -1248,8 +1250,8 @@ class JNI { static jshort CallNonvirtualShortMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualShortMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualShortMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1258,16 +1260,16 @@ class JNI { static jshort CallNonvirtualShortMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualShortMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualShortMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, obj, mid, args).GetS(); } static jshort CallNonvirtualShortMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualShortMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualShortMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetS(); } @@ -1275,8 +1277,8 @@ class JNI { static jint CallNonvirtualIntMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualIntMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualIntMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1285,16 +1287,16 @@ class JNI { static jint CallNonvirtualIntMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualIntMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualIntMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, obj, mid, args).GetI(); } static jint CallNonvirtualIntMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualIntMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualIntMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetI(); } @@ -1302,8 +1304,8 @@ class JNI { static jlong CallNonvirtualLongMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualLongMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualLongMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1312,16 +1314,16 @@ class JNI { static jlong CallNonvirtualLongMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualLongMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualLongMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, obj, mid, args).GetJ(); } static jlong CallNonvirtualLongMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualLongMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualLongMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetJ(); } @@ -1329,8 +1331,8 @@ class JNI { static jfloat CallNonvirtualFloatMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualFloatMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualFloatMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1339,16 +1341,16 @@ class JNI { static jfloat CallNonvirtualFloatMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualFloatMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualFloatMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, obj, mid, args).GetF(); } static jfloat CallNonvirtualFloatMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualFloatMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualFloatMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetF(); } @@ -1356,8 +1358,8 @@ class JNI { static jdouble CallNonvirtualDoubleMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualDoubleMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualDoubleMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, obj, mid, ap)); va_end(ap); @@ -1366,16 +1368,16 @@ class JNI { static jdouble CallNonvirtualDoubleMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualDoubleMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualDoubleMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, obj, mid, args).GetD(); } static jdouble CallNonvirtualDoubleMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualDoubleMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualDoubleMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args).GetD(); } @@ -1383,8 +1385,8 @@ class JNI { static void CallNonvirtualVoidMethod(JNIEnv* env, jobject obj, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualVoidMethod, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualVoidMethod, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeWithVarArgs(soa, obj, mid, ap); va_end(ap); @@ -1392,40 +1394,40 @@ class JNI { static void CallNonvirtualVoidMethodV(JNIEnv* env, jobject obj, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualVoidMethodV, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualVoidMethodV, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeWithVarArgs(soa, obj, mid, args); } static void CallNonvirtualVoidMethodA(JNIEnv* env, jobject obj, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallNonvirtualVoidMethodA, obj); - CHECK_NON_NULL_ARGUMENT(CallNonvirtualVoidMethodA, mid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeWithJValues(soa, soa.Decode<mirror::Object*>(obj), mid, args); } static jfieldID GetFieldID(JNIEnv* env, jclass java_class, const char* name, const char* sig) { - CHECK_NON_NULL_ARGUMENT(GetFieldID, java_class); - CHECK_NON_NULL_ARGUMENT(GetFieldID, name); - CHECK_NON_NULL_ARGUMENT(GetFieldID, sig); + CHECK_NON_NULL_ARGUMENT(java_class); + CHECK_NON_NULL_ARGUMENT(name); + CHECK_NON_NULL_ARGUMENT(sig); ScopedObjectAccess soa(env); return FindFieldID(soa, java_class, name, sig, false); } static jfieldID GetStaticFieldID(JNIEnv* env, jclass java_class, const char* name, const char* sig) { - CHECK_NON_NULL_ARGUMENT(GetStaticFieldID, java_class); - CHECK_NON_NULL_ARGUMENT(GetStaticFieldID, name); - CHECK_NON_NULL_ARGUMENT(GetFieldID, sig); + CHECK_NON_NULL_ARGUMENT(java_class); + CHECK_NON_NULL_ARGUMENT(name); + CHECK_NON_NULL_ARGUMENT(sig); ScopedObjectAccess soa(env); return FindFieldID(soa, java_class, name, sig, true); } static jobject GetObjectField(JNIEnv* env, jobject obj, jfieldID fid) { - CHECK_NON_NULL_ARGUMENT(GetObjectField, obj); - CHECK_NON_NULL_ARGUMENT(GetObjectField, fid); + CHECK_NON_NULL_ARGUMENT(obj); + CHECK_NON_NULL_ARGUMENT(fid); ScopedObjectAccess soa(env); mirror::Object* o = soa.Decode<mirror::Object*>(obj); mirror::ArtField* f = soa.DecodeField(fid); @@ -1433,15 +1435,15 @@ class JNI { } static jobject GetStaticObjectField(JNIEnv* env, jclass, jfieldID fid) { - CHECK_NON_NULL_ARGUMENT(GetStaticObjectField, fid); + CHECK_NON_NULL_ARGUMENT(fid); ScopedObjectAccess soa(env); mirror::ArtField* f = soa.DecodeField(fid); return soa.AddLocalReference<jobject>(f->GetObject(f->GetDeclaringClass())); } static void SetObjectField(JNIEnv* env, jobject java_object, jfieldID fid, jobject java_value) { - CHECK_NON_NULL_ARGUMENT(SetObjectField, java_object); - CHECK_NON_NULL_ARGUMENT(SetObjectField, fid); + CHECK_NON_NULL_ARGUMENT(java_object); + CHECK_NON_NULL_ARGUMENT(fid); ScopedObjectAccess soa(env); mirror::Object* o = soa.Decode<mirror::Object*>(java_object); mirror::Object* v = soa.Decode<mirror::Object*>(java_value); @@ -1450,7 +1452,7 @@ class JNI { } static void SetStaticObjectField(JNIEnv* env, jclass, jfieldID fid, jobject java_value) { - CHECK_NON_NULL_ARGUMENT(SetStaticObjectField, fid); + CHECK_NON_NULL_ARGUMENT(fid); ScopedObjectAccess soa(env); mirror::Object* v = soa.Decode<mirror::Object*>(java_value); mirror::ArtField* f = soa.DecodeField(fid); @@ -1458,29 +1460,29 @@ class JNI { } #define GET_PRIMITIVE_FIELD(fn, instance) \ - CHECK_NON_NULL_ARGUMENT(Get #fn Field, instance); \ - CHECK_NON_NULL_ARGUMENT(Get #fn Field, fid); \ + CHECK_NON_NULL_ARGUMENT(instance); \ + CHECK_NON_NULL_ARGUMENT(fid); \ ScopedObjectAccess soa(env); \ mirror::Object* o = soa.Decode<mirror::Object*>(instance); \ mirror::ArtField* f = soa.DecodeField(fid); \ return f->Get ##fn (o) #define GET_STATIC_PRIMITIVE_FIELD(fn) \ - CHECK_NON_NULL_ARGUMENT(GetStatic #fn Field, fid); \ + CHECK_NON_NULL_ARGUMENT(fid); \ ScopedObjectAccess soa(env); \ mirror::ArtField* f = soa.DecodeField(fid); \ return f->Get ##fn (f->GetDeclaringClass()) #define SET_PRIMITIVE_FIELD(fn, instance, value) \ - CHECK_NON_NULL_ARGUMENT(Set #fn Field, instance); \ - CHECK_NON_NULL_ARGUMENT(Set #fn Field, fid); \ + CHECK_NON_NULL_ARGUMENT(instance); \ + CHECK_NON_NULL_ARGUMENT(fid); \ ScopedObjectAccess soa(env); \ mirror::Object* o = soa.Decode<mirror::Object*>(instance); \ mirror::ArtField* f = soa.DecodeField(fid); \ f->Set ##fn <false>(o, value) #define SET_STATIC_PRIMITIVE_FIELD(fn, value) \ - CHECK_NON_NULL_ARGUMENT(SetStatic #fn Field, fid); \ + CHECK_NON_NULL_ARGUMENT(fid); \ ScopedObjectAccess soa(env); \ mirror::ArtField* f = soa.DecodeField(fid); \ f->Set ##fn <false>(f->GetDeclaringClass(), value) @@ -1616,7 +1618,7 @@ class JNI { static jobject CallStaticObjectMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticObjectMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); jobject local_result = soa.AddLocalReference<jobject>(result.GetL()); @@ -1625,14 +1627,14 @@ class JNI { } static jobject CallStaticObjectMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticObjectMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, args)); return soa.AddLocalReference<jobject>(result.GetL()); } static jobject CallStaticObjectMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticObjectMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithJValues(soa, nullptr, mid, args)); return soa.AddLocalReference<jobject>(result.GetL()); @@ -1641,7 +1643,7 @@ class JNI { static jboolean CallStaticBooleanMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticBooleanMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); va_end(ap); @@ -1649,13 +1651,13 @@ class JNI { } static jboolean CallStaticBooleanMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticBooleanMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, nullptr, mid, args).GetZ(); } static jboolean CallStaticBooleanMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticBooleanMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, nullptr, mid, args).GetZ(); } @@ -1663,7 +1665,7 @@ class JNI { static jbyte CallStaticByteMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticByteMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); va_end(ap); @@ -1671,13 +1673,13 @@ class JNI { } static jbyte CallStaticByteMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticByteMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, nullptr, mid, args).GetB(); } static jbyte CallStaticByteMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticByteMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, nullptr, mid, args).GetB(); } @@ -1685,7 +1687,7 @@ class JNI { static jchar CallStaticCharMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticCharMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); va_end(ap); @@ -1693,13 +1695,13 @@ class JNI { } static jchar CallStaticCharMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticCharMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, nullptr, mid, args).GetC(); } static jchar CallStaticCharMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticCharMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, nullptr, mid, args).GetC(); } @@ -1707,7 +1709,7 @@ class JNI { static jshort CallStaticShortMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticShortMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); va_end(ap); @@ -1715,13 +1717,13 @@ class JNI { } static jshort CallStaticShortMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticShortMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, nullptr, mid, args).GetS(); } static jshort CallStaticShortMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticShortMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, nullptr, mid, args).GetS(); } @@ -1729,7 +1731,7 @@ class JNI { static jint CallStaticIntMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticIntMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); va_end(ap); @@ -1737,13 +1739,13 @@ class JNI { } static jint CallStaticIntMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticIntMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, nullptr, mid, args).GetI(); } static jint CallStaticIntMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticIntMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, nullptr, mid, args).GetI(); } @@ -1751,7 +1753,7 @@ class JNI { static jlong CallStaticLongMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticLongMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); va_end(ap); @@ -1759,13 +1761,13 @@ class JNI { } static jlong CallStaticLongMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticLongMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, nullptr, mid, args).GetJ(); } static jlong CallStaticLongMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticLongMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, nullptr, mid, args).GetJ(); } @@ -1773,7 +1775,7 @@ class JNI { static jfloat CallStaticFloatMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticFloatMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); va_end(ap); @@ -1781,13 +1783,13 @@ class JNI { } static jfloat CallStaticFloatMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticFloatMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, nullptr, mid, args).GetF(); } static jfloat CallStaticFloatMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticFloatMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, nullptr, mid, args).GetF(); } @@ -1795,7 +1797,7 @@ class JNI { static jdouble CallStaticDoubleMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticDoubleMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); JValue result(InvokeWithVarArgs(soa, nullptr, mid, ap)); va_end(ap); @@ -1803,13 +1805,13 @@ class JNI { } static jdouble CallStaticDoubleMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticDoubleMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithVarArgs(soa, nullptr, mid, args).GetD(); } static jdouble CallStaticDoubleMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticDoubleMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); return InvokeWithJValues(soa, nullptr, mid, args).GetD(); } @@ -1817,20 +1819,20 @@ class JNI { static void CallStaticVoidMethod(JNIEnv* env, jclass, jmethodID mid, ...) { va_list ap; va_start(ap, mid); - CHECK_NON_NULL_ARGUMENT(CallStaticVoidMethod, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeWithVarArgs(soa, nullptr, mid, ap); va_end(ap); } static void CallStaticVoidMethodV(JNIEnv* env, jclass, jmethodID mid, va_list args) { - CHECK_NON_NULL_ARGUMENT(CallStaticVoidMethodV, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeWithVarArgs(soa, nullptr, mid, args); } static void CallStaticVoidMethodA(JNIEnv* env, jclass, jmethodID mid, jvalue* args) { - CHECK_NON_NULL_ARGUMENT(CallStaticVoidMethodA, mid); + CHECK_NON_NULL_ARGUMENT(mid); ScopedObjectAccess soa(env); InvokeWithJValues(soa, nullptr, mid, args); } @@ -1859,26 +1861,26 @@ class JNI { } static jsize GetStringLength(JNIEnv* env, jstring java_string) { - CHECK_NON_NULL_ARGUMENT(GetStringLength, java_string); + CHECK_NON_NULL_ARGUMENT(java_string); ScopedObjectAccess soa(env); return soa.Decode<mirror::String*>(java_string)->GetLength(); } static jsize GetStringUTFLength(JNIEnv* env, jstring java_string) { - CHECK_NON_NULL_ARGUMENT(GetStringLength, java_string); + CHECK_NON_NULL_ARGUMENT(java_string); ScopedObjectAccess soa(env); return soa.Decode<mirror::String*>(java_string)->GetUtfLength(); } static void GetStringRegion(JNIEnv* env, jstring java_string, jsize start, jsize length, jchar* buf) { - CHECK_NON_NULL_ARGUMENT(GetStringRegion, java_string); + CHECK_NON_NULL_ARGUMENT(java_string); ScopedObjectAccess soa(env); mirror::String* s = soa.Decode<mirror::String*>(java_string); if (start < 0 || length < 0 || start + length > s->GetLength()) { ThrowSIOOBE(soa, start, length, s->GetLength()); } else { - CHECK_NON_NULL_MEMCPY_ARGUMENT(GetStringRegion, length, buf); + CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); const jchar* chars = s->GetCharArray()->GetData() + s->GetOffset(); memcpy(buf, chars + start, length * sizeof(jchar)); } @@ -1886,20 +1888,20 @@ class JNI { static void GetStringUTFRegion(JNIEnv* env, jstring java_string, jsize start, jsize length, char* buf) { - CHECK_NON_NULL_ARGUMENT(GetStringUTFRegion, java_string); + CHECK_NON_NULL_ARGUMENT(java_string); ScopedObjectAccess soa(env); mirror::String* s = soa.Decode<mirror::String*>(java_string); if (start < 0 || length < 0 || start + length > s->GetLength()) { ThrowSIOOBE(soa, start, length, s->GetLength()); } else { - CHECK_NON_NULL_MEMCPY_ARGUMENT(GetStringUTFRegion, length, buf); + CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); const jchar* chars = s->GetCharArray()->GetData() + s->GetOffset(); ConvertUtf16ToModifiedUtf8(buf, chars + start, length); } } static const jchar* GetStringChars(JNIEnv* env, jstring java_string, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetStringChars, java_string); + CHECK_NON_NULL_ARGUMENT(java_string); ScopedObjectAccess soa(env); mirror::String* s = soa.Decode<mirror::String*>(java_string); mirror::CharArray* chars = s->GetCharArray(); @@ -1918,7 +1920,7 @@ class JNI { } static void ReleaseStringChars(JNIEnv* env, jstring java_string, const jchar* chars) { - CHECK_NON_NULL_ARGUMENT(ReleaseStringChars, java_string); + CHECK_NON_NULL_ARGUMENT(java_string); delete[] chars; ScopedObjectAccess soa(env); UnpinPrimitiveArray(soa, soa.Decode<mirror::String*>(java_string)->GetCharArray()); @@ -1955,7 +1957,7 @@ class JNI { } static jsize GetArrayLength(JNIEnv* env, jarray java_array) { - CHECK_NON_NULL_ARGUMENT(GetArrayLength, java_array); + CHECK_NON_NULL_ARGUMENT(java_array); ScopedObjectAccess soa(env); mirror::Object* obj = soa.Decode<mirror::Object*>(java_array); if (UNLIKELY(!obj->IsArrayInstance())) { @@ -1966,7 +1968,7 @@ class JNI { } static jobject GetObjectArrayElement(JNIEnv* env, jobjectArray java_array, jsize index) { - CHECK_NON_NULL_ARGUMENT(GetObjectArrayElement, java_array); + CHECK_NON_NULL_ARGUMENT(java_array); ScopedObjectAccess soa(env); mirror::ObjectArray<mirror::Object>* array = soa.Decode<mirror::ObjectArray<mirror::Object>*>(java_array); @@ -1975,7 +1977,7 @@ class JNI { static void SetObjectArrayElement(JNIEnv* env, jobjectArray java_array, jsize index, jobject java_value) { - CHECK_NON_NULL_ARGUMENT(SetObjectArrayElement, java_array); + CHECK_NON_NULL_ARGUMENT(java_array); ScopedObjectAccess soa(env); mirror::ObjectArray<mirror::Object>* array = soa.Decode<mirror::ObjectArray<mirror::Object>*>(java_array); @@ -2070,7 +2072,7 @@ class JNI { } static void* GetPrimitiveArrayCritical(JNIEnv* env, jarray java_array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetPrimitiveArrayCritical, java_array); + CHECK_NON_NULL_ARGUMENT(java_array); ScopedObjectAccess soa(env); mirror::Array* array = soa.Decode<mirror::Array*>(java_array); gc::Heap* heap = Runtime::Current()->GetHeap(); @@ -2087,54 +2089,54 @@ class JNI { } static void ReleasePrimitiveArrayCritical(JNIEnv* env, jarray array, void* elements, jint mode) { - CHECK_NON_NULL_ARGUMENT(ReleasePrimitiveArrayCritical, array); + CHECK_NON_NULL_ARGUMENT(array); ReleasePrimitiveArray(env, array, elements, mode); } static jboolean* GetBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetBooleanArrayElements, array); + CHECK_NON_NULL_ARGUMENT(array); ScopedObjectAccess soa(env); return GetPrimitiveArray<jbooleanArray, jboolean*, mirror::BooleanArray>(soa, array, is_copy); } static jbyte* GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetByteArrayElements, array); + CHECK_NON_NULL_ARGUMENT(array); ScopedObjectAccess soa(env); return GetPrimitiveArray<jbyteArray, jbyte*, mirror::ByteArray>(soa, array, is_copy); } static jchar* GetCharArrayElements(JNIEnv* env, jcharArray array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetCharArrayElements, array); + CHECK_NON_NULL_ARGUMENT(array); ScopedObjectAccess soa(env); return GetPrimitiveArray<jcharArray, jchar*, mirror::CharArray>(soa, array, is_copy); } static jdouble* GetDoubleArrayElements(JNIEnv* env, jdoubleArray array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetDoubleArrayElements, array); + CHECK_NON_NULL_ARGUMENT(array); ScopedObjectAccess soa(env); return GetPrimitiveArray<jdoubleArray, jdouble*, mirror::DoubleArray>(soa, array, is_copy); } static jfloat* GetFloatArrayElements(JNIEnv* env, jfloatArray array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetFloatArrayElements, array); + CHECK_NON_NULL_ARGUMENT(array); ScopedObjectAccess soa(env); return GetPrimitiveArray<jfloatArray, jfloat*, mirror::FloatArray>(soa, array, is_copy); } static jint* GetIntArrayElements(JNIEnv* env, jintArray array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetIntArrayElements, array); + CHECK_NON_NULL_ARGUMENT(array); ScopedObjectAccess soa(env); return GetPrimitiveArray<jintArray, jint*, mirror::IntArray>(soa, array, is_copy); } static jlong* GetLongArrayElements(JNIEnv* env, jlongArray array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetLongArrayElements, array); + CHECK_NON_NULL_ARGUMENT(array); ScopedObjectAccess soa(env); return GetPrimitiveArray<jlongArray, jlong*, mirror::LongArray>(soa, array, is_copy); } static jshort* GetShortArrayElements(JNIEnv* env, jshortArray array, jboolean* is_copy) { - CHECK_NON_NULL_ARGUMENT(GetShortArrayElements, array); + CHECK_NON_NULL_ARGUMENT(array); ScopedObjectAccess soa(env); return GetPrimitiveArray<jshortArray, jshort*, mirror::ShortArray>(soa, array, is_copy); } @@ -2290,7 +2292,7 @@ class JNI { JniAbortF("RegisterNatives", "negative method count: %d", method_count); return JNI_ERR; // Not reached. } - CHECK_NON_NULL_ARGUMENT(RegisterNatives, java_class); + CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", java_class); ScopedObjectAccess soa(env); mirror::Class* c = soa.Decode<mirror::Class*>(java_class); if (UNLIKELY(method_count == 0)) { @@ -2298,7 +2300,7 @@ class JNI { << PrettyDescriptor(c); return JNI_OK; } - CHECK_NON_NULL_ARGUMENT(RegisterNatives, methods); + CHECK_NON_NULL_ARGUMENT_FN_NAME("RegisterNatives", methods); for (jint i = 0; i < method_count; ++i) { const char* name = methods[i].name; const char* sig = methods[i].signature; @@ -2335,7 +2337,7 @@ class JNI { } static jint UnregisterNatives(JNIEnv* env, jclass java_class) { - CHECK_NON_NULL_ARGUMENT(UnregisterNatives, java_class); + CHECK_NON_NULL_ARGUMENT(java_class); ScopedObjectAccess soa(env); mirror::Class* c = soa.Decode<mirror::Class*>(java_class); @@ -2358,7 +2360,7 @@ class JNI { } static jint MonitorEnter(JNIEnv* env, jobject java_object) NO_THREAD_SAFETY_ANALYSIS { - CHECK_NON_NULL_ARGUMENT(MonitorEnter, java_object); + CHECK_NON_NULL_ARGUMENT(java_object); ScopedObjectAccess soa(env); mirror::Object* o = soa.Decode<mirror::Object*>(java_object); o = o->MonitorEnter(soa.Self()); @@ -2370,7 +2372,7 @@ class JNI { } static jint MonitorExit(JNIEnv* env, jobject java_object) NO_THREAD_SAFETY_ANALYSIS { - CHECK_NON_NULL_ARGUMENT(MonitorExit, java_object); + CHECK_NON_NULL_ARGUMENT(java_object); ScopedObjectAccess soa(env); mirror::Object* o = soa.Decode<mirror::Object*>(java_object); o->MonitorExit(soa.Self()); @@ -2382,7 +2384,7 @@ class JNI { } static jint GetJavaVM(JNIEnv* env, JavaVM** vm) { - CHECK_NON_NULL_ARGUMENT(GetJavaVM, vm); + CHECK_NON_NULL_ARGUMENT(vm); Runtime* runtime = Runtime::Current(); if (runtime != nullptr) { *vm = runtime->GetJavaVM(); @@ -2422,7 +2424,7 @@ class JNI { } static jobjectRefType GetObjectRefType(JNIEnv* env, jobject java_object) { - CHECK_NON_NULL_ARGUMENT(GetObjectRefType, java_object); + CHECK_NON_NULL_ARGUMENT(java_object); // Do we definitely know what kind of reference this is? IndirectRef ref = reinterpret_cast<IndirectRef>(java_object); @@ -2444,23 +2446,6 @@ class JNI { if (static_cast<JNIEnvExt*>(env)->self->SirtContains(java_object)) { return JNILocalRefType; } - - if (!static_cast<JNIEnvExt*>(env)->vm->work_around_app_jni_bugs) { - return JNIInvalidRefType; - } - - // If we're handing out direct pointers, check whether it's a direct pointer to a local - // reference. - { - ScopedObjectAccess soa(env); - if (soa.Decode<mirror::Object*>(java_object) == - reinterpret_cast<mirror::Object*>(java_object)) { - mirror::Object* object = reinterpret_cast<mirror::Object*>(java_object); - if (soa.Env()->locals.ContainsDirectPointer(object)) { - return JNILocalRefType; - } - } - } return JNIInvalidRefType; } LOG(FATAL) << "IndirectRefKind[" << kind << "]"; @@ -2560,12 +2545,12 @@ class JNI { static void GetPrimitiveArrayRegion(ScopedObjectAccess& soa, JavaArrayT java_array, jsize start, jsize length, JavaT* buf) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - CHECK_NON_NULL_ARGUMENT(GetPrimitiveArrayRegion, java_array); + CHECK_NON_NULL_ARGUMENT(java_array); ArrayT* array = soa.Decode<ArrayT*>(java_array); if (start < 0 || length < 0 || start + length > array->GetLength()) { ThrowAIOOBE(soa, array, start, length, "src"); } else { - CHECK_NON_NULL_MEMCPY_ARGUMENT(GetStringRegion, length, buf); + CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); JavaT* data = array->GetData(); memcpy(buf, data + start, length * sizeof(JavaT)); } @@ -2575,12 +2560,12 @@ class JNI { static void SetPrimitiveArrayRegion(ScopedObjectAccess& soa, JavaArrayT java_array, jsize start, jsize length, const JavaT* buf) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - CHECK_NON_NULL_ARGUMENT(SetPrimitiveArrayRegion, java_array); + CHECK_NON_NULL_ARGUMENT(java_array); ArrayT* array = soa.Decode<ArrayT*>(java_array); if (start < 0 || length < 0 || start + length > array->GetLength()) { ThrowAIOOBE(soa, array, start, length, "dst"); } else { - CHECK_NON_NULL_MEMCPY_ARGUMENT(GetStringRegion, length, buf); + CHECK_NON_NULL_MEMCPY_ARGUMENT(length, buf); JavaT* data = array->GetData(); memcpy(data + start, buf, length * sizeof(JavaT)); } @@ -2993,7 +2978,6 @@ JavaVMExt::JavaVMExt(Runtime* runtime, ParsedOptions* options) check_jni(false), force_copy(false), // TODO: add a way to enable this trace(options->jni_trace_), - work_around_app_jni_bugs(false), pins_lock("JNI pin table lock", kPinTableLock), pin_table("pin table", kPinTableInitial, kPinTableMax), globals_lock("JNI global reference table lock"), @@ -3044,7 +3028,6 @@ void JavaVMExt::DumpForSigQuit(std::ostream& os) { if (force_copy) { os << " (with forcecopy)"; } - os << "; workarounds are " << (work_around_app_jni_bugs ? "on" : "off"); Thread* self = Thread::Current(); { MutexLock mu(self, pins_lock); @@ -3162,7 +3145,7 @@ bool JavaVMExt::LoadNativeLibrary(const std::string& path, if (handle == nullptr) { *detail = dlerror(); - LOG(ERROR) << "dlopen(\"" << path << "\", RTLD_LAZY) failed: " << detail; + LOG(ERROR) << "dlopen(\"" << path << "\", RTLD_LAZY) failed: " << *detail; return false; } diff --git a/runtime/jni_internal.h b/runtime/jni_internal.h index 42796dbe79..ec911b204b 100644 --- a/runtime/jni_internal.h +++ b/runtime/jni_internal.h @@ -110,9 +110,6 @@ class JavaVMExt : public JavaVM { // Extra diagnostics. std::string trace; - // Used to provide compatibility for apps that assumed direct references. - bool work_around_app_jni_bugs; - // Used to hold references to pinned primitive arrays. Mutex pins_lock DEFAULT_MUTEX_ACQUIRED_AFTER; ReferenceTable pin_table GUARDED_BY(pins_lock); @@ -149,7 +146,7 @@ struct JNIEnvExt : public JNIEnv { void PopFrame(); template<typename T> - T AddLocalReference(mirror::Object* obj, bool jni_work_arounds) + T AddLocalReference(mirror::Object* obj) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); static Offset SegmentStateOffset(); @@ -216,7 +213,7 @@ class ScopedJniEnvLocalRefState { }; template<typename T> -inline T JNIEnvExt::AddLocalReference(mirror::Object* obj, bool jni_work_arounds) { +inline T JNIEnvExt::AddLocalReference(mirror::Object* obj) { IndirectRef ref = locals.Add(local_ref_cookie, obj); // TODO: fix this to understand PushLocalFrame, so we can turn it on. @@ -231,9 +228,6 @@ inline T JNIEnvExt::AddLocalReference(mirror::Object* obj, bool jni_work_arounds } } - if (jni_work_arounds) { - return reinterpret_cast<T>(obj); - } return reinterpret_cast<T>(ref); } diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h index 3d2fd7b0ae..7f974d0cf0 100644 --- a/runtime/mirror/array-inl.h +++ b/runtime/mirror/array-inl.h @@ -27,10 +27,11 @@ namespace art { namespace mirror { -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline size_t Array::SizeOf() { // This is safe from overflow because the array was already allocated, so we know it's sane. - size_t component_size = GetClass<kVerifyFlags>()->GetComponentSize(); + size_t component_size = + GetClass<kVerifyFlags, kDoReadBarrier>()->template GetComponentSize<kDoReadBarrier>(); // Don't need to check this since we already check this in GetClass. int32_t component_count = GetLength<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>(); diff --git a/runtime/mirror/array.h b/runtime/mirror/array.h index 772d303360..6bfd5c890f 100644 --- a/runtime/mirror/array.h +++ b/runtime/mirror/array.h @@ -41,7 +41,7 @@ class MANAGED Array : public Object { const SirtRef<IntArray>& dimensions) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> int32_t GetLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { diff --git a/runtime/mirror/art_field.cc b/runtime/mirror/art_field.cc index f91cab1036..7b0b94cd78 100644 --- a/runtime/mirror/art_field.cc +++ b/runtime/mirror/art_field.cc @@ -19,6 +19,7 @@ #include "art_field-inl.h" #include "gc/accounting/card_table-inl.h" #include "object-inl.h" +#include "object_array-inl.h" #include "object_utils.h" #include "runtime.h" #include "scoped_thread_state_change.h" @@ -69,5 +70,25 @@ void ArtField::VisitRoots(RootCallback* callback, void* arg) { } } +// TODO: we could speed up the search if fields are ordered by offsets. +ArtField* ArtField::FindInstanceFieldWithOffset(mirror::Class* klass, uint32_t field_offset) { + DCHECK(klass != nullptr); + ObjectArray<ArtField>* instance_fields = klass->GetIFields(); + if (instance_fields != nullptr) { + for (int32_t i = 0, e = instance_fields->GetLength(); i < e; ++i) { + mirror::ArtField* field = instance_fields->GetWithoutChecks(i); + if (field->GetOffset().Uint32Value() == field_offset) { + return field; + } + } + } + // We did not find field in the class: look into superclass. + if (klass->GetSuperClass() != NULL) { + return FindInstanceFieldWithOffset(klass->GetSuperClass(), field_offset); + } else { + return nullptr; + } +} + } // namespace mirror } // namespace art diff --git a/runtime/mirror/art_field.h b/runtime/mirror/art_field.h index 0daa838a2c..ba70cc64e3 100644 --- a/runtime/mirror/art_field.h +++ b/runtime/mirror/art_field.h @@ -132,6 +132,10 @@ class MANAGED ArtField : public Object { return (GetAccessFlags() & kAccVolatile) != 0; } + // Returns an instance field with this offset in the given class or nullptr if not found. + static ArtField* FindInstanceFieldWithOffset(mirror::Class* klass, uint32_t field_offset) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + private: // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". // The class we are a part of diff --git a/runtime/mirror/art_method-inl.h b/runtime/mirror/art_method-inl.h index d5eccaffdc..5d62b88a0b 100644 --- a/runtime/mirror/art_method-inl.h +++ b/runtime/mirror/art_method-inl.h @@ -22,6 +22,7 @@ #include "dex_file.h" #include "entrypoints/entrypoint_utils.h" #include "object_array.h" +#include "oat.h" #include "runtime.h" namespace art { @@ -83,7 +84,7 @@ inline uint32_t ArtMethod::GetCodeSize() { } // TODO: make this Thumb2 specific code &= ~0x1; - return reinterpret_cast<uint32_t*>(code)[-1]; + return reinterpret_cast<OatMethodHeader*>(code)[-1].code_size_; } inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { diff --git a/runtime/mirror/art_method.cc b/runtime/mirror/art_method.cc index ee5a0a4060..f3303a8267 100644 --- a/runtime/mirror/art_method.cc +++ b/runtime/mirror/art_method.cc @@ -230,10 +230,15 @@ uintptr_t ArtMethod::ToNativePc(const uint32_t dex_pc) { return 0; } -uint32_t ArtMethod::FindCatchBlock(Class* exception_type, uint32_t dex_pc, +uint32_t ArtMethod::FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_pc, bool* has_no_move_exception) { MethodHelper mh(this); const DexFile::CodeItem* code_item = mh.GetCodeItem(); + // Set aside the exception while we resolve its type. + Thread* self = Thread::Current(); + ThrowLocation throw_location; + SirtRef<mirror::Throwable> exception(self, self->GetException(&throw_location)); + self->ClearException(); // Default to handler not found. uint32_t found_dex_pc = DexFile::kDexNoIndex; // Iterate over the catch handlers associated with dex_pc. @@ -245,21 +250,25 @@ uint32_t ArtMethod::FindCatchBlock(Class* exception_type, uint32_t dex_pc, break; } // Does this catch exception type apply? - Class* iter_exception_type = mh.GetDexCacheResolvedType(iter_type_idx); - if (iter_exception_type == NULL) { - // The verifier should take care of resolving all exception classes early + Class* iter_exception_type = mh.GetClassFromTypeIdx(iter_type_idx); + if (exception_type.get() == nullptr) { + self->ClearException(); LOG(WARNING) << "Unresolved exception class when finding catch block: " << mh.GetTypeDescriptorFromTypeIdx(iter_type_idx); - } else if (iter_exception_type->IsAssignableFrom(exception_type)) { + } else if (iter_exception_type->IsAssignableFrom(exception_type.get())) { found_dex_pc = it.GetHandlerAddress(); break; } } if (found_dex_pc != DexFile::kDexNoIndex) { const Instruction* first_catch_instr = - Instruction::At(&mh.GetCodeItem()->insns_[found_dex_pc]); + Instruction::At(&code_item->insns_[found_dex_pc]); *has_no_move_exception = (first_catch_instr->Opcode() != Instruction::MOVE_EXCEPTION); } + // Put the exception back. + if (exception.get() != nullptr) { + self->SetException(throw_location, exception.get()); + } return found_dex_pc; } @@ -342,30 +351,15 @@ bool ArtMethod::IsRegistered() { return native_method != jni_stub; } -extern "C" void art_work_around_app_jni_bugs(JNIEnv*, jobject); void ArtMethod::RegisterNative(Thread* self, const void* native_method, bool is_fast) { DCHECK(Thread::Current() == self); CHECK(IsNative()) << PrettyMethod(this); CHECK(!IsFastNative()) << PrettyMethod(this); CHECK(native_method != NULL) << PrettyMethod(this); - if (!self->GetJniEnv()->vm->work_around_app_jni_bugs) { - if (is_fast) { - SetAccessFlags(GetAccessFlags() | kAccFastNative); - } - SetNativeMethod(native_method); - } else { - // We've been asked to associate this method with the given native method but are working - // around JNI bugs, that include not giving Object** SIRT references to native methods. Direct - // the native method to runtime support and store the target somewhere runtime support will - // find it. -#if defined(__i386__) || defined(__x86_64__) - UNIMPLEMENTED(FATAL); -#else - SetNativeMethod(reinterpret_cast<void*>(art_work_around_app_jni_bugs)); -#endif - SetFieldPtr<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), - reinterpret_cast<const uint8_t*>(native_method), false); + if (is_fast) { + SetAccessFlags(GetAccessFlags() | kAccFastNative); } + SetNativeMethod(native_method); } void ArtMethod::UnregisterNative(Thread* self) { diff --git a/runtime/mirror/art_method.h b/runtime/mirror/art_method.h index fd5ac19435..4462036366 100644 --- a/runtime/mirror/art_method.h +++ b/runtime/mirror/art_method.h @@ -270,9 +270,11 @@ class MANAGED ArtMethod : public Object { return pc == 0; } /* - * During a stack walk, a return PC may point to the end of the code + 1 - * (in the case that the last instruction is a call that isn't expected to + * During a stack walk, a return PC may point past-the-end of the code + * in the case that the last instruction is a call that isn't expected to * return. Thus, we check <= code + GetCodeSize(). + * + * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state. */ return (code <= pc && pc <= code + GetCodeSize()); } @@ -418,12 +420,15 @@ class MANAGED ArtMethod : public Object { // Find the catch block for the given exception type and dex_pc. When a catch block is found, // indicates whether the found catch block is responsible for clearing the exception or whether // a move-exception instruction is present. - uint32_t FindCatchBlock(Class* exception_type, uint32_t dex_pc, bool* has_no_move_exception) + uint32_t FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_pc, + bool* has_no_move_exception) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); static void SetClass(Class* java_lang_reflect_ArtMethod); + template <bool kDoReadBarrier = true> static Class* GetJavaLangReflectArtMethod() { + // This does not need a RB because it is a root. return java_lang_reflect_ArtMethod_; } diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h index 025e62a5cb..3c02aa0b49 100644 --- a/runtime/mirror/class-inl.h +++ b/runtime/mirror/class-inl.h @@ -478,6 +478,19 @@ inline void Class::VisitReferences(mirror::Class* klass, const Visitor& visitor) VisitStaticFieldsReferences<kVisitClass>(this, visitor); } +template<bool kDoReadBarrier> +bool Class::IsArtFieldClass() { + Class* java_lang_Class = GetClass<kVerifyNone, kDoReadBarrier>(); + Class* java_lang_reflect_ArtField = + java_lang_Class->GetInstanceField(0)->GetClass<kVerifyNone, kDoReadBarrier>(); + return this == java_lang_reflect_ArtField; +} + +template<bool kDoReadBarrier> +bool Class::IsArtMethodClass() { + return this == ArtMethod::GetJavaLangReflectArtMethod<kDoReadBarrier>(); +} + } // namespace mirror } // namespace art diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index 6dbb29dae3..ad86e1fc88 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -328,16 +328,6 @@ bool Class::IsThrowableClass() { return WellKnownClasses::ToClass(WellKnownClasses::java_lang_Throwable)->IsAssignableFrom(this); } -bool Class::IsArtFieldClass() { - Class* java_lang_Class = GetClass(); - Class* java_lang_reflect_ArtField = java_lang_Class->GetInstanceField(0)->GetClass(); - return this == java_lang_reflect_ArtField; -} - -bool Class::IsArtMethodClass() { - return this == ArtMethod::GetJavaLangReflectArtMethod(); -} - void Class::SetClassLoader(ClassLoader* new_class_loader) { if (Runtime::Current()->IsActiveTransaction()) { SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false); diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h index d955b9791f..226dee0c9a 100644 --- a/runtime/mirror/class.h +++ b/runtime/mirror/class.h @@ -364,9 +364,9 @@ class MANAGED Class : public Object { return depth; } - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> bool IsArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return GetComponentType<kVerifyFlags>() != NULL; + return GetComponentType<kVerifyFlags, kDoReadBarrier>() != NULL; } bool IsClassClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); @@ -375,17 +375,19 @@ class MANAGED Class : public Object { bool IsThrowableClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + template<bool kDoReadBarrier = true> bool IsArtFieldClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + template<bool kDoReadBarrier = true> bool IsArtMethodClass(); static MemberOffset ComponentTypeOffset() { return OFFSET_OF_OBJECT_MEMBER(Class, component_type_); } - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return GetFieldObject<Class, kVerifyFlags>(ComponentTypeOffset(), false); + return GetFieldObject<Class, kVerifyFlags, kDoReadBarrier>(ComponentTypeOffset(), false); } void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { @@ -395,8 +397,10 @@ class MANAGED Class : public Object { SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type, false); } + template<bool kDoReadBarrier = true> size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return Primitive::ComponentSize(GetComponentType()->GetPrimitiveType()); + return Primitive::ComponentSize( + GetComponentType<kDefaultVerifyFlags, kDoReadBarrier>()->GetPrimitiveType()); } bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { @@ -427,7 +431,7 @@ class MANAGED Class : public Object { return IsClassClass() || IsArrayClass(); } - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), false); } diff --git a/runtime/mirror/object-inl.h b/runtime/mirror/object-inl.h index 2505855831..04517ec28b 100644 --- a/runtime/mirror/object-inl.h +++ b/runtime/mirror/object-inl.h @@ -34,9 +34,10 @@ namespace art { namespace mirror { -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline Class* Object::GetClass() { - return GetFieldObject<Class, kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Object, klass_), false); + return GetFieldObject<Class, kVerifyFlags, kDoReadBarrier>( + OFFSET_OF_OBJECT_MEMBER(Object, klass_), false); } template<VerifyObjectFlags kVerifyFlags> @@ -51,14 +52,14 @@ inline void Object::SetClass(Class* new_klass) { OFFSET_OF_OBJECT_MEMBER(Object, klass_), new_klass, false); } -inline LockWord Object::GetLockWord(bool is_volatile) { - return LockWord(GetField32(OFFSET_OF_OBJECT_MEMBER(Object, monitor_), is_volatile)); +inline LockWord Object::GetLockWord(bool as_volatile) { + return LockWord(GetField32(OFFSET_OF_OBJECT_MEMBER(Object, monitor_), as_volatile)); } -inline void Object::SetLockWord(LockWord new_val, bool is_volatile) { +inline void Object::SetLockWord(LockWord new_val, bool as_volatile) { // Force use of non-transactional mode and do not check. SetField32<false, false>(OFFSET_OF_OBJECT_MEMBER(Object, monitor_), new_val.GetValue(), - is_volatile); + as_volatile); } inline bool Object::CasLockWord(LockWord old_val, LockWord new_val) { @@ -105,15 +106,42 @@ inline Object* Object::GetReadBarrierPointer() { #endif } -inline void Object::SetReadBarrierPointer(Object* rb_pointer) { +inline void Object::SetReadBarrierPointer(Object* rb_ptr) { #ifdef USE_BAKER_OR_BROOKS_READ_BARRIER DCHECK(kUseBakerOrBrooksReadBarrier); // We don't mark the card as this occurs as part of object allocation. Not all objects have // backing cards, such as large objects. SetFieldObjectWithoutWriteBarrier<false, false, kVerifyNone>( - OFFSET_OF_OBJECT_MEMBER(Object, x_rb_ptr_), rb_pointer, false); + OFFSET_OF_OBJECT_MEMBER(Object, x_rb_ptr_), rb_ptr, false); +#else + LOG(FATAL) << "Unreachable"; +#endif +} + +inline bool Object::AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr) { +#ifdef USE_BAKER_OR_BROOKS_READ_BARRIER + DCHECK(kUseBakerOrBrooksReadBarrier); + MemberOffset offset = OFFSET_OF_OBJECT_MEMBER(Object, x_rb_ptr_); + byte* raw_addr = reinterpret_cast<byte*>(this) + offset.SizeValue(); + HeapReference<Object>* ref = reinterpret_cast<HeapReference<Object>*>(raw_addr); + HeapReference<Object> expected_ref(HeapReference<Object>::FromMirrorPtr(expected_rb_ptr)); + HeapReference<Object> new_ref(HeapReference<Object>::FromMirrorPtr(rb_ptr)); + uint32_t expected_val = expected_ref.reference_; + uint32_t new_val; + do { + uint32_t old_val = ref->reference_; + if (old_val != expected_val) { + // Lost the race. + return false; + } + new_val = new_ref.reference_; + } while (!__sync_bool_compare_and_swap( + reinterpret_cast<uint32_t*>(raw_addr), expected_val, new_val)); + DCHECK_EQ(new_val, ref->reference_); + return true; #else LOG(FATAL) << "Unreachable"; + return false; #endif } @@ -147,16 +175,17 @@ inline bool Object::InstanceOf(Class* klass) { return klass->IsAssignableFrom(GetClass<kVerifyFlags>()); } -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline bool Object::IsClass() { - Class* java_lang_Class = GetClass<kVerifyFlags>()->GetClass(); - return GetClass<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>() == + Class* java_lang_Class = + GetClass<kVerifyFlags, kDoReadBarrier>()->template GetClass<kVerifyFlags, kDoReadBarrier>(); + return GetClass<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis), kDoReadBarrier>() == java_lang_Class; } -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline Class* Object::AsClass() { - DCHECK(IsClass<kVerifyFlags>()); + DCHECK((IsClass<kVerifyFlags, kDoReadBarrier>())); return down_cast<Class*>(this); } @@ -173,14 +202,15 @@ inline ObjectArray<T>* Object::AsObjectArray() { return down_cast<ObjectArray<T>*>(this); } -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline bool Object::IsArrayInstance() { - return GetClass<kVerifyFlags>()->IsArrayClass(); + return GetClass<kVerifyFlags, kDoReadBarrier>()-> + template IsArrayClass<kVerifyFlags, kDoReadBarrier>(); } -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline bool Object::IsArtField() { - return GetClass<kVerifyFlags>()->IsArtFieldClass(); + return GetClass<kVerifyFlags, kDoReadBarrier>()->template IsArtFieldClass<kDoReadBarrier>(); } template<VerifyObjectFlags kVerifyFlags> @@ -189,9 +219,9 @@ inline ArtField* Object::AsArtField() { return down_cast<ArtField*>(this); } -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline bool Object::IsArtMethod() { - return GetClass<kVerifyFlags>()->IsArtMethodClass(); + return GetClass<kVerifyFlags, kDoReadBarrier>()->template IsArtMethodClass<kDoReadBarrier>(); } template<VerifyObjectFlags kVerifyFlags> @@ -211,9 +241,9 @@ inline Reference* Object::AsReference() { return down_cast<Reference*>(this); } -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline Array* Object::AsArray() { - DCHECK(IsArrayInstance<kVerifyFlags>()); + DCHECK((IsArrayInstance<kVerifyFlags, kDoReadBarrier>())); return down_cast<Array*>(this); } @@ -339,20 +369,21 @@ inline bool Object::IsPhantomReferenceInstance() { return GetClass<kVerifyFlags>()->IsPhantomReferenceClass(); } -template<VerifyObjectFlags kVerifyFlags> +template<VerifyObjectFlags kVerifyFlags, bool kDoReadBarrier> inline size_t Object::SizeOf() { size_t result; constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis); - if (IsArrayInstance<kVerifyFlags>()) { - result = AsArray<kNewFlags>()->template SizeOf<kNewFlags>(); - } else if (IsClass<kNewFlags>()) { - result = AsClass<kNewFlags>()->template SizeOf<kNewFlags>(); + if (IsArrayInstance<kVerifyFlags, kDoReadBarrier>()) { + result = AsArray<kNewFlags, kDoReadBarrier>()->template SizeOf<kNewFlags, kDoReadBarrier>(); + } else if (IsClass<kNewFlags, kDoReadBarrier>()) { + result = AsClass<kNewFlags, kDoReadBarrier>()->template SizeOf<kNewFlags, kDoReadBarrier>(); } else { - result = GetClass<kNewFlags>()->GetObjectSize(); + result = GetClass<kNewFlags, kDoReadBarrier>()->GetObjectSize(); } - DCHECK_GE(result, sizeof(Object)) << " class=" << PrettyTypeOf(GetClass<kNewFlags>()); - DCHECK(!IsArtField<kNewFlags>() || result == sizeof(ArtField)); - DCHECK(!IsArtMethod<kNewFlags>() || result == sizeof(ArtMethod)); + DCHECK_GE(result, sizeof(Object)) + << " class=" << PrettyTypeOf(GetClass<kNewFlags, kDoReadBarrier>()); + DCHECK(!(IsArtField<kNewFlags, kDoReadBarrier>()) || result == sizeof(ArtField)); + DCHECK(!(IsArtMethod<kNewFlags, kDoReadBarrier>()) || result == sizeof(ArtMethod)); return result; } diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h index fd31dfbbb5..370b3b89cb 100644 --- a/runtime/mirror/object.h +++ b/runtime/mirror/object.h @@ -72,14 +72,16 @@ class MANAGED LOCKABLE Object { return OFFSET_OF_OBJECT_MEMBER(Object, klass_); } - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> Class* GetClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> void SetClass(Class* new_klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); Object* GetReadBarrierPointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - void SetReadBarrierPointer(Object* rb_pointer) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + void SetReadBarrierPointer(Object* rb_ptr) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void AssertReadBarrierPointer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in @@ -89,7 +91,7 @@ class MANAGED LOCKABLE Object { template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> bool InstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); Object* Clone(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); @@ -116,9 +118,9 @@ class MANAGED LOCKABLE Object { void Wait(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> bool IsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> Class* AsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> @@ -126,9 +128,9 @@ class MANAGED LOCKABLE Object { template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ObjectArray<T>* AsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> bool IsArrayInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> Array* AsArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> @@ -161,12 +163,12 @@ class MANAGED LOCKABLE Object { template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> Throwable* AsThrowable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> bool IsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ArtMethod* AsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> bool IsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ArtField* AsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc index 5c5eaa1ad4..76c58662d4 100644 --- a/runtime/native/dalvik_system_VMRuntime.cc +++ b/runtime/native/dalvik_system_VMRuntime.cc @@ -164,23 +164,12 @@ static jstring VMRuntime_vmLibrary(JNIEnv* env, jobject) { } static void VMRuntime_setTargetSdkVersionNative(JNIEnv* env, jobject, jint targetSdkVersion) { - // This is the target SDK version of the app we're about to run. + // This is the target SDK version of the app we're about to run. It is intended that this a place + // where workarounds can be enabled. // Note that targetSdkVersion may be CUR_DEVELOPMENT (10000). // Note that targetSdkVersion may be 0, meaning "current". - if (targetSdkVersion > 0 && targetSdkVersion <= 13 /* honeycomb-mr2 */) { - Runtime* runtime = Runtime::Current(); - JavaVMExt* vm = runtime->GetJavaVM(); - if (vm->check_jni) { - LOG(INFO) << "CheckJNI enabled: not enabling JNI app bug workarounds."; - } else { - LOG(INFO) << "Turning on JNI app bug workarounds for target SDK version " - << targetSdkVersion << "..."; - - vm->work_around_app_jni_bugs = true; - LOG(WARNING) << "Permenantly disabling heap compaction due to jni workarounds"; - Runtime::Current()->GetHeap()->DisableCompaction(); - } - } + UNUSED(env); + UNUSED(targetSdkVersion); } static void VMRuntime_registerNativeAllocation(JNIEnv* env, jobject, jint bytes) { diff --git a/runtime/native/java_lang_Thread.cc b/runtime/native/java_lang_Thread.cc index 0b84005f5a..86db893cf8 100644 --- a/runtime/native/java_lang_Thread.cc +++ b/runtime/native/java_lang_Thread.cc @@ -88,6 +88,7 @@ static jint Thread_nativeGetStatus(JNIEnv* env, jobject java_thread, jboolean ha case kSuspended: return kJavaRunnable; // Don't add a 'default' here so the compiler can spot incompatible enum changes. } + LOG(ERROR) << "Unexpected thread state: " << internal_thread_state; return -1; // Unreachable. } diff --git a/runtime/oat.cc b/runtime/oat.cc index 246e090f22..d01dc72b05 100644 --- a/runtime/oat.cc +++ b/runtime/oat.cc @@ -22,7 +22,7 @@ namespace art { const uint8_t OatHeader::kOatMagic[] = { 'o', 'a', 't', '\n' }; -const uint8_t OatHeader::kOatVersion[] = { '0', '2', '0', '\0' }; +const uint8_t OatHeader::kOatVersion[] = { '0', '2', '1', '\0' }; OatHeader::OatHeader() { memset(this, 0, sizeof(*this)); @@ -372,4 +372,14 @@ OatMethodOffsets::OatMethodOffsets(uint32_t code_offset, OatMethodOffsets::~OatMethodOffsets() {} +OatMethodHeader::OatMethodHeader() + : code_size_(0) +{} + +OatMethodHeader::OatMethodHeader(uint32_t code_size) + : code_size_(code_size) +{} + +OatMethodHeader::~OatMethodHeader() {} + } // namespace art diff --git a/runtime/oat.h b/runtime/oat.h index 2851f5c14d..035aba1057 100644 --- a/runtime/oat.h +++ b/runtime/oat.h @@ -155,6 +155,19 @@ class PACKED(4) OatMethodOffsets { uint32_t gc_map_offset_; }; +// OatMethodHeader precedes the raw code chunk generated by the Quick compiler. +class PACKED(4) OatMethodHeader { + public: + OatMethodHeader(); + + explicit OatMethodHeader(uint32_t code_size); + + ~OatMethodHeader(); + + // The code size in bytes. + uint32_t code_size_; +}; + } // namespace art #endif // ART_RUNTIME_OAT_H_ diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index 1967345c7c..0aff8c300f 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -386,7 +386,7 @@ const DexFile* OatFile::OatDexFile::OpenDexFile(std::string* error_msg) const { dex_file_location_checksum_, error_msg); } -const OatFile::OatClass* OatFile::OatDexFile::GetOatClass(uint16_t class_def_index) const { +OatFile::OatClass OatFile::OatDexFile::GetOatClass(uint16_t class_def_index) const { uint32_t oat_class_offset = oat_class_offsets_pointer_[class_def_index]; const byte* oat_class_pointer = oat_file_->Begin() + oat_class_offset; @@ -419,12 +419,12 @@ const OatFile::OatClass* OatFile::OatDexFile::GetOatClass(uint16_t class_def_ind } CHECK_LE(methods_pointer, oat_file_->End()) << oat_file_->GetLocation(); - return new OatClass(oat_file_, - status, - type, - bitmap_size, - reinterpret_cast<const uint32_t*>(bitmap_pointer), - reinterpret_cast<const OatMethodOffsets*>(methods_pointer)); + return OatClass(oat_file_, + status, + type, + bitmap_size, + reinterpret_cast<const uint32_t*>(bitmap_pointer), + reinterpret_cast<const OatMethodOffsets*>(methods_pointer)); } OatFile::OatClass::OatClass(const OatFile* oat_file, @@ -434,7 +434,7 @@ OatFile::OatClass::OatClass(const OatFile* oat_file, const uint32_t* bitmap_pointer, const OatMethodOffsets* methods_pointer) : oat_file_(oat_file), status_(status), type_(type), - bitmap_(NULL), methods_pointer_(methods_pointer) { + bitmap_(bitmap_pointer), methods_pointer_(methods_pointer) { CHECK(methods_pointer != nullptr); switch (type_) { case kOatClassAllCompiled: { @@ -445,14 +445,12 @@ OatFile::OatClass::OatClass(const OatFile* oat_file, case kOatClassSomeCompiled: { CHECK_NE(0U, bitmap_size); CHECK(bitmap_pointer != nullptr); - bitmap_ = new BitVector(0, false, Allocator::GetNoopAllocator(), bitmap_size, - const_cast<uint32_t*>(bitmap_pointer)); break; } case kOatClassNoneCompiled: { CHECK_EQ(0U, bitmap_size); CHECK(bitmap_pointer == nullptr); - methods_pointer_ = NULL; + methods_pointer_ = nullptr; break; } case kOatClassMax: { @@ -462,11 +460,8 @@ OatFile::OatClass::OatClass(const OatFile* oat_file, } } -OatFile::OatClass::~OatClass() { - delete bitmap_; -} - const OatFile::OatMethod OatFile::OatClass::GetOatMethod(uint32_t method_index) const { + // NOTE: We don't keep the number of methods and cannot do a bounds check for method_index. if (methods_pointer_ == NULL) { CHECK_EQ(kOatClassNoneCompiled, type_); return OatMethod(NULL, 0, 0, 0, 0, 0, 0, 0); @@ -477,12 +472,11 @@ const OatFile::OatMethod OatFile::OatClass::GetOatMethod(uint32_t method_index) methods_pointer_index = method_index; } else { CHECK_EQ(kOatClassSomeCompiled, type_); - if (!bitmap_->IsBitSet(method_index)) { + if (!BitVector::IsBitSet(bitmap_, method_index)) { return OatMethod(NULL, 0, 0, 0, 0, 0, 0, 0); } - size_t num_set_bits = bitmap_->NumSetBits(method_index); - CHECK_NE(0U, num_set_bits); - methods_pointer_index = num_set_bits - 1; + size_t num_set_bits = BitVector::NumSetBits(bitmap_, method_index); + methods_pointer_index = num_set_bits; } const OatMethodOffsets& oat_method_offsets = methods_pointer_[methods_pointer_index]; return OatMethod( diff --git a/runtime/oat_file.h b/runtime/oat_file.h index d6e8dc07f2..10f64cc91e 100644 --- a/runtime/oat_file.h +++ b/runtime/oat_file.h @@ -181,7 +181,6 @@ class OatFile { // methods. note that runtime created methods such as miranda // methods are not included. const OatMethod GetOatMethod(uint32_t method_index) const; - ~OatClass(); private: OatClass(const OatFile* oat_file, @@ -191,15 +190,13 @@ class OatFile { const uint32_t* bitmap_pointer, const OatMethodOffsets* methods_pointer); - const OatFile* oat_file_; + const OatFile* const oat_file_; const mirror::Class::Status status_; - COMPILE_ASSERT(mirror::Class::Status::kStatusMax < (2 ^ 16), class_status_wont_fit_in_16bits); - OatClassType type_; - COMPILE_ASSERT(OatClassType::kOatClassMax < (2 ^ 16), oat_class_type_wont_fit_in_16bits); + const OatClassType type_; - const BitVector* bitmap_; + const uint32_t* const bitmap_; const OatMethodOffsets* methods_pointer_; @@ -225,7 +222,7 @@ class OatFile { } // Returns the OatClass for the class specified by the given DexFile class_def_index. - const OatClass* GetOatClass(uint16_t class_def_index) const; + OatClass GetOatClass(uint16_t class_def_index) const; ~OatDexFile(); diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc index 57d32bb476..084e8f6a0e 100644 --- a/runtime/parsed_options.cc +++ b/runtime/parsed_options.cc @@ -251,7 +251,7 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni // TODO: support -Djava.class.path i++; if (i == options.size()) { - Usage("Missing required class path value for %s", option.c_str()); + Usage("Missing required class path value for %s\n", option.c_str()); return false; } const StringPiece& value = options[i].first; @@ -279,35 +279,35 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni } else if (StartsWith(option, "-Xms")) { size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024); if (size == 0) { - Usage("Failed to parse memory option %s", option.c_str()); + Usage("Failed to parse memory option %s\n", option.c_str()); return false; } heap_initial_size_ = size; } else if (StartsWith(option, "-Xmx")) { size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024); if (size == 0) { - Usage("Failed to parse memory option %s", option.c_str()); + Usage("Failed to parse memory option %s\n", option.c_str()); return false; } heap_maximum_size_ = size; } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) { size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024); if (size == 0) { - Usage("Failed to parse memory option %s", option.c_str()); + Usage("Failed to parse memory option %s\n", option.c_str()); return false; } heap_growth_limit_ = size; } else if (StartsWith(option, "-XX:HeapMinFree=")) { size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024); if (size == 0) { - Usage("Failed to parse memory option %s", option.c_str()); + Usage("Failed to parse memory option %s\n", option.c_str()); return false; } heap_min_free_ = size; } else if (StartsWith(option, "-XX:HeapMaxFree=")) { size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024); if (size == 0) { - Usage("Failed to parse memory option %s", option.c_str()); + Usage("Failed to parse memory option %s\n", option.c_str()); return false; } heap_max_free_ = size; @@ -316,7 +316,7 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni return false; } } else if (StartsWith(option, "-XX:ForegroundHeapGrowthMultiplier=")) { - if (!ParseDouble(option, '=', 0.1, 0.9, &foreground_heap_growth_multiplier_)) { + if (!ParseDouble(option, '=', 0.1, 10.0, &foreground_heap_growth_multiplier_)) { return false; } } else if (StartsWith(option, "-XX:ParallelGCThreads=")) { @@ -330,7 +330,7 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni } else if (StartsWith(option, "-Xss")) { size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1); if (size == 0) { - Usage("Failed to parse memory option %s", option.c_str()); + Usage("Failed to parse memory option %s\n", option.c_str()); return false; } stack_size_ = size; @@ -398,7 +398,7 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni (gc_option == "noverifycardtable")) { // Ignored for backwards compatibility. } else { - Usage("Unknown -Xgc option %s", gc_option.c_str()); + Usage("Unknown -Xgc option %s\n", gc_option.c_str()); return false; } } @@ -411,7 +411,7 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni if (collector_type != gc::kCollectorTypeNone) { background_collector_type_ = collector_type; } else { - Usage("Unknown -XX:BackgroundGC option %s", substring.c_str()); + Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str()); return false; } } else if (option == "-XX:+DisableExplicitGC") { @@ -443,10 +443,13 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni } else if (verbose_options[i] == "threads") { gLogVerbosity.threads = true; } else { - Usage("Unknown -verbose option %s", verbose_options[i].c_str()); + Usage("Unknown -verbose option %s\n", verbose_options[i].c_str()); return false; } } + } else if (StartsWith(option, "-verbose-methods:")) { + gLogVerbosity.compiler = false; + Split(option.substr(strlen("-verbose-methods:")), ',', gVerboseMethods); } else if (StartsWith(option, "-Xlockprofthreshold:")) { if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) { return false; @@ -476,7 +479,7 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni } else if (option == "abort") { const void* hook = options[i].second; if (hook == nullptr) { - Usage("abort was NULL"); + Usage("abort was NULL\n"); return false; } hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook)); @@ -568,14 +571,14 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni } else if (option == "-Xcompiler-option") { i++; if (i == options.size()) { - Usage("Missing required compiler option for %s", option.c_str()); + Usage("Missing required compiler option for %s\n", option.c_str()); return false; } compiler_options_.push_back(options[i].first); } else if (option == "-Ximage-compiler-option") { i++; if (i == options.size()) { - Usage("Missing required compiler option for %s", option.c_str()); + Usage("Missing required compiler option for %s\n", option.c_str()); return false; } image_compiler_options_.push_back(options[i].first); @@ -586,7 +589,7 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni } else if (verify_mode == "remote" || verify_mode == "all") { verify_ = true; } else { - Usage("Unknown -Xverify option %s", verify_mode.c_str()); + Usage("Unknown -Xverify option %s\n", verify_mode.c_str()); return false; } } else if (StartsWith(option, "-ea") || @@ -626,7 +629,7 @@ bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecogni StartsWith(option, "-XX:mainThreadStackSize=")) { // Ignored for backwards compatibility. } else if (!ignore_unrecognized) { - Usage("Unrecognized option %s", option.c_str()); + Usage("Unrecognized option %s\n", option.c_str()); return false; } } @@ -717,6 +720,7 @@ void ParsedOptions::Usage(const char* fmt, ...) { UsageMessage(stream, " -XX:HeapMinFree=N\n"); UsageMessage(stream, " -XX:HeapMaxFree=N\n"); UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n"); + UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n"); UsageMessage(stream, " -XX:LowMemoryMode\n"); UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n"); UsageMessage(stream, "\n"); @@ -789,7 +793,7 @@ void ParsedOptions::Usage(const char* fmt, ...) { bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) { std::string::size_type colon = s.find(c); if (colon == std::string::npos) { - Usage("Missing char %c in option %s", c, s.c_str()); + Usage("Missing char %c in option %s\n", c, s.c_str()); return false; } // Add one to remove the char we were trimming until. @@ -800,14 +804,14 @@ bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::stri bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) { std::string::size_type colon = s.find(after_char); if (colon == std::string::npos) { - Usage("Missing char %c in option %s", after_char, s.c_str()); + Usage("Missing char %c in option %s\n", after_char, s.c_str()); return false; } const char* begin = &s[colon + 1]; char* end; size_t result = strtoul(begin, &end, 10); if (begin == end || *end != '\0') { - Usage("Failed to parse integer from %s ", s.c_str()); + Usage("Failed to parse integer from %s\n", s.c_str()); return false; } *parsed_value = result; @@ -821,7 +825,7 @@ bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char, return false; } if (i < 0) { - Usage("Negative value %d passed for unsigned option %s", i, s.c_str()); + Usage("Negative value %d passed for unsigned option %s\n", i, s.c_str()); return false; } *parsed_value = i; @@ -840,7 +844,7 @@ bool ParsedOptions::ParseDouble(const std::string& option, char after_char, // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range. const bool sane_val = iss.eof() && (value >= min) && (value <= max); if (!sane_val) { - Usage("Invalid double value %s for option %s", option.c_str()); + Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str()); return false; } *parsed_value = value; diff --git a/runtime/runtime_linux.cc b/runtime/runtime_linux.cc index da1b2cac14..960d3324d3 100644 --- a/runtime/runtime_linux.cc +++ b/runtime/runtime_linux.cc @@ -33,7 +33,7 @@ static constexpr bool kDumpHeapObjectOnSigsevg = false; struct Backtrace { void Dump(std::ostream& os) { - DumpNativeStack(os, GetTid(), "\t", true); + DumpNativeStack(os, GetTid(), "\t"); } }; diff --git a/runtime/scoped_thread_state_change.h b/runtime/scoped_thread_state_change.h index ebc545250a..7698d6a49b 100644 --- a/runtime/scoped_thread_state_change.h +++ b/runtime/scoped_thread_state_change.h @@ -38,23 +38,18 @@ class ScopedThreadStateChange { Runtime* runtime = Runtime::Current(); CHECK(runtime == NULL || !runtime->IsStarted() || runtime->IsShuttingDown(self_)); } else { - bool runnable_transition; DCHECK_EQ(self, Thread::Current()); // Read state without locks, ok as state is effectively thread local and we're not interested // in the suspend count (this will be handled in the runnable transitions). old_thread_state_ = self->GetState(); - runnable_transition = old_thread_state_ == kRunnable || new_thread_state == kRunnable; - if (!runnable_transition) { - // A suspended transition to another effectively suspended transition, ok to use Unsafe. - self_->SetState(new_thread_state); - } - - if (runnable_transition && old_thread_state_ != new_thread_state) { + if (old_thread_state_ != new_thread_state) { if (new_thread_state == kRunnable) { self_->TransitionFromSuspendedToRunnable(); - } else { - DCHECK_EQ(old_thread_state_, kRunnable); + } else if (old_thread_state_ == kRunnable) { self_->TransitionFromRunnableToSuspended(new_thread_state); + } else { + // A suspended transition to another effectively suspended transition, ok to use Unsafe. + self_->SetState(new_thread_state); } } } @@ -171,7 +166,7 @@ class ScopedObjectAccessUnchecked : public ScopedThreadStateChange { DCHECK_NE((reinterpret_cast<uintptr_t>(obj) & 0xffff0000), 0xebad0000); - return Env()->AddLocalReference<T>(obj, Vm()->work_around_app_jni_bugs); + return Env()->AddLocalReference<T>(obj); } template<typename T> diff --git a/runtime/thread.cc b/runtime/thread.cc index 8691dec3b6..998579dbc7 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -939,7 +939,7 @@ void Thread::DumpStack(std::ostream& os) const { if (dump_for_abort || ShouldShowNativeStack(this)) { DumpKernelStack(os, GetTid(), " kernel: ", false); SirtRef<mirror::ArtMethod> method_ref(Thread::Current(), GetCurrentMethod(nullptr)); - DumpNativeStack(os, GetTid(), " native: ", false, method_ref.get()); + DumpNativeStack(os, GetTid(), " native: ", method_ref.get()); } DumpJavaStack(os); } else { @@ -1248,10 +1248,6 @@ mirror::Object* Thread::DecodeJObject(jobject obj) const { // Read from SIRT. result = reinterpret_cast<StackReference<mirror::Object>*>(obj)->AsMirrorPtr(); VerifyObject(result); - } else if (Runtime::Current()->GetJavaVM()->work_around_app_jni_bugs) { - // Assume an invalid local reference is actually a direct pointer. - result = reinterpret_cast<mirror::Object*>(obj); - VerifyObject(result); } else { result = kInvalidIndirectRefObject; } diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc index 270deb0a9e..6f93566a57 100644 --- a/runtime/thread_list.cc +++ b/runtime/thread_list.cc @@ -78,7 +78,7 @@ void ThreadList::DumpNativeStacks(std::ostream& os) { MutexLock mu(Thread::Current(), *Locks::thread_list_lock_); for (const auto& thread : list_) { os << "DUMPING THREAD " << thread->GetTid() << "\n"; - DumpNativeStack(os, thread->GetTid(), "\t", true); + DumpNativeStack(os, thread->GetTid(), "\t"); os << "\n"; } } @@ -99,7 +99,7 @@ static void DumpUnattachedThread(std::ostream& os, pid_t tid) NO_THREAD_SAFETY_A // TODO: Reenable this when the native code in system_server can handle it. // Currently "adb shell kill -3 `pid system_server`" will cause it to exit. if (false) { - DumpNativeStack(os, tid, " native: ", false); + DumpNativeStack(os, tid, " native: "); } os << "\n"; } diff --git a/runtime/utils.cc b/runtime/utils.cc index afbcbb7582..c4d1a7864c 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -1041,20 +1041,7 @@ std::string GetSchedulerGroupName(pid_t tid) { return ""; } -static std::string CleanMapName(const backtrace_map_t* map) { - if (map == NULL || map->name.empty()) { - return "???"; - } - // Turn "/usr/local/google/home/enh/clean-dalvik-dev/out/host/linux-x86/lib/libartd.so" - // into "libartd.so". - size_t last_slash = map->name.rfind('/'); - if (last_slash == std::string::npos) { - return map->name; - } - return map->name.substr(last_slash + 1); -} - -void DumpNativeStack(std::ostream& os, pid_t tid, const char* prefix, bool include_count, +void DumpNativeStack(std::ostream& os, pid_t tid, const char* prefix, mirror::ArtMethod* current_method) { // We may be called from contexts where current_method is not null, so we must assert this. if (current_method != nullptr) { @@ -1072,27 +1059,34 @@ void DumpNativeStack(std::ostream& os, pid_t tid, const char* prefix, bool inclu for (Backtrace::const_iterator it = backtrace->begin(); it != backtrace->end(); ++it) { // We produce output like this: - // ] #00 unwind_backtrace_thread+536 [0x55d75bb8] (libbacktrace.so) - os << prefix; - if (include_count) { - os << StringPrintf("#%02zu ", it->num); - } - if (!it->func_name.empty()) { - os << it->func_name; + // ] #00 pc 000075bb8 /system/lib/libc.so (unwind_backtrace_thread+536) + // In order for parsing tools to continue to function, the stack dump + // format must at least adhere to this format: + // #XX pc <RELATIVE_ADDR> <FULL_PATH_TO_SHARED_LIBRARY> ... + // The parsers require a single space before and after pc, and two spaces + // after the <RELATIVE_ADDR>. There can be any prefix data before the + // #XX. <RELATIVE_ADDR> has to be a hex number but with no 0x prefix. + os << prefix << StringPrintf("#%02zu pc ", it->num); + if (!it->map) { + os << StringPrintf("%08" PRIxPTR " ???", it->pc); } else { - if (current_method != nullptr && current_method->IsWithinQuickCode(it->pc)) { + os << StringPrintf("%08" PRIxPTR " ", it->pc - it->map->start) + << it->map->name << " ("; + if (!it->func_name.empty()) { + os << it->func_name; + if (it->func_offset != 0) { + os << "+" << it->func_offset; + } + } else if (current_method != nullptr && current_method->IsWithinQuickCode(it->pc)) { const void* start_of_code = current_method->GetEntryPointFromQuickCompiledCode(); os << JniLongName(current_method) << "+" << (it->pc - reinterpret_cast<uintptr_t>(start_of_code)); } else { os << "???"; } + os << ")"; } - if (it->func_offset != 0) { - os << "+" << it->func_offset; - } - os << StringPrintf(" [%p]", reinterpret_cast<void*>(it->pc)); - os << " (" << CleanMapName(it->map) << ")\n"; + os << "\n"; } } diff --git a/runtime/utils.h b/runtime/utils.h index 5def66b56c..6ab10137b1 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -382,7 +382,7 @@ void SetThreadName(const char* thread_name); // Dumps the native stack for thread 'tid' to 'os'. void DumpNativeStack(std::ostream& os, pid_t tid, const char* prefix = "", - bool include_count = true, mirror::ArtMethod* current_method = nullptr) + mirror::ArtMethod* current_method = nullptr) NO_THREAD_SAFETY_ANALYSIS; // Dumps the kernel stack for thread 'tid' to 'os'. Note that this is only available on linux-x86. diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index 4159c08486..91170f0e83 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -2868,11 +2868,7 @@ const RegType& MethodVerifier::GetCaughtExceptionType() { common_super = ®_types_.JavaLangThrowable(false); } else { const RegType& exception = ResolveClassAndCheckAccess(iterator.GetHandlerTypeIndex()); - if (common_super == NULL) { - // Unconditionally assign for the first handler. We don't assert this is a Throwable - // as that is caught at runtime - common_super = &exception; - } else if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(exception)) { + if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(exception)) { if (exception.IsUnresolvedTypes()) { // We don't know enough about the type. Fail here and let runtime handle it. Fail(VERIFY_ERROR_NO_CLASS) << "unresolved exception class " << exception; @@ -2881,6 +2877,8 @@ const RegType& MethodVerifier::GetCaughtExceptionType() { Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "unexpected non-exception class " << exception; return reg_types_.Conflict(); } + } else if (common_super == nullptr) { + common_super = &exception; } else if (common_super->Equals(exception)) { // odd case, but nothing to do } else { @@ -3599,29 +3597,6 @@ void MethodVerifier::VerifyISPut(const Instruction* inst, const RegType& insn_ty } } -// Look for an instance field with this offset. -// TODO: we may speed up the search if offsets are sorted by doing a quick search. -static mirror::ArtField* FindInstanceFieldWithOffset(mirror::Class* klass, uint32_t field_offset) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - mirror::ObjectArray<mirror::ArtField>* instance_fields = klass->GetIFields(); - if (instance_fields != NULL) { - for (int32_t i = 0, e = instance_fields->GetLength(); i < e; ++i) { - mirror::ArtField* field = instance_fields->Get(i); - if (field->GetOffset().Uint32Value() == field_offset) { - return field; - } - } - } - // We did not find field in class: look into superclass. - if (klass->GetSuperClass() != NULL) { - return FindInstanceFieldWithOffset(klass->GetSuperClass(), field_offset); - } else { - VLOG(verifier) << "Failed to find instance field at offset '" << field_offset - << "' from '" << PrettyDescriptor(klass) << "'"; - return nullptr; - } -} - mirror::ArtField* MethodVerifier::GetQuickFieldAccess(const Instruction* inst, RegisterLine* reg_line) { DCHECK(inst->Opcode() == Instruction::IGET_QUICK || @@ -3636,7 +3611,13 @@ mirror::ArtField* MethodVerifier::GetQuickFieldAccess(const Instruction* inst, return nullptr; } uint32_t field_offset = static_cast<uint32_t>(inst->VRegC_22c()); - return FindInstanceFieldWithOffset(object_type.GetClass(), field_offset); + mirror::ArtField* f = mirror::ArtField::FindInstanceFieldWithOffset(object_type.GetClass(), + field_offset); + if (f == nullptr) { + VLOG(verifier) << "Failed to find instance field at offset '" << field_offset + << "' from '" << PrettyDescriptor(object_type.GetClass()) << "'"; + } + return f; } void MethodVerifier::VerifyIGetQuick(const Instruction* inst, const RegType& insn_type, diff --git a/test/046-reflect/expected.txt b/test/046-reflect/expected.txt index 55b0dbe8f4..ecb3599482 100644 --- a/test/046-reflect/expected.txt +++ b/test/046-reflect/expected.txt @@ -92,6 +92,8 @@ SuperTarget constructor ()V Target constructor (IF)V : ii=7 ff=3.3333 myMethod (I)I arg=17 anInt=7 +got expected exception for Class.newInstance +got expected exception for Constructor.newInstance ReflectTest done! public method static java.lang.Object java.util.Collections.checkType(java.lang.Object,java.lang.Class) accessible=false diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java index d60fcb485b..3e6d7007f9 100644 --- a/test/046-reflect/src/Main.java +++ b/test/046-reflect/src/Main.java @@ -362,6 +362,27 @@ public class Main { targ = cons.newInstance(args); targ.myMethod(17); + try { + Thrower thrower = Thrower.class.newInstance(); + System.out.println("ERROR: Class.newInstance did not throw exception"); + } catch (UnsupportedOperationException uoe) { + System.out.println("got expected exception for Class.newInstance"); + } catch (Exception e) { + System.out.println("ERROR: Class.newInstance got unexpected exception: " + + e.getClass().getName()); + } + + try { + Constructor<Thrower> constructor = Thrower.class.getDeclaredConstructor(); + Thrower thrower = constructor.newInstance(); + System.out.println("ERROR: Constructor.newInstance did not throw exception"); + } catch (InvocationTargetException ite) { + System.out.println("got expected exception for Constructor.newInstance"); + } catch (Exception e) { + System.out.println("ERROR: Constructor.newInstance got unexpected exception: " + + e.getClass().getName()); + } + } catch (Exception ex) { System.out.println("----- unexpected exception -----"); ex.printStackTrace(); @@ -669,3 +690,9 @@ class MethodNoisyInitUser { public static void staticMethod() {} public void createMethodNoisyInit(MethodNoisyInit ni) {} } + +class Thrower { + public Thrower() throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } +} diff --git a/test/Android.mk b/test/Android.mk index 334df1f72a..08a925c7a4 100644 --- a/test/Android.mk +++ b/test/Android.mk @@ -57,6 +57,8 @@ TEST_OAT_DIRECTORIES := \ # StackWalk2 \ ART_TEST_TARGET_DEX_FILES := +ART_TEST_TARGET_DEX_FILES$(ART_PHONY_TEST_TARGET_SUFFIX) := +ART_TEST_TARGET_DEX_FILES$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) := ART_TEST_HOST_DEX_FILES := # $(1): module prefix @@ -76,13 +78,17 @@ define build-art-test-dex LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common.mk LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk include $(BUILD_JAVA_LIBRARY) + ART_TEST_TARGET_DEX_FILES += $$(LOCAL_INSTALLED_MODULE) + ART_TEST_TARGET_DEX_FILES$(ART_PHONY_TEST_TARGET_SUFFIX) += $$(LOCAL_INSTALLED_MODULE) ifdef TARGET_2ND_ARCH + ART_TEST_TARGET_DEX_FILES$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) += $(4)/$(1)-$(2).jar + # TODO: make this a simple copy -$(4)/$(1)-$(2).jar: $(3)/$(1)-$(2).jar +$(4)/$(1)-$(2).jar: $(3)/$(1)-$(2).jar $(4) cp $$< $(4)/ - endif + endif endif ifeq ($(ART_BUILD_HOST),true) @@ -102,9 +108,22 @@ endef $(foreach dir,$(TEST_DEX_DIRECTORIES), $(eval $(call build-art-test-dex,art-test-dex,$(dir),$(ART_NATIVETEST_OUT),$(2ND_ART_NATIVETEST_OUT)))) $(foreach dir,$(TEST_OAT_DIRECTORIES), $(eval $(call build-art-test-dex,oat-test-dex,$(dir),$(ART_TEST_OUT),$(2ND_ART_TEST_OUT)))) +# Rules to explicitly create 2nd-arch test directories, as we use a "cp" for them +# instead of BUILD_JAVA_LIBRARY +ifneq ($(2ND_ART_NATIVETEST_OUT),) +$(2ND_ART_NATIVETEST_OUT): + $(hide) mkdir -p $@ +endif + +ifneq ($(2ND_ART_TEST_OUT),) +$(2ND_ART_TEST_OUT): + $(hide) mkdir -p $@ +endif + ######################################################################## -ART_TEST_TARGET_OAT_TARGETS := +ART_TEST_TARGET_OAT_TARGETS$(ART_PHONY_TEST_TARGET_SUFFIX) := +ART_TEST_TARGET_OAT_TARGETS$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) := ART_TEST_HOST_OAT_DEFAULT_TARGETS := ART_TEST_HOST_OAT_INTERPRETER_TARGETS := @@ -160,7 +179,10 @@ test-art-host-oat-$(1): test-art-host-oat-default-$(1) test-art-host-oat-interpr .PHONY: test-art-oat-$(1) test-art-oat-$(1): test-art-host-oat-$(1) test-art-target-oat-$(1) -ART_TEST_TARGET_OAT_TARGETS += test-art-target-oat-$(1) +ART_TEST_TARGET_OAT_TARGETS$(ART_PHONY_TEST_TARGET_SUFFIX) += test-art-target-oat-$(1)$(ART_PHONY_TEST_TARGET_SUFFIX) +ifdef TARGET_2ND_ARCH + ART_TEST_TARGET_OAT_TARGETS$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) += test-art-target-oat-$(1)$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) +endif ART_TEST_HOST_OAT_DEFAULT_TARGETS += test-art-host-oat-default-$(1) ART_TEST_HOST_OAT_INTERPRETER_TARGETS += test-art-host-oat-interpreter-$(1) endef diff --git a/test/run-test b/test/run-test index 58de9809df..6e59641eba 100755 --- a/test/run-test +++ b/test/run-test @@ -68,6 +68,7 @@ debug_mode="no" runtime="art" usage="no" build_only="no" +suffix64="" while true; do if [ "x$1" = "x--host" ]; then @@ -154,6 +155,7 @@ while true; do shift elif [ "x$1" = "x--64" ]; then run_args="${run_args} --64" + suffix64="64" shift elif expr "x$1" : "x--" >/dev/null 2>&1; then echo "unknown $0 option: $1" 1>&2 @@ -187,7 +189,7 @@ elif [ "$runtime" = "art" ]; then fi run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art" else - run_args="${run_args} --boot -Ximage:/data/art-test/core.art" + run_args="${run_args} --boot -Ximage:/data/art-test${suffix64}/core.art" fi fi |