< prev index next >
src/share/vm/gc/shared/gcLocker.cpp
Print this page
@@ -24,10 +24,11 @@
#include "precompiled.hpp"
#include "gc/shared/collectedHeap.hpp"
#include "gc/shared/gcLocker.inline.hpp"
#include "memory/resourceArea.hpp"
+#include "logging/log.hpp"
#include "runtime/atomic.inline.hpp"
#include "runtime/thread.inline.hpp"
volatile jint GC_locker::_jni_lock_count = 0;
volatile bool GC_locker::_needs_gc = false;
@@ -71,35 +72,34 @@
assert(_debug_jni_lock_count > 0, "bad value");
Atomic::dec(&_debug_jni_lock_count);
}
#endif
+void GC_locker::log_debug_jni(const char* msg) {
+ LogHandle(gc, jni) log;
+ if (log.is_debug()) {
+ ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
+ log.debug("%s Thread \"%s\" %d locked.", msg, Thread::current()->name(), _jni_lock_count);
+ }
+}
+
bool GC_locker::check_active_before_gc() {
assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
if (is_active() && !_needs_gc) {
verify_critical_count();
_needs_gc = true;
- if (PrintJNIGCStalls && PrintGCDetails) {
- ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
- gclog_or_tty->print_cr("%.3f: Setting _needs_gc. Thread \"%s\" %d locked.",
- gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count);
- }
-
+ log_debug_jni("Setting _needs_gc.");
}
return is_active();
}
void GC_locker::stall_until_clear() {
assert(!JavaThread::current()->in_critical(), "Would deadlock");
MutexLocker ml(JNICritical_lock);
if (needs_gc()) {
- if (PrintJNIGCStalls && PrintGCDetails) {
- ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
- gclog_or_tty->print_cr("%.3f: Allocation failed. Thread \"%s\" is stalled by JNI critical section, %d locked.",
- gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count);
- }
+ log_debug_jni("Allocation failed. Thread stalled by JNI critical section.");
}
// Wait for _needs_gc to be cleared
while (needs_gc()) {
JNICritical_lock->wait();
@@ -132,15 +132,11 @@
// We're the last thread out. Cause a GC to occur.
_doing_gc = true;
{
// Must give up the lock while at a safepoint
MutexUnlocker munlock(JNICritical_lock);
- if (PrintJNIGCStalls && PrintGCDetails) {
- ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
- gclog_or_tty->print_cr("%.3f: Thread \"%s\" is performing GC after exiting critical section, %d locked",
- gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count);
- }
+ log_debug_jni("Performing GC after exiting critical section.");
Universe::heap()->collect(GCCause::_gc_locker);
}
_doing_gc = false;
_needs_gc = false;
JNICritical_lock->notify_all();
< prev index next >