title: Why do JNI active instances prevent GC?
body: <h1>bool PSScavenge::invoke_no_policy()</h1>
  
  <pre><code>  ...
    if (GCLocker::check_active_before_gc()) {
      return false;
    }
    ...
  </code></pre>
  
  <p>As you can see, if <code>GCLocker::check_active_before_gc()</code> is <code>true</code>, it doesn't invoke minor GC, which is <code>PSScavenge::invoke_no_policy()</code>. Why is it?</p>
  
  <h1>check_active_before_gc()</h1>
  
  <pre><code>bool GCLocker::check_active_before_gc() {
    assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
    if (is_active() &amp;&amp; !_needs_gc) {
      verify_critical_count();
      _needs_gc = true;
      log_debug_jni("Setting _needs_gc.");
    }
    return is_active();
  }
  </code></pre>
  
  <h1>is_active()</h1>
  
  <pre><code>  // Accessors
    static bool is_active() {
      assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
      return is_active_internal();
    }
  </code></pre>
  
  <h1>is_active_internal()</h1>
  
  <pre><code>  static bool is_active_internal() {
      verify_critical_count();
      return _jni_lock_count &gt; 0;
    }
  </code></pre>
  
  <h1>_jni_lock_count</h1>
  
  <pre><code>static volatile jint _jni_lock_count;  // number of jni active instances.
  </code></pre>
  
  <p>The <code>_jni_lock_count</code> keeps track of the number of threads that are
  currently in a critical region. </p>