Some interpreter cleanup.

- Pass result pointer to interpreter to interpreter entry point.
- Avoid using MethodHelper.ChangeMethod in DoInvoke.

Change-Id: I714b78d50fb14d7a0edced54cd4de78ae54021da
diff --git a/src/class_linker.cc b/src/class_linker.cc
index 63d01a9..52ce964 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -74,7 +74,7 @@
 
 namespace art {
 
-JValue artInterpreterToQuickEntry(Thread* self, ShadowFrame* shadow_frame);
+void artInterpreterToQuickEntry(Thread* self, ShadowFrame* shadow_frame, JValue* result);
 
 static void ThrowNoClassDefFoundError(const char* fmt, ...)
     __attribute__((__format__(__printf__, 1, 2)))
diff --git a/src/interpreter/interpreter.cc b/src/interpreter/interpreter.cc
index 03618da..e2cc3d6 100644
--- a/src/interpreter/interpreter.cc
+++ b/src/interpreter/interpreter.cc
@@ -132,7 +132,7 @@
     }
   } else {
     // Not special, continue with regular interpreter execution.
-    result->SetJ(EnterInterpreterFromInterpreter(self, shadow_frame).GetJ());
+    EnterInterpreterFromInterpreter(self, shadow_frame, result);
   }
 }
 
@@ -403,9 +403,9 @@
     result->SetJ(0);
     return;
   }
-  mh.ChangeMethod(target_method);
+  MethodHelper target_mh(target_method);
 
-  const DexFile::CodeItem* code_item = mh.GetCodeItem();
+  const DexFile::CodeItem* code_item = target_mh.GetCodeItem();
   uint16_t num_regs;
   uint16_t num_ins;
   if (code_item != NULL) {
@@ -418,7 +418,7 @@
     return;
   } else {
     DCHECK(target_method->IsNative() || target_method->IsProxyMethod());
-    num_regs = num_ins = AbstractMethod::NumArgRegisters(mh.GetShorty());
+    num_regs = num_ins = AbstractMethod::NumArgRegisters(target_mh.GetShorty());
     if (!target_method->IsStatic()) {
       num_regs++;
       num_ins++;
@@ -435,13 +435,13 @@
   }
 
   size_t arg_offset = (receiver == NULL) ? 0 : 1;
-  const char* shorty = mh.GetShorty();
+  const char* shorty = target_mh.GetShorty();
   uint32_t arg[5];
   if (!is_range) {
     inst->GetArgs(arg);
   }
   for (size_t shorty_pos = 0; cur_reg < num_regs; ++shorty_pos, cur_reg++, arg_offset++) {
-    DCHECK_LT(shorty_pos + 1, mh.GetShortyLength());
+    DCHECK_LT(shorty_pos + 1, target_mh.GetShortyLength());
     size_t arg_pos = is_range ? vregC + arg_offset : arg[arg_offset];
     switch (shorty[shorty_pos + 1]) {
       case 'L': {
@@ -464,11 +464,10 @@
   }
 
   if (LIKELY(Runtime::Current()->IsStarted())) {
-    result->SetJ((target_method->GetEntryPointFromInterpreter())(self, new_shadow_frame).GetJ());
+    (target_method->GetEntryPointFromInterpreter())(self, new_shadow_frame, result);
   } else {
     UnstartedRuntimeInvoke(self, target_method, new_shadow_frame, result, num_regs - num_ins);
   }
-  mh.ChangeMethod(shadow_frame.GetMethod());
 }
 
 static void DoFieldGet(Thread* self, ShadowFrame& shadow_frame,
@@ -2808,11 +2807,11 @@
   return Execute(self, mh, code_item, shadow_frame, JValue());
 }
 
-JValue EnterInterpreterFromInterpreter(Thread* self, ShadowFrame* shadow_frame)
+void EnterInterpreterFromInterpreter(Thread* self, ShadowFrame* shadow_frame, JValue* result)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   if (__builtin_frame_address(0) < self->GetStackEnd()) {
     ThrowStackOverflowError(self);
-    return JValue();
+    return;
   }
 
   AbstractMethod* method = shadow_frame->GetMethod();
@@ -2820,7 +2819,7 @@
     if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(method->GetDeclaringClass(),
                                                                  true, true)) {
       DCHECK(Thread::Current()->IsExceptionPending());
-      return JValue();
+      return;
     }
     CHECK(method->GetDeclaringClass()->IsInitializing());
   }
@@ -2829,20 +2828,19 @@
 
   MethodHelper mh(method);
   const DexFile::CodeItem* code_item = mh.GetCodeItem();
-  JValue result;
   if (LIKELY(!method->IsNative())) {
-    result = Execute(self, mh, code_item, *shadow_frame, JValue());
+    result->SetJ(Execute(self, mh, code_item, *shadow_frame, JValue()).GetJ());
   } else {
     // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
     // generated stub) except during testing and image writing.
     CHECK(!Runtime::Current()->IsStarted());
     Object* receiver = method->IsStatic() ? NULL : shadow_frame->GetVRegReference(0);
     uint32_t* args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1);
-    UnstartedRuntimeJni(self, method, receiver, args, &result);
+    UnstartedRuntimeJni(self, method, receiver, args, result);
   }
 
   self->PopShadowFrame();
-  return result;
+  return;
 }
 
 }  // namespace interpreter
diff --git a/src/interpreter/interpreter.h b/src/interpreter/interpreter.h
index 94fdff1..96fa050 100644
--- a/src/interpreter/interpreter.h
+++ b/src/interpreter/interpreter.h
@@ -47,7 +47,7 @@
                                        ShadowFrame& shadow_frame)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
-extern JValue EnterInterpreterFromInterpreter(Thread* self, ShadowFrame* shadow_frame)
+extern void EnterInterpreterFromInterpreter(Thread* self, ShadowFrame* shadow_frame, JValue* result)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
 }  // namespace interpreter
diff --git a/src/mirror/abstract_method.h b/src/mirror/abstract_method.h
index 8f8038f..c8aa11e 100644
--- a/src/mirror/abstract_method.h
+++ b/src/mirror/abstract_method.h
@@ -37,7 +37,7 @@
 
 class StaticStorageBase;
 
-typedef JValue (EntryPointFromInterpreter)(Thread* self, ShadowFrame* shadow_frame);
+typedef void (EntryPointFromInterpreter)(Thread* self, ShadowFrame* shadow_frame, JValue* result);
 
 // C++ mirror of java.lang.reflect.Method and java.lang.reflect.Constructor
 class MANAGED AbstractMethod : public Object {
diff --git a/src/oat/runtime/support_interpreter.cc b/src/oat/runtime/support_interpreter.cc
index d10a468..a5d6fa3 100644
--- a/src/oat/runtime/support_interpreter.cc
+++ b/src/oat/runtime/support_interpreter.cc
@@ -110,7 +110,7 @@
   return result.GetJ();
 }
 
-JValue artInterpreterToQuickEntry(Thread* self, ShadowFrame* shadow_frame)
+void artInterpreterToQuickEntry(Thread* self, ShadowFrame* shadow_frame, JValue* result)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   mirror::AbstractMethod* method = shadow_frame->GetMethod();
   MethodHelper mh(method);
@@ -119,10 +119,7 @@
   uint16_t arg_offset = (code_item == NULL) ? 0 : code_item->registers_size_ - code_item->ins_size_;
   ArgArray arg_array(mh.GetShorty(), mh.GetShortyLength());
   arg_array.BuildArgArray(shadow_frame, arg_offset);
-  JValue result;
-  method->Invoke(self, arg_array.GetArray(), arg_array.GetNumBytes(), &result, mh.GetShorty()[0]);
-
-  return result;
+  method->Invoke(self, arg_array.GetArray(), arg_array.GetNumBytes(), result, mh.GetShorty()[0]);
 }
 
 }  // namespace art