src/share/vm/memory/gcLocker.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2009, 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 // The direct lock/unlock calls do not force a collection if an unlock
  26 // decrements the count to zero. Avoid calling these if at all possible.
  27 
  28 class GC_locker: public AllStatic {
  29  private:
  30   static volatile jint _jni_lock_count;  // number of jni active instances
  31   static volatile jint _lock_count;      // number of other active instances
  32   static volatile bool _needs_gc;        // heap is filling, we need a GC
  33                                          // note: bool is typedef'd as jint
  34   static volatile bool _doing_gc;        // unlock_critical() is doing a GC
  35 
  36   // Accessors
  37   static bool is_jni_active() {
  38     return _jni_lock_count > 0;
  39   }
  40 
  41   static void set_needs_gc() {
  42     assert(SafepointSynchronize::is_at_safepoint(),
  43       "needs_gc is only set at a safepoint");
  44     _needs_gc = true;


 293 
 294 class No_Alloc_Verifier : public StackObj {
 295  private:
 296   bool  _activated;
 297 
 298  public:
 299 #ifdef ASSERT
 300   No_Alloc_Verifier(bool activated = true) {
 301     _activated = activated;
 302     if (_activated) Thread::current()->_allow_allocation_count++;
 303   }
 304 
 305   ~No_Alloc_Verifier() {
 306     if (_activated) Thread::current()->_allow_allocation_count--;
 307   }
 308 #else
 309   No_Alloc_Verifier(bool activated = true) {}
 310   ~No_Alloc_Verifier() {}
 311 #endif
 312 };


   1 /*
   2  * Copyright (c) 1997, 2010, 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 #ifdef TARGET_OS_FAMILY_linux
  33 # include "os_linux.inline.hpp"
  34 # include "thread_linux.inline.hpp"
  35 #endif
  36 #ifdef TARGET_OS_FAMILY_solaris
  37 # include "os_solaris.inline.hpp"
  38 # include "thread_solaris.inline.hpp"
  39 #endif
  40 #ifdef TARGET_OS_FAMILY_windows
  41 # include "os_windows.inline.hpp"
  42 # include "thread_windows.inline.hpp"
  43 #endif
  44 
  45 // The direct lock/unlock calls do not force a collection if an unlock
  46 // decrements the count to zero. Avoid calling these if at all possible.
  47 
  48 class GC_locker: public AllStatic {
  49  private:
  50   static volatile jint _jni_lock_count;  // number of jni active instances
  51   static volatile jint _lock_count;      // number of other active instances
  52   static volatile bool _needs_gc;        // heap is filling, we need a GC
  53                                          // note: bool is typedef'd as jint
  54   static volatile bool _doing_gc;        // unlock_critical() is doing a GC
  55 
  56   // Accessors
  57   static bool is_jni_active() {
  58     return _jni_lock_count > 0;
  59   }
  60 
  61   static void set_needs_gc() {
  62     assert(SafepointSynchronize::is_at_safepoint(),
  63       "needs_gc is only set at a safepoint");
  64     _needs_gc = true;


 313 
 314 class No_Alloc_Verifier : public StackObj {
 315  private:
 316   bool  _activated;
 317 
 318  public:
 319 #ifdef ASSERT
 320   No_Alloc_Verifier(bool activated = true) {
 321     _activated = activated;
 322     if (_activated) Thread::current()->_allow_allocation_count++;
 323   }
 324 
 325   ~No_Alloc_Verifier() {
 326     if (_activated) Thread::current()->_allow_allocation_count--;
 327   }
 328 #else
 329   No_Alloc_Verifier(bool activated = true) {}
 330   ~No_Alloc_Verifier() {}
 331 #endif
 332 };
 333 
 334 #endif // SHARE_VM_MEMORY_GCLOCKER_HPP