< prev index next >

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

Print this page




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

  29 #include "gc/shared/genCollectedHeap.hpp"
  30 #include "oops/instanceRefKlass.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 bool ConcurrentMarkSweepThread::_should_terminate           = false;
  45 int  ConcurrentMarkSweepThread::_CMS_flag                   = CMS_nil;
  46 
  47 volatile jint ConcurrentMarkSweepThread::_pending_yields    = 0;
  48 


 107     while (!is_init_completed() && !Universe::is_fully_initialized() &&
 108            !_should_terminate) {
 109       CGC_lock->wait(true, 200);
 110       loopX.tick();
 111     }
 112     // Wait until the surrogate locker thread that will do
 113     // pending list locking on our behalf has been created.
 114     // We cannot start the SLT thread ourselves since we need
 115     // to be a JavaThread to do so.
 116     CMSLoopCountWarn loopY("CMS::run", "waiting for SLT installation", 2);
 117     while (_slt == NULL && !_should_terminate) {
 118       CGC_lock->wait(true, 200);
 119       loopY.tick();
 120     }
 121     clear_CMS_flag(CMS_cms_wants_token);
 122   }
 123 
 124   while (!_should_terminate) {
 125     sleepBeforeNextCycle();
 126     if (_should_terminate) break;

 127     GCCause::Cause cause = _collector->_full_gc_requested ?
 128       _collector->_full_gc_cause : GCCause::_cms_concurrent_mark;
 129     _collector->collect_in_background(cause);
 130   }
 131   assert(_should_terminate, "just checking");
 132   // Check that the state of any protocol for synchronization
 133   // between background (CMS) and foreground collector is "clean"
 134   // (i.e. will not potentially block the foreground collector,
 135   // requiring action by us).
 136   verify_ok_to_terminate();
 137   // Signal that it is terminated
 138   {
 139     MutexLockerEx mu(Terminator_lock,
 140                      Mutex::_no_safepoint_check_flag);
 141     assert(_cmst == this, "Weird!");
 142     _cmst = NULL;
 143     Terminator_lock->notify();
 144   }
 145 
 146   // Thread destructor usually does this..




   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 "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/instanceRefKlass.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 bool ConcurrentMarkSweepThread::_should_terminate           = false;
  46 int  ConcurrentMarkSweepThread::_CMS_flag                   = CMS_nil;
  47 
  48 volatile jint ConcurrentMarkSweepThread::_pending_yields    = 0;
  49 


 108     while (!is_init_completed() && !Universe::is_fully_initialized() &&
 109            !_should_terminate) {
 110       CGC_lock->wait(true, 200);
 111       loopX.tick();
 112     }
 113     // Wait until the surrogate locker thread that will do
 114     // pending list locking on our behalf has been created.
 115     // We cannot start the SLT thread ourselves since we need
 116     // to be a JavaThread to do so.
 117     CMSLoopCountWarn loopY("CMS::run", "waiting for SLT installation", 2);
 118     while (_slt == NULL && !_should_terminate) {
 119       CGC_lock->wait(true, 200);
 120       loopY.tick();
 121     }
 122     clear_CMS_flag(CMS_cms_wants_token);
 123   }
 124 
 125   while (!_should_terminate) {
 126     sleepBeforeNextCycle();
 127     if (_should_terminate) break;
 128     GCIdMark gc_id_mark;
 129     GCCause::Cause cause = _collector->_full_gc_requested ?
 130       _collector->_full_gc_cause : GCCause::_cms_concurrent_mark;
 131     _collector->collect_in_background(cause);
 132   }
 133   assert(_should_terminate, "just checking");
 134   // Check that the state of any protocol for synchronization
 135   // between background (CMS) and foreground collector is "clean"
 136   // (i.e. will not potentially block the foreground collector,
 137   // requiring action by us).
 138   verify_ok_to_terminate();
 139   // Signal that it is terminated
 140   {
 141     MutexLockerEx mu(Terminator_lock,
 142                      Mutex::_no_safepoint_check_flag);
 143     assert(_cmst == this, "Weird!");
 144     _cmst = NULL;
 145     Terminator_lock->notify();
 146   }
 147 
 148   // Thread destructor usually does this..


< prev index next >