Fix test failures with -Xjitthreshold:0.

Namely
  - 667-jit-jni-stub:
    fix GenericJNI to respect -Xjitthreshold:0,
  - 1935-get-set-current-frame-jit:
    check for OSR, not for being interpreted.
However, some failures remain when --gcstress is added.

Test: testrunner.py --host --jit --runtime-option=-Xjitthreshold:0
Test: testrunner.py --host
Bug: 62611253
Change-Id: I4ca880f6a8b64a1659a27a107fae9933d4174f8d
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index e9a0808..c37e9ea 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -2246,10 +2246,6 @@
   ArtMethod* called = *sp;
   DCHECK(called->IsNative()) << called->PrettyMethod(true);
   Runtime* runtime = Runtime::Current();
-  jit::Jit* jit = runtime->GetJit();
-  if (jit != nullptr) {
-    jit->AddSamples(self, called, 1u, /*with_backedges*/ false);
-  }
   uint32_t shorty_len = 0;
   const char* shorty = called->GetShorty(&shorty_len);
   bool critical_native = called->IsCriticalNative();
@@ -2275,6 +2271,12 @@
 
   self->VerifyStack();
 
+  // We can now walk the stack if needed by JIT GC from MethodEntered() for JIT-on-first-use.
+  jit::Jit* jit = runtime->GetJit();
+  if (jit != nullptr) {
+    jit->MethodEntered(self, called);
+  }
+
   uint32_t cookie;
   uint32_t* sp32;
   // Skip calling JniMethodStart for @CriticalNative.
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 23cf071..813430f 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -718,10 +718,11 @@
   Runtime* runtime = Runtime::Current();
   if (UNLIKELY(runtime->UseJitCompilation() && runtime->GetJit()->JitAtFirstUse())) {
     ArtMethod* np_method = method->GetInterfaceMethodIfProxy(kRuntimePointerSize);
-    DCHECK(!np_method->IsNative());
     if (np_method->IsCompilable()) {
-      // The compiler requires a ProfilingInfo object.
-      ProfilingInfo::Create(thread, np_method, /* retry_allocation */ true);
+      if (!np_method->IsNative()) {
+        // The compiler requires a ProfilingInfo object for non-native methods.
+        ProfilingInfo::Create(thread, np_method, /* retry_allocation */ true);
+      }
       JitCompileTask compile_task(method, JitCompileTask::kCompile);
       compile_task.Run(thread);
     }
diff --git a/test/1935-get-set-current-frame-jit/expected.txt b/test/1935-get-set-current-frame-jit/expected.txt
index fed993c..cdb8f6a 100644
--- a/test/1935-get-set-current-frame-jit/expected.txt
+++ b/test/1935-get-set-current-frame-jit/expected.txt
@@ -1,7 +1,7 @@
 JNI_OnLoad called
 From GetLocalInt(), value is 42
-isInterpreted? true
+isInOsrCode? false
 	Value is '42'
 Setting TARGET to 1337
-isInterpreted? true
+isInOsrCode? false
 	Value is '1337'
diff --git a/test/1935-get-set-current-frame-jit/src/Main.java b/test/1935-get-set-current-frame-jit/src/Main.java
index eb0a637..714a98a 100644
--- a/test/1935-get-set-current-frame-jit/src/Main.java
+++ b/test/1935-get-set-current-frame-jit/src/Main.java
@@ -64,9 +64,9 @@
         Main.ensureJitCompiled(IntRunner.class, "run");
         i++;
       }
-      // We shouldn't be doing OSR since we are using JVMTI and the get/set local will push us to
-      // interpreter.
-      System.out.println("isInterpreted? " + Main.isInterpreted());
+      // We shouldn't be doing OSR since we are using JVMTI and the get/set prevents OSR.
+      // Set local will also push us to interpreter but the get local may remain in compiled code.
+      System.out.println("isInOsrCode? " + (hasJit() && Main.isInOsrCode("run")));
       reportValue(TARGET);
     }
     public void waitForBusyLoopStart() { while (!inBusyLoop) {} }
@@ -159,4 +159,6 @@
 
   public static native void ensureJitCompiled(Class k, String f);
   public static native boolean isInterpreted();
+  public static native boolean isInOsrCode(String methodName);
+  public static native boolean hasJit();
 }