1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)gcLocker.cpp 1.52 07/05/17 15:54:45 JVM"
3 #endif
4 /*
5 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
26 */
27
28 # include "incls/_precompiled.incl"
29 # include "incls/_gcLocker.cpp.incl"
30
31 volatile jint GC_locker::_jni_lock_count = 0;
32 volatile jint GC_locker::_lock_count = 0;
33 volatile bool GC_locker::_needs_gc = false;
34 volatile bool GC_locker::_doing_gc = false;
35
36 void GC_locker::stall_until_clear() {
37 assert(!JavaThread::current()->in_critical(), "Would deadlock");
38 MutexLocker ml(JNICritical_lock);
39 // Wait for _needs_gc to be cleared
40 while (GC_locker::needs_gc()) {
41 JNICritical_lock->wait();
42 }
43 }
44
45 void GC_locker::jni_lock_slow() {
46 MutexLocker mu(JNICritical_lock);
47 // Block entering threads if we know at least one thread is in a
48 // JNI critical region and we need a GC.
49 // We check that at least one thread is in a critical region before
50 // blocking because blocked threads are woken up by a thread exiting
51 // a JNI critical region.
52 while ((is_jni_active() && needs_gc()) || _doing_gc) {
53 JNICritical_lock->wait();
54 }
55 jni_lock();
56 }
57
|
1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)gcLocker.cpp 1.52 07/05/17 15:54:45 JVM"
3 #endif
4 /*
5 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
26 */
27
28 # include "incls/_precompiled.incl"
29 # include "incls/_gcLocker.cpp.incl"
30
31 volatile jint GC_locker::_jni_lock_count = 0;
32 volatile jint GC_locker::_lock_count = 0;
33 volatile bool GC_locker::_needs_gc = false;
34 volatile bool GC_locker::_doing_gc = false;
35
36 void GC_locker::stall_until_clear() {
37 assert(!JavaThread::current()->in_critical(), "Would deadlock");
38 if (PrintJNIGCStalls && PrintGCDetails) {
39 ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
40 gclog_or_tty->print_cr(
41 "Allocation failed. Thread \"%s\" is stalled by JNI critical section.",
42 JavaThread::current()->name());
43 }
44 MutexLocker ml(JNICritical_lock);
45 // Wait for _needs_gc to be cleared
46 while (GC_locker::needs_gc()) {
47 JNICritical_lock->wait();
48 }
49 }
50
51 void GC_locker::jni_lock_slow() {
52 MutexLocker mu(JNICritical_lock);
53 // Block entering threads if we know at least one thread is in a
54 // JNI critical region and we need a GC.
55 // We check that at least one thread is in a critical region before
56 // blocking because blocked threads are woken up by a thread exiting
57 // a JNI critical region.
58 while ((is_jni_active() && needs_gc()) || _doing_gc) {
59 JNICritical_lock->wait();
60 }
61 jni_lock();
62 }
63
|