Re-enable thread-safety checking on host, warn when not enabled.

Disable thread safety checks in the interpreter where template specialization
is causing annotalysis issues.

Change-Id: I178ea278a93a3eb90f386b3e02827b5c61ea0e52
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 508ff1b..f6a1300 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -62,13 +62,6 @@
 	-Wstrict-aliasing=3 \
 	-fstrict-aliasing
 
-# Enable thread-safety for GCC 4.6 but not for GCC 4.7 where this feature was removed.
-# Enable GCC 4.6 builds with 'export TARGET_GCC_VERSION_EXP=4.6'
-ifneq ($(filter 4.6 4.6.%, $(TARGET_GCC_VERSION)),)
-  $(info Enabling thread-safety for GCC $(TARGET_GCC_VERSION))
-  art_cflags += -Wthread-safety
-endif
-
 ifeq ($(ART_SMALL_MODE),true)
   art_cflags += -DART_SMALL_MODE=1
 endif
@@ -108,6 +101,19 @@
   ART_TARGET_CFLAGS += -DANDROID_SMP=0
 endif
 
+# Enable thread-safety for GCC 4.6 on the target but not for GCC 4.7 where this feature was removed.
+ifneq ($(filter 4.6 4.6.%, $(TARGET_GCC_VERSION)),)
+  ART_TARGET_CFLAGS += -Wthread-safety
+else
+  # Warn if not using GCC 4.6 for target builds when not doing a top-level or 'mma' build.
+  ifneq ($(ONE_SHOT_MAKEFILE),)
+    # Enable target GCC 4.6 with: export TARGET_GCC_VERSION_EXP=4.6
+    $(info Using target GCC $(TARGET_GCC_VERSION) disables thread-safety checks.)
+  endif
+endif
+# We build with GCC 4.6 on the host.
+ART_HOST_CFLAGS += -Wthread-safety
+
 # To use oprofile_android --callgraph, uncomment this and recompile with "mmm art -B -j16"
 # ART_TARGET_CFLAGS += -fno-omit-frame-pointer -marm -mapcs
 
diff --git a/src/interpreter/interpreter.cc b/src/interpreter/interpreter.cc
index 124c0ee..bce2ed2 100644
--- a/src/interpreter/interpreter.cc
+++ b/src/interpreter/interpreter.cc
@@ -384,10 +384,15 @@
   ref->MonitorExit(self);
 }
 
+// TODO: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) which is failing due to template
+// specialization.
 template<InvokeType type, bool is_range>
 static void DoInvoke(Thread* self, ShadowFrame& shadow_frame,
-                     const Instruction* inst, JValue* result)
-    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+                     const Instruction* inst, JValue* result) NO_THREAD_SAFETY_ANALYSIS;
+
+template<InvokeType type, bool is_range>
+static void DoInvoke(Thread* self, ShadowFrame& shadow_frame,
+                     const Instruction* inst, JValue* result) {
   uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
   uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
   Object* receiver = (type == kStatic) ? NULL : shadow_frame.GetVRegReference(vregC);
@@ -470,10 +475,12 @@
 // are now part of the template arguments.
 // Note these template functions are static and inlined so they should not be
 // part of the final object file.
+// TODO: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) which is failing due to template
+// specialization.
 template<FindFieldType find_type, Primitive::Type field_type>
 static void DoFieldGet(Thread* self, ShadowFrame& shadow_frame,
                        const Instruction* inst)
-    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
+    NO_THREAD_SAFETY_ANALYSIS ALWAYS_INLINE;
 
 template<FindFieldType find_type, Primitive::Type field_type>
 static inline void DoFieldGet(Thread* self, ShadowFrame& shadow_frame,
@@ -524,10 +531,12 @@
   }
 }
 
+// TODO: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) which is failing due to template
+// specialization.
 template<FindFieldType find_type, Primitive::Type field_type>
 static void DoFieldPut(Thread* self, const ShadowFrame& shadow_frame,
                        const Instruction* inst)
-    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
+    NO_THREAD_SAFETY_ANALYSIS ALWAYS_INLINE;
 
 template<FindFieldType find_type, Primitive::Type field_type>
 static inline void DoFieldPut(Thread* self, const ShadowFrame& shadow_frame,