Merge "Treat larger than jint capacity in NewDirectByteBuffer as an error"
diff --git a/Android.mk b/Android.mk
index 18e1c64..7d31382 100644
--- a/Android.mk
+++ b/Android.mk
@@ -105,9 +105,13 @@
 
 
 # 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 := \
+	$(ART_HOST_EXECUTABLES) \
+	$(HOST_OUT_JAVA_LIBRARIES)/core-libart-hostdex.jar \
 	$(HOST_LIBRARY_PATH)/libjavacore$(ART_HOST_SHLIB_EXTENSION)
-ART_TARGET_DEPENDENCIES := $(ART_TARGET_EXECUTABLES) $(TARGET_OUT_JAVA_LIBRARIES)/core-libart.jar \
+ART_TARGET_DEPENDENCIES := \
+	$(ART_TARGET_EXECUTABLES) \
+	$(TARGET_OUT_JAVA_LIBRARIES)/core-libart.jar \
 	$(TARGET_OUT_SHARED_LIBRARIES)/libjavacore.so
 ifdef TARGET_2ND_ARCH
 ART_TARGET_DEPENDENCIES += $(2ND_TARGET_OUT_SHARED_LIBRARIES)/libjavacore.so
diff --git a/build/Android.common_path.mk b/build/Android.common_path.mk
index d672393..8c0d9f2 100644
--- a/build/Android.common_path.mk
+++ b/build/Android.common_path.mk
@@ -72,5 +72,4 @@
 
 HOST_CORE_DEX_FILES   := $(foreach jar,$(HOST_CORE_JARS),  $(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),t,COMMON)/javalib.jar)
 TARGET_CORE_DEX_FILES := $(foreach jar,$(TARGET_CORE_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar), ,COMMON)/javalib.jar)
-
 endif # ANDROID_COMMON_PATH_MK
diff --git a/build/Android.common_test.mk b/build/Android.common_test.mk
index 1815f50..21a8931 100644
--- a/build/Android.common_test.mk
+++ b/build/Android.common_test.mk
@@ -99,6 +99,7 @@
     LOCAL_MODULE_PATH := $(3)
     LOCAL_DEX_PREOPT_IMAGE_LOCATION := $(TARGET_CORE_IMG_OUT)
     include $(BUILD_JAVA_LIBRARY)
+    $(5) := $$(LOCAL_INSTALLED_MODULE)
   endif
   ifeq ($(ART_BUILD_HOST),true)
     include $(CLEAR_VARS)
@@ -110,8 +111,8 @@
     LOCAL_JAVA_LIBRARIES := $(HOST_CORE_JARS)
     LOCAL_DEX_PREOPT_IMAGE := $(HOST_CORE_IMG_LOCATION)
     include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
+    $(5)-host := $$(LOCAL_INSTALLED_MODULE)
   endif
-  $(5) := $$(LOCAL_INSTALLED_MODULE)
 endef
 
 endif # ANDROID_COMMON_TEST_MK
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index a6f6298..69d6c5a 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -45,20 +45,17 @@
   $(ART_TARGET_NATIVETEST_OUT),art/build/Android.gtest.mk,ART_GTEST_$(dir)_DEX)))
 
 # Dex file dependencies for each gtest.
-ART_GTEST_class_linker_test_DEPS := $(ART_GTEST_Interfaces_DEX) $(ART_GTEST_MyClass_DEX) \
-  $(ART_GTEST_Nested_DEX) $(ART_GTEST_Statics_DEX) $(ART_GTEST_StaticsFromCode_DEX)
-ART_GTEST_compiler_driver_test_DEPS := $(ART_GTEST_AbstractMethod_DEX)
-ART_GTEST_dex_file_test_DEPS := $(ART_GTEST_GetMethodSignature_DEX)
-ART_GTEST_exception_test_DEPS := $(ART_GTEST_ExceptionHandle_DEX)
-ART_GTEST_jni_compiler_test_DEPS := $(ART_GTEST_MyClassNatives_DEX)
-ART_GTEST_jni_internal_test_DEPS := $(ART_GTEST_AllFields_DEX)
-ART_GTEST_object_test_DEPS := $(ART_GTEST_ProtoCompare_DEX) $(ART_GTEST_ProtoCompare2_DEX) \
-   $(ART_GTEST_StaticsFromCode_DEX) $(ART_GTEST_XandY_DEX)
-ART_GTEST_proxy_test_DEPS := $(ART_GTEST_Interfaces_DEX)
-ART_GTEST_reflection_test_DEPS := $(ART_GTEST_Main_DEX) $(ART_GTEST_NonStaticLeafMethods_DEX) \
-  $(ART_GTEST_StaticLeafMethods_DEX)
-ART_GTEST_stub_test_DEPS := $(ART_GTEST_AllFields_DEX)
-ART_GTEST_transaction_test_DEPS := $(ART_GTEST_Transaction_DEX)
+ART_GTEST_class_linker_test_DEPS := Interfaces MyClass Nested Statics StaticsFromCode
+ART_GTEST_compiler_driver_test_DEPS := AbstractMethod
+ART_GTEST_dex_file_test_DEPS := GetMethodSignature
+ART_GTEST_exception_test_DEPS := ExceptionHandle
+ART_GTEST_jni_compiler_test_DEPS := MyClassNatives
+ART_GTEST_jni_internal_test_DEPS := AllFields StaticLeafMethods
+ART_GTEST_object_test_DEPS := ProtoCompare ProtoCompare2 StaticsFromCode XandY
+ART_GTEST_proxy_test_DEPS := Interfaces
+ART_GTEST_reflection_test_DEPS := Main NonStaticLeafMethods StaticLeafMethods
+ART_GTEST_stub_test_DEPS := AllFields
+ART_GTEST_transaction_test_DEPS := Transaction
 
 # The elf writer test has dependencies on core.oat.
 ART_GTEST_elf_writer_test_DEPS := $(HOST_CORE_OAT_OUT) $(2ND_HOST_CORE_OAT_OUT) \
@@ -194,12 +191,11 @@
 define define-art-gtest-rule-target
   gtest_rule := test-art-target-gtest-$(1)$$($(2)ART_PHONY_TEST_TARGET_SUFFIX)
 
-  # Add the test dependencies to test-art-target-sync, which will be a prerequisit for the test
+  # Add the test dependencies to test-art-target-sync, which will be a prerequisite for the test
   # to ensure files are pushed to the device.
   TEST_ART_TARGET_SYNC_DEPS += \
-    $$(ART_GTEST_$(1)_DEPS) \
+    $(foreach file,$(ART_GTEST_$(1)_DEPS),$(ART_GTEST_$(file)_DEX)) \
     $$(ART_TARGET_NATIVETEST_OUT)/$$(TARGET_$(2)ARCH)/$(1) \
-    $$(TARGET_CORE_DEX_LOCATIONS) \
     $$($(2)TARGET_OUT_SHARED_LIBRARIES)/libjavacore.so
 
 .PHONY: $$(gtest_rule)
@@ -234,7 +230,7 @@
 
 
 .PHONY: $$(gtest_rule)
-$$(gtest_rule): $$(gtest_exe) $$(ART_GTEST_$(1)_DEPS) $$(gtest_deps)
+$$(gtest_rule): $$(gtest_exe) $(foreach file,$(ART_GTEST_$(1)_DEPS),$(ART_GTEST_$(file)_DEX-host)) $$(gtest_deps)
 	$(hide) ($$(call ART_TEST_SKIP,$$@) && $$< && $$(call ART_TEST_PASSED,$$@)) \
 	  || $$(call ART_TEST_FAILED,$$@)
 
@@ -461,4 +457,4 @@
 ART_GTEST_transaction_test_DEPS :=
 $(foreach dir,$(GTEST_DEX_DIRECTORIES), $(eval ART_GTEST_TEST_$(dir)_DEX :=))
 GTEST_DEX_DIRECTORIES :=
-LOCAL_PATH :=
\ No newline at end of file
+LOCAL_PATH :=
diff --git a/compiler/optimizing/register_allocator_test.cc b/compiler/optimizing/register_allocator_test.cc
index bfabc5a..a7283ab 100644
--- a/compiler/optimizing/register_allocator_test.cc
+++ b/compiler/optimizing/register_allocator_test.cc
@@ -318,4 +318,42 @@
   ASSERT_EQ(phi_interval->GetRegister(), ret->InputAt(0)->GetLiveInterval()->GetRegister());
 }
 
+TEST(RegisterAllocatorTest, FirstRegisterUse) {
+  const uint16_t data[] = THREE_REGISTERS_CODE_ITEM(
+    Instruction::CONST_4 | 0 | 0,
+    Instruction::ADD_INT_LIT8 | 1 << 8, 1 << 8,
+    Instruction::ADD_INT_LIT8 | 0 << 8, 1 << 8,
+    Instruction::ADD_INT_LIT8 | 1 << 8, 1 << 8 | 1,
+    Instruction::RETURN_VOID);
+
+  ArenaPool pool;
+  ArenaAllocator allocator(&pool);
+  HGraph* graph = BuildSSAGraph(data, &allocator);
+  CodeGenerator* codegen = CodeGenerator::Create(&allocator, graph, kArm);
+  SsaLivenessAnalysis liveness(*graph, codegen);
+  liveness.Analyze();
+
+  HAdd* first_add = graph->GetBlocks().Get(1)->GetFirstInstruction()->AsAdd();
+  HAdd* last_add = graph->GetBlocks().Get(1)->GetLastInstruction()->GetPrevious()->AsAdd();
+  ASSERT_EQ(last_add->InputAt(0), first_add);
+  LiveInterval* interval = first_add->GetLiveInterval();
+  ASSERT_EQ(interval->GetEnd(), last_add->GetLifetimePosition() + 1);
+  ASSERT_TRUE(interval->GetNextSibling() == nullptr);
+
+  // We need a register for the output of the instruction.
+  ASSERT_EQ(interval->FirstRegisterUse(), first_add->GetLifetimePosition());
+
+  // Split at the next instruction.
+  interval = interval->SplitAt(first_add->GetLifetimePosition() + 2);
+  // The user of the split is the last add.
+  ASSERT_EQ(interval->FirstRegisterUse(), last_add->GetLifetimePosition() + 1);
+
+  // Split before the last add.
+  LiveInterval* new_interval = interval->SplitAt(last_add->GetLifetimePosition() - 1);
+  // Ensure the current interval has no register use...
+  ASSERT_EQ(interval->FirstRegisterUse(), kNoLifetime);
+  // And the new interval has it for the last add.
+  ASSERT_EQ(new_interval->FirstRegisterUse(), last_add->GetLifetimePosition() + 1);
+}
+
 }  // namespace art
diff --git a/compiler/optimizing/ssa_liveness_analysis.h b/compiler/optimizing/ssa_liveness_analysis.h
index fc3eb66..83035b5 100644
--- a/compiler/optimizing/ssa_liveness_analysis.h
+++ b/compiler/optimizing/ssa_liveness_analysis.h
@@ -289,21 +289,23 @@
 
   size_t FirstRegisterUseAfter(size_t position) const {
     if (position == GetStart() && defined_by_ != nullptr) {
-      Location location = defined_by_->GetLocations()->Out();
+      LocationSummary* locations = defined_by_->GetLocations();
+      Location location = locations->Out();
       // This interval is the first interval of the instruction. If the output
       // of the instruction requires a register, we return the position of that instruction
       // as the first register use.
       if (location.IsUnallocated()) {
         if ((location.GetPolicy() == Location::kRequiresRegister)
              || (location.GetPolicy() == Location::kSameAsFirstInput
-                && defined_by_->GetLocations()->InAt(0).GetPolicy() == Location::kRequiresRegister)) {
+                 && locations->InAt(0).GetPolicy() == Location::kRequiresRegister)) {
           return position;
         }
       }
     }
 
     UsePosition* use = first_use_;
-    while (use != nullptr) {
+    size_t end = GetEnd();
+    while (use != nullptr && use->GetPosition() <= end) {
       size_t use_position = use->GetPosition();
       if (use_position >= position && !use->GetIsEnvironment()) {
         Location location = use->GetUser()->GetLocations()->InAt(use->GetInputIndex());
diff --git a/test/Android.oat.mk b/test/Android.oat.mk
index 97f8cd5..3cf9f61 100644
--- a/test/Android.oat.mk
+++ b/test/Android.oat.mk
@@ -60,7 +60,10 @@
 ART_TEST_TARGET_OAT_RULES :=
 
 # We need dex2oat and dalvikvm on the target as well as the core image.
-TEST_ART_TARGET_SYNC_DEPS += $(ART_TARGET_EXECUTABLES) $(TARGET_CORE_IMG_OUT) $(2ND_TARGET_CORE_IMG_OUT)
+TEST_ART_TARGET_SYNC_DEPS += $(ART_TARGET_EXECUTABLES) $(TARGET_CORE_IMG_OUT) $(2ND_TARGET_CORE_IMG_OUT) $(ART_TARGET_TEST_OUT)/$(TARGET_ARCH)/libarttest.so
+ifdef TARGET_2ND_ARCH
+TEST_ART_TARGET_SYNC_DEPS += $(ART_TARGET_TEST_OUT)/$(TARGET_2ND_ARCH)/libarttest.so
+endif
 
 # Define rule to run an individual oat test on the host. Output from the test is written to the
 # host in /tmp/android-data in a directory named after test's rule name (its target) and the parent
@@ -72,7 +75,7 @@
 # $(3): the target (rule name), e.g. test-art-target-oat-default-HelloWorld64
 # $(4): -Xint or undefined - do we want to run with the interpreter or default.
 define define-test-art-oat-rule-target
-  # Add the test dependencies to test-art-target-sync, which will be a prerequisit for the test
+  # Add the test dependencies to test-art-target-sync, which will be a prerequisite for the test
   # to ensure files are pushed to the device.
   TEST_ART_TARGET_SYNC_DEPS += $$(ART_OAT_TEST_$(1)_DEX)