Add missing memory barrier.

When DEX-to-DEX compiler is not run onto a method (because it's not preverified
at the time of compilation), we do not replace RETURN where a barrier is needed
into RETURN_VOID_BARRIER.
This CL fixes this by placing a barrier on RETURN instruction only when the
checks are enabled (non-preverified method).

Change-Id: I4eb4cf79bb4a74684579c578318e27f62f4d9e8a
diff --git a/runtime/interpreter/interpreter_goto_table_impl.cc b/runtime/interpreter/interpreter_goto_table_impl.cc
index 67517ea..10c50f3 100644
--- a/runtime/interpreter/interpreter_goto_table_impl.cc
+++ b/runtime/interpreter/interpreter_goto_table_impl.cc
@@ -197,6 +197,12 @@
 
   HANDLE_INSTRUCTION_START(RETURN_VOID) {
     JValue result;
+    if (do_access_check) {
+      // If access checks are required then the dex-to-dex compiler and analysis of
+      // whether the class has final fields hasn't been performed. Conservatively
+      // perform the memory barrier now.
+      ANDROID_MEMBAR_STORE();
+    }
     if (UNLIKELY(self->TestAllFlags())) {
       CheckSuspend(self);
     }
diff --git a/runtime/interpreter/interpreter_switch_impl.cc b/runtime/interpreter/interpreter_switch_impl.cc
index 2f0b5e9..5253e9d 100644
--- a/runtime/interpreter/interpreter_switch_impl.cc
+++ b/runtime/interpreter/interpreter_switch_impl.cc
@@ -166,6 +166,12 @@
       case Instruction::RETURN_VOID: {
         PREAMBLE();
         JValue result;
+        if (do_access_check) {
+          // If access checks are required then the dex-to-dex compiler and analysis of
+          // whether the class has final fields hasn't been performed. Conservatively
+          // perform the memory barrier now.
+          ANDROID_MEMBAR_STORE();
+        }
         if (UNLIKELY(self->TestAllFlags())) {
           CheckSuspend(self);
         }