1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/shared/collectedHeap.hpp"
27 #include "gc/shared/gcLocker.inline.hpp"
28 #include "memory/resourceArea.hpp"
29 #include "logging/log.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/thread.inline.hpp"
32
33 volatile jint GCLocker::_jni_lock_count = 0;
34 volatile bool GCLocker::_needs_gc = false;
35 volatile bool GCLocker::_doing_gc = false;
36
37 #ifdef ASSERT
38 volatile jint GCLocker::_debug_jni_lock_count = 0;
39 #endif
40
41
42 #ifdef ASSERT
43 void GCLocker::verify_critical_count() {
44 if (SafepointSynchronize::is_at_safepoint()) {
45 assert(!needs_gc() || _debug_jni_lock_count == _jni_lock_count, "must agree");
46 int count = 0;
47 // Count the number of threads with critical operations in progress
48 for (JavaThread* thr = Threads::first(); thr; thr = thr->next()) {
49 if (thr->in_critical()) {
50 count++;
51 }
52 }
53 if (_jni_lock_count != count) {
54 log_error(gc, verify)("critical counts don't match: %d != %d", _jni_lock_count, count);
55 for (JavaThread* thr = Threads::first(); thr; thr = thr->next()) {
56 if (thr->in_critical()) {
57 log_error(gc, verify)(INTPTR_FORMAT " in_critical %d", p2i(thr), thr->in_critical());
58 }
59 }
60 }
61 assert(_jni_lock_count == count, "must be equal");
62 }
63 }
64
65 // In debug mode track the locking state at all times
66 void GCLocker::increment_debug_jni_lock_count() {
67 assert(_debug_jni_lock_count >= 0, "bad value");
68 Atomic::inc(&_debug_jni_lock_count);
69 }
70
71 void GCLocker::decrement_debug_jni_lock_count() {
72 assert(_debug_jni_lock_count > 0, "bad value");
73 Atomic::dec(&_debug_jni_lock_count);
74 }
75 #endif
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/shared/collectedHeap.hpp"
27 #include "gc/shared/gcLocker.inline.hpp"
28 #include "memory/resourceArea.hpp"
29 #include "logging/log.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/thread.inline.hpp"
32 #include "runtime/threadSMR.hpp"
33
34 volatile jint GCLocker::_jni_lock_count = 0;
35 volatile bool GCLocker::_needs_gc = false;
36 volatile bool GCLocker::_doing_gc = false;
37
38 #ifdef ASSERT
39 volatile jint GCLocker::_debug_jni_lock_count = 0;
40 #endif
41
42
43 #ifdef ASSERT
44 void GCLocker::verify_critical_count() {
45 if (SafepointSynchronize::is_at_safepoint()) {
46 assert(!needs_gc() || _debug_jni_lock_count == _jni_lock_count, "must agree");
47 int count = 0;
48 // Count the number of threads with critical operations in progress
49 JavaThreadIteratorWithHandle jtiwh;
50 for (; JavaThread *thr = jtiwh.next(); ) {
51 if (thr->in_critical()) {
52 count++;
53 }
54 }
55 if (_jni_lock_count != count) {
56 log_error(gc, verify)("critical counts don't match: %d != %d", _jni_lock_count, count);
57 jtiwh.rewind();
58 for (; JavaThread *thr = jtiwh.next(); ) {
59 if (thr->in_critical()) {
60 log_error(gc, verify)(INTPTR_FORMAT " in_critical %d", p2i(thr), thr->in_critical());
61 }
62 }
63 }
64 assert(_jni_lock_count == count, "must be equal");
65 }
66 }
67
68 // In debug mode track the locking state at all times
69 void GCLocker::increment_debug_jni_lock_count() {
70 assert(_debug_jni_lock_count >= 0, "bad value");
71 Atomic::inc(&_debug_jni_lock_count);
72 }
73
74 void GCLocker::decrement_debug_jni_lock_count() {
75 assert(_debug_jni_lock_count > 0, "bad value");
76 Atomic::dec(&_debug_jni_lock_count);
77 }
78 #endif
|