1 /*
2 * Copyright (c) 1997, 2013, 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 #ifndef SHARE_VM_MEMORY_GCLOCKER_HPP
26 #define SHARE_VM_MEMORY_GCLOCKER_HPP
27
28 #include "gc_interface/collectedHeap.hpp"
29 #include "memory/genCollectedHeap.hpp"
30 #include "memory/universe.hpp"
31 #include "oops/oop.hpp"
32
33 // The direct lock/unlock calls do not force a collection if an unlock
34 // decrements the count to zero. Avoid calling these if at all possible.
35
36 class GC_locker: public AllStatic {
37 private:
38 // The _jni_lock_count keeps track of the number of threads that are
39 // currently in a critical region. It's only kept up to date when
40 // _needs_gc is true. The current value is computed during
41 // safepointing and decremented during the slow path of GC_locker
42 // unlocking.
43 static volatile jint _jni_lock_count; // number of jni active instances.
44 static volatile bool _needs_gc; // heap is filling, we need a GC
45 // note: bool is typedef'd as jint
46 static volatile bool _doing_gc; // unlock_critical() is doing a GC
47
48 #ifdef ASSERT
49 // This lock count is updated for all operations and is used to
309 class No_Alloc_Verifier : public StackObj {
310 private:
311 bool _activated;
312
313 public:
314 #ifdef ASSERT
315 No_Alloc_Verifier(bool activated = true) {
316 _activated = activated;
317 if (_activated) Thread::current()->_allow_allocation_count++;
318 }
319
320 ~No_Alloc_Verifier() {
321 if (_activated) Thread::current()->_allow_allocation_count--;
322 }
323 #else
324 No_Alloc_Verifier(bool activated = true) {}
325 ~No_Alloc_Verifier() {}
326 #endif
327 };
328
329 #endif // SHARE_VM_MEMORY_GCLOCKER_HPP
|
1 /*
2 * Copyright (c) 1997, 2015, 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 #ifndef SHARE_VM_GC_SHARED_GCLOCKER_HPP
26 #define SHARE_VM_GC_SHARED_GCLOCKER_HPP
27
28 #include "gc/shared/collectedHeap.hpp"
29 #include "gc/shared/genCollectedHeap.hpp"
30 #include "memory/universe.hpp"
31 #include "oops/oop.hpp"
32
33 // The direct lock/unlock calls do not force a collection if an unlock
34 // decrements the count to zero. Avoid calling these if at all possible.
35
36 class GC_locker: public AllStatic {
37 private:
38 // The _jni_lock_count keeps track of the number of threads that are
39 // currently in a critical region. It's only kept up to date when
40 // _needs_gc is true. The current value is computed during
41 // safepointing and decremented during the slow path of GC_locker
42 // unlocking.
43 static volatile jint _jni_lock_count; // number of jni active instances.
44 static volatile bool _needs_gc; // heap is filling, we need a GC
45 // note: bool is typedef'd as jint
46 static volatile bool _doing_gc; // unlock_critical() is doing a GC
47
48 #ifdef ASSERT
49 // This lock count is updated for all operations and is used to
309 class No_Alloc_Verifier : public StackObj {
310 private:
311 bool _activated;
312
313 public:
314 #ifdef ASSERT
315 No_Alloc_Verifier(bool activated = true) {
316 _activated = activated;
317 if (_activated) Thread::current()->_allow_allocation_count++;
318 }
319
320 ~No_Alloc_Verifier() {
321 if (_activated) Thread::current()->_allow_allocation_count--;
322 }
323 #else
324 No_Alloc_Verifier(bool activated = true) {}
325 ~No_Alloc_Verifier() {}
326 #endif
327 };
328
329 #endif // SHARE_VM_GC_SHARED_GCLOCKER_HPP
|