< prev index next >

src/share/vm/gc/cms/concurrentMarkSweepThread.cpp

Print this page
rev 11747 : [mq]: per.hotspot.patch


  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 "classfile/systemDictionary.hpp"
  27 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp"
  28 #include "gc/cms/concurrentMarkSweepThread.hpp"
  29 #include "gc/shared/gcId.hpp"
  30 #include "gc/shared/genCollectedHeap.hpp"
  31 #include "gc/shared/referencePendingListLocker.hpp"
  32 #include "oops/oop.inline.hpp"
  33 #include "runtime/init.hpp"
  34 #include "runtime/interfaceSupport.hpp"
  35 #include "runtime/java.hpp"
  36 #include "runtime/javaCalls.hpp"
  37 #include "runtime/mutexLocker.hpp"
  38 #include "runtime/os.hpp"
  39 #include "runtime/vmThread.hpp"
  40 
  41 // ======= Concurrent Mark Sweep Thread ========
  42 
  43 ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::_cmst = NULL;
  44 CMSCollector* ConcurrentMarkSweepThread::_collector         = NULL;
  45 int  ConcurrentMarkSweepThread::_CMS_flag                   = CMS_nil;
  46 
  47 volatile jint ConcurrentMarkSweepThread::_pending_yields    = 0;
  48 
  49 ConcurrentMarkSweepThread::ConcurrentMarkSweepThread(CMSCollector* collector)
  50   : ConcurrentGCThread() {
  51   assert(UseConcMarkSweepGC,  "UseConcMarkSweepGC should be set");


  58 
  59   // An old comment here said: "Priority should be just less
  60   // than that of VMThread".  Since the VMThread runs at
  61   // NearMaxPriority, the old comment was inaccurate, but
  62   // changing the default priority to NearMaxPriority-1
  63   // could change current behavior, so the default of
  64   // NearMaxPriority stays in place.
  65   //
  66   // Note that there's a possibility of the VMThread
  67   // starving if UseCriticalCMSThreadPriority is on.
  68   // That won't happen on Solaris for various reasons,
  69   // but may well happen on non-Solaris platforms.
  70   create_and_start(UseCriticalCMSThreadPriority ? CriticalPriority : NearMaxPriority);
  71 }
  72 
  73 void ConcurrentMarkSweepThread::run_service() {
  74   assert(this == cmst(), "just checking");
  75 
  76   if (BindCMSThreadToCPU && !os::bind_to_processor(CPUForCMSThread)) {
  77     log_warning(gc)("Couldn't bind CMS thread to processor " UINTX_FORMAT, CPUForCMSThread);
  78   }
  79 
  80   {
  81     MutexLockerEx x(CGC_lock, true);
  82     set_CMS_flag(CMS_cms_wants_token);
  83     assert(is_init_completed() && Universe::is_fully_initialized(), "ConcurrentGCThread::run() should have waited for this.");
  84 
  85     // Wait until the surrogate locker thread that will do
  86     // pending list locking on our behalf has been created.
  87     // We cannot start the SLT thread ourselves since we need
  88     // to be a JavaThread to do so.
  89     CMSLoopCountWarn loopY("CMS::run", "waiting for SLT installation", 2);
  90     while (!ReferencePendingListLocker::is_initialized() && !should_terminate()) {
  91       CGC_lock->wait(true, 200);
  92       loopY.tick();
  93     }
  94     clear_CMS_flag(CMS_cms_wants_token);
  95   }
  96 
  97   while (!should_terminate()) {
  98     sleepBeforeNextCycle();
  99     if (should_terminate()) break;
 100     GCIdMark gc_id_mark;
 101     GCCause::Cause cause = _collector->_full_gc_requested ?
 102       _collector->_full_gc_cause : GCCause::_cms_concurrent_mark;
 103     _collector->collect_in_background(cause);
 104   }
 105 
 106   // Check that the state of any protocol for synchronization
 107   // between background (CMS) and foreground collector is "clean"
 108   // (i.e. will not potentially block the foreground collector,
 109   // requiring action by us).
 110   verify_ok_to_terminate();
 111 }
 112 
 113 #ifndef PRODUCT
 114 void ConcurrentMarkSweepThread::verify_ok_to_terminate() const {




  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 "classfile/systemDictionary.hpp"
  27 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp"
  28 #include "gc/cms/concurrentMarkSweepThread.hpp"
  29 #include "gc/shared/gcId.hpp"
  30 #include "gc/shared/genCollectedHeap.hpp"

  31 #include "oops/oop.inline.hpp"
  32 #include "runtime/init.hpp"
  33 #include "runtime/interfaceSupport.hpp"
  34 #include "runtime/java.hpp"
  35 #include "runtime/javaCalls.hpp"
  36 #include "runtime/mutexLocker.hpp"
  37 #include "runtime/os.hpp"
  38 #include "runtime/vmThread.hpp"
  39 
  40 // ======= Concurrent Mark Sweep Thread ========
  41 
  42 ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::_cmst = NULL;
  43 CMSCollector* ConcurrentMarkSweepThread::_collector         = NULL;
  44 int  ConcurrentMarkSweepThread::_CMS_flag                   = CMS_nil;
  45 
  46 volatile jint ConcurrentMarkSweepThread::_pending_yields    = 0;
  47 
  48 ConcurrentMarkSweepThread::ConcurrentMarkSweepThread(CMSCollector* collector)
  49   : ConcurrentGCThread() {
  50   assert(UseConcMarkSweepGC,  "UseConcMarkSweepGC should be set");


  57 
  58   // An old comment here said: "Priority should be just less
  59   // than that of VMThread".  Since the VMThread runs at
  60   // NearMaxPriority, the old comment was inaccurate, but
  61   // changing the default priority to NearMaxPriority-1
  62   // could change current behavior, so the default of
  63   // NearMaxPriority stays in place.
  64   //
  65   // Note that there's a possibility of the VMThread
  66   // starving if UseCriticalCMSThreadPriority is on.
  67   // That won't happen on Solaris for various reasons,
  68   // but may well happen on non-Solaris platforms.
  69   create_and_start(UseCriticalCMSThreadPriority ? CriticalPriority : NearMaxPriority);
  70 }
  71 
  72 void ConcurrentMarkSweepThread::run_service() {
  73   assert(this == cmst(), "just checking");
  74 
  75   if (BindCMSThreadToCPU && !os::bind_to_processor(CPUForCMSThread)) {
  76     log_warning(gc)("Couldn't bind CMS thread to processor " UINTX_FORMAT, CPUForCMSThread);

















  77   }
  78 
  79   while (!should_terminate()) {
  80     sleepBeforeNextCycle();
  81     if (should_terminate()) break;
  82     GCIdMark gc_id_mark;
  83     GCCause::Cause cause = _collector->_full_gc_requested ?
  84       _collector->_full_gc_cause : GCCause::_cms_concurrent_mark;
  85     _collector->collect_in_background(cause);
  86   }
  87 
  88   // Check that the state of any protocol for synchronization
  89   // between background (CMS) and foreground collector is "clean"
  90   // (i.e. will not potentially block the foreground collector,
  91   // requiring action by us).
  92   verify_ok_to_terminate();
  93 }
  94 
  95 #ifndef PRODUCT
  96 void ConcurrentMarkSweepThread::verify_ok_to_terminate() const {


< prev index next >