Merge "Keep the symbol table in the shared libraries."
diff --git a/Android.mk b/Android.mk
index ac19a56..5325abd 100644
--- a/Android.mk
+++ b/Android.mk
@@ -284,9 +284,9 @@
 .PHONY: oat-target-$(1)
 oat-target-$(1): $$(OUT_OAT_FILE)
 
-$$(OUT_OAT_FILE): $(PRODUCT_OUT)/$(1) $(DEFAULT_DEX_PREOPT_BUILT_IMAGE) $(DEX2OAT_DEPENDENCY)
+$$(OUT_OAT_FILE): $(PRODUCT_OUT)/$(1) $(DEFAULT_DEX_PREOPT_BUILT_IMAGE) $(DEX2OATD_DEPENDENCY)
 	@mkdir -p $$(dir $$@)
-	$(DEX2OAT) --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=$(TARGET_ARCH) --instruction-set-features=$(TARGET_INSTRUCTION_SET_FEATURES) --android-root=$(PRODUCT_OUT)/system
 
 endif
 
diff --git a/build/Android.executable.mk b/build/Android.executable.mk
index 88ca47e..27d687c 100644
--- a/build/Android.executable.mk
+++ b/build/Android.executable.mk
@@ -30,6 +30,7 @@
 # $(4): extra include directories
 # $(5): target or host
 # $(6): ndebug or debug
+# $(7): value for LOCAL_MULTILIB (empty means default)
 define build-art-executable
   ifneq ($(5),target)
     ifneq ($(5),host)
@@ -48,6 +49,7 @@
   art_c_includes := $(4)
   art_target_or_host := $(5)
   art_ndebug_or_debug := $(6)
+  art_multilib := $(7)
 
   include $(CLEAR_VARS)
   ifeq ($$(art_target_or_host),target)
@@ -98,6 +100,7 @@
 
   ifeq ($$(art_target_or_host),target)
     LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
+    LOCAL_MULTILIB := $$(art_multilib)
   endif
 
   ifeq ($$(art_target_or_host),target)
diff --git a/build/Android.oat.mk b/build/Android.oat.mk
index 51beedc..cb45a85 100644
--- a/build/Android.oat.mk
+++ b/build/Android.oat.mk
@@ -43,10 +43,11 @@
 
 TARGET_INSTRUCTION_SET_FEATURES := $(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
 
-$(HOST_CORE_IMG_OUT): $(HOST_CORE_DEX_FILES) $(DEX2OAT_DEPENDENCY)
+# Use dex2oat debug version for better error reporting
+$(HOST_CORE_IMG_OUT): $(HOST_CORE_DEX_FILES) $(DEX2OATD_DEPENDENCY)
 	@echo "host dex2oat: $@ ($?)"
 	@mkdir -p $(dir $@)
-	$(hide) $(DEX2OAT) --runtime-arg -Xms16m --runtime-arg -Xmx16m --image-classes=$(PRELOADED_CLASSES) $(addprefix \
+	$(hide) $(DEX2OATD) --runtime-arg -Xms16m --runtime-arg -Xmx16m --image-classes=$(PRELOADED_CLASSES) $(addprefix \
 		--dex-file=,$(HOST_CORE_DEX_FILES)) $(addprefix --dex-location=,$(HOST_CORE_DEX_LOCATIONS)) --oat-file=$(HOST_CORE_OAT_OUT) \
 		--oat-location=$(HOST_CORE_OAT) --image=$(HOST_CORE_IMG_OUT) --base=$(LIBART_IMG_HOST_BASE_ADDRESS) \
 		--instruction-set=$(ART_HOST_ARCH) --host --android-root=$(HOST_OUT)
@@ -54,10 +55,10 @@
 $(HOST_CORE_OAT_OUT): $(HOST_CORE_IMG_OUT)
 
 define create-oat-target-targets
-$$($(1)TARGET_CORE_IMG_OUT): $$($(1)TARGET_CORE_DEX_FILES) $$(DEX2OAT_DEPENDENCY)
+$$($(1)TARGET_CORE_IMG_OUT): $$($(1)TARGET_CORE_DEX_FILES) $$(DEX2OATD_DEPENDENCY)
 	@echo "target dex2oat: $$@ ($$?)"
 	@mkdir -p $$(dir $$@)
-	$$(hide) $$(DEX2OAT) --runtime-arg -Xms16m --runtime-arg -Xmx16m --image-classes=$$(PRELOADED_CLASSES) $$(addprefix \
+	$$(hide) $$(DEX2OATD) --runtime-arg -Xms16m --runtime-arg -Xmx16m --image-classes=$$(PRELOADED_CLASSES) $$(addprefix \
 		--dex-file=,$$(TARGET_CORE_DEX_FILES)) $$(addprefix --dex-location=,$$(TARGET_CORE_DEX_LOCATIONS)) --oat-file=$$($(1)TARGET_CORE_OAT_OUT) \
 		--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
diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h
index 6aa85d4..9a21da0 100644
--- a/compiler/common_compiler_test.h
+++ b/compiler/common_compiler_test.h
@@ -291,7 +291,7 @@
 
       // Take the default set of instruction features from the build.
       InstructionSetFeatures instruction_set_features =
-          ParseFeatureList(STRINGIFY(ART_DEFAULT_INSTRUCTION_SET_FEATURES));
+          ParseFeatureList(Runtime::GetDefaultInstructionSetFeatures());
 
 #if defined(__arm__)
       instruction_set = kThumb2;
diff --git a/compiler/dex/quick/arm/target_arm.cc b/compiler/dex/quick/arm/target_arm.cc
index 5ebe0a3..5e9a8b0 100644
--- a/compiler/dex/quick/arm/target_arm.cc
+++ b/compiler/dex/quick/arm/target_arm.cc
@@ -559,10 +559,13 @@
       (arena_->Alloc(num_fp_regs * sizeof(*reg_pool_->FPRegs), kArenaAllocRegAlloc));
   CompilerInitPool(reg_pool_->core_regs, core_regs, reg_pool_->num_core_regs);
   CompilerInitPool(reg_pool_->FPRegs, FpRegs, reg_pool_->num_fp_regs);
+
   // Keep special registers from being allocated
+  // Don't reserve the r4 if we are doing implicit suspend checks.
+  bool no_suspend = NO_SUSPEND || !Runtime::Current()->ExplicitSuspendChecks();
   for (int i = 0; i < num_reserved; i++) {
-    if (NO_SUSPEND && (ReservedRegs[i] == rARM_SUSPEND)) {
-      // To measure cost of suspend check
+    if (no_suspend && (ReservedRegs[i] == rARM_SUSPEND)) {
+      // Don't reserve the suspend register.
       continue;
     }
     MarkInUse(ReservedRegs[i]);
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index c367260..c10dd84 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -2052,7 +2052,7 @@
   // This is the number of hits in all methods.
   uint32_t total_count = 0;
   for (int i = 0 ; i < 3; ++i) {
-    total_count += atoi(summary_info[0].c_str());
+    total_count += atoi(summary_info[i].c_str());
   }
 
   // Now read each line until the end of file.  Each line consists of 3 fields separated by /
diff --git a/compiler/jni/jni_compiler_test.cc b/compiler/jni/jni_compiler_test.cc
index 31acb69..3204282 100644
--- a/compiler/jni/jni_compiler_test.cc
+++ b/compiler/jni/jni_compiler_test.cc
@@ -590,7 +590,7 @@
     ScopedObjectAccess soa(env);
 
     // Build stack trace
-    jobject internal = Thread::Current()->CreateInternalStackTrace(soa);
+    jobject internal = Thread::Current()->CreateInternalStackTrace<false>(soa);
     jobjectArray ste_array = Thread::InternalStackTraceToStackTraceElementArray(soa, internal);
     mirror::ObjectArray<mirror::StackTraceElement>* trace_array =
         soa.Decode<mirror::ObjectArray<mirror::StackTraceElement>*>(ste_array);
diff --git a/dex2oat/Android.mk b/dex2oat/Android.mk
index 6cd0538..038f0a7 100644
--- a/dex2oat/Android.mk
+++ b/dex2oat/Android.mk
@@ -22,10 +22,10 @@
 	dex2oat.cc
 
 ifeq ($(ART_BUILD_TARGET_NDEBUG),true)
-  $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libart-compiler,art/compiler,target,ndebug))
+  $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libart-compiler,art/compiler,target,ndebug,32))
 endif
 ifeq ($(ART_BUILD_TARGET_DEBUG),true)
-  $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libartd-compiler,art/compiler,target,debug))
+  $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libartd-compiler,art/compiler,target,debug,32))
 endif
 
 ifeq ($(WITH_HOST_DALVIK),true)
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 72effde..552ec89 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -740,7 +740,7 @@
 
   // Take the default set of instruction features from the build.
   InstructionSetFeatures instruction_set_features =
-      ParseFeatureList(STRINGIFY(ART_DEFAULT_INSTRUCTION_SET_FEATURES));
+      ParseFeatureList(Runtime::GetDefaultInstructionSetFeatures());
 
 #if defined(__arm__)
   InstructionSet instruction_set = kThumb2;
diff --git a/runtime/Android.mk b/runtime/Android.mk
index c8d294a..cf7f895 100644
--- a/runtime/Android.mk
+++ b/runtime/Android.mk
@@ -73,6 +73,7 @@
 	hprof/hprof.cc \
 	image.cc \
 	indirect_reference_table.cc \
+	instruction_set.cc \
 	instrumentation.cc \
 	intern_table.cc \
 	interpreter/interpreter.cc \
@@ -103,7 +104,7 @@
 	native/dalvik_system_VMDebug.cc \
 	native/dalvik_system_VMRuntime.cc \
 	native/dalvik_system_VMStack.cc \
-	native/dalvik_system_Zygote.cc \
+	native/dalvik_system_ZygoteHooks.cc \
 	native/java_lang_Class.cc \
 	native/java_lang_DexCache.cc \
 	native/java_lang_Object.cc \
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 3957493..19cc23c 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -567,40 +567,12 @@
   argv.push_back("--runtime-arg");
   argv.push_back(Runtime::Current()->GetClassPathString());
 
-  argv.push_back("--runtime-arg");
-  std::string checkstr = "-implicit-checks";
-
-  int nchecks = 0;
-  char checksep = ':';
-
-  if (!Runtime::Current()->ExplicitNullChecks()) {
-    checkstr += checksep;
-    checksep = ',';
-    checkstr += "null";
-    ++nchecks;
-  }
-  if (!Runtime::Current()->ExplicitSuspendChecks()) {
-    checkstr += checksep;
-    checksep = ',';
-    checkstr += "suspend";
-    ++nchecks;
-  }
-
-  if (!Runtime::Current()->ExplicitStackOverflowChecks()) {
-    checkstr += checksep;
-    checksep = ',';
-    checkstr += "stack";
-    ++nchecks;
-  }
-
-  if (nchecks == 0) {
-    checkstr += ":none";
-  }
-  argv.push_back(checkstr);
+  Runtime::Current()->AddCurrentRuntimeFeaturesAsDex2OatArguments(&argv);
 
   if (!kIsTargetBuild) {
     argv.push_back("--host");
   }
+
   argv.push_back(boot_image_option);
   argv.push_back(dex_file_option);
   argv.push_back(oat_fd_option);
diff --git a/runtime/exception_test.cc b/runtime/exception_test.cc
index 9c76a14..208eb74 100644
--- a/runtime/exception_test.cc
+++ b/runtime/exception_test.cc
@@ -199,7 +199,7 @@
     thread->PushShadowFrame(reinterpret_cast<ShadowFrame*>(&fake_stack[0]));
   }
 
-  jobject internal = thread->CreateInternalStackTrace(soa);
+  jobject internal = thread->CreateInternalStackTrace<false>(soa);
   ASSERT_TRUE(internal != NULL);
   jobjectArray ste_array = Thread::InternalStackTraceToStackTraceElementArray(soa, internal);
   ASSERT_TRUE(ste_array != NULL);
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 9a2815a..faa539f 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -67,36 +67,6 @@
   arg_vector.push_back("--runtime-arg");
   arg_vector.push_back("-Xmx64m");
 
-  arg_vector.push_back("--runtime-arg");
-  std::string checkstr = "-implicit-checks";
-  int nchecks = 0;
-  char checksep = ':';
-
-  if (!Runtime::Current()->ExplicitNullChecks()) {
-    checkstr += checksep;
-    checksep = ',';
-    checkstr += "null";
-    ++nchecks;
-  }
-  if (!Runtime::Current()->ExplicitSuspendChecks()) {
-    checkstr += checksep;
-    checksep = ',';
-    checkstr += "suspend";
-    ++nchecks;
-  }
-
-  if (!Runtime::Current()->ExplicitStackOverflowChecks()) {
-    checkstr += checksep;
-    checksep = ',';
-    checkstr += "stack";
-    ++nchecks;
-  }
-
-  if (nchecks == 0) {
-    checkstr += ":none";
-  }
-
-  arg_vector.push_back(checkstr);
 
   for (size_t i = 0; i < boot_class_path.size(); i++) {
     arg_vector.push_back(std::string("--dex-file=") + boot_class_path[i]);
@@ -108,6 +78,8 @@
   oat_file_option_string += "oat";
   arg_vector.push_back(oat_file_option_string);
 
+  Runtime::Current()->AddCurrentRuntimeFeaturesAsDex2OatArguments(&arg_vector);
+
   arg_vector.push_back(StringPrintf("--base=0x%x", ART_BASE_ADDRESS));
 
   if (kIsTargetBuild) {
diff --git a/runtime/instruction_set.cc b/runtime/instruction_set.cc
new file mode 100644
index 0000000..c964629
--- /dev/null
+++ b/runtime/instruction_set.cc
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "instruction_set.h"
+
+namespace art {
+
+std::string InstructionSetFeatures::GetFeatureString() const {
+  std::string result;
+  if ((mask_ & kHwDiv) != 0) {
+    result += "div";
+  }
+  if (result.size() == 0) {
+    result = "none";
+  }
+  return result;
+}
+
+}  // namespace art
diff --git a/runtime/instruction_set.h b/runtime/instruction_set.h
index cbc9912..c5a4ec8 100644
--- a/runtime/instruction_set.h
+++ b/runtime/instruction_set.h
@@ -33,6 +33,7 @@
   kX86_64,
   kMips
 };
+std::ostream& operator<<(std::ostream& os, const InstructionSet& rhs);
 
 enum InstructionFeatures {
   kHwDiv = 1                  // Supports hardware divide.
@@ -44,6 +45,8 @@
   InstructionSetFeatures() : mask_(0) {}
   explicit InstructionSetFeatures(uint32_t mask) : mask_(mask) {}
 
+  static InstructionSetFeatures GuessInstructionSetFeatures();
+
   bool HasDivideInstruction() const {
       return (mask_ & kHwDiv) != 0;
   }
@@ -52,20 +55,7 @@
     mask_ = (mask_ & ~kHwDiv) | (v ? kHwDiv : 0);
   }
 
-  std::string GetFeatureString() const {
-    std::string result;
-    if ((mask_ & kHwDiv) != 0) {
-      result += "div";
-    }
-    if (result.size() == 0) {
-      result = "none";
-    }
-    return result;
-  }
-
-  uint32_t get_mask() const {
-    return mask_;
-  }
+  std::string GetFeatureString() const;
 
   // Other features in here.
 
@@ -81,8 +71,6 @@
   uint32_t mask_;
 };
 
-std::ostream& operator<<(std::ostream& os, const InstructionSet& rhs);
-
 }  // namespace art
 
 #endif  // ART_RUNTIME_INSTRUCTION_SET_H_
diff --git a/runtime/interpreter/interpreter.cc b/runtime/interpreter/interpreter.cc
index abe7fe1..1bf0078 100644
--- a/runtime/interpreter/interpreter.cc
+++ b/runtime/interpreter/interpreter.cc
@@ -68,7 +68,7 @@
     result->SetL(Array::CreateMultiArray(self, sirt_class, sirt_dimensions));
   } else if (name == "java.lang.Object java.lang.Throwable.nativeFillInStackTrace()") {
     ScopedObjectAccessUnchecked soa(self);
-    result->SetL(soa.Decode<Object*>(self->CreateInternalStackTrace(soa)));
+    result->SetL(soa.Decode<Object*>(self->CreateInternalStackTrace<true>(soa)));
   } else if (name == "int java.lang.System.identityHashCode(java.lang.Object)") {
     mirror::Object* obj = reinterpret_cast<Object*>(args[0]);
     result->SetI((obj != nullptr) ? obj->IdentityHashCode() : 0);
@@ -96,7 +96,7 @@
     result->SetI(Primitive::ComponentSize(primitive_type));
   } else {
     // Throw an exception so we can abort the transaction and undo every change.
-    ThrowLocation throw_location;
+    ThrowLocation throw_location = self->GetCurrentLocationForThrow();
     self->ThrowNewExceptionF(throw_location, "Ljava/lang/InternalError;",
                              "Attempt to invoke native method in non-started runtime: %s",
                              name.c_str());
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index ddc07ff..d955b97 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -391,11 +391,8 @@
   void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     DCHECK(GetComponentType() == NULL);
     DCHECK(new_component_type != NULL);
-    if (Runtime::Current()->IsActiveTransaction()) {
-      SetFieldObject<true>(ComponentTypeOffset(), new_component_type, false);
-    } else {
-      SetFieldObject<false>(ComponentTypeOffset(), new_component_type, false);
-    }
+    // Component type is invariant: use non-transactional mode without check.
+    SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type, false);
   }
 
   size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc
index 7d8da14..32f30c3 100644
--- a/runtime/mirror/object_test.cc
+++ b/runtime/mirror/object_test.cc
@@ -425,8 +425,8 @@
   EXPECT_EQ(string->GetLength(), 7);
   EXPECT_EQ(string->GetUtfLength(), 7);
 
-  string->SetOffset<false>(2);
-  string->SetCount<false>(5);
+  string->SetOffset(2);
+  string->SetCount(5);
   EXPECT_TRUE(string->Equals("droid"));
   EXPECT_EQ(string->GetLength(), 5);
   EXPECT_EQ(string->GetUtfLength(), 5);
diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc
index d4f11b2..88a8e6f 100644
--- a/runtime/mirror/string.cc
+++ b/runtime/mirror/string.cc
@@ -59,10 +59,11 @@
   return -1;
 }
 
-template<bool kTransactionActive>
 void String::SetArray(CharArray* new_array) {
+  // Array is invariant so use non-transactional mode. Also disable check as we may run inside
+  // a transaction.
   DCHECK(new_array != NULL);
-  SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(String, array_), new_array, false);
+  SetFieldObject<false, false>(OFFSET_OF_OBJECT_MEMBER(String, array_), new_array, false);
 }
 
 // TODO: get global references for these
@@ -168,13 +169,8 @@
   // Hold reference in case AllocObject causes GC.
   String* string = down_cast<String*>(GetJavaLangString()->AllocObject(self));
   if (LIKELY(string != nullptr)) {
-    if (Runtime::Current()->IsActiveTransaction()) {
-      string->SetArray<true>(array.get());
-      string->SetCount<true>(array->GetLength());
-    } else {
-      string->SetArray<false>(array.get());
-      string->SetCount<false>(array->GetLength());
-    }
+    string->SetArray(array.get());
+    string->SetCount(array->GetLength());
   }
   return string;
 }
diff --git a/runtime/mirror/string.h b/runtime/mirror/string.h
index 1340e7d..de9e4c4 100644
--- a/runtime/mirror/string.h
+++ b/runtime/mirror/string.h
@@ -118,17 +118,18 @@
     SetField32<false, false>(OFFSET_OF_OBJECT_MEMBER(String, hash_code_), new_hash_code, false);
   }
 
-  template<bool kTransactionActive>
   void SetCount(int32_t new_count) {
+    // Count is invariant so use non-transactional mode. Also disable check as we may run inside
+    // a transaction.
     DCHECK_LE(0, new_count);
-    SetField32<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(String, count_), new_count, false);
+    SetField32<false, false>(OFFSET_OF_OBJECT_MEMBER(String, count_), new_count, false);
   }
 
-  template<bool kTransactionActive>
   void SetOffset(int32_t new_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+    // Offset is only used during testing so use non-transactional mode.
     DCHECK_LE(0, new_offset);
     DCHECK_GE(GetLength(), new_offset);
-    SetField32<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(String, offset_), new_offset, false);
+    SetField32<false>(OFFSET_OF_OBJECT_MEMBER(String, offset_), new_offset, false);
   }
 
   static String* Alloc(Thread* self, int32_t utf16_length)
@@ -137,7 +138,6 @@
   static String* Alloc(Thread* self, const SirtRef<CharArray>& array)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
-  template<bool kTransactionActive>
   void SetArray(CharArray* new_array) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
diff --git a/runtime/native/dalvik_system_VMStack.cc b/runtime/native/dalvik_system_VMStack.cc
index 9975bf7..cf31064 100644
--- a/runtime/native/dalvik_system_VMStack.cc
+++ b/runtime/native/dalvik_system_VMStack.cc
@@ -30,7 +30,7 @@
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   jobject trace = nullptr;
   if (soa.Decode<mirror::Object*>(peer) == soa.Self()->GetPeer()) {
-    trace = soa.Self()->CreateInternalStackTrace(soa);
+    trace = soa.Self()->CreateInternalStackTrace<false>(soa);
   } else {
     // Suspend thread to build stack trace.
     soa.Self()->TransitionFromRunnableToSuspended(kNative);
@@ -39,7 +39,7 @@
     if (thread != nullptr) {
       // Must be runnable to create returned array.
       CHECK_EQ(soa.Self()->TransitionFromSuspendedToRunnable(), kNative);
-      trace = thread->CreateInternalStackTrace(soa);
+      trace = thread->CreateInternalStackTrace<false>(soa);
       soa.Self()->TransitionFromRunnableToSuspended(kNative);
       // Restart suspended thread.
       Runtime::Current()->GetThreadList()->Resume(thread, false);
diff --git a/runtime/native/dalvik_system_Zygote.cc b/runtime/native/dalvik_system_Zygote.cc
deleted file mode 100644
index 0307207..0000000
--- a/runtime/native/dalvik_system_Zygote.cc
+++ /dev/null
@@ -1,606 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// sys/mount.h has to come before linux/fs.h due to redefinition of MS_RDONLY, MS_BIND, etc
-#include <sys/mount.h>
-#include <linux/fs.h>
-
-#include <grp.h>
-#include <paths.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <sys/resource.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "cutils/fs.h"
-#include "cutils/multiuser.h"
-#include "cutils/sched_policy.h"
-#include "debugger.h"
-#include "jni_internal.h"
-#include "JNIHelp.h"
-#include "ScopedLocalRef.h"
-#include "ScopedPrimitiveArray.h"
-#include "ScopedUtfChars.h"
-#include "thread-inl.h"
-#include "utils.h"
-
-#if defined(HAVE_PRCTL)
-#include <sys/prctl.h>
-#endif
-
-#include <selinux/android.h>
-
-#if defined(__linux__)
-#include <sys/personality.h>
-#include <sys/utsname.h>
-#if defined(HAVE_ANDROID_OS)
-#include <sys/capability.h>
-#endif
-#endif
-
-namespace art {
-
-static pid_t gSystemServerPid = 0;
-
-// Must match values in dalvik.system.Zygote.
-enum MountExternalKind {
-  MOUNT_EXTERNAL_NONE = 0,
-  MOUNT_EXTERNAL_SINGLEUSER = 1,
-  MOUNT_EXTERNAL_MULTIUSER = 2,
-  MOUNT_EXTERNAL_MULTIUSER_ALL = 3,
-};
-
-// This signal handler is for zygote mode, since the zygote must reap its children
-static void SigChldHandler(int /*signal_number*/) {
-  pid_t pid;
-  int status;
-
-  while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
-     // Log process-death status that we care about.  In general it is
-     // not safe to call LOG(...) from a signal handler because of
-     // possible reentrancy.  However, we know a priori that the
-     // current implementation of LOG() is safe to call from a SIGCHLD
-     // handler in the zygote process.  If the LOG() implementation
-     // changes its locking strategy or its use of syscalls within the
-     // lazy-init critical section, its use here may become unsafe.
-    if (WIFEXITED(status)) {
-      if (WEXITSTATUS(status)) {
-        LOG(INFO) << "Process " << pid << " exited cleanly (" << WEXITSTATUS(status) << ")";
-      } else if (false) {
-        LOG(INFO) << "Process " << pid << " exited cleanly (" << WEXITSTATUS(status) << ")";
-      }
-    } else if (WIFSIGNALED(status)) {
-      if (WTERMSIG(status) != SIGKILL) {
-        LOG(INFO) << "Process " << pid << " terminated by signal (" << WTERMSIG(status) << ")";
-      } else if (false) {
-        LOG(INFO) << "Process " << pid << " terminated by signal (" << WTERMSIG(status) << ")";
-      }
-#ifdef WCOREDUMP
-      if (WCOREDUMP(status)) {
-        LOG(INFO) << "Process " << pid << " dumped core";
-      }
-#endif /* ifdef WCOREDUMP */
-    }
-
-    // If the just-crashed process is the system_server, bring down zygote
-    // so that it is restarted by init and system server will be restarted
-    // from there.
-    if (pid == gSystemServerPid) {
-      LOG(ERROR) << "Exit zygote because system server (" << pid << ") has terminated";
-      kill(getpid(), SIGKILL);
-    }
-  }
-
-  if (pid < 0) {
-    PLOG(WARNING) << "Zygote SIGCHLD error in waitpid";
-  }
-}
-
-// Configures the SIGCHLD handler for the zygote process. This is configured
-// very late, because earlier in the runtime we may fork() and exec()
-// other processes, and we want to waitpid() for those rather than
-// have them be harvested immediately.
-//
-// This ends up being called repeatedly before each fork(), but there's
-// no real harm in that.
-static void SetSigChldHandler() {
-  struct sigaction sa;
-  memset(&sa, 0, sizeof(sa));
-  sa.sa_handler = SigChldHandler;
-
-  int err = sigaction(SIGCHLD, &sa, NULL);
-  if (err < 0) {
-    PLOG(WARNING) << "Error setting SIGCHLD handler";
-  }
-}
-
-// Sets the SIGCHLD handler back to default behavior in zygote children.
-static void UnsetSigChldHandler() {
-  struct sigaction sa;
-  memset(&sa, 0, sizeof(sa));
-  sa.sa_handler = SIG_DFL;
-
-  int err = sigaction(SIGCHLD, &sa, NULL);
-  if (err < 0) {
-    PLOG(WARNING) << "Error unsetting SIGCHLD handler";
-  }
-}
-
-// Calls POSIX setgroups() using the int[] object as an argument.
-// A NULL argument is tolerated.
-static void SetGids(JNIEnv* env, jintArray javaGids) {
-  if (javaGids == NULL) {
-    return;
-  }
-
-  COMPILE_ASSERT(sizeof(gid_t) == sizeof(jint), sizeof_gid_and_jint_are_differerent);
-  ScopedIntArrayRO gids(env, javaGids);
-  CHECK(gids.get() != NULL);
-  int rc = setgroups(gids.size(), reinterpret_cast<const gid_t*>(&gids[0]));
-  if (rc == -1) {
-    PLOG(FATAL) << "setgroups failed";
-  }
-}
-
-// Sets the resource limits via setrlimit(2) for the values in the
-// two-dimensional array of integers that's passed in. The second dimension
-// contains a tuple of length 3: (resource, rlim_cur, rlim_max). NULL is
-// treated as an empty array.
-static void SetRLimits(JNIEnv* env, jobjectArray javaRlimits) {
-  if (javaRlimits == NULL) {
-    return;
-  }
-
-  rlimit rlim;
-  memset(&rlim, 0, sizeof(rlim));
-
-  for (int i = 0; i < env->GetArrayLength(javaRlimits); ++i) {
-    ScopedLocalRef<jobject> javaRlimitObject(env, env->GetObjectArrayElement(javaRlimits, i));
-    ScopedIntArrayRO javaRlimit(env, reinterpret_cast<jintArray>(javaRlimitObject.get()));
-    if (javaRlimit.size() != 3) {
-      LOG(FATAL) << "rlimits array must have a second dimension of size 3";
-    }
-
-    rlim.rlim_cur = javaRlimit[1];
-    rlim.rlim_max = javaRlimit[2];
-
-    int rc = setrlimit(javaRlimit[0], &rlim);
-    if (rc == -1) {
-      PLOG(FATAL) << "setrlimit(" << javaRlimit[0] << ", "
-                  << "{" << rlim.rlim_cur << ", " << rlim.rlim_max << "}) failed";
-    }
-  }
-}
-
-#if defined(HAVE_ANDROID_OS)
-
-// The debug malloc library needs to know whether it's the zygote or a child.
-extern "C" int gMallocLeakZygoteChild;
-
-static void EnableDebugger() {
-  // To let a non-privileged gdbserver attach to this
-  // process, we must set our dumpable flag.
-  if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
-    PLOG(ERROR) << "prctl(PR_SET_DUMPABLE) failed for pid " << getpid();
-  }
-  // We don't want core dumps, though, so set the core dump size to 0.
-  rlimit rl;
-  rl.rlim_cur = 0;
-  rl.rlim_max = RLIM_INFINITY;
-  if (setrlimit(RLIMIT_CORE, &rl) == -1) {
-    PLOG(ERROR) << "setrlimit(RLIMIT_CORE) failed for pid " << getpid();
-  }
-}
-
-static void EnableKeepCapabilities() {
-  int rc = prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
-  if (rc == -1) {
-    PLOG(FATAL) << "prctl(PR_SET_KEEPCAPS) failed";
-  }
-}
-
-static void DropCapabilitiesBoundingSet() {
-  for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {
-    int rc = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
-    if (rc == -1) {
-      if (errno == EINVAL) {
-        PLOG(ERROR) << "prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
-                    << "your kernel is compiled with file capabilities support";
-      } else {
-        PLOG(FATAL) << "prctl(PR_CAPBSET_DROP) failed";
-      }
-    }
-  }
-}
-
-static void SetCapabilities(int64_t permitted, int64_t effective) {
-  __user_cap_header_struct capheader;
-  memset(&capheader, 0, sizeof(capheader));
-  capheader.version = _LINUX_CAPABILITY_VERSION_3;
-  capheader.pid = 0;
-
-  __user_cap_data_struct capdata[2];
-  memset(&capdata, 0, sizeof(capdata));
-  capdata[0].effective = effective;
-  capdata[1].effective = effective >> 32;
-  capdata[0].permitted = permitted;
-  capdata[1].permitted = permitted >> 32;
-
-  if (capset(&capheader, &capdata[0]) == -1) {
-    PLOG(FATAL) << "capset(" << permitted << ", " << effective << ") failed";
-  }
-}
-
-static void SetSchedulerPolicy() {
-  errno = -set_sched_policy(0, SP_DEFAULT);
-  if (errno != 0) {
-    PLOG(FATAL) << "set_sched_policy(0, SP_DEFAULT) failed";
-  }
-}
-
-#else
-
-static int gMallocLeakZygoteChild = 0;
-
-static void EnableDebugger() {}
-static void EnableKeepCapabilities() {}
-static void DropCapabilitiesBoundingSet() {}
-static void SetCapabilities(int64_t, int64_t) {}
-static void SetSchedulerPolicy() {}
-
-#endif
-
-static void EnableDebugFeatures(uint32_t debug_flags) {
-  // Must match values in dalvik.system.Zygote.
-  enum {
-    DEBUG_ENABLE_DEBUGGER           = 1,
-    DEBUG_ENABLE_CHECKJNI           = 1 << 1,
-    DEBUG_ENABLE_ASSERT             = 1 << 2,
-    DEBUG_ENABLE_SAFEMODE           = 1 << 3,
-    DEBUG_ENABLE_JNI_LOGGING        = 1 << 4,
-  };
-
-  if ((debug_flags & DEBUG_ENABLE_CHECKJNI) != 0) {
-    Runtime* runtime = Runtime::Current();
-    JavaVMExt* vm = runtime->GetJavaVM();
-    if (!vm->check_jni) {
-      LOG(DEBUG) << "Late-enabling -Xcheck:jni";
-      vm->SetCheckJniEnabled(true);
-      // There's only one thread running at this point, so only one JNIEnv to fix up.
-      Thread::Current()->GetJniEnv()->SetCheckJniEnabled(true);
-    } else {
-      LOG(DEBUG) << "Not late-enabling -Xcheck:jni (already on)";
-    }
-    debug_flags &= ~DEBUG_ENABLE_CHECKJNI;
-  }
-
-  if ((debug_flags & DEBUG_ENABLE_JNI_LOGGING) != 0) {
-    gLogVerbosity.third_party_jni = true;
-    debug_flags &= ~DEBUG_ENABLE_JNI_LOGGING;
-  }
-
-  Dbg::SetJdwpAllowed((debug_flags & DEBUG_ENABLE_DEBUGGER) != 0);
-  if ((debug_flags & DEBUG_ENABLE_DEBUGGER) != 0) {
-    EnableDebugger();
-  }
-  debug_flags &= ~DEBUG_ENABLE_DEBUGGER;
-
-  // These two are for backwards compatibility with Dalvik.
-  debug_flags &= ~DEBUG_ENABLE_ASSERT;
-  debug_flags &= ~DEBUG_ENABLE_SAFEMODE;
-
-  if (debug_flags != 0) {
-    LOG(ERROR) << StringPrintf("Unknown bits set in debug_flags: %#x", debug_flags);
-  }
-}
-
-// Create a private mount namespace and bind mount appropriate emulated
-// storage for the given user.
-static bool MountEmulatedStorage(uid_t uid, jint mount_mode) {
-  if (mount_mode == MOUNT_EXTERNAL_NONE) {
-    return true;
-  }
-
-  // See storage config details at http://source.android.com/tech/storage/
-  userid_t user_id = multiuser_get_user_id(uid);
-
-  // Create a second private mount namespace for our process
-  if (unshare(CLONE_NEWNS) == -1) {
-      PLOG(WARNING) << "Failed to unshare()";
-      return false;
-  }
-
-  // Create bind mounts to expose external storage
-  if (mount_mode == MOUNT_EXTERNAL_MULTIUSER || mount_mode == MOUNT_EXTERNAL_MULTIUSER_ALL) {
-    // These paths must already be created by init.rc
-    const char* source = getenv("EMULATED_STORAGE_SOURCE");
-    const char* target = getenv("EMULATED_STORAGE_TARGET");
-    const char* legacy = getenv("EXTERNAL_STORAGE");
-    if (source == NULL || target == NULL || legacy == NULL) {
-      LOG(WARNING) << "Storage environment undefined; unable to provide external storage";
-      return false;
-    }
-
-    // Prepare source paths
-
-    // /mnt/shell/emulated/0
-    std::string source_user(StringPrintf("%s/%d", source, user_id));
-    // /storage/emulated/0
-    std::string target_user(StringPrintf("%s/%d", target, user_id));
-
-    if (fs_prepare_dir(source_user.c_str(), 0000, 0, 0) == -1
-        || fs_prepare_dir(target_user.c_str(), 0000, 0, 0) == -1) {
-      return false;
-    }
-
-    if (mount_mode == MOUNT_EXTERNAL_MULTIUSER_ALL) {
-      // Mount entire external storage tree for all users
-      if (TEMP_FAILURE_RETRY(mount(source, target, NULL, MS_BIND, NULL)) == -1) {
-        PLOG(WARNING) << "Failed to mount " << source << " to " << target;
-        return false;
-      }
-    } else {
-      // Only mount user-specific external storage
-      if (TEMP_FAILURE_RETRY(
-              mount(source_user.c_str(), target_user.c_str(), NULL, MS_BIND, NULL)) == -1) {
-        PLOG(WARNING) << "Failed to mount " << source_user << " to " << target_user;
-        return false;
-      }
-    }
-
-    if (fs_prepare_dir(legacy, 0000, 0, 0) == -1) {
-        return false;
-    }
-
-    // Finally, mount user-specific path into place for legacy users
-    if (TEMP_FAILURE_RETRY(
-            mount(target_user.c_str(), legacy, NULL, MS_BIND | MS_REC, NULL)) == -1) {
-      PLOG(WARNING) << "Failed to mount " << target_user << " to " << legacy;
-      return false;
-    }
-  } else {
-    LOG(WARNING) << "Mount mode " << mount_mode << " unsupported";
-    return false;
-  }
-
-  return true;
-}
-
-#if defined(__linux__)
-static bool NeedsNoRandomizeWorkaround() {
-#if !defined(__arm__)
-    return false;
-#else
-    int major;
-    int minor;
-    struct utsname uts;
-    if (uname(&uts) == -1) {
-        return false;
-    }
-
-    if (sscanf(uts.release, "%d.%d", &major, &minor) != 2) {
-        return false;
-    }
-
-    // Kernels before 3.4.* need the workaround.
-    return (major < 3) || ((major == 3) && (minor < 4));
-#endif
-}
-#endif
-
-// Utility to close down the Zygote socket file descriptors while
-// the child is still running as root with Zygote's privileges.  Each
-// descriptor (if any) is closed via dup2(), replacing it with a valid
-// (open) descriptor to /dev/null.
-
-static void DetachDescriptors(JNIEnv* env, jintArray fdsToClose) {
-  if (!fdsToClose) {
-    return;
-  }
-  jsize count = env->GetArrayLength(fdsToClose);
-  jint *ar = env->GetIntArrayElements(fdsToClose, 0);
-  if (!ar) {
-      PLOG(FATAL) << "Bad fd array";
-  }
-  jsize i;
-  int devnull;
-  for (i = 0; i < count; i++) {
-    devnull = open("/dev/null", O_RDWR);
-    if (devnull < 0) {
-      PLOG(FATAL) << "Failed to open /dev/null";
-      continue;
-    }
-    PLOG(VERBOSE) << "Switching descriptor " << ar[i] << " to /dev/null";
-    if (dup2(devnull, ar[i]) < 0) {
-      PLOG(FATAL) << "Failed dup2() on descriptor " << ar[i];
-    }
-    close(devnull);
-  }
-}
-
-// Utility routine to fork zygote and specialize the child process.
-static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray javaGids,
-                                     jint debug_flags, jobjectArray javaRlimits,
-                                     jlong permittedCapabilities, jlong effectiveCapabilities,
-                                     jint mount_external,
-                                     jstring java_se_info, jstring java_se_name,
-                                     bool is_system_server, jintArray fdsToClose) {
-  Runtime* runtime = Runtime::Current();
-  CHECK(runtime->IsZygote()) << "runtime instance not started with -Xzygote";
-  if (!runtime->PreZygoteFork()) {
-    LOG(FATAL) << "pre-fork heap failed";
-  }
-
-  SetSigChldHandler();
-
-  // Grab thread before fork potentially makes Thread::pthread_key_self_ unusable.
-  Thread* self = Thread::Current();
-
-  // dvmDumpLoaderStats("zygote");  // TODO: ?
-  pid_t pid = fork();
-
-  if (pid == 0) {
-    // The child process.
-    gMallocLeakZygoteChild = 1;
-
-    // Clean up any descriptors which must be closed immediately
-    DetachDescriptors(env, fdsToClose);
-
-    // Keep capabilities across UID change, unless we're staying root.
-    if (uid != 0) {
-      EnableKeepCapabilities();
-    }
-
-    DropCapabilitiesBoundingSet();
-
-    if (!MountEmulatedStorage(uid, mount_external)) {
-      PLOG(WARNING) << "Failed to mount emulated storage";
-      if (errno == ENOTCONN || errno == EROFS) {
-        // When device is actively encrypting, we get ENOTCONN here
-        // since FUSE was mounted before the framework restarted.
-        // When encrypted device is booting, we get EROFS since
-        // FUSE hasn't been created yet by init.
-        // In either case, continue without external storage.
-      } else {
-        LOG(FATAL) << "Cannot continue without emulated storage";
-      }
-    }
-
-    SetGids(env, javaGids);
-
-    SetRLimits(env, javaRlimits);
-
-    int rc = setresgid(gid, gid, gid);
-    if (rc == -1) {
-      PLOG(FATAL) << "setresgid(" << gid << ") failed";
-    }
-
-    rc = setresuid(uid, uid, uid);
-    if (rc == -1) {
-      PLOG(FATAL) << "setresuid(" << uid << ") failed";
-    }
-
-#if defined(__linux__)
-    if (NeedsNoRandomizeWorkaround()) {
-        // Work around ARM kernel ASLR lossage (http://b/5817320).
-        int old_personality = personality(0xffffffff);
-        int new_personality = personality(old_personality | ADDR_NO_RANDOMIZE);
-        if (new_personality == -1) {
-            PLOG(WARNING) << "personality(" << new_personality << ") failed";
-        }
-    }
-#endif
-
-    SetCapabilities(permittedCapabilities, effectiveCapabilities);
-
-    SetSchedulerPolicy();
-
-#if defined(HAVE_ANDROID_OS)
-    {  // NOLINT(whitespace/braces)
-      const char* se_info_c_str = NULL;
-      UniquePtr<ScopedUtfChars> se_info;
-      if (java_se_info != NULL) {
-          se_info.reset(new ScopedUtfChars(env, java_se_info));
-          se_info_c_str = se_info->c_str();
-          CHECK(se_info_c_str != NULL);
-      }
-      const char* se_name_c_str = NULL;
-      UniquePtr<ScopedUtfChars> se_name;
-      if (java_se_name != NULL) {
-          se_name.reset(new ScopedUtfChars(env, java_se_name));
-          se_name_c_str = se_name->c_str();
-          CHECK(se_name_c_str != NULL);
-      }
-      rc = selinux_android_setcontext(uid, is_system_server, se_info_c_str, se_name_c_str);
-      if (rc == -1) {
-        PLOG(FATAL) << "selinux_android_setcontext(" << uid << ", "
-                    << (is_system_server ? "true" : "false") << ", "
-                    << "\"" << se_info_c_str << "\", \"" << se_name_c_str << "\") failed";
-      }
-
-      // Make it easier to debug audit logs by setting the main thread's name to the
-      // nice name rather than "app_process".
-      if (se_info_c_str == NULL && is_system_server) {
-        se_name_c_str = "system_server";
-      }
-      if (se_info_c_str != NULL) {
-        SetThreadName(se_name_c_str);
-      }
-    }
-#else
-    UNUSED(is_system_server);
-    UNUSED(java_se_info);
-    UNUSED(java_se_name);
-#endif
-
-    // Our system thread ID, etc, has changed so reset Thread state.
-    self->InitAfterFork();
-
-    EnableDebugFeatures(debug_flags);
-
-    UnsetSigChldHandler();
-    runtime->DidForkFromZygote();
-  } else if (pid > 0) {
-    // the parent process
-  }
-  return pid;
-}
-
-static jint Zygote_nativeForkAndSpecialize(JNIEnv* env, jclass, jint uid, jint gid, jintArray gids,
-                                           jint debug_flags, jobjectArray rlimits,
-                                           jint mount_external, jstring se_info, jstring se_name,
-                                           jintArray fdsToClose) {
-  return ForkAndSpecializeCommon(env, uid, gid, gids, debug_flags, rlimits, 0, 0, mount_external,
-                                 se_info, se_name, false, fdsToClose);
-}
-
-static jint Zygote_nativeForkSystemServer(JNIEnv* env, jclass, uid_t uid, gid_t gid, jintArray gids,
-                                          jint debug_flags, jobjectArray rlimits,
-                                          jlong permittedCapabilities,
-                                          jlong effectiveCapabilities) {
-  pid_t pid = ForkAndSpecializeCommon(env, uid, gid, gids,
-                                      debug_flags, rlimits,
-                                      permittedCapabilities, effectiveCapabilities,
-                                      MOUNT_EXTERNAL_NONE, NULL, NULL, true, NULL);
-  if (pid > 0) {
-      // The zygote process checks whether the child process has died or not.
-      LOG(INFO) << "System server process " << pid << " has been created";
-      gSystemServerPid = pid;
-      // There is a slight window that the system server process has crashed
-      // but it went unnoticed because we haven't published its pid yet. So
-      // we recheck here just to make sure that all is well.
-      int status;
-      if (waitpid(pid, &status, WNOHANG) == pid) {
-          LOG(FATAL) << "System server process " << pid << " has died. Restarting Zygote!";
-      }
-  }
-  return pid;
-}
-
-static JNINativeMethod gMethods[] = {
-  NATIVE_METHOD(Zygote, nativeForkAndSpecialize, "(II[II[[IILjava/lang/String;Ljava/lang/String;[I)I"),
-  NATIVE_METHOD(Zygote, nativeForkSystemServer, "(II[II[[IJJ)I"),
-};
-
-void register_dalvik_system_Zygote(JNIEnv* env) {
-  REGISTER_NATIVE_METHODS("dalvik/system/Zygote");
-}
-
-}  // namespace art
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
new file mode 100644
index 0000000..2af5324
--- /dev/null
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+
+#include "debugger.h"
+#include "jni_internal.h"
+#include "JNIHelp.h"
+#include "thread-inl.h"
+
+#if defined(HAVE_PRCTL)
+#include <sys/prctl.h>
+#endif
+
+#include <sys/resource.h>
+
+namespace art {
+
+static void EnableDebugger() {
+  // To let a non-privileged gdbserver attach to this
+  // process, we must set our dumpable flag.
+  if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
+    PLOG(ERROR) << "prctl(PR_SET_DUMPABLE) failed for pid " << getpid();
+  }
+  // We don't want core dumps, though, so set the core dump size to 0.
+  rlimit rl;
+  rl.rlim_cur = 0;
+  rl.rlim_max = RLIM_INFINITY;
+  if (setrlimit(RLIMIT_CORE, &rl) == -1) {
+    PLOG(ERROR) << "setrlimit(RLIMIT_CORE) failed for pid " << getpid();
+  }
+}
+
+static void EnableDebugFeatures(uint32_t debug_flags) {
+  // Must match values in dalvik.system.Zygote.
+  enum {
+    DEBUG_ENABLE_DEBUGGER           = 1,
+    DEBUG_ENABLE_CHECKJNI           = 1 << 1,
+    DEBUG_ENABLE_ASSERT             = 1 << 2,
+    DEBUG_ENABLE_SAFEMODE           = 1 << 3,
+    DEBUG_ENABLE_JNI_LOGGING        = 1 << 4,
+  };
+
+  if ((debug_flags & DEBUG_ENABLE_CHECKJNI) != 0) {
+    Runtime* runtime = Runtime::Current();
+    JavaVMExt* vm = runtime->GetJavaVM();
+    if (!vm->check_jni) {
+      LOG(DEBUG) << "Late-enabling -Xcheck:jni";
+      vm->SetCheckJniEnabled(true);
+      // There's only one thread running at this point, so only one JNIEnv to fix up.
+      Thread::Current()->GetJniEnv()->SetCheckJniEnabled(true);
+    } else {
+      LOG(DEBUG) << "Not late-enabling -Xcheck:jni (already on)";
+    }
+    debug_flags &= ~DEBUG_ENABLE_CHECKJNI;
+  }
+
+  if ((debug_flags & DEBUG_ENABLE_JNI_LOGGING) != 0) {
+    gLogVerbosity.third_party_jni = true;
+    debug_flags &= ~DEBUG_ENABLE_JNI_LOGGING;
+  }
+
+  Dbg::SetJdwpAllowed((debug_flags & DEBUG_ENABLE_DEBUGGER) != 0);
+  if ((debug_flags & DEBUG_ENABLE_DEBUGGER) != 0) {
+    EnableDebugger();
+  }
+  debug_flags &= ~DEBUG_ENABLE_DEBUGGER;
+
+  // These two are for backwards compatibility with Dalvik.
+  debug_flags &= ~DEBUG_ENABLE_ASSERT;
+  debug_flags &= ~DEBUG_ENABLE_SAFEMODE;
+
+  if (debug_flags != 0) {
+    LOG(ERROR) << StringPrintf("Unknown bits set in debug_flags: %#x", debug_flags);
+  }
+}
+
+static jlong ZygoteHooks_nativePreFork(JNIEnv* env, jclass) {
+  Runtime* runtime = Runtime::Current();
+  CHECK(runtime->IsZygote()) << "runtime instance not started with -Xzygote";
+  if (!runtime->PreZygoteFork()) {
+    LOG(FATAL) << "pre-fork heap failed";
+  }
+
+  // Grab thread before fork potentially makes Thread::pthread_key_self_ unusable.
+  Thread* self = Thread::Current();
+  return reinterpret_cast<jlong>(self);
+}
+
+static void ZygoteHooks_nativePostForkChild(JNIEnv* env, jclass, jlong token, jint debug_flags) {
+  Thread* thread = reinterpret_cast<Thread*>(token);
+  // Our system thread ID, etc, has changed so reset Thread state.
+  thread->InitAfterFork();
+  EnableDebugFeatures(debug_flags);
+  Runtime::Current()->DidForkFromZygote();
+}
+
+static JNINativeMethod gMethods[] = {
+  NATIVE_METHOD(ZygoteHooks, nativePreFork, "()J"),
+  NATIVE_METHOD(ZygoteHooks, nativePostForkChild, "(JI)V"),
+};
+
+void register_dalvik_system_ZygoteHooks(JNIEnv* env) {
+  REGISTER_NATIVE_METHODS("dalvik/system/ZygoteHooks");
+}
+
+}  // namespace art
diff --git a/runtime/native/java_lang_Throwable.cc b/runtime/native/java_lang_Throwable.cc
index d1a1105..3ed4cfe 100644
--- a/runtime/native/java_lang_Throwable.cc
+++ b/runtime/native/java_lang_Throwable.cc
@@ -22,7 +22,7 @@
 
 static jobject Throwable_nativeFillInStackTrace(JNIEnv* env, jclass) {
   ScopedFastNativeObjectAccess soa(env);
-  return soa.Self()->CreateInternalStackTrace(soa);
+  return soa.Self()->CreateInternalStackTrace<false>(soa);
 }
 
 static jobjectArray Throwable_nativeGetStackTrace(JNIEnv* env, jclass, jobject javaStackState) {
diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
index a7ca0b8..5d90f1a 100644
--- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
+++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
@@ -49,7 +49,7 @@
   if (static_cast<uint32_t>(thin_lock_id) == self->GetThreadId()) {
     // No need to suspend ourself to build stacktrace.
     ScopedObjectAccess soa(env);
-    jobject internal_trace = self->CreateInternalStackTrace(soa);
+    jobject internal_trace = self->CreateInternalStackTrace<false>(soa);
     trace = Thread::InternalStackTraceToStackTraceElementArray(soa, internal_trace);
   } else {
     // Suspend thread to build stack trace.
@@ -59,7 +59,7 @@
     if (thread != nullptr) {
       {
         ScopedObjectAccess soa(env);
-        jobject internal_trace = thread->CreateInternalStackTrace(soa);
+        jobject internal_trace = thread->CreateInternalStackTrace<false>(soa);
         trace = Thread::InternalStackTraceToStackTraceElementArray(soa, internal_trace);
       }
       // Restart suspended thread.
diff --git a/runtime/oat.cc b/runtime/oat.cc
index f970789..246e090 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', '1', '9', '\0' };
+const uint8_t OatHeader::kOatVersion[] = { '0', '2', '0', '\0' };
 
 OatHeader::OatHeader() {
   memset(this, 0, sizeof(*this));
diff --git a/runtime/object_utils.h b/runtime/object_utils.h
index 63801d3..072f074 100644
--- a/runtime/object_utils.h
+++ b/runtime/object_utils.h
@@ -25,6 +25,7 @@
 #include "mirror/class.h"
 #include "mirror/dex_cache.h"
 #include "mirror/iftable.h"
+#include "mirror/proxy.h"
 #include "mirror/string.h"
 
 #include "runtime.h"
@@ -133,7 +134,9 @@
     } else if (klass_->IsArrayClass()) {
       return 2;
     } else if (klass_->IsProxyClass()) {
-      return klass_->GetIfTable()->Count();
+      mirror::SynthesizedProxyClass* proxyClass = reinterpret_cast<mirror::SynthesizedProxyClass*>(klass_);
+      mirror::ObjectArray<mirror::Class>* interfaces = proxyClass->GetInterfaces();
+      return interfaces != nullptr ? interfaces->GetLength() : 0;
     } else {
       const DexFile::TypeList* interfaces = GetInterfaceTypeList();
       if (interfaces == nullptr) {
@@ -164,7 +167,10 @@
         return GetClassLinker()->FindSystemClass(Thread::Current(), "Ljava/io/Serializable;");
       }
     } else if (klass_->IsProxyClass()) {
-      return klass_->GetIfTable()->GetInterface(idx);
+      mirror::SynthesizedProxyClass* proxyClass = reinterpret_cast<mirror::SynthesizedProxyClass*>(klass_);
+      mirror::ObjectArray<mirror::Class>* interfaces = proxyClass->GetInterfaces();
+      DCHECK(interfaces != nullptr);
+      return interfaces->Get(idx);
     } else {
       uint16_t type_idx = GetDirectInterfaceTypeIdx(idx);
       mirror::Class* interface = GetDexCache()->GetResolvedType(type_idx);
diff --git a/runtime/proxy_test.cc b/runtime/proxy_test.cc
index 6453cb4..eebfba8 100644
--- a/runtime/proxy_test.cc
+++ b/runtime/proxy_test.cc
@@ -107,7 +107,8 @@
 TEST_F(ProxyTest, ProxyClassHelper) {
   ScopedObjectAccess soa(Thread::Current());
   jobject jclass_loader = LoadDex("Interfaces");
-  SirtRef<mirror::ClassLoader> class_loader(soa.Self(), soa.Decode<mirror::ClassLoader*>(jclass_loader));
+  SirtRef<mirror::ClassLoader> class_loader(soa.Self(),
+                                            soa.Decode<mirror::ClassLoader*>(jclass_loader));
 
   mirror::Class* I = class_linker_->FindClass(soa.Self(), "LInterfaces$I;", class_loader);
   mirror::Class* J = class_linker_->FindClass(soa.Self(), "LInterfaces$J;", class_loader);
@@ -120,20 +121,66 @@
   mirror::Class* proxyClass = GenerateProxyClass(soa, jclass_loader, "$Proxy1234", interfaces);
   ASSERT_TRUE(proxyClass != nullptr);
   ASSERT_TRUE(proxyClass->IsProxyClass());
-
-  mirror::Class* javaIoSerializable = class_linker_->FindSystemClass(soa.Self(), "Ljava/io/Serializable;");
-  ASSERT_TRUE(javaIoSerializable != nullptr);
+  ASSERT_TRUE(proxyClass->IsInitialized());
 
   // Check ClassHelper for proxy.
   ClassHelper kh(proxyClass);
-  EXPECT_EQ(kh.NumDirectInterfaces(), 3U);  // java.io.Serializable, Interfaces$I and Interfaces$J.
-  EXPECT_EQ(javaIoSerializable, kh.GetDirectInterface(0));
-  EXPECT_EQ(I, kh.GetDirectInterface(1));
-  EXPECT_EQ(J, kh.GetDirectInterface(2));
+  EXPECT_EQ(kh.NumDirectInterfaces(), 2U);  // Interfaces$I and Interfaces$J.
+  EXPECT_EQ(I, kh.GetDirectInterface(0));
+  EXPECT_EQ(J, kh.GetDirectInterface(1));
   std::string proxyClassDescriptor(kh.GetDescriptor());
   EXPECT_EQ("L$Proxy1234;", proxyClassDescriptor);
-//  EXPECT_EQ(nullptr, kh.GetSourceFile());
 }
 
+// Creates a proxy class and check FieldHelper works correctly.
+TEST_F(ProxyTest, ProxyFieldHelper) {
+  ScopedObjectAccess soa(Thread::Current());
+  jobject jclass_loader = LoadDex("Interfaces");
+  SirtRef<mirror::ClassLoader> class_loader(soa.Self(),
+                                            soa.Decode<mirror::ClassLoader*>(jclass_loader));
+
+  mirror::Class* I = class_linker_->FindClass(soa.Self(), "LInterfaces$I;", class_loader);
+  mirror::Class* J = class_linker_->FindClass(soa.Self(), "LInterfaces$J;", class_loader);
+  ASSERT_TRUE(I != nullptr);
+  ASSERT_TRUE(J != nullptr);
+  std::vector<mirror::Class*> interfaces;
+  interfaces.push_back(I);
+  interfaces.push_back(J);
+
+  mirror::Class* proxyClass = GenerateProxyClass(soa, jclass_loader, "$Proxy1234", interfaces);
+  ASSERT_TRUE(proxyClass != nullptr);
+  ASSERT_TRUE(proxyClass->IsProxyClass());
+  ASSERT_TRUE(proxyClass->IsInitialized());
+
+  mirror::ObjectArray<mirror::ArtField>* instance_fields = proxyClass->GetIFields();
+  EXPECT_TRUE(instance_fields == nullptr);
+
+  mirror::ObjectArray<mirror::ArtField>* static_fields = proxyClass->GetSFields();
+  ASSERT_TRUE(static_fields != nullptr);
+  ASSERT_EQ(2, static_fields->GetLength());
+
+  mirror::Class* interfacesFieldClass = class_linker_->FindSystemClass(soa.Self(),
+                                                                       "[Ljava/lang/Class;");
+  ASSERT_TRUE(interfacesFieldClass != nullptr);
+  mirror::Class* throwsFieldClass = class_linker_->FindSystemClass(soa.Self(),
+                                                                   "[[Ljava/lang/Class;");
+  ASSERT_TRUE(throwsFieldClass != nullptr);
+
+  // Test "Class[] interfaces" field.
+  FieldHelper fh(static_fields->Get(0));
+  EXPECT_EQ("interfaces", std::string(fh.GetName()));
+  EXPECT_EQ("[Ljava/lang/Class;", std::string(fh.GetTypeDescriptor()));
+  EXPECT_EQ(interfacesFieldClass, fh.GetType());
+  EXPECT_EQ("L$Proxy1234;", std::string(fh.GetDeclaringClassDescriptor()));
+  EXPECT_FALSE(fh.IsPrimitiveType());
+
+  // Test "Class[][] throws" field.
+  fh.ChangeField(static_fields->Get(1));
+  EXPECT_EQ("throws", std::string(fh.GetName()));
+  EXPECT_EQ("[[Ljava/lang/Class;", std::string(fh.GetTypeDescriptor()));
+  EXPECT_EQ(throwsFieldClass, fh.GetType());
+  EXPECT_EQ("L$Proxy1234;", std::string(fh.GetDeclaringClassDescriptor()));
+  EXPECT_FALSE(fh.IsPrimitiveType());
+}
 
 }  // namespace art
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index c0bb36a..b0a6584 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -79,6 +79,8 @@
 namespace art {
 
 static constexpr bool kEnableJavaStackTraceHandler = true;
+const char* Runtime::kDefaultInstructionSetFeatures =
+    STRINGIFY(ART_DEFAULT_INSTRUCTION_SET_FEATURES);
 Runtime* Runtime::instance_ = NULL;
 
 Runtime::Runtime()
@@ -127,7 +129,7 @@
       system_thread_group_(nullptr),
       system_class_loader_(nullptr),
       dump_gc_performance_on_shutdown_(false),
-      preinitialization_transaction(nullptr),
+      preinitialization_transaction_(nullptr),
       null_pointer_handler_(nullptr),
       suspend_handler_(nullptr),
       stack_overflow_handler_(nullptr) {
@@ -708,7 +710,7 @@
   REGISTER(register_dalvik_system_VMDebug);
   REGISTER(register_dalvik_system_VMRuntime);
   REGISTER(register_dalvik_system_VMStack);
-  REGISTER(register_dalvik_system_Zygote);
+  REGISTER(register_dalvik_system_ZygoteHooks);
   REGISTER(register_java_lang_Class);
   REGISTER(register_java_lang_DexCache);
   REGISTER(register_java_lang_Object);
@@ -900,8 +902,8 @@
       verifier->VisitRoots(callback, arg);
     }
   }
-  if (preinitialization_transaction != nullptr) {
-    preinitialization_transaction->VisitRoots(callback, arg);
+  if (preinitialization_transaction_ != nullptr) {
+    preinitialization_transaction_->VisitRoots(callback, arg);
   }
   instrumentation_.VisitRoots(callback, arg);
 }
@@ -1147,73 +1149,68 @@
 }
 
 // Transaction support.
-// TODO move them to header file for inlining.
-bool Runtime::IsActiveTransaction() const {
-  return preinitialization_transaction != nullptr;
-}
-
 void Runtime::EnterTransactionMode(Transaction* transaction) {
   DCHECK(IsCompiler());
   DCHECK(transaction != nullptr);
   DCHECK(!IsActiveTransaction());
-  preinitialization_transaction = transaction;
+  preinitialization_transaction_ = transaction;
 }
 
 void Runtime::ExitTransactionMode() {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction = nullptr;
+  preinitialization_transaction_ = nullptr;
 }
 
 void Runtime::RecordWriteField32(mirror::Object* obj, MemberOffset field_offset,
                                  uint32_t value, bool is_volatile) const {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction->RecordWriteField32(obj, field_offset, value, is_volatile);
+  preinitialization_transaction_->RecordWriteField32(obj, field_offset, value, is_volatile);
 }
 
 void Runtime::RecordWriteField64(mirror::Object* obj, MemberOffset field_offset,
                                  uint64_t value, bool is_volatile) const {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction->RecordWriteField64(obj, field_offset, value, is_volatile);
+  preinitialization_transaction_->RecordWriteField64(obj, field_offset, value, is_volatile);
 }
 
 void Runtime::RecordWriteFieldReference(mirror::Object* obj, MemberOffset field_offset,
                                         mirror::Object* value, bool is_volatile) const {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction->RecordWriteFieldReference(obj, field_offset, value, is_volatile);
+  preinitialization_transaction_->RecordWriteFieldReference(obj, field_offset, value, is_volatile);
 }
 
 void Runtime::RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) const {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction->RecordWriteArray(array, index, value);
+  preinitialization_transaction_->RecordWriteArray(array, index, value);
 }
 
 void Runtime::RecordStrongStringInsertion(mirror::String* s, uint32_t hash_code) const {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction->RecordStrongStringInsertion(s, hash_code);
+  preinitialization_transaction_->RecordStrongStringInsertion(s, hash_code);
 }
 
 void Runtime::RecordWeakStringInsertion(mirror::String* s, uint32_t hash_code) const {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction->RecordWeakStringInsertion(s, hash_code);
+  preinitialization_transaction_->RecordWeakStringInsertion(s, hash_code);
 }
 
 void Runtime::RecordStrongStringRemoval(mirror::String* s, uint32_t hash_code) const {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction->RecordStrongStringRemoval(s, hash_code);
+  preinitialization_transaction_->RecordStrongStringRemoval(s, hash_code);
 }
 
 void Runtime::RecordWeakStringRemoval(mirror::String* s, uint32_t hash_code) const {
   DCHECK(IsCompiler());
   DCHECK(IsActiveTransaction());
-  preinitialization_transaction->RecordWeakStringRemoval(s, hash_code);
+  preinitialization_transaction_->RecordWeakStringRemoval(s, hash_code);
 }
 
 void Runtime::SetFaultMessage(const std::string& message) {
@@ -1221,6 +1218,59 @@
   fault_message_ = message;
 }
 
+void Runtime::AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* argv)
+    const {
+  argv->push_back("--runtime-arg");
+  std::string checkstr = "-implicit-checks";
+
+  int nchecks = 0;
+  char checksep = ':';
+
+  if (!ExplicitNullChecks()) {
+    checkstr += checksep;
+    checksep = ',';
+    checkstr += "null";
+    ++nchecks;
+  }
+  if (!ExplicitSuspendChecks()) {
+    checkstr += checksep;
+    checksep = ',';
+    checkstr += "suspend";
+    ++nchecks;
+  }
+
+  if (!ExplicitStackOverflowChecks()) {
+    checkstr += checksep;
+    checksep = ',';
+    checkstr += "stack";
+    ++nchecks;
+  }
+
+  if (nchecks == 0) {
+    checkstr += ":none";
+  }
+  argv->push_back(checkstr);
+
+  // Make the dex2oat instruction set match that of the launching runtime. If we have multiple
+  // architecture support, dex2oat may be compiled as a different instruction-set than that
+  // currently being executed.
+#if defined(__arm__)
+  argv->push_back("--instruction-set=arm");
+#elif defined(__aarch64__)
+  argv->push_back("--instruction-set=arm64");
+#elif defined(__i386__)
+  argv->push_back("--instruction-set=x86");
+#elif defined(__x86_64__)
+  argv->push_back("--instruction-set=x86_64");
+#elif defined(__mips__)
+  argv->push_back("--instruction-set=mips");
+#endif
+
+  std::string features("--instruction-set-features=");
+  features += GetDefaultInstructionSetFeatures();
+  argv->push_back(features);
+}
+
 void Runtime::UpdateProfilerState(int state) {
   LOG(DEBUG) << "Profiler state updated to " << state;
 }
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 755c0f0..176b71c 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -378,7 +378,9 @@
   void UpdateProfilerState(int state);
 
   // Transaction support.
-  bool IsActiveTransaction() const;
+  bool IsActiveTransaction() const {
+    return preinitialization_transaction_ != nullptr;
+  }
   void EnterTransactionMode(Transaction* transaction);
   void ExitTransactionMode();
   void RecordWriteField32(mirror::Object* obj, MemberOffset field_offset, uint32_t value,
@@ -405,6 +407,8 @@
     return fault_message_;
   }
 
+  void AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* arg_vector) const;
+
   bool ExplicitNullChecks() const {
     return null_pointer_handler_ == nullptr;
   }
@@ -421,6 +425,10 @@
     return running_on_valgrind_;
   }
 
+  static const char* GetDefaultInstructionSetFeatures() {
+    return kDefaultInstructionSetFeatures;
+  }
+
  private:
   static void InitPlatformSignalHandlers();
 
@@ -437,15 +445,15 @@
   void StartDaemonThreads();
   void StartSignalCatcher();
 
-  // NOTE: these must match the gc::ProcessState values as they come directly
-  // from the framework.
-  static constexpr int kProfileForground = 0;
-  static constexpr int kProfileBackgrouud = 1;
-
-
   // A pointer to the active runtime or NULL.
   static Runtime* instance_;
 
+  static const char* kDefaultInstructionSetFeatures;
+
+  // NOTE: these must match the gc::ProcessState values as they come directly from the framework.
+  static constexpr int kProfileForground = 0;
+  static constexpr int kProfileBackgrouud = 1;
+
   mirror::ArtMethod* callee_save_methods_[kLastCalleeSaveType];
   mirror::Throwable* pre_allocated_OutOfMemoryError_;
   mirror::ArtMethod* resolution_method_;
@@ -550,7 +558,7 @@
   bool dump_gc_performance_on_shutdown_;
 
   // Transaction used for pre-initializing classes at compilation time.
-  Transaction* preinitialization_transaction;
+  Transaction* preinitialization_transaction_;
   NullPointerHandler* null_pointer_handler_;
   SuspensionHandler* suspend_handler_;
   StackOverflowHandler* stack_overflow_handler_;
diff --git a/runtime/thread.cc b/runtime/thread.cc
index c2fad44..29d011c 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -598,12 +598,14 @@
 }
 
 void Thread::ModifySuspendCount(Thread* self, int delta, bool for_debugger) {
-  DCHECK(delta == -1 || delta == +1 || delta == -tls32_.debug_suspend_count)
-      << delta << " " << tls32_.debug_suspend_count << " " << this;
-  DCHECK_GE(tls32_.suspend_count, tls32_.debug_suspend_count) << this;
-  Locks::thread_suspend_count_lock_->AssertHeld(self);
-  if (this != self && !IsSuspended()) {
-    Locks::thread_list_lock_->AssertHeld(self);
+  if (kIsDebugBuild) {
+    DCHECK(delta == -1 || delta == +1 || delta == -tls32_.debug_suspend_count)
+          << delta << " " << tls32_.debug_suspend_count << " " << this;
+    DCHECK_GE(tls32_.suspend_count, tls32_.debug_suspend_count) << this;
+    Locks::thread_suspend_count_lock_->AssertHeld(self);
+    if (this != self && !IsSuspended()) {
+      Locks::thread_list_lock_->AssertHeld(self);
+    }
   }
   if (UNLIKELY(delta < 0 && tls32_.suspend_count <= 0)) {
     UnsafeLogFatalForSuspendCount(self, this);
@@ -1346,6 +1348,7 @@
   bool skipping_;
 };
 
+template<bool kTransactionActive>
 class BuildInternalStackTraceVisitor : public StackVisitor {
  public:
   explicit BuildInternalStackTraceVisitor(Thread* self, Thread* thread, int skip_depth)
@@ -1369,7 +1372,7 @@
     // Save PC trace in last element of method trace, also places it into the
     // object graph.
     // We are called from native: use non-transactional mode.
-    method_trace->Set<false>(depth, dex_pc_trace);
+    method_trace->Set<kTransactionActive>(depth, dex_pc_trace);
     // Set the Object*s and assert that no thread suspension is now possible.
     const char* last_no_suspend_cause =
         self_->StartAssertNoThreadSuspension("Building internal stack trace");
@@ -1397,14 +1400,8 @@
     if (m->IsRuntimeMethod()) {
       return true;  // Ignore runtime frames (in particular callee save).
     }
-    // TODO dedup this code.
-    if (Runtime::Current()->IsActiveTransaction()) {
-      method_trace_->Set<true>(count_, m);
-      dex_pc_trace_->Set<true>(count_, m->IsProxyMethod() ? DexFile::kDexNoIndex : GetDexPc());
-    } else {
-      method_trace_->Set<false>(count_, m);
-      dex_pc_trace_->Set<false>(count_, m->IsProxyMethod() ? DexFile::kDexNoIndex : GetDexPc());
-    }
+    method_trace_->Set<kTransactionActive>(count_, m);
+    dex_pc_trace_->Set<kTransactionActive>(count_, m->IsProxyMethod() ? DexFile::kDexNoIndex : GetDexPc());
     ++count_;
     return true;
   }
@@ -1425,6 +1422,7 @@
   mirror::ObjectArray<mirror::Object>* method_trace_;
 };
 
+template<bool kTransactionActive>
 jobject Thread::CreateInternalStackTrace(const ScopedObjectAccessUnchecked& soa) const {
   // Compute depth of stack
   CountStackDepthVisitor count_visitor(const_cast<Thread*>(this));
@@ -1433,8 +1431,9 @@
   int32_t skip_depth = count_visitor.GetSkipDepth();
 
   // Build internal stack trace.
-  BuildInternalStackTraceVisitor build_trace_visitor(soa.Self(), const_cast<Thread*>(this),
-                                                     skip_depth);
+  BuildInternalStackTraceVisitor<kTransactionActive> build_trace_visitor(soa.Self(),
+                                                                         const_cast<Thread*>(this),
+                                                                         skip_depth);
   if (!build_trace_visitor.Init(depth)) {
     return nullptr;  // Allocation failed.
   }
@@ -1447,6 +1446,8 @@
   }
   return soa.AddLocalReference<jobjectArray>(trace);
 }
+template jobject Thread::CreateInternalStackTrace<false>(const ScopedObjectAccessUnchecked& soa) const;
+template jobject Thread::CreateInternalStackTrace<true>(const ScopedObjectAccessUnchecked& soa) const;
 
 jobjectArray Thread::InternalStackTraceToStackTraceElementArray(const ScopedObjectAccess& soa,
     jobject internal, jobjectArray output_array, int* stack_depth) {
diff --git a/runtime/thread.h b/runtime/thread.h
index f1c1d77..d25bbe9 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -450,7 +450,8 @@
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   // Create the internal representation of a stack trace, that is more time
-  // and space efficient to compute than the StackTraceElement[]
+  // and space efficient to compute than the StackTraceElement[].
+  template<bool kTransactionActive>
   jobject CreateInternalStackTrace(const ScopedObjectAccessUnchecked& soa) const
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc
index 0933780..7de9433 100644
--- a/runtime/thread_list.cc
+++ b/runtime/thread_list.cc
@@ -750,14 +750,13 @@
   MutexLock mu(self, *Locks::thread_list_lock_);
   MutexLock mu2(self, *Locks::thread_suspend_count_lock_);
   CHECK_GE(suspend_all_count_, debug_suspend_all_count_);
-  if (debug_suspend_all_count_ > 0) {
-    self->ModifySuspendCount(self, debug_suspend_all_count_, true);
+  // Modify suspend count in increments of 1 to maintain invariants in ModifySuspendCount. While
+  // this isn't particularly efficient the suspend counts are most commonly 0 or 1.
+  for (int delta = debug_suspend_all_count_; delta > 0; delta--) {
+    self->ModifySuspendCount(self, +1, true);
   }
-  if (suspend_all_count_ > 0) {
-    int delta = suspend_all_count_ - debug_suspend_all_count_;
-    if (delta > 0) {
-      self->ModifySuspendCount(self, delta, false);
-    }
+  for (int delta = suspend_all_count_ - debug_suspend_all_count_; delta > 0; delta--) {
+    self->ModifySuspendCount(self, +1, false);
   }
   CHECK(!Contains(self));
   list_.push_back(self);
diff --git a/runtime/transaction.cc b/runtime/transaction.cc
index fcda6c9..e18cf04 100644
--- a/runtime/transaction.cc
+++ b/runtime/transaction.cc
@@ -84,19 +84,18 @@
 void Transaction::RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) {
   DCHECK(array != nullptr);
   DCHECK(array->IsArrayInstance());
+  DCHECK(!array->IsObjectArray());
   MutexLock mu(Thread::Current(), log_lock_);
   ArrayLog& array_log = array_logs_[array];
   array_log.LogValue(index, value);
 }
 
 void Transaction::RecordStrongStringInsertion(mirror::String* s, uint32_t hash_code) {
-  DCHECK(s != nullptr);
   InternStringLog log(s, hash_code, InternStringLog::kStrongString, InternStringLog::kInsert);
   LogInternedString(log);
 }
 
 void Transaction::RecordWeakStringInsertion(mirror::String* s, uint32_t hash_code) {
-  DCHECK(s != nullptr);
   InternStringLog log(s, hash_code, InternStringLog::kWeakString, InternStringLog::kInsert);
   LogInternedString(log);
 }
@@ -198,9 +197,7 @@
 
   for (auto it : array_logs_) {
     mirror::Array* old_root = it.first;
-    if (old_root->IsObjectArray()) {
-      it.second.VisitRoots(callback, arg);
-    }
+    CHECK(!old_root->IsObjectArray());
     mirror::Array* new_root = old_root;
     callback(reinterpret_cast<mirror::Object**>(&new_root), arg, 0, kRootUnknown);
     if (new_root != old_root) {
@@ -403,23 +400,12 @@
     case Primitive::kPrimDouble:
       array->AsDoubleArray()->SetWithoutChecks<false>(index, static_cast<double>(value));
       break;
-    case Primitive::kPrimNot: {
-      mirror::ObjectArray<mirror::Object>* obj_array = array->AsObjectArray<mirror::Object>();
-      obj_array->SetWithoutChecks<false>(index, reinterpret_cast<mirror::Object*>(
-          static_cast<uintptr_t>(value)));
+    case Primitive::kPrimNot:
+      LOG(FATAL) << "ObjectArray should be treated as Object";
       break;
-    }
     default:
       LOG(FATAL) << "Unsupported type " << array_type;
   }
 }
 
-void Transaction::ArrayLog::VisitRoots(RootCallback* callback, void* arg) {
-  for (auto& it : array_values_) {
-    mirror::Object* obj = reinterpret_cast<mirror::Object*>(static_cast<uintptr_t>(it.second));
-    callback(&obj, arg, 0, kRootUnknown);
-    it.second = reinterpret_cast<uintptr_t>(obj);
-  }
-}
-
 }  // namespace art
diff --git a/runtime/transaction.h b/runtime/transaction.h
index cf696de..6fd86c8 100644
--- a/runtime/transaction.h
+++ b/runtime/transaction.h
@@ -118,7 +118,6 @@
     void LogValue(size_t index, uint64_t value);
 
     void Undo(mirror::Array* obj) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-    void VisitRoots(RootCallback* callback, void* arg);
 
     size_t Size() const {
       return array_values_.size();
@@ -145,6 +144,7 @@
     };
     InternStringLog(mirror::String* s, uint32_t hash_code, StringKind kind, StringOp op)
       : str_(s), hash_code_(hash_code), string_kind_(kind), string_op_(op) {
+      DCHECK(s != nullptr);
     }
 
     void Undo(InternTable* intern_table) EXCLUSIVE_LOCKS_REQUIRED(Locks::intern_table_lock_);
diff --git a/test/Android.mk b/test/Android.mk
index 0c27349..5879039 100644
--- a/test/Android.mk
+++ b/test/Android.mk
@@ -131,8 +131,8 @@
   endif
   $(call declare-test-art-oat-targets-impl,$(1),)
 
-$(HOST_OUT_JAVA_LIBRARIES)/oat-test-dex-$(1).odex: $(HOST_OUT_JAVA_LIBRARIES)/oat-test-dex-$(1).jar $(HOST_CORE_IMG_OUT) | $(DEX2OAT)
-	$(DEX2OAT) $(DEX2OAT_FLAGS) --runtime-arg -Xms16m --runtime-arg -Xmx16m --boot-image=$(HOST_CORE_IMG_OUT) --dex-file=$(PWD)/$$< --oat-file=$(PWD)/$$@ --instruction-set=$(ART_HOST_ARCH) --host --android-root=$(HOST_OUT)
+$(HOST_OUT_JAVA_LIBRARIES)/oat-test-dex-$(1).odex: $(HOST_OUT_JAVA_LIBRARIES)/oat-test-dex-$(1).jar $(HOST_CORE_IMG_OUT) | $(DEX2OATD)
+	$(DEX2OATD) $(DEX2OAT_FLAGS) --runtime-arg -Xms16m --runtime-arg -Xmx16m --boot-image=$(HOST_CORE_IMG_OUT) --dex-file=$(PWD)/$$< --oat-file=$(PWD)/$$@ --instruction-set=$(ART_HOST_ARCH) --host --android-root=$(HOST_OUT)
 
 .PHONY: test-art-host-oat-default-$(1)
 test-art-host-oat-default-$(1): $(HOST_OUT_JAVA_LIBRARIES)/oat-test-dex-$(1).odex test-art-host-dependencies