/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "memory/gcLocker.inline.hpp"
#include "memory/resourceArea.hpp"
#include "memory/sharedHeap.hpp"
#ifdef ASSERT
#endif
#ifdef ASSERT
if (SafepointSynchronize::is_at_safepoint()) {
int count = 0;
// Count the number of threads with critical operations in progress
if (thr->in_critical()) {
count++;
}
}
if (_jni_lock_count != count) {
if (thr->in_critical()) {
}
}
}
}
}
#endif
_needs_gc = true;
if (PrintJNIGCStalls && PrintGCDetails) {
}
}
return is_active();
}
if (needs_gc()) {
if (PrintJNIGCStalls && PrintGCDetails) {
gclog_or_tty->print_cr("%.3f: Allocation failed. Thread \"%s\" is stalled by JNI critical section, %d locked.",
}
}
// Wait for _needs_gc to be cleared
while (needs_gc()) {
JNICritical_lock->wait();
}
}
// Block entering threads if we know at least one thread is in a
// JNI critical region and we need a GC.
// We check that at least one thread is in a critical region before
// blocking because blocked threads are woken up by a thread exiting
// a JNI critical region.
JNICritical_lock->wait();
}
thread->enter_critical();
}
thread->exit_critical();
if (needs_gc() && !is_jni_active()) {
// We're the last thread out. Cause a GC to occur.
// GC will also check is_active, so this check is not
// strictly needed. It's added here to make it clear that
// the GC will NOT be performed if any other caller
// of GC_locker::lock() still needs GC locked.
if (!is_active()) {
_doing_gc = true;
{
// Must give up the lock while at a safepoint
if (PrintJNIGCStalls && PrintGCDetails) {
gclog_or_tty->print_cr("%.3f: Thread \"%s\" is performing GC after exiting critical section, %d locked",
}
}
_doing_gc = false;
}
_needs_gc = false;
}
}
// Implementation of No_GC_Verifier
#ifdef ASSERT
if (_verifygc) {
_old_invocations = h->total_collections();
}
}
No_GC_Verifier::~No_GC_Verifier() {
if (_verifygc) {
if (_old_invocations != h->total_collections()) {
fatal("collection in a No_GC_Verifier secured function");
}
}
}
// if we were verifying, then make sure that nothing is
// wrong before we "pause" verification
fatal("collection in a No_GC_Verifier secured function");
}
}
}
// if we were verifying before, then reenable verification
}
}
// JRT_LEAF rules:
// A JRT_LEAF method may not interfere with safepointing by
// 1) acquiring or blocking on a Mutex or JavaLock - checked
// 2) allocating heap memory - checked
// 3) executing a VM operation - checked
// 4) executing a system call (including malloc) that could block or grab a lock
// 5) invoking GC
// 6) reaching a safepoint
// 7) running too long
// Nor may any method it calls.
{
}
{
}
case _thread_in_Java:
// is in a leaf routine, there must be no safepoint.
return true;
case _thread_in_native:
// A native thread is not subject to safepoints.
// Even while it is in a leaf routine, GC is ok
return false;
default:
// Leaf routines cannot be called from other contexts.
return false;
}
}
#endif