Tue, 11 Nov 2014 13:39:00 -0500
8062036: ConcurrentMarkThread::slt may be invoked before ConcurrentMarkThread::makeSurrogateLockerThread causing intermittent crashes
Summary: Suppress gc_alot during VM init, improve error for SLT uninitialized.
Reviewed-by: jmasa, brutisso, tschatzl
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. |
kbarrett@7360 | 53 | SurrogateLockerThread* slt = ConcurrentMarkSweepThread::slt(); |
kbarrett@7360 | 54 | if (slt != NULL) { |
kbarrett@7360 | 55 | slt->manipulatePLL(SurrogateLockerThread::acquirePLL); |
kbarrett@7360 | 56 | } else { |
kbarrett@7360 | 57 | SurrogateLockerThread::report_missing_slt(); |
kbarrett@7360 | 58 | } |
duke@435 | 59 | } |
duke@435 | 60 | |
duke@435 | 61 | void VM_CMS_Operation::release_and_notify_pending_list_lock() { |
duke@435 | 62 | // The caller may block while communicating |
duke@435 | 63 | // with the SLT thread in order to acquire/release the PLL. |
duke@435 | 64 | ConcurrentMarkSweepThread::slt()-> |
duke@435 | 65 | manipulatePLL(SurrogateLockerThread::releaseAndNotifyPLL); |
duke@435 | 66 | } |
duke@435 | 67 | |
duke@435 | 68 | void VM_CMS_Operation::verify_before_gc() { |
duke@435 | 69 | if (VerifyBeforeGC && |
duke@435 | 70 | GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { |
brutisso@6904 | 71 | GCTraceTime tm("Verify Before", false, false, _collector->_gc_timer_cm, _collector->_gc_tracer_cm->gc_id()); |
duke@435 | 72 | HandleMark hm; |
duke@435 | 73 | FreelistLocker x(_collector); |
duke@435 | 74 | MutexLockerEx y(_collector->bitMapLock(), Mutex::_no_safepoint_check_flag); |
duke@435 | 75 | Universe::heap()->prepare_for_verify(); |
johnc@4176 | 76 | Universe::verify(); |
duke@435 | 77 | } |
duke@435 | 78 | } |
duke@435 | 79 | |
duke@435 | 80 | void VM_CMS_Operation::verify_after_gc() { |
duke@435 | 81 | if (VerifyAfterGC && |
duke@435 | 82 | GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { |
brutisso@6904 | 83 | GCTraceTime tm("Verify After", false, false, _collector->_gc_timer_cm, _collector->_gc_tracer_cm->gc_id()); |
duke@435 | 84 | HandleMark hm; |
duke@435 | 85 | FreelistLocker x(_collector); |
duke@435 | 86 | MutexLockerEx y(_collector->bitMapLock(), Mutex::_no_safepoint_check_flag); |
johnc@4176 | 87 | Universe::verify(); |
duke@435 | 88 | } |
duke@435 | 89 | } |
duke@435 | 90 | |
duke@435 | 91 | bool VM_CMS_Operation::lost_race() const { |
duke@435 | 92 | if (CMSCollector::abstract_state() == CMSCollector::Idling) { |
duke@435 | 93 | // We lost a race to a foreground collection |
duke@435 | 94 | // -- there's nothing to do |
duke@435 | 95 | return true; |
duke@435 | 96 | } |
duke@435 | 97 | assert(CMSCollector::abstract_state() == legal_state(), |
duke@435 | 98 | "Inconsistent collector state?"); |
duke@435 | 99 | return false; |
duke@435 | 100 | } |
duke@435 | 101 | |
duke@435 | 102 | bool VM_CMS_Operation::doit_prologue() { |
duke@435 | 103 | assert(Thread::current()->is_ConcurrentGC_thread(), "just checking"); |
duke@435 | 104 | assert(!CMSCollector::foregroundGCShouldWait(), "Possible deadlock"); |
duke@435 | 105 | assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), |
duke@435 | 106 | "Possible deadlock"); |
duke@435 | 107 | |
duke@435 | 108 | if (needs_pll()) { |
duke@435 | 109 | acquire_pending_list_lock(); |
duke@435 | 110 | } |
duke@435 | 111 | // Get the Heap_lock after the pending_list_lock. |
duke@435 | 112 | Heap_lock->lock(); |
duke@435 | 113 | if (lost_race()) { |
duke@435 | 114 | assert(_prologue_succeeded == false, "Initialized in c'tor"); |
duke@435 | 115 | Heap_lock->unlock(); |
duke@435 | 116 | if (needs_pll()) { |
duke@435 | 117 | release_and_notify_pending_list_lock(); |
duke@435 | 118 | } |
duke@435 | 119 | } else { |
duke@435 | 120 | _prologue_succeeded = true; |
duke@435 | 121 | } |
duke@435 | 122 | return _prologue_succeeded; |
duke@435 | 123 | } |
duke@435 | 124 | |
duke@435 | 125 | void VM_CMS_Operation::doit_epilogue() { |
duke@435 | 126 | assert(Thread::current()->is_ConcurrentGC_thread(), "just checking"); |
duke@435 | 127 | assert(!CMSCollector::foregroundGCShouldWait(), "Possible deadlock"); |
duke@435 | 128 | assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), |
duke@435 | 129 | "Possible deadlock"); |
duke@435 | 130 | |
duke@435 | 131 | // Release the Heap_lock first. |
duke@435 | 132 | Heap_lock->unlock(); |
duke@435 | 133 | if (needs_pll()) { |
duke@435 | 134 | release_and_notify_pending_list_lock(); |
duke@435 | 135 | } |
duke@435 | 136 | } |
duke@435 | 137 | |
duke@435 | 138 | ////////////////////////////////////////////////////////// |
duke@435 | 139 | // Methods in class VM_CMS_Initial_Mark |
duke@435 | 140 | ////////////////////////////////////////////////////////// |
duke@435 | 141 | void VM_CMS_Initial_Mark::doit() { |
duke@435 | 142 | if (lost_race()) { |
duke@435 | 143 | // Nothing to do. |
duke@435 | 144 | return; |
duke@435 | 145 | } |
dcubed@3202 | 146 | #ifndef USDT2 |
duke@435 | 147 | HS_DTRACE_PROBE(hs_private, cms__initmark__begin); |
dcubed@3202 | 148 | #else /* USDT2 */ |
dcubed@3202 | 149 | HS_PRIVATE_CMS_INITMARK_BEGIN( |
dcubed@3202 | 150 | ); |
dcubed@3202 | 151 | #endif /* USDT2 */ |
duke@435 | 152 | |
mgronlun@6131 | 153 | _collector->_gc_timer_cm->register_gc_pause_start("Initial Mark"); |
sla@5237 | 154 | |
duke@435 | 155 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 156 | GCCauseSetter gccs(gch, GCCause::_cms_initial_mark); |
duke@435 | 157 | |
duke@435 | 158 | VM_CMS_Operation::verify_before_gc(); |
duke@435 | 159 | |
duke@435 | 160 | IsGCActiveMark x; // stop-world GC active |
brutisso@3767 | 161 | _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsInitial, gch->gc_cause()); |
duke@435 | 162 | |
duke@435 | 163 | VM_CMS_Operation::verify_after_gc(); |
sla@5237 | 164 | |
mgronlun@6131 | 165 | _collector->_gc_timer_cm->register_gc_pause_end(); |
sla@5237 | 166 | |
dcubed@3202 | 167 | #ifndef USDT2 |
duke@435 | 168 | HS_DTRACE_PROBE(hs_private, cms__initmark__end); |
dcubed@3202 | 169 | #else /* USDT2 */ |
dcubed@3202 | 170 | HS_PRIVATE_CMS_INITMARK_END( |
dcubed@3202 | 171 | ); |
dcubed@3202 | 172 | #endif /* USDT2 */ |
duke@435 | 173 | } |
duke@435 | 174 | |
duke@435 | 175 | ////////////////////////////////////////////////////////// |
duke@435 | 176 | // Methods in class VM_CMS_Final_Remark_Operation |
duke@435 | 177 | ////////////////////////////////////////////////////////// |
duke@435 | 178 | void VM_CMS_Final_Remark::doit() { |
duke@435 | 179 | if (lost_race()) { |
duke@435 | 180 | // Nothing to do. |
duke@435 | 181 | return; |
duke@435 | 182 | } |
dcubed@3202 | 183 | #ifndef USDT2 |
duke@435 | 184 | HS_DTRACE_PROBE(hs_private, cms__remark__begin); |
dcubed@3202 | 185 | #else /* USDT2 */ |
dcubed@3202 | 186 | HS_PRIVATE_CMS_REMARK_BEGIN( |
dcubed@3202 | 187 | ); |
dcubed@3202 | 188 | #endif /* USDT2 */ |
duke@435 | 189 | |
mgronlun@6131 | 190 | _collector->_gc_timer_cm->register_gc_pause_start("Final Mark"); |
sla@5237 | 191 | |
duke@435 | 192 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 193 | GCCauseSetter gccs(gch, GCCause::_cms_final_remark); |
duke@435 | 194 | |
duke@435 | 195 | VM_CMS_Operation::verify_before_gc(); |
duke@435 | 196 | |
duke@435 | 197 | IsGCActiveMark x; // stop-world GC active |
brutisso@3767 | 198 | _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsFinal, gch->gc_cause()); |
duke@435 | 199 | |
duke@435 | 200 | VM_CMS_Operation::verify_after_gc(); |
sla@5237 | 201 | |
sla@5237 | 202 | _collector->save_heap_summary(); |
mgronlun@6131 | 203 | _collector->_gc_timer_cm->register_gc_pause_end(); |
sla@5237 | 204 | |
dcubed@3202 | 205 | #ifndef USDT2 |
duke@435 | 206 | HS_DTRACE_PROBE(hs_private, cms__remark__end); |
dcubed@3202 | 207 | #else /* USDT2 */ |
dcubed@3202 | 208 | HS_PRIVATE_CMS_REMARK_END( |
dcubed@3202 | 209 | ); |
dcubed@3202 | 210 | #endif /* USDT2 */ |
duke@435 | 211 | } |
duke@435 | 212 | |
duke@435 | 213 | // VM operation to invoke a concurrent collection of a |
duke@435 | 214 | // GenCollectedHeap heap. |
duke@435 | 215 | void VM_GenCollectFullConcurrent::doit() { |
duke@435 | 216 | assert(Thread::current()->is_VM_thread(), "Should be VM thread"); |
ysr@1875 | 217 | assert(GCLockerInvokesConcurrent || ExplicitGCInvokesConcurrent, "Unexpected"); |
duke@435 | 218 | |
duke@435 | 219 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 220 | if (_gc_count_before == gch->total_collections()) { |
duke@435 | 221 | // The "full" of do_full_collection call below "forces" |
duke@435 | 222 | // a collection; the second arg, 0, below ensures that |
duke@435 | 223 | // only the young gen is collected. XXX In the future, |
duke@435 | 224 | // we'll probably need to have something in this interface |
duke@435 | 225 | // to say do this only if we are sure we will not bail |
duke@435 | 226 | // out to a full collection in this attempt, but that's |
duke@435 | 227 | // for the future. |
duke@435 | 228 | assert(SafepointSynchronize::is_at_safepoint(), |
duke@435 | 229 | "We can only be executing this arm of if at a safepoint"); |
duke@435 | 230 | GCCauseSetter gccs(gch, _gc_cause); |
duke@435 | 231 | gch->do_full_collection(gch->must_clear_all_soft_refs(), |
duke@435 | 232 | 0 /* collect only youngest gen */); |
duke@435 | 233 | } // Else no need for a foreground young gc |
duke@435 | 234 | assert((_gc_count_before < gch->total_collections()) || |
duke@435 | 235 | (GC_locker::is_active() /* gc may have been skipped */ |
duke@435 | 236 | && (_gc_count_before == gch->total_collections())), |
duke@435 | 237 | "total_collections() should be monotonically increasing"); |
duke@435 | 238 | |
duke@435 | 239 | MutexLockerEx x(FullGCCount_lock, Mutex::_no_safepoint_check_flag); |
ysr@2647 | 240 | assert(_full_gc_count_before <= gch->total_full_collections(), "Error"); |
duke@435 | 241 | if (gch->total_full_collections() == _full_gc_count_before) { |
ysr@2647 | 242 | // Disable iCMS until the full collection is done, and |
ysr@2647 | 243 | // remember that we did so. |
duke@435 | 244 | CMSCollector::disable_icms(); |
ysr@2647 | 245 | _disabled_icms = true; |
duke@435 | 246 | // In case CMS thread was in icms_wait(), wake it up. |
duke@435 | 247 | CMSCollector::start_icms(); |
ysr@1875 | 248 | // Nudge the CMS thread to start a concurrent collection. |
sla@5237 | 249 | CMSCollector::request_full_gc(_full_gc_count_before, _gc_cause); |
duke@435 | 250 | } else { |
ysr@2647 | 251 | assert(_full_gc_count_before < gch->total_full_collections(), "Error"); |
duke@435 | 252 | FullGCCount_lock->notify_all(); // Inform the Java thread its work is done |
duke@435 | 253 | } |
duke@435 | 254 | } |
duke@435 | 255 | |
duke@435 | 256 | bool VM_GenCollectFullConcurrent::evaluate_at_safepoint() const { |
duke@435 | 257 | Thread* thr = Thread::current(); |
duke@435 | 258 | assert(thr != NULL, "Unexpected tid"); |
duke@435 | 259 | if (!thr->is_Java_thread()) { |
duke@435 | 260 | assert(thr->is_VM_thread(), "Expected to be evaluated by VM thread"); |
duke@435 | 261 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 262 | if (_gc_count_before != gch->total_collections()) { |
duke@435 | 263 | // No need to do a young gc, we'll just nudge the CMS thread |
duke@435 | 264 | // in the doit() method above, to be executed soon. |
duke@435 | 265 | assert(_gc_count_before < gch->total_collections(), |
duke@435 | 266 | "total_collections() should be monotnically increasing"); |
duke@435 | 267 | return false; // no need for foreground young gc |
duke@435 | 268 | } |
duke@435 | 269 | } |
duke@435 | 270 | return true; // may still need foreground young gc |
duke@435 | 271 | } |
duke@435 | 272 | |
duke@435 | 273 | |
duke@435 | 274 | void VM_GenCollectFullConcurrent::doit_epilogue() { |
duke@435 | 275 | Thread* thr = Thread::current(); |
duke@435 | 276 | assert(thr->is_Java_thread(), "just checking"); |
duke@435 | 277 | JavaThread* jt = (JavaThread*)thr; |
duke@435 | 278 | // Release the Heap_lock first. |
duke@435 | 279 | Heap_lock->unlock(); |
duke@435 | 280 | release_and_notify_pending_list_lock(); |
duke@435 | 281 | |
duke@435 | 282 | // It is fine to test whether completed collections has |
duke@435 | 283 | // exceeded our request count without locking because |
duke@435 | 284 | // the completion count is monotonically increasing; |
duke@435 | 285 | // this will break for very long-running apps when the |
duke@435 | 286 | // count overflows and wraps around. XXX fix me !!! |
duke@435 | 287 | // e.g. at the rate of 1 full gc per ms, this could |
duke@435 | 288 | // overflow in about 1000 years. |
duke@435 | 289 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
ysr@1875 | 290 | if (_gc_cause != GCCause::_gc_locker && |
ysr@1875 | 291 | gch->total_full_collections_completed() <= _full_gc_count_before) { |
tonyp@2011 | 292 | // maybe we should change the condition to test _gc_cause == |
tonyp@2011 | 293 | // GCCause::_java_lang_system_gc, instead of |
tonyp@2011 | 294 | // _gc_cause != GCCause::_gc_locker |
tonyp@2011 | 295 | assert(_gc_cause == GCCause::_java_lang_system_gc, |
tonyp@2011 | 296 | "the only way to get here if this was a System.gc()-induced GC"); |
ysr@1875 | 297 | assert(ExplicitGCInvokesConcurrent, "Error"); |
duke@435 | 298 | // Now, wait for witnessing concurrent gc cycle to complete, |
duke@435 | 299 | // but do so in native mode, because we want to lock the |
duke@435 | 300 | // FullGCEvent_lock, which may be needed by the VM thread |
duke@435 | 301 | // or by the CMS thread, so we do not want to be suspended |
duke@435 | 302 | // while holding that lock. |
duke@435 | 303 | ThreadToNativeFromVM native(jt); |
duke@435 | 304 | MutexLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag); |
duke@435 | 305 | // Either a concurrent or a stop-world full gc is sufficient |
duke@435 | 306 | // witness to our request. |
duke@435 | 307 | while (gch->total_full_collections_completed() <= _full_gc_count_before) { |
duke@435 | 308 | FullGCCount_lock->wait(Mutex::_no_safepoint_check_flag); |
duke@435 | 309 | } |
duke@435 | 310 | } |
ysr@2647 | 311 | // Enable iCMS back if we disabled it earlier. |
ysr@2647 | 312 | if (_disabled_icms) { |
ysr@2647 | 313 | CMSCollector::enable_icms(); |
ysr@2647 | 314 | } |
duke@435 | 315 | } |