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

Thu, 13 Feb 2014 17:44:39 +0100

author
stefank
date
Thu, 13 Feb 2014 17:44:39 +0100
changeset 6971
7426d8d76305
parent 6904
0982ec23da03
child 7360
4e4ebe50c8e3
permissions
-rw-r--r--

8034761: Remove the do_code_roots parameter from process_strong_roots
Reviewed-by: tschatzl, mgerdin, jmasa

duke@435 1 /*
drchase@6680 2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.inline.hpp"
stefank@2314 27 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
stefank@2314 28 #include "gc_implementation/concurrentMarkSweep/vmCMSOperations.hpp"
sla@5237 29 #include "gc_implementation/shared/gcTimer.hpp"
sla@5237 30 #include "gc_implementation/shared/gcTraceTime.hpp"
stefank@2314 31 #include "gc_implementation/shared/isGCActiveMark.hpp"
stefank@2314 32 #include "memory/gcLocker.inline.hpp"
stefank@2314 33 #include "runtime/interfaceSupport.hpp"
sla@5237 34 #include "runtime/os.hpp"
stefank@2314 35 #include "utilities/dtrace.hpp"
dcubed@3202 36
drchase@6680 37 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
dcubed@3202 38
dcubed@3202 39 #ifndef USDT2
duke@435 40 HS_DTRACE_PROBE_DECL(hs_private, cms__initmark__begin);
duke@435 41 HS_DTRACE_PROBE_DECL(hs_private, cms__initmark__end);
duke@435 42
duke@435 43 HS_DTRACE_PROBE_DECL(hs_private, cms__remark__begin);
duke@435 44 HS_DTRACE_PROBE_DECL(hs_private, cms__remark__end);
dcubed@3202 45 #endif /* !USDT2 */
duke@435 46
duke@435 47 //////////////////////////////////////////////////////////
duke@435 48 // Methods in abstract class VM_CMS_Operation
duke@435 49 //////////////////////////////////////////////////////////
duke@435 50 void VM_CMS_Operation::acquire_pending_list_lock() {
duke@435 51 // The caller may block while communicating
duke@435 52 // with the SLT thread in order to acquire/release the PLL.
duke@435 53 ConcurrentMarkSweepThread::slt()->
duke@435 54 manipulatePLL(SurrogateLockerThread::acquirePLL);
duke@435 55 }
duke@435 56
duke@435 57 void VM_CMS_Operation::release_and_notify_pending_list_lock() {
duke@435 58 // The caller may block while communicating
duke@435 59 // with the SLT thread in order to acquire/release the PLL.
duke@435 60 ConcurrentMarkSweepThread::slt()->
duke@435 61 manipulatePLL(SurrogateLockerThread::releaseAndNotifyPLL);
duke@435 62 }
duke@435 63
duke@435 64 void VM_CMS_Operation::verify_before_gc() {
duke@435 65 if (VerifyBeforeGC &&
duke@435 66 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) {
brutisso@6904 67 GCTraceTime tm("Verify Before", false, false, _collector->_gc_timer_cm, _collector->_gc_tracer_cm->gc_id());
duke@435 68 HandleMark hm;
duke@435 69 FreelistLocker x(_collector);
duke@435 70 MutexLockerEx y(_collector->bitMapLock(), Mutex::_no_safepoint_check_flag);
duke@435 71 Universe::heap()->prepare_for_verify();
johnc@4176 72 Universe::verify();
duke@435 73 }
duke@435 74 }
duke@435 75
duke@435 76 void VM_CMS_Operation::verify_after_gc() {
duke@435 77 if (VerifyAfterGC &&
duke@435 78 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) {
brutisso@6904 79 GCTraceTime tm("Verify After", false, false, _collector->_gc_timer_cm, _collector->_gc_tracer_cm->gc_id());
duke@435 80 HandleMark hm;
duke@435 81 FreelistLocker x(_collector);
duke@435 82 MutexLockerEx y(_collector->bitMapLock(), Mutex::_no_safepoint_check_flag);
johnc@4176 83 Universe::verify();
duke@435 84 }
duke@435 85 }
duke@435 86
duke@435 87 bool VM_CMS_Operation::lost_race() const {
duke@435 88 if (CMSCollector::abstract_state() == CMSCollector::Idling) {
duke@435 89 // We lost a race to a foreground collection
duke@435 90 // -- there's nothing to do
duke@435 91 return true;
duke@435 92 }
duke@435 93 assert(CMSCollector::abstract_state() == legal_state(),
duke@435 94 "Inconsistent collector state?");
duke@435 95 return false;
duke@435 96 }
duke@435 97
duke@435 98 bool VM_CMS_Operation::doit_prologue() {
duke@435 99 assert(Thread::current()->is_ConcurrentGC_thread(), "just checking");
duke@435 100 assert(!CMSCollector::foregroundGCShouldWait(), "Possible deadlock");
duke@435 101 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(),
duke@435 102 "Possible deadlock");
duke@435 103
duke@435 104 if (needs_pll()) {
duke@435 105 acquire_pending_list_lock();
duke@435 106 }
duke@435 107 // Get the Heap_lock after the pending_list_lock.
duke@435 108 Heap_lock->lock();
duke@435 109 if (lost_race()) {
duke@435 110 assert(_prologue_succeeded == false, "Initialized in c'tor");
duke@435 111 Heap_lock->unlock();
duke@435 112 if (needs_pll()) {
duke@435 113 release_and_notify_pending_list_lock();
duke@435 114 }
duke@435 115 } else {
duke@435 116 _prologue_succeeded = true;
duke@435 117 }
duke@435 118 return _prologue_succeeded;
duke@435 119 }
duke@435 120
duke@435 121 void VM_CMS_Operation::doit_epilogue() {
duke@435 122 assert(Thread::current()->is_ConcurrentGC_thread(), "just checking");
duke@435 123 assert(!CMSCollector::foregroundGCShouldWait(), "Possible deadlock");
duke@435 124 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(),
duke@435 125 "Possible deadlock");
duke@435 126
duke@435 127 // Release the Heap_lock first.
duke@435 128 Heap_lock->unlock();
duke@435 129 if (needs_pll()) {
duke@435 130 release_and_notify_pending_list_lock();
duke@435 131 }
duke@435 132 }
duke@435 133
duke@435 134 //////////////////////////////////////////////////////////
duke@435 135 // Methods in class VM_CMS_Initial_Mark
duke@435 136 //////////////////////////////////////////////////////////
duke@435 137 void VM_CMS_Initial_Mark::doit() {
duke@435 138 if (lost_race()) {
duke@435 139 // Nothing to do.
duke@435 140 return;
duke@435 141 }
dcubed@3202 142 #ifndef USDT2
duke@435 143 HS_DTRACE_PROBE(hs_private, cms__initmark__begin);
dcubed@3202 144 #else /* USDT2 */
dcubed@3202 145 HS_PRIVATE_CMS_INITMARK_BEGIN(
dcubed@3202 146 );
dcubed@3202 147 #endif /* USDT2 */
duke@435 148
mgronlun@6131 149 _collector->_gc_timer_cm->register_gc_pause_start("Initial Mark");
sla@5237 150
duke@435 151 GenCollectedHeap* gch = GenCollectedHeap::heap();
duke@435 152 GCCauseSetter gccs(gch, GCCause::_cms_initial_mark);
duke@435 153
duke@435 154 VM_CMS_Operation::verify_before_gc();
duke@435 155
duke@435 156 IsGCActiveMark x; // stop-world GC active
brutisso@3767 157 _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsInitial, gch->gc_cause());
duke@435 158
duke@435 159 VM_CMS_Operation::verify_after_gc();
sla@5237 160
mgronlun@6131 161 _collector->_gc_timer_cm->register_gc_pause_end();
sla@5237 162
dcubed@3202 163 #ifndef USDT2
duke@435 164 HS_DTRACE_PROBE(hs_private, cms__initmark__end);
dcubed@3202 165 #else /* USDT2 */
dcubed@3202 166 HS_PRIVATE_CMS_INITMARK_END(
dcubed@3202 167 );
dcubed@3202 168 #endif /* USDT2 */
duke@435 169 }
duke@435 170
duke@435 171 //////////////////////////////////////////////////////////
duke@435 172 // Methods in class VM_CMS_Final_Remark_Operation
duke@435 173 //////////////////////////////////////////////////////////
duke@435 174 void VM_CMS_Final_Remark::doit() {
duke@435 175 if (lost_race()) {
duke@435 176 // Nothing to do.
duke@435 177 return;
duke@435 178 }
dcubed@3202 179 #ifndef USDT2
duke@435 180 HS_DTRACE_PROBE(hs_private, cms__remark__begin);
dcubed@3202 181 #else /* USDT2 */
dcubed@3202 182 HS_PRIVATE_CMS_REMARK_BEGIN(
dcubed@3202 183 );
dcubed@3202 184 #endif /* USDT2 */
duke@435 185
mgronlun@6131 186 _collector->_gc_timer_cm->register_gc_pause_start("Final Mark");
sla@5237 187
duke@435 188 GenCollectedHeap* gch = GenCollectedHeap::heap();
duke@435 189 GCCauseSetter gccs(gch, GCCause::_cms_final_remark);
duke@435 190
duke@435 191 VM_CMS_Operation::verify_before_gc();
duke@435 192
duke@435 193 IsGCActiveMark x; // stop-world GC active
brutisso@3767 194 _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsFinal, gch->gc_cause());
duke@435 195
duke@435 196 VM_CMS_Operation::verify_after_gc();
sla@5237 197
sla@5237 198 _collector->save_heap_summary();
mgronlun@6131 199 _collector->_gc_timer_cm->register_gc_pause_end();
sla@5237 200
dcubed@3202 201 #ifndef USDT2
duke@435 202 HS_DTRACE_PROBE(hs_private, cms__remark__end);
dcubed@3202 203 #else /* USDT2 */
dcubed@3202 204 HS_PRIVATE_CMS_REMARK_END(
dcubed@3202 205 );
dcubed@3202 206 #endif /* USDT2 */
duke@435 207 }
duke@435 208
duke@435 209 // VM operation to invoke a concurrent collection of a
duke@435 210 // GenCollectedHeap heap.
duke@435 211 void VM_GenCollectFullConcurrent::doit() {
duke@435 212 assert(Thread::current()->is_VM_thread(), "Should be VM thread");
ysr@1875 213 assert(GCLockerInvokesConcurrent || ExplicitGCInvokesConcurrent, "Unexpected");
duke@435 214
duke@435 215 GenCollectedHeap* gch = GenCollectedHeap::heap();
duke@435 216 if (_gc_count_before == gch->total_collections()) {
duke@435 217 // The "full" of do_full_collection call below "forces"
duke@435 218 // a collection; the second arg, 0, below ensures that
duke@435 219 // only the young gen is collected. XXX In the future,
duke@435 220 // we'll probably need to have something in this interface
duke@435 221 // to say do this only if we are sure we will not bail
duke@435 222 // out to a full collection in this attempt, but that's
duke@435 223 // for the future.
duke@435 224 assert(SafepointSynchronize::is_at_safepoint(),
duke@435 225 "We can only be executing this arm of if at a safepoint");
duke@435 226 GCCauseSetter gccs(gch, _gc_cause);
duke@435 227 gch->do_full_collection(gch->must_clear_all_soft_refs(),
duke@435 228 0 /* collect only youngest gen */);
duke@435 229 } // Else no need for a foreground young gc
duke@435 230 assert((_gc_count_before < gch->total_collections()) ||
duke@435 231 (GC_locker::is_active() /* gc may have been skipped */
duke@435 232 && (_gc_count_before == gch->total_collections())),
duke@435 233 "total_collections() should be monotonically increasing");
duke@435 234
duke@435 235 MutexLockerEx x(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
ysr@2647 236 assert(_full_gc_count_before <= gch->total_full_collections(), "Error");
duke@435 237 if (gch->total_full_collections() == _full_gc_count_before) {
ysr@2647 238 // Disable iCMS until the full collection is done, and
ysr@2647 239 // remember that we did so.
duke@435 240 CMSCollector::disable_icms();
ysr@2647 241 _disabled_icms = true;
duke@435 242 // In case CMS thread was in icms_wait(), wake it up.
duke@435 243 CMSCollector::start_icms();
ysr@1875 244 // Nudge the CMS thread to start a concurrent collection.
sla@5237 245 CMSCollector::request_full_gc(_full_gc_count_before, _gc_cause);
duke@435 246 } else {
ysr@2647 247 assert(_full_gc_count_before < gch->total_full_collections(), "Error");
duke@435 248 FullGCCount_lock->notify_all(); // Inform the Java thread its work is done
duke@435 249 }
duke@435 250 }
duke@435 251
duke@435 252 bool VM_GenCollectFullConcurrent::evaluate_at_safepoint() const {
duke@435 253 Thread* thr = Thread::current();
duke@435 254 assert(thr != NULL, "Unexpected tid");
duke@435 255 if (!thr->is_Java_thread()) {
duke@435 256 assert(thr->is_VM_thread(), "Expected to be evaluated by VM thread");
duke@435 257 GenCollectedHeap* gch = GenCollectedHeap::heap();
duke@435 258 if (_gc_count_before != gch->total_collections()) {
duke@435 259 // No need to do a young gc, we'll just nudge the CMS thread
duke@435 260 // in the doit() method above, to be executed soon.
duke@435 261 assert(_gc_count_before < gch->total_collections(),
duke@435 262 "total_collections() should be monotnically increasing");
duke@435 263 return false; // no need for foreground young gc
duke@435 264 }
duke@435 265 }
duke@435 266 return true; // may still need foreground young gc
duke@435 267 }
duke@435 268
duke@435 269
duke@435 270 void VM_GenCollectFullConcurrent::doit_epilogue() {
duke@435 271 Thread* thr = Thread::current();
duke@435 272 assert(thr->is_Java_thread(), "just checking");
duke@435 273 JavaThread* jt = (JavaThread*)thr;
duke@435 274 // Release the Heap_lock first.
duke@435 275 Heap_lock->unlock();
duke@435 276 release_and_notify_pending_list_lock();
duke@435 277
duke@435 278 // It is fine to test whether completed collections has
duke@435 279 // exceeded our request count without locking because
duke@435 280 // the completion count is monotonically increasing;
duke@435 281 // this will break for very long-running apps when the
duke@435 282 // count overflows and wraps around. XXX fix me !!!
duke@435 283 // e.g. at the rate of 1 full gc per ms, this could
duke@435 284 // overflow in about 1000 years.
duke@435 285 GenCollectedHeap* gch = GenCollectedHeap::heap();
ysr@1875 286 if (_gc_cause != GCCause::_gc_locker &&
ysr@1875 287 gch->total_full_collections_completed() <= _full_gc_count_before) {
tonyp@2011 288 // maybe we should change the condition to test _gc_cause ==
tonyp@2011 289 // GCCause::_java_lang_system_gc, instead of
tonyp@2011 290 // _gc_cause != GCCause::_gc_locker
tonyp@2011 291 assert(_gc_cause == GCCause::_java_lang_system_gc,
tonyp@2011 292 "the only way to get here if this was a System.gc()-induced GC");
ysr@1875 293 assert(ExplicitGCInvokesConcurrent, "Error");
duke@435 294 // Now, wait for witnessing concurrent gc cycle to complete,
duke@435 295 // but do so in native mode, because we want to lock the
duke@435 296 // FullGCEvent_lock, which may be needed by the VM thread
duke@435 297 // or by the CMS thread, so we do not want to be suspended
duke@435 298 // while holding that lock.
duke@435 299 ThreadToNativeFromVM native(jt);
duke@435 300 MutexLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
duke@435 301 // Either a concurrent or a stop-world full gc is sufficient
duke@435 302 // witness to our request.
duke@435 303 while (gch->total_full_collections_completed() <= _full_gc_count_before) {
duke@435 304 FullGCCount_lock->wait(Mutex::_no_safepoint_check_flag);
duke@435 305 }
duke@435 306 }
ysr@2647 307 // Enable iCMS back if we disabled it earlier.
ysr@2647 308 if (_disabled_icms) {
ysr@2647 309 CMSCollector::enable_icms();
ysr@2647 310 }
duke@435 311 }

mercurial