src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "classfile/systemDictionary.hpp"
aoqi@0 27 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.inline.hpp"
aoqi@0 28 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
aoqi@0 29 #include "memory/genCollectedHeap.hpp"
aoqi@0 30 #include "oops/instanceRefKlass.hpp"
aoqi@0 31 #include "oops/oop.inline.hpp"
aoqi@0 32 #include "runtime/init.hpp"
aoqi@0 33 #include "runtime/interfaceSupport.hpp"
aoqi@0 34 #include "runtime/java.hpp"
aoqi@0 35 #include "runtime/javaCalls.hpp"
aoqi@0 36 #include "runtime/mutexLocker.hpp"
aoqi@0 37 #include "runtime/os.hpp"
aoqi@0 38 #include "runtime/vmThread.hpp"
aoqi@0 39
aoqi@0 40 // ======= Concurrent Mark Sweep Thread ========
aoqi@0 41
aoqi@0 42 // The CMS thread is created when Concurrent Mark Sweep is used in the
aoqi@0 43 // older of two generations in a generational memory system.
aoqi@0 44
aoqi@0 45 ConcurrentMarkSweepThread*
aoqi@0 46 ConcurrentMarkSweepThread::_cmst = NULL;
aoqi@0 47 CMSCollector* ConcurrentMarkSweepThread::_collector = NULL;
aoqi@0 48 bool ConcurrentMarkSweepThread::_should_terminate = false;
aoqi@0 49 int ConcurrentMarkSweepThread::_CMS_flag = CMS_nil;
aoqi@0 50
aoqi@0 51 volatile jint ConcurrentMarkSweepThread::_pending_yields = 0;
aoqi@0 52 volatile jint ConcurrentMarkSweepThread::_pending_decrements = 0;
aoqi@0 53
aoqi@0 54 volatile jint ConcurrentMarkSweepThread::_icms_disabled = 0;
aoqi@0 55 volatile bool ConcurrentMarkSweepThread::_should_run = false;
aoqi@0 56 // When icms is enabled, the icms thread is stopped until explicitly
aoqi@0 57 // started.
aoqi@0 58 volatile bool ConcurrentMarkSweepThread::_should_stop = true;
aoqi@0 59
aoqi@0 60 SurrogateLockerThread*
aoqi@0 61 ConcurrentMarkSweepThread::_slt = NULL;
aoqi@0 62 SurrogateLockerThread::SLT_msg_type
aoqi@0 63 ConcurrentMarkSweepThread::_sltBuffer = SurrogateLockerThread::empty;
aoqi@0 64 Monitor*
aoqi@0 65 ConcurrentMarkSweepThread::_sltMonitor = NULL;
aoqi@0 66
aoqi@0 67 ConcurrentMarkSweepThread::ConcurrentMarkSweepThread(CMSCollector* collector)
aoqi@0 68 : ConcurrentGCThread() {
aoqi@0 69 assert(UseConcMarkSweepGC, "UseConcMarkSweepGC should be set");
aoqi@0 70 assert(_cmst == NULL, "CMS thread already created");
aoqi@0 71 _cmst = this;
aoqi@0 72 assert(_collector == NULL, "Collector already set");
aoqi@0 73 _collector = collector;
aoqi@0 74
aoqi@0 75 set_name("Concurrent Mark-Sweep GC Thread");
aoqi@0 76
aoqi@0 77 if (os::create_thread(this, os::cgc_thread)) {
aoqi@0 78 // An old comment here said: "Priority should be just less
aoqi@0 79 // than that of VMThread". Since the VMThread runs at
aoqi@0 80 // NearMaxPriority, the old comment was inaccurate, but
aoqi@0 81 // changing the default priority to NearMaxPriority-1
aoqi@0 82 // could change current behavior, so the default of
aoqi@0 83 // NearMaxPriority stays in place.
aoqi@0 84 //
aoqi@0 85 // Note that there's a possibility of the VMThread
aoqi@0 86 // starving if UseCriticalCMSThreadPriority is on.
aoqi@0 87 // That won't happen on Solaris for various reasons,
aoqi@0 88 // but may well happen on non-Solaris platforms.
aoqi@0 89 int native_prio;
aoqi@0 90 if (UseCriticalCMSThreadPriority) {
aoqi@0 91 native_prio = os::java_to_os_priority[CriticalPriority];
aoqi@0 92 } else {
aoqi@0 93 native_prio = os::java_to_os_priority[NearMaxPriority];
aoqi@0 94 }
aoqi@0 95 os::set_native_priority(this, native_prio);
aoqi@0 96
aoqi@0 97 if (!DisableStartThread) {
aoqi@0 98 os::start_thread(this);
aoqi@0 99 }
aoqi@0 100 }
aoqi@0 101 _sltMonitor = SLT_lock;
aoqi@0 102 assert(!CMSIncrementalMode || icms_is_enabled(), "Error");
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 void ConcurrentMarkSweepThread::run() {
aoqi@0 106 assert(this == cmst(), "just checking");
aoqi@0 107
aoqi@0 108 this->record_stack_base_and_size();
aoqi@0 109 this->initialize_thread_local_storage();
aoqi@0 110 this->set_active_handles(JNIHandleBlock::allocate_block());
aoqi@0 111 // From this time Thread::current() should be working.
aoqi@0 112 assert(this == Thread::current(), "just checking");
aoqi@0 113 if (BindCMSThreadToCPU && !os::bind_to_processor(CPUForCMSThread)) {
aoqi@0 114 warning("Couldn't bind CMS thread to processor " UINTX_FORMAT, CPUForCMSThread);
aoqi@0 115 }
aoqi@0 116 // Wait until Universe::is_fully_initialized()
aoqi@0 117 {
aoqi@0 118 CMSLoopCountWarn loopX("CMS::run", "waiting for "
aoqi@0 119 "Universe::is_fully_initialized()", 2);
aoqi@0 120 MutexLockerEx x(CGC_lock, true);
aoqi@0 121 set_CMS_flag(CMS_cms_wants_token);
aoqi@0 122 // Wait until Universe is initialized and all initialization is completed.
aoqi@0 123 while (!is_init_completed() && !Universe::is_fully_initialized() &&
aoqi@0 124 !_should_terminate) {
aoqi@0 125 CGC_lock->wait(true, 200);
aoqi@0 126 loopX.tick();
aoqi@0 127 }
aoqi@0 128 // Wait until the surrogate locker thread that will do
aoqi@0 129 // pending list locking on our behalf has been created.
aoqi@0 130 // We cannot start the SLT thread ourselves since we need
aoqi@0 131 // to be a JavaThread to do so.
aoqi@0 132 CMSLoopCountWarn loopY("CMS::run", "waiting for SLT installation", 2);
aoqi@0 133 while (_slt == NULL && !_should_terminate) {
aoqi@0 134 CGC_lock->wait(true, 200);
aoqi@0 135 loopY.tick();
aoqi@0 136 }
aoqi@0 137 clear_CMS_flag(CMS_cms_wants_token);
aoqi@0 138 }
aoqi@0 139
aoqi@0 140 while (!_should_terminate) {
aoqi@0 141 sleepBeforeNextCycle();
aoqi@0 142 if (_should_terminate) break;
aoqi@0 143 GCCause::Cause cause = _collector->_full_gc_requested ?
aoqi@0 144 _collector->_full_gc_cause : GCCause::_cms_concurrent_mark;
aoqi@0 145 _collector->collect_in_background(false, cause);
aoqi@0 146 }
aoqi@0 147 assert(_should_terminate, "just checking");
aoqi@0 148 // Check that the state of any protocol for synchronization
aoqi@0 149 // between background (CMS) and foreground collector is "clean"
aoqi@0 150 // (i.e. will not potentially block the foreground collector,
aoqi@0 151 // requiring action by us).
aoqi@0 152 verify_ok_to_terminate();
aoqi@0 153 // Signal that it is terminated
aoqi@0 154 {
aoqi@0 155 MutexLockerEx mu(Terminator_lock,
aoqi@0 156 Mutex::_no_safepoint_check_flag);
aoqi@0 157 assert(_cmst == this, "Weird!");
aoqi@0 158 _cmst = NULL;
aoqi@0 159 Terminator_lock->notify();
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 // Thread destructor usually does this..
aoqi@0 163 ThreadLocalStorage::set_thread(NULL);
aoqi@0 164 }
aoqi@0 165
aoqi@0 166 #ifndef PRODUCT
aoqi@0 167 void ConcurrentMarkSweepThread::verify_ok_to_terminate() const {
aoqi@0 168 assert(!(CGC_lock->owned_by_self() || cms_thread_has_cms_token() ||
aoqi@0 169 cms_thread_wants_cms_token()),
aoqi@0 170 "Must renounce all worldly possessions and desires for nirvana");
aoqi@0 171 _collector->verify_ok_to_terminate();
aoqi@0 172 }
aoqi@0 173 #endif
aoqi@0 174
aoqi@0 175 // create and start a new ConcurrentMarkSweep Thread for given CMS generation
aoqi@0 176 ConcurrentMarkSweepThread* ConcurrentMarkSweepThread::start(CMSCollector* collector) {
aoqi@0 177 if (!_should_terminate) {
aoqi@0 178 assert(cmst() == NULL, "start() called twice?");
aoqi@0 179 ConcurrentMarkSweepThread* th = new ConcurrentMarkSweepThread(collector);
aoqi@0 180 assert(cmst() == th, "Where did the just-created CMS thread go?");
aoqi@0 181 return th;
aoqi@0 182 }
aoqi@0 183 return NULL;
aoqi@0 184 }
aoqi@0 185
aoqi@0 186 void ConcurrentMarkSweepThread::stop() {
aoqi@0 187 if (CMSIncrementalMode) {
aoqi@0 188 // Disable incremental mode and wake up the thread so it notices the change.
aoqi@0 189 disable_icms();
aoqi@0 190 start_icms();
aoqi@0 191 }
aoqi@0 192 // it is ok to take late safepoints here, if needed
aoqi@0 193 {
aoqi@0 194 MutexLockerEx x(Terminator_lock);
aoqi@0 195 _should_terminate = true;
aoqi@0 196 }
aoqi@0 197 { // Now post a notify on CGC_lock so as to nudge
aoqi@0 198 // CMS thread(s) that might be slumbering in
aoqi@0 199 // sleepBeforeNextCycle.
aoqi@0 200 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 201 CGC_lock->notify_all();
aoqi@0 202 }
aoqi@0 203 { // Now wait until (all) CMS thread(s) have exited
aoqi@0 204 MutexLockerEx x(Terminator_lock);
aoqi@0 205 while(cmst() != NULL) {
aoqi@0 206 Terminator_lock->wait();
aoqi@0 207 }
aoqi@0 208 }
aoqi@0 209 }
aoqi@0 210
aoqi@0 211 void ConcurrentMarkSweepThread::threads_do(ThreadClosure* tc) {
aoqi@0 212 assert(tc != NULL, "Null ThreadClosure");
aoqi@0 213 if (_cmst != NULL) {
aoqi@0 214 tc->do_thread(_cmst);
aoqi@0 215 }
aoqi@0 216 assert(Universe::is_fully_initialized(),
aoqi@0 217 "Called too early, make sure heap is fully initialized");
aoqi@0 218 if (_collector != NULL) {
aoqi@0 219 AbstractWorkGang* gang = _collector->conc_workers();
aoqi@0 220 if (gang != NULL) {
aoqi@0 221 gang->threads_do(tc);
aoqi@0 222 }
aoqi@0 223 }
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 void ConcurrentMarkSweepThread::print_on(outputStream* st) const {
aoqi@0 227 st->print("\"%s\" ", name());
aoqi@0 228 Thread::print_on(st);
aoqi@0 229 st->cr();
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 void ConcurrentMarkSweepThread::print_all_on(outputStream* st) {
aoqi@0 233 if (_cmst != NULL) {
aoqi@0 234 _cmst->print_on(st);
aoqi@0 235 st->cr();
aoqi@0 236 }
aoqi@0 237 if (_collector != NULL) {
aoqi@0 238 AbstractWorkGang* gang = _collector->conc_workers();
aoqi@0 239 if (gang != NULL) {
aoqi@0 240 gang->print_worker_threads_on(st);
aoqi@0 241 }
aoqi@0 242 }
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 void ConcurrentMarkSweepThread::synchronize(bool is_cms_thread) {
aoqi@0 246 assert(UseConcMarkSweepGC, "just checking");
aoqi@0 247
aoqi@0 248 MutexLockerEx x(CGC_lock,
aoqi@0 249 Mutex::_no_safepoint_check_flag);
aoqi@0 250 if (!is_cms_thread) {
aoqi@0 251 assert(Thread::current()->is_VM_thread(), "Not a VM thread");
aoqi@0 252 CMSSynchronousYieldRequest yr;
aoqi@0 253 while (CMS_flag_is_set(CMS_cms_has_token)) {
aoqi@0 254 // indicate that we want to get the token
aoqi@0 255 set_CMS_flag(CMS_vm_wants_token);
aoqi@0 256 CGC_lock->wait(true);
aoqi@0 257 }
aoqi@0 258 // claim the token and proceed
aoqi@0 259 clear_CMS_flag(CMS_vm_wants_token);
aoqi@0 260 set_CMS_flag(CMS_vm_has_token);
aoqi@0 261 } else {
aoqi@0 262 assert(Thread::current()->is_ConcurrentGC_thread(),
aoqi@0 263 "Not a CMS thread");
aoqi@0 264 // The following barrier assumes there's only one CMS thread.
aoqi@0 265 // This will need to be modified is there are more CMS threads than one.
aoqi@0 266 while (CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token)) {
aoqi@0 267 set_CMS_flag(CMS_cms_wants_token);
aoqi@0 268 CGC_lock->wait(true);
aoqi@0 269 }
aoqi@0 270 // claim the token
aoqi@0 271 clear_CMS_flag(CMS_cms_wants_token);
aoqi@0 272 set_CMS_flag(CMS_cms_has_token);
aoqi@0 273 }
aoqi@0 274 }
aoqi@0 275
aoqi@0 276 void ConcurrentMarkSweepThread::desynchronize(bool is_cms_thread) {
aoqi@0 277 assert(UseConcMarkSweepGC, "just checking");
aoqi@0 278
aoqi@0 279 MutexLockerEx x(CGC_lock,
aoqi@0 280 Mutex::_no_safepoint_check_flag);
aoqi@0 281 if (!is_cms_thread) {
aoqi@0 282 assert(Thread::current()->is_VM_thread(), "Not a VM thread");
aoqi@0 283 assert(CMS_flag_is_set(CMS_vm_has_token), "just checking");
aoqi@0 284 clear_CMS_flag(CMS_vm_has_token);
aoqi@0 285 if (CMS_flag_is_set(CMS_cms_wants_token)) {
aoqi@0 286 // wake-up a waiting CMS thread
aoqi@0 287 CGC_lock->notify();
aoqi@0 288 }
aoqi@0 289 assert(!CMS_flag_is_set(CMS_vm_has_token | CMS_vm_wants_token),
aoqi@0 290 "Should have been cleared");
aoqi@0 291 } else {
aoqi@0 292 assert(Thread::current()->is_ConcurrentGC_thread(),
aoqi@0 293 "Not a CMS thread");
aoqi@0 294 assert(CMS_flag_is_set(CMS_cms_has_token), "just checking");
aoqi@0 295 clear_CMS_flag(CMS_cms_has_token);
aoqi@0 296 if (CMS_flag_is_set(CMS_vm_wants_token)) {
aoqi@0 297 // wake-up a waiting VM thread
aoqi@0 298 CGC_lock->notify();
aoqi@0 299 }
aoqi@0 300 assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
aoqi@0 301 "Should have been cleared");
aoqi@0 302 }
aoqi@0 303 }
aoqi@0 304
aoqi@0 305 // Wait until any cms_lock event
aoqi@0 306 void ConcurrentMarkSweepThread::wait_on_cms_lock(long t_millis) {
aoqi@0 307 MutexLockerEx x(CGC_lock,
aoqi@0 308 Mutex::_no_safepoint_check_flag);
aoqi@0 309 if (_should_terminate || _collector->_full_gc_requested) {
aoqi@0 310 return;
aoqi@0 311 }
aoqi@0 312 set_CMS_flag(CMS_cms_wants_token); // to provoke notifies
aoqi@0 313 CGC_lock->wait(Mutex::_no_safepoint_check_flag, t_millis);
aoqi@0 314 clear_CMS_flag(CMS_cms_wants_token);
aoqi@0 315 assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
aoqi@0 316 "Should not be set");
aoqi@0 317 }
aoqi@0 318
aoqi@0 319 // Wait until the next synchronous GC, a concurrent full gc request,
aoqi@0 320 // or a timeout, whichever is earlier.
aoqi@0 321 void ConcurrentMarkSweepThread::wait_on_cms_lock_for_scavenge(long t_millis) {
aoqi@0 322 // Wait time in millis or 0 value representing infinite wait for a scavenge
aoqi@0 323 assert(t_millis >= 0, "Wait time for scavenge should be 0 or positive");
aoqi@0 324
aoqi@0 325 GenCollectedHeap* gch = GenCollectedHeap::heap();
aoqi@0 326 double start_time_secs = os::elapsedTime();
aoqi@0 327 double end_time_secs = start_time_secs + (t_millis / ((double) MILLIUNITS));
aoqi@0 328
aoqi@0 329 // Total collections count before waiting loop
aoqi@0 330 unsigned int before_count;
aoqi@0 331 {
aoqi@0 332 MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 333 before_count = gch->total_collections();
aoqi@0 334 }
aoqi@0 335
aoqi@0 336 unsigned int loop_count = 0;
aoqi@0 337
aoqi@0 338 while(!_should_terminate) {
aoqi@0 339 double now_time = os::elapsedTime();
aoqi@0 340 long wait_time_millis;
aoqi@0 341
aoqi@0 342 if(t_millis != 0) {
aoqi@0 343 // New wait limit
aoqi@0 344 wait_time_millis = (long) ((end_time_secs - now_time) * MILLIUNITS);
aoqi@0 345 if(wait_time_millis <= 0) {
aoqi@0 346 // Wait time is over
aoqi@0 347 break;
aoqi@0 348 }
aoqi@0 349 } else {
aoqi@0 350 // No wait limit, wait if necessary forever
aoqi@0 351 wait_time_millis = 0;
aoqi@0 352 }
aoqi@0 353
aoqi@0 354 // Wait until the next event or the remaining timeout
aoqi@0 355 {
aoqi@0 356 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 357
aoqi@0 358 if (_should_terminate || _collector->_full_gc_requested) {
aoqi@0 359 return;
aoqi@0 360 }
aoqi@0 361 set_CMS_flag(CMS_cms_wants_token); // to provoke notifies
aoqi@0 362 assert(t_millis == 0 || wait_time_millis > 0, "Sanity");
aoqi@0 363 CGC_lock->wait(Mutex::_no_safepoint_check_flag, wait_time_millis);
aoqi@0 364 clear_CMS_flag(CMS_cms_wants_token);
aoqi@0 365 assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
aoqi@0 366 "Should not be set");
aoqi@0 367 }
aoqi@0 368
aoqi@0 369 // Extra wait time check before entering the heap lock to get the collection count
aoqi@0 370 if(t_millis != 0 && os::elapsedTime() >= end_time_secs) {
aoqi@0 371 // Wait time is over
aoqi@0 372 break;
aoqi@0 373 }
aoqi@0 374
aoqi@0 375 // Total collections count after the event
aoqi@0 376 unsigned int after_count;
aoqi@0 377 {
aoqi@0 378 MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 379 after_count = gch->total_collections();
aoqi@0 380 }
aoqi@0 381
aoqi@0 382 if(before_count != after_count) {
aoqi@0 383 // There was a collection - success
aoqi@0 384 break;
aoqi@0 385 }
aoqi@0 386
aoqi@0 387 // Too many loops warning
aoqi@0 388 if(++loop_count == 0) {
aoqi@0 389 warning("wait_on_cms_lock_for_scavenge() has looped %u times", loop_count - 1);
aoqi@0 390 }
aoqi@0 391 }
aoqi@0 392 }
aoqi@0 393
aoqi@0 394 void ConcurrentMarkSweepThread::sleepBeforeNextCycle() {
aoqi@0 395 while (!_should_terminate) {
aoqi@0 396 if (CMSIncrementalMode) {
aoqi@0 397 icms_wait();
aoqi@0 398 if(CMSWaitDuration >= 0) {
aoqi@0 399 // Wait until the next synchronous GC, a concurrent full gc
aoqi@0 400 // request or a timeout, whichever is earlier.
aoqi@0 401 wait_on_cms_lock_for_scavenge(CMSWaitDuration);
aoqi@0 402 }
aoqi@0 403 return;
aoqi@0 404 } else {
aoqi@0 405 if(CMSWaitDuration >= 0) {
aoqi@0 406 // Wait until the next synchronous GC, a concurrent full gc
aoqi@0 407 // request or a timeout, whichever is earlier.
aoqi@0 408 wait_on_cms_lock_for_scavenge(CMSWaitDuration);
aoqi@0 409 } else {
aoqi@0 410 // Wait until any cms_lock event or check interval not to call shouldConcurrentCollect permanently
aoqi@0 411 wait_on_cms_lock(CMSCheckInterval);
aoqi@0 412 }
aoqi@0 413 }
aoqi@0 414 // Check if we should start a CMS collection cycle
aoqi@0 415 if (_collector->shouldConcurrentCollect()) {
aoqi@0 416 return;
aoqi@0 417 }
aoqi@0 418 // .. collection criterion not yet met, let's go back
aoqi@0 419 // and wait some more
aoqi@0 420 }
aoqi@0 421 }
aoqi@0 422
aoqi@0 423 // Incremental CMS
aoqi@0 424 void ConcurrentMarkSweepThread::start_icms() {
aoqi@0 425 assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
aoqi@0 426 MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 427 trace_state("start_icms");
aoqi@0 428 _should_run = true;
aoqi@0 429 iCMS_lock->notify_all();
aoqi@0 430 }
aoqi@0 431
aoqi@0 432 void ConcurrentMarkSweepThread::stop_icms() {
aoqi@0 433 assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
aoqi@0 434 MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 435 if (!_should_stop) {
aoqi@0 436 trace_state("stop_icms");
aoqi@0 437 _should_stop = true;
aoqi@0 438 _should_run = false;
aoqi@0 439 asynchronous_yield_request();
aoqi@0 440 iCMS_lock->notify_all();
aoqi@0 441 }
aoqi@0 442 }
aoqi@0 443
aoqi@0 444 void ConcurrentMarkSweepThread::icms_wait() {
aoqi@0 445 assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
aoqi@0 446 if (_should_stop && icms_is_enabled()) {
aoqi@0 447 MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 448 trace_state("pause_icms");
aoqi@0 449 _collector->stats().stop_cms_timer();
aoqi@0 450 while(!_should_run && icms_is_enabled()) {
aoqi@0 451 iCMS_lock->wait(Mutex::_no_safepoint_check_flag);
aoqi@0 452 }
aoqi@0 453 _collector->stats().start_cms_timer();
aoqi@0 454 _should_stop = false;
aoqi@0 455 trace_state("pause_icms end");
aoqi@0 456 }
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 // Note: this method, although exported by the ConcurrentMarkSweepThread,
aoqi@0 460 // which is a non-JavaThread, can only be called by a JavaThread.
aoqi@0 461 // Currently this is done at vm creation time (post-vm-init) by the
aoqi@0 462 // main/Primordial (Java)Thread.
aoqi@0 463 // XXX Consider changing this in the future to allow the CMS thread
aoqi@0 464 // itself to create this thread?
aoqi@0 465 void ConcurrentMarkSweepThread::makeSurrogateLockerThread(TRAPS) {
aoqi@0 466 assert(UseConcMarkSweepGC, "SLT thread needed only for CMS GC");
aoqi@0 467 assert(_slt == NULL, "SLT already created");
aoqi@0 468 _slt = SurrogateLockerThread::make(THREAD);
aoqi@0 469 }

mercurial