Fix lock visiting for synchronized native methods.

The `GetGenericJniSynchronizationObject()` function was used
in the wrong context. As documented, it can be used only for
a method with a GenericJni frame and also on the top of the
stack. When visiting locks, we can have a non-GenericJni
method frame as well as a method deeper in the stack.
Replace the wrong use with specialized code.

Test: Added regression test to 178-app-image-native-methods
Test: testrunner.py --host --debug --ndebug
Bug: 172332525
Bug: 189235039
Change-Id: Ia26f0b980c04a766e31b1588a1c011bcf46c90d8
diff --git a/test/178-app-image-native-method/src/Main.java b/test/178-app-image-native-method/src/Main.java
index e6c76ff..294ad47 100644
--- a/test/178-app-image-native-method/src/Main.java
+++ b/test/178-app-image-native-method/src/Main.java
@@ -52,6 +52,7 @@
     $noinline$opt$testCriticalSignatures();
 
     $noinline$regressionTestB181736463();
+    $noinline$regressionTestB189235039();
 
     new CriticalClinitCheck();
     sTestCriticalClinitCheckOtherThread.join();
@@ -380,6 +381,10 @@
     }
   }
 
+  static void $noinline$regressionTestB189235039() {
+    assertEquals(42, new Main().b189235039CallThrough());
+  }
+
   static void initializingCriticalClinitCheck() {
     // Called from CriticalClinitCheck.<clinit>().
     // Test @CriticalNative calls on the initializing thread.
@@ -425,6 +430,9 @@
   }
 
   public static native void makeVisiblyInitialized();
+
+  public native synchronized int b189235039CallThrough();
+  public static native int b189235039CheckLocks(int placeholder, Main m);
 }
 
 class Test {