Call Jit::MaybeCompileMethod less frequently.

We have added more logic into the method (and may still add more).

Test: test.py -b --host --64 --jit
Change-Id: I8198db36b42a63c9e4ebf88651bea0e1ae70d5ae
diff --git a/runtime/jit/jit-inl.h b/runtime/jit/jit-inl.h
index 80324ad..e6b4095 100644
--- a/runtime/jit/jit-inl.h
+++ b/runtime/jit/jit-inl.h
@@ -46,14 +46,12 @@
   // NB: The method needs to see the transitions of the counter past the thresholds.
   uint32_t old_batch = RoundDown(old_count, kJitSamplesBatchSize);  // Clear lower bits.
   uint32_t new_batch = RoundDown(new_count, kJitSamplesBatchSize);  // Clear lower bits.
-  if (UNLIKELY(old_batch == 0)) {
-    // For low sample counts, we check every time (which is important for tests).
+  if (UNLIKELY(kSlowMode)) {  // Check every time in slow-debug mode.
     if (!MaybeCompileMethod(self, method, old_count, new_count, with_backedges)) {
       // Tests may check that the counter is 0 for methods that we never compile.
       return;  // Ignore the samples for now and retry later.
     }
   } else if (UNLIKELY(old_batch != new_batch)) {
-    // For high sample counts, we check only when we move past the batch boundary.
     if (!MaybeCompileMethod(self, method, old_batch, new_batch, with_backedges)) {
       // OSR compilation will ignore the samples if they don't have backedges.
       return;  // Ignore the samples for now and retry later.
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 6bdc8de..902d924 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -59,6 +59,8 @@
 static constexpr size_t kJitStressDefaultCompileThreshold     = 100;    // Fast-debug build.
 static constexpr size_t kJitSlowStressDefaultCompileThreshold = 2;      // Slow-debug build.
 
+DEFINE_RUNTIME_DEBUG_FLAG(Jit, kSlowMode);
+
 // JIT compiler
 void* Jit::jit_library_handle_ = nullptr;
 void* Jit::jit_compiler_handle_ = nullptr;
@@ -70,13 +72,8 @@
 bool (*Jit::jit_generate_debug_info_)(void*) = nullptr;
 void (*Jit::jit_update_options_)(void*) = nullptr;
 
-struct StressModeHelper {
-  DECLARE_RUNTIME_DEBUG_FLAG(kSlowMode);
-};
-DEFINE_RUNTIME_DEBUG_FLAG(StressModeHelper, kSlowMode);
-
 uint32_t JitOptions::RoundUpThreshold(uint32_t threshold) {
-  if (threshold > kJitSamplesBatchSize) {
+  if (!Jit::kSlowMode) {
     threshold = RoundUp(threshold, kJitSamplesBatchSize);
   }
   CHECK_LE(threshold, std::numeric_limits<uint16_t>::max());
@@ -103,7 +100,7 @@
   } else {
     jit_options->compile_threshold_ =
         kIsDebugBuild
-            ? (StressModeHelper::kSlowMode
+            ? (Jit::kSlowMode
                    ? kJitSlowStressDefaultCompileThreshold
                    : kJitStressDefaultCompileThreshold)
             : kJitDefaultCompileThreshold;
diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h
index 0147f37..1c7be7c 100644
--- a/runtime/jit/jit.h
+++ b/runtime/jit/jit.h
@@ -20,6 +20,7 @@
 #include "base/histogram-inl.h"
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/runtime_debug.h"
 #include "base/timing_logger.h"
 #include "handle.h"
 #include "jit/profile_saver_options.h"
@@ -54,7 +55,7 @@
 // At what priority to schedule jit threads. 9 is the lowest foreground priority on device.
 // See android/os/Process.java.
 static constexpr int kJitPoolThreadPthreadDefaultPriority = 9;
-static constexpr uint32_t kJitSamplesBatchSize = 32;  // Must be power of 2.
+static constexpr uint32_t kJitSamplesBatchSize = 1024;  // Must be power of 2.
 
 class JitOptions {
  public:
@@ -168,6 +169,8 @@
   // How frequently should the interpreter check to see if OSR compilation is ready.
   static constexpr int16_t kJitRecheckOSRThreshold = 101;  // Prime number to avoid patterns.
 
+  DECLARE_RUNTIME_DEBUG_FLAG(kSlowMode);
+
   virtual ~Jit();
 
   // Create JIT itself.
diff --git a/test/638-checker-inline-cache-intrinsic/run b/test/638-checker-inline-cache-intrinsic/run
index 1540310..d5d03cd 100644
--- a/test/638-checker-inline-cache-intrinsic/run
+++ b/test/638-checker-inline-cache-intrinsic/run
@@ -14,6 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Set threshold to 100 to math the iterations done in the test.
+# Set threshold to 1000 to match the iterations done in the test.
 # Pass --verbose-methods to only generate the CFG of these methods.
-exec ${RUN} --jit --runtime-option -Xjitthreshold:100 -Xcompiler-option --verbose-methods=inlineMonomorphic,knownReceiverType,stringEquals $@
+exec ${RUN} --jit --runtime-option -Xjitthreshold:1000 -Xcompiler-option --verbose-methods=inlineMonomorphic,knownReceiverType,stringEquals $@
diff --git a/test/638-checker-inline-cache-intrinsic/src/Main.java b/test/638-checker-inline-cache-intrinsic/src/Main.java
index 4a9aba5..1449f0a 100644
--- a/test/638-checker-inline-cache-intrinsic/src/Main.java
+++ b/test/638-checker-inline-cache-intrinsic/src/Main.java
@@ -64,10 +64,10 @@
 
   public static void test() {
     // Warm up inline cache.
-    for (int i = 0; i < 45; i++) {
+    for (int i = 0; i < 450; i++) {
       $noinline$inlineMonomorphic(str);
     }
-    for (int i = 0; i < 60; i++) {
+    for (int i = 0; i < 600; i++) {
       $noinline$stringEquals(str);
     }
     ensureJitCompiled(Main.class, "$noinline$stringEquals");