...
if (GCLocker::check_active_before_gc()) {
return false;
}
...
As you can see, if GCLocker::check_active_before_gc()
is true
, it doesn't invoke minor GC, which is PSScavenge::invoke_no_policy()
. Why is it?
bool GCLocker::check_active_before_gc() {
assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
if (is_active() && !_needs_gc) {
verify_critical_count();
_needs_gc = true;
log_debug_jni("Setting _needs_gc.");
}
return is_active();
}
// Accessors
static bool is_active() {
assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
return is_active_internal();
}
static bool is_active_internal() {
verify_critical_count();
return _jni_lock_count > 0;
}
static volatile jint _jni_lock_count; // number of jni active instances.
The _jni_lock_count
keeps track of the number of threads that are
currently in a critical region.
_jni_lock_count
keeps track of the number of threads that are currently in a critical region.
As suggested by JNI specification, JNI critical functions temporarily disable garbage collection.
After calling GetPrimitiveArrayCritical, the native code should not run for an extended period of time before it calls ReleasePrimitiveArrayCritical. We must treat the code inside this pair of functions as running in a "critical region." Inside a critical region, native code must not call other JNI functions, or any system call that may cause the current thread to block and wait for another Java thread. (For example, the current thread must not call read on a stream being written by another Java thread.)
These restrictions make it more likely that the native code will obtain an uncopied version of the array, even if the VM does not support pinning. For example, a VM may temporarily disable garbage collection when the native code is holding a pointer to an array obtained via GetPrimitiveArrayCritical.