comparison src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp @ 2365:a181f3a124dd

6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent Summary: Count enable_icms() and disable_icms() events so as to prevent inteference between concurrent calls, which can cause the iCMS thread to be left stranded in icms_wait() with an unserviced request and no young allocations to unwedge it. Reviewed-by: jcoomes, poonam
author ysr
date Mon, 14 Mar 2011 21:52:24 -0700
parents f95d63e2154a
children f08d439fab8c
comparison
equal deleted inserted replaced
2364:04d1138b4cce 2365:a181f3a124dd
1 /* 1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
38 #endif 38 #endif
39 39
40 class ConcurrentMarkSweepGeneration; 40 class ConcurrentMarkSweepGeneration;
41 class CMSCollector; 41 class CMSCollector;
42 42
43 // The Concurrent Mark Sweep GC Thread (could be several in the future). 43 // The Concurrent Mark Sweep GC Thread
44 class ConcurrentMarkSweepThread: public ConcurrentGCThread { 44 class ConcurrentMarkSweepThread: public ConcurrentGCThread {
45 friend class VMStructs; 45 friend class VMStructs;
46 friend class ConcurrentMarkSweepGeneration; // XXX should remove friendship 46 friend class ConcurrentMarkSweepGeneration; // XXX should remove friendship
47 friend class CMSCollector; 47 friend class CMSCollector;
48 public: 48 public:
52 static ConcurrentMarkSweepThread* _cmst; 52 static ConcurrentMarkSweepThread* _cmst;
53 static CMSCollector* _collector; 53 static CMSCollector* _collector;
54 static SurrogateLockerThread* _slt; 54 static SurrogateLockerThread* _slt;
55 static SurrogateLockerThread::SLT_msg_type _sltBuffer; 55 static SurrogateLockerThread::SLT_msg_type _sltBuffer;
56 static Monitor* _sltMonitor; 56 static Monitor* _sltMonitor;
57
58 ConcurrentMarkSweepThread* _next;
59 57
60 static bool _should_terminate; 58 static bool _should_terminate;
61 59
62 enum CMS_flag_type { 60 enum CMS_flag_type {
63 CMS_nil = NoBits, 61 CMS_nil = NoBits,
82 static char _pad_2[64 - sizeof(jint)]; // prevent cache-line sharing 80 static char _pad_2[64 - sizeof(jint)]; // prevent cache-line sharing
83 81
84 // Tracing messages, enabled by CMSTraceThreadState. 82 // Tracing messages, enabled by CMSTraceThreadState.
85 static inline void trace_state(const char* desc); 83 static inline void trace_state(const char* desc);
86 84
87 static volatile bool _icms_enabled; // iCMS enabled? 85 static volatile int _icms_disabled; // a counter to track #iCMS disable & enable
88 static volatile bool _should_run; // iCMS may run 86 static volatile bool _should_run; // iCMS may run
89 static volatile bool _should_stop; // iCMS should stop 87 static volatile bool _should_stop; // iCMS should stop
90 88
91 // debugging 89 // debugging
92 void verify_ok_to_terminate() const PRODUCT_RETURN; 90 void verify_ok_to_terminate() const PRODUCT_RETURN;
212 static void stop_icms(); // request thread to stop working 210 static void stop_icms(); // request thread to stop working
213 void icms_wait(); // if asked to stop, wait until notified to start 211 void icms_wait(); // if asked to stop, wait until notified to start
214 212
215 // Incremental mode is enabled globally by the flag CMSIncrementalMode. It 213 // Incremental mode is enabled globally by the flag CMSIncrementalMode. It
216 // must also be enabled/disabled dynamically to allow foreground collections. 214 // must also be enabled/disabled dynamically to allow foreground collections.
217 static inline void enable_icms() { _icms_enabled = true; } 215 #define ICMS_ENABLING_ASSERT \
218 static inline void disable_icms() { _icms_enabled = false; } 216 assert((CMSIncrementalMode && _icms_disabled >= 0) || \
219 static inline void set_icms_enabled(bool val) { _icms_enabled = val; } 217 (!CMSIncrementalMode && _icms_disabled <= 0), "Error")
220 static inline bool icms_enabled() { return _icms_enabled; } 218
219 static inline void enable_icms() {
220 ICMS_ENABLING_ASSERT;
221 Atomic::dec(&_icms_disabled);
222 }
223 static inline void disable_icms() {
224 ICMS_ENABLING_ASSERT;
225 Atomic::inc(&_icms_disabled);
226 }
227 static inline bool icms_is_disabled() {
228 ICMS_ENABLING_ASSERT;
229 return _icms_disabled > 0;
230 }
231 static inline bool icms_is_enabled() {
232 return !icms_is_disabled();
233 }
221 }; 234 };
222 235
223 inline void ConcurrentMarkSweepThread::trace_state(const char* desc) { 236 inline void ConcurrentMarkSweepThread::trace_state(const char* desc) {
224 if (CMSTraceThreadState) { 237 if (CMSTraceThreadState) {
225 char buf[128]; 238 char buf[128];