ART: Add more deopt tests

Extend libarttest with the ability to turn off asserts for method
state. Use this to put asserts into test functions, but turn them
off if the test wouldn't react as we want, e.g., when we're in
interpreter mode.

Extend run-test 449 by adding asserts for the method state for the
expected deopt cases. This tests both standard behavior, as well
as single-frame deoptimization.

Bug: 21611912
Change-Id: I27fa5e3e44d8c5eab57962d144c6aec96587bf45
diff --git a/test/088-monitor-verification/smali/NotStructuredOverUnlock.smali b/test/088-monitor-verification/smali/NotStructuredOverUnlock.smali
index aa0c2d5..0dc492f 100644
--- a/test/088-monitor-verification/smali/NotStructuredOverUnlock.smali
+++ b/test/088-monitor-verification/smali/NotStructuredOverUnlock.smali
@@ -5,7 +5,7 @@
 .method public static run(Ljava/lang/Object;)V
    .registers 3
 
-   invoke-static {}, LMain;->assertCallerIsInterpreted()V
+   invoke-static {}, LMain;->assertIsInterpreted()V
 
    # Lock twice, but unlock thrice.
 
diff --git a/test/088-monitor-verification/smali/NotStructuredUnderUnlock.smali b/test/088-monitor-verification/smali/NotStructuredUnderUnlock.smali
index 2c31fda..df6e168 100644
--- a/test/088-monitor-verification/smali/NotStructuredUnderUnlock.smali
+++ b/test/088-monitor-verification/smali/NotStructuredUnderUnlock.smali
@@ -5,7 +5,7 @@
 .method public static run(Ljava/lang/Object;)V
    .registers 3
 
-   invoke-static {}, LMain;->assertCallerIsInterpreted()V
+   invoke-static {}, LMain;->assertIsInterpreted()V
 
    # Lock thrice, but only unlock twice.
 
diff --git a/test/088-monitor-verification/smali/OK.smali b/test/088-monitor-verification/smali/OK.smali
index 596798d..a43ecb0 100644
--- a/test/088-monitor-verification/smali/OK.smali
+++ b/test/088-monitor-verification/smali/OK.smali
@@ -20,7 +20,7 @@
 .method public static runNoMonitors(Ljava/lang/Object;Ljava/lang/Object;)V
    .registers 3
 
-   invoke-static {}, LMain;->assertCallerIsManaged()V
+   invoke-static {}, LMain;->assertIsManaged()V
 
    return-void
 
@@ -29,7 +29,7 @@
 .method public static runStraightLine(Ljava/lang/Object;Ljava/lang/Object;)V
    .registers 3
 
-   invoke-static {}, LMain;->assertCallerIsManaged()V
+   invoke-static {}, LMain;->assertIsManaged()V
 
    monitor-enter v1      # 1
    monitor-enter v2      # 2
@@ -44,7 +44,7 @@
 .method public static runBalancedJoin(Ljava/lang/Object;Ljava/lang/Object;)V
    .registers 3
 
-   invoke-static {}, LMain;->assertCallerIsManaged()V
+   invoke-static {}, LMain;->assertIsManaged()V
 
    monitor-enter v1      # 1
 
diff --git a/test/088-monitor-verification/smali/TooDeep.smali b/test/088-monitor-verification/smali/TooDeep.smali
index 1a8f2f0..a1e3281 100644
--- a/test/088-monitor-verification/smali/TooDeep.smali
+++ b/test/088-monitor-verification/smali/TooDeep.smali
@@ -7,7 +7,7 @@
 
    # Lock depth is 33, which is more than the verifier supports. This should have been punted to
    # the interpreter.
-   invoke-static {}, LMain;->assertCallerIsInterpreted()V
+   invoke-static {}, LMain;->assertIsInterpreted()V
 
    monitor-enter v2        #  1
    monitor-enter v2        #  2
diff --git a/test/088-monitor-verification/smali/UnbalancedJoin.smali b/test/088-monitor-verification/smali/UnbalancedJoin.smali
index da8f773..993f32c 100644
--- a/test/088-monitor-verification/smali/UnbalancedJoin.smali
+++ b/test/088-monitor-verification/smali/UnbalancedJoin.smali
@@ -5,7 +5,7 @@
 .method public static run(Ljava/lang/Object;Ljava/lang/Object;)V
    .registers 3
 
-   invoke-static {}, LMain;->assertCallerIsInterpreted()V
+   invoke-static {}, LMain;->assertIsInterpreted()V
 
    if-eqz v2, :Lnull
 
diff --git a/test/088-monitor-verification/smali/UnbalancedStraight.smali b/test/088-monitor-verification/smali/UnbalancedStraight.smali
index 68edb6c..cbb8bcc 100644
--- a/test/088-monitor-verification/smali/UnbalancedStraight.smali
+++ b/test/088-monitor-verification/smali/UnbalancedStraight.smali
@@ -5,7 +5,7 @@
 .method public static run(Ljava/lang/Object;Ljava/lang/Object;)V
    .registers 3
 
-   invoke-static {}, LMain;->assertCallerIsInterpreted()V
+   invoke-static {}, LMain;->assertIsInterpreted()V
 
    monitor-enter v1      # 1
    monitor-enter v2      # 2
diff --git a/test/088-monitor-verification/src/Main.java b/test/088-monitor-verification/src/Main.java
index fc5755b..2188055 100644
--- a/test/088-monitor-verification/src/Main.java
+++ b/test/088-monitor-verification/src/Main.java
@@ -220,7 +220,7 @@
 
     // Smali testing code.
     private static void runSmaliTests() {
-        if (!hasOatFile() || runtimeIsSoftFail() || isCallerInterpreted()) {
+        if (!hasOatFile() || runtimeIsSoftFail() || isInterpreted()) {
             // Skip test, this seems to be a non-compiled code test configuration.
             return;
         }
@@ -277,9 +277,9 @@
     }
 
     // Helpers for the smali code.
-    public static native void assertCallerIsInterpreted();
-    public static native void assertCallerIsManaged();
+    public static native void assertIsInterpreted();
+    public static native void assertIsManaged();
     public static native boolean hasOatFile();
     public static native boolean runtimeIsSoftFail();
-    public static native boolean isCallerInterpreted();
+    public static native boolean isInterpreted();
 }
diff --git a/test/449-checker-bce/expected.txt b/test/449-checker-bce/expected.txt
index e114c50..4665d7a 100644
--- a/test/449-checker-bce/expected.txt
+++ b/test/449-checker-bce/expected.txt
@@ -1 +1,2 @@
+JNI_OnLoad called
 java.lang.ArrayIndexOutOfBoundsException: length=5; index=82
diff --git a/test/449-checker-bce/src/Main.java b/test/449-checker-bce/src/Main.java
index f06c250..22829cd 100644
--- a/test/449-checker-bce/src/Main.java
+++ b/test/449-checker-bce/src/Main.java
@@ -265,6 +265,7 @@
 
   // A helper into which the actual throwing function should be inlined.
   static void constantIndexingForward6(int[] array) {
+    assertIsManaged();
     constantIndexing6(array);
   }
 
@@ -618,13 +619,17 @@
 
   static int foo() {
     try {
+      assertIsManaged();
       // This will cause AIOOBE.
       constantIndexing2(new int[3]);
     } catch (ArrayIndexOutOfBoundsException e) {
+      assertIsManaged();  // This is to ensure that single-frame deoptimization works.
+                                // Will need to be updated if constantIndexing2 is inlined.
       try {
         // This will cause AIOOBE.
         constantIndexingForward6(new int[3]);
       } catch (ArrayIndexOutOfBoundsException e2) {
+        assertIsManaged();
         return 99;
       }
     }
@@ -634,13 +639,13 @@
 
   int sum;
 
-  /// CHECK-START: void Main.foo1(int[], int, int) BCE (before)
+  /// CHECK-START: void Main.foo1(int[], int, int, boolean) BCE (before)
   /// CHECK: BoundsCheck
   /// CHECK: ArraySet
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArrayGet
 
-  /// CHECK-START: void Main.foo1(int[], int, int) BCE (after)
+  /// CHECK-START: void Main.foo1(int[], int, int, boolean) BCE (after)
   /// CHECK: Phi
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArraySet
@@ -657,25 +662,30 @@
   /// CHECK: Phi
   /// CHECK: Goto
 
-  void foo1(int[] array, int start, int end) {
+  void foo1(int[] array, int start, int end, boolean expectInterpreter) {
     // Three HDeoptimize will be added. One for
     // start >= 0, one for end <= array.length,
     // and one for null check on array (to hoist null
     // check and array.length out of loop).
     for (int i = start ; i < end; i++) {
+      if (expectInterpreter) {
+        assertIsInterpreted();
+      } else {
+        assertIsManaged();
+      }
       array[i] = 1;
       sum += array[i];
     }
   }
 
 
-  /// CHECK-START: void Main.foo2(int[], int, int) BCE (before)
+  /// CHECK-START: void Main.foo2(int[], int, int, boolean) BCE (before)
   /// CHECK: BoundsCheck
   /// CHECK: ArraySet
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArrayGet
 
-  /// CHECK-START: void Main.foo2(int[], int, int) BCE (after)
+  /// CHECK-START: void Main.foo2(int[], int, int, boolean) BCE (after)
   /// CHECK: Phi
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArraySet
@@ -692,25 +702,30 @@
   /// CHECK: Phi
   /// CHECK: Goto
 
-  void foo2(int[] array, int start, int end) {
+  void foo2(int[] array, int start, int end, boolean expectInterpreter) {
     // Three HDeoptimize will be added. One for
     // start >= 0, one for end <= array.length,
     // and one for null check on array (to hoist null
     // check and array.length out of loop).
     for (int i = start ; i <= end; i++) {
+      if (expectInterpreter) {
+        assertIsInterpreted();
+      } else {
+        assertIsManaged();
+      }
       array[i] = 1;
       sum += array[i];
     }
   }
 
 
-  /// CHECK-START: void Main.foo3(int[], int) BCE (before)
+  /// CHECK-START: void Main.foo3(int[], int, boolean) BCE (before)
   /// CHECK: BoundsCheck
   /// CHECK: ArraySet
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArrayGet
 
-  /// CHECK-START: void Main.foo3(int[], int) BCE (after)
+  /// CHECK-START: void Main.foo3(int[], int, boolean) BCE (after)
   /// CHECK: Phi
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArraySet
@@ -726,24 +741,29 @@
   /// CHECK: Phi
   /// CHECK: Goto
 
-  void foo3(int[] array, int end) {
+  void foo3(int[] array, int end, boolean expectInterpreter) {
     // Two HDeoptimize will be added. One for end < array.length,
     // and one for null check on array (to hoist null check
     // and array.length out of loop).
     for (int i = 3 ; i <= end; i++) {
+      if (expectInterpreter) {
+        assertIsInterpreted();
+      } else {
+        assertIsManaged();
+      }
       array[i] = 1;
       sum += array[i];
     }
   }
 
 
-  /// CHECK-START: void Main.foo4(int[], int) BCE (before)
+  /// CHECK-START: void Main.foo4(int[], int, boolean) BCE (before)
   /// CHECK: BoundsCheck
   /// CHECK: ArraySet
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArrayGet
 
-  /// CHECK-START: void Main.foo4(int[], int) BCE (after)
+  /// CHECK-START: void Main.foo4(int[], int, boolean) BCE (after)
   /// CHECK: Phi
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArraySet
@@ -759,18 +779,23 @@
   /// CHECK: Phi
   /// CHECK: Goto
 
-  void foo4(int[] array, int end) {
+  void foo4(int[] array, int end, boolean expectInterpreter) {
     // Two HDeoptimize will be added. One for end <= array.length,
     // and one for null check on array (to hoist null check
     // and array.length out of loop).
     for (int i = end ; i > 0; i--) {
+      if (expectInterpreter) {
+        assertIsInterpreted();
+      } else {
+        assertIsManaged();
+      }
       array[i - 1] = 1;
       sum += array[i - 1];
     }
   }
 
 
-  /// CHECK-START: void Main.foo5(int[], int) BCE (before)
+  /// CHECK-START: void Main.foo5(int[], int, boolean) BCE (before)
   /// CHECK: BoundsCheck
   /// CHECK: ArraySet
   /// CHECK: BoundsCheck
@@ -780,7 +805,7 @@
   /// CHECK: BoundsCheck
   /// CHECK: ArrayGet
 
-  /// CHECK-START: void Main.foo5(int[], int) BCE (after)
+  /// CHECK-START: void Main.foo5(int[], int, boolean) BCE (after)
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArraySet
   /// CHECK: Phi
@@ -800,7 +825,7 @@
   /// CHECK-NOT: Phi
   /// CHECK: Goto
 
-  void foo5(int[] array, int end) {
+  void foo5(int[] array, int end, boolean expectInterpreter) {
     // Bounds check in this loop can be eliminated without deoptimization.
     for (int i = array.length - 1 ; i >= 0; i--) {
       array[i] = 1;
@@ -808,6 +833,11 @@
     // One HDeoptimize will be added.
     // It's for (end - 2 <= array.length - 2).
     for (int i = end - 2 ; i > 0; i--) {
+      if (expectInterpreter) {
+        assertIsInterpreted();
+      } else {
+        assertIsManaged();
+      }
       sum += array[i - 1];
       sum += array[i];
       sum += array[i + 1];
@@ -815,7 +845,7 @@
   }
 
 
-  /// CHECK-START: void Main.foo6(int[], int, int) BCE (before)
+  /// CHECK-START: void Main.foo6(int[], int, int, boolean) BCE (before)
   /// CHECK: BoundsCheck
   /// CHECK: ArrayGet
   /// CHECK: BoundsCheck
@@ -829,7 +859,7 @@
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArraySet
 
-  /// CHECK-START: void Main.foo6(int[], int, int) BCE (after)
+  /// CHECK-START: void Main.foo6(int[], int, int, boolean) BCE (after)
   /// CHECK: Phi
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArrayGet
@@ -855,12 +885,17 @@
   /// CHECK: Goto
   /// CHECK-NOT: Deoptimize
 
-  void foo6(int[] array, int start, int end) {
+  void foo6(int[] array, int start, int end, boolean expectInterpreter) {
     // Three HDeoptimize will be added. One for
     // start >= 2, one for end <= array.length - 3,
     // and one for null check on array (to hoist null
     // check and array.length out of loop).
     for (int i = end; i >= start; i--) {
+      if (expectInterpreter) {
+        assertIsInterpreted();
+      } else {
+        assertIsManaged();
+      }
       array[i] = (array[i-2] + array[i-1] + array[i] + array[i+1] + array[i+2]) / 5;
     }
   }
@@ -948,12 +983,12 @@
   }
 
 
-  /// CHECK-START: void Main.foo9(int[]) BCE (before)
+  /// CHECK-START: void Main.foo9(int[], boolean) BCE (before)
   /// CHECK: NullCheck
   /// CHECK: BoundsCheck
   /// CHECK: ArrayGet
 
-  /// CHECK-START: void Main.foo9(int[]) BCE (after)
+  /// CHECK-START: void Main.foo9(int[], boolean) BCE (after)
   //  The loop is guaranteed to be entered. No need to transform the
   //  loop for loop body entry test.
   /// CHECK: Deoptimize
@@ -964,10 +999,15 @@
   /// CHECK-NOT: BoundsCheck
   /// CHECK: ArrayGet
 
-  void foo9(int[] array) {
+  void foo9(int[] array, boolean expectInterpreter) {
     // Two HDeoptimize will be added. One for
     // 10 <= array.length, and one for null check on array.
     for (int i = 0 ; i < 10; i++) {
+      if (expectInterpreter) {
+        assertIsInterpreted();
+      } else {
+        assertIsManaged();
+      }
       sum += array[i];
     }
   }
@@ -999,7 +1039,7 @@
   static void testUnknownBounds() {
     boolean caught = false;
     Main main = new Main();
-    main.foo1(new int[10], 0, 10);
+    main.foo1(new int[10], 0, 10, false);
     if (main.sum != 10) {
       System.out.println("foo1 failed!");
     }
@@ -1007,7 +1047,7 @@
     caught = false;
     main = new Main();
     try {
-      main.foo1(new int[10], 0, 11);
+      main.foo1(new int[10], 0, 11, true);
     } catch (ArrayIndexOutOfBoundsException e) {
       caught = true;
     }
@@ -1016,7 +1056,7 @@
     }
 
     main = new Main();
-    main.foo2(new int[10], 0, 9);
+    main.foo2(new int[10], 0, 9, false);
     if (main.sum != 10) {
       System.out.println("foo2 failed!");
     }
@@ -1024,7 +1064,7 @@
     caught = false;
     main = new Main();
     try {
-      main.foo2(new int[10], 0, 10);
+      main.foo2(new int[10], 0, 10, true);
     } catch (ArrayIndexOutOfBoundsException e) {
       caught = true;
     }
@@ -1033,7 +1073,7 @@
     }
 
     main = new Main();
-    main.foo3(new int[10], 9);
+    main.foo3(new int[10], 9, false);
     if (main.sum != 7) {
       System.out.println("foo3 failed!");
     }
@@ -1041,7 +1081,7 @@
     caught = false;
     main = new Main();
     try {
-      main.foo3(new int[10], 10);
+      main.foo3(new int[10], 10, true);
     } catch (ArrayIndexOutOfBoundsException e) {
       caught = true;
     }
@@ -1050,7 +1090,7 @@
     }
 
     main = new Main();
-    main.foo4(new int[10], 10);
+    main.foo4(new int[10], 10, false);
     if (main.sum != 10) {
       System.out.println("foo4 failed!");
     }
@@ -1058,7 +1098,7 @@
     caught = false;
     main = new Main();
     try {
-      main.foo4(new int[10], 11);
+      main.foo4(new int[10], 11, true);
     } catch (ArrayIndexOutOfBoundsException e) {
       caught = true;
     }
@@ -1067,7 +1107,7 @@
     }
 
     main = new Main();
-    main.foo5(new int[10], 10);
+    main.foo5(new int[10], 10, false);
     if (main.sum != 24) {
       System.out.println("foo5 failed!");
     }
@@ -1075,7 +1115,7 @@
     caught = false;
     main = new Main();
     try {
-      main.foo5(new int[10], 11);
+      main.foo5(new int[10], 11, true);
     } catch (ArrayIndexOutOfBoundsException e) {
       caught = true;
     }
@@ -1084,11 +1124,11 @@
     }
 
     main = new Main();
-    main.foo6(new int[10], 2, 7);
+    main.foo6(new int[10], 2, 7, false);
 
     main = new Main();
     int[] array9 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
-    main.foo9(array9);
+    main.foo9(array9, false);
     if (main.sum != 45) {
       System.out.println("foo9 failed!");
     }
@@ -1104,7 +1144,7 @@
     caught = false;
     main = new Main();
     try {
-      main.foo6(new int[10], 2, 8);
+      main.foo6(new int[10], 2, 8, true);
     } catch (ArrayIndexOutOfBoundsException e) {
       caught = true;
     }
@@ -1115,7 +1155,7 @@
     caught = false;
     main = new Main();
     try {
-      main.foo6(new int[10], 1, 7);
+      main.foo6(new int[10], 1, 7, true);
     } catch (ArrayIndexOutOfBoundsException e) {
       caught = true;
     }
@@ -1152,6 +1192,15 @@
   /// CHECK: ParallelMove
 
   public static void main(String[] args) {
+    System.loadLibrary(args[0]);
+
+    if (!compiledWithOptimizing() ||
+        !hasOatFile() ||
+        runtimeIsSoftFail() ||
+        isInterpreted()) {
+      disableStackFrameAsserts();
+    }
+
     sieve(20);
 
     int[] array = {5, 2, 3, 7, 0, 1, 6, 4};
@@ -1190,4 +1239,11 @@
     new Main().testExceptionMessage();
   }
 
+  public static native boolean compiledWithOptimizing();
+  public static native void disableStackFrameAsserts();
+  public static native void assertIsManaged();
+  public static native void assertIsInterpreted();
+  public static native boolean hasOatFile();
+  public static native boolean runtimeIsSoftFail();
+  public static native boolean isInterpreted();
 }
diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc
index 042b03b..082c9b3 100644
--- a/test/common/runtime_state.cc
+++ b/test/common/runtime_state.cc
@@ -66,4 +66,54 @@
   return Runtime::Current()->IsImageDex2OatEnabled();
 }
 
+// public static native boolean compiledWithOptimizing();
+// Did we use the optimizing compiler to compile this?
+
+extern "C" JNIEXPORT jboolean JNICALL Java_Main_compiledWithOptimizing(JNIEnv* env, jclass cls) {
+  ScopedObjectAccess soa(env);
+
+  mirror::Class* klass = soa.Decode<mirror::Class*>(cls);
+  const DexFile& dex_file = klass->GetDexFile();
+  const OatFile::OatDexFile* oat_dex_file = dex_file.GetOatDexFile();
+  if (oat_dex_file == nullptr) {
+    // Could be JIT, which also uses optimizing, but conservatively say no.
+    return JNI_FALSE;
+  }
+  const OatFile* oat_file = oat_dex_file->GetOatFile();
+  CHECK(oat_file != nullptr);
+
+  const char* cmd_line = oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kDex2OatCmdLineKey);
+  CHECK(cmd_line != nullptr);  // Huh? This should not happen.
+
+  // Check the backend.
+  constexpr const char* kCompilerBackend = "--compiler-backend=";
+  const char* backend = strstr(cmd_line, kCompilerBackend);
+  if (backend != nullptr) {
+    // If it's set, make sure it's optimizing.
+    backend += strlen(kCompilerBackend);
+    if (strncmp(backend, "Optimizing", strlen("Optimizing")) != 0) {
+      return JNI_FALSE;
+    }
+  }
+
+  // Check the filter.
+  constexpr const char* kCompilerFilter = "--compiler-filter=";
+  const char* filter = strstr(cmd_line, kCompilerFilter);
+  if (filter != nullptr) {
+    // If it's set, make sure it's not interpret-only|verify-none|verify-at-runtime.
+    // Note: The space filter might have an impact on the test, but ignore that for now.
+    filter += strlen(kCompilerFilter);
+    constexpr const char* kInterpretOnly = "interpret-only";
+    constexpr const char* kVerifyNone = "verify-none";
+    constexpr const char* kVerifyAtRuntime = "verify-at-runtime";
+    if (strncmp(filter, kInterpretOnly, strlen(kInterpretOnly)) == 0 ||
+        strncmp(filter, kVerifyNone, strlen(kVerifyNone)) == 0 ||
+        strncmp(filter, kVerifyAtRuntime, strlen(kVerifyAtRuntime)) == 0) {
+      return JNI_FALSE;
+    }
+  }
+
+  return JNI_TRUE;
+}
+
 }  // namespace art
diff --git a/test/common/stack_inspect.cc b/test/common/stack_inspect.cc
index d22cf52..922eae6 100644
--- a/test/common/stack_inspect.cc
+++ b/test/common/stack_inspect.cc
@@ -27,9 +27,20 @@
 
 namespace art {
 
-// public static native boolean isCallerInterpreted();
+static bool asserts_enabled = true;
 
-extern "C" JNIEXPORT jboolean JNICALL Java_Main_isCallerInterpreted(JNIEnv* env, jclass) {
+// public static native void disableStackFrameAsserts();
+// Note: to globally disable asserts in unsupported configurations.
+
+extern "C" JNIEXPORT void JNICALL Java_Main_disableStackFrameAsserts(JNIEnv* env ATTRIBUTE_UNUSED,
+                                                                     jclass cls ATTRIBUTE_UNUSED) {
+  asserts_enabled = false;
+}
+
+
+// public static native boolean isInterpreted();
+
+extern "C" JNIEXPORT jboolean JNICALL Java_Main_isInterpreted(JNIEnv* env, jclass) {
   ScopedObjectAccess soa(env);
   NthCallerVisitor caller(soa.Self(), 1, false);
   caller.WalkStack();
@@ -37,16 +48,18 @@
   return caller.GetCurrentShadowFrame() != nullptr ? JNI_TRUE : JNI_FALSE;
 }
 
-// public static native void assertCallerIsInterpreted();
+// public static native void assertIsInterpreted();
 
-extern "C" JNIEXPORT void JNICALL Java_Main_assertCallerIsInterpreted(JNIEnv* env, jclass klass) {
-  CHECK(Java_Main_isCallerInterpreted(env, klass));
+extern "C" JNIEXPORT void JNICALL Java_Main_assertIsInterpreted(JNIEnv* env, jclass klass) {
+  if (asserts_enabled) {
+    CHECK(Java_Main_isInterpreted(env, klass));
+  }
 }
 
 
-// public static native boolean isCallerManaged();
+// public static native boolean isManaged();
 
-extern "C" JNIEXPORT jboolean JNICALL Java_Main_isCallerManaged(JNIEnv* env, jclass cls) {
+extern "C" JNIEXPORT jboolean JNICALL Java_Main_isManaged(JNIEnv* env, jclass cls) {
   ScopedObjectAccess soa(env);
 
   mirror::Class* klass = soa.Decode<mirror::Class*>(cls);
@@ -65,10 +78,12 @@
   return caller.GetCurrentShadowFrame() != nullptr ? JNI_FALSE : JNI_TRUE;
 }
 
-// public static native void assertCallerIsManaged();
+// public static native void assertIsManaged();
 
-extern "C" JNIEXPORT void JNICALL Java_Main_assertCallerIsManaged(JNIEnv* env, jclass cls) {
-  CHECK(Java_Main_isCallerManaged(env, cls));
+extern "C" JNIEXPORT void JNICALL Java_Main_assertIsManaged(JNIEnv* env, jclass cls) {
+  if (asserts_enabled) {
+    CHECK(Java_Main_isManaged(env, cls));
+  }
 }
 
 }  // namespace art