Fix method profiling [issue 4260697]

In the new interpreter control mechanism, method tracing invoke
events are generated at the call site, whereas debug entry events
happen prior to the interpretation of the first instruction of a
method.  Because we were failing to check for active profiling
on entry to a new interpreter instance, we would miss the profile
event for the first method interpreted.  We subsequently (and correctly)
recorded the return event, and ended up with a mismatch causing traceview
to complain and die.

Change-Id: Ibd93dfcd16c2f1fc62f6a86626a902eaf5d4b160
diff --git a/vm/mterp/Mterp.c b/vm/mterp/Mterp.c
index 4bcf822..fa9b037 100644
--- a/vm/mterp/Mterp.c
+++ b/vm/mterp/Mterp.c
@@ -89,6 +89,14 @@
     //      self->interpSave.fp);
     //LOGI("first instruction is 0x%04x\n", self->interpSave.pc[0]);
 
+    /*
+     * Handle any ongoing profiling and prep for debugging
+     */
+    if (self->interpBreak.ctl.subMode != 0) {
+        TRACE_METHOD_ENTER(self, self->interpSave.method);
+        self->debugIsMethodEntry = true;   // Always true on startup
+    }
+
     dvmMterpStdRun(self);
 
 #ifdef LOG_INSTR
diff --git a/vm/mterp/out/InterpC-portable.c b/vm/mterp/out/InterpC-portable.c
index 967cae5..425885e 100644
--- a/vm/mterp/out/InterpC-portable.c
+++ b/vm/mterp/out/InterpC-portable.c
@@ -1270,6 +1270,13 @@
         pc - curMethod->insns, fp);
 
     /*
+     * Handle any ongoing profiling and prep for debugging.
+     */
+    if (self->interpBreak.ctl.subMode != 0) {
+        TRACE_METHOD_ENTER(self, curMethod);
+        self->debugIsMethodEntry = true;   // Always true on startup
+    }
+    /*
      * DEBUG: scramble this to ensure we're not relying on it.
      */
     methodToCall = (const Method*) -1;
diff --git a/vm/mterp/portable/entry.c b/vm/mterp/portable/entry.c
index fa1b4a8..485fa82 100644
--- a/vm/mterp/portable/entry.c
+++ b/vm/mterp/portable/entry.c
@@ -44,6 +44,13 @@
         pc - curMethod->insns, fp);
 
     /*
+     * Handle any ongoing profiling and prep for debugging.
+     */
+    if (self->interpBreak.ctl.subMode != 0) {
+        TRACE_METHOD_ENTER(self, curMethod);
+        self->debugIsMethodEntry = true;   // Always true on startup
+    }
+    /*
      * DEBUG: scramble this to ensure we're not relying on it.
      */
     methodToCall = (const Method*) -1;