Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @ 20520:4001310db3f5
8026303: CMS: JVM intermittently crashes with "FreeList of size 258 violates Conservation Principle" assert
Reviewed-by: tschatzl, brutisso
author | jmasa |
---|---|
date | Thu, 21 Nov 2013 09:57:00 -0800 |
parents | da00a41842a5 |
children | c2844108a708 |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1521
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1521
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1521
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
26 #include "classfile/classLoaderData.hpp" |
1972 | 27 #include "classfile/symbolTable.hpp" |
28 #include "classfile/systemDictionary.hpp" | |
29 #include "code/codeCache.hpp" | |
30 #include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp" | |
31 #include "gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.hpp" | |
32 #include "gc_implementation/concurrentMarkSweep/cmsGCAdaptivePolicyCounters.hpp" | |
33 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp" | |
34 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" | |
35 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.inline.hpp" | |
36 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" | |
37 #include "gc_implementation/concurrentMarkSweep/vmCMSOperations.hpp" | |
38 #include "gc_implementation/parNew/parNewGeneration.hpp" | |
39 #include "gc_implementation/shared/collectorCounters.hpp" | |
10405 | 40 #include "gc_implementation/shared/gcTimer.hpp" |
41 #include "gc_implementation/shared/gcTrace.hpp" | |
42 #include "gc_implementation/shared/gcTraceTime.hpp" | |
1972 | 43 #include "gc_implementation/shared/isGCActiveMark.hpp" |
44 #include "gc_interface/collectedHeap.inline.hpp" | |
10405 | 45 #include "memory/allocation.hpp" |
1972 | 46 #include "memory/cardTableRS.hpp" |
47 #include "memory/collectorPolicy.hpp" | |
48 #include "memory/gcLocker.inline.hpp" | |
49 #include "memory/genCollectedHeap.hpp" | |
50 #include "memory/genMarkSweep.hpp" | |
51 #include "memory/genOopClosures.inline.hpp" | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
52 #include "memory/iterator.inline.hpp" |
12029
9766f73e770d
8022880: False sharing between PSPromotionManager instances
stefank
parents:
11975
diff
changeset
|
53 #include "memory/padded.hpp" |
1972 | 54 #include "memory/referencePolicy.hpp" |
55 #include "memory/resourceArea.hpp" | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
56 #include "memory/tenuredGeneration.hpp" |
1972 | 57 #include "oops/oop.inline.hpp" |
58 #include "prims/jvmtiExport.hpp" | |
59 #include "runtime/globals_extension.hpp" | |
60 #include "runtime/handles.inline.hpp" | |
61 #include "runtime/java.hpp" | |
20197
ce8f6bb717c9
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
20190
diff
changeset
|
62 #include "runtime/orderAccess.inline.hpp" |
1972 | 63 #include "runtime/vmThread.hpp" |
64 #include "services/memoryService.hpp" | |
65 #include "services/runtimeService.hpp" | |
0 | 66 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
67 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
68 |
0 | 69 // statics |
70 CMSCollector* ConcurrentMarkSweepGeneration::_collector = NULL; | |
10405 | 71 bool CMSCollector::_full_gc_requested = false; |
72 GCCause::Cause CMSCollector::_full_gc_cause = GCCause::_no_gc; | |
0 | 73 |
74 ////////////////////////////////////////////////////////////////// | |
75 // In support of CMS/VM thread synchronization | |
76 ////////////////////////////////////////////////////////////////// | |
77 // We split use of the CGC_lock into 2 "levels". | |
78 // The low-level locking is of the usual CGC_lock monitor. We introduce | |
79 // a higher level "token" (hereafter "CMS token") built on top of the | |
80 // low level monitor (hereafter "CGC lock"). | |
81 // The token-passing protocol gives priority to the VM thread. The | |
82 // CMS-lock doesn't provide any fairness guarantees, but clients | |
83 // should ensure that it is only held for very short, bounded | |
84 // durations. | |
85 // | |
86 // When either of the CMS thread or the VM thread is involved in | |
87 // collection operations during which it does not want the other | |
88 // thread to interfere, it obtains the CMS token. | |
89 // | |
90 // If either thread tries to get the token while the other has | |
91 // it, that thread waits. However, if the VM thread and CMS thread | |
92 // both want the token, then the VM thread gets priority while the | |
93 // CMS thread waits. This ensures, for instance, that the "concurrent" | |
94 // phases of the CMS thread's work do not block out the VM thread | |
95 // for long periods of time as the CMS thread continues to hog | |
96 // the token. (See bug 4616232). | |
97 // | |
98 // The baton-passing functions are, however, controlled by the | |
99 // flags _foregroundGCShouldWait and _foregroundGCIsActive, | |
100 // and here the low-level CMS lock, not the high level token, | |
101 // ensures mutual exclusion. | |
102 // | |
103 // Two important conditions that we have to satisfy: | |
104 // 1. if a thread does a low-level wait on the CMS lock, then it | |
105 // relinquishes the CMS token if it were holding that token | |
106 // when it acquired the low-level CMS lock. | |
107 // 2. any low-level notifications on the low-level lock | |
108 // should only be sent when a thread has relinquished the token. | |
109 // | |
110 // In the absence of either property, we'd have potential deadlock. | |
111 // | |
112 // We protect each of the CMS (concurrent and sequential) phases | |
113 // with the CMS _token_, not the CMS _lock_. | |
114 // | |
115 // The only code protected by CMS lock is the token acquisition code | |
116 // itself, see ConcurrentMarkSweepThread::[de]synchronize(), and the | |
117 // baton-passing code. | |
118 // | |
119 // Unfortunately, i couldn't come up with a good abstraction to factor and | |
120 // hide the naked CGC_lock manipulation in the baton-passing code | |
121 // further below. That's something we should try to do. Also, the proof | |
122 // of correctness of this 2-level locking scheme is far from obvious, | |
123 // and potentially quite slippery. We have an uneasy supsicion, for instance, | |
124 // that there may be a theoretical possibility of delay/starvation in the | |
125 // low-level lock/wait/notify scheme used for the baton-passing because of | |
126 // potential intereference with the priority scheme embodied in the | |
127 // CMS-token-passing protocol. See related comments at a CGC_lock->wait() | |
128 // invocation further below and marked with "XXX 20011219YSR". | |
129 // Indeed, as we note elsewhere, this may become yet more slippery | |
130 // in the presence of multiple CMS and/or multiple VM threads. XXX | |
131 | |
132 class CMSTokenSync: public StackObj { | |
133 private: | |
134 bool _is_cms_thread; | |
135 public: | |
136 CMSTokenSync(bool is_cms_thread): | |
137 _is_cms_thread(is_cms_thread) { | |
138 assert(is_cms_thread == Thread::current()->is_ConcurrentGC_thread(), | |
139 "Incorrect argument to constructor"); | |
140 ConcurrentMarkSweepThread::synchronize(_is_cms_thread); | |
141 } | |
142 | |
143 ~CMSTokenSync() { | |
144 assert(_is_cms_thread ? | |
145 ConcurrentMarkSweepThread::cms_thread_has_cms_token() : | |
146 ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
147 "Incorrect state"); | |
148 ConcurrentMarkSweepThread::desynchronize(_is_cms_thread); | |
149 } | |
150 }; | |
151 | |
152 // Convenience class that does a CMSTokenSync, and then acquires | |
153 // upto three locks. | |
154 class CMSTokenSyncWithLocks: public CMSTokenSync { | |
155 private: | |
156 // Note: locks are acquired in textual declaration order | |
157 // and released in the opposite order | |
158 MutexLockerEx _locker1, _locker2, _locker3; | |
159 public: | |
160 CMSTokenSyncWithLocks(bool is_cms_thread, Mutex* mutex1, | |
161 Mutex* mutex2 = NULL, Mutex* mutex3 = NULL): | |
162 CMSTokenSync(is_cms_thread), | |
163 _locker1(mutex1, Mutex::_no_safepoint_check_flag), | |
164 _locker2(mutex2, Mutex::_no_safepoint_check_flag), | |
165 _locker3(mutex3, Mutex::_no_safepoint_check_flag) | |
166 { } | |
167 }; | |
168 | |
169 | |
170 // Wrapper class to temporarily disable icms during a foreground cms collection. | |
171 class ICMSDisabler: public StackObj { | |
172 public: | |
173 // The ctor disables icms and wakes up the thread so it notices the change; | |
174 // the dtor re-enables icms. Note that the CMSCollector methods will check | |
175 // CMSIncrementalMode. | |
176 ICMSDisabler() { CMSCollector::disable_icms(); CMSCollector::start_icms(); } | |
177 ~ICMSDisabler() { CMSCollector::enable_icms(); } | |
178 }; | |
179 | |
180 ////////////////////////////////////////////////////////////////// | |
181 // Concurrent Mark-Sweep Generation ///////////////////////////// | |
182 ////////////////////////////////////////////////////////////////// | |
183 | |
184 NOT_PRODUCT(CompactibleFreeListSpace* debug_cms_space;) | |
185 | |
186 // This struct contains per-thread things necessary to support parallel | |
187 // young-gen collection. | |
6197 | 188 class CMSParGCThreadState: public CHeapObj<mtGC> { |
0 | 189 public: |
190 CFLS_LAB lab; | |
191 PromotionInfo promo; | |
192 | |
193 // Constructor. | |
194 CMSParGCThreadState(CompactibleFreeListSpace* cfls) : lab(cfls) { | |
195 promo.setSpace(cfls); | |
196 } | |
197 }; | |
198 | |
199 ConcurrentMarkSweepGeneration::ConcurrentMarkSweepGeneration( | |
200 ReservedSpace rs, size_t initial_byte_size, int level, | |
201 CardTableRS* ct, bool use_adaptive_freelists, | |
6026 | 202 FreeBlockDictionary<FreeChunk>::DictionaryChoice dictionaryChoice) : |
0 | 203 CardGeneration(rs, initial_byte_size, level, ct), |
1571
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
1521
diff
changeset
|
204 _dilatation_factor(((double)MinChunkSize)/((double)(CollectedHeap::min_fill_size()))), |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
205 _debug_collection_type(Concurrent_collection_type), |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
206 _did_compact(false) |
0 | 207 { |
208 HeapWord* bottom = (HeapWord*) _virtual_space.low(); | |
209 HeapWord* end = (HeapWord*) _virtual_space.high(); | |
210 | |
211 _direct_allocated_words = 0; | |
212 NOT_PRODUCT( | |
213 _numObjectsPromoted = 0; | |
214 _numWordsPromoted = 0; | |
215 _numObjectsAllocated = 0; | |
216 _numWordsAllocated = 0; | |
217 ) | |
218 | |
219 _cmsSpace = new CompactibleFreeListSpace(_bts, MemRegion(bottom, end), | |
220 use_adaptive_freelists, | |
221 dictionaryChoice); | |
222 NOT_PRODUCT(debug_cms_space = _cmsSpace;) | |
223 if (_cmsSpace == NULL) { | |
224 vm_exit_during_initialization( | |
225 "CompactibleFreeListSpace allocation failure"); | |
226 } | |
227 _cmsSpace->_gen = this; | |
228 | |
229 _gc_stats = new CMSGCStats(); | |
230 | |
231 // Verify the assumption that FreeChunk::_prev and OopDesc::_klass | |
232 // offsets match. The ability to tell free chunks from objects | |
233 // depends on this property. | |
234 debug_only( | |
235 FreeChunk* junk = NULL; | |
12226
7944aba7ba41
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
12112
diff
changeset
|
236 assert(UseCompressedClassPointers || |
187 | 237 junk->prev_addr() == (void*)(oop(junk)->klass_addr()), |
0 | 238 "Offset of FreeChunk::_prev within FreeChunk must match" |
239 " that of OopDesc::_klass within OopDesc"); | |
240 ) | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
241 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 242 typedef CMSParGCThreadState* CMSParGCThreadStatePtr; |
243 _par_gc_thread_states = | |
6197 | 244 NEW_C_HEAP_ARRAY(CMSParGCThreadStatePtr, ParallelGCThreads, mtGC); |
0 | 245 if (_par_gc_thread_states == NULL) { |
246 vm_exit_during_initialization("Could not allocate par gc structs"); | |
247 } | |
248 for (uint i = 0; i < ParallelGCThreads; i++) { | |
249 _par_gc_thread_states[i] = new CMSParGCThreadState(cmsSpace()); | |
250 if (_par_gc_thread_states[i] == NULL) { | |
251 vm_exit_during_initialization("Could not allocate par gc structs"); | |
252 } | |
253 } | |
254 } else { | |
255 _par_gc_thread_states = NULL; | |
256 } | |
257 _incremental_collection_failed = false; | |
258 // The "dilatation_factor" is the expansion that can occur on | |
259 // account of the fact that the minimum object size in the CMS | |
260 // generation may be larger than that in, say, a contiguous young | |
261 // generation. | |
262 // Ideally, in the calculation below, we'd compute the dilatation | |
263 // factor as: MinChunkSize/(promoting_gen's min object size) | |
264 // Since we do not have such a general query interface for the | |
265 // promoting generation, we'll instead just use the mimimum | |
266 // object size (which today is a header's worth of space); | |
267 // note that all arithmetic is in units of HeapWords. | |
1571
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
1521
diff
changeset
|
268 assert(MinChunkSize >= CollectedHeap::min_fill_size(), "just checking"); |
0 | 269 assert(_dilatation_factor >= 1.0, "from previous assert"); |
270 } | |
271 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
272 |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
273 // The field "_initiating_occupancy" represents the occupancy percentage |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
274 // at which we trigger a new collection cycle. Unless explicitly specified |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
275 // via CMSInitiatingOccupancyFraction (argument "io" below), it |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
276 // is calculated by: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
277 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
278 // Let "f" be MinHeapFreeRatio in |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
279 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
280 // _intiating_occupancy = 100-f + |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
281 // f * (CMSTriggerRatio/100) |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
282 // where CMSTriggerRatio is the argument "tr" below. |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
283 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
284 // That is, if we assume the heap is at its desired maximum occupancy at the |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
285 // end of a collection, we let CMSTriggerRatio of the (purported) free |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
286 // space be allocated before initiating a new collection cycle. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
287 // |
8035 | 288 void ConcurrentMarkSweepGeneration::init_initiating_occupancy(intx io, uintx tr) { |
289 assert(io <= 100 && tr <= 100, "Check the arguments"); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
290 if (io >= 0) { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
291 _initiating_occupancy = (double)io / 100.0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
292 } else { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
293 _initiating_occupancy = ((100 - MinHeapFreeRatio) + |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
294 (double)(tr * MinHeapFreeRatio) / 100.0) |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
295 / 100.0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
296 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
297 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
298 |
0 | 299 void ConcurrentMarkSweepGeneration::ref_processor_init() { |
300 assert(collector() != NULL, "no collector"); | |
301 collector()->ref_processor_init(); | |
302 } | |
303 | |
304 void CMSCollector::ref_processor_init() { | |
305 if (_ref_processor == NULL) { | |
306 // Allocate and initialize a reference processor | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
307 _ref_processor = |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
308 new ReferenceProcessor(_span, // span |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
309 (ParallelGCThreads > 1) && ParallelRefProcEnabled, // mt processing |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
310 (int) ParallelGCThreads, // mt processing degree |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
311 _cmsGen->refs_discovery_is_mt(), // mt discovery |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
312 (int) MAX2(ConcGCThreads, ParallelGCThreads), // mt discovery degree |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
313 _cmsGen->refs_discovery_is_atomic(), // discovery is not atomic |
17976
8e20ef014b08
8043239: G1: Missing post barrier in processing of j.l.ref.Reference objects
brutisso
parents:
17937
diff
changeset
|
314 &_is_alive_closure); // closure for liveness info |
0 | 315 // Initialize the _ref_processor field of CMSGen |
316 _cmsGen->set_ref_processor(_ref_processor); | |
317 | |
318 } | |
319 } | |
320 | |
321 CMSAdaptiveSizePolicy* CMSCollector::size_policy() { | |
322 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
323 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
324 "Wrong type of heap"); | |
325 CMSAdaptiveSizePolicy* sp = (CMSAdaptiveSizePolicy*) | |
326 gch->gen_policy()->size_policy(); | |
327 assert(sp->is_gc_cms_adaptive_size_policy(), | |
328 "Wrong type of size policy"); | |
329 return sp; | |
330 } | |
331 | |
332 CMSGCAdaptivePolicyCounters* CMSCollector::gc_adaptive_policy_counters() { | |
333 CMSGCAdaptivePolicyCounters* results = | |
334 (CMSGCAdaptivePolicyCounters*) collector_policy()->counters(); | |
335 assert( | |
336 results->kind() == GCPolicyCounters::CMSGCAdaptivePolicyCountersKind, | |
337 "Wrong gc policy counter kind"); | |
338 return results; | |
339 } | |
340 | |
341 | |
342 void ConcurrentMarkSweepGeneration::initialize_performance_counters() { | |
343 | |
344 const char* gen_name = "old"; | |
345 | |
346 // Generation Counters - generation 1, 1 subspace | |
347 _gen_counters = new GenerationCounters(gen_name, 1, 1, &_virtual_space); | |
348 | |
349 _space_counters = new GSpaceCounters(gen_name, 0, | |
350 _virtual_space.reserved_size(), | |
351 this, _gen_counters); | |
352 } | |
353 | |
354 CMSStats::CMSStats(ConcurrentMarkSweepGeneration* cms_gen, unsigned int alpha): | |
355 _cms_gen(cms_gen) | |
356 { | |
357 assert(alpha <= 100, "bad value"); | |
358 _saved_alpha = alpha; | |
359 | |
360 // Initialize the alphas to the bootstrap value of 100. | |
361 _gc0_alpha = _cms_alpha = 100; | |
362 | |
363 _cms_begin_time.update(); | |
364 _cms_end_time.update(); | |
365 | |
366 _gc0_duration = 0.0; | |
367 _gc0_period = 0.0; | |
368 _gc0_promoted = 0; | |
369 | |
370 _cms_duration = 0.0; | |
371 _cms_period = 0.0; | |
372 _cms_allocated = 0; | |
373 | |
374 _cms_used_at_gc0_begin = 0; | |
375 _cms_used_at_gc0_end = 0; | |
376 _allow_duty_cycle_reduction = false; | |
377 _valid_bits = 0; | |
378 _icms_duty_cycle = CMSIncrementalDutyCycle; | |
379 } | |
380 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
381 double CMSStats::cms_free_adjustment_factor(size_t free) const { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
382 // TBD: CR 6909490 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
383 return 1.0; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
384 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
385 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
386 void CMSStats::adjust_cms_free_adjustment_factor(bool fail, size_t free) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
387 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
388 |
0 | 389 // If promotion failure handling is on use |
390 // the padded average size of the promotion for each | |
391 // young generation collection. | |
392 double CMSStats::time_until_cms_gen_full() const { | |
393 size_t cms_free = _cms_gen->cmsSpace()->free(); | |
394 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
395 size_t expected_promotion = MIN2(gch->get_gen(0)->capacity(), |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
396 (size_t) _cms_gen->gc_stats()->avg_promoted()->padded_average()); |
0 | 397 if (cms_free > expected_promotion) { |
398 // Start a cms collection if there isn't enough space to promote | |
399 // for the next minor collection. Use the padded average as | |
400 // a safety factor. | |
401 cms_free -= expected_promotion; | |
402 | |
403 // Adjust by the safety factor. | |
404 double cms_free_dbl = (double)cms_free; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
405 double cms_adjustment = (100.0 - CMSIncrementalSafetyFactor)/100.0; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
406 // Apply a further correction factor which tries to adjust |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
407 // for recent occurance of concurrent mode failures. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
408 cms_adjustment = cms_adjustment * cms_free_adjustment_factor(cms_free); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
409 cms_free_dbl = cms_free_dbl * cms_adjustment; |
0 | 410 |
411 if (PrintGCDetails && Verbose) { | |
412 gclog_or_tty->print_cr("CMSStats::time_until_cms_gen_full: cms_free " | |
413 SIZE_FORMAT " expected_promotion " SIZE_FORMAT, | |
414 cms_free, expected_promotion); | |
415 gclog_or_tty->print_cr(" cms_free_dbl %f cms_consumption_rate %f", | |
416 cms_free_dbl, cms_consumption_rate() + 1.0); | |
417 } | |
418 // Add 1 in case the consumption rate goes to zero. | |
419 return cms_free_dbl / (cms_consumption_rate() + 1.0); | |
420 } | |
421 return 0.0; | |
422 } | |
423 | |
424 // Compare the duration of the cms collection to the | |
425 // time remaining before the cms generation is empty. | |
426 // Note that the time from the start of the cms collection | |
427 // to the start of the cms sweep (less than the total | |
428 // duration of the cms collection) can be used. This | |
429 // has been tried and some applications experienced | |
430 // promotion failures early in execution. This was | |
431 // possibly because the averages were not accurate | |
432 // enough at the beginning. | |
433 double CMSStats::time_until_cms_start() const { | |
434 // We add "gc0_period" to the "work" calculation | |
435 // below because this query is done (mostly) at the | |
436 // end of a scavenge, so we need to conservatively | |
437 // account for that much possible delay | |
438 // in the query so as to avoid concurrent mode failures | |
439 // due to starting the collection just a wee bit too | |
440 // late. | |
441 double work = cms_duration() + gc0_period(); | |
442 double deadline = time_until_cms_gen_full(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
443 // If a concurrent mode failure occurred recently, we want to be |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
444 // more conservative and halve our expected time_until_cms_gen_full() |
0 | 445 if (work > deadline) { |
446 if (Verbose && PrintGCDetails) { | |
447 gclog_or_tty->print( | |
448 " CMSCollector: collect because of anticipated promotion " | |
449 "before full %3.7f + %3.7f > %3.7f ", cms_duration(), | |
450 gc0_period(), time_until_cms_gen_full()); | |
451 } | |
452 return 0.0; | |
453 } | |
454 return work - deadline; | |
455 } | |
456 | |
457 // Return a duty cycle based on old_duty_cycle and new_duty_cycle, limiting the | |
458 // amount of change to prevent wild oscillation. | |
459 unsigned int CMSStats::icms_damped_duty_cycle(unsigned int old_duty_cycle, | |
460 unsigned int new_duty_cycle) { | |
461 assert(old_duty_cycle <= 100, "bad input value"); | |
462 assert(new_duty_cycle <= 100, "bad input value"); | |
463 | |
464 // Note: use subtraction with caution since it may underflow (values are | |
465 // unsigned). Addition is safe since we're in the range 0-100. | |
466 unsigned int damped_duty_cycle = new_duty_cycle; | |
467 if (new_duty_cycle < old_duty_cycle) { | |
468 const unsigned int largest_delta = MAX2(old_duty_cycle / 4, 5U); | |
469 if (new_duty_cycle + largest_delta < old_duty_cycle) { | |
470 damped_duty_cycle = old_duty_cycle - largest_delta; | |
471 } | |
472 } else if (new_duty_cycle > old_duty_cycle) { | |
473 const unsigned int largest_delta = MAX2(old_duty_cycle / 4, 15U); | |
474 if (new_duty_cycle > old_duty_cycle + largest_delta) { | |
475 damped_duty_cycle = MIN2(old_duty_cycle + largest_delta, 100U); | |
476 } | |
477 } | |
478 assert(damped_duty_cycle <= 100, "invalid duty cycle computed"); | |
479 | |
480 if (CMSTraceIncrementalPacing) { | |
481 gclog_or_tty->print(" [icms_damped_duty_cycle(%d,%d) = %d] ", | |
482 old_duty_cycle, new_duty_cycle, damped_duty_cycle); | |
483 } | |
484 return damped_duty_cycle; | |
485 } | |
486 | |
487 unsigned int CMSStats::icms_update_duty_cycle_impl() { | |
488 assert(CMSIncrementalPacing && valid(), | |
489 "should be handled in icms_update_duty_cycle()"); | |
490 | |
491 double cms_time_so_far = cms_timer().seconds(); | |
492 double scaled_duration = cms_duration_per_mb() * _cms_used_at_gc0_end / M; | |
493 double scaled_duration_remaining = fabsd(scaled_duration - cms_time_so_far); | |
494 | |
495 // Avoid division by 0. | |
496 double time_until_full = MAX2(time_until_cms_gen_full(), 0.01); | |
497 double duty_cycle_dbl = 100.0 * scaled_duration_remaining / time_until_full; | |
498 | |
499 unsigned int new_duty_cycle = MIN2((unsigned int)duty_cycle_dbl, 100U); | |
500 if (new_duty_cycle > _icms_duty_cycle) { | |
501 // Avoid very small duty cycles (1 or 2); 0 is allowed. | |
502 if (new_duty_cycle > 2) { | |
503 _icms_duty_cycle = icms_damped_duty_cycle(_icms_duty_cycle, | |
504 new_duty_cycle); | |
505 } | |
506 } else if (_allow_duty_cycle_reduction) { | |
507 // The duty cycle is reduced only once per cms cycle (see record_cms_end()). | |
508 new_duty_cycle = icms_damped_duty_cycle(_icms_duty_cycle, new_duty_cycle); | |
509 // Respect the minimum duty cycle. | |
510 unsigned int min_duty_cycle = (unsigned int)CMSIncrementalDutyCycleMin; | |
511 _icms_duty_cycle = MAX2(new_duty_cycle, min_duty_cycle); | |
512 } | |
513 | |
514 if (PrintGCDetails || CMSTraceIncrementalPacing) { | |
515 gclog_or_tty->print(" icms_dc=%d ", _icms_duty_cycle); | |
516 } | |
517 | |
518 _allow_duty_cycle_reduction = false; | |
519 return _icms_duty_cycle; | |
520 } | |
521 | |
522 #ifndef PRODUCT | |
523 void CMSStats::print_on(outputStream *st) const { | |
524 st->print(" gc0_alpha=%d,cms_alpha=%d", _gc0_alpha, _cms_alpha); | |
525 st->print(",gc0_dur=%g,gc0_per=%g,gc0_promo=" SIZE_FORMAT, | |
526 gc0_duration(), gc0_period(), gc0_promoted()); | |
527 st->print(",cms_dur=%g,cms_dur_per_mb=%g,cms_per=%g,cms_alloc=" SIZE_FORMAT, | |
528 cms_duration(), cms_duration_per_mb(), | |
529 cms_period(), cms_allocated()); | |
530 st->print(",cms_since_beg=%g,cms_since_end=%g", | |
531 cms_time_since_begin(), cms_time_since_end()); | |
532 st->print(",cms_used_beg=" SIZE_FORMAT ",cms_used_end=" SIZE_FORMAT, | |
533 _cms_used_at_gc0_begin, _cms_used_at_gc0_end); | |
534 if (CMSIncrementalMode) { | |
535 st->print(",dc=%d", icms_duty_cycle()); | |
536 } | |
537 | |
538 if (valid()) { | |
539 st->print(",promo_rate=%g,cms_alloc_rate=%g", | |
540 promotion_rate(), cms_allocation_rate()); | |
541 st->print(",cms_consumption_rate=%g,time_until_full=%g", | |
542 cms_consumption_rate(), time_until_cms_gen_full()); | |
543 } | |
544 st->print(" "); | |
545 } | |
546 #endif // #ifndef PRODUCT | |
547 | |
548 CMSCollector::CollectorState CMSCollector::_collectorState = | |
549 CMSCollector::Idling; | |
550 bool CMSCollector::_foregroundGCIsActive = false; | |
551 bool CMSCollector::_foregroundGCShouldWait = false; | |
552 | |
553 CMSCollector::CMSCollector(ConcurrentMarkSweepGeneration* cmsGen, | |
554 CardTableRS* ct, | |
555 ConcurrentMarkSweepPolicy* cp): | |
556 _cmsGen(cmsGen), | |
557 _ct(ct), | |
558 _ref_processor(NULL), // will be set later | |
559 _conc_workers(NULL), // may be set later | |
560 _abort_preclean(false), | |
561 _start_sampling(false), | |
562 _between_prologue_and_epilogue(false), | |
563 _markBitMap(0, Mutex::leaf + 1, "CMS_markBitMap_lock"), | |
564 _modUnionTable((CardTableModRefBS::card_shift - LogHeapWordSize), | |
565 -1 /* lock-free */, "No_lock" /* dummy */), | |
566 _modUnionClosure(&_modUnionTable), | |
567 _modUnionClosurePar(&_modUnionTable), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
568 // Adjust my span to cover old (cms) gen |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
569 _span(cmsGen->reserved()), |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
570 // Construct the is_alive_closure with _span & markBitMap |
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
571 _is_alive_closure(_span, &_markBitMap), |
0 | 572 _restart_addr(NULL), |
573 _overflow_list(NULL), | |
574 _stats(cmsGen), | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
575 _eden_chunk_lock(new Mutex(Mutex::leaf + 1, "CMS_eden_chunk_lock", true)), |
0 | 576 _eden_chunk_array(NULL), // may be set in ctor body |
577 _eden_chunk_capacity(0), // -- ditto -- | |
578 _eden_chunk_index(0), // -- ditto -- | |
579 _survivor_plab_array(NULL), // -- ditto -- | |
580 _survivor_chunk_array(NULL), // -- ditto -- | |
581 _survivor_chunk_capacity(0), // -- ditto -- | |
582 _survivor_chunk_index(0), // -- ditto -- | |
583 _ser_pmc_preclean_ovflw(0), | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
584 _ser_kac_preclean_ovflw(0), |
0 | 585 _ser_pmc_remark_ovflw(0), |
586 _par_pmc_remark_ovflw(0), | |
587 _ser_kac_ovflw(0), | |
588 _par_kac_ovflw(0), | |
589 #ifndef PRODUCT | |
590 _num_par_pushes(0), | |
591 #endif | |
592 _collection_count_start(0), | |
593 _verifying(false), | |
594 _icms_start_limit(NULL), | |
595 _icms_stop_limit(NULL), | |
596 _verification_mark_bm(0, Mutex::leaf + 1, "CMS_verification_mark_bm_lock"), | |
597 _completed_initialization(false), | |
598 _collector_policy(cp), | |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
599 _should_unload_classes(CMSClassUnloadingEnabled), |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
600 _concurrent_cycles_since_last_unload(0), |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
601 _roots_scanning_options(SharedHeap::SO_None), |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
602 _inter_sweep_estimate(CMS_SweepWeight, CMS_SweepPadding), |
10405 | 603 _intra_sweep_estimate(CMS_SweepWeight, CMS_SweepPadding), |
604 _gc_tracer_cm(new (ResourceObj::C_HEAP, mtGC) CMSTracer()), | |
605 _gc_timer_cm(new (ResourceObj::C_HEAP, mtGC) ConcurrentGCTimer()), | |
606 _cms_start_registered(false) | |
0 | 607 { |
608 if (ExplicitGCInvokesConcurrentAndUnloadsClasses) { | |
609 ExplicitGCInvokesConcurrent = true; | |
610 } | |
611 // Now expand the span and allocate the collection support structures | |
612 // (MUT, marking bit map etc.) to cover both generations subject to | |
613 // collection. | |
614 | |
615 // For use by dirty card to oop closures. | |
616 _cmsGen->cmsSpace()->set_collector(this); | |
617 | |
618 // Allocate MUT and marking bit map | |
619 { | |
620 MutexLockerEx x(_markBitMap.lock(), Mutex::_no_safepoint_check_flag); | |
621 if (!_markBitMap.allocate(_span)) { | |
622 warning("Failed to allocate CMS Bit Map"); | |
623 return; | |
624 } | |
625 assert(_markBitMap.covers(_span), "_markBitMap inconsistency?"); | |
626 } | |
627 { | |
628 _modUnionTable.allocate(_span); | |
629 assert(_modUnionTable.covers(_span), "_modUnionTable inconsistency?"); | |
630 } | |
631 | |
1284 | 632 if (!_markStack.allocate(MarkStackSize)) { |
0 | 633 warning("Failed to allocate CMS Marking Stack"); |
634 return; | |
635 } | |
636 | |
637 // Support for multi-threaded concurrent phases | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
638 if (CMSConcurrentMTEnabled) { |
1284 | 639 if (FLAG_IS_DEFAULT(ConcGCThreads)) { |
0 | 640 // just for now |
1284 | 641 FLAG_SET_DEFAULT(ConcGCThreads, (ParallelGCThreads + 3)/4); |
642 } | |
643 if (ConcGCThreads > 1) { | |
0 | 644 _conc_workers = new YieldingFlexibleWorkGang("Parallel CMS Threads", |
1284 | 645 ConcGCThreads, true); |
0 | 646 if (_conc_workers == NULL) { |
647 warning("GC/CMS: _conc_workers allocation failure: " | |
648 "forcing -CMSConcurrentMTEnabled"); | |
649 CMSConcurrentMTEnabled = false; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
650 } else { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
651 _conc_workers->initialize_workers(); |
0 | 652 } |
653 } else { | |
654 CMSConcurrentMTEnabled = false; | |
655 } | |
656 } | |
657 if (!CMSConcurrentMTEnabled) { | |
1284 | 658 ConcGCThreads = 0; |
0 | 659 } else { |
660 // Turn off CMSCleanOnEnter optimization temporarily for | |
661 // the MT case where it's not fixed yet; see 6178663. | |
662 CMSCleanOnEnter = false; | |
663 } | |
1284 | 664 assert((_conc_workers != NULL) == (ConcGCThreads > 1), |
0 | 665 "Inconsistency"); |
666 | |
667 // Parallel task queues; these are shared for the | |
668 // concurrent and stop-world phases of CMS, but | |
669 // are not shared with parallel scavenge (ParNew). | |
670 { | |
671 uint i; | |
1284 | 672 uint num_queues = (uint) MAX2(ParallelGCThreads, ConcGCThreads); |
0 | 673 |
674 if ((CMSParallelRemarkEnabled || CMSConcurrentMTEnabled | |
675 || ParallelRefProcEnabled) | |
676 && num_queues > 0) { | |
677 _task_queues = new OopTaskQueueSet(num_queues); | |
678 if (_task_queues == NULL) { | |
679 warning("task_queues allocation failure."); | |
680 return; | |
681 } | |
6197 | 682 _hash_seed = NEW_C_HEAP_ARRAY(int, num_queues, mtGC); |
0 | 683 if (_hash_seed == NULL) { |
684 warning("_hash_seed array allocation failure"); | |
685 return; | |
686 } | |
687 | |
1665 | 688 typedef Padded<OopTaskQueue> PaddedOopTaskQueue; |
0 | 689 for (i = 0; i < num_queues; i++) { |
1665 | 690 PaddedOopTaskQueue *q = new PaddedOopTaskQueue(); |
691 if (q == NULL) { | |
0 | 692 warning("work_queue allocation failure."); |
693 return; | |
694 } | |
1665 | 695 _task_queues->register_queue(i, q); |
0 | 696 } |
697 for (i = 0; i < num_queues; i++) { | |
698 _task_queues->queue(i)->initialize(); | |
699 _hash_seed[i] = 17; // copied from ParNew | |
700 } | |
701 } | |
702 } | |
703 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
704 _cmsGen ->init_initiating_occupancy(CMSInitiatingOccupancyFraction, CMSTriggerRatio); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
705 |
0 | 706 // Clip CMSBootstrapOccupancy between 0 and 100. |
10287
12f651e29f6b
6843347: Boundary values in some public GC options cause crashes
tschatzl
parents:
10244
diff
changeset
|
707 _bootstrap_occupancy = ((double)CMSBootstrapOccupancy)/(double)100; |
0 | 708 |
709 _full_gcs_since_conc_gc = 0; | |
710 | |
711 // Now tell CMS generations the identity of their collector | |
712 ConcurrentMarkSweepGeneration::set_collector(this); | |
713 | |
714 // Create & start a CMS thread for this CMS collector | |
715 _cmsThread = ConcurrentMarkSweepThread::start(this); | |
716 assert(cmsThread() != NULL, "CMS Thread should have been created"); | |
717 assert(cmsThread()->collector() == this, | |
718 "CMS Thread should refer to this gen"); | |
719 assert(CGC_lock != NULL, "Where's the CGC_lock?"); | |
720 | |
721 // Support for parallelizing young gen rescan | |
722 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
723 _young_gen = gch->prev_gen(_cmsGen); | |
724 if (gch->supports_inline_contig_alloc()) { | |
725 _top_addr = gch->top_addr(); | |
726 _end_addr = gch->end_addr(); | |
727 assert(_young_gen != NULL, "no _young_gen"); | |
728 _eden_chunk_index = 0; | |
729 _eden_chunk_capacity = (_young_gen->max_capacity()+CMSSamplingGrain)/CMSSamplingGrain; | |
6197 | 730 _eden_chunk_array = NEW_C_HEAP_ARRAY(HeapWord*, _eden_chunk_capacity, mtGC); |
0 | 731 if (_eden_chunk_array == NULL) { |
732 _eden_chunk_capacity = 0; | |
733 warning("GC/CMS: _eden_chunk_array allocation failure"); | |
734 } | |
735 } | |
736 assert(_eden_chunk_array != NULL || _eden_chunk_capacity == 0, "Error"); | |
737 | |
738 // Support for parallelizing survivor space rescan | |
11975 | 739 if ((CMSParallelRemarkEnabled && CMSParallelSurvivorRemarkEnabled) || CMSParallelInitialMarkEnabled) { |
1289
d47555d7aca8
6910182: CMS: assert(_cursor[j] == _survivor_plab_array[j].end(),"Ctl pt invariant")
jmasa
parents:
1284
diff
changeset
|
740 const size_t max_plab_samples = |
d47555d7aca8
6910182: CMS: assert(_cursor[j] == _survivor_plab_array[j].end(),"Ctl pt invariant")
jmasa
parents:
1284
diff
changeset
|
741 ((DefNewGeneration*)_young_gen)->max_survivor_size()/MinTLABSize; |
d47555d7aca8
6910182: CMS: assert(_cursor[j] == _survivor_plab_array[j].end(),"Ctl pt invariant")
jmasa
parents:
1284
diff
changeset
|
742 |
6197 | 743 _survivor_plab_array = NEW_C_HEAP_ARRAY(ChunkArray, ParallelGCThreads, mtGC); |
744 _survivor_chunk_array = NEW_C_HEAP_ARRAY(HeapWord*, 2*max_plab_samples, mtGC); | |
745 _cursor = NEW_C_HEAP_ARRAY(size_t, ParallelGCThreads, mtGC); | |
0 | 746 if (_survivor_plab_array == NULL || _survivor_chunk_array == NULL |
747 || _cursor == NULL) { | |
748 warning("Failed to allocate survivor plab/chunk array"); | |
749 if (_survivor_plab_array != NULL) { | |
6197 | 750 FREE_C_HEAP_ARRAY(ChunkArray, _survivor_plab_array, mtGC); |
0 | 751 _survivor_plab_array = NULL; |
752 } | |
753 if (_survivor_chunk_array != NULL) { | |
6197 | 754 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_chunk_array, mtGC); |
0 | 755 _survivor_chunk_array = NULL; |
756 } | |
757 if (_cursor != NULL) { | |
6197 | 758 FREE_C_HEAP_ARRAY(size_t, _cursor, mtGC); |
0 | 759 _cursor = NULL; |
760 } | |
761 } else { | |
762 _survivor_chunk_capacity = 2*max_plab_samples; | |
763 for (uint i = 0; i < ParallelGCThreads; i++) { | |
6197 | 764 HeapWord** vec = NEW_C_HEAP_ARRAY(HeapWord*, max_plab_samples, mtGC); |
0 | 765 if (vec == NULL) { |
766 warning("Failed to allocate survivor plab array"); | |
767 for (int j = i; j > 0; j--) { | |
6197 | 768 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_plab_array[j-1].array(), mtGC); |
0 | 769 } |
6197 | 770 FREE_C_HEAP_ARRAY(ChunkArray, _survivor_plab_array, mtGC); |
771 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_chunk_array, mtGC); | |
0 | 772 _survivor_plab_array = NULL; |
773 _survivor_chunk_array = NULL; | |
774 _survivor_chunk_capacity = 0; | |
775 break; | |
776 } else { | |
777 ChunkArray* cur = | |
778 ::new (&_survivor_plab_array[i]) ChunkArray(vec, | |
779 max_plab_samples); | |
780 assert(cur->end() == 0, "Should be 0"); | |
781 assert(cur->array() == vec, "Should be vec"); | |
782 assert(cur->capacity() == max_plab_samples, "Error"); | |
783 } | |
784 } | |
785 } | |
786 } | |
787 assert( ( _survivor_plab_array != NULL | |
788 && _survivor_chunk_array != NULL) | |
789 || ( _survivor_chunk_capacity == 0 | |
790 && _survivor_chunk_index == 0), | |
791 "Error"); | |
792 | |
793 NOT_PRODUCT(_overflow_counter = CMSMarkStackOverflowInterval;) | |
794 _gc_counters = new CollectorCounters("CMS", 1); | |
795 _completed_initialization = true; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
796 _inter_sweep_timer.start(); // start of time |
0 | 797 } |
798 | |
799 const char* ConcurrentMarkSweepGeneration::name() const { | |
800 return "concurrent mark-sweep generation"; | |
801 } | |
802 void ConcurrentMarkSweepGeneration::update_counters() { | |
803 if (UsePerfData) { | |
804 _space_counters->update_all(); | |
805 _gen_counters->update_all(); | |
806 } | |
807 } | |
808 | |
809 // this is an optimized version of update_counters(). it takes the | |
810 // used value as a parameter rather than computing it. | |
811 // | |
812 void ConcurrentMarkSweepGeneration::update_counters(size_t used) { | |
813 if (UsePerfData) { | |
814 _space_counters->update_used(used); | |
815 _space_counters->update_capacity(); | |
816 _gen_counters->update_all(); | |
817 } | |
818 } | |
819 | |
820 void ConcurrentMarkSweepGeneration::print() const { | |
821 Generation::print(); | |
822 cmsSpace()->print(); | |
823 } | |
824 | |
825 #ifndef PRODUCT | |
826 void ConcurrentMarkSweepGeneration::print_statistics() { | |
827 cmsSpace()->printFLCensus(0); | |
828 } | |
829 #endif | |
830 | |
831 void ConcurrentMarkSweepGeneration::printOccupancy(const char *s) { | |
832 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
833 if (PrintGCDetails) { | |
834 if (Verbose) { | |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6885
diff
changeset
|
835 gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"("SIZE_FORMAT")]", |
0 | 836 level(), short_name(), s, used(), capacity()); |
837 } else { | |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6885
diff
changeset
|
838 gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"K("SIZE_FORMAT"K)]", |
0 | 839 level(), short_name(), s, used() / K, capacity() / K); |
840 } | |
841 } | |
842 if (Verbose) { | |
843 gclog_or_tty->print(" "SIZE_FORMAT"("SIZE_FORMAT")", | |
844 gch->used(), gch->capacity()); | |
845 } else { | |
846 gclog_or_tty->print(" "SIZE_FORMAT"K("SIZE_FORMAT"K)", | |
847 gch->used() / K, gch->capacity() / K); | |
848 } | |
849 } | |
850 | |
851 size_t | |
852 ConcurrentMarkSweepGeneration::contiguous_available() const { | |
853 // dld proposes an improvement in precision here. If the committed | |
854 // part of the space ends in a free block we should add that to | |
855 // uncommitted size in the calculation below. Will make this | |
856 // change later, staying with the approximation below for the | |
857 // time being. -- ysr. | |
858 return MAX2(_virtual_space.uncommitted_size(), unsafe_max_alloc_nogc()); | |
859 } | |
860 | |
861 size_t | |
862 ConcurrentMarkSweepGeneration::unsafe_max_alloc_nogc() const { | |
863 return _cmsSpace->max_alloc_in_words() * HeapWordSize; | |
864 } | |
865 | |
866 size_t ConcurrentMarkSweepGeneration::max_available() const { | |
867 return free() + _virtual_space.uncommitted_size(); | |
868 } | |
869 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
870 bool ConcurrentMarkSweepGeneration::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const { |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
871 size_t available = max_available(); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
872 size_t av_promo = (size_t)gc_stats()->avg_promoted()->padded_average(); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
873 bool res = (available >= av_promo) || (available >= max_promotion_in_bytes); |
1994
6cd6d394f280
7001033: assert(gch->gc_cause() == GCCause::_scavenge_alot || !gch->incremental_collection_failed())
ysr
parents:
1972
diff
changeset
|
874 if (Verbose && PrintGCDetails) { |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
875 gclog_or_tty->print_cr( |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
876 "CMS: promo attempt is%s safe: available("SIZE_FORMAT") %s av_promo("SIZE_FORMAT")," |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
877 "max_promo("SIZE_FORMAT")", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
878 res? "":" not", available, res? ">=":"<", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
879 av_promo, max_promotion_in_bytes); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
880 } |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
881 return res; |
0 | 882 } |
883 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
884 // At a promotion failure dump information on block layout in heap |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
885 // (cms old generation). |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
886 void ConcurrentMarkSweepGeneration::promotion_failure_occurred() { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
887 if (CMSDumpAtPromotionFailure) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
888 cmsSpace()->dump_at_safepoint_with_locks(collector(), gclog_or_tty); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
889 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
890 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
891 |
0 | 892 CompactibleSpace* |
893 ConcurrentMarkSweepGeneration::first_compaction_space() const { | |
894 return _cmsSpace; | |
895 } | |
896 | |
897 void ConcurrentMarkSweepGeneration::reset_after_compaction() { | |
898 // Clear the promotion information. These pointers can be adjusted | |
899 // along with all the other pointers into the heap but | |
900 // compaction is expected to be a rare event with | |
901 // a heap using cms so don't do it without seeing the need. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
902 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 903 for (uint i = 0; i < ParallelGCThreads; i++) { |
904 _par_gc_thread_states[i]->promo.reset(); | |
905 } | |
906 } | |
907 } | |
908 | |
909 void ConcurrentMarkSweepGeneration::space_iterate(SpaceClosure* blk, bool usedOnly) { | |
910 blk->do_space(_cmsSpace); | |
911 } | |
912 | |
913 void ConcurrentMarkSweepGeneration::compute_new_size() { | |
914 assert_locked_or_safepoint(Heap_lock); | |
915 | |
916 // If incremental collection failed, we just want to expand | |
917 // to the limit. | |
918 if (incremental_collection_failed()) { | |
919 clear_incremental_collection_failed(); | |
920 grow_to_reserved(); | |
921 return; | |
922 } | |
923 | |
10243
a9d568b7df60
8013032: CMS: assert(used() == used_after_gc && used_after_gc <= capacity()) failed: used: 0 used_after_gc: 292080 capacity: 1431699456
jmasa
parents:
10188
diff
changeset
|
924 // The heap has been compacted but not reset yet. |
a9d568b7df60
8013032: CMS: assert(used() == used_after_gc && used_after_gc <= capacity()) failed: used: 0 used_after_gc: 292080 capacity: 1431699456
jmasa
parents:
10188
diff
changeset
|
925 // Any metric such as free() or used() will be incorrect. |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
926 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
927 CardGeneration::compute_new_size(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
928 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
929 // Reset again after a possible resizing |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
930 if (did_compact()) { |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
931 cmsSpace()->reset_after_compaction(); |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
932 } |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
933 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
934 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
935 void ConcurrentMarkSweepGeneration::compute_new_size_free_list() { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
936 assert_locked_or_safepoint(Heap_lock); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
937 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
938 // If incremental collection failed, we just want to expand |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
939 // to the limit. |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
940 if (incremental_collection_failed()) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
941 clear_incremental_collection_failed(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
942 grow_to_reserved(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
943 return; |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
944 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
945 |
0 | 946 double free_percentage = ((double) free()) / capacity(); |
947 double desired_free_percentage = (double) MinHeapFreeRatio / 100; | |
948 double maximum_free_percentage = (double) MaxHeapFreeRatio / 100; | |
949 | |
950 // compute expansion delta needed for reaching desired free percentage | |
951 if (free_percentage < desired_free_percentage) { | |
952 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); | |
953 assert(desired_capacity >= capacity(), "invalid expansion size"); | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
954 size_t expand_bytes = MAX2(desired_capacity - capacity(), MinHeapDeltaBytes); |
0 | 955 if (PrintGCDetails && Verbose) { |
956 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); | |
957 gclog_or_tty->print_cr("\nFrom compute_new_size: "); | |
958 gclog_or_tty->print_cr(" Free fraction %f", free_percentage); | |
959 gclog_or_tty->print_cr(" Desired free fraction %f", | |
960 desired_free_percentage); | |
961 gclog_or_tty->print_cr(" Maximum free fraction %f", | |
962 maximum_free_percentage); | |
963 gclog_or_tty->print_cr(" Capactiy "SIZE_FORMAT, capacity()/1000); | |
964 gclog_or_tty->print_cr(" Desired capacity "SIZE_FORMAT, | |
965 desired_capacity/1000); | |
966 int prev_level = level() - 1; | |
967 if (prev_level >= 0) { | |
968 size_t prev_size = 0; | |
969 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
970 Generation* prev_gen = gch->_gens[prev_level]; | |
971 prev_size = prev_gen->capacity(); | |
972 gclog_or_tty->print_cr(" Younger gen size "SIZE_FORMAT, | |
973 prev_size/1000); | |
974 } | |
975 gclog_or_tty->print_cr(" unsafe_max_alloc_nogc "SIZE_FORMAT, | |
976 unsafe_max_alloc_nogc()/1000); | |
977 gclog_or_tty->print_cr(" contiguous available "SIZE_FORMAT, | |
978 contiguous_available()/1000); | |
979 gclog_or_tty->print_cr(" Expand by "SIZE_FORMAT" (bytes)", | |
980 expand_bytes); | |
981 } | |
982 // safe if expansion fails | |
983 expand(expand_bytes, 0, CMSExpansionCause::_satisfy_free_ratio); | |
984 if (PrintGCDetails && Verbose) { | |
985 gclog_or_tty->print_cr(" Expanded free fraction %f", | |
986 ((double) free()) / capacity()); | |
987 } | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
988 } else { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
989 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
990 assert(desired_capacity <= capacity(), "invalid expansion size"); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
991 size_t shrink_bytes = capacity() - desired_capacity; |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
992 // Don't shrink unless the delta is greater than the minimum shrink we want |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
993 if (shrink_bytes >= MinHeapDeltaBytes) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
994 shrink_free_list_by(shrink_bytes); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
995 } |
0 | 996 } |
997 } | |
998 | |
999 Mutex* ConcurrentMarkSweepGeneration::freelistLock() const { | |
1000 return cmsSpace()->freelistLock(); | |
1001 } | |
1002 | |
1003 HeapWord* ConcurrentMarkSweepGeneration::allocate(size_t size, | |
1004 bool tlab) { | |
1005 CMSSynchronousYieldRequest yr; | |
1006 MutexLockerEx x(freelistLock(), | |
1007 Mutex::_no_safepoint_check_flag); | |
1008 return have_lock_and_allocate(size, tlab); | |
1009 } | |
1010 | |
1011 HeapWord* ConcurrentMarkSweepGeneration::have_lock_and_allocate(size_t size, | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1012 bool tlab /* ignored */) { |
0 | 1013 assert_lock_strong(freelistLock()); |
1014 size_t adjustedSize = CompactibleFreeListSpace::adjustObjectSize(size); | |
1015 HeapWord* res = cmsSpace()->allocate(adjustedSize); | |
1016 // Allocate the object live (grey) if the background collector has | |
1017 // started marking. This is necessary because the marker may | |
1018 // have passed this address and consequently this object will | |
1019 // not otherwise be greyed and would be incorrectly swept up. | |
1020 // Note that if this object contains references, the writing | |
1021 // of those references will dirty the card containing this object | |
1022 // allowing the object to be blackened (and its references scanned) | |
1023 // either during a preclean phase or at the final checkpoint. | |
1024 if (res != NULL) { | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1025 // We may block here with an uninitialized object with |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1026 // its mark-bit or P-bits not yet set. Such objects need |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1027 // to be safely navigable by block_start(). |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1028 assert(oop(res)->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1029 assert(!((FreeChunk*)res)->is_free(), "Error, block will look free but show wrong size"); |
0 | 1030 collector()->direct_allocated(res, adjustedSize); |
1031 _direct_allocated_words += adjustedSize; | |
1032 // allocation counters | |
1033 NOT_PRODUCT( | |
1034 _numObjectsAllocated++; | |
1035 _numWordsAllocated += (int)adjustedSize; | |
1036 ) | |
1037 } | |
1038 return res; | |
1039 } | |
1040 | |
1041 // In the case of direct allocation by mutators in a generation that | |
1042 // is being concurrently collected, the object must be allocated | |
1043 // live (grey) if the background collector has started marking. | |
1044 // This is necessary because the marker may | |
1045 // have passed this address and consequently this object will | |
1046 // not otherwise be greyed and would be incorrectly swept up. | |
1047 // Note that if this object contains references, the writing | |
1048 // of those references will dirty the card containing this object | |
1049 // allowing the object to be blackened (and its references scanned) | |
1050 // either during a preclean phase or at the final checkpoint. | |
1051 void CMSCollector::direct_allocated(HeapWord* start, size_t size) { | |
1052 assert(_markBitMap.covers(start, size), "Out of bounds"); | |
1053 if (_collectorState >= Marking) { | |
1054 MutexLockerEx y(_markBitMap.lock(), | |
1055 Mutex::_no_safepoint_check_flag); | |
1056 // [see comments preceding SweepClosure::do_blk() below for details] | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1057 // |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1058 // Can the P-bits be deleted now? JJJ |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1059 // |
0 | 1060 // 1. need to mark the object as live so it isn't collected |
1061 // 2. need to mark the 2nd bit to indicate the object may be uninitialized | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1062 // 3. need to mark the end of the object so marking, precleaning or sweeping |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1063 // can skip over uninitialized or unparsable objects. An allocated |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1064 // object is considered uninitialized for our purposes as long as |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1065 // its klass word is NULL. All old gen objects are parsable |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1066 // as soon as they are initialized.) |
0 | 1067 _markBitMap.mark(start); // object is live |
1068 _markBitMap.mark(start + 1); // object is potentially uninitialized? | |
1069 _markBitMap.mark(start + size - 1); | |
1070 // mark end of object | |
1071 } | |
1072 // check that oop looks uninitialized | |
187 | 1073 assert(oop(start)->klass_or_null() == NULL, "_klass should be NULL"); |
0 | 1074 } |
1075 | |
1076 void CMSCollector::promoted(bool par, HeapWord* start, | |
1077 bool is_obj_array, size_t obj_size) { | |
1078 assert(_markBitMap.covers(start), "Out of bounds"); | |
1079 // See comment in direct_allocated() about when objects should | |
1080 // be allocated live. | |
1081 if (_collectorState >= Marking) { | |
1082 // we already hold the marking bit map lock, taken in | |
1083 // the prologue | |
1084 if (par) { | |
1085 _markBitMap.par_mark(start); | |
1086 } else { | |
1087 _markBitMap.mark(start); | |
1088 } | |
1089 // We don't need to mark the object as uninitialized (as | |
1090 // in direct_allocated above) because this is being done with the | |
1091 // world stopped and the object will be initialized by the | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1092 // time the marking, precleaning or sweeping get to look at it. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1093 // But see the code for copying objects into the CMS generation, |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1094 // where we need to ensure that concurrent readers of the |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1095 // block offset table are able to safely navigate a block that |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1096 // is in flux from being free to being allocated (and in |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1097 // transition while being copied into) and subsequently |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1098 // becoming a bona-fide object when the copy/promotion is complete. |
0 | 1099 assert(SafepointSynchronize::is_at_safepoint(), |
1100 "expect promotion only at safepoints"); | |
1101 | |
1102 if (_collectorState < Sweeping) { | |
1103 // Mark the appropriate cards in the modUnionTable, so that | |
1104 // this object gets scanned before the sweep. If this is | |
1105 // not done, CMS generation references in the object might | |
1106 // not get marked. | |
1107 // For the case of arrays, which are otherwise precisely | |
1108 // marked, we need to dirty the entire array, not just its head. | |
1109 if (is_obj_array) { | |
1110 // The [par_]mark_range() method expects mr.end() below to | |
1111 // be aligned to the granularity of a bit's representation | |
1112 // in the heap. In the case of the MUT below, that's a | |
1113 // card size. | |
1114 MemRegion mr(start, | |
1115 (HeapWord*)round_to((intptr_t)(start + obj_size), | |
1116 CardTableModRefBS::card_size /* bytes */)); | |
1117 if (par) { | |
1118 _modUnionTable.par_mark_range(mr); | |
1119 } else { | |
1120 _modUnionTable.mark_range(mr); | |
1121 } | |
1122 } else { // not an obj array; we can just mark the head | |
1123 if (par) { | |
1124 _modUnionTable.par_mark(start); | |
1125 } else { | |
1126 _modUnionTable.mark(start); | |
1127 } | |
1128 } | |
1129 } | |
1130 } | |
1131 } | |
1132 | |
1133 static inline size_t percent_of_space(Space* space, HeapWord* addr) | |
1134 { | |
1135 size_t delta = pointer_delta(addr, space->bottom()); | |
1136 return (size_t)(delta * 100.0 / (space->capacity() / HeapWordSize)); | |
1137 } | |
1138 | |
1139 void CMSCollector::icms_update_allocation_limits() | |
1140 { | |
1141 Generation* gen0 = GenCollectedHeap::heap()->get_gen(0); | |
1142 EdenSpace* eden = gen0->as_DefNewGeneration()->eden(); | |
1143 | |
1144 const unsigned int duty_cycle = stats().icms_update_duty_cycle(); | |
1145 if (CMSTraceIncrementalPacing) { | |
1146 stats().print(); | |
1147 } | |
1148 | |
1149 assert(duty_cycle <= 100, "invalid duty cycle"); | |
1150 if (duty_cycle != 0) { | |
1151 // The duty_cycle is a percentage between 0 and 100; convert to words and | |
1152 // then compute the offset from the endpoints of the space. | |
1153 size_t free_words = eden->free() / HeapWordSize; | |
1154 double free_words_dbl = (double)free_words; | |
1155 size_t duty_cycle_words = (size_t)(free_words_dbl * duty_cycle / 100.0); | |
1156 size_t offset_words = (free_words - duty_cycle_words) / 2; | |
1157 | |
1158 _icms_start_limit = eden->top() + offset_words; | |
1159 _icms_stop_limit = eden->end() - offset_words; | |
1160 | |
1161 // The limits may be adjusted (shifted to the right) by | |
1162 // CMSIncrementalOffset, to allow the application more mutator time after a | |
1163 // young gen gc (when all mutators were stopped) and before CMS starts and | |
1164 // takes away one or more cpus. | |
1165 if (CMSIncrementalOffset != 0) { | |
1166 double adjustment_dbl = free_words_dbl * CMSIncrementalOffset / 100.0; | |
1167 size_t adjustment = (size_t)adjustment_dbl; | |
1168 HeapWord* tmp_stop = _icms_stop_limit + adjustment; | |
1169 if (tmp_stop > _icms_stop_limit && tmp_stop < eden->end()) { | |
1170 _icms_start_limit += adjustment; | |
1171 _icms_stop_limit = tmp_stop; | |
1172 } | |
1173 } | |
1174 } | |
1175 if (duty_cycle == 0 || (_icms_start_limit == _icms_stop_limit)) { | |
1176 _icms_start_limit = _icms_stop_limit = eden->end(); | |
1177 } | |
1178 | |
1179 // Install the new start limit. | |
1180 eden->set_soft_end(_icms_start_limit); | |
1181 | |
1182 if (CMSTraceIncrementalMode) { | |
1183 gclog_or_tty->print(" icms alloc limits: " | |
1184 PTR_FORMAT "," PTR_FORMAT | |
1185 " (" SIZE_FORMAT "%%," SIZE_FORMAT "%%) ", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1186 p2i(_icms_start_limit), p2i(_icms_stop_limit), |
0 | 1187 percent_of_space(eden, _icms_start_limit), |
1188 percent_of_space(eden, _icms_stop_limit)); | |
1189 if (Verbose) { | |
1190 gclog_or_tty->print("eden: "); | |
1191 eden->print_on(gclog_or_tty); | |
1192 } | |
1193 } | |
1194 } | |
1195 | |
1196 // Any changes here should try to maintain the invariant | |
1197 // that if this method is called with _icms_start_limit | |
1198 // and _icms_stop_limit both NULL, then it should return NULL | |
1199 // and not notify the icms thread. | |
1200 HeapWord* | |
1201 CMSCollector::allocation_limit_reached(Space* space, HeapWord* top, | |
1202 size_t word_size) | |
1203 { | |
1204 // A start_limit equal to end() means the duty cycle is 0, so treat that as a | |
1205 // nop. | |
1206 if (CMSIncrementalMode && _icms_start_limit != space->end()) { | |
1207 if (top <= _icms_start_limit) { | |
1208 if (CMSTraceIncrementalMode) { | |
1209 space->print_on(gclog_or_tty); | |
1210 gclog_or_tty->stamp(); | |
1211 gclog_or_tty->print_cr(" start limit top=" PTR_FORMAT | |
1212 ", new limit=" PTR_FORMAT | |
1213 " (" SIZE_FORMAT "%%)", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1214 p2i(top), p2i(_icms_stop_limit), |
0 | 1215 percent_of_space(space, _icms_stop_limit)); |
1216 } | |
1217 ConcurrentMarkSweepThread::start_icms(); | |
1218 assert(top < _icms_stop_limit, "Tautology"); | |
1219 if (word_size < pointer_delta(_icms_stop_limit, top)) { | |
1220 return _icms_stop_limit; | |
1221 } | |
1222 | |
1223 // The allocation will cross both the _start and _stop limits, so do the | |
1224 // stop notification also and return end(). | |
1225 if (CMSTraceIncrementalMode) { | |
1226 space->print_on(gclog_or_tty); | |
1227 gclog_or_tty->stamp(); | |
1228 gclog_or_tty->print_cr(" +stop limit top=" PTR_FORMAT | |
1229 ", new limit=" PTR_FORMAT | |
1230 " (" SIZE_FORMAT "%%)", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1231 p2i(top), p2i(space->end()), |
0 | 1232 percent_of_space(space, space->end())); |
1233 } | |
1234 ConcurrentMarkSweepThread::stop_icms(); | |
1235 return space->end(); | |
1236 } | |
1237 | |
1238 if (top <= _icms_stop_limit) { | |
1239 if (CMSTraceIncrementalMode) { | |
1240 space->print_on(gclog_or_tty); | |
1241 gclog_or_tty->stamp(); | |
1242 gclog_or_tty->print_cr(" stop limit top=" PTR_FORMAT | |
1243 ", new limit=" PTR_FORMAT | |
1244 " (" SIZE_FORMAT "%%)", | |
1245 top, space->end(), | |
1246 percent_of_space(space, space->end())); | |
1247 } | |
1248 ConcurrentMarkSweepThread::stop_icms(); | |
1249 return space->end(); | |
1250 } | |
1251 | |
1252 if (CMSTraceIncrementalMode) { | |
1253 space->print_on(gclog_or_tty); | |
1254 gclog_or_tty->stamp(); | |
1255 gclog_or_tty->print_cr(" end limit top=" PTR_FORMAT | |
1256 ", new limit=" PTR_FORMAT, | |
1257 top, NULL); | |
1258 } | |
1259 } | |
1260 | |
1261 return NULL; | |
1262 } | |
1263 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1264 oop ConcurrentMarkSweepGeneration::promote(oop obj, size_t obj_size) { |
0 | 1265 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
1266 // allocate, copy and if necessary update promoinfo -- | |
1267 // delegate to underlying space. | |
1268 assert_lock_strong(freelistLock()); | |
1269 | |
1270 #ifndef PRODUCT | |
1271 if (Universe::heap()->promotion_should_fail()) { | |
1272 return NULL; | |
1273 } | |
1274 #endif // #ifndef PRODUCT | |
1275 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1276 oop res = _cmsSpace->promote(obj, obj_size); |
0 | 1277 if (res == NULL) { |
1278 // expand and retry | |
1279 size_t s = _cmsSpace->expansionSpaceRequired(obj_size); // HeapWords | |
1280 expand(s*HeapWordSize, MinHeapDeltaBytes, | |
1281 CMSExpansionCause::_satisfy_promotion); | |
1282 // Since there's currently no next generation, we don't try to promote | |
1283 // into a more senior generation. | |
1284 assert(next_gen() == NULL, "assumption, based upon which no attempt " | |
1285 "is made to pass on a possibly failing " | |
1286 "promotion to next generation"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1287 res = _cmsSpace->promote(obj, obj_size); |
0 | 1288 } |
1289 if (res != NULL) { | |
1290 // See comment in allocate() about when objects should | |
1291 // be allocated live. | |
1292 assert(obj->is_oop(), "Will dereference klass pointer below"); | |
1293 collector()->promoted(false, // Not parallel | |
1294 (HeapWord*)res, obj->is_objArray(), obj_size); | |
1295 // promotion counters | |
1296 NOT_PRODUCT( | |
1297 _numObjectsPromoted++; | |
1298 _numWordsPromoted += | |
1299 (int)(CompactibleFreeListSpace::adjustObjectSize(obj->size())); | |
1300 ) | |
1301 } | |
1302 return res; | |
1303 } | |
1304 | |
1305 | |
1306 HeapWord* | |
1307 ConcurrentMarkSweepGeneration::allocation_limit_reached(Space* space, | |
1308 HeapWord* top, | |
1309 size_t word_sz) | |
1310 { | |
1311 return collector()->allocation_limit_reached(space, top, word_sz); | |
1312 } | |
1313 | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1314 // IMPORTANT: Notes on object size recognition in CMS. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1315 // --------------------------------------------------- |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1316 // A block of storage in the CMS generation is always in |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1317 // one of three states. A free block (FREE), an allocated |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1318 // object (OBJECT) whose size() method reports the correct size, |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1319 // and an intermediate state (TRANSIENT) in which its size cannot |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1320 // be accurately determined. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1321 // STATE IDENTIFICATION: (32 bit and 64 bit w/o COOPS) |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1322 // ----------------------------------------------------- |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1323 // FREE: klass_word & 1 == 1; mark_word holds block size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1324 // |
1777
179464550c7d
6983930: CMS: Various small cleanups ca September 2010
ysr
parents:
1720
diff
changeset
|
1325 // OBJECT: klass_word installed; klass_word != 0 && klass_word & 1 == 0; |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1326 // obj->size() computes correct size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1327 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1328 // TRANSIENT: klass_word == 0; size is indeterminate until we become an OBJECT |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1329 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1330 // STATE IDENTIFICATION: (64 bit+COOPS) |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1331 // ------------------------------------ |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1332 // FREE: mark_word & CMS_FREE_BIT == 1; mark_word & ~CMS_FREE_BIT gives block_size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1333 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1334 // OBJECT: klass_word installed; klass_word != 0; |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1335 // obj->size() computes correct size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1336 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1337 // TRANSIENT: klass_word == 0; size is indeterminate until we become an OBJECT |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1338 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1339 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1340 // STATE TRANSITION DIAGRAM |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1341 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1342 // mut / parnew mut / parnew |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1343 // FREE --------------------> TRANSIENT ---------------------> OBJECT --| |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1344 // ^ | |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1345 // |------------------------ DEAD <------------------------------------| |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1346 // sweep mut |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1347 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1348 // While a block is in TRANSIENT state its size cannot be determined |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1349 // so readers will either need to come back later or stall until |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1350 // the size can be determined. Note that for the case of direct |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1351 // allocation, P-bits, when available, may be used to determine the |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1352 // size of an object that may not yet have been initialized. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1353 |
0 | 1354 // Things to support parallel young-gen collection. |
1355 oop | |
1356 ConcurrentMarkSweepGeneration::par_promote(int thread_num, | |
1357 oop old, markOop m, | |
1358 size_t word_sz) { | |
1359 #ifndef PRODUCT | |
1360 if (Universe::heap()->promotion_should_fail()) { | |
1361 return NULL; | |
1362 } | |
1363 #endif // #ifndef PRODUCT | |
1364 | |
1365 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1366 PromotionInfo* promoInfo = &ps->promo; | |
1367 // if we are tracking promotions, then first ensure space for | |
1368 // promotion (including spooling space for saving header if necessary). | |
1369 // then allocate and copy, then track promoted info if needed. | |
1370 // When tracking (see PromotionInfo::track()), the mark word may | |
1371 // be displaced and in this case restoration of the mark word | |
1372 // occurs in the (oop_since_save_marks_)iterate phase. | |
1373 if (promoInfo->tracking() && !promoInfo->ensure_spooling_space()) { | |
1374 // Out of space for allocating spooling buffers; | |
1375 // try expanding and allocating spooling buffers. | |
1376 if (!expand_and_ensure_spooling_space(promoInfo)) { | |
1377 return NULL; | |
1378 } | |
1379 } | |
1380 assert(promoInfo->has_spooling_space(), "Control point invariant"); | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1381 const size_t alloc_sz = CompactibleFreeListSpace::adjustObjectSize(word_sz); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1382 HeapWord* obj_ptr = ps->lab.alloc(alloc_sz); |
0 | 1383 if (obj_ptr == NULL) { |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1384 obj_ptr = expand_and_par_lab_allocate(ps, alloc_sz); |
0 | 1385 if (obj_ptr == NULL) { |
1386 return NULL; | |
1387 } | |
1388 } | |
1389 oop obj = oop(obj_ptr); | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1390 OrderAccess::storestore(); |
187 | 1391 assert(obj->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1392 assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size"); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1393 // IMPORTANT: See note on object initialization for CMS above. |
0 | 1394 // Otherwise, copy the object. Here we must be careful to insert the |
1395 // klass pointer last, since this marks the block as an allocated object. | |
187 | 1396 // Except with compressed oops it's the mark word. |
0 | 1397 HeapWord* old_ptr = (HeapWord*)old; |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1398 // Restore the mark word copied above. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1399 obj->set_mark(m); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1400 assert(obj->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1401 assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size"); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1402 OrderAccess::storestore(); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1403 |
12226
7944aba7ba41
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
12112
diff
changeset
|
1404 if (UseCompressedClassPointers) { |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1405 // Copy gap missed by (aligned) header size calculation below |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1406 obj->set_klass_gap(old->klass_gap()); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1407 } |
0 | 1408 if (word_sz > (size_t)oopDesc::header_size()) { |
1409 Copy::aligned_disjoint_words(old_ptr + oopDesc::header_size(), | |
1410 obj_ptr + oopDesc::header_size(), | |
1411 word_sz - oopDesc::header_size()); | |
1412 } | |
187 | 1413 |
0 | 1414 // Now we can track the promoted object, if necessary. We take care |
1521 | 1415 // to delay the transition from uninitialized to full object |
0 | 1416 // (i.e., insertion of klass pointer) until after, so that it |
1417 // atomically becomes a promoted object. | |
1418 if (promoInfo->tracking()) { | |
1419 promoInfo->track((PromotedObject*)obj, old->klass()); | |
1420 } | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1421 assert(obj->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1422 assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size"); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1423 assert(old->is_oop(), "Will use and dereference old klass ptr below"); |
187 | 1424 |
1425 // Finally, install the klass pointer (this should be volatile). | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1426 OrderAccess::storestore(); |
0 | 1427 obj->set_klass(old->klass()); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1428 // We should now be able to calculate the right size for this object |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1429 assert(obj->is_oop() && obj->size() == (int)word_sz, "Error, incorrect size computed for promoted object"); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1430 |
0 | 1431 collector()->promoted(true, // parallel |
1432 obj_ptr, old->is_objArray(), word_sz); | |
1433 | |
1434 NOT_PRODUCT( | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1435 Atomic::inc_ptr(&_numObjectsPromoted); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1436 Atomic::add_ptr(alloc_sz, &_numWordsPromoted); |
0 | 1437 ) |
1438 | |
1439 return obj; | |
1440 } | |
1441 | |
1442 void | |
1443 ConcurrentMarkSweepGeneration:: | |
1444 par_promote_alloc_undo(int thread_num, | |
1445 HeapWord* obj, size_t word_sz) { | |
1446 // CMS does not support promotion undo. | |
1447 ShouldNotReachHere(); | |
1448 } | |
1449 | |
1450 void | |
1451 ConcurrentMarkSweepGeneration:: | |
1452 par_promote_alloc_done(int thread_num) { | |
1453 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
1454 ps->lab.retire(thread_num); |
0 | 1455 } |
1456 | |
1457 void | |
1458 ConcurrentMarkSweepGeneration:: | |
1459 par_oop_since_save_marks_iterate_done(int thread_num) { | |
1460 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1461 ParScanWithoutBarrierClosure* dummy_cl = NULL; | |
1462 ps->promo.promoted_oops_iterate_nv(dummy_cl); | |
1463 } | |
1464 | |
1465 bool ConcurrentMarkSweepGeneration::should_collect(bool full, | |
1466 size_t size, | |
1467 bool tlab) | |
1468 { | |
1469 // We allow a STW collection only if a full | |
1470 // collection was requested. | |
1471 return full || should_allocate(size, tlab); // FIX ME !!! | |
1472 // This and promotion failure handling are connected at the | |
1473 // hip and should be fixed by untying them. | |
1474 } | |
1475 | |
1476 bool CMSCollector::shouldConcurrentCollect() { | |
1477 if (_full_gc_requested) { | |
1478 if (Verbose && PrintGCDetails) { | |
1479 gclog_or_tty->print_cr("CMSCollector: collect because of explicit " | |
1520
bb843ebc7c55
6919638: CMS: ExplicitGCInvokesConcurrent misinteracts with gc locker
ysr
parents:
1518
diff
changeset
|
1480 " gc request (or gc_locker)"); |
0 | 1481 } |
1482 return true; | |
1483 } | |
1484 | |
1485 // For debugging purposes, change the type of collection. | |
1486 // If the rotation is not on the concurrent collection | |
1487 // type, don't start a concurrent collection. | |
1488 NOT_PRODUCT( | |
1489 if (RotateCMSCollectionTypes && | |
1490 (_cmsGen->debug_collection_type() != | |
1491 ConcurrentMarkSweepGeneration::Concurrent_collection_type)) { | |
1492 assert(_cmsGen->debug_collection_type() != | |
1493 ConcurrentMarkSweepGeneration::Unknown_collection_type, | |
1494 "Bad cms collection type"); | |
1495 return false; | |
1496 } | |
1497 ) | |
1498 | |
1499 FreelistLocker x(this); | |
1500 // ------------------------------------------------------------------ | |
1501 // Print out lots of information which affects the initiation of | |
1502 // a collection. | |
1503 if (PrintCMSInitiationStatistics && stats().valid()) { | |
1504 gclog_or_tty->print("CMSCollector shouldConcurrentCollect: "); | |
1505 gclog_or_tty->stamp(); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1506 gclog_or_tty->cr(); |
0 | 1507 stats().print_on(gclog_or_tty); |
1508 gclog_or_tty->print_cr("time_until_cms_gen_full %3.7f", | |
1509 stats().time_until_cms_gen_full()); | |
1510 gclog_or_tty->print_cr("free="SIZE_FORMAT, _cmsGen->free()); | |
1511 gclog_or_tty->print_cr("contiguous_available="SIZE_FORMAT, | |
1512 _cmsGen->contiguous_available()); | |
1513 gclog_or_tty->print_cr("promotion_rate=%g", stats().promotion_rate()); | |
1514 gclog_or_tty->print_cr("cms_allocation_rate=%g", stats().cms_allocation_rate()); | |
1515 gclog_or_tty->print_cr("occupancy=%3.7f", _cmsGen->occupancy()); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1516 gclog_or_tty->print_cr("initiatingOccupancy=%3.7f", _cmsGen->initiating_occupancy()); |
20326
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1517 gclog_or_tty->print_cr("cms_time_since_begin=%3.7f", stats().cms_time_since_begin()); |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1518 gclog_or_tty->print_cr("cms_time_since_end=%3.7f", stats().cms_time_since_end()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1519 gclog_or_tty->print_cr("metadata initialized %d", |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1520 MetaspaceGC::should_concurrent_collect()); |
0 | 1521 } |
1522 // ------------------------------------------------------------------ | |
1523 | |
1524 // If the estimated time to complete a cms collection (cms_duration()) | |
1525 // is less than the estimated time remaining until the cms generation | |
1526 // is full, start a collection. | |
1527 if (!UseCMSInitiatingOccupancyOnly) { | |
1528 if (stats().valid()) { | |
1529 if (stats().time_until_cms_start() == 0.0) { | |
1530 return true; | |
1531 } | |
1532 } else { | |
1533 // We want to conservatively collect somewhat early in order | |
1534 // to try and "bootstrap" our CMS/promotion statistics; | |
1535 // this branch will not fire after the first successful CMS | |
1536 // collection because the stats should then be valid. | |
1537 if (_cmsGen->occupancy() >= _bootstrap_occupancy) { | |
1538 if (Verbose && PrintGCDetails) { | |
1539 gclog_or_tty->print_cr( | |
1540 " CMSCollector: collect for bootstrapping statistics:" | |
1541 " occupancy = %f, boot occupancy = %f", _cmsGen->occupancy(), | |
1542 _bootstrap_occupancy); | |
1543 } | |
1544 return true; | |
1545 } | |
1546 } | |
1547 } | |
1548 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1549 // Otherwise, we start a collection cycle if |
0 | 1550 // old gen want a collection cycle started. Each may use |
1551 // an appropriate criterion for making this decision. | |
1552 // XXX We need to make sure that the gen expansion | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1553 // criterion dovetails well with this. XXX NEED TO FIX THIS |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1554 if (_cmsGen->should_concurrent_collect()) { |
0 | 1555 if (Verbose && PrintGCDetails) { |
1556 gclog_or_tty->print_cr("CMS old gen initiated"); | |
1557 } | |
1558 return true; | |
1559 } | |
1560 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1561 // We start a collection if we believe an incremental collection may fail; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1562 // this is not likely to be productive in practice because it's probably too |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1563 // late anyway. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1564 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1565 assert(gch->collector_policy()->is_two_generation_policy(), |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1566 "You may want to check the correctness of the following"); |
1994
6cd6d394f280
7001033: assert(gch->gc_cause() == GCCause::_scavenge_alot || !gch->incremental_collection_failed())
ysr
parents:
1972
diff
changeset
|
1567 if (gch->incremental_collection_will_fail(true /* consult_young */)) { |
6cd6d394f280
7001033: assert(gch->gc_cause() == GCCause::_scavenge_alot || !gch->incremental_collection_failed())
ysr
parents:
1972
diff
changeset
|
1568 if (Verbose && PrintGCDetails) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1569 gclog_or_tty->print("CMSCollector: collect because incremental collection will fail "); |
0 | 1570 } |
1571 return true; | |
1572 } | |
1573 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1574 if (MetaspaceGC::should_concurrent_collect()) { |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1575 if (Verbose && PrintGCDetails) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1576 gclog_or_tty->print("CMSCollector: collect for metadata allocation "); |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1577 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1578 return true; |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1579 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1580 |
20326
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1581 // CMSTriggerInterval starts a CMS cycle if enough time has passed. |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1582 if (CMSTriggerInterval >= 0) { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1583 if (CMSTriggerInterval == 0) { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1584 // Trigger always |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1585 return true; |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1586 } |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1587 |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1588 // Check the CMS time since begin (we do not check the stats validity |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1589 // as we want to be able to trigger the first CMS cycle as well) |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1590 if (stats().cms_time_since_begin() >= (CMSTriggerInterval / ((double) MILLIUNITS))) { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1591 if (Verbose && PrintGCDetails) { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1592 if (stats().valid()) { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1593 gclog_or_tty->print_cr("CMSCollector: collect because of trigger interval (time since last begin %3.7f secs)", |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1594 stats().cms_time_since_begin()); |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1595 } else { |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1596 gclog_or_tty->print_cr("CMSCollector: collect because of trigger interval (first collection)"); |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1597 } |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1598 } |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1599 return true; |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1600 } |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1601 } |
da00a41842a5
8038265: CMS: enable time based triggering of concurrent cycles
brutisso
parents:
20297
diff
changeset
|
1602 |
0 | 1603 return false; |
1604 } | |
1605 | |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1606 void CMSCollector::set_did_compact(bool v) { _cmsGen->set_did_compact(v); } |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1607 |
0 | 1608 // Clear _expansion_cause fields of constituent generations |
1609 void CMSCollector::clear_expansion_cause() { | |
1610 _cmsGen->clear_expansion_cause(); | |
1611 } | |
1612 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1613 // We should be conservative in starting a collection cycle. To |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1614 // start too eagerly runs the risk of collecting too often in the |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1615 // extreme. To collect too rarely falls back on full collections, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1616 // which works, even if not optimum in terms of concurrent work. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1617 // As a work around for too eagerly collecting, use the flag |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1618 // UseCMSInitiatingOccupancyOnly. This also has the advantage of |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1619 // giving the user an easily understandable way of controlling the |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1620 // collections. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1621 // We want to start a new collection cycle if any of the following |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1622 // conditions hold: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1623 // . our current occupancy exceeds the configured initiating occupancy |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1624 // for this generation, or |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1625 // . we recently needed to expand this space and have not, since that |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1626 // expansion, done a collection of this generation, or |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1627 // . the underlying space believes that it may be a good idea to initiate |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1628 // a concurrent collection (this may be based on criteria such as the |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1629 // following: the space uses linear allocation and linear allocation is |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1630 // going to fail, or there is believed to be excessive fragmentation in |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1631 // the generation, etc... or ... |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1632 // [.(currently done by CMSCollector::shouldConcurrentCollect() only for |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1633 // the case of the old generation; see CR 6543076): |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1634 // we may be approaching a point at which allocation requests may fail because |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1635 // we will be out of sufficient free space given allocation rate estimates.] |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1636 bool ConcurrentMarkSweepGeneration::should_concurrent_collect() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1637 |
0 | 1638 assert_lock_strong(freelistLock()); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1639 if (occupancy() > initiating_occupancy()) { |
0 | 1640 if (PrintGCDetails && Verbose) { |
1641 gclog_or_tty->print(" %s: collect because of occupancy %f / %f ", | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1642 short_name(), occupancy(), initiating_occupancy()); |
0 | 1643 } |
1644 return true; | |
1645 } | |
1646 if (UseCMSInitiatingOccupancyOnly) { | |
1647 return false; | |
1648 } | |
1649 if (expansion_cause() == CMSExpansionCause::_satisfy_allocation) { | |
1650 if (PrintGCDetails && Verbose) { | |
1651 gclog_or_tty->print(" %s: collect because expanded for allocation ", | |
1652 short_name()); | |
1653 } | |
1654 return true; | |
1655 } | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1656 if (_cmsSpace->should_concurrent_collect()) { |
0 | 1657 if (PrintGCDetails && Verbose) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1658 gclog_or_tty->print(" %s: collect because cmsSpace says so ", |
0 | 1659 short_name()); |
1660 } | |
1661 return true; | |
1662 } | |
1663 return false; | |
1664 } | |
1665 | |
1666 void ConcurrentMarkSweepGeneration::collect(bool full, | |
1667 bool clear_all_soft_refs, | |
1668 size_t size, | |
1669 bool tlab) | |
1670 { | |
1671 collector()->collect(full, clear_all_soft_refs, size, tlab); | |
1672 } | |
1673 | |
1674 void CMSCollector::collect(bool full, | |
1675 bool clear_all_soft_refs, | |
1676 size_t size, | |
1677 bool tlab) | |
1678 { | |
1679 if (!UseCMSCollectionPassing && _collectorState > Idling) { | |
1680 // For debugging purposes skip the collection if the state | |
1681 // is not currently idle | |
1682 if (TraceCMSState) { | |
1683 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " skipped full:%d CMS state %d", | |
1684 Thread::current(), full, _collectorState); | |
1685 } | |
1686 return; | |
1687 } | |
1688 | |
1689 // The following "if" branch is present for defensive reasons. | |
1690 // In the current uses of this interface, it can be replaced with: | |
1691 // assert(!GC_locker.is_active(), "Can't be called otherwise"); | |
1692 // But I am not placing that assert here to allow future | |
1693 // generality in invoking this interface. | |
1694 if (GC_locker::is_active()) { | |
1695 // A consistency test for GC_locker | |
1696 assert(GC_locker::needs_gc(), "Should have been set already"); | |
1697 // Skip this foreground collection, instead | |
1698 // expanding the heap if necessary. | |
1699 // Need the free list locks for the call to free() in compute_new_size() | |
1700 compute_new_size(); | |
1701 return; | |
1702 } | |
1703 acquire_control_and_collect(full, clear_all_soft_refs); | |
1704 _full_gcs_since_conc_gc++; | |
1705 } | |
1706 | |
10405 | 1707 void CMSCollector::request_full_gc(unsigned int full_gc_count, GCCause::Cause cause) { |
0 | 1708 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
1709 unsigned int gc_count = gch->total_full_collections(); | |
1710 if (gc_count == full_gc_count) { | |
1711 MutexLockerEx y(CGC_lock, Mutex::_no_safepoint_check_flag); | |
1712 _full_gc_requested = true; | |
10405 | 1713 _full_gc_cause = cause; |
0 | 1714 CGC_lock->notify(); // nudge CMS thread |
2365
a181f3a124dd
6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents:
2226
diff
changeset
|
1715 } else { |
a181f3a124dd
6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents:
2226
diff
changeset
|
1716 assert(gc_count > full_gc_count, "Error: causal loop"); |
0 | 1717 } |
1718 } | |
1719 | |
10405 | 1720 bool CMSCollector::is_external_interruption() { |
1721 GCCause::Cause cause = GenCollectedHeap::heap()->gc_cause(); | |
1722 return GCCause::is_user_requested_gc(cause) || | |
1723 GCCause::is_serviceability_requested_gc(cause); | |
1724 } | |
1725 | |
1726 void CMSCollector::report_concurrent_mode_interruption() { | |
1727 if (is_external_interruption()) { | |
1728 if (PrintGCDetails) { | |
1729 gclog_or_tty->print(" (concurrent mode interrupted)"); | |
1730 } | |
1731 } else { | |
1732 if (PrintGCDetails) { | |
1733 gclog_or_tty->print(" (concurrent mode failure)"); | |
1734 } | |
1735 _gc_tracer_cm->report_concurrent_mode_failure(); | |
1736 } | |
1737 } | |
1738 | |
0 | 1739 |
1740 // The foreground and background collectors need to coordinate in order | |
1741 // to make sure that they do not mutually interfere with CMS collections. | |
1742 // When a background collection is active, | |
1743 // the foreground collector may need to take over (preempt) and | |
1744 // synchronously complete an ongoing collection. Depending on the | |
1745 // frequency of the background collections and the heap usage | |
1746 // of the application, this preemption can be seldom or frequent. | |
1747 // There are only certain | |
1748 // points in the background collection that the "collection-baton" | |
1749 // can be passed to the foreground collector. | |
1750 // | |
1751 // The foreground collector will wait for the baton before | |
1752 // starting any part of the collection. The foreground collector | |
1753 // will only wait at one location. | |
1754 // | |
1755 // The background collector will yield the baton before starting a new | |
1756 // phase of the collection (e.g., before initial marking, marking from roots, | |
1757 // precleaning, final re-mark, sweep etc.) This is normally done at the head | |
1758 // of the loop which switches the phases. The background collector does some | |
1759 // of the phases (initial mark, final re-mark) with the world stopped. | |
1760 // Because of locking involved in stopping the world, | |
1761 // the foreground collector should not block waiting for the background | |
1762 // collector when it is doing a stop-the-world phase. The background | |
1763 // collector will yield the baton at an additional point just before | |
1764 // it enters a stop-the-world phase. Once the world is stopped, the | |
1765 // background collector checks the phase of the collection. If the | |
1766 // phase has not changed, it proceeds with the collection. If the | |
1767 // phase has changed, it skips that phase of the collection. See | |
1768 // the comments on the use of the Heap_lock in collect_in_background(). | |
1769 // | |
1770 // Variable used in baton passing. | |
1771 // _foregroundGCIsActive - Set to true by the foreground collector when | |
1772 // it wants the baton. The foreground clears it when it has finished | |
1773 // the collection. | |
1774 // _foregroundGCShouldWait - Set to true by the background collector | |
1775 // when it is running. The foreground collector waits while | |
1776 // _foregroundGCShouldWait is true. | |
1777 // CGC_lock - monitor used to protect access to the above variables | |
1778 // and to notify the foreground and background collectors. | |
1779 // _collectorState - current state of the CMS collection. | |
1780 // | |
1781 // The foreground collector | |
1782 // acquires the CGC_lock | |
1783 // sets _foregroundGCIsActive | |
1784 // waits on the CGC_lock for _foregroundGCShouldWait to be false | |
1785 // various locks acquired in preparation for the collection | |
1786 // are released so as not to block the background collector | |
1787 // that is in the midst of a collection | |
1788 // proceeds with the collection | |
1789 // clears _foregroundGCIsActive | |
1790 // returns | |
1791 // | |
1792 // The background collector in a loop iterating on the phases of the | |
1793 // collection | |
1794 // acquires the CGC_lock | |
1795 // sets _foregroundGCShouldWait | |
1796 // if _foregroundGCIsActive is set | |
1797 // clears _foregroundGCShouldWait, notifies _CGC_lock | |
1798 // waits on _CGC_lock for _foregroundGCIsActive to become false | |
1799 // and exits the loop. | |
1800 // otherwise | |
1801 // proceed with that phase of the collection | |
1802 // if the phase is a stop-the-world phase, | |
1803 // yield the baton once more just before enqueueing | |
1804 // the stop-world CMS operation (executed by the VM thread). | |
1805 // returns after all phases of the collection are done | |
1806 // | |
1807 | |
1808 void CMSCollector::acquire_control_and_collect(bool full, | |
1809 bool clear_all_soft_refs) { | |
1810 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | |
1811 assert(!Thread::current()->is_ConcurrentGC_thread(), | |
1812 "shouldn't try to acquire control from self!"); | |
1813 | |
1814 // Start the protocol for acquiring control of the | |
1815 // collection from the background collector (aka CMS thread). | |
1816 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
1817 "VM thread should have CMS token"); | |
1818 // Remember the possibly interrupted state of an ongoing | |
1819 // concurrent collection | |
1820 CollectorState first_state = _collectorState; | |
1821 | |
1822 // Signal to a possibly ongoing concurrent collection that | |
1823 // we want to do a foreground collection. | |
1824 _foregroundGCIsActive = true; | |
1825 | |
1826 // Disable incremental mode during a foreground collection. | |
1827 ICMSDisabler icms_disabler; | |
1828 | |
1829 // release locks and wait for a notify from the background collector | |
1830 // releasing the locks in only necessary for phases which | |
1831 // do yields to improve the granularity of the collection. | |
1832 assert_lock_strong(bitMapLock()); | |
1833 // We need to lock the Free list lock for the space that we are | |
1834 // currently collecting. | |
1835 assert(haveFreelistLocks(), "Must be holding free list locks"); | |
1836 bitMapLock()->unlock(); | |
1837 releaseFreelistLocks(); | |
1838 { | |
1839 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
1840 if (_foregroundGCShouldWait) { | |
1841 // We are going to be waiting for action for the CMS thread; | |
1842 // it had better not be gone (for instance at shutdown)! | |
1843 assert(ConcurrentMarkSweepThread::cmst() != NULL, | |
1844 "CMS thread must be running"); | |
1845 // Wait here until the background collector gives us the go-ahead | |
1846 ConcurrentMarkSweepThread::clear_CMS_flag( | |
1847 ConcurrentMarkSweepThread::CMS_vm_has_token); // release token | |
1848 // Get a possibly blocked CMS thread going: | |
1849 // Note that we set _foregroundGCIsActive true above, | |
1850 // without protection of the CGC_lock. | |
1851 CGC_lock->notify(); | |
1852 assert(!ConcurrentMarkSweepThread::vm_thread_wants_cms_token(), | |
1853 "Possible deadlock"); | |
1854 while (_foregroundGCShouldWait) { | |
1855 // wait for notification | |
1856 CGC_lock->wait(Mutex::_no_safepoint_check_flag); | |
1857 // Possibility of delay/starvation here, since CMS token does | |
1858 // not know to give priority to VM thread? Actually, i think | |
1859 // there wouldn't be any delay/starvation, but the proof of | |
1860 // that "fact" (?) appears non-trivial. XXX 20011219YSR | |
1861 } | |
1862 ConcurrentMarkSweepThread::set_CMS_flag( | |
1863 ConcurrentMarkSweepThread::CMS_vm_has_token); | |
1864 } | |
1865 } | |
1866 // The CMS_token is already held. Get back the other locks. | |
1867 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
1868 "VM thread should have CMS token"); | |
1869 getFreelistLocks(); | |
1870 bitMapLock()->lock_without_safepoint_check(); | |
1871 if (TraceCMSState) { | |
1872 gclog_or_tty->print_cr("CMS foreground collector has asked for control " | |
1873 INTPTR_FORMAT " with first state %d", Thread::current(), first_state); | |
1874 gclog_or_tty->print_cr(" gets control with state %d", _collectorState); | |
1875 } | |
1876 | |
1877 // Check if we need to do a compaction, or if not, whether | |
1878 // we need to start the mark-sweep from scratch. | |
1879 bool should_compact = false; | |
1880 bool should_start_over = false; | |
1881 decide_foreground_collection_type(clear_all_soft_refs, | |
1882 &should_compact, &should_start_over); | |
1883 | |
1884 NOT_PRODUCT( | |
1885 if (RotateCMSCollectionTypes) { | |
1886 if (_cmsGen->debug_collection_type() == | |
1887 ConcurrentMarkSweepGeneration::MSC_foreground_collection_type) { | |
1888 should_compact = true; | |
1889 } else if (_cmsGen->debug_collection_type() == | |
1890 ConcurrentMarkSweepGeneration::MS_foreground_collection_type) { | |
1891 should_compact = false; | |
1892 } | |
1893 } | |
1894 ) | |
1895 | |
10405 | 1896 if (first_state > Idling) { |
1897 report_concurrent_mode_interruption(); | |
0 | 1898 } |
1899 | |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1900 set_did_compact(should_compact); |
0 | 1901 if (should_compact) { |
1902 // If the collection is being acquired from the background | |
1903 // collector, there may be references on the discovered | |
1904 // references lists that have NULL referents (being those | |
1905 // that were concurrently cleared by a mutator) or | |
1906 // that are no longer active (having been enqueued concurrently | |
1907 // by the mutator). | |
1908 // Scrub the list of those references because Mark-Sweep-Compact | |
1909 // code assumes referents are not NULL and that all discovered | |
1910 // Reference objects are active. | |
1911 ref_processor()->clean_up_discovered_references(); | |
1912 | |
10405 | 1913 if (first_state > Idling) { |
1914 save_heap_summary(); | |
1915 } | |
1916 | |
0 | 1917 do_compaction_work(clear_all_soft_refs); |
1918 | |
1919 // Has the GC time limit been exceeded? | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1920 DefNewGeneration* young_gen = _young_gen->as_DefNewGeneration(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1921 size_t max_eden_size = young_gen->max_capacity() - |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1922 young_gen->to()->capacity() - |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1923 young_gen->from()->capacity(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1924 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1925 GCCause::Cause gc_cause = gch->gc_cause(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1926 size_policy()->check_gc_overhead_limit(_young_gen->used(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1927 young_gen->eden()->used(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1928 _cmsGen->max_capacity(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1929 max_eden_size, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1930 full, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1931 gc_cause, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1932 gch->collector_policy()); |
0 | 1933 } else { |
1934 do_mark_sweep_work(clear_all_soft_refs, first_state, | |
1935 should_start_over); | |
1936 } | |
1937 // Reset the expansion cause, now that we just completed | |
1938 // a collection cycle. | |
1939 clear_expansion_cause(); | |
1940 _foregroundGCIsActive = false; | |
1941 return; | |
1942 } | |
1943 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1944 // Resize the tenured generation |
0 | 1945 // after obtaining the free list locks for the |
1946 // two generations. | |
1947 void CMSCollector::compute_new_size() { | |
1948 assert_locked_or_safepoint(Heap_lock); | |
1949 FreelistLocker z(this); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1950 MetaspaceGC::compute_new_size(); |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
1951 _cmsGen->compute_new_size_free_list(); |
0 | 1952 } |
1953 | |
1954 // A work method used by foreground collection to determine | |
1955 // what type of collection (compacting or not, continuing or fresh) | |
1956 // it should do. | |
1957 // NOTE: the intent is to make UseCMSCompactAtFullCollection | |
1958 // and CMSCompactWhenClearAllSoftRefs the default in the future | |
1959 // and do away with the flags after a suitable period. | |
1960 void CMSCollector::decide_foreground_collection_type( | |
1961 bool clear_all_soft_refs, bool* should_compact, | |
1962 bool* should_start_over) { | |
1963 // Normally, we'll compact only if the UseCMSCompactAtFullCollection | |
1964 // flag is set, and we have either requested a System.gc() or | |
1965 // the number of full gc's since the last concurrent cycle | |
1966 // has exceeded the threshold set by CMSFullGCsBeforeCompaction, | |
1967 // or if an incremental collection has failed | |
1968 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1969 assert(gch->collector_policy()->is_two_generation_policy(), | |
1970 "You may want to check the correctness of the following"); | |
1971 // Inform cms gen if this was due to partial collection failing. | |
1972 // The CMS gen may use this fact to determine its expansion policy. | |
1994
6cd6d394f280
7001033: assert(gch->gc_cause() == GCCause::_scavenge_alot || !gch->incremental_collection_failed())
ysr
parents:
1972
diff
changeset
|
1973 if (gch->incremental_collection_will_fail(false /* don't consult_young */)) { |
0 | 1974 assert(!_cmsGen->incremental_collection_failed(), |
1975 "Should have been noticed, reacted to and cleared"); | |
1976 _cmsGen->set_incremental_collection_failed(); | |
1977 } | |
1978 *should_compact = | |
1979 UseCMSCompactAtFullCollection && | |
1980 ((_full_gcs_since_conc_gc >= CMSFullGCsBeforeCompaction) || | |
1981 GCCause::is_user_requested_gc(gch->gc_cause()) || | |
1994
6cd6d394f280
7001033: assert(gch->gc_cause() == GCCause::_scavenge_alot || !gch->incremental_collection_failed())
ysr
parents:
1972
diff
changeset
|
1982 gch->incremental_collection_will_fail(true /* consult_young */)); |
0 | 1983 *should_start_over = false; |
1984 if (clear_all_soft_refs && !*should_compact) { | |
1985 // We are about to do a last ditch collection attempt | |
1986 // so it would normally make sense to do a compaction | |
1987 // to reclaim as much space as possible. | |
1988 if (CMSCompactWhenClearAllSoftRefs) { | |
1989 // Default: The rationale is that in this case either | |
1990 // we are past the final marking phase, in which case | |
1991 // we'd have to start over, or so little has been done | |
1992 // that there's little point in saving that work. Compaction | |
1993 // appears to be the sensible choice in either case. | |
1994 *should_compact = true; | |
1995 } else { | |
1996 // We have been asked to clear all soft refs, but not to | |
1997 // compact. Make sure that we aren't past the final checkpoint | |
1998 // phase, for that is where we process soft refs. If we are already | |
1999 // past that phase, we'll need to redo the refs discovery phase and | |
2000 // if necessary clear soft refs that weren't previously | |
2001 // cleared. We do so by remembering the phase in which | |
2002 // we came in, and if we are past the refs processing | |
2003 // phase, we'll choose to just redo the mark-sweep | |
2004 // collection from scratch. | |
2005 if (_collectorState > FinalMarking) { | |
2006 // We are past the refs processing phase; | |
2007 // start over and do a fresh synchronous CMS cycle | |
2008 _collectorState = Resetting; // skip to reset to start new cycle | |
2009 reset(false /* == !asynch */); | |
2010 *should_start_over = true; | |
2011 } // else we can continue a possibly ongoing current cycle | |
2012 } | |
2013 } | |
2014 } | |
2015 | |
2016 // A work method used by the foreground collector to do | |
2017 // a mark-sweep-compact. | |
2018 void CMSCollector::do_compaction_work(bool clear_all_soft_refs) { | |
2019 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
10405 | 2020 |
2021 STWGCTimer* gc_timer = GenMarkSweep::gc_timer(); | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2022 gc_timer->register_gc_start(); |
10405 | 2023 |
2024 SerialOldTracer* gc_tracer = GenMarkSweep::gc_tracer(); | |
2025 gc_tracer->report_gc_start(gch->gc_cause(), gc_timer->gc_start()); | |
2026 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2027 GCTraceTime t("CMS:MSC ", PrintGCDetails && Verbose, true, NULL, gc_tracer->gc_id()); |
0 | 2028 if (PrintGC && Verbose && !(GCCause::is_user_requested_gc(gch->gc_cause()))) { |
2029 gclog_or_tty->print_cr("Compact ConcurrentMarkSweepGeneration after %d " | |
2030 "collections passed to foreground collector", _full_gcs_since_conc_gc); | |
2031 } | |
2032 | |
2033 // Sample collection interval time and reset for collection pause. | |
2034 if (UseAdaptiveSizePolicy) { | |
2035 size_policy()->msc_collection_begin(); | |
2036 } | |
2037 | |
2038 // Temporarily widen the span of the weak reference processing to | |
2039 // the entire heap. | |
2040 MemRegion new_span(GenCollectedHeap::heap()->reserved_region()); | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2041 ReferenceProcessorSpanMutator rp_mut_span(ref_processor(), new_span); |
0 | 2042 // Temporarily, clear the "is_alive_non_header" field of the |
2043 // reference processor. | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2044 ReferenceProcessorIsAliveMutator rp_mut_closure(ref_processor(), NULL); |
0 | 2045 // Temporarily make reference _processing_ single threaded (non-MT). |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2046 ReferenceProcessorMTProcMutator rp_mut_mt_processing(ref_processor(), false); |
0 | 2047 // Temporarily make refs discovery atomic |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2048 ReferenceProcessorAtomicMutator rp_mut_atomic(ref_processor(), true); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2049 // Temporarily make reference _discovery_ single threaded (non-MT) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2050 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(ref_processor(), false); |
0 | 2051 |
2052 ref_processor()->set_enqueuing_is_done(false); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
2053 ref_processor()->enable_discovery(false /*verify_disabled*/, false /*check_no_refs*/); |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
2054 ref_processor()->setup_policy(clear_all_soft_refs); |
0 | 2055 // If an asynchronous collection finishes, the _modUnionTable is |
2056 // all clear. If we are assuming the collection from an asynchronous | |
2057 // collection, clear the _modUnionTable. | |
2058 assert(_collectorState != Idling || _modUnionTable.isAllClear(), | |
2059 "_modUnionTable should be clear if the baton was not passed"); | |
2060 _modUnionTable.clear_all(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2061 assert(_collectorState != Idling || _ct->klass_rem_set()->mod_union_is_clear(), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2062 "mod union for klasses should be clear if the baton was passed"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2063 _ct->klass_rem_set()->clear_mod_union(); |
0 | 2064 |
2065 // We must adjust the allocation statistics being maintained | |
2066 // in the free list space. We do so by reading and clearing | |
2067 // the sweep timer and updating the block flux rate estimates below. | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2068 assert(!_intra_sweep_timer.is_active(), "_intra_sweep_timer should be inactive"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2069 if (_inter_sweep_timer.is_active()) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2070 _inter_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2071 // Note that we do not use this sample to update the _inter_sweep_estimate. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2072 _cmsGen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2073 _inter_sweep_estimate.padded_average(), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2074 _intra_sweep_estimate.padded_average()); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2075 } |
0 | 2076 |
2077 GenMarkSweep::invoke_at_safepoint(_cmsGen->level(), | |
2078 ref_processor(), clear_all_soft_refs); | |
2079 #ifdef ASSERT | |
2080 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); | |
2081 size_t free_size = cms_space->free(); | |
2082 assert(free_size == | |
2083 pointer_delta(cms_space->end(), cms_space->compaction_top()) | |
2084 * HeapWordSize, | |
2085 "All the free space should be compacted into one chunk at top"); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
2086 assert(cms_space->dictionary()->total_chunk_size( |
0 | 2087 debug_only(cms_space->freelistLock())) == 0 || |
2088 cms_space->totalSizeInIndexedFreeLists() == 0, | |
2089 "All the free space should be in a single chunk"); | |
2090 size_t num = cms_space->totalCount(); | |
2091 assert((free_size == 0 && num == 0) || | |
2092 (free_size > 0 && (num == 1 || num == 2)), | |
2093 "There should be at most 2 free chunks after compaction"); | |
2094 #endif // ASSERT | |
2095 _collectorState = Resetting; | |
2096 assert(_restart_addr == NULL, | |
2097 "Should have been NULL'd before baton was passed"); | |
2098 reset(false /* == !asynch */); | |
2099 _cmsGen->reset_after_compaction(); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2100 _concurrent_cycles_since_last_unload = 0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2101 |
0 | 2102 // Clear any data recorded in the PLAB chunk arrays. |
2103 if (_survivor_plab_array != NULL) { | |
2104 reset_survivor_plab_arrays(); | |
2105 } | |
2106 | |
2107 // Adjust the per-size allocation stats for the next epoch. | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2108 _cmsGen->cmsSpace()->endSweepFLCensus(sweep_count() /* fake */); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2109 // Restart the "inter sweep timer" for the next epoch. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2110 _inter_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2111 _inter_sweep_timer.start(); |
0 | 2112 |
2113 // Sample collection pause time and reset for collection interval. | |
2114 if (UseAdaptiveSizePolicy) { | |
2115 size_policy()->msc_collection_end(gch->gc_cause()); | |
2116 } | |
2117 | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2118 gc_timer->register_gc_end(); |
10405 | 2119 |
2120 gc_tracer->report_gc_end(gc_timer->gc_end(), gc_timer->time_partitions()); | |
2121 | |
0 | 2122 // For a mark-sweep-compact, compute_new_size() will be called |
2123 // in the heap's do_collection() method. | |
2124 } | |
2125 | |
2126 // A work method used by the foreground collector to do | |
2127 // a mark-sweep, after taking over from a possibly on-going | |
2128 // concurrent mark-sweep collection. | |
2129 void CMSCollector::do_mark_sweep_work(bool clear_all_soft_refs, | |
2130 CollectorState first_state, bool should_start_over) { | |
2131 if (PrintGC && Verbose) { | |
2132 gclog_or_tty->print_cr("Pass concurrent collection to foreground " | |
2133 "collector with count %d", | |
2134 _full_gcs_since_conc_gc); | |
2135 } | |
2136 switch (_collectorState) { | |
2137 case Idling: | |
2138 if (first_state == Idling || should_start_over) { | |
2139 // The background GC was not active, or should | |
2140 // restarted from scratch; start the cycle. | |
2141 _collectorState = InitialMarking; | |
2142 } | |
2143 // If first_state was not Idling, then a background GC | |
2144 // was in progress and has now finished. No need to do it | |
2145 // again. Leave the state as Idling. | |
2146 break; | |
2147 case Precleaning: | |
2148 // In the foreground case don't do the precleaning since | |
2149 // it is not done concurrently and there is extra work | |
2150 // required. | |
2151 _collectorState = FinalMarking; | |
2152 } | |
10405 | 2153 collect_in_foreground(clear_all_soft_refs, GenCollectedHeap::heap()->gc_cause()); |
0 | 2154 |
2155 // For a mark-sweep, compute_new_size() will be called | |
2156 // in the heap's do_collection() method. | |
2157 } | |
2158 | |
2159 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2160 void CMSCollector::print_eden_and_survivor_chunk_arrays() { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2161 DefNewGeneration* dng = _young_gen->as_DefNewGeneration(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2162 EdenSpace* eden_space = dng->eden(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2163 ContiguousSpace* from_space = dng->from(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2164 ContiguousSpace* to_space = dng->to(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2165 // Eden |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2166 if (_eden_chunk_array != NULL) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2167 gclog_or_tty->print_cr("eden " PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "(" SIZE_FORMAT ")", |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2168 eden_space->bottom(), eden_space->top(), |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2169 eden_space->end(), eden_space->capacity()); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2170 gclog_or_tty->print_cr("_eden_chunk_index=" SIZE_FORMAT ", " |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2171 "_eden_chunk_capacity=" SIZE_FORMAT, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2172 _eden_chunk_index, _eden_chunk_capacity); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2173 for (size_t i = 0; i < _eden_chunk_index; i++) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2174 gclog_or_tty->print_cr("_eden_chunk_array[" SIZE_FORMAT "]=" PTR_FORMAT, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2175 i, _eden_chunk_array[i]); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2176 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2177 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2178 // Survivor |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2179 if (_survivor_chunk_array != NULL) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2180 gclog_or_tty->print_cr("survivor " PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "(" SIZE_FORMAT ")", |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2181 from_space->bottom(), from_space->top(), |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2182 from_space->end(), from_space->capacity()); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2183 gclog_or_tty->print_cr("_survivor_chunk_index=" SIZE_FORMAT ", " |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2184 "_survivor_chunk_capacity=" SIZE_FORMAT, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2185 _survivor_chunk_index, _survivor_chunk_capacity); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2186 for (size_t i = 0; i < _survivor_chunk_index; i++) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2187 gclog_or_tty->print_cr("_survivor_chunk_array[" SIZE_FORMAT "]=" PTR_FORMAT, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2188 i, _survivor_chunk_array[i]); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2189 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2190 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2191 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2192 |
0 | 2193 void CMSCollector::getFreelistLocks() const { |
2194 // Get locks for all free lists in all generations that this | |
2195 // collector is responsible for | |
2196 _cmsGen->freelistLock()->lock_without_safepoint_check(); | |
2197 } | |
2198 | |
2199 void CMSCollector::releaseFreelistLocks() const { | |
2200 // Release locks for all free lists in all generations that this | |
2201 // collector is responsible for | |
2202 _cmsGen->freelistLock()->unlock(); | |
2203 } | |
2204 | |
2205 bool CMSCollector::haveFreelistLocks() const { | |
2206 // Check locks for all free lists in all generations that this | |
2207 // collector is responsible for | |
2208 assert_lock_strong(_cmsGen->freelistLock()); | |
2209 PRODUCT_ONLY(ShouldNotReachHere()); | |
2210 return true; | |
2211 } | |
2212 | |
2213 // A utility class that is used by the CMS collector to | |
2214 // temporarily "release" the foreground collector from its | |
2215 // usual obligation to wait for the background collector to | |
2216 // complete an ongoing phase before proceeding. | |
2217 class ReleaseForegroundGC: public StackObj { | |
2218 private: | |
2219 CMSCollector* _c; | |
2220 public: | |
2221 ReleaseForegroundGC(CMSCollector* c) : _c(c) { | |
2222 assert(_c->_foregroundGCShouldWait, "Else should not need to call"); | |
2223 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2224 // allow a potentially blocked foreground collector to proceed | |
2225 _c->_foregroundGCShouldWait = false; | |
2226 if (_c->_foregroundGCIsActive) { | |
2227 CGC_lock->notify(); | |
2228 } | |
2229 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2230 "Possible deadlock"); | |
2231 } | |
2232 | |
2233 ~ReleaseForegroundGC() { | |
2234 assert(!_c->_foregroundGCShouldWait, "Usage protocol violation?"); | |
2235 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2236 _c->_foregroundGCShouldWait = true; | |
2237 } | |
2238 }; | |
2239 | |
2240 // There are separate collect_in_background and collect_in_foreground because of | |
2241 // the different locking requirements of the background collector and the | |
2242 // foreground collector. There was originally an attempt to share | |
2243 // one "collect" method between the background collector and the foreground | |
2244 // collector but the if-then-else required made it cleaner to have | |
2245 // separate methods. | |
10405 | 2246 void CMSCollector::collect_in_background(bool clear_all_soft_refs, GCCause::Cause cause) { |
0 | 2247 assert(Thread::current()->is_ConcurrentGC_thread(), |
2248 "A CMS asynchronous collection is only allowed on a CMS thread."); | |
2249 | |
2250 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2251 { | |
2252 bool safepoint_check = Mutex::_no_safepoint_check_flag; | |
2253 MutexLockerEx hl(Heap_lock, safepoint_check); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2254 FreelistLocker fll(this); |
0 | 2255 MutexLockerEx x(CGC_lock, safepoint_check); |
2256 if (_foregroundGCIsActive || !UseAsyncConcMarkSweepGC) { | |
2257 // The foreground collector is active or we're | |
2258 // not using asynchronous collections. Skip this | |
2259 // background collection. | |
2260 assert(!_foregroundGCShouldWait, "Should be clear"); | |
2261 return; | |
2262 } else { | |
2263 assert(_collectorState == Idling, "Should be idling before start."); | |
2264 _collectorState = InitialMarking; | |
10405 | 2265 register_gc_start(cause); |
0 | 2266 // Reset the expansion cause, now that we are about to begin |
2267 // a new cycle. | |
2268 clear_expansion_cause(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2269 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2270 // Clear the MetaspaceGC flag since a concurrent collection |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2271 // is starting but also clear it after the collection. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2272 MetaspaceGC::set_should_concurrent_collect(false); |
0 | 2273 } |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2274 // Decide if we want to enable class unloading as part of the |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2275 // ensuing concurrent GC cycle. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2276 update_should_unload_classes(); |
0 | 2277 _full_gc_requested = false; // acks all outstanding full gc requests |
10405 | 2278 _full_gc_cause = GCCause::_no_gc; |
0 | 2279 // Signal that we are about to start a collection |
2280 gch->increment_total_full_collections(); // ... starting a collection cycle | |
2281 _collection_count_start = gch->total_full_collections(); | |
2282 } | |
2283 | |
2284 // Used for PrintGC | |
2285 size_t prev_used; | |
2286 if (PrintGC && Verbose) { | |
2287 prev_used = _cmsGen->used(); // XXXPERM | |
2288 } | |
2289 | |
2290 // The change of the collection state is normally done at this level; | |
2291 // the exceptions are phases that are executed while the world is | |
2292 // stopped. For those phases the change of state is done while the | |
2293 // world is stopped. For baton passing purposes this allows the | |
2294 // background collector to finish the phase and change state atomically. | |
2295 // The foreground collector cannot wait on a phase that is done | |
2296 // while the world is stopped because the foreground collector already | |
2297 // has the world stopped and would deadlock. | |
2298 while (_collectorState != Idling) { | |
2299 if (TraceCMSState) { | |
2300 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", | |
2301 Thread::current(), _collectorState); | |
2302 } | |
2303 // The foreground collector | |
2304 // holds the Heap_lock throughout its collection. | |
2305 // holds the CMS token (but not the lock) | |
2306 // except while it is waiting for the background collector to yield. | |
2307 // | |
2308 // The foreground collector should be blocked (not for long) | |
2309 // if the background collector is about to start a phase | |
2310 // executed with world stopped. If the background | |
2311 // collector has already started such a phase, the | |
2312 // foreground collector is blocked waiting for the | |
2313 // Heap_lock. The stop-world phases (InitialMarking and FinalMarking) | |
2314 // are executed in the VM thread. | |
2315 // | |
2316 // The locking order is | |
2317 // PendingListLock (PLL) -- if applicable (FinalMarking) | |
2318 // Heap_lock (both this & PLL locked in VM_CMS_Operation::prologue()) | |
2319 // CMS token (claimed in | |
2320 // stop_world_and_do() --> | |
2321 // safepoint_synchronize() --> | |
2322 // CMSThread::synchronize()) | |
2323 | |
2324 { | |
2325 // Check if the FG collector wants us to yield. | |
2326 CMSTokenSync x(true); // is cms thread | |
2327 if (waitForForegroundGC()) { | |
2328 // We yielded to a foreground GC, nothing more to be | |
2329 // done this round. | |
2330 assert(_foregroundGCShouldWait == false, "We set it to false in " | |
2331 "waitForForegroundGC()"); | |
2332 if (TraceCMSState) { | |
2333 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2334 " exiting collection CMS state %d", | |
2335 Thread::current(), _collectorState); | |
2336 } | |
2337 return; | |
2338 } else { | |
2339 // The background collector can run but check to see if the | |
2340 // foreground collector has done a collection while the | |
2341 // background collector was waiting to get the CGC_lock | |
2342 // above. If yes, break so that _foregroundGCShouldWait | |
2343 // is cleared before returning. | |
2344 if (_collectorState == Idling) { | |
2345 break; | |
2346 } | |
2347 } | |
2348 } | |
2349 | |
2350 assert(_foregroundGCShouldWait, "Foreground collector, if active, " | |
2351 "should be waiting"); | |
2352 | |
2353 switch (_collectorState) { | |
2354 case InitialMarking: | |
2355 { | |
2356 ReleaseForegroundGC x(this); | |
2357 stats().record_cms_begin(); | |
2358 VM_CMS_Initial_Mark initial_mark_op(this); | |
2359 VMThread::execute(&initial_mark_op); | |
2360 } | |
2361 // The collector state may be any legal state at this point | |
2362 // since the background collector may have yielded to the | |
2363 // foreground collector. | |
2364 break; | |
2365 case Marking: | |
2366 // initial marking in checkpointRootsInitialWork has been completed | |
2367 if (markFromRoots(true)) { // we were successful | |
2368 assert(_collectorState == Precleaning, "Collector state should " | |
2369 "have changed"); | |
2370 } else { | |
2371 assert(_foregroundGCIsActive, "Internal state inconsistency"); | |
2372 } | |
2373 break; | |
2374 case Precleaning: | |
2375 if (UseAdaptiveSizePolicy) { | |
2376 size_policy()->concurrent_precleaning_begin(); | |
2377 } | |
2378 // marking from roots in markFromRoots has been completed | |
2379 preclean(); | |
2380 if (UseAdaptiveSizePolicy) { | |
2381 size_policy()->concurrent_precleaning_end(); | |
2382 } | |
2383 assert(_collectorState == AbortablePreclean || | |
2384 _collectorState == FinalMarking, | |
2385 "Collector state should have changed"); | |
2386 break; | |
2387 case AbortablePreclean: | |
2388 if (UseAdaptiveSizePolicy) { | |
2389 size_policy()->concurrent_phases_resume(); | |
2390 } | |
2391 abortable_preclean(); | |
2392 if (UseAdaptiveSizePolicy) { | |
2393 size_policy()->concurrent_precleaning_end(); | |
2394 } | |
2395 assert(_collectorState == FinalMarking, "Collector state should " | |
2396 "have changed"); | |
2397 break; | |
2398 case FinalMarking: | |
2399 { | |
2400 ReleaseForegroundGC x(this); | |
2401 | |
2402 VM_CMS_Final_Remark final_remark_op(this); | |
2403 VMThread::execute(&final_remark_op); | |
935 | 2404 } |
0 | 2405 assert(_foregroundGCShouldWait, "block post-condition"); |
2406 break; | |
2407 case Sweeping: | |
2408 if (UseAdaptiveSizePolicy) { | |
2409 size_policy()->concurrent_sweeping_begin(); | |
2410 } | |
2411 // final marking in checkpointRootsFinal has been completed | |
2412 sweep(true); | |
2413 assert(_collectorState == Resizing, "Collector state change " | |
2414 "to Resizing must be done under the free_list_lock"); | |
2415 _full_gcs_since_conc_gc = 0; | |
2416 | |
2417 // Stop the timers for adaptive size policy for the concurrent phases | |
2418 if (UseAdaptiveSizePolicy) { | |
2419 size_policy()->concurrent_sweeping_end(); | |
2420 size_policy()->concurrent_phases_end(gch->gc_cause(), | |
2421 gch->prev_gen(_cmsGen)->capacity(), | |
2422 _cmsGen->free()); | |
2423 } | |
2424 | |
2425 case Resizing: { | |
2426 // Sweeping has been completed... | |
2427 // At this point the background collection has completed. | |
2428 // Don't move the call to compute_new_size() down | |
2429 // into code that might be executed if the background | |
2430 // collection was preempted. | |
2431 { | |
2432 ReleaseForegroundGC x(this); // unblock FG collection | |
2433 MutexLockerEx y(Heap_lock, Mutex::_no_safepoint_check_flag); | |
2434 CMSTokenSync z(true); // not strictly needed. | |
2435 if (_collectorState == Resizing) { | |
2436 compute_new_size(); | |
10405 | 2437 save_heap_summary(); |
0 | 2438 _collectorState = Resetting; |
2439 } else { | |
2440 assert(_collectorState == Idling, "The state should only change" | |
2441 " because the foreground collector has finished the collection"); | |
2442 } | |
2443 } | |
2444 break; | |
2445 } | |
2446 case Resetting: | |
2447 // CMS heap resizing has been completed | |
2448 reset(true); | |
2449 assert(_collectorState == Idling, "Collector state should " | |
2450 "have changed"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2451 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2452 MetaspaceGC::set_should_concurrent_collect(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2453 |
0 | 2454 stats().record_cms_end(); |
2455 // Don't move the concurrent_phases_end() and compute_new_size() | |
2456 // calls to here because a preempted background collection | |
2457 // has it's state set to "Resetting". | |
2458 break; | |
2459 case Idling: | |
2460 default: | |
2461 ShouldNotReachHere(); | |
2462 break; | |
2463 } | |
2464 if (TraceCMSState) { | |
2465 gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", | |
2466 Thread::current(), _collectorState); | |
2467 } | |
2468 assert(_foregroundGCShouldWait, "block post-condition"); | |
2469 } | |
2470 | |
2471 // Should this be in gc_epilogue? | |
2472 collector_policy()->counters()->update_counters(); | |
2473 | |
2474 { | |
2475 // Clear _foregroundGCShouldWait and, in the event that the | |
2476 // foreground collector is waiting, notify it, before | |
2477 // returning. | |
2478 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2479 _foregroundGCShouldWait = false; | |
2480 if (_foregroundGCIsActive) { | |
2481 CGC_lock->notify(); | |
2482 } | |
2483 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2484 "Possible deadlock"); | |
2485 } | |
2486 if (TraceCMSState) { | |
2487 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2488 " exiting collection CMS state %d", | |
2489 Thread::current(), _collectorState); | |
2490 } | |
2491 if (PrintGC && Verbose) { | |
2492 _cmsGen->print_heap_change(prev_used); | |
2493 } | |
2494 } | |
2495 | |
10405 | 2496 void CMSCollector::register_foreground_gc_start(GCCause::Cause cause) { |
2497 if (!_cms_start_registered) { | |
2498 register_gc_start(cause); | |
2499 } | |
2500 } | |
2501 | |
2502 void CMSCollector::register_gc_start(GCCause::Cause cause) { | |
2503 _cms_start_registered = true; | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2504 _gc_timer_cm->register_gc_start(); |
10405 | 2505 _gc_tracer_cm->report_gc_start(cause, _gc_timer_cm->gc_start()); |
2506 } | |
2507 | |
2508 void CMSCollector::register_gc_end() { | |
2509 if (_cms_start_registered) { | |
2510 report_heap_summary(GCWhen::AfterGC); | |
2511 | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2512 _gc_timer_cm->register_gc_end(); |
10405 | 2513 _gc_tracer_cm->report_gc_end(_gc_timer_cm->gc_end(), _gc_timer_cm->time_partitions()); |
2514 _cms_start_registered = false; | |
2515 } | |
2516 } | |
2517 | |
2518 void CMSCollector::save_heap_summary() { | |
2519 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2520 _last_heap_summary = gch->create_heap_summary(); | |
2521 _last_metaspace_summary = gch->create_metaspace_summary(); | |
2522 } | |
2523 | |
2524 void CMSCollector::report_heap_summary(GCWhen::Type when) { | |
17771
9fdaa79b0c27
8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents:
13400
diff
changeset
|
2525 _gc_tracer_cm->report_gc_heap_summary(when, _last_heap_summary); |
9fdaa79b0c27
8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents:
13400
diff
changeset
|
2526 _gc_tracer_cm->report_metaspace_summary(when, _last_metaspace_summary); |
10405 | 2527 } |
2528 | |
2529 void CMSCollector::collect_in_foreground(bool clear_all_soft_refs, GCCause::Cause cause) { | |
0 | 2530 assert(_foregroundGCIsActive && !_foregroundGCShouldWait, |
2531 "Foreground collector should be waiting, not executing"); | |
2532 assert(Thread::current()->is_VM_thread(), "A foreground collection" | |
2533 "may only be done by the VM Thread with the world stopped"); | |
2534 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
2535 "VM thread should have CMS token"); | |
2536 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2537 // The gc id is created in register_foreground_gc_start if this collection is synchronous |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2538 const GCId gc_id = _collectorState == InitialMarking ? GCId::peek() : _gc_tracer_cm->gc_id(); |
10405 | 2539 NOT_PRODUCT(GCTraceTime t("CMS:MS (foreground) ", PrintGCDetails && Verbose, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2540 true, NULL, gc_id);) |
0 | 2541 if (UseAdaptiveSizePolicy) { |
2542 size_policy()->ms_collection_begin(); | |
2543 } | |
2544 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact); | |
2545 | |
2546 HandleMark hm; // Discard invalid handles created during verification | |
2547 | |
2548 if (VerifyBeforeGC && | |
2549 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
2550 Universe::verify(); |
0 | 2551 } |
2552 | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
2553 // Snapshot the soft reference policy to be used in this collection cycle. |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
2554 ref_processor()->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
2555 |
13064
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2556 // Decide if class unloading should be done |
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2557 update_should_unload_classes(); |
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2558 |
0 | 2559 bool init_mark_was_synchronous = false; // until proven otherwise |
2560 while (_collectorState != Idling) { | |
2561 if (TraceCMSState) { | |
2562 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", | |
2563 Thread::current(), _collectorState); | |
2564 } | |
2565 switch (_collectorState) { | |
2566 case InitialMarking: | |
10405 | 2567 register_foreground_gc_start(cause); |
0 | 2568 init_mark_was_synchronous = true; // fact to be exploited in re-mark |
2569 checkpointRootsInitial(false); | |
2570 assert(_collectorState == Marking, "Collector state should have changed" | |
2571 " within checkpointRootsInitial()"); | |
2572 break; | |
2573 case Marking: | |
2574 // initial marking in checkpointRootsInitialWork has been completed | |
2575 if (VerifyDuringGC && | |
2576 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2577 Universe::verify("Verify before initial mark: "); |
0 | 2578 } |
2579 { | |
2580 bool res = markFromRoots(false); | |
2581 assert(res && _collectorState == FinalMarking, "Collector state should " | |
2582 "have changed"); | |
2583 break; | |
2584 } | |
2585 case FinalMarking: | |
2586 if (VerifyDuringGC && | |
2587 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2588 Universe::verify("Verify before re-mark: "); |
0 | 2589 } |
2590 checkpointRootsFinal(false, clear_all_soft_refs, | |
2591 init_mark_was_synchronous); | |
2592 assert(_collectorState == Sweeping, "Collector state should not " | |
2593 "have changed within checkpointRootsFinal()"); | |
2594 break; | |
2595 case Sweeping: | |
2596 // final marking in checkpointRootsFinal has been completed | |
2597 if (VerifyDuringGC && | |
2598 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2599 Universe::verify("Verify before sweep: "); |
0 | 2600 } |
2601 sweep(false); | |
2602 assert(_collectorState == Resizing, "Incorrect state"); | |
2603 break; | |
2604 case Resizing: { | |
2605 // Sweeping has been completed; the actual resize in this case | |
2606 // is done separately; nothing to be done in this state. | |
2607 _collectorState = Resetting; | |
2608 break; | |
2609 } | |
2610 case Resetting: | |
2611 // The heap has been resized. | |
2612 if (VerifyDuringGC && | |
2613 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2614 Universe::verify("Verify before reset: "); |
0 | 2615 } |
10405 | 2616 save_heap_summary(); |
0 | 2617 reset(false); |
2618 assert(_collectorState == Idling, "Collector state should " | |
2619 "have changed"); | |
2620 break; | |
2621 case Precleaning: | |
2622 case AbortablePreclean: | |
2623 // Elide the preclean phase | |
2624 _collectorState = FinalMarking; | |
2625 break; | |
2626 default: | |
2627 ShouldNotReachHere(); | |
2628 } | |
2629 if (TraceCMSState) { | |
2630 gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", | |
2631 Thread::current(), _collectorState); | |
2632 } | |
2633 } | |
2634 | |
2635 if (UseAdaptiveSizePolicy) { | |
2636 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2637 size_policy()->ms_collection_end(gch->gc_cause()); | |
2638 } | |
2639 | |
2640 if (VerifyAfterGC && | |
2641 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
2642 Universe::verify(); |
0 | 2643 } |
2644 if (TraceCMSState) { | |
2645 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2646 " exiting collection CMS state %d", | |
2647 Thread::current(), _collectorState); | |
2648 } | |
2649 } | |
2650 | |
2651 bool CMSCollector::waitForForegroundGC() { | |
2652 bool res = false; | |
2653 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2654 "CMS thread should have CMS token"); | |
2655 // Block the foreground collector until the | |
2656 // background collectors decides whether to | |
2657 // yield. | |
2658 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2659 _foregroundGCShouldWait = true; | |
2660 if (_foregroundGCIsActive) { | |
2661 // The background collector yields to the | |
2662 // foreground collector and returns a value | |
2663 // indicating that it has yielded. The foreground | |
2664 // collector can proceed. | |
2665 res = true; | |
2666 _foregroundGCShouldWait = false; | |
2667 ConcurrentMarkSweepThread::clear_CMS_flag( | |
2668 ConcurrentMarkSweepThread::CMS_cms_has_token); | |
2669 ConcurrentMarkSweepThread::set_CMS_flag( | |
2670 ConcurrentMarkSweepThread::CMS_cms_wants_token); | |
2671 // Get a possibly blocked foreground thread going | |
2672 CGC_lock->notify(); | |
2673 if (TraceCMSState) { | |
2674 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " waiting at CMS state %d", | |
2675 Thread::current(), _collectorState); | |
2676 } | |
2677 while (_foregroundGCIsActive) { | |
2678 CGC_lock->wait(Mutex::_no_safepoint_check_flag); | |
2679 } | |
2680 ConcurrentMarkSweepThread::set_CMS_flag( | |
2681 ConcurrentMarkSweepThread::CMS_cms_has_token); | |
2682 ConcurrentMarkSweepThread::clear_CMS_flag( | |
2683 ConcurrentMarkSweepThread::CMS_cms_wants_token); | |
2684 } | |
2685 if (TraceCMSState) { | |
2686 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " continuing at CMS state %d", | |
2687 Thread::current(), _collectorState); | |
2688 } | |
2689 return res; | |
2690 } | |
2691 | |
2692 // Because of the need to lock the free lists and other structures in | |
2693 // the collector, common to all the generations that the collector is | |
2694 // collecting, we need the gc_prologues of individual CMS generations | |
2695 // delegate to their collector. It may have been simpler had the | |
2696 // current infrastructure allowed one to call a prologue on a | |
2697 // collector. In the absence of that we have the generation's | |
2698 // prologue delegate to the collector, which delegates back | |
2699 // some "local" work to a worker method in the individual generations | |
2700 // that it's responsible for collecting, while itself doing any | |
2701 // work common to all generations it's responsible for. A similar | |
2702 // comment applies to the gc_epilogue()'s. | |
2703 // The role of the varaible _between_prologue_and_epilogue is to | |
2704 // enforce the invocation protocol. | |
2705 void CMSCollector::gc_prologue(bool full) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2706 // Call gc_prologue_work() for the CMSGen |
0 | 2707 // we are responsible for. |
2708 | |
2709 // The following locking discipline assumes that we are only called | |
2710 // when the world is stopped. | |
2711 assert(SafepointSynchronize::is_at_safepoint(), "world is stopped assumption"); | |
2712 | |
2713 // The CMSCollector prologue must call the gc_prologues for the | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2714 // "generations" that it's responsible |
0 | 2715 // for. |
2716 | |
2717 assert( Thread::current()->is_VM_thread() | |
2718 || ( CMSScavengeBeforeRemark | |
2719 && Thread::current()->is_ConcurrentGC_thread()), | |
2720 "Incorrect thread type for prologue execution"); | |
2721 | |
2722 if (_between_prologue_and_epilogue) { | |
2723 // We have already been invoked; this is a gc_prologue delegation | |
2724 // from yet another CMS generation that we are responsible for, just | |
2725 // ignore it since all relevant work has already been done. | |
2726 return; | |
2727 } | |
2728 | |
2729 // set a bit saying prologue has been called; cleared in epilogue | |
2730 _between_prologue_and_epilogue = true; | |
2731 // Claim locks for common data structures, then call gc_prologue_work() | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2732 // for each CMSGen. |
0 | 2733 |
2734 getFreelistLocks(); // gets free list locks on constituent spaces | |
2735 bitMapLock()->lock_without_safepoint_check(); | |
2736 | |
2737 // Should call gc_prologue_work() for all cms gens we are responsible for | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2738 bool duringMarking = _collectorState >= Marking |
0 | 2739 && _collectorState < Sweeping; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2740 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2741 // The young collections clear the modified oops state, which tells if |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2742 // there are any modified oops in the class. The remark phase also needs |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2743 // that information. Tell the young collection to save the union of all |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2744 // modified klasses. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2745 if (duringMarking) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2746 _ct->klass_rem_set()->set_accumulate_modified_oops(true); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2747 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2748 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2749 bool registerClosure = duringMarking; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2750 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2751 ModUnionClosure* muc = CollectedHeap::use_parallel_gc_threads() ? |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2752 &_modUnionClosurePar |
0 | 2753 : &_modUnionClosure; |
2754 _cmsGen->gc_prologue_work(full, registerClosure, muc); | |
2755 | |
2756 if (!full) { | |
2757 stats().record_gc0_begin(); | |
2758 } | |
2759 } | |
2760 | |
2761 void ConcurrentMarkSweepGeneration::gc_prologue(bool full) { | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2762 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2763 _capacity_at_prologue = capacity(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2764 _used_at_prologue = used(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2765 |
0 | 2766 // Delegate to CMScollector which knows how to coordinate between |
2767 // this and any other CMS generations that it is responsible for | |
2768 // collecting. | |
2769 collector()->gc_prologue(full); | |
2770 } | |
2771 | |
2772 // This is a "private" interface for use by this generation's CMSCollector. | |
2773 // Not to be called directly by any other entity (for instance, | |
2774 // GenCollectedHeap, which calls the "public" gc_prologue method above). | |
2775 void ConcurrentMarkSweepGeneration::gc_prologue_work(bool full, | |
2776 bool registerClosure, ModUnionClosure* modUnionClosure) { | |
2777 assert(!incremental_collection_failed(), "Shouldn't be set yet"); | |
2778 assert(cmsSpace()->preconsumptionDirtyCardClosure() == NULL, | |
2779 "Should be NULL"); | |
2780 if (registerClosure) { | |
2781 cmsSpace()->setPreconsumptionDirtyCardClosure(modUnionClosure); | |
2782 } | |
2783 cmsSpace()->gc_prologue(); | |
2784 // Clear stat counters | |
2785 NOT_PRODUCT( | |
2786 assert(_numObjectsPromoted == 0, "check"); | |
2787 assert(_numWordsPromoted == 0, "check"); | |
2788 if (Verbose && PrintGC) { | |
2789 gclog_or_tty->print("Allocated "SIZE_FORMAT" objects, " | |
2790 SIZE_FORMAT" bytes concurrently", | |
2791 _numObjectsAllocated, _numWordsAllocated*sizeof(HeapWord)); | |
2792 } | |
2793 _numObjectsAllocated = 0; | |
2794 _numWordsAllocated = 0; | |
2795 ) | |
2796 } | |
2797 | |
2798 void CMSCollector::gc_epilogue(bool full) { | |
2799 // The following locking discipline assumes that we are only called | |
2800 // when the world is stopped. | |
2801 assert(SafepointSynchronize::is_at_safepoint(), | |
2802 "world is stopped assumption"); | |
2803 | |
2804 // Currently the CMS epilogue (see CompactibleFreeListSpace) merely checks | |
2805 // if linear allocation blocks need to be appropriately marked to allow the | |
2806 // the blocks to be parsable. We also check here whether we need to nudge the | |
2807 // CMS collector thread to start a new cycle (if it's not already active). | |
2808 assert( Thread::current()->is_VM_thread() | |
2809 || ( CMSScavengeBeforeRemark | |
2810 && Thread::current()->is_ConcurrentGC_thread()), | |
2811 "Incorrect thread type for epilogue execution"); | |
2812 | |
2813 if (!_between_prologue_and_epilogue) { | |
2814 // We have already been invoked; this is a gc_epilogue delegation | |
2815 // from yet another CMS generation that we are responsible for, just | |
2816 // ignore it since all relevant work has already been done. | |
2817 return; | |
2818 } | |
2819 assert(haveFreelistLocks(), "must have freelist locks"); | |
2820 assert_lock_strong(bitMapLock()); | |
2821 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2822 _ct->klass_rem_set()->set_accumulate_modified_oops(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2823 |
0 | 2824 _cmsGen->gc_epilogue_work(full); |
2825 | |
2826 if (_collectorState == AbortablePreclean || _collectorState == Precleaning) { | |
2827 // in case sampling was not already enabled, enable it | |
2828 _start_sampling = true; | |
2829 } | |
2830 // reset _eden_chunk_array so sampling starts afresh | |
2831 _eden_chunk_index = 0; | |
2832 | |
2833 size_t cms_used = _cmsGen->cmsSpace()->used(); | |
2834 | |
2835 // update performance counters - this uses a special version of | |
2836 // update_counters() that allows the utilization to be passed as a | |
2837 // parameter, avoiding multiple calls to used(). | |
2838 // | |
2839 _cmsGen->update_counters(cms_used); | |
2840 | |
2841 if (CMSIncrementalMode) { | |
2842 icms_update_allocation_limits(); | |
2843 } | |
2844 | |
2845 bitMapLock()->unlock(); | |
2846 releaseFreelistLocks(); | |
2847 | |
3799
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2848 if (!CleanChunkPoolAsync) { |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2849 Chunk::clean_chunk_pool(); |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2850 } |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2851 |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
2852 set_did_compact(false); |
0 | 2853 _between_prologue_and_epilogue = false; // ready for next cycle |
2854 } | |
2855 | |
2856 void ConcurrentMarkSweepGeneration::gc_epilogue(bool full) { | |
2857 collector()->gc_epilogue(full); | |
2858 | |
2859 // Also reset promotion tracking in par gc thread states. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2860 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 2861 for (uint i = 0; i < ParallelGCThreads; i++) { |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2862 _par_gc_thread_states[i]->promo.stopTrackingPromotions(i); |
0 | 2863 } |
2864 } | |
2865 } | |
2866 | |
2867 void ConcurrentMarkSweepGeneration::gc_epilogue_work(bool full) { | |
2868 assert(!incremental_collection_failed(), "Should have been cleared"); | |
2869 cmsSpace()->setPreconsumptionDirtyCardClosure(NULL); | |
2870 cmsSpace()->gc_epilogue(); | |
2871 // Print stat counters | |
2872 NOT_PRODUCT( | |
2873 assert(_numObjectsAllocated == 0, "check"); | |
2874 assert(_numWordsAllocated == 0, "check"); | |
2875 if (Verbose && PrintGC) { | |
2876 gclog_or_tty->print("Promoted "SIZE_FORMAT" objects, " | |
2877 SIZE_FORMAT" bytes", | |
2878 _numObjectsPromoted, _numWordsPromoted*sizeof(HeapWord)); | |
2879 } | |
2880 _numObjectsPromoted = 0; | |
2881 _numWordsPromoted = 0; | |
2882 ) | |
2883 | |
2884 if (PrintGC && Verbose) { | |
2885 // Call down the chain in contiguous_available needs the freelistLock | |
2886 // so print this out before releasing the freeListLock. | |
2887 gclog_or_tty->print(" Contiguous available "SIZE_FORMAT" bytes ", | |
2888 contiguous_available()); | |
2889 } | |
2890 } | |
2891 | |
2892 #ifndef PRODUCT | |
2893 bool CMSCollector::have_cms_token() { | |
2894 Thread* thr = Thread::current(); | |
2895 if (thr->is_VM_thread()) { | |
2896 return ConcurrentMarkSweepThread::vm_thread_has_cms_token(); | |
2897 } else if (thr->is_ConcurrentGC_thread()) { | |
2898 return ConcurrentMarkSweepThread::cms_thread_has_cms_token(); | |
2899 } else if (thr->is_GC_task_thread()) { | |
2900 return ConcurrentMarkSweepThread::vm_thread_has_cms_token() && | |
2901 ParGCRareEvent_lock->owned_by_self(); | |
2902 } | |
2903 return false; | |
2904 } | |
2905 #endif | |
2906 | |
2907 // Check reachability of the given heap address in CMS generation, | |
2908 // treating all other generations as roots. | |
2909 bool CMSCollector::is_cms_reachable(HeapWord* addr) { | |
2910 // We could "guarantee" below, rather than assert, but i'll | |
2911 // leave these as "asserts" so that an adventurous debugger | |
2912 // could try this in the product build provided some subset of | |
2913 // the conditions were met, provided they were intersted in the | |
2914 // results and knew that the computation below wouldn't interfere | |
2915 // with other concurrent computations mutating the structures | |
2916 // being read or written. | |
2917 assert(SafepointSynchronize::is_at_safepoint(), | |
2918 "Else mutations in object graph will make answer suspect"); | |
2919 assert(have_cms_token(), "Should hold cms token"); | |
2920 assert(haveFreelistLocks(), "must hold free list locks"); | |
2921 assert_lock_strong(bitMapLock()); | |
2922 | |
2923 // Clear the marking bit map array before starting, but, just | |
2924 // for kicks, first report if the given address is already marked | |
2925 gclog_or_tty->print_cr("Start: Address 0x%x is%s marked", addr, | |
2926 _markBitMap.isMarked(addr) ? "" : " not"); | |
2927 | |
2928 if (verify_after_remark()) { | |
2929 MutexLockerEx x(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); | |
2930 bool result = verification_mark_bm()->isMarked(addr); | |
2931 gclog_or_tty->print_cr("TransitiveMark: Address 0x%x %s marked", addr, | |
2932 result ? "IS" : "is NOT"); | |
2933 return result; | |
2934 } else { | |
2935 gclog_or_tty->print_cr("Could not compute result"); | |
2936 return false; | |
2937 } | |
2938 } | |
2939 | |
9076
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2940 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2941 void |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2942 CMSCollector::print_on_error(outputStream* st) { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2943 CMSCollector* collector = ConcurrentMarkSweepGeneration::_collector; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2944 if (collector != NULL) { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2945 CMSBitMap* bitmap = &collector->_markBitMap; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2946 st->print_cr("Marking Bits: (CMSBitMap*) " PTR_FORMAT, bitmap); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2947 bitmap->print_on_error(st, " Bits: "); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2948 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2949 st->cr(); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2950 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2951 CMSBitMap* mut_bitmap = &collector->_modUnionTable; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2952 st->print_cr("Mod Union Table: (CMSBitMap*) " PTR_FORMAT, mut_bitmap); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2953 mut_bitmap->print_on_error(st, " Bits: "); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2954 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2955 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2956 |
0 | 2957 //////////////////////////////////////////////////////// |
2958 // CMS Verification Support | |
2959 //////////////////////////////////////////////////////// | |
2960 // Following the remark phase, the following invariant | |
2961 // should hold -- each object in the CMS heap which is | |
2962 // marked in markBitMap() should be marked in the verification_mark_bm(). | |
2963 | |
2964 class VerifyMarkedClosure: public BitMapClosure { | |
2965 CMSBitMap* _marks; | |
2966 bool _failed; | |
2967 | |
2968 public: | |
2969 VerifyMarkedClosure(CMSBitMap* bm): _marks(bm), _failed(false) {} | |
2970 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
2971 bool do_bit(size_t offset) { |
0 | 2972 HeapWord* addr = _marks->offsetToHeapWord(offset); |
2973 if (!_marks->isMarked(addr)) { | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2974 oop(addr)->print_on(gclog_or_tty); |
0 | 2975 gclog_or_tty->print_cr(" ("INTPTR_FORMAT" should have been marked)", addr); |
2976 _failed = true; | |
2977 } | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
2978 return true; |
0 | 2979 } |
2980 | |
2981 bool failed() { return _failed; } | |
2982 }; | |
2983 | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2984 bool CMSCollector::verify_after_remark(bool silent) { |
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2985 if (!silent) gclog_or_tty->print(" [Verifying CMS Marking... "); |
0 | 2986 MutexLockerEx ml(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); |
2987 static bool init = false; | |
2988 | |
2989 assert(SafepointSynchronize::is_at_safepoint(), | |
2990 "Else mutations in object graph will make answer suspect"); | |
2991 assert(have_cms_token(), | |
2992 "Else there may be mutual interference in use of " | |
2993 " verification data structures"); | |
2994 assert(_collectorState > Marking && _collectorState <= Sweeping, | |
2995 "Else marking info checked here may be obsolete"); | |
2996 assert(haveFreelistLocks(), "must hold free list locks"); | |
2997 assert_lock_strong(bitMapLock()); | |
2998 | |
2999 | |
3000 // Allocate marking bit map if not already allocated | |
3001 if (!init) { // first time | |
3002 if (!verification_mark_bm()->allocate(_span)) { | |
3003 return false; | |
3004 } | |
3005 init = true; | |
3006 } | |
3007 | |
3008 assert(verification_mark_stack()->isEmpty(), "Should be empty"); | |
3009 | |
3010 // Turn off refs discovery -- so we will be tracing through refs. | |
3011 // This is as intended, because by this time | |
3012 // GC must already have cleared any refs that need to be cleared, | |
3013 // and traced those that need to be marked; moreover, | |
3014 // the marking done here is not going to intefere in any | |
3015 // way with the marking information used by GC. | |
3016 NoRefDiscovery no_discovery(ref_processor()); | |
3017 | |
3018 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
3019 | |
3020 // Clear any marks from a previous round | |
3021 verification_mark_bm()->clear_all(); | |
3022 assert(verification_mark_stack()->isEmpty(), "markStack should be empty"); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3023 verify_work_stacks_empty(); |
0 | 3024 |
3025 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3026 gch->ensure_parsability(false); // fill TLABs, but no need to retire them | |
3027 // Update the saved marks which may affect the root scans. | |
3028 gch->save_marks(); | |
3029 | |
3030 if (CMSRemarkVerifyVariant == 1) { | |
3031 // In this first variant of verification, we complete | |
3032 // all marking, then check if the new marks-verctor is | |
3033 // a subset of the CMS marks-vector. | |
3034 verify_after_remark_work_1(); | |
3035 } else if (CMSRemarkVerifyVariant == 2) { | |
3036 // In this second variant of verification, we flag an error | |
3037 // (i.e. an object reachable in the new marks-vector not reachable | |
3038 // in the CMS marks-vector) immediately, also indicating the | |
3039 // identify of an object (A) that references the unmarked object (B) -- | |
3040 // presumably, a mutation to A failed to be picked up by preclean/remark? | |
3041 verify_after_remark_work_2(); | |
3042 } else { | |
3043 warning("Unrecognized value %d for CMSRemarkVerifyVariant", | |
3044 CMSRemarkVerifyVariant); | |
3045 } | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
3046 if (!silent) gclog_or_tty->print(" done] "); |
0 | 3047 return true; |
3048 } | |
3049 | |
3050 void CMSCollector::verify_after_remark_work_1() { | |
3051 ResourceMark rm; | |
3052 HandleMark hm; | |
3053 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3054 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3055 // Get a clear set of claim bits for the roots processing to work with. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3056 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3057 |
0 | 3058 // Mark from roots one level into CMS |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3059 MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); |
0 | 3060 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3061 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3062 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3063 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3064 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3065 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3066 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3067 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3068 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3069 NULL); // SSS: Provide correct closure |
0 | 3070 |
3071 // Now mark from the roots | |
3072 MarkFromRootsClosure markFromRootsClosure(this, _span, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3073 verification_mark_bm(), verification_mark_stack(), |
0 | 3074 false /* don't yield */, true /* verifying */); |
3075 assert(_restart_addr == NULL, "Expected pre-condition"); | |
3076 verification_mark_bm()->iterate(&markFromRootsClosure); | |
3077 while (_restart_addr != NULL) { | |
3078 // Deal with stack overflow: by restarting at the indicated | |
3079 // address. | |
3080 HeapWord* ra = _restart_addr; | |
3081 markFromRootsClosure.reset(ra); | |
3082 _restart_addr = NULL; | |
3083 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end()); | |
3084 } | |
3085 assert(verification_mark_stack()->isEmpty(), "Should have been drained"); | |
3086 verify_work_stacks_empty(); | |
3087 | |
3088 // Marking completed -- now verify that each bit marked in | |
3089 // verification_mark_bm() is also marked in markBitMap(); flag all | |
3090 // errors by printing corresponding objects. | |
3091 VerifyMarkedClosure vcl(markBitMap()); | |
3092 verification_mark_bm()->iterate(&vcl); | |
3093 if (vcl.failed()) { | |
3094 gclog_or_tty->print("Verification failed"); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3095 Universe::heap()->print_on(gclog_or_tty); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3096 fatal("CMS: failed marking verification after remark"); |
0 | 3097 } |
3098 } | |
3099 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3100 class VerifyKlassOopsKlassClosure : public KlassClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3101 class VerifyKlassOopsClosure : public OopClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3102 CMSBitMap* _bitmap; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3103 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3104 VerifyKlassOopsClosure(CMSBitMap* bitmap) : _bitmap(bitmap) { } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3105 void do_oop(oop* p) { guarantee(*p == NULL || _bitmap->isMarked((HeapWord*) *p), "Should be marked"); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3106 void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3107 } _oop_closure; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3108 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3109 VerifyKlassOopsKlassClosure(CMSBitMap* bitmap) : _oop_closure(bitmap) {} |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3110 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3111 k->oops_do(&_oop_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3112 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3113 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3114 |
0 | 3115 void CMSCollector::verify_after_remark_work_2() { |
3116 ResourceMark rm; | |
3117 HandleMark hm; | |
3118 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3119 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3120 // Get a clear set of claim bits for the roots processing to work with. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3121 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3122 |
0 | 3123 // Mark from roots one level into CMS |
3124 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(), | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3125 markBitMap()); |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3126 CLDToOopClosure cld_closure(¬Older, true); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3127 |
0 | 3128 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3129 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3130 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3131 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3132 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3133 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3134 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3135 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3136 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3137 &cld_closure); |
0 | 3138 |
3139 // Now mark from the roots | |
3140 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, | |
3141 verification_mark_bm(), markBitMap(), verification_mark_stack()); | |
3142 assert(_restart_addr == NULL, "Expected pre-condition"); | |
3143 verification_mark_bm()->iterate(&markFromRootsClosure); | |
3144 while (_restart_addr != NULL) { | |
3145 // Deal with stack overflow: by restarting at the indicated | |
3146 // address. | |
3147 HeapWord* ra = _restart_addr; | |
3148 markFromRootsClosure.reset(ra); | |
3149 _restart_addr = NULL; | |
3150 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end()); | |
3151 } | |
3152 assert(verification_mark_stack()->isEmpty(), "Should have been drained"); | |
3153 verify_work_stacks_empty(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3154 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3155 VerifyKlassOopsKlassClosure verify_klass_oops(verification_mark_bm()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3156 ClassLoaderDataGraph::classes_do(&verify_klass_oops); |
0 | 3157 |
3158 // Marking completed -- now verify that each bit marked in | |
3159 // verification_mark_bm() is also marked in markBitMap(); flag all | |
3160 // errors by printing corresponding objects. | |
3161 VerifyMarkedClosure vcl(markBitMap()); | |
3162 verification_mark_bm()->iterate(&vcl); | |
3163 assert(!vcl.failed(), "Else verification above should not have succeeded"); | |
3164 } | |
3165 | |
3166 void ConcurrentMarkSweepGeneration::save_marks() { | |
3167 // delegate to CMS space | |
3168 cmsSpace()->save_marks(); | |
3169 for (uint i = 0; i < ParallelGCThreads; i++) { | |
3170 _par_gc_thread_states[i]->promo.startTrackingPromotions(); | |
3171 } | |
3172 } | |
3173 | |
3174 bool ConcurrentMarkSweepGeneration::no_allocs_since_save_marks() { | |
3175 return cmsSpace()->no_allocs_since_save_marks(); | |
3176 } | |
3177 | |
3178 #define CMS_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ | |
3179 \ | |
3180 void ConcurrentMarkSweepGeneration:: \ | |
3181 oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ | |
3182 cl->set_generation(this); \ | |
3183 cmsSpace()->oop_since_save_marks_iterate##nv_suffix(cl); \ | |
3184 cl->reset_generation(); \ | |
3185 save_marks(); \ | |
3186 } | |
3187 | |
3188 ALL_SINCE_SAVE_MARKS_CLOSURES(CMS_SINCE_SAVE_MARKS_DEFN) | |
3189 | |
3190 void | |
3191 ConcurrentMarkSweepGeneration::younger_refs_iterate(OopsInGenClosure* cl) { | |
3192 cl->set_generation(this); | |
3193 younger_refs_in_space_iterate(_cmsSpace, cl); | |
3194 cl->reset_generation(); | |
3195 } | |
3196 | |
3197 void | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3198 ConcurrentMarkSweepGeneration::oop_iterate(ExtendedOopClosure* cl) { |
0 | 3199 if (freelistLock()->owned_by_self()) { |
3200 Generation::oop_iterate(cl); | |
3201 } else { | |
3202 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3203 Generation::oop_iterate(cl); | |
3204 } | |
3205 } | |
3206 | |
3207 void | |
3208 ConcurrentMarkSweepGeneration::object_iterate(ObjectClosure* cl) { | |
3209 if (freelistLock()->owned_by_self()) { | |
3210 Generation::object_iterate(cl); | |
3211 } else { | |
3212 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3213 Generation::object_iterate(cl); | |
3214 } | |
3215 } | |
3216 | |
3217 void | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3218 ConcurrentMarkSweepGeneration::safe_object_iterate(ObjectClosure* cl) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3219 if (freelistLock()->owned_by_self()) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3220 Generation::safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3221 } else { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3222 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3223 Generation::safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3224 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3225 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3226 |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3227 void |
0 | 3228 ConcurrentMarkSweepGeneration::post_compact() { |
3229 } | |
3230 | |
3231 void | |
3232 ConcurrentMarkSweepGeneration::prepare_for_verify() { | |
3233 // Fix the linear allocation blocks to look like free blocks. | |
3234 | |
3235 // Locks are normally acquired/released in gc_prologue/gc_epilogue, but those | |
3236 // are not called when the heap is verified during universe initialization and | |
3237 // at vm shutdown. | |
3238 if (freelistLock()->owned_by_self()) { | |
3239 cmsSpace()->prepare_for_verify(); | |
3240 } else { | |
3241 MutexLockerEx fll(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3242 cmsSpace()->prepare_for_verify(); | |
3243 } | |
3244 } | |
3245 | |
3246 void | |
6008 | 3247 ConcurrentMarkSweepGeneration::verify() { |
0 | 3248 // Locks are normally acquired/released in gc_prologue/gc_epilogue, but those |
3249 // are not called when the heap is verified during universe initialization and | |
3250 // at vm shutdown. | |
3251 if (freelistLock()->owned_by_self()) { | |
6008 | 3252 cmsSpace()->verify(); |
0 | 3253 } else { |
3254 MutexLockerEx fll(freelistLock(), Mutex::_no_safepoint_check_flag); | |
6008 | 3255 cmsSpace()->verify(); |
3256 } | |
3257 } | |
3258 | |
3259 void CMSCollector::verify() { | |
3260 _cmsGen->verify(); | |
0 | 3261 } |
3262 | |
3263 #ifndef PRODUCT | |
3264 bool CMSCollector::overflow_list_is_empty() const { | |
3265 assert(_num_par_pushes >= 0, "Inconsistency"); | |
3266 if (_overflow_list == NULL) { | |
3267 assert(_num_par_pushes == 0, "Inconsistency"); | |
3268 } | |
3269 return _overflow_list == NULL; | |
3270 } | |
3271 | |
3272 // The methods verify_work_stacks_empty() and verify_overflow_empty() | |
3273 // merely consolidate assertion checks that appear to occur together frequently. | |
3274 void CMSCollector::verify_work_stacks_empty() const { | |
3275 assert(_markStack.isEmpty(), "Marking stack should be empty"); | |
3276 assert(overflow_list_is_empty(), "Overflow list should be empty"); | |
3277 } | |
3278 | |
3279 void CMSCollector::verify_overflow_empty() const { | |
3280 assert(overflow_list_is_empty(), "Overflow list should be empty"); | |
3281 assert(no_preserved_marks(), "No preserved marks"); | |
3282 } | |
3283 #endif // PRODUCT | |
3284 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3285 // Decide if we want to enable class unloading as part of the |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3286 // ensuing concurrent GC cycle. We will collect and |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3287 // unload classes if it's the case that: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3288 // (1) an explicit gc request has been made and the flag |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3289 // ExplicitGCInvokesConcurrentAndUnloadsClasses is set, OR |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3290 // (2) (a) class unloading is enabled at the command line, and |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3291 // (b) old gen is getting really full |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3292 // NOTE: Provided there is no change in the state of the heap between |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3293 // calls to this method, it should have idempotent results. Moreover, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3294 // its results should be monotonically increasing (i.e. going from 0 to 1, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3295 // but not 1 to 0) between successive calls between which the heap was |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3296 // not collected. For the implementation below, it must thus rely on |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3297 // the property that concurrent_cycles_since_last_unload() |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3298 // will not decrease unless a collection cycle happened and that |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3299 // _cmsGen->is_too_full() are |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3300 // themselves also monotonic in that sense. See check_monotonicity() |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3301 // below. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3302 void CMSCollector::update_should_unload_classes() { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3303 _should_unload_classes = false; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3304 // Condition 1 above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3305 if (_full_gc_requested && ExplicitGCInvokesConcurrentAndUnloadsClasses) { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3306 _should_unload_classes = true; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3307 } else if (CMSClassUnloadingEnabled) { // Condition 2.a above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3308 // Disjuncts 2.b.(i,ii,iii) above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3309 _should_unload_classes = (concurrent_cycles_since_last_unload() >= |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3310 CMSClassUnloadingMaxInterval) |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3311 || _cmsGen->is_too_full(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3312 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3313 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3314 |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3315 bool ConcurrentMarkSweepGeneration::is_too_full() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3316 bool res = should_concurrent_collect(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3317 res = res && (occupancy() > (double)CMSIsTooFullPercentage/100.0); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3318 return res; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3319 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3320 |
0 | 3321 void CMSCollector::setup_cms_unloading_and_verification_state() { |
3293
1f4413413144
7039089: G1: changeset for 7037276 broke heap verification, and related cleanups
ysr
parents:
2379
diff
changeset
|
3322 const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC |
0 | 3323 || VerifyBeforeExit; |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3324 const int rso = SharedHeap::SO_AllCodeCache; |
0 | 3325 |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
3326 // We set the proper root for this CMS cycle here. |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3327 if (should_unload_classes()) { // Should unload classes this cycle |
0 | 3328 remove_root_scanning_option(rso); // Shrink the root set appropriately |
3329 set_verifying(should_verify); // Set verification state for this cycle | |
3330 return; // Nothing else needs to be done at this time | |
3331 } | |
3332 | |
3333 // Not unloading classes this cycle | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3334 assert(!should_unload_classes(), "Inconsitency!"); |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
3335 |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3336 if ((!verifying() || unloaded_classes_last_cycle()) && should_verify) { |
0 | 3337 // Include symbols, strings and code cache elements to prevent their resurrection. |
3338 add_root_scanning_option(rso); | |
3339 set_verifying(true); | |
3340 } else if (verifying() && !should_verify) { | |
3341 // We were verifying, but some verification flags got disabled. | |
3342 set_verifying(false); | |
3343 // Exclude symbols, strings and code cache elements from root scanning to | |
3344 // reduce IM and RM pauses. | |
3345 remove_root_scanning_option(rso); | |
3346 } | |
3347 } | |
3348 | |
3349 | |
3350 #ifndef PRODUCT | |
3351 HeapWord* CMSCollector::block_start(const void* p) const { | |
3352 const HeapWord* addr = (HeapWord*)p; | |
3353 if (_span.contains(p)) { | |
3354 if (_cmsGen->cmsSpace()->is_in_reserved(addr)) { | |
3355 return _cmsGen->cmsSpace()->block_start(p); | |
3356 } | |
3357 } | |
3358 return NULL; | |
3359 } | |
3360 #endif | |
3361 | |
3362 HeapWord* | |
3363 ConcurrentMarkSweepGeneration::expand_and_allocate(size_t word_size, | |
3364 bool tlab, | |
3365 bool parallel) { | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3366 CMSSynchronousYieldRequest yr; |
0 | 3367 assert(!tlab, "Can't deal with TLAB allocation"); |
3368 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3369 expand(word_size*HeapWordSize, MinHeapDeltaBytes, | |
3370 CMSExpansionCause::_satisfy_allocation); | |
3371 if (GCExpandToAllocateDelayMillis > 0) { | |
3372 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3373 } | |
9
173195ff483a
6642634: Test nsk/regression/b6186200 crashed with SIGSEGV
ysr
parents:
7
diff
changeset
|
3374 return have_lock_and_allocate(word_size, tlab); |
0 | 3375 } |
3376 | |
3377 // YSR: All of this generation expansion/shrinking stuff is an exact copy of | |
3378 // OneContigSpaceCardGeneration, which makes me wonder if we should move this | |
3379 // to CardGeneration and share it... | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3380 bool ConcurrentMarkSweepGeneration::expand(size_t bytes, size_t expand_bytes) { |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3381 return CardGeneration::expand(bytes, expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3382 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3383 |
0 | 3384 void ConcurrentMarkSweepGeneration::expand(size_t bytes, size_t expand_bytes, |
3385 CMSExpansionCause::Cause cause) | |
3386 { | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3387 |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3388 bool success = expand(bytes, expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3389 |
0 | 3390 // remember why we expanded; this information is used |
3391 // by shouldConcurrentCollect() when making decisions on whether to start | |
3392 // a new CMS cycle. | |
3393 if (success) { | |
3394 set_expansion_cause(cause); | |
3395 if (PrintGCDetails && Verbose) { | |
3396 gclog_or_tty->print_cr("Expanded CMS gen for %s", | |
3397 CMSExpansionCause::to_string(cause)); | |
3398 } | |
3399 } | |
3400 } | |
3401 | |
3402 HeapWord* ConcurrentMarkSweepGeneration::expand_and_par_lab_allocate(CMSParGCThreadState* ps, size_t word_sz) { | |
3403 HeapWord* res = NULL; | |
3404 MutexLocker x(ParGCRareEvent_lock); | |
3405 while (true) { | |
3406 // Expansion by some other thread might make alloc OK now: | |
3407 res = ps->lab.alloc(word_sz); | |
3408 if (res != NULL) return res; | |
3409 // If there's not enough expansion space available, give up. | |
3410 if (_virtual_space.uncommitted_size() < (word_sz * HeapWordSize)) { | |
3411 return NULL; | |
3412 } | |
3413 // Otherwise, we try expansion. | |
3414 expand(word_sz*HeapWordSize, MinHeapDeltaBytes, | |
3415 CMSExpansionCause::_allocate_par_lab); | |
3416 // Now go around the loop and try alloc again; | |
3417 // A competing par_promote might beat us to the expansion space, | |
3418 // so we may go around the loop again if promotion fails agaion. | |
3419 if (GCExpandToAllocateDelayMillis > 0) { | |
3420 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3421 } | |
3422 } | |
3423 } | |
3424 | |
3425 | |
3426 bool ConcurrentMarkSweepGeneration::expand_and_ensure_spooling_space( | |
3427 PromotionInfo* promo) { | |
3428 MutexLocker x(ParGCRareEvent_lock); | |
3429 size_t refill_size_bytes = promo->refillSize() * HeapWordSize; | |
3430 while (true) { | |
3431 // Expansion by some other thread might make alloc OK now: | |
3432 if (promo->ensure_spooling_space()) { | |
3433 assert(promo->has_spooling_space(), | |
3434 "Post-condition of successful ensure_spooling_space()"); | |
3435 return true; | |
3436 } | |
3437 // If there's not enough expansion space available, give up. | |
3438 if (_virtual_space.uncommitted_size() < refill_size_bytes) { | |
3439 return false; | |
3440 } | |
3441 // Otherwise, we try expansion. | |
3442 expand(refill_size_bytes, MinHeapDeltaBytes, | |
3443 CMSExpansionCause::_allocate_par_spooling_space); | |
3444 // Now go around the loop and try alloc again; | |
3445 // A competing allocation might beat us to the expansion space, | |
3446 // so we may go around the loop again if allocation fails again. | |
3447 if (GCExpandToAllocateDelayMillis > 0) { | |
3448 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3449 } | |
3450 } | |
3451 } | |
3452 | |
3453 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3454 void ConcurrentMarkSweepGeneration::shrink_by(size_t bytes) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3455 assert_locked_or_safepoint(ExpandHeap_lock); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3456 // Shrink committed space |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3457 _virtual_space.shrink_by(bytes); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3458 // Shrink space; this also shrinks the space's BOT |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3459 _cmsSpace->set_end((HeapWord*) _virtual_space.high()); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3460 size_t new_word_size = heap_word_size(_cmsSpace->capacity()); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3461 // Shrink the shared block offset array |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3462 _bts->resize(new_word_size); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3463 MemRegion mr(_cmsSpace->bottom(), new_word_size); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3464 // Shrink the card table |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3465 Universe::heap()->barrier_set()->resize_covered_region(mr); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3466 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3467 if (Verbose && PrintGC) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3468 size_t new_mem_size = _virtual_space.committed_size(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3469 size_t old_mem_size = new_mem_size + bytes; |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3470 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3471 name(), old_mem_size/K, new_mem_size/K); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3472 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3473 } |
0 | 3474 |
3475 void ConcurrentMarkSweepGeneration::shrink(size_t bytes) { | |
3476 assert_locked_or_safepoint(Heap_lock); | |
3477 size_t size = ReservedSpace::page_align_size_down(bytes); | |
12112
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
3478 // Only shrink if a compaction was done so that all the free space |
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
3479 // in the generation is in a contiguous block at the end. |
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
3480 if (size > 0 && did_compact()) { |
0 | 3481 shrink_by(size); |
3482 } | |
3483 } | |
3484 | |
3485 bool ConcurrentMarkSweepGeneration::grow_by(size_t bytes) { | |
3486 assert_locked_or_safepoint(Heap_lock); | |
3487 bool result = _virtual_space.expand_by(bytes); | |
3488 if (result) { | |
3489 size_t new_word_size = | |
3490 heap_word_size(_virtual_space.committed_size()); | |
3491 MemRegion mr(_cmsSpace->bottom(), new_word_size); | |
3492 _bts->resize(new_word_size); // resize the block offset shared array | |
3493 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
3494 // Hmmmm... why doesn't CFLS::set_end verify locking? | |
3495 // This is quite ugly; FIX ME XXX | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3496 _cmsSpace->assert_locked(freelistLock()); |
0 | 3497 _cmsSpace->set_end((HeapWord*)_virtual_space.high()); |
3498 | |
3499 // update the space and generation capacity counters | |
3500 if (UsePerfData) { | |
3501 _space_counters->update_capacity(); | |
3502 _gen_counters->update_all(); | |
3503 } | |
3504 | |
3505 if (Verbose && PrintGC) { | |
3506 size_t new_mem_size = _virtual_space.committed_size(); | |
3507 size_t old_mem_size = new_mem_size - bytes; | |
7623
203f64878aab
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
6885
diff
changeset
|
3508 gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
0 | 3509 name(), old_mem_size/K, bytes/K, new_mem_size/K); |
3510 } | |
3511 } | |
3512 return result; | |
3513 } | |
3514 | |
3515 bool ConcurrentMarkSweepGeneration::grow_to_reserved() { | |
3516 assert_locked_or_safepoint(Heap_lock); | |
3517 bool success = true; | |
3518 const size_t remaining_bytes = _virtual_space.uncommitted_size(); | |
3519 if (remaining_bytes > 0) { | |
3520 success = grow_by(remaining_bytes); | |
3521 DEBUG_ONLY(if (!success) warning("grow to reserved failed");) | |
3522 } | |
3523 return success; | |
3524 } | |
3525 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3526 void ConcurrentMarkSweepGeneration::shrink_free_list_by(size_t bytes) { |
0 | 3527 assert_locked_or_safepoint(Heap_lock); |
3528 assert_lock_strong(freelistLock()); | |
10180
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3529 if (PrintGCDetails && Verbose) { |
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3530 warning("Shrinking of CMS not yet implemented"); |
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3531 } |
0 | 3532 return; |
3533 } | |
3534 | |
3535 | |
3536 // Simple ctor/dtor wrapper for accounting & timer chores around concurrent | |
3537 // phases. | |
3538 class CMSPhaseAccounting: public StackObj { | |
3539 public: | |
3540 CMSPhaseAccounting(CMSCollector *collector, | |
3541 const char *phase, | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3542 const GCId gc_id, |
0 | 3543 bool print_cr = true); |
3544 ~CMSPhaseAccounting(); | |
3545 | |
3546 private: | |
3547 CMSCollector *_collector; | |
3548 const char *_phase; | |
3549 elapsedTimer _wallclock; | |
3550 bool _print_cr; | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3551 const GCId _gc_id; |
0 | 3552 |
3553 public: | |
3554 // Not MT-safe; so do not pass around these StackObj's | |
3555 // where they may be accessed by other threads. | |
3556 jlong wallclock_millis() { | |
3557 assert(_wallclock.is_active(), "Wall clock should not stop"); | |
3558 _wallclock.stop(); // to record time | |
3559 jlong ret = _wallclock.milliseconds(); | |
3560 _wallclock.start(); // restart | |
3561 return ret; | |
3562 } | |
3563 }; | |
3564 | |
3565 CMSPhaseAccounting::CMSPhaseAccounting(CMSCollector *collector, | |
3566 const char *phase, | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3567 const GCId gc_id, |
0 | 3568 bool print_cr) : |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3569 _collector(collector), _phase(phase), _print_cr(print_cr), _gc_id(gc_id) { |
0 | 3570 |
3571 if (PrintCMSStatistics != 0) { | |
3572 _collector->resetYields(); | |
3573 } | |
8740
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3574 if (PrintGCDetails) { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3575 gclog_or_tty->gclog_stamp(_gc_id); |
8740
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3576 gclog_or_tty->print_cr("[%s-concurrent-%s-start]", |
0 | 3577 _collector->cmsGen()->short_name(), _phase); |
3578 } | |
3579 _collector->resetTimer(); | |
3580 _wallclock.start(); | |
3581 _collector->startTimer(); | |
3582 } | |
3583 | |
3584 CMSPhaseAccounting::~CMSPhaseAccounting() { | |
3585 assert(_wallclock.is_active(), "Wall clock should not have stopped"); | |
3586 _collector->stopTimer(); | |
3587 _wallclock.stop(); | |
3588 if (PrintGCDetails) { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3589 gclog_or_tty->gclog_stamp(_gc_id); |
0 | 3590 gclog_or_tty->print("[%s-concurrent-%s: %3.3f/%3.3f secs]", |
3591 _collector->cmsGen()->short_name(), | |
3592 _phase, _collector->timerValue(), _wallclock.seconds()); | |
3593 if (_print_cr) { | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
3594 gclog_or_tty->cr(); |
0 | 3595 } |
3596 if (PrintCMSStatistics != 0) { | |
3597 gclog_or_tty->print_cr(" (CMS-concurrent-%s yielded %d times)", _phase, | |
3598 _collector->yields()); | |
3599 } | |
3600 } | |
3601 } | |
3602 | |
3603 // CMS work | |
3604 | |
11975 | 3605 // The common parts of CMSParInitialMarkTask and CMSParRemarkTask. |
3606 class CMSParMarkTask : public AbstractGangTask { | |
3607 protected: | |
3608 CMSCollector* _collector; | |
3609 int _n_workers; | |
3610 CMSParMarkTask(const char* name, CMSCollector* collector, int n_workers) : | |
3611 AbstractGangTask(name), | |
3612 _collector(collector), | |
3613 _n_workers(n_workers) {} | |
3614 // Work method in support of parallel rescan ... of young gen spaces | |
3615 void do_young_space_rescan(uint worker_id, OopsInGenClosure* cl, | |
3616 ContiguousSpace* space, | |
3617 HeapWord** chunk_array, size_t chunk_top); | |
3618 void work_on_young_gen_roots(uint worker_id, OopsInGenClosure* cl); | |
3619 }; | |
3620 | |
3621 // Parallel initial mark task | |
3622 class CMSParInitialMarkTask: public CMSParMarkTask { | |
3623 public: | |
3624 CMSParInitialMarkTask(CMSCollector* collector, int n_workers) : | |
3625 CMSParMarkTask("Scan roots and young gen for initial mark in parallel", | |
3626 collector, n_workers) {} | |
3627 void work(uint worker_id); | |
3628 }; | |
3629 | |
0 | 3630 // Checkpoint the roots into this generation from outside |
3631 // this generation. [Note this initial checkpoint need only | |
3632 // be approximate -- we'll do a catch up phase subsequently.] | |
3633 void CMSCollector::checkpointRootsInitial(bool asynch) { | |
3634 assert(_collectorState == InitialMarking, "Wrong collector state"); | |
3635 check_correct_thread_executing(); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
3636 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
3637 |
10405 | 3638 save_heap_summary(); |
3639 report_heap_summary(GCWhen::BeforeGC); | |
3640 | |
0 | 3641 ReferenceProcessor* rp = ref_processor(); |
3642 SpecializationStats::clear(); | |
3643 assert(_restart_addr == NULL, "Control point invariant"); | |
3644 if (asynch) { | |
3645 // acquire locks for subsequent manipulations | |
3646 MutexLockerEx x(bitMapLock(), | |
3647 Mutex::_no_safepoint_check_flag); | |
3648 checkpointRootsInitialWork(asynch); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3649 // enable ("weak") refs discovery |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3650 rp->enable_discovery(true /*verify_disabled*/, true /*check_no_refs*/); |
0 | 3651 _collectorState = Marking; |
3652 } else { | |
3653 // (Weak) Refs discovery: this is controlled from genCollectedHeap::do_collection | |
3654 // which recognizes if we are a CMS generation, and doesn't try to turn on | |
3655 // discovery; verify that they aren't meddling. | |
3656 assert(!rp->discovery_is_atomic(), | |
3657 "incorrect setting of discovery predicate"); | |
3658 assert(!rp->discovery_enabled(), "genCollectedHeap shouldn't control " | |
3659 "ref discovery for this generation kind"); | |
3660 // already have locks | |
3661 checkpointRootsInitialWork(asynch); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3662 // now enable ("weak") refs discovery |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3663 rp->enable_discovery(true /*verify_disabled*/, false /*verify_no_refs*/); |
0 | 3664 _collectorState = Marking; |
3665 } | |
3666 SpecializationStats::print(); | |
3667 } | |
3668 | |
3669 void CMSCollector::checkpointRootsInitialWork(bool asynch) { | |
3670 assert(SafepointSynchronize::is_at_safepoint(), "world should be stopped"); | |
3671 assert(_collectorState == InitialMarking, "just checking"); | |
3672 | |
3673 // If there has not been a GC[n-1] since last GC[n] cycle completed, | |
3674 // precede our marking with a collection of all | |
3675 // younger generations to keep floating garbage to a minimum. | |
3676 // XXX: we won't do this for now -- it's an optimization to be done later. | |
3677 | |
3678 // already have locks | |
3679 assert_lock_strong(bitMapLock()); | |
3680 assert(_markBitMap.isAllClear(), "was reset at end of previous cycle"); | |
3681 | |
3682 // Setup the verification and class unloading state for this | |
3683 // CMS collection cycle. | |
3684 setup_cms_unloading_and_verification_state(); | |
3685 | |
10405 | 3686 NOT_PRODUCT(GCTraceTime t("\ncheckpointRootsInitialWork", |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3687 PrintGCDetails && Verbose, true, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 3688 if (UseAdaptiveSizePolicy) { |
3689 size_policy()->checkpoint_roots_initial_begin(); | |
3690 } | |
3691 | |
3692 // Reset all the PLAB chunk arrays if necessary. | |
3693 if (_survivor_plab_array != NULL && !CMSPLABRecordAlways) { | |
3694 reset_survivor_plab_arrays(); | |
3695 } | |
3696 | |
3697 ResourceMark rm; | |
3698 HandleMark hm; | |
3699 | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3700 MarkRefsIntoClosure notOlder(_span, &_markBitMap); |
0 | 3701 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3702 | |
3703 verify_work_stacks_empty(); | |
3704 verify_overflow_empty(); | |
3705 | |
3706 gch->ensure_parsability(false); // fill TLABs, but no need to retire them | |
3707 // Update the saved marks which may affect the root scans. | |
3708 gch->save_marks(); | |
3709 | |
3710 // weak reference processing has not started yet. | |
3711 ref_processor()->set_enqueuing_is_done(false); | |
3712 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3713 // Need to remember all newly created CLDs, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3714 // so that we can guarantee that the remark finds them. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3715 ClassLoaderDataGraph::remember_new_clds(true); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3716 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3717 // Whenever a CLD is found, it will be claimed before proceeding to mark |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3718 // the klasses. The claimed marks need to be cleared before marking starts. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3719 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3720 |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3721 if (CMSPrintEdenSurvivorChunks) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3722 print_eden_and_survivor_chunk_arrays(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3723 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3724 |
0 | 3725 { |
3726 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
11975 | 3727 if (CMSParallelInitialMarkEnabled && CollectedHeap::use_parallel_gc_threads()) { |
3728 // The parallel version. | |
3729 FlexibleWorkGang* workers = gch->workers(); | |
3730 assert(workers != NULL, "Need parallel worker threads."); | |
3731 int n_workers = workers->active_workers(); | |
3732 CMSParInitialMarkTask tsk(this, n_workers); | |
3733 gch->set_par_threads(n_workers); | |
3734 initialize_sequential_subtasks_for_young_gen_rescan(n_workers); | |
3735 if (n_workers > 1) { | |
3736 GenCollectedHeap::StrongRootsScope srs(gch); | |
3737 workers->run_task(&tsk); | |
3738 } else { | |
3739 GenCollectedHeap::StrongRootsScope srs(gch); | |
3740 tsk.work(0); | |
3741 } | |
3742 gch->set_par_threads(0); | |
3743 } else { | |
3744 // The serial version. | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3745 CLDToOopClosure cld_closure(¬Older, true); |
11975 | 3746 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3747 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3748 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3749 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3750 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3751 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3752 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3753 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3754 &cld_closure); |
11975 | 3755 } |
0 | 3756 } |
3757 | |
3758 // Clear mod-union table; it will be dirtied in the prologue of | |
3759 // CMS generation per each younger generation collection. | |
3760 | |
3761 assert(_modUnionTable.isAllClear(), | |
3762 "Was cleared in most recent final checkpoint phase" | |
3763 " or no bits are set in the gc_prologue before the start of the next " | |
3764 "subsequent marking phase."); | |
3765 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3766 assert(_ct->klass_rem_set()->mod_union_is_clear(), "Must be"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3767 |
0 | 3768 // Save the end of the used_region of the constituent generations |
3769 // to be used to limit the extent of sweep in each generation. | |
3770 save_sweep_limits(); | |
3771 if (UseAdaptiveSizePolicy) { | |
3772 size_policy()->checkpoint_roots_initial_end(gch->gc_cause()); | |
3773 } | |
3774 verify_overflow_empty(); | |
3775 } | |
3776 | |
3777 bool CMSCollector::markFromRoots(bool asynch) { | |
3778 // we might be tempted to assert that: | |
3779 // assert(asynch == !SafepointSynchronize::is_at_safepoint(), | |
3780 // "inconsistent argument?"); | |
3781 // However that wouldn't be right, because it's possible that | |
3782 // a safepoint is indeed in progress as a younger generation | |
3783 // stop-the-world GC happens even as we mark in this generation. | |
3784 assert(_collectorState == Marking, "inconsistent state?"); | |
3785 check_correct_thread_executing(); | |
3786 verify_overflow_empty(); | |
3787 | |
3788 bool res; | |
3789 if (asynch) { | |
3790 | |
3791 // Start the timers for adaptive size policy for the concurrent phases | |
3792 // Do it here so that the foreground MS can use the concurrent | |
3793 // timer since a foreground MS might has the sweep done concurrently | |
3794 // or STW. | |
3795 if (UseAdaptiveSizePolicy) { | |
3796 size_policy()->concurrent_marking_begin(); | |
3797 } | |
3798 | |
3799 // Weak ref discovery note: We may be discovering weak | |
3800 // refs in this generation concurrent (but interleaved) with | |
3801 // weak ref discovery by a younger generation collector. | |
3802 | |
3803 CMSTokenSyncWithLocks ts(true, bitMapLock()); | |
3804 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3805 CMSPhaseAccounting pa(this, "mark", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 3806 res = markFromRootsWork(asynch); |
3807 if (res) { | |
3808 _collectorState = Precleaning; | |
3809 } else { // We failed and a foreground collection wants to take over | |
3810 assert(_foregroundGCIsActive, "internal state inconsistency"); | |
3811 assert(_restart_addr == NULL, "foreground will restart from scratch"); | |
3812 if (PrintGCDetails) { | |
3813 gclog_or_tty->print_cr("bailing out to foreground collection"); | |
3814 } | |
3815 } | |
3816 if (UseAdaptiveSizePolicy) { | |
3817 size_policy()->concurrent_marking_end(); | |
3818 } | |
3819 } else { | |
3820 assert(SafepointSynchronize::is_at_safepoint(), | |
3821 "inconsistent with asynch == false"); | |
3822 if (UseAdaptiveSizePolicy) { | |
3823 size_policy()->ms_collection_marking_begin(); | |
3824 } | |
3825 // already have locks | |
3826 res = markFromRootsWork(asynch); | |
3827 _collectorState = FinalMarking; | |
3828 if (UseAdaptiveSizePolicy) { | |
3829 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3830 size_policy()->ms_collection_marking_end(gch->gc_cause()); | |
3831 } | |
3832 } | |
3833 verify_overflow_empty(); | |
3834 return res; | |
3835 } | |
3836 | |
3837 bool CMSCollector::markFromRootsWork(bool asynch) { | |
3838 // iterate over marked bits in bit map, doing a full scan and mark | |
3839 // from these roots using the following algorithm: | |
3840 // . if oop is to the right of the current scan pointer, | |
3841 // mark corresponding bit (we'll process it later) | |
3842 // . else (oop is to left of current scan pointer) | |
3843 // push oop on marking stack | |
3844 // . drain the marking stack | |
3845 | |
3846 // Note that when we do a marking step we need to hold the | |
3847 // bit map lock -- recall that direct allocation (by mutators) | |
3848 // and promotion (by younger generation collectors) is also | |
3849 // marking the bit map. [the so-called allocate live policy.] | |
3850 // Because the implementation of bit map marking is not | |
3851 // robust wrt simultaneous marking of bits in the same word, | |
3852 // we need to make sure that there is no such interference | |
3853 // between concurrent such updates. | |
3854 | |
3855 // already have locks | |
3856 assert_lock_strong(bitMapLock()); | |
3857 | |
3858 verify_work_stacks_empty(); | |
3859 verify_overflow_empty(); | |
3860 bool result = false; | |
1284 | 3861 if (CMSConcurrentMTEnabled && ConcGCThreads > 0) { |
0 | 3862 result = do_marking_mt(asynch); |
3863 } else { | |
3864 result = do_marking_st(asynch); | |
3865 } | |
3866 return result; | |
3867 } | |
3868 | |
3869 // Forward decl | |
3870 class CMSConcMarkingTask; | |
3871 | |
3872 class CMSConcMarkingTerminator: public ParallelTaskTerminator { | |
3873 CMSCollector* _collector; | |
3874 CMSConcMarkingTask* _task; | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3875 public: |
0 | 3876 virtual void yield(); |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3877 |
0 | 3878 // "n_threads" is the number of threads to be terminated. |
3879 // "queue_set" is a set of work queues of other threads. | |
3880 // "collector" is the CMS collector associated with this task terminator. | |
3881 // "yield" indicates whether we need the gang as a whole to yield. | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3882 CMSConcMarkingTerminator(int n_threads, TaskQueueSetSuper* queue_set, CMSCollector* collector) : |
0 | 3883 ParallelTaskTerminator(n_threads, queue_set), |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3884 _collector(collector) { } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3885 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3886 void set_task(CMSConcMarkingTask* task) { |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3887 _task = task; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3888 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3889 }; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3890 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3891 class CMSConcMarkingTerminatorTerminator: public TerminatorTerminator { |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3892 CMSConcMarkingTask* _task; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3893 public: |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3894 bool should_exit_termination(); |
0 | 3895 void set_task(CMSConcMarkingTask* task) { |
3896 _task = task; | |
3897 } | |
3898 }; | |
3899 | |
3900 // MT Concurrent Marking Task | |
3901 class CMSConcMarkingTask: public YieldingFlexibleGangTask { | |
3902 CMSCollector* _collector; | |
3903 int _n_workers; // requested/desired # workers | |
3904 bool _asynch; | |
3905 bool _result; | |
3906 CompactibleFreeListSpace* _cms_space; | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3907 char _pad_front[64]; // padding to ... |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3908 HeapWord* _global_finger; // ... avoid sharing cache line |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3909 char _pad_back[64]; |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3910 HeapWord* _restart_addr; |
0 | 3911 |
3912 // Exposed here for yielding support | |
3913 Mutex* const _bit_map_lock; | |
3914 | |
3915 // The per thread work queues, available here for stealing | |
3916 OopTaskQueueSet* _task_queues; | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3917 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3918 // Termination (and yielding) support |
0 | 3919 CMSConcMarkingTerminator _term; |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3920 CMSConcMarkingTerminatorTerminator _term_term; |
0 | 3921 |
3922 public: | |
3923 CMSConcMarkingTask(CMSCollector* collector, | |
3924 CompactibleFreeListSpace* cms_space, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3925 bool asynch, |
0 | 3926 YieldingFlexibleWorkGang* workers, |
3927 OopTaskQueueSet* task_queues): | |
3928 YieldingFlexibleGangTask("Concurrent marking done multi-threaded"), | |
3929 _collector(collector), | |
3930 _cms_space(cms_space), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3931 _asynch(asynch), _n_workers(0), _result(true), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3932 _task_queues(task_queues), |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3933 _term(_n_workers, task_queues, _collector), |
0 | 3934 _bit_map_lock(collector->bitMapLock()) |
3935 { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3936 _requested_size = _n_workers; |
0 | 3937 _term.set_task(this); |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3938 _term_term.set_task(this); |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3939 _restart_addr = _global_finger = _cms_space->bottom(); |
0 | 3940 } |
3941 | |
3942 | |
3943 OopTaskQueueSet* task_queues() { return _task_queues; } | |
3944 | |
3945 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
3946 | |
3947 HeapWord** global_finger_addr() { return &_global_finger; } | |
3948 | |
3949 CMSConcMarkingTerminator* terminator() { return &_term; } | |
3950 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3951 virtual void set_for_termination(int active_workers) { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3952 terminator()->reset_for_reuse(active_workers); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3953 } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3954 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3955 void work(uint worker_id); |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3956 bool should_yield() { |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3957 return ConcurrentMarkSweepThread::should_yield() |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3958 && !_collector->foregroundGCIsActive() |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3959 && _asynch; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3960 } |
0 | 3961 |
3962 virtual void coordinator_yield(); // stuff done by coordinator | |
3963 bool result() { return _result; } | |
3964 | |
3965 void reset(HeapWord* ra) { | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3966 assert(_global_finger >= _cms_space->end(), "Postcondition of ::work(i)"); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3967 _restart_addr = _global_finger = ra; |
0 | 3968 _term.reset_for_reuse(); |
3969 } | |
3970 | |
3971 static bool get_work_from_overflow_stack(CMSMarkStack* ovflw_stk, | |
3972 OopTaskQueue* work_q); | |
3973 | |
3974 private: | |
3975 void do_scan_and_mark(int i, CompactibleFreeListSpace* sp); | |
3976 void do_work_steal(int i); | |
3977 void bump_global_finger(HeapWord* f); | |
3978 }; | |
3979 | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3980 bool CMSConcMarkingTerminatorTerminator::should_exit_termination() { |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3981 assert(_task != NULL, "Error"); |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3982 return _task->yielding(); |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3983 // Note that we do not need the disjunct || _task->should_yield() above |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3984 // because we want terminating threads to yield only if the task |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3985 // is already in the midst of yielding, which happens only after at least one |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3986 // thread has yielded. |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3987 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3988 |
0 | 3989 void CMSConcMarkingTerminator::yield() { |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3990 if (_task->should_yield()) { |
0 | 3991 _task->yield(); |
3992 } else { | |
3993 ParallelTaskTerminator::yield(); | |
3994 } | |
3995 } | |
3996 | |
3997 //////////////////////////////////////////////////////////////// | |
3998 // Concurrent Marking Algorithm Sketch | |
3999 //////////////////////////////////////////////////////////////// | |
4000 // Until all tasks exhausted (both spaces): | |
4001 // -- claim next available chunk | |
4002 // -- bump global finger via CAS | |
4003 // -- find first object that starts in this chunk | |
4004 // and start scanning bitmap from that position | |
4005 // -- scan marked objects for oops | |
4006 // -- CAS-mark target, and if successful: | |
4007 // . if target oop is above global finger (volatile read) | |
4008 // nothing to do | |
4009 // . if target oop is in chunk and above local finger | |
4010 // then nothing to do | |
4011 // . else push on work-queue | |
4012 // -- Deal with possible overflow issues: | |
4013 // . local work-queue overflow causes stuff to be pushed on | |
4014 // global (common) overflow queue | |
4015 // . always first empty local work queue | |
4016 // . then get a batch of oops from global work queue if any | |
4017 // . then do work stealing | |
4018 // -- When all tasks claimed (both spaces) | |
4019 // and local work queue empty, | |
4020 // then in a loop do: | |
4021 // . check global overflow stack; steal a batch of oops and trace | |
4022 // . try to steal from other threads oif GOS is empty | |
4023 // . if neither is available, offer termination | |
4024 // -- Terminate and return result | |
4025 // | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4026 void CMSConcMarkingTask::work(uint worker_id) { |
0 | 4027 elapsedTimer _timer; |
4028 ResourceMark rm; | |
4029 HandleMark hm; | |
4030 | |
4031 DEBUG_ONLY(_collector->verify_overflow_empty();) | |
4032 | |
4033 // Before we begin work, our work queue should be empty | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4034 assert(work_queue(worker_id)->size() == 0, "Expected to be empty"); |
0 | 4035 // Scan the bitmap covering _cms_space, tracing through grey objects. |
4036 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4037 do_scan_and_mark(worker_id, _cms_space); |
0 | 4038 _timer.stop(); |
4039 if (PrintCMSStatistics != 0) { | |
4040 gclog_or_tty->print_cr("Finished cms space scanning in %dth thread: %3.3f sec", | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4041 worker_id, _timer.seconds()); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4042 // XXX: need xxx/xxx type of notation, two timers |
0 | 4043 } |
4044 | |
4045 // ... do work stealing | |
4046 _timer.reset(); | |
4047 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4048 do_work_steal(worker_id); |
0 | 4049 _timer.stop(); |
4050 if (PrintCMSStatistics != 0) { | |
4051 gclog_or_tty->print_cr("Finished work stealing in %dth thread: %3.3f sec", | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4052 worker_id, _timer.seconds()); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4053 // XXX: need xxx/xxx type of notation, two timers |
0 | 4054 } |
4055 assert(_collector->_markStack.isEmpty(), "Should have been emptied"); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4056 assert(work_queue(worker_id)->size() == 0, "Should have been emptied"); |
0 | 4057 // Note that under the current task protocol, the |
4058 // following assertion is true even of the spaces | |
4059 // expanded since the completion of the concurrent | |
4060 // marking. XXX This will likely change under a strict | |
4061 // ABORT semantics. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4062 // After perm removal the comparison was changed to |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4063 // greater than or equal to from strictly greater than. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4064 // Before perm removal the highest address sweep would |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4065 // have been at the end of perm gen but now is at the |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4066 // end of the tenured gen. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4067 assert(_global_finger >= _cms_space->end(), |
0 | 4068 "All tasks have been completed"); |
4069 DEBUG_ONLY(_collector->verify_overflow_empty();) | |
4070 } | |
4071 | |
4072 void CMSConcMarkingTask::bump_global_finger(HeapWord* f) { | |
4073 HeapWord* read = _global_finger; | |
4074 HeapWord* cur = read; | |
4075 while (f > read) { | |
4076 cur = read; | |
4077 read = (HeapWord*) Atomic::cmpxchg_ptr(f, &_global_finger, cur); | |
4078 if (cur == read) { | |
4079 // our cas succeeded | |
4080 assert(_global_finger >= f, "protocol consistency"); | |
4081 break; | |
4082 } | |
4083 } | |
4084 } | |
4085 | |
4086 // This is really inefficient, and should be redone by | |
4087 // using (not yet available) block-read and -write interfaces to the | |
4088 // stack and the work_queue. XXX FIX ME !!! | |
4089 bool CMSConcMarkingTask::get_work_from_overflow_stack(CMSMarkStack* ovflw_stk, | |
4090 OopTaskQueue* work_q) { | |
4091 // Fast lock-free check | |
4092 if (ovflw_stk->length() == 0) { | |
4093 return false; | |
4094 } | |
4095 assert(work_q->size() == 0, "Shouldn't steal"); | |
4096 MutexLockerEx ml(ovflw_stk->par_lock(), | |
4097 Mutex::_no_safepoint_check_flag); | |
4098 // Grab up to 1/4 the size of the work queue | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
4099 size_t num = MIN2((size_t)(work_q->max_elems() - work_q->size())/4, |
0 | 4100 (size_t)ParGCDesiredObjsFromOverflowList); |
4101 num = MIN2(num, ovflw_stk->length()); | |
4102 for (int i = (int) num; i > 0; i--) { | |
4103 oop cur = ovflw_stk->pop(); | |
4104 assert(cur != NULL, "Counted wrong?"); | |
4105 work_q->push(cur); | |
4106 } | |
4107 return num > 0; | |
4108 } | |
4109 | |
4110 void CMSConcMarkingTask::do_scan_and_mark(int i, CompactibleFreeListSpace* sp) { | |
4111 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); | |
4112 int n_tasks = pst->n_tasks(); | |
4113 // We allow that there may be no tasks to do here because | |
4114 // we are restarting after a stack overflow. | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4115 assert(pst->valid() || n_tasks == 0, "Uninitialized use?"); |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4116 uint nth_task = 0; |
0 | 4117 |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4118 HeapWord* aligned_start = sp->bottom(); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4119 if (sp->used_region().contains(_restart_addr)) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4120 // Align down to a card boundary for the start of 0th task |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4121 // for this space. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4122 aligned_start = |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4123 (HeapWord*)align_size_down((uintptr_t)_restart_addr, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4124 CardTableModRefBS::card_size); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4125 } |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4126 |
0 | 4127 size_t chunk_size = sp->marking_task_size(); |
4128 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
4129 // Having claimed the nth task in this space, | |
4130 // compute the chunk that it corresponds to: | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4131 MemRegion span = MemRegion(aligned_start + nth_task*chunk_size, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4132 aligned_start + (nth_task+1)*chunk_size); |
0 | 4133 // Try and bump the global finger via a CAS; |
4134 // note that we need to do the global finger bump | |
4135 // _before_ taking the intersection below, because | |
4136 // the task corresponding to that region will be | |
4137 // deemed done even if the used_region() expands | |
4138 // because of allocation -- as it almost certainly will | |
4139 // during start-up while the threads yield in the | |
4140 // closure below. | |
4141 HeapWord* finger = span.end(); | |
4142 bump_global_finger(finger); // atomically | |
4143 // There are null tasks here corresponding to chunks | |
4144 // beyond the "top" address of the space. | |
4145 span = span.intersection(sp->used_region()); | |
4146 if (!span.is_empty()) { // Non-null task | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4147 HeapWord* prev_obj; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4148 assert(!span.contains(_restart_addr) || nth_task == 0, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4149 "Inconsistency"); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4150 if (nth_task == 0) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4151 // For the 0th task, we'll not need to compute a block_start. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4152 if (span.contains(_restart_addr)) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4153 // In the case of a restart because of stack overflow, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4154 // we might additionally skip a chunk prefix. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4155 prev_obj = _restart_addr; |
0 | 4156 } else { |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4157 prev_obj = span.start(); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4158 } |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4159 } else { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4160 // We want to skip the first object because |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4161 // the protocol is to scan any object in its entirety |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4162 // that _starts_ in this span; a fortiori, any |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4163 // object starting in an earlier span is scanned |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4164 // as part of an earlier claimed task. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4165 // Below we use the "careful" version of block_start |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4166 // so we do not try to navigate uninitialized objects. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4167 prev_obj = sp->block_start_careful(span.start()); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4168 // Below we use a variant of block_size that uses the |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4169 // Printezis bits to avoid waiting for allocated |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4170 // objects to become initialized/parsable. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4171 while (prev_obj < span.start()) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4172 size_t sz = sp->block_size_no_stall(prev_obj, _collector); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4173 if (sz > 0) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4174 prev_obj += sz; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4175 } else { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4176 // In this case we may end up doing a bit of redundant |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4177 // scanning, but that appears unavoidable, short of |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4178 // locking the free list locks; see bug 6324141. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4179 break; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4180 } |
0 | 4181 } |
4182 } | |
4183 if (prev_obj < span.end()) { | |
4184 MemRegion my_span = MemRegion(prev_obj, span.end()); | |
4185 // Do the marking work within a non-empty span -- | |
4186 // the last argument to the constructor indicates whether the | |
4187 // iteration should be incremental with periodic yields. | |
4188 Par_MarkFromRootsClosure cl(this, _collector, my_span, | |
4189 &_collector->_markBitMap, | |
4190 work_queue(i), | |
4191 &_collector->_markStack, | |
4192 _asynch); | |
4193 _collector->_markBitMap.iterate(&cl, my_span.start(), my_span.end()); | |
4194 } // else nothing to do for this task | |
4195 } // else nothing to do for this task | |
4196 } | |
4197 // We'd be tempted to assert here that since there are no | |
4198 // more tasks left to claim in this space, the global_finger | |
4199 // must exceed space->top() and a fortiori space->end(). However, | |
4200 // that would not quite be correct because the bumping of | |
4201 // global_finger occurs strictly after the claiming of a task, | |
4202 // so by the time we reach here the global finger may not yet | |
4203 // have been bumped up by the thread that claimed the last | |
4204 // task. | |
4205 pst->all_tasks_completed(); | |
4206 } | |
4207 | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
4208 class Par_ConcMarkingClosure: public MetadataAwareOopClosure { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4209 private: |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4210 CMSCollector* _collector; |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4211 CMSConcMarkingTask* _task; |
0 | 4212 MemRegion _span; |
4213 CMSBitMap* _bit_map; | |
4214 CMSMarkStack* _overflow_stack; | |
4215 OopTaskQueue* _work_queue; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4216 protected: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4217 DO_OOP_WORK_DEFN |
0 | 4218 public: |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4219 Par_ConcMarkingClosure(CMSCollector* collector, CMSConcMarkingTask* task, OopTaskQueue* work_queue, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4220 CMSBitMap* bit_map, CMSMarkStack* overflow_stack): |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
4221 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4222 _collector(collector), |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4223 _task(task), |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4224 _span(collector->_span), |
0 | 4225 _work_queue(work_queue), |
4226 _bit_map(bit_map), | |
935 | 4227 _overflow_stack(overflow_stack) |
4228 { } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4229 virtual void do_oop(oop* p); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4230 virtual void do_oop(narrowOop* p); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4231 |
0 | 4232 void trim_queue(size_t max); |
4233 void handle_stack_overflow(HeapWord* lost); | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4234 void do_yield_check() { |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4235 if (_task->should_yield()) { |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4236 _task->yield(); |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4237 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4238 } |
0 | 4239 }; |
4240 | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4241 // Grey object scanning during work stealing phase -- |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4242 // the salient assumption here is that any references |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4243 // that are in these stolen objects being scanned must |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4244 // already have been initialized (else they would not have |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4245 // been published), so we do not need to check for |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4246 // uninitialized objects before pushing here. |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4247 void Par_ConcMarkingClosure::do_oop(oop obj) { |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4248 assert(obj->is_oop_or_null(true), "expected an oop or NULL"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4249 HeapWord* addr = (HeapWord*)obj; |
0 | 4250 // Check if oop points into the CMS generation |
4251 // and is not marked | |
4252 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
4253 // a white object ... | |
4254 // If we manage to "claim" the object, by being the | |
4255 // first thread to mark it, then we push it on our | |
4256 // marking stack | |
4257 if (_bit_map->par_mark(addr)) { // ... now grey | |
4258 // push on work queue (grey set) | |
4259 bool simulate_overflow = false; | |
4260 NOT_PRODUCT( | |
4261 if (CMSMarkStackOverflowALot && | |
4262 _collector->simulate_overflow()) { | |
4263 // simulate a stack overflow | |
4264 simulate_overflow = true; | |
4265 } | |
4266 ) | |
4267 if (simulate_overflow || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4268 !(_work_queue->push(obj) || _overflow_stack->par_push(obj))) { |
0 | 4269 // stack overflow |
4270 if (PrintCMSStatistics != 0) { | |
4271 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
4272 SIZE_FORMAT, _overflow_stack->capacity()); | |
4273 } | |
4274 // We cannot assert that the overflow stack is full because | |
4275 // it may have been emptied since. | |
4276 assert(simulate_overflow || | |
4277 _work_queue->size() == _work_queue->max_elems(), | |
4278 "Else push should have succeeded"); | |
4279 handle_stack_overflow(addr); | |
4280 } | |
4281 } // Else, some other thread got there first | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4282 do_yield_check(); |
0 | 4283 } |
4284 } | |
4285 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4286 void Par_ConcMarkingClosure::do_oop(oop* p) { Par_ConcMarkingClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4287 void Par_ConcMarkingClosure::do_oop(narrowOop* p) { Par_ConcMarkingClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4288 |
0 | 4289 void Par_ConcMarkingClosure::trim_queue(size_t max) { |
4290 while (_work_queue->size() > max) { | |
4291 oop new_oop; | |
4292 if (_work_queue->pop_local(new_oop)) { | |
4293 assert(new_oop->is_oop(), "Should be an oop"); | |
4294 assert(_bit_map->isMarked((HeapWord*)new_oop), "Grey object"); | |
4295 assert(_span.contains((HeapWord*)new_oop), "Not in span"); | |
4296 new_oop->oop_iterate(this); // do_oop() above | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4297 do_yield_check(); |
0 | 4298 } |
4299 } | |
4300 } | |
4301 | |
4302 // Upon stack overflow, we discard (part of) the stack, | |
4303 // remembering the least address amongst those discarded | |
4304 // in CMSCollector's _restart_address. | |
4305 void Par_ConcMarkingClosure::handle_stack_overflow(HeapWord* lost) { | |
4306 // We need to do this under a mutex to prevent other | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4307 // workers from interfering with the work done below. |
0 | 4308 MutexLockerEx ml(_overflow_stack->par_lock(), |
4309 Mutex::_no_safepoint_check_flag); | |
4310 // Remember the least grey address discarded | |
4311 HeapWord* ra = (HeapWord*)_overflow_stack->least_value(lost); | |
4312 _collector->lower_restart_addr(ra); | |
4313 _overflow_stack->reset(); // discard stack contents | |
4314 _overflow_stack->expand(); // expand the stack if possible | |
4315 } | |
4316 | |
4317 | |
4318 void CMSConcMarkingTask::do_work_steal(int i) { | |
4319 OopTaskQueue* work_q = work_queue(i); | |
4320 oop obj_to_scan; | |
4321 CMSBitMap* bm = &(_collector->_markBitMap); | |
4322 CMSMarkStack* ovflw = &(_collector->_markStack); | |
4323 int* seed = _collector->hash_seed(i); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4324 Par_ConcMarkingClosure cl(_collector, this, work_q, bm, ovflw); |
0 | 4325 while (true) { |
4326 cl.trim_queue(0); | |
4327 assert(work_q->size() == 0, "Should have been emptied above"); | |
4328 if (get_work_from_overflow_stack(ovflw, work_q)) { | |
4329 // Can't assert below because the work obtained from the | |
4330 // overflow stack may already have been stolen from us. | |
4331 // assert(work_q->size() > 0, "Work from overflow stack"); | |
4332 continue; | |
4333 } else if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
4334 assert(obj_to_scan->is_oop(), "Should be an oop"); | |
4335 assert(bm->isMarked((HeapWord*)obj_to_scan), "Grey object"); | |
4336 obj_to_scan->oop_iterate(&cl); | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4337 } else if (terminator()->offer_termination(&_term_term)) { |
0 | 4338 assert(work_q->size() == 0, "Impossible!"); |
4339 break; | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4340 } else if (yielding() || should_yield()) { |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4341 yield(); |
0 | 4342 } |
4343 } | |
4344 } | |
4345 | |
4346 // This is run by the CMS (coordinator) thread. | |
4347 void CMSConcMarkingTask::coordinator_yield() { | |
4348 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
4349 "CMS thread should hold CMS token"); | |
4350 // First give up the locks, then yield, then re-lock | |
4351 // We should probably use a constructor/destructor idiom to | |
4352 // do this unlock/lock or modify the MutexUnlocker class to | |
4353 // serve our purpose. XXX | |
4354 assert_lock_strong(_bit_map_lock); | |
4355 _bit_map_lock->unlock(); | |
4356 ConcurrentMarkSweepThread::desynchronize(true); | |
4357 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
4358 _collector->stopTimer(); | |
4359 if (PrintCMSStatistics != 0) { | |
4360 _collector->incrementYields(); | |
4361 } | |
4362 _collector->icms_wait(); | |
4363 | |
4364 // It is possible for whichever thread initiated the yield request | |
4365 // not to get a chance to wake up and take the bitmap lock between | |
4366 // this thread releasing it and reacquiring it. So, while the | |
4367 // should_yield() flag is on, let's sleep for a bit to give the | |
4368 // other thread a chance to wake up. The limit imposed on the number | |
4369 // of iterations is defensive, to avoid any unforseen circumstances | |
4370 // putting us into an infinite loop. Since it's always been this | |
4371 // (coordinator_yield()) method that was observed to cause the | |
4372 // problem, we are using a parameter (CMSCoordinatorYieldSleepCount) | |
4373 // which is by default non-zero. For the other seven methods that | |
4374 // also perform the yield operation, as are using a different | |
4375 // parameter (CMSYieldSleepCount) which is by default zero. This way we | |
4376 // can enable the sleeping for those methods too, if necessary. | |
4377 // See 6442774. | |
4378 // | |
4379 // We really need to reconsider the synchronization between the GC | |
4380 // thread and the yield-requesting threads in the future and we | |
4381 // should really use wait/notify, which is the recommended | |
4382 // way of doing this type of interaction. Additionally, we should | |
4383 // consolidate the eight methods that do the yield operation and they | |
4384 // are almost identical into one for better maintenability and | |
4385 // readability. See 6445193. | |
4386 // | |
4387 // Tony 2006.06.29 | |
4388 for (unsigned i = 0; i < CMSCoordinatorYieldSleepCount && | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4389 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4390 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 4391 os::sleep(Thread::current(), 1, false); |
4392 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
4393 } | |
4394 | |
4395 ConcurrentMarkSweepThread::synchronize(true); | |
4396 _bit_map_lock->lock_without_safepoint_check(); | |
4397 _collector->startTimer(); | |
4398 } | |
4399 | |
4400 bool CMSCollector::do_marking_mt(bool asynch) { | |
1284 | 4401 assert(ConcGCThreads > 0 && conc_workers() != NULL, "precondition"); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4402 int num_workers = AdaptiveSizePolicy::calc_active_conc_workers( |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4403 conc_workers()->total_workers(), |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4404 conc_workers()->active_workers(), |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4405 Threads::number_of_non_daemon_threads()); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4406 conc_workers()->set_active_workers(num_workers); |
0 | 4407 |
4408 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); | |
4409 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4410 CMSConcMarkingTask tsk(this, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4411 cms_space, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4412 asynch, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4413 conc_workers(), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4414 task_queues()); |
0 | 4415 |
4416 // Since the actual number of workers we get may be different | |
4417 // from the number we requested above, do we need to do anything different | |
4418 // below? In particular, may be we need to subclass the SequantialSubTasksDone | |
4419 // class?? XXX | |
4420 cms_space ->initialize_sequential_subtasks_for_marking(num_workers); | |
4421 | |
4422 // Refs discovery is already non-atomic. | |
4423 assert(!ref_processor()->discovery_is_atomic(), "Should be non-atomic"); | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4424 assert(ref_processor()->discovery_is_mt(), "Discovery should be MT"); |
0 | 4425 conc_workers()->start_task(&tsk); |
4426 while (tsk.yielded()) { | |
4427 tsk.coordinator_yield(); | |
4428 conc_workers()->continue_task(&tsk); | |
4429 } | |
4430 // If the task was aborted, _restart_addr will be non-NULL | |
4431 assert(tsk.completed() || _restart_addr != NULL, "Inconsistency"); | |
4432 while (_restart_addr != NULL) { | |
4433 // XXX For now we do not make use of ABORTED state and have not | |
4434 // yet implemented the right abort semantics (even in the original | |
4435 // single-threaded CMS case). That needs some more investigation | |
4436 // and is deferred for now; see CR# TBF. 07252005YSR. XXX | |
4437 assert(!CMSAbortSemantics || tsk.aborted(), "Inconsistency"); | |
4438 // If _restart_addr is non-NULL, a marking stack overflow | |
605 | 4439 // occurred; we need to do a fresh marking iteration from the |
0 | 4440 // indicated restart address. |
4441 if (_foregroundGCIsActive && asynch) { | |
4442 // We may be running into repeated stack overflows, having | |
4443 // reached the limit of the stack size, while making very | |
4444 // slow forward progress. It may be best to bail out and | |
4445 // let the foreground collector do its job. | |
4446 // Clear _restart_addr, so that foreground GC | |
4447 // works from scratch. This avoids the headache of | |
4448 // a "rescan" which would otherwise be needed because | |
4449 // of the dirty mod union table & card table. | |
4450 _restart_addr = NULL; | |
4451 return false; | |
4452 } | |
4453 // Adjust the task to restart from _restart_addr | |
4454 tsk.reset(_restart_addr); | |
4455 cms_space ->initialize_sequential_subtasks_for_marking(num_workers, | |
4456 _restart_addr); | |
4457 _restart_addr = NULL; | |
4458 // Get the workers going again | |
4459 conc_workers()->start_task(&tsk); | |
4460 while (tsk.yielded()) { | |
4461 tsk.coordinator_yield(); | |
4462 conc_workers()->continue_task(&tsk); | |
4463 } | |
4464 } | |
4465 assert(tsk.completed(), "Inconsistency"); | |
4466 assert(tsk.result() == true, "Inconsistency"); | |
4467 return true; | |
4468 } | |
4469 | |
4470 bool CMSCollector::do_marking_st(bool asynch) { | |
4471 ResourceMark rm; | |
4472 HandleMark hm; | |
4473 | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4474 // Temporarily make refs discovery single threaded (non-MT) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4475 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(ref_processor(), false); |
0 | 4476 MarkFromRootsClosure markFromRootsClosure(this, _span, &_markBitMap, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4477 &_markStack, CMSYield && asynch); |
0 | 4478 // the last argument to iterate indicates whether the iteration |
4479 // should be incremental with periodic yields. | |
4480 _markBitMap.iterate(&markFromRootsClosure); | |
4481 // If _restart_addr is non-NULL, a marking stack overflow | |
605 | 4482 // occurred; we need to do a fresh iteration from the |
0 | 4483 // indicated restart address. |
4484 while (_restart_addr != NULL) { | |
4485 if (_foregroundGCIsActive && asynch) { | |
4486 // We may be running into repeated stack overflows, having | |
4487 // reached the limit of the stack size, while making very | |
4488 // slow forward progress. It may be best to bail out and | |
4489 // let the foreground collector do its job. | |
4490 // Clear _restart_addr, so that foreground GC | |
4491 // works from scratch. This avoids the headache of | |
4492 // a "rescan" which would otherwise be needed because | |
4493 // of the dirty mod union table & card table. | |
4494 _restart_addr = NULL; | |
4495 return false; // indicating failure to complete marking | |
4496 } | |
4497 // Deal with stack overflow: | |
4498 // we restart marking from _restart_addr | |
4499 HeapWord* ra = _restart_addr; | |
4500 markFromRootsClosure.reset(ra); | |
4501 _restart_addr = NULL; | |
4502 _markBitMap.iterate(&markFromRootsClosure, ra, _span.end()); | |
4503 } | |
4504 return true; | |
4505 } | |
4506 | |
4507 void CMSCollector::preclean() { | |
4508 check_correct_thread_executing(); | |
4509 assert(Thread::current()->is_ConcurrentGC_thread(), "Wrong thread"); | |
4510 verify_work_stacks_empty(); | |
4511 verify_overflow_empty(); | |
4512 _abort_preclean = false; | |
4513 if (CMSPrecleaningEnabled) { | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4514 if (!CMSEdenChunksRecordAlways) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4515 _eden_chunk_index = 0; |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4516 } |
0 | 4517 size_t used = get_eden_used(); |
4518 size_t capacity = get_eden_capacity(); | |
4519 // Don't start sampling unless we will get sufficiently | |
4520 // many samples. | |
4521 if (used < (capacity/(CMSScheduleRemarkSamplingRatio * 100) | |
4522 * CMSScheduleRemarkEdenPenetration)) { | |
4523 _start_sampling = true; | |
4524 } else { | |
4525 _start_sampling = false; | |
4526 } | |
4527 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
4528 CMSPhaseAccounting pa(this, "preclean", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 4529 preclean_work(CMSPrecleanRefLists1, CMSPrecleanSurvivors1); |
4530 } | |
4531 CMSTokenSync x(true); // is cms thread | |
4532 if (CMSPrecleaningEnabled) { | |
4533 sample_eden(); | |
4534 _collectorState = AbortablePreclean; | |
4535 } else { | |
4536 _collectorState = FinalMarking; | |
4537 } | |
4538 verify_work_stacks_empty(); | |
4539 verify_overflow_empty(); | |
4540 } | |
4541 | |
4542 // Try and schedule the remark such that young gen | |
4543 // occupancy is CMSScheduleRemarkEdenPenetration %. | |
4544 void CMSCollector::abortable_preclean() { | |
4545 check_correct_thread_executing(); | |
4546 assert(CMSPrecleaningEnabled, "Inconsistent control state"); | |
4547 assert(_collectorState == AbortablePreclean, "Inconsistent control state"); | |
4548 | |
4549 // If Eden's current occupancy is below this threshold, | |
4550 // immediately schedule the remark; else preclean | |
4551 // past the next scavenge in an effort to | |
4552 // schedule the pause as described avove. By choosing | |
4553 // CMSScheduleRemarkEdenSizeThreshold >= max eden size | |
4554 // we will never do an actual abortable preclean cycle. | |
4555 if (get_eden_used() > CMSScheduleRemarkEdenSizeThreshold) { | |
4556 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
4557 CMSPhaseAccounting pa(this, "abortable-preclean", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 4558 // We need more smarts in the abortable preclean |
4559 // loop below to deal with cases where allocation | |
4560 // in young gen is very very slow, and our precleaning | |
4561 // is running a losing race against a horde of | |
4562 // mutators intent on flooding us with CMS updates | |
4563 // (dirty cards). | |
4564 // One, admittedly dumb, strategy is to give up | |
4565 // after a certain number of abortable precleaning loops | |
4566 // or after a certain maximum time. We want to make | |
4567 // this smarter in the next iteration. | |
4568 // XXX FIX ME!!! YSR | |
4569 size_t loops = 0, workdone = 0, cumworkdone = 0, waited = 0; | |
4570 while (!(should_abort_preclean() || | |
4571 ConcurrentMarkSweepThread::should_terminate())) { | |
4572 workdone = preclean_work(CMSPrecleanRefLists2, CMSPrecleanSurvivors2); | |
4573 cumworkdone += workdone; | |
4574 loops++; | |
4575 // Voluntarily terminate abortable preclean phase if we have | |
4576 // been at it for too long. | |
4577 if ((CMSMaxAbortablePrecleanLoops != 0) && | |
4578 loops >= CMSMaxAbortablePrecleanLoops) { | |
4579 if (PrintGCDetails) { | |
4580 gclog_or_tty->print(" CMS: abort preclean due to loops "); | |
4581 } | |
4582 break; | |
4583 } | |
4584 if (pa.wallclock_millis() > CMSMaxAbortablePrecleanTime) { | |
4585 if (PrintGCDetails) { | |
4586 gclog_or_tty->print(" CMS: abort preclean due to time "); | |
4587 } | |
4588 break; | |
4589 } | |
4590 // If we are doing little work each iteration, we should | |
4591 // take a short break. | |
4592 if (workdone < CMSAbortablePrecleanMinWorkPerIteration) { | |
4593 // Sleep for some time, waiting for work to accumulate | |
4594 stopTimer(); | |
4595 cmsThread()->wait_on_cms_lock(CMSAbortablePrecleanWaitMillis); | |
4596 startTimer(); | |
4597 waited++; | |
4598 } | |
4599 } | |
4600 if (PrintCMSStatistics > 0) { | |
4601 gclog_or_tty->print(" [%d iterations, %d waits, %d cards)] ", | |
4602 loops, waited, cumworkdone); | |
4603 } | |
4604 } | |
4605 CMSTokenSync x(true); // is cms thread | |
4606 if (_collectorState != Idling) { | |
4607 assert(_collectorState == AbortablePreclean, | |
4608 "Spontaneous state transition?"); | |
4609 _collectorState = FinalMarking; | |
4610 } // Else, a foreground collection completed this CMS cycle. | |
4611 return; | |
4612 } | |
4613 | |
4614 // Respond to an Eden sampling opportunity | |
4615 void CMSCollector::sample_eden() { | |
4616 // Make sure a young gc cannot sneak in between our | |
4617 // reading and recording of a sample. | |
4618 assert(Thread::current()->is_ConcurrentGC_thread(), | |
4619 "Only the cms thread may collect Eden samples"); | |
4620 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
4621 "Should collect samples while holding CMS token"); | |
4622 if (!_start_sampling) { | |
4623 return; | |
4624 } | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4625 // When CMSEdenChunksRecordAlways is true, the eden chunk array |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4626 // is populated by the young generation. |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4627 if (_eden_chunk_array != NULL && !CMSEdenChunksRecordAlways) { |
0 | 4628 if (_eden_chunk_index < _eden_chunk_capacity) { |
4629 _eden_chunk_array[_eden_chunk_index] = *_top_addr; // take sample | |
4630 assert(_eden_chunk_array[_eden_chunk_index] <= *_end_addr, | |
4631 "Unexpected state of Eden"); | |
4632 // We'd like to check that what we just sampled is an oop-start address; | |
4633 // however, we cannot do that here since the object may not yet have been | |
4634 // initialized. So we'll instead do the check when we _use_ this sample | |
4635 // later. | |
4636 if (_eden_chunk_index == 0 || | |
4637 (pointer_delta(_eden_chunk_array[_eden_chunk_index], | |
4638 _eden_chunk_array[_eden_chunk_index-1]) | |
4639 >= CMSSamplingGrain)) { | |
4640 _eden_chunk_index++; // commit sample | |
4641 } | |
4642 } | |
4643 } | |
4644 if ((_collectorState == AbortablePreclean) && !_abort_preclean) { | |
4645 size_t used = get_eden_used(); | |
4646 size_t capacity = get_eden_capacity(); | |
4647 assert(used <= capacity, "Unexpected state of Eden"); | |
4648 if (used > (capacity/100 * CMSScheduleRemarkEdenPenetration)) { | |
4649 _abort_preclean = true; | |
4650 } | |
4651 } | |
4652 } | |
4653 | |
4654 | |
4655 size_t CMSCollector::preclean_work(bool clean_refs, bool clean_survivor) { | |
4656 assert(_collectorState == Precleaning || | |
4657 _collectorState == AbortablePreclean, "incorrect state"); | |
4658 ResourceMark rm; | |
4659 HandleMark hm; | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4660 |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4661 // Precleaning is currently not MT but the reference processor |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4662 // may be set for MT. Disable it temporarily here. |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4663 ReferenceProcessor* rp = ref_processor(); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4664 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(rp, false); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4665 |
0 | 4666 // Do one pass of scrubbing the discovered reference lists |
4667 // to remove any reference objects with strongly-reachable | |
4668 // referents. | |
4669 if (clean_refs) { | |
4670 CMSPrecleanRefsYieldClosure yield_cl(this); | |
4671 assert(rp->span().equals(_span), "Spans should be equal"); | |
4672 CMSKeepAliveClosure keep_alive(this, _span, &_markBitMap, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4673 &_markStack, true /* preclean */); |
0 | 4674 CMSDrainMarkingStackClosure complete_trace(this, |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
4675 _span, &_markBitMap, &_markStack, |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
4676 &keep_alive, true /* preclean */); |
0 | 4677 |
4678 // We don't want this step to interfere with a young | |
4679 // collection because we don't want to take CPU | |
4680 // or memory bandwidth away from the young GC threads | |
4681 // (which may be as many as there are CPUs). | |
4682 // Note that we don't need to protect ourselves from | |
4683 // interference with mutators because they can't | |
4684 // manipulate the discovered reference lists nor affect | |
4685 // the computed reachability of the referents, the | |
4686 // only properties manipulated by the precleaning | |
4687 // of these reference lists. | |
4688 stopTimer(); | |
4689 CMSTokenSyncWithLocks x(true /* is cms thread */, | |
4690 bitMapLock()); | |
4691 startTimer(); | |
4692 sample_eden(); | |
935 | 4693 |
0 | 4694 // The following will yield to allow foreground |
4695 // collection to proceed promptly. XXX YSR: | |
4696 // The code in this method may need further | |
4697 // tweaking for better performance and some restructuring | |
4698 // for cleaner interfaces. | |
10405 | 4699 GCTimer *gc_timer = NULL; // Currently not tracing concurrent phases |
0 | 4700 rp->preclean_discovered_references( |
10405 | 4701 rp->is_alive_non_header(), &keep_alive, &complete_trace, &yield_cl, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
4702 gc_timer, _gc_tracer_cm->gc_id()); |
0 | 4703 } |
4704 | |
4705 if (clean_survivor) { // preclean the active survivor space(s) | |
4706 assert(_young_gen->kind() == Generation::DefNew || | |
4707 _young_gen->kind() == Generation::ParNew || | |
4708 _young_gen->kind() == Generation::ASParNew, | |
4709 "incorrect type for cast"); | |
4710 DefNewGeneration* dng = (DefNewGeneration*)_young_gen; | |
4711 PushAndMarkClosure pam_cl(this, _span, ref_processor(), | |
4712 &_markBitMap, &_modUnionTable, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4713 &_markStack, true /* precleaning phase */); |
0 | 4714 stopTimer(); |
4715 CMSTokenSyncWithLocks ts(true /* is cms thread */, | |
4716 bitMapLock()); | |
4717 startTimer(); | |
4718 unsigned int before_count = | |
4719 GenCollectedHeap::heap()->total_collections(); | |
4720 SurvivorSpacePrecleanClosure | |
4721 sss_cl(this, _span, &_markBitMap, &_markStack, | |
4722 &pam_cl, before_count, CMSYield); | |
4723 dng->from()->object_iterate_careful(&sss_cl); | |
4724 dng->to()->object_iterate_careful(&sss_cl); | |
4725 } | |
4726 MarkRefsIntoAndScanClosure | |
4727 mrias_cl(_span, ref_processor(), &_markBitMap, &_modUnionTable, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4728 &_markStack, this, CMSYield, |
0 | 4729 true /* precleaning phase */); |
4730 // CAUTION: The following closure has persistent state that may need to | |
4731 // be reset upon a decrease in the sequence of addresses it | |
4732 // processes. | |
4733 ScanMarkedObjectsAgainCarefullyClosure | |
4734 smoac_cl(this, _span, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4735 &_markBitMap, &_markStack, &mrias_cl, CMSYield); |
0 | 4736 |
4737 // Preclean dirty cards in ModUnionTable and CardTable using | |
4738 // appropriate convergence criterion; | |
4739 // repeat CMSPrecleanIter times unless we find that | |
4740 // we are losing. | |
4741 assert(CMSPrecleanIter < 10, "CMSPrecleanIter is too large"); | |
4742 assert(CMSPrecleanNumerator < CMSPrecleanDenominator, | |
4743 "Bad convergence multiplier"); | |
4744 assert(CMSPrecleanThreshold >= 100, | |
4745 "Unreasonably low CMSPrecleanThreshold"); | |
4746 | |
4747 size_t numIter, cumNumCards, lastNumCards, curNumCards; | |
4748 for (numIter = 0, cumNumCards = lastNumCards = curNumCards = 0; | |
4749 numIter < CMSPrecleanIter; | |
4750 numIter++, lastNumCards = curNumCards, cumNumCards += curNumCards) { | |
4751 curNumCards = preclean_mod_union_table(_cmsGen, &smoac_cl); | |
4752 if (Verbose && PrintGCDetails) { | |
4753 gclog_or_tty->print(" (modUnionTable: %d cards)", curNumCards); | |
4754 } | |
4755 // Either there are very few dirty cards, so re-mark | |
4756 // pause will be small anyway, or our pre-cleaning isn't | |
4757 // that much faster than the rate at which cards are being | |
4758 // dirtied, so we might as well stop and re-mark since | |
4759 // precleaning won't improve our re-mark time by much. | |
4760 if (curNumCards <= CMSPrecleanThreshold || | |
4761 (numIter > 0 && | |
4762 (curNumCards * CMSPrecleanDenominator > | |
4763 lastNumCards * CMSPrecleanNumerator))) { | |
4764 numIter++; | |
4765 cumNumCards += curNumCards; | |
4766 break; | |
4767 } | |
4768 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4769 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4770 preclean_klasses(&mrias_cl, _cmsGen->freelistLock()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4771 |
0 | 4772 curNumCards = preclean_card_table(_cmsGen, &smoac_cl); |
4773 cumNumCards += curNumCards; | |
4774 if (PrintGCDetails && PrintCMSStatistics != 0) { | |
4775 gclog_or_tty->print_cr(" (cardTable: %d cards, re-scanned %d cards, %d iterations)", | |
4776 curNumCards, cumNumCards, numIter); | |
4777 } | |
4778 return cumNumCards; // as a measure of useful work done | |
4779 } | |
4780 | |
4781 // PRECLEANING NOTES: | |
4782 // Precleaning involves: | |
4783 // . reading the bits of the modUnionTable and clearing the set bits. | |
4784 // . For the cards corresponding to the set bits, we scan the | |
4785 // objects on those cards. This means we need the free_list_lock | |
4786 // so that we can safely iterate over the CMS space when scanning | |
4787 // for oops. | |
4788 // . When we scan the objects, we'll be both reading and setting | |
4789 // marks in the marking bit map, so we'll need the marking bit map. | |
4790 // . For protecting _collector_state transitions, we take the CGC_lock. | |
4791 // Note that any races in the reading of of card table entries by the | |
4792 // CMS thread on the one hand and the clearing of those entries by the | |
4793 // VM thread or the setting of those entries by the mutator threads on the | |
4794 // other are quite benign. However, for efficiency it makes sense to keep | |
4795 // the VM thread from racing with the CMS thread while the latter is | |
4796 // dirty card info to the modUnionTable. We therefore also use the | |
4797 // CGC_lock to protect the reading of the card table and the mod union | |
4798 // table by the CM thread. | |
4799 // . We run concurrently with mutator updates, so scanning | |
4800 // needs to be done carefully -- we should not try to scan | |
4801 // potentially uninitialized objects. | |
4802 // | |
4803 // Locking strategy: While holding the CGC_lock, we scan over and | |
4804 // reset a maximal dirty range of the mod union / card tables, then lock | |
4805 // the free_list_lock and bitmap lock to do a full marking, then | |
4806 // release these locks; and repeat the cycle. This allows for a | |
4807 // certain amount of fairness in the sharing of these locks between | |
4808 // the CMS collector on the one hand, and the VM thread and the | |
4809 // mutators on the other. | |
4810 | |
4811 // NOTE: preclean_mod_union_table() and preclean_card_table() | |
4812 // further below are largely identical; if you need to modify | |
4813 // one of these methods, please check the other method too. | |
4814 | |
4815 size_t CMSCollector::preclean_mod_union_table( | |
4816 ConcurrentMarkSweepGeneration* gen, | |
4817 ScanMarkedObjectsAgainCarefullyClosure* cl) { | |
4818 verify_work_stacks_empty(); | |
4819 verify_overflow_empty(); | |
4820 | |
4821 // strategy: starting with the first card, accumulate contiguous | |
4822 // ranges of dirty cards; clear these cards, then scan the region | |
4823 // covered by these cards. | |
4824 | |
4825 // Since all of the MUT is committed ahead, we can just use | |
4826 // that, in case the generations expand while we are precleaning. | |
4827 // It might also be fine to just use the committed part of the | |
4828 // generation, but we might potentially miss cards when the | |
4829 // generation is rapidly expanding while we are in the midst | |
4830 // of precleaning. | |
4831 HeapWord* startAddr = gen->reserved().start(); | |
4832 HeapWord* endAddr = gen->reserved().end(); | |
4833 | |
4834 cl->setFreelistLock(gen->freelistLock()); // needed for yielding | |
4835 | |
4836 size_t numDirtyCards, cumNumDirtyCards; | |
4837 HeapWord *nextAddr, *lastAddr; | |
4838 for (cumNumDirtyCards = numDirtyCards = 0, | |
4839 nextAddr = lastAddr = startAddr; | |
4840 nextAddr < endAddr; | |
4841 nextAddr = lastAddr, cumNumDirtyCards += numDirtyCards) { | |
4842 | |
4843 ResourceMark rm; | |
4844 HandleMark hm; | |
4845 | |
4846 MemRegion dirtyRegion; | |
4847 { | |
4848 stopTimer(); | |
935 | 4849 // Potential yield point |
0 | 4850 CMSTokenSync ts(true); |
4851 startTimer(); | |
4852 sample_eden(); | |
4853 // Get dirty region starting at nextOffset (inclusive), | |
4854 // simultaneously clearing it. | |
4855 dirtyRegion = | |
4856 _modUnionTable.getAndClearMarkedRegion(nextAddr, endAddr); | |
4857 assert(dirtyRegion.start() >= nextAddr, | |
4858 "returned region inconsistent?"); | |
4859 } | |
4860 // Remember where the next search should begin. | |
4861 // The returned region (if non-empty) is a right open interval, | |
4862 // so lastOffset is obtained from the right end of that | |
4863 // interval. | |
4864 lastAddr = dirtyRegion.end(); | |
4865 // Should do something more transparent and less hacky XXX | |
4866 numDirtyCards = | |
4867 _modUnionTable.heapWordDiffToOffsetDiff(dirtyRegion.word_size()); | |
4868 | |
4869 // We'll scan the cards in the dirty region (with periodic | |
4870 // yields for foreground GC as needed). | |
4871 if (!dirtyRegion.is_empty()) { | |
4872 assert(numDirtyCards > 0, "consistency check"); | |
4873 HeapWord* stop_point = NULL; | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4874 stopTimer(); |
935 | 4875 // Potential yield point |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4876 CMSTokenSyncWithLocks ts(true, gen->freelistLock(), |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4877 bitMapLock()); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4878 startTimer(); |
0 | 4879 { |
4880 verify_work_stacks_empty(); | |
4881 verify_overflow_empty(); | |
4882 sample_eden(); | |
4883 stop_point = | |
4884 gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); | |
4885 } | |
4886 if (stop_point != NULL) { | |
4887 // The careful iteration stopped early either because it found an | |
4888 // uninitialized object, or because we were in the midst of an | |
4889 // "abortable preclean", which should now be aborted. Redirty | |
4890 // the bits corresponding to the partially-scanned or unscanned | |
4891 // cards. We'll either restart at the next block boundary or | |
4892 // abort the preclean. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4893 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4894 "Should only be AbortablePreclean."); |
0 | 4895 _modUnionTable.mark_range(MemRegion(stop_point, dirtyRegion.end())); |
4896 if (should_abort_preclean()) { | |
4897 break; // out of preclean loop | |
4898 } else { | |
4899 // Compute the next address at which preclean should pick up; | |
4900 // might need bitMapLock in order to read P-bits. | |
4901 lastAddr = next_card_start_after_block(stop_point); | |
4902 } | |
4903 } | |
4904 } else { | |
4905 assert(lastAddr == endAddr, "consistency check"); | |
4906 assert(numDirtyCards == 0, "consistency check"); | |
4907 break; | |
4908 } | |
4909 } | |
4910 verify_work_stacks_empty(); | |
4911 verify_overflow_empty(); | |
4912 return cumNumDirtyCards; | |
4913 } | |
4914 | |
4915 // NOTE: preclean_mod_union_table() above and preclean_card_table() | |
4916 // below are largely identical; if you need to modify | |
4917 // one of these methods, please check the other method too. | |
4918 | |
4919 size_t CMSCollector::preclean_card_table(ConcurrentMarkSweepGeneration* gen, | |
4920 ScanMarkedObjectsAgainCarefullyClosure* cl) { | |
4921 // strategy: it's similar to precleamModUnionTable above, in that | |
4922 // we accumulate contiguous ranges of dirty cards, mark these cards | |
4923 // precleaned, then scan the region covered by these cards. | |
4924 HeapWord* endAddr = (HeapWord*)(gen->_virtual_space.high()); | |
4925 HeapWord* startAddr = (HeapWord*)(gen->_virtual_space.low()); | |
4926 | |
4927 cl->setFreelistLock(gen->freelistLock()); // needed for yielding | |
4928 | |
4929 size_t numDirtyCards, cumNumDirtyCards; | |
4930 HeapWord *lastAddr, *nextAddr; | |
4931 | |
4932 for (cumNumDirtyCards = numDirtyCards = 0, | |
4933 nextAddr = lastAddr = startAddr; | |
4934 nextAddr < endAddr; | |
4935 nextAddr = lastAddr, cumNumDirtyCards += numDirtyCards) { | |
4936 | |
4937 ResourceMark rm; | |
4938 HandleMark hm; | |
4939 | |
4940 MemRegion dirtyRegion; | |
4941 { | |
4942 // See comments in "Precleaning notes" above on why we | |
4943 // do this locking. XXX Could the locking overheads be | |
4944 // too high when dirty cards are sparse? [I don't think so.] | |
4945 stopTimer(); | |
4946 CMSTokenSync x(true); // is cms thread | |
4947 startTimer(); | |
4948 sample_eden(); | |
4949 // Get and clear dirty region from card table | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4950 dirtyRegion = _ct->ct_bs()->dirty_card_range_after_reset( |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4951 MemRegion(nextAddr, endAddr), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4952 true, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4953 CardTableModRefBS::precleaned_card_val()); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4954 |
0 | 4955 assert(dirtyRegion.start() >= nextAddr, |
4956 "returned region inconsistent?"); | |
4957 } | |
4958 lastAddr = dirtyRegion.end(); | |
4959 numDirtyCards = | |
4960 dirtyRegion.word_size()/CardTableModRefBS::card_size_in_words; | |
4961 | |
4962 if (!dirtyRegion.is_empty()) { | |
4963 stopTimer(); | |
4964 CMSTokenSyncWithLocks ts(true, gen->freelistLock(), bitMapLock()); | |
4965 startTimer(); | |
4966 sample_eden(); | |
4967 verify_work_stacks_empty(); | |
4968 verify_overflow_empty(); | |
4969 HeapWord* stop_point = | |
4970 gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); | |
4971 if (stop_point != NULL) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4972 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4973 "Should only be AbortablePreclean."); |
0 | 4974 _ct->ct_bs()->invalidate(MemRegion(stop_point, dirtyRegion.end())); |
4975 if (should_abort_preclean()) { | |
4976 break; // out of preclean loop | |
4977 } else { | |
4978 // Compute the next address at which preclean should pick up. | |
4979 lastAddr = next_card_start_after_block(stop_point); | |
4980 } | |
4981 } | |
4982 } else { | |
4983 break; | |
4984 } | |
4985 } | |
4986 verify_work_stacks_empty(); | |
4987 verify_overflow_empty(); | |
4988 return cumNumDirtyCards; | |
4989 } | |
4990 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4991 class PrecleanKlassClosure : public KlassClosure { |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
4992 KlassToOopClosure _cm_klass_closure; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4993 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4994 PrecleanKlassClosure(OopClosure* oop_closure) : _cm_klass_closure(oop_closure) {} |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4995 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4996 if (k->has_accumulated_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4997 k->clear_accumulated_modified_oops(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4998 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4999 _cm_klass_closure.do_klass(k); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5000 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5001 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5002 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5003 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5004 // The freelist lock is needed to prevent asserts, is it really needed? |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5005 void CMSCollector::preclean_klasses(MarkRefsIntoAndScanClosure* cl, Mutex* freelistLock) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5006 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5007 cl->set_freelistLock(freelistLock); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5008 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5009 CMSTokenSyncWithLocks ts(true, freelistLock, bitMapLock()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5010 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5011 // SSS: Add equivalent to ScanMarkedObjectsAgainCarefullyClosure::do_yield_check and should_abort_preclean? |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5012 // SSS: We should probably check if precleaning should be aborted, at suitable intervals? |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5013 PrecleanKlassClosure preclean_klass_closure(cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5014 ClassLoaderDataGraph::classes_do(&preclean_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5015 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5016 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5017 verify_overflow_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5018 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5019 |
0 | 5020 void CMSCollector::checkpointRootsFinal(bool asynch, |
5021 bool clear_all_soft_refs, bool init_mark_was_synchronous) { | |
5022 assert(_collectorState == FinalMarking, "incorrect state transition?"); | |
5023 check_correct_thread_executing(); | |
5024 // world is stopped at this checkpoint | |
5025 assert(SafepointSynchronize::is_at_safepoint(), | |
5026 "world should be stopped"); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
5027 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
5028 |
0 | 5029 verify_work_stacks_empty(); |
5030 verify_overflow_empty(); | |
5031 | |
5032 SpecializationStats::clear(); | |
5033 if (PrintGCDetails) { | |
5034 gclog_or_tty->print("[YG occupancy: "SIZE_FORMAT" K ("SIZE_FORMAT" K)]", | |
5035 _young_gen->used() / K, | |
5036 _young_gen->capacity() / K); | |
5037 } | |
5038 if (asynch) { | |
5039 if (CMSScavengeBeforeRemark) { | |
5040 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5041 // Temporarily set flag to false, GCH->do_collection will | |
5042 // expect it to be false and set to true | |
5043 FlagSetting fl(gch->_is_gc_active, false); | |
10405 | 5044 NOT_PRODUCT(GCTraceTime t("Scavenge-Before-Remark", |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5045 PrintGCDetails && Verbose, true, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5046 int level = _cmsGen->level() - 1; |
5047 if (level >= 0) { | |
5048 gch->do_collection(true, // full (i.e. force, see below) | |
5049 false, // !clear_all_soft_refs | |
5050 0, // size | |
5051 false, // is_tlab | |
5052 level // max_level | |
5053 ); | |
5054 } | |
5055 } | |
5056 FreelistLocker x(this); | |
5057 MutexLockerEx y(bitMapLock(), | |
5058 Mutex::_no_safepoint_check_flag); | |
5059 assert(!init_mark_was_synchronous, "but that's impossible!"); | |
5060 checkpointRootsFinalWork(asynch, clear_all_soft_refs, false); | |
5061 } else { | |
5062 // already have all the locks | |
5063 checkpointRootsFinalWork(asynch, clear_all_soft_refs, | |
5064 init_mark_was_synchronous); | |
5065 } | |
5066 verify_work_stacks_empty(); | |
5067 verify_overflow_empty(); | |
5068 SpecializationStats::print(); | |
5069 } | |
5070 | |
5071 void CMSCollector::checkpointRootsFinalWork(bool asynch, | |
5072 bool clear_all_soft_refs, bool init_mark_was_synchronous) { | |
5073 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5074 NOT_PRODUCT(GCTraceTime tr("checkpointRootsFinalWork", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5075 |
5076 assert(haveFreelistLocks(), "must have free list locks"); | |
5077 assert_lock_strong(bitMapLock()); | |
5078 | |
5079 if (UseAdaptiveSizePolicy) { | |
5080 size_policy()->checkpoint_roots_final_begin(); | |
5081 } | |
5082 | |
5083 ResourceMark rm; | |
5084 HandleMark hm; | |
5085 | |
5086 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5087 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
5088 if (should_unload_classes()) { |
0 | 5089 CodeCache::gc_prologue(); |
5090 } | |
5091 assert(haveFreelistLocks(), "must have free list locks"); | |
5092 assert_lock_strong(bitMapLock()); | |
5093 | |
5094 if (!init_mark_was_synchronous) { | |
5095 // We might assume that we need not fill TLAB's when | |
5096 // CMSScavengeBeforeRemark is set, because we may have just done | |
5097 // a scavenge which would have filled all TLAB's -- and besides | |
5098 // Eden would be empty. This however may not always be the case -- | |
5099 // for instance although we asked for a scavenge, it may not have | |
5100 // happened because of a JNI critical section. We probably need | |
5101 // a policy for deciding whether we can in that case wait until | |
5102 // the critical section releases and then do the remark following | |
5103 // the scavenge, and skip it here. In the absence of that policy, | |
5104 // or of an indication of whether the scavenge did indeed occur, | |
5105 // we cannot rely on TLAB's having been filled and must do | |
5106 // so here just in case a scavenge did not happen. | |
5107 gch->ensure_parsability(false); // fill TLAB's, but no need to retire them | |
5108 // Update the saved marks which may affect the root scans. | |
5109 gch->save_marks(); | |
5110 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5111 if (CMSPrintEdenSurvivorChunks) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5112 print_eden_and_survivor_chunk_arrays(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5113 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5114 |
0 | 5115 { |
5116 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
5117 | |
5118 // Note on the role of the mod union table: | |
5119 // Since the marker in "markFromRoots" marks concurrently with | |
5120 // mutators, it is possible for some reachable objects not to have been | |
5121 // scanned. For instance, an only reference to an object A was | |
5122 // placed in object B after the marker scanned B. Unless B is rescanned, | |
5123 // A would be collected. Such updates to references in marked objects | |
5124 // are detected via the mod union table which is the set of all cards | |
5125 // dirtied since the first checkpoint in this GC cycle and prior to | |
5126 // the most recent young generation GC, minus those cleaned up by the | |
5127 // concurrent precleaning. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5128 if (CMSParallelRemarkEnabled && CollectedHeap::use_parallel_gc_threads()) { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5129 GCTraceTime t("Rescan (parallel) ", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5130 do_remark_parallel(); |
5131 } else { | |
10405 | 5132 GCTraceTime t("Rescan (non-parallel) ", PrintGCDetails, false, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5133 _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5134 do_remark_non_parallel(); |
5135 } | |
5136 } | |
5137 } else { | |
5138 assert(!asynch, "Can't have init_mark_was_synchronous in asynch mode"); | |
5139 // The initial mark was stop-world, so there's no rescanning to | |
5140 // do; go straight on to the next step below. | |
5141 } | |
5142 verify_work_stacks_empty(); | |
5143 verify_overflow_empty(); | |
5144 | |
5145 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5146 NOT_PRODUCT(GCTraceTime ts("refProcessingWork", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5147 refProcessingWork(asynch, clear_all_soft_refs); |
5148 } | |
5149 verify_work_stacks_empty(); | |
5150 verify_overflow_empty(); | |
5151 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
5152 if (should_unload_classes()) { |
0 | 5153 CodeCache::gc_epilogue(); |
5154 } | |
2147
9afee0b9fc1d
7012505: BreakpointWithFullGC.sh fails with Internal Error (src/share/vm/oops/methodOop.cpp:220)
kamg
parents:
2137
diff
changeset
|
5155 JvmtiExport::gc_epilogue(); |
0 | 5156 |
5157 // If we encountered any (marking stack / work queue) overflow | |
5158 // events during the current CMS cycle, take appropriate | |
5159 // remedial measures, where possible, so as to try and avoid | |
5160 // recurrence of that condition. | |
5161 assert(_markStack.isEmpty(), "No grey objects"); | |
5162 size_t ser_ovflw = _ser_pmc_remark_ovflw + _ser_pmc_preclean_ovflw + | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5163 _ser_kac_ovflw + _ser_kac_preclean_ovflw; |
0 | 5164 if (ser_ovflw > 0) { |
5165 if (PrintCMSStatistics != 0) { | |
5166 gclog_or_tty->print_cr("Marking stack overflow (benign) " | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5167 "(pmc_pc="SIZE_FORMAT", pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5168 ", kac_preclean="SIZE_FORMAT")", |
0 | 5169 _ser_pmc_preclean_ovflw, _ser_pmc_remark_ovflw, |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5170 _ser_kac_ovflw, _ser_kac_preclean_ovflw); |
0 | 5171 } |
5172 _markStack.expand(); | |
5173 _ser_pmc_remark_ovflw = 0; | |
5174 _ser_pmc_preclean_ovflw = 0; | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5175 _ser_kac_preclean_ovflw = 0; |
0 | 5176 _ser_kac_ovflw = 0; |
5177 } | |
5178 if (_par_pmc_remark_ovflw > 0 || _par_kac_ovflw > 0) { | |
5179 if (PrintCMSStatistics != 0) { | |
5180 gclog_or_tty->print_cr("Work queue overflow (benign) " | |
5181 "(pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT")", | |
5182 _par_pmc_remark_ovflw, _par_kac_ovflw); | |
5183 } | |
5184 _par_pmc_remark_ovflw = 0; | |
5185 _par_kac_ovflw = 0; | |
5186 } | |
5187 if (PrintCMSStatistics != 0) { | |
5188 if (_markStack._hit_limit > 0) { | |
5189 gclog_or_tty->print_cr(" (benign) Hit max stack size limit ("SIZE_FORMAT")", | |
5190 _markStack._hit_limit); | |
5191 } | |
5192 if (_markStack._failed_double > 0) { | |
5193 gclog_or_tty->print_cr(" (benign) Failed stack doubling ("SIZE_FORMAT")," | |
5194 " current capacity "SIZE_FORMAT, | |
5195 _markStack._failed_double, | |
5196 _markStack.capacity()); | |
5197 } | |
5198 } | |
5199 _markStack._hit_limit = 0; | |
5200 _markStack._failed_double = 0; | |
5201 | |
5202 if ((VerifyAfterGC || VerifyDuringGC) && | |
5203 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
5204 verify_after_remark(); | |
5205 } | |
5206 | |
10405 | 5207 _gc_tracer_cm->report_object_count_after_gc(&_is_alive_closure); |
5208 | |
0 | 5209 // Change under the freelistLocks. |
5210 _collectorState = Sweeping; | |
5211 // Call isAllClear() under bitMapLock | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5212 assert(_modUnionTable.isAllClear(), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5213 "Should be clear by end of the final marking"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5214 assert(_ct->klass_rem_set()->mod_union_is_clear(), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5215 "Should be clear by end of the final marking"); |
0 | 5216 if (UseAdaptiveSizePolicy) { |
5217 size_policy()->checkpoint_roots_final_end(gch->gc_cause()); | |
5218 } | |
5219 } | |
5220 | |
11975 | 5221 void CMSParInitialMarkTask::work(uint worker_id) { |
5222 elapsedTimer _timer; | |
5223 ResourceMark rm; | |
5224 HandleMark hm; | |
5225 | |
5226 // ---------- scan from roots -------------- | |
5227 _timer.start(); | |
5228 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5229 Par_MarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap)); | |
5230 | |
5231 // ---------- young gen roots -------------- | |
5232 { | |
5233 work_on_young_gen_roots(worker_id, &par_mri_cl); | |
5234 _timer.stop(); | |
5235 if (PrintCMSStatistics != 0) { | |
5236 gclog_or_tty->print_cr( | |
5237 "Finished young gen initial mark scan work in %dth thread: %3.3f sec", | |
5238 worker_id, _timer.seconds()); | |
5239 } | |
5240 } | |
5241 | |
5242 // ---------- remaining roots -------------- | |
5243 _timer.reset(); | |
5244 _timer.start(); | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5245 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5246 CLDToOopClosure cld_closure(&par_mri_cl, true); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5247 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5248 gch->gen_process_roots(_collector->_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5249 false, // yg was scanned above |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5250 false, // this is parallel code |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5251 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5252 _collector->should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5253 &par_mri_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5254 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5255 &cld_closure); |
11975 | 5256 assert(_collector->should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
5257 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
11975 | 5258 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5259 _timer.stop(); | |
5260 if (PrintCMSStatistics != 0) { | |
5261 gclog_or_tty->print_cr( | |
5262 "Finished remaining root initial mark scan work in %dth thread: %3.3f sec", | |
5263 worker_id, _timer.seconds()); | |
5264 } | |
5265 } | |
5266 | |
0 | 5267 // Parallel remark task |
11975 | 5268 class CMSParRemarkTask: public CMSParMarkTask { |
0 | 5269 CompactibleFreeListSpace* _cms_space; |
5270 | |
5271 // The per-thread work queues, available here for stealing. | |
5272 OopTaskQueueSet* _task_queues; | |
5273 ParallelTaskTerminator _term; | |
5274 | |
5275 public: | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5276 // A value of 0 passed to n_workers will cause the number of |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5277 // workers to be taken from the active workers in the work gang. |
0 | 5278 CMSParRemarkTask(CMSCollector* collector, |
5279 CompactibleFreeListSpace* cms_space, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5280 int n_workers, FlexibleWorkGang* workers, |
0 | 5281 OopTaskQueueSet* task_queues): |
11975 | 5282 CMSParMarkTask("Rescan roots and grey objects in parallel", |
5283 collector, n_workers), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5284 _cms_space(cms_space), |
0 | 5285 _task_queues(task_queues), |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5286 _term(n_workers, task_queues) { } |
0 | 5287 |
5288 OopTaskQueueSet* task_queues() { return _task_queues; } | |
5289 | |
5290 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
5291 | |
5292 ParallelTaskTerminator* terminator() { return &_term; } | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5293 int n_workers() { return _n_workers; } |
0 | 5294 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5295 void work(uint worker_id); |
0 | 5296 |
5297 private: | |
5298 // ... of dirty cards in old space | |
5299 void do_dirty_card_rescan_tasks(CompactibleFreeListSpace* sp, int i, | |
5300 Par_MarkRefsIntoAndScanClosure* cl); | |
5301 | |
5302 // ... work stealing for the above | |
5303 void do_work_steal(int i, Par_MarkRefsIntoAndScanClosure* cl, int* seed); | |
5304 }; | |
5305 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5306 class RemarkKlassClosure : public KlassClosure { |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
5307 KlassToOopClosure _cm_klass_closure; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5308 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5309 RemarkKlassClosure(OopClosure* oop_closure) : _cm_klass_closure(oop_closure) {} |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5310 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5311 // Check if we have modified any oops in the Klass during the concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5312 if (k->has_accumulated_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5313 k->clear_accumulated_modified_oops(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5314 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5315 // We could have transfered the current modified marks to the accumulated marks, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5316 // like we do with the Card Table to Mod Union Table. But it's not really necessary. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5317 } else if (k->has_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5318 // Don't clear anything, this info is needed by the next young collection. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5319 } else { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5320 // No modified oops in the Klass. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5321 return; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5322 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5323 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5324 // The klass has modified fields, need to scan the klass. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5325 _cm_klass_closure.do_klass(k); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5326 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5327 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5328 |
11975 | 5329 void CMSParMarkTask::work_on_young_gen_roots(uint worker_id, OopsInGenClosure* cl) { |
5330 DefNewGeneration* dng = _collector->_young_gen->as_DefNewGeneration(); | |
5331 EdenSpace* eden_space = dng->eden(); | |
5332 ContiguousSpace* from_space = dng->from(); | |
5333 ContiguousSpace* to_space = dng->to(); | |
5334 | |
5335 HeapWord** eca = _collector->_eden_chunk_array; | |
5336 size_t ect = _collector->_eden_chunk_index; | |
5337 HeapWord** sca = _collector->_survivor_chunk_array; | |
5338 size_t sct = _collector->_survivor_chunk_index; | |
5339 | |
5340 assert(ect <= _collector->_eden_chunk_capacity, "out of bounds"); | |
5341 assert(sct <= _collector->_survivor_chunk_capacity, "out of bounds"); | |
5342 | |
5343 do_young_space_rescan(worker_id, cl, to_space, NULL, 0); | |
5344 do_young_space_rescan(worker_id, cl, from_space, sca, sct); | |
5345 do_young_space_rescan(worker_id, cl, eden_space, eca, ect); | |
5346 } | |
5347 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5348 // work_queue(i) is passed to the closure |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5349 // Par_MarkRefsIntoAndScanClosure. The "i" parameter |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5350 // also is passed to do_dirty_card_rescan_tasks() and to |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5351 // do_work_steal() to select the i-th task_queue. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5352 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5353 void CMSParRemarkTask::work(uint worker_id) { |
0 | 5354 elapsedTimer _timer; |
5355 ResourceMark rm; | |
5356 HandleMark hm; | |
5357 | |
5358 // ---------- rescan from roots -------------- | |
5359 _timer.start(); | |
5360 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5361 Par_MarkRefsIntoAndScanClosure par_mrias_cl(_collector, | |
5362 _collector->_span, _collector->ref_processor(), | |
5363 &(_collector->_markBitMap), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5364 work_queue(worker_id)); |
0 | 5365 |
5366 // Rescan young gen roots first since these are likely | |
5367 // coarsely partitioned and may, on that account, constitute | |
5368 // the critical path; thus, it's best to start off that | |
5369 // work first. | |
5370 // ---------- young gen roots -------------- | |
5371 { | |
11975 | 5372 work_on_young_gen_roots(worker_id, &par_mrias_cl); |
0 | 5373 _timer.stop(); |
5374 if (PrintCMSStatistics != 0) { | |
5375 gclog_or_tty->print_cr( | |
5376 "Finished young gen rescan work in %dth thread: %3.3f sec", | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5377 worker_id, _timer.seconds()); |
0 | 5378 } |
5379 } | |
5380 | |
5381 // ---------- remaining roots -------------- | |
5382 _timer.reset(); | |
5383 _timer.start(); | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5384 gch->gen_process_roots(_collector->_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5385 false, // yg was scanned above |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5386 false, // this is parallel code |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5387 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5388 _collector->should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5389 &par_mrias_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5390 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5391 NULL); // The dirty klasses will be handled below |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5392 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5393 assert(_collector->should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
5394 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5395 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
0 | 5396 _timer.stop(); |
5397 if (PrintCMSStatistics != 0) { | |
5398 gclog_or_tty->print_cr( | |
5399 "Finished remaining root rescan work in %dth thread: %3.3f sec", | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5400 worker_id, _timer.seconds()); |
0 | 5401 } |
5402 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5403 // ---------- unhandled CLD scanning ---------- |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5404 if (worker_id == 0) { // Single threaded at the moment. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5405 _timer.reset(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5406 _timer.start(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5407 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5408 // Scan all new class loader data objects and new dependencies that were |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5409 // introduced during concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5410 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5411 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5412 for (int i = 0; i < array->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5413 par_mrias_cl.do_class_loader_data(array->at(i)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5414 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5415 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5416 // We don't need to keep track of new CLDs anymore. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5417 ClassLoaderDataGraph::remember_new_clds(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5418 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5419 _timer.stop(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5420 if (PrintCMSStatistics != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5421 gclog_or_tty->print_cr( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5422 "Finished unhandled CLD scanning work in %dth thread: %3.3f sec", |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5423 worker_id, _timer.seconds()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5424 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5425 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5426 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5427 // ---------- dirty klass scanning ---------- |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5428 if (worker_id == 0) { // Single threaded at the moment. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5429 _timer.reset(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5430 _timer.start(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5431 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5432 // Scan all classes that was dirtied during the concurrent marking phase. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5433 RemarkKlassClosure remark_klass_closure(&par_mrias_cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5434 ClassLoaderDataGraph::classes_do(&remark_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5435 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5436 _timer.stop(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5437 if (PrintCMSStatistics != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5438 gclog_or_tty->print_cr( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5439 "Finished dirty klass scanning work in %dth thread: %3.3f sec", |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5440 worker_id, _timer.seconds()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5441 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5442 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5443 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5444 // We might have added oops to ClassLoaderData::_handles during the |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5445 // concurrent marking phase. These oops point to newly allocated objects |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5446 // that are guaranteed to be kept alive. Either by the direct allocation |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5447 // code, or when the young collector processes the roots. Hence, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5448 // we don't have to revisit the _handles block during the remark phase. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5449 |
0 | 5450 // ---------- rescan dirty cards ------------ |
5451 _timer.reset(); | |
5452 _timer.start(); | |
5453 | |
5454 // Do the rescan tasks for each of the two spaces | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5455 // (cms_space) in turn. |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5456 // "worker_id" is passed to select the task_queue for "worker_id" |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5457 do_dirty_card_rescan_tasks(_cms_space, worker_id, &par_mrias_cl); |
0 | 5458 _timer.stop(); |
5459 if (PrintCMSStatistics != 0) { | |
5460 gclog_or_tty->print_cr( | |
5461 "Finished dirty card rescan work in %dth thread: %3.3f sec", | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5462 worker_id, _timer.seconds()); |
0 | 5463 } |
5464 | |
5465 // ---------- steal work from other threads ... | |
5466 // ---------- ... and drain overflow list. | |
5467 _timer.reset(); | |
5468 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5469 do_work_steal(worker_id, &par_mrias_cl, _collector->hash_seed(worker_id)); |
0 | 5470 _timer.stop(); |
5471 if (PrintCMSStatistics != 0) { | |
5472 gclog_or_tty->print_cr( | |
5473 "Finished work stealing in %dth thread: %3.3f sec", | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5474 worker_id, _timer.seconds()); |
0 | 5475 } |
5476 } | |
5477 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5478 // Note that parameter "i" is not used. |
0 | 5479 void |
11975 | 5480 CMSParMarkTask::do_young_space_rescan(uint worker_id, |
5481 OopsInGenClosure* cl, ContiguousSpace* space, | |
0 | 5482 HeapWord** chunk_array, size_t chunk_top) { |
5483 // Until all tasks completed: | |
5484 // . claim an unclaimed task | |
5485 // . compute region boundaries corresponding to task claimed | |
5486 // using chunk_array | |
5487 // . par_oop_iterate(cl) over that region | |
5488 | |
5489 ResourceMark rm; | |
5490 HandleMark hm; | |
5491 | |
5492 SequentialSubTasksDone* pst = space->par_seq_tasks(); | |
5493 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5494 uint nth_task = 0; |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5495 uint n_tasks = pst->n_tasks(); |
0 | 5496 |
12088
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5497 if (n_tasks > 0) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5498 assert(pst->valid(), "Uninitialized use?"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5499 HeapWord *start, *end; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5500 while (!pst->is_task_claimed(/* reference */ nth_task)) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5501 // We claimed task # nth_task; compute its boundaries. |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5502 if (chunk_top == 0) { // no samples were taken |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5503 assert(nth_task == 0 && n_tasks == 1, "Can have only 1 EdenSpace task"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5504 start = space->bottom(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5505 end = space->top(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5506 } else if (nth_task == 0) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5507 start = space->bottom(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5508 end = chunk_array[nth_task]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5509 } else if (nth_task < (uint)chunk_top) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5510 assert(nth_task >= 1, "Control point invariant"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5511 start = chunk_array[nth_task - 1]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5512 end = chunk_array[nth_task]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5513 } else { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5514 assert(nth_task == (uint)chunk_top, "Control point invariant"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5515 start = chunk_array[chunk_top - 1]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5516 end = space->top(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5517 } |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5518 MemRegion mr(start, end); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5519 // Verify that mr is in space |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5520 assert(mr.is_empty() || space->used_region().contains(mr), |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5521 "Should be in space"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5522 // Verify that "start" is an object boundary |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5523 assert(mr.is_empty() || oop(mr.start())->is_oop(), |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5524 "Should be an oop"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5525 space->par_oop_iterate(mr, cl); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5526 } |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5527 pst->all_tasks_completed(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5528 } |
0 | 5529 } |
5530 | |
5531 void | |
5532 CMSParRemarkTask::do_dirty_card_rescan_tasks( | |
5533 CompactibleFreeListSpace* sp, int i, | |
5534 Par_MarkRefsIntoAndScanClosure* cl) { | |
5535 // Until all tasks completed: | |
5536 // . claim an unclaimed task | |
5537 // . compute region boundaries corresponding to task claimed | |
5538 // . transfer dirty bits ct->mut for that region | |
5539 // . apply rescanclosure to dirty mut bits for that region | |
5540 | |
5541 ResourceMark rm; | |
5542 HandleMark hm; | |
5543 | |
5544 OopTaskQueue* work_q = work_queue(i); | |
5545 ModUnionClosure modUnionClosure(&(_collector->_modUnionTable)); | |
5546 // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! | |
5547 // CAUTION: This closure has state that persists across calls to | |
5548 // the work method dirty_range_iterate_clear() in that it has | |
5549 // imbedded in it a (subtype of) UpwardsObjectClosure. The | |
5550 // use of that state in the imbedded UpwardsObjectClosure instance | |
5551 // assumes that the cards are always iterated (even if in parallel | |
5552 // by several threads) in monotonically increasing order per each | |
5553 // thread. This is true of the implementation below which picks | |
5554 // card ranges (chunks) in monotonically increasing order globally | |
5555 // and, a-fortiori, in monotonically increasing order per thread | |
5556 // (the latter order being a subsequence of the former). | |
5557 // If the work code below is ever reorganized into a more chaotic | |
5558 // work-partitioning form than the current "sequential tasks" | |
5559 // paradigm, the use of that persistent state will have to be | |
5560 // revisited and modified appropriately. See also related | |
5561 // bug 4756801 work on which should examine this code to make | |
5562 // sure that the changes there do not run counter to the | |
5563 // assumptions made here and necessary for correctness and | |
5564 // efficiency. Note also that this code might yield inefficient | |
5565 // behaviour in the case of very large objects that span one or | |
5566 // more work chunks. Such objects would potentially be scanned | |
5567 // several times redundantly. Work on 4756801 should try and | |
5568 // address that performance anomaly if at all possible. XXX | |
5569 MemRegion full_span = _collector->_span; | |
5570 CMSBitMap* bm = &(_collector->_markBitMap); // shared | |
5571 MarkFromDirtyCardsClosure | |
5572 greyRescanClosure(_collector, full_span, // entire span of interest | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5573 sp, bm, work_q, cl); |
0 | 5574 |
5575 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); | |
5576 assert(pst->valid(), "Uninitialized use?"); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5577 uint nth_task = 0; |
0 | 5578 const int alignment = CardTableModRefBS::card_size * BitsPerWord; |
5579 MemRegion span = sp->used_region(); | |
5580 HeapWord* start_addr = span.start(); | |
5581 HeapWord* end_addr = (HeapWord*)round_to((intptr_t)span.end(), | |
5582 alignment); | |
5583 const size_t chunk_size = sp->rescan_task_size(); // in HeapWord units | |
5584 assert((HeapWord*)round_to((intptr_t)start_addr, alignment) == | |
5585 start_addr, "Check alignment"); | |
5586 assert((size_t)round_to((intptr_t)chunk_size, alignment) == | |
5587 chunk_size, "Check alignment"); | |
5588 | |
5589 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
5590 // Having claimed the nth_task, compute corresponding mem-region, | |
5591 // which is a-fortiori aligned correctly (i.e. at a MUT bopundary). | |
5592 // The alignment restriction ensures that we do not need any | |
5593 // synchronization with other gang-workers while setting or | |
5594 // clearing bits in thus chunk of the MUT. | |
5595 MemRegion this_span = MemRegion(start_addr + nth_task*chunk_size, | |
5596 start_addr + (nth_task+1)*chunk_size); | |
5597 // The last chunk's end might be way beyond end of the | |
5598 // used region. In that case pull back appropriately. | |
5599 if (this_span.end() > end_addr) { | |
5600 this_span.set_end(end_addr); | |
5601 assert(!this_span.is_empty(), "Program logic (calculation of n_tasks)"); | |
5602 } | |
5603 // Iterate over the dirty cards covering this chunk, marking them | |
5604 // precleaned, and setting the corresponding bits in the mod union | |
5605 // table. Since we have been careful to partition at Card and MUT-word | |
5606 // boundaries no synchronization is needed between parallel threads. | |
5607 _collector->_ct->ct_bs()->dirty_card_iterate(this_span, | |
5608 &modUnionClosure); | |
5609 | |
5610 // Having transferred these marks into the modUnionTable, | |
5611 // rescan the marked objects on the dirty cards in the modUnionTable. | |
5612 // Even if this is at a synchronous collection, the initial marking | |
5613 // may have been done during an asynchronous collection so there | |
5614 // may be dirty bits in the mod-union table. | |
5615 _collector->_modUnionTable.dirty_range_iterate_clear( | |
5616 this_span, &greyRescanClosure); | |
5617 _collector->_modUnionTable.verifyNoOneBitsInRange( | |
5618 this_span.start(), | |
5619 this_span.end()); | |
5620 } | |
5621 pst->all_tasks_completed(); // declare that i am done | |
5622 } | |
5623 | |
5624 // . see if we can share work_queues with ParNew? XXX | |
5625 void | |
5626 CMSParRemarkTask::do_work_steal(int i, Par_MarkRefsIntoAndScanClosure* cl, | |
5627 int* seed) { | |
5628 OopTaskQueue* work_q = work_queue(i); | |
5629 NOT_PRODUCT(int num_steals = 0;) | |
5630 oop obj_to_scan; | |
5631 CMSBitMap* bm = &(_collector->_markBitMap); | |
5632 | |
5633 while (true) { | |
5634 // Completely finish any left over work from (an) earlier round(s) | |
5635 cl->trim_queue(0); | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
5636 size_t num_from_overflow_list = MIN2((size_t)(work_q->max_elems() - work_q->size())/4, |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
5637 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 5638 // Now check if there's any work in the overflow list |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5639 // Passing ParallelGCThreads as the third parameter, no_of_gc_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5640 // only affects the number of attempts made to get work from the |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5641 // overflow list and does not affect the number of workers. Just |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5642 // pass ParallelGCThreads so this behavior is unchanged. |
0 | 5643 if (_collector->par_take_from_overflow_list(num_from_overflow_list, |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5644 work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5645 ParallelGCThreads)) { |
0 | 5646 // found something in global overflow list; |
5647 // not yet ready to go stealing work from others. | |
5648 // We'd like to assert(work_q->size() != 0, ...) | |
5649 // because we just took work from the overflow list, | |
5650 // but of course we can't since all of that could have | |
5651 // been already stolen from us. | |
5652 // "He giveth and He taketh away." | |
5653 continue; | |
5654 } | |
5655 // Verify that we have no work before we resort to stealing | |
5656 assert(work_q->size() == 0, "Have work, shouldn't steal"); | |
5657 // Try to steal from other queues that have work | |
5658 if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
5659 NOT_PRODUCT(num_steals++;) | |
5660 assert(obj_to_scan->is_oop(), "Oops, not an oop!"); | |
5661 assert(bm->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?"); | |
5662 // Do scanning work | |
5663 obj_to_scan->oop_iterate(cl); | |
5664 // Loop around, finish this work, and try to steal some more | |
5665 } else if (terminator()->offer_termination()) { | |
5666 break; // nirvana from the infinite cycle | |
5667 } | |
5668 } | |
5669 NOT_PRODUCT( | |
5670 if (PrintCMSStatistics != 0) { | |
5671 gclog_or_tty->print("\n\t(%d: stole %d oops)", i, num_steals); | |
5672 } | |
5673 ) | |
5674 assert(work_q->size() == 0 && _collector->overflow_list_is_empty(), | |
5675 "Else our work is not yet done"); | |
5676 } | |
5677 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5678 // Record object boundaries in _eden_chunk_array by sampling the eden |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5679 // top in the slow-path eden object allocation code path and record |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5680 // the boundaries, if CMSEdenChunksRecordAlways is true. If |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5681 // CMSEdenChunksRecordAlways is false, we use the other asynchronous |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5682 // sampling in sample_eden() that activates during the part of the |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5683 // preclean phase. |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5684 void CMSCollector::sample_eden_chunk() { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5685 if (CMSEdenChunksRecordAlways && _eden_chunk_array != NULL) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5686 if (_eden_chunk_lock->try_lock()) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5687 // Record a sample. This is the critical section. The contents |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5688 // of the _eden_chunk_array have to be non-decreasing in the |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5689 // address order. |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5690 _eden_chunk_array[_eden_chunk_index] = *_top_addr; |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5691 assert(_eden_chunk_array[_eden_chunk_index] <= *_end_addr, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5692 "Unexpected state of Eden"); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5693 if (_eden_chunk_index == 0 || |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5694 ((_eden_chunk_array[_eden_chunk_index] > _eden_chunk_array[_eden_chunk_index-1]) && |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5695 (pointer_delta(_eden_chunk_array[_eden_chunk_index], |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5696 _eden_chunk_array[_eden_chunk_index-1]) >= CMSSamplingGrain))) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5697 _eden_chunk_index++; // commit sample |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5698 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5699 _eden_chunk_lock->unlock(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5700 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5701 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5702 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5703 |
0 | 5704 // Return a thread-local PLAB recording array, as appropriate. |
5705 void* CMSCollector::get_data_recorder(int thr_num) { | |
5706 if (_survivor_plab_array != NULL && | |
5707 (CMSPLABRecordAlways || | |
5708 (_collectorState > Marking && _collectorState < FinalMarking))) { | |
5709 assert(thr_num < (int)ParallelGCThreads, "thr_num is out of bounds"); | |
5710 ChunkArray* ca = &_survivor_plab_array[thr_num]; | |
5711 ca->reset(); // clear it so that fresh data is recorded | |
5712 return (void*) ca; | |
5713 } else { | |
5714 return NULL; | |
5715 } | |
5716 } | |
5717 | |
5718 // Reset all the thread-local PLAB recording arrays | |
5719 void CMSCollector::reset_survivor_plab_arrays() { | |
5720 for (uint i = 0; i < ParallelGCThreads; i++) { | |
5721 _survivor_plab_array[i].reset(); | |
5722 } | |
5723 } | |
5724 | |
5725 // Merge the per-thread plab arrays into the global survivor chunk | |
5726 // array which will provide the partitioning of the survivor space | |
11975 | 5727 // for CMS initial scan and rescan. |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5728 void CMSCollector::merge_survivor_plab_arrays(ContiguousSpace* surv, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5729 int no_of_gc_threads) { |
0 | 5730 assert(_survivor_plab_array != NULL, "Error"); |
5731 assert(_survivor_chunk_array != NULL, "Error"); | |
11975 | 5732 assert(_collectorState == FinalMarking || |
5733 (CMSParallelInitialMarkEnabled && _collectorState == InitialMarking), "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5734 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5735 _cursor[j] = 0; |
5736 } | |
5737 HeapWord* top = surv->top(); | |
5738 size_t i; | |
5739 for (i = 0; i < _survivor_chunk_capacity; i++) { // all sca entries | |
5740 HeapWord* min_val = top; // Higher than any PLAB address | |
5741 uint min_tid = 0; // position of min_val this round | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5742 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5743 ChunkArray* cur_sca = &_survivor_plab_array[j]; |
5744 if (_cursor[j] == cur_sca->end()) { | |
5745 continue; | |
5746 } | |
5747 assert(_cursor[j] < cur_sca->end(), "ctl pt invariant"); | |
5748 HeapWord* cur_val = cur_sca->nth(_cursor[j]); | |
5749 assert(surv->used_region().contains(cur_val), "Out of bounds value"); | |
5750 if (cur_val < min_val) { | |
5751 min_tid = j; | |
5752 min_val = cur_val; | |
5753 } else { | |
5754 assert(cur_val < top, "All recorded addresses should be less"); | |
5755 } | |
5756 } | |
5757 // At this point min_val and min_tid are respectively | |
5758 // the least address in _survivor_plab_array[j]->nth(_cursor[j]) | |
5759 // and the thread (j) that witnesses that address. | |
5760 // We record this address in the _survivor_chunk_array[i] | |
5761 // and increment _cursor[min_tid] prior to the next round i. | |
5762 if (min_val == top) { | |
5763 break; | |
5764 } | |
5765 _survivor_chunk_array[i] = min_val; | |
5766 _cursor[min_tid]++; | |
5767 } | |
5768 // We are all done; record the size of the _survivor_chunk_array | |
5769 _survivor_chunk_index = i; // exclusive: [0, i) | |
5770 if (PrintCMSStatistics > 0) { | |
5771 gclog_or_tty->print(" (Survivor:" SIZE_FORMAT "chunks) ", i); | |
5772 } | |
5773 // Verify that we used up all the recorded entries | |
5774 #ifdef ASSERT | |
5775 size_t total = 0; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5776 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5777 assert(_cursor[j] == _survivor_plab_array[j].end(), "Ctl pt invariant"); |
5778 total += _cursor[j]; | |
5779 } | |
5780 assert(total == _survivor_chunk_index, "Ctl Pt Invariant"); | |
5781 // Check that the merged array is in sorted order | |
5782 if (total > 0) { | |
5783 for (size_t i = 0; i < total - 1; i++) { | |
5784 if (PrintCMSStatistics > 0) { | |
5785 gclog_or_tty->print(" (chunk" SIZE_FORMAT ":" INTPTR_FORMAT ") ", | |
5786 i, _survivor_chunk_array[i]); | |
5787 } | |
5788 assert(_survivor_chunk_array[i] < _survivor_chunk_array[i+1], | |
5789 "Not sorted"); | |
5790 } | |
5791 } | |
5792 #endif // ASSERT | |
5793 } | |
5794 | |
5795 // Set up the space's par_seq_tasks structure for work claiming | |
11975 | 5796 // for parallel initial scan and rescan of young gen. |
0 | 5797 // See ParRescanTask where this is currently used. |
5798 void | |
5799 CMSCollector:: | |
5800 initialize_sequential_subtasks_for_young_gen_rescan(int n_threads) { | |
5801 assert(n_threads > 0, "Unexpected n_threads argument"); | |
5802 DefNewGeneration* dng = (DefNewGeneration*)_young_gen; | |
5803 | |
5804 // Eden space | |
12088
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5805 if (!dng->eden()->is_empty()) { |
0 | 5806 SequentialSubTasksDone* pst = dng->eden()->par_seq_tasks(); |
5807 assert(!pst->valid(), "Clobbering existing data?"); | |
5808 // Each valid entry in [0, _eden_chunk_index) represents a task. | |
5809 size_t n_tasks = _eden_chunk_index + 1; | |
5810 assert(n_tasks == 1 || _eden_chunk_array != NULL, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5811 // Sets the condition for completion of the subtask (how many threads |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5812 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5813 pst->set_n_threads(n_threads); |
0 | 5814 pst->set_n_tasks((int)n_tasks); |
5815 } | |
5816 | |
5817 // Merge the survivor plab arrays into _survivor_chunk_array | |
5818 if (_survivor_plab_array != NULL) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5819 merge_survivor_plab_arrays(dng->from(), n_threads); |
0 | 5820 } else { |
5821 assert(_survivor_chunk_index == 0, "Error"); | |
5822 } | |
5823 | |
5824 // To space | |
5825 { | |
5826 SequentialSubTasksDone* pst = dng->to()->par_seq_tasks(); | |
5827 assert(!pst->valid(), "Clobbering existing data?"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5828 // Sets the condition for completion of the subtask (how many threads |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5829 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5830 pst->set_n_threads(n_threads); |
0 | 5831 pst->set_n_tasks(1); |
5832 assert(pst->valid(), "Error"); | |
5833 } | |
5834 | |
5835 // From space | |
5836 { | |
5837 SequentialSubTasksDone* pst = dng->from()->par_seq_tasks(); | |
5838 assert(!pst->valid(), "Clobbering existing data?"); | |
5839 size_t n_tasks = _survivor_chunk_index + 1; | |
5840 assert(n_tasks == 1 || _survivor_chunk_array != NULL, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5841 // Sets the condition for completion of the subtask (how many threads |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5842 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5843 pst->set_n_threads(n_threads); |
0 | 5844 pst->set_n_tasks((int)n_tasks); |
5845 assert(pst->valid(), "Error"); | |
5846 } | |
5847 } | |
5848 | |
5849 // Parallel version of remark | |
5850 void CMSCollector::do_remark_parallel() { | |
5851 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5852 FlexibleWorkGang* workers = gch->workers(); |
0 | 5853 assert(workers != NULL, "Need parallel worker threads."); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5854 // Choose to use the number of GC workers most recently set |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5855 // into "active_workers". If active_workers is not set, set it |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5856 // to ParallelGCThreads. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5857 int n_workers = workers->active_workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5858 if (n_workers == 0) { |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5859 assert(n_workers > 0, "Should have been set during scavenge"); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5860 n_workers = ParallelGCThreads; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5861 workers->set_active_workers(n_workers); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5862 } |
0 | 5863 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); |
5864 | |
5865 CMSParRemarkTask tsk(this, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5866 cms_space, |
0 | 5867 n_workers, workers, task_queues()); |
5868 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5869 // Set up for parallel process_roots work. |
0 | 5870 gch->set_par_threads(n_workers); |
5871 // We won't be iterating over the cards in the card table updating | |
5872 // the younger_gen cards, so we shouldn't call the following else | |
5873 // the verification code as well as subsequent younger_refs_iterate | |
5874 // code would get confused. XXX | |
5875 // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel | |
5876 | |
5877 // The young gen rescan work will not be done as part of | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5878 // process_roots (which currently doesn't know how to |
0 | 5879 // parallelize such a scan), but rather will be broken up into |
5880 // a set of parallel tasks (via the sampling that the [abortable] | |
5881 // preclean phase did of EdenSpace, plus the [two] tasks of | |
5882 // scanning the [two] survivor spaces. Further fine-grain | |
5883 // parallelization of the scanning of the survivor spaces | |
5884 // themselves, and of precleaning of the younger gen itself | |
5885 // is deferred to the future. | |
5886 initialize_sequential_subtasks_for_young_gen_rescan(n_workers); | |
5887 | |
5888 // The dirty card rescan work is broken up into a "sequence" | |
5889 // of parallel tasks (per constituent space) that are dynamically | |
5890 // claimed by the parallel threads. | |
5891 cms_space->initialize_sequential_subtasks_for_rescan(n_workers); | |
5892 | |
5893 // It turns out that even when we're using 1 thread, doing the work in a | |
5894 // separate thread causes wide variance in run times. We can't help this | |
5895 // in the multi-threaded case, but we special-case n=1 here to get | |
5896 // repeatable measurements of the 1-thread overhead of the parallel code. | |
5897 if (n_workers > 1) { | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5898 // Make refs discovery MT-safe, if it isn't already: it may not |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5899 // necessarily be so, since it's possible that we are doing |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5900 // ST marking. |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5901 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), true); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5902 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5903 workers->run_task(&tsk); |
5904 } else { | |
4876
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5905 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5906 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5907 tsk.work(0); |
5908 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5909 |
0 | 5910 gch->set_par_threads(0); // 0 ==> non-parallel. |
5911 // restore, single-threaded for now, any preserved marks | |
5912 // as a result of work_q overflow | |
5913 restore_preserved_marks_if_any(); | |
5914 } | |
5915 | |
5916 // Non-parallel version of remark | |
5917 void CMSCollector::do_remark_non_parallel() { | |
5918 ResourceMark rm; | |
5919 HandleMark hm; | |
5920 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
4876
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5921 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); |
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5922 |
0 | 5923 MarkRefsIntoAndScanClosure |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5924 mrias_cl(_span, ref_processor(), &_markBitMap, NULL /* not precleaning */, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5925 &_markStack, this, |
0 | 5926 false /* should_yield */, false /* not precleaning */); |
5927 MarkFromDirtyCardsClosure | |
5928 markFromDirtyCardsClosure(this, _span, | |
5929 NULL, // space is set further below | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5930 &_markBitMap, &_markStack, &mrias_cl); |
0 | 5931 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5932 GCTraceTime t("grey object rescan", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
5933 // Iterate over the dirty cards, setting the corresponding bits in the |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
5934 // mod union table. |
0 | 5935 { |
5936 ModUnionClosure modUnionClosure(&_modUnionTable); | |
5937 _ct->ct_bs()->dirty_card_iterate( | |
5938 _cmsGen->used_region(), | |
5939 &modUnionClosure); | |
5940 } | |
5941 // Having transferred these marks into the modUnionTable, we just need | |
5942 // to rescan the marked objects on the dirty cards in the modUnionTable. | |
5943 // The initial marking may have been done during an asynchronous | |
5944 // collection so there may be dirty bits in the mod-union table. | |
5945 const int alignment = | |
5946 CardTableModRefBS::card_size * BitsPerWord; | |
5947 { | |
5948 // ... First handle dirty cards in CMS gen | |
5949 markFromDirtyCardsClosure.set_space(_cmsGen->cmsSpace()); | |
5950 MemRegion ur = _cmsGen->used_region(); | |
5951 HeapWord* lb = ur.start(); | |
5952 HeapWord* ub = (HeapWord*)round_to((intptr_t)ur.end(), alignment); | |
5953 MemRegion cms_span(lb, ub); | |
5954 _modUnionTable.dirty_range_iterate_clear(cms_span, | |
5955 &markFromDirtyCardsClosure); | |
5956 verify_work_stacks_empty(); | |
5957 if (PrintCMSStatistics != 0) { | |
5958 gclog_or_tty->print(" (re-scanned "SIZE_FORMAT" dirty cards in cms gen) ", | |
5959 markFromDirtyCardsClosure.num_dirty_cards()); | |
5960 } | |
5961 } | |
5962 } | |
5963 if (VerifyDuringGC && | |
5964 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
5965 HandleMark hm; // Discard invalid handles created during verification | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
5966 Universe::verify(); |
0 | 5967 } |
5968 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5969 GCTraceTime t("root rescan", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5970 |
5971 verify_work_stacks_empty(); | |
5972 | |
5973 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5974 GenCollectedHeap::StrongRootsScope srs(gch); |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5975 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5976 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5977 true, // younger gens as roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5978 false, // use the local StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5979 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5980 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5981 &mrias_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5982 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5983 NULL); // The dirty klasses will be handled below |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5984 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5985 assert(should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
5986 || (roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5987 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
0 | 5988 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5989 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5990 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5991 GCTraceTime t("visit unhandled CLDs", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5992 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5993 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5994 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5995 // Scan all class loader data objects that might have been introduced |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5996 // during concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5997 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5998 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5999 for (int i = 0; i < array->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6000 mrias_cl.do_class_loader_data(array->at(i)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6001 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6002 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6003 // We don't need to keep track of new CLDs anymore. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6004 ClassLoaderDataGraph::remember_new_clds(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6005 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6006 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6007 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6008 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6009 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6010 GCTraceTime t("dirty klass scan", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6011 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6012 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6013 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6014 RemarkKlassClosure remark_klass_closure(&mrias_cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6015 ClassLoaderDataGraph::classes_do(&remark_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6016 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6017 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6018 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6019 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6020 // We might have added oops to ClassLoaderData::_handles during the |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6021 // concurrent marking phase. These oops point to newly allocated objects |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6022 // that are guaranteed to be kept alive. Either by the direct allocation |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6023 // code, or when the young collector processes the roots. Hence, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6024 // we don't have to revisit the _handles block during the remark phase. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6025 |
0 | 6026 verify_work_stacks_empty(); |
6027 // Restore evacuated mark words, if any, used for overflow list links | |
6028 if (!CMSOverflowEarlyRestoration) { | |
6029 restore_preserved_marks_if_any(); | |
6030 } | |
6031 verify_overflow_empty(); | |
6032 } | |
6033 | |
6034 //////////////////////////////////////////////////////// | |
6035 // Parallel Reference Processing Task Proxy Class | |
6036 //////////////////////////////////////////////////////// | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6037 class CMSRefProcTaskProxy: public AbstractGangTaskWOopQueues { |
0 | 6038 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; |
6039 CMSCollector* _collector; | |
6040 CMSBitMap* _mark_bit_map; | |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6041 const MemRegion _span; |
0 | 6042 ProcessTask& _task; |
6043 | |
6044 public: | |
6045 CMSRefProcTaskProxy(ProcessTask& task, | |
6046 CMSCollector* collector, | |
6047 const MemRegion& span, | |
6048 CMSBitMap* mark_bit_map, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6049 AbstractWorkGang* workers, |
0 | 6050 OopTaskQueueSet* task_queues): |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6051 // XXX Should superclass AGTWOQ also know about AWG since it knows |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6052 // about the task_queues used by the AWG? Then it could initialize |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6053 // the terminator() object. See 6984287. The set_for_termination() |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6054 // below is a temporary band-aid for the regression in 6984287. |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6055 AbstractGangTaskWOopQueues("Process referents by policy in parallel", |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6056 task_queues), |
0 | 6057 _task(task), |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6058 _collector(collector), _span(span), _mark_bit_map(mark_bit_map) |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6059 { |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6060 assert(_collector->_span.equals(_span) && !_span.is_empty(), |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6061 "Inconsistency in _span"); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6062 set_for_termination(workers->active_workers()); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6063 } |
0 | 6064 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6065 OopTaskQueueSet* task_queues() { return queues(); } |
0 | 6066 |
6067 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
6068 | |
6069 void do_work_steal(int i, | |
6070 CMSParDrainMarkingStackClosure* drain, | |
6071 CMSParKeepAliveClosure* keep_alive, | |
6072 int* seed); | |
6073 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6074 virtual void work(uint worker_id); |
0 | 6075 }; |
6076 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6077 void CMSRefProcTaskProxy::work(uint worker_id) { |
20297
ca8b8e21e2ca
8050973: CMS/G1 GC: add missing Resource and Handle mark
mdoerr
parents:
20278
diff
changeset
|
6078 ResourceMark rm; |
ca8b8e21e2ca
8050973: CMS/G1 GC: add missing Resource and Handle mark
mdoerr
parents:
20278
diff
changeset
|
6079 HandleMark hm; |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6080 assert(_collector->_span.equals(_span), "Inconsistency in _span"); |
0 | 6081 CMSParKeepAliveClosure par_keep_alive(_collector, _span, |
935 | 6082 _mark_bit_map, |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6083 work_queue(worker_id)); |
0 | 6084 CMSParDrainMarkingStackClosure par_drain_stack(_collector, _span, |
935 | 6085 _mark_bit_map, |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6086 work_queue(worker_id)); |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6087 CMSIsAliveClosure is_alive_closure(_span, _mark_bit_map); |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6088 _task.work(worker_id, is_alive_closure, par_keep_alive, par_drain_stack); |
0 | 6089 if (_task.marks_oops_alive()) { |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6090 do_work_steal(worker_id, &par_drain_stack, &par_keep_alive, |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6091 _collector->hash_seed(worker_id)); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6092 } |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6093 assert(work_queue(worker_id)->size() == 0, "work_queue should be empty"); |
0 | 6094 assert(_collector->_overflow_list == NULL, "non-empty _overflow_list"); |
6095 } | |
6096 | |
6097 class CMSRefEnqueueTaskProxy: public AbstractGangTask { | |
6098 typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask; | |
6099 EnqueueTask& _task; | |
6100 | |
6101 public: | |
6102 CMSRefEnqueueTaskProxy(EnqueueTask& task) | |
6103 : AbstractGangTask("Enqueue reference objects in parallel"), | |
6104 _task(task) | |
6105 { } | |
6106 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6107 virtual void work(uint worker_id) |
0 | 6108 { |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6109 _task.work(worker_id); |
0 | 6110 } |
6111 }; | |
6112 | |
6113 CMSParKeepAliveClosure::CMSParKeepAliveClosure(CMSCollector* collector, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6114 MemRegion span, CMSBitMap* bit_map, OopTaskQueue* work_queue): |
0 | 6115 _span(span), |
6116 _bit_map(bit_map), | |
6117 _work_queue(work_queue), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6118 _mark_and_push(collector, span, bit_map, work_queue), |
0 | 6119 _low_water_mark(MIN2((uint)(work_queue->max_elems()/4), |
6120 (uint)(CMSWorkQueueDrainThreshold * ParallelGCThreads))) | |
6121 { } | |
6122 | |
6123 // . see if we can share work_queues with ParNew? XXX | |
6124 void CMSRefProcTaskProxy::do_work_steal(int i, | |
6125 CMSParDrainMarkingStackClosure* drain, | |
6126 CMSParKeepAliveClosure* keep_alive, | |
6127 int* seed) { | |
6128 OopTaskQueue* work_q = work_queue(i); | |
6129 NOT_PRODUCT(int num_steals = 0;) | |
6130 oop obj_to_scan; | |
6131 | |
6132 while (true) { | |
6133 // Completely finish any left over work from (an) earlier round(s) | |
6134 drain->trim_queue(0); | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
6135 size_t num_from_overflow_list = MIN2((size_t)(work_q->max_elems() - work_q->size())/4, |
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
6136 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 6137 // Now check if there's any work in the overflow list |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6138 // Passing ParallelGCThreads as the third parameter, no_of_gc_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6139 // only affects the number of attempts made to get work from the |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6140 // overflow list and does not affect the number of workers. Just |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6141 // pass ParallelGCThreads so this behavior is unchanged. |
0 | 6142 if (_collector->par_take_from_overflow_list(num_from_overflow_list, |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6143 work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6144 ParallelGCThreads)) { |
0 | 6145 // Found something in global overflow list; |
6146 // not yet ready to go stealing work from others. | |
6147 // We'd like to assert(work_q->size() != 0, ...) | |
6148 // because we just took work from the overflow list, | |
6149 // but of course we can't, since all of that might have | |
6150 // been already stolen from us. | |
6151 continue; | |
6152 } | |
6153 // Verify that we have no work before we resort to stealing | |
6154 assert(work_q->size() == 0, "Have work, shouldn't steal"); | |
6155 // Try to steal from other queues that have work | |
6156 if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
6157 NOT_PRODUCT(num_steals++;) | |
6158 assert(obj_to_scan->is_oop(), "Oops, not an oop!"); | |
6159 assert(_mark_bit_map->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?"); | |
6160 // Do scanning work | |
6161 obj_to_scan->oop_iterate(keep_alive); | |
6162 // Loop around, finish this work, and try to steal some more | |
6163 } else if (terminator()->offer_termination()) { | |
6164 break; // nirvana from the infinite cycle | |
6165 } | |
6166 } | |
6167 NOT_PRODUCT( | |
6168 if (PrintCMSStatistics != 0) { | |
6169 gclog_or_tty->print("\n\t(%d: stole %d oops)", i, num_steals); | |
6170 } | |
6171 ) | |
6172 } | |
6173 | |
6174 void CMSRefProcTaskExecutor::execute(ProcessTask& task) | |
6175 { | |
6176 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6177 FlexibleWorkGang* workers = gch->workers(); |
0 | 6178 assert(workers != NULL, "Need parallel worker threads."); |
6179 CMSRefProcTaskProxy rp_task(task, &_collector, | |
6180 _collector.ref_processor()->span(), | |
6181 _collector.markBitMap(), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6182 workers, _collector.task_queues()); |
0 | 6183 workers->run_task(&rp_task); |
6184 } | |
6185 | |
6186 void CMSRefProcTaskExecutor::execute(EnqueueTask& task) | |
6187 { | |
6188 | |
6189 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6190 FlexibleWorkGang* workers = gch->workers(); |
0 | 6191 assert(workers != NULL, "Need parallel worker threads."); |
6192 CMSRefEnqueueTaskProxy enq_task(task); | |
6193 workers->run_task(&enq_task); | |
6194 } | |
6195 | |
6196 void CMSCollector::refProcessingWork(bool asynch, bool clear_all_soft_refs) { | |
6197 | |
6198 ResourceMark rm; | |
6199 HandleMark hm; | |
6200 | |
6201 ReferenceProcessor* rp = ref_processor(); | |
6202 assert(rp->span().equals(_span), "Spans should be equal"); | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6203 assert(!rp->enqueuing_is_done(), "Enqueuing should not be complete"); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6204 // Process weak references. |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
6205 rp->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6206 verify_work_stacks_empty(); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6207 |
0 | 6208 CMSKeepAliveClosure cmsKeepAliveClosure(this, _span, &_markBitMap, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6209 &_markStack, false /* !preclean */); |
0 | 6210 CMSDrainMarkingStackClosure cmsDrainMarkingStackClosure(this, |
6211 _span, &_markBitMap, &_markStack, | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
6212 &cmsKeepAliveClosure, false /* !preclean */); |
0 | 6213 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6214 GCTraceTime t("weak refs processing", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
10405 | 6215 |
6216 ReferenceProcessorStats stats; | |
0 | 6217 if (rp->processing_is_mt()) { |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6218 // Set the degree of MT here. If the discovery is done MT, there |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6219 // may have been a different number of threads doing the discovery |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6220 // and a different number of discovered lists may have Ref objects. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6221 // That is OK as long as the Reference lists are balanced (see |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6222 // balance_all_queues() and balance_queues()). |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6223 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6224 int active_workers = ParallelGCThreads; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6225 FlexibleWorkGang* workers = gch->workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6226 if (workers != NULL) { |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6227 active_workers = workers->active_workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6228 // The expectation is that active_workers will have already |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6229 // been set to a reasonable value. If it has not been set, |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6230 // investigate. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6231 assert(active_workers > 0, "Should have been set during scavenge"); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6232 } |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6233 rp->set_active_mt_degree(active_workers); |
0 | 6234 CMSRefProcTaskExecutor task_executor(*this); |
10405 | 6235 stats = rp->process_discovered_references(&_is_alive_closure, |
0 | 6236 &cmsKeepAliveClosure, |
6237 &cmsDrainMarkingStackClosure, | |
10405 | 6238 &task_executor, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6239 _gc_timer_cm, |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6240 _gc_tracer_cm->gc_id()); |
0 | 6241 } else { |
10405 | 6242 stats = rp->process_discovered_references(&_is_alive_closure, |
0 | 6243 &cmsKeepAliveClosure, |
6244 &cmsDrainMarkingStackClosure, | |
10405 | 6245 NULL, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6246 _gc_timer_cm, |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6247 _gc_tracer_cm->gc_id()); |
10405 | 6248 } |
6249 _gc_tracer_cm->report_gc_reference_stats(stats); | |
6250 | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6251 } |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6252 |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6253 // This is the point where the entire marking should have completed. |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6254 verify_work_stacks_empty(); |
0 | 6255 |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6256 if (should_unload_classes()) { |
0 | 6257 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6258 GCTraceTime t("class unloading", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 6259 |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6260 // Unload classes and purge the SystemDictionary. |
0 | 6261 bool purged_class = SystemDictionary::do_unloading(&_is_alive_closure); |
6262 | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6263 // Unload nmethods. |
6787
8966c2d65d96
7200470: KeepAliveClosure not needed in CodeCache::do_unloading
brutisso
parents:
6755
diff
changeset
|
6264 CodeCache::do_unloading(&_is_alive_closure, purged_class); |
0 | 6265 |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6266 // Prune dead klasses from subklass/sibling/implementor lists. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6267 Klass::clean_weak_klass_links(&_is_alive_closure); |
0 | 6268 } |
6269 | |
6270 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6271 GCTraceTime t("scrub symbol table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2147
diff
changeset
|
6272 // Clean up unreferenced symbols in symbol table. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2147
diff
changeset
|
6273 SymbolTable::unlink(); |
0 | 6274 } |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6275 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6276 { |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6277 GCTraceTime t("scrub string table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6278 // Delete entries for dead interned strings. |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6279 StringTable::unlink(&_is_alive_closure); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6280 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6281 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6282 |
2379
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2369
diff
changeset
|
6283 |
0 | 6284 // Restore any preserved marks as a result of mark stack or |
6285 // work queue overflow | |
6286 restore_preserved_marks_if_any(); // done single-threaded for now | |
6287 | |
6288 rp->set_enqueuing_is_done(true); | |
6289 if (rp->processing_is_mt()) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6290 rp->balance_all_queues(); |
0 | 6291 CMSRefProcTaskExecutor task_executor(*this); |
6292 rp->enqueue_discovered_references(&task_executor); | |
6293 } else { | |
6294 rp->enqueue_discovered_references(NULL); | |
6295 } | |
6296 rp->verify_no_references_recorded(); | |
6297 assert(!rp->discovery_enabled(), "should have been disabled"); | |
6298 } | |
6299 | |
6300 #ifndef PRODUCT | |
6301 void CMSCollector::check_correct_thread_executing() { | |
6302 Thread* t = Thread::current(); | |
6303 // Only the VM thread or the CMS thread should be here. | |
6304 assert(t->is_ConcurrentGC_thread() || t->is_VM_thread(), | |
6305 "Unexpected thread type"); | |
6306 // If this is the vm thread, the foreground process | |
6307 // should not be waiting. Note that _foregroundGCIsActive is | |
6308 // true while the foreground collector is waiting. | |
6309 if (_foregroundGCShouldWait) { | |
6310 // We cannot be the VM thread | |
6311 assert(t->is_ConcurrentGC_thread(), | |
6312 "Should be CMS thread"); | |
6313 } else { | |
6314 // We can be the CMS thread only if we are in a stop-world | |
6315 // phase of CMS collection. | |
6316 if (t->is_ConcurrentGC_thread()) { | |
6317 assert(_collectorState == InitialMarking || | |
6318 _collectorState == FinalMarking, | |
6319 "Should be a stop-world phase"); | |
6320 // The CMS thread should be holding the CMS_token. | |
6321 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6322 "Potential interference with concurrently " | |
6323 "executing VM thread"); | |
6324 } | |
6325 } | |
6326 } | |
6327 #endif | |
6328 | |
6329 void CMSCollector::sweep(bool asynch) { | |
6330 assert(_collectorState == Sweeping, "just checking"); | |
6331 check_correct_thread_executing(); | |
6332 verify_work_stacks_empty(); | |
6333 verify_overflow_empty(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6334 increment_sweep_count(); |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
6335 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
6336 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6337 _inter_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6338 _inter_sweep_estimate.sample(_inter_sweep_timer.seconds()); |
0 | 6339 size_policy()->avg_cms_free_at_sweep()->sample(_cmsGen->free()); |
6340 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6341 assert(!_intra_sweep_timer.is_active(), "Should not be active"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6342 _intra_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6343 _intra_sweep_timer.start(); |
0 | 6344 if (asynch) { |
6345 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6346 CMSPhaseAccounting pa(this, "sweep", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6347 // First sweep the old gen |
0 | 6348 { |
6349 CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock(), | |
6350 bitMapLock()); | |
6351 sweepWork(_cmsGen, asynch); | |
6352 } | |
6353 | |
6354 // Update Universe::_heap_*_at_gc figures. | |
6355 // We need all the free list locks to make the abstract state | |
6356 // transition from Sweeping to Resetting. See detailed note | |
6357 // further below. | |
6358 { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6359 CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock()); |
0 | 6360 // Update heap occupancy information which is used as |
6361 // input to soft ref clearing policy at the next gc. | |
6362 Universe::update_heap_info_at_gc(); | |
6363 _collectorState = Resizing; | |
6364 } | |
6365 } else { | |
6366 // already have needed locks | |
6367 sweepWork(_cmsGen, asynch); | |
6368 // Update heap occupancy information which is used as | |
6369 // input to soft ref clearing policy at the next gc. | |
6370 Universe::update_heap_info_at_gc(); | |
6371 _collectorState = Resizing; | |
6372 } | |
6373 verify_work_stacks_empty(); | |
6374 verify_overflow_empty(); | |
6375 | |
8784
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6376 if (should_unload_classes()) { |
17935
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17771
diff
changeset
|
6377 // Delay purge to the beginning of the next safepoint. Metaspace::contains |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17771
diff
changeset
|
6378 // requires that the virtual spaces are stable and not deleted. |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17771
diff
changeset
|
6379 ClassLoaderDataGraph::set_should_purge(true); |
8784
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6380 } |
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6381 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6382 _intra_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6383 _intra_sweep_estimate.sample(_intra_sweep_timer.seconds()); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6384 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6385 _inter_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6386 _inter_sweep_timer.start(); |
0 | 6387 |
4911 | 6388 // We need to use a monotonically non-deccreasing time in ms |
6389 // or we will see time-warp warnings and os::javaTimeMillis() | |
6390 // does not guarantee monotonicity. | |
6391 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; | |
6392 update_time_of_last_gc(now); | |
0 | 6393 |
6394 // NOTE on abstract state transitions: | |
6395 // Mutators allocate-live and/or mark the mod-union table dirty | |
6396 // based on the state of the collection. The former is done in | |
6397 // the interval [Marking, Sweeping] and the latter in the interval | |
6398 // [Marking, Sweeping). Thus the transitions into the Marking state | |
6399 // and out of the Sweeping state must be synchronously visible | |
6400 // globally to the mutators. | |
6401 // The transition into the Marking state happens with the world | |
6402 // stopped so the mutators will globally see it. Sweeping is | |
6403 // done asynchronously by the background collector so the transition | |
6404 // from the Sweeping state to the Resizing state must be done | |
6405 // under the freelistLock (as is the check for whether to | |
6406 // allocate-live and whether to dirty the mod-union table). | |
6407 assert(_collectorState == Resizing, "Change of collector state to" | |
6408 " Resizing must be done under the freelistLocks (plural)"); | |
6409 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6410 // Now that sweeping has been completed, we clear |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6411 // the incremental_collection_failed flag, |
0 | 6412 // thus inviting a younger gen collection to promote into |
6413 // this generation. If such a promotion may still fail, | |
6414 // the flag will be set again when a young collection is | |
6415 // attempted. | |
6416 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6417 gch->clear_incremental_collection_failed(); // Worth retrying as fresh space may have been freed up |
0 | 6418 gch->update_full_collections_completed(_collection_count_start); |
6419 } | |
6420 | |
6421 // FIX ME!!! Looks like this belongs in CFLSpace, with | |
6422 // CMSGen merely delegating to it. | |
6423 void ConcurrentMarkSweepGeneration::setNearLargestChunk() { | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6424 double nearLargestPercent = FLSLargestBlockCoalesceProximity; |
0 | 6425 HeapWord* minAddr = _cmsSpace->bottom(); |
6426 HeapWord* largestAddr = | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
6427 (HeapWord*) _cmsSpace->dictionary()->find_largest_dict(); |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6428 if (largestAddr == NULL) { |
0 | 6429 // The dictionary appears to be empty. In this case |
6430 // try to coalesce at the end of the heap. | |
6431 largestAddr = _cmsSpace->end(); | |
6432 } | |
6433 size_t largestOffset = pointer_delta(largestAddr, minAddr); | |
6434 size_t nearLargestOffset = | |
6435 (size_t)((double)largestOffset * nearLargestPercent) - MinChunkSize; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6436 if (PrintFLSStatistics != 0) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6437 gclog_or_tty->print_cr( |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6438 "CMS: Large Block: " PTR_FORMAT ";" |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6439 " Proximity: " PTR_FORMAT " -> " PTR_FORMAT, |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6440 largestAddr, |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6441 _cmsSpace->nearLargestChunk(), minAddr + nearLargestOffset); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6442 } |
0 | 6443 _cmsSpace->set_nearLargestChunk(minAddr + nearLargestOffset); |
6444 } | |
6445 | |
6446 bool ConcurrentMarkSweepGeneration::isNearLargestChunk(HeapWord* addr) { | |
6447 return addr >= _cmsSpace->nearLargestChunk(); | |
6448 } | |
6449 | |
6450 FreeChunk* ConcurrentMarkSweepGeneration::find_chunk_at_end() { | |
6451 return _cmsSpace->find_chunk_at_end(); | |
6452 } | |
6453 | |
6454 void ConcurrentMarkSweepGeneration::update_gc_stats(int current_level, | |
6455 bool full) { | |
6456 // The next lower level has been collected. Gather any statistics | |
6457 // that are of interest at this point. | |
6458 if (!full && (current_level + 1) == level()) { | |
6459 // Gather statistics on the young generation collection. | |
6460 collector()->stats().record_gc0_end(used()); | |
6461 } | |
6462 } | |
6463 | |
6464 CMSAdaptiveSizePolicy* ConcurrentMarkSweepGeneration::size_policy() { | |
6465 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
6466 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
6467 "Wrong type of heap"); | |
6468 CMSAdaptiveSizePolicy* sp = (CMSAdaptiveSizePolicy*) | |
6469 gch->gen_policy()->size_policy(); | |
6470 assert(sp->is_gc_cms_adaptive_size_policy(), | |
6471 "Wrong type of size policy"); | |
6472 return sp; | |
6473 } | |
6474 | |
6475 void ConcurrentMarkSweepGeneration::rotate_debug_collection_type() { | |
6476 if (PrintGCDetails && Verbose) { | |
6477 gclog_or_tty->print("Rotate from %d ", _debug_collection_type); | |
6478 } | |
6479 _debug_collection_type = (CollectionTypes) (_debug_collection_type + 1); | |
6480 _debug_collection_type = | |
6481 (CollectionTypes) (_debug_collection_type % Unknown_collection_type); | |
6482 if (PrintGCDetails && Verbose) { | |
6483 gclog_or_tty->print_cr("to %d ", _debug_collection_type); | |
6484 } | |
6485 } | |
6486 | |
6487 void CMSCollector::sweepWork(ConcurrentMarkSweepGeneration* gen, | |
6488 bool asynch) { | |
6489 // We iterate over the space(s) underlying this generation, | |
6490 // checking the mark bit map to see if the bits corresponding | |
6491 // to specific blocks are marked or not. Blocks that are | |
6492 // marked are live and are not swept up. All remaining blocks | |
6493 // are swept up, with coalescing on-the-fly as we sweep up | |
6494 // contiguous free and/or garbage blocks: | |
6495 // We need to ensure that the sweeper synchronizes with allocators | |
6496 // and stop-the-world collectors. In particular, the following | |
6497 // locks are used: | |
6498 // . CMS token: if this is held, a stop the world collection cannot occur | |
6499 // . freelistLock: if this is held no allocation can occur from this | |
6500 // generation by another thread | |
6501 // . bitMapLock: if this is held, no other thread can access or update | |
6502 // | |
6503 | |
6504 // Note that we need to hold the freelistLock if we use | |
6505 // block iterate below; else the iterator might go awry if | |
6506 // a mutator (or promotion) causes block contents to change | |
6507 // (for instance if the allocator divvies up a block). | |
6508 // If we hold the free list lock, for all practical purposes | |
6509 // young generation GC's can't occur (they'll usually need to | |
6510 // promote), so we might as well prevent all young generation | |
6511 // GC's while we do a sweeping step. For the same reason, we might | |
6512 // as well take the bit map lock for the entire duration | |
6513 | |
6514 // check that we hold the requisite locks | |
6515 assert(have_cms_token(), "Should hold cms token"); | |
6516 assert( (asynch && ConcurrentMarkSweepThread::cms_thread_has_cms_token()) | |
6517 || (!asynch && ConcurrentMarkSweepThread::vm_thread_has_cms_token()), | |
6518 "Should possess CMS token to sweep"); | |
6519 assert_lock_strong(gen->freelistLock()); | |
6520 assert_lock_strong(bitMapLock()); | |
6521 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6522 assert(!_inter_sweep_timer.is_active(), "Was switched off in an outer context"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6523 assert(_intra_sweep_timer.is_active(), "Was switched on in an outer context"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6524 gen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6525 _inter_sweep_estimate.padded_average(), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6526 _intra_sweep_estimate.padded_average()); |
0 | 6527 gen->setNearLargestChunk(); |
6528 | |
6529 { | |
6530 SweepClosure sweepClosure(this, gen, &_markBitMap, | |
6531 CMSYield && asynch); | |
6532 gen->cmsSpace()->blk_iterate_careful(&sweepClosure); | |
6533 // We need to free-up/coalesce garbage/blocks from a | |
6534 // co-terminal free run. This is done in the SweepClosure | |
6535 // destructor; so, do not remove this scope, else the | |
6536 // end-of-sweep-census below will be off by a little bit. | |
6537 } | |
6538 gen->cmsSpace()->sweep_completed(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6539 gen->cmsSpace()->endSweepFLCensus(sweep_count()); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6540 if (should_unload_classes()) { // unloaded classes this cycle, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6541 _concurrent_cycles_since_last_unload = 0; // ... reset count |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6542 } else { // did not unload classes, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6543 _concurrent_cycles_since_last_unload++; // ... increment count |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6544 } |
0 | 6545 } |
6546 | |
6547 // Reset CMS data structures (for now just the marking bit map) | |
6548 // preparatory for the next cycle. | |
6549 void CMSCollector::reset(bool asynch) { | |
6550 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
6551 CMSAdaptiveSizePolicy* sp = size_policy(); | |
6552 AdaptiveSizePolicyOutput(sp, gch->total_collections()); | |
6553 if (asynch) { | |
6554 CMSTokenSyncWithLocks ts(true, bitMapLock()); | |
6555 | |
6556 // If the state is not "Resetting", the foreground thread | |
6557 // has done a collection and the resetting. | |
6558 if (_collectorState != Resetting) { | |
6559 assert(_collectorState == Idling, "The state should only change" | |
6560 " because the foreground collector has finished the collection"); | |
6561 return; | |
6562 } | |
6563 | |
6564 // Clear the mark bitmap (no grey objects to start with) | |
6565 // for the next cycle. | |
6566 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6567 CMSPhaseAccounting cmspa(this, "reset", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 6568 |
6569 HeapWord* curAddr = _markBitMap.startWord(); | |
6570 while (curAddr < _markBitMap.endWord()) { | |
6571 size_t remaining = pointer_delta(_markBitMap.endWord(), curAddr); | |
6572 MemRegion chunk(curAddr, MIN2(CMSBitMapYieldQuantum, remaining)); | |
6573 _markBitMap.clear_large_range(chunk); | |
6574 if (ConcurrentMarkSweepThread::should_yield() && | |
6575 !foregroundGCIsActive() && | |
6576 CMSYield) { | |
6577 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6578 "CMS thread should hold CMS token"); | |
6579 assert_lock_strong(bitMapLock()); | |
6580 bitMapLock()->unlock(); | |
6581 ConcurrentMarkSweepThread::desynchronize(true); | |
6582 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6583 stopTimer(); | |
6584 if (PrintCMSStatistics != 0) { | |
6585 incrementYields(); | |
6586 } | |
6587 icms_wait(); | |
6588 | |
6589 // See the comment in coordinator_yield() | |
6590 for (unsigned i = 0; i < CMSYieldSleepCount && | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6591 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6592 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 6593 os::sleep(Thread::current(), 1, false); |
6594 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6595 } | |
6596 | |
6597 ConcurrentMarkSweepThread::synchronize(true); | |
6598 bitMapLock()->lock_without_safepoint_check(); | |
6599 startTimer(); | |
6600 } | |
6601 curAddr = chunk.end(); | |
6602 } | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6603 // A successful mostly concurrent collection has been done. |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6604 // Because only the full (i.e., concurrent mode failure) collections |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6605 // are being measured for gc overhead limits, clean the "near" flag |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6606 // and count. |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6607 sp->reset_gc_overhead_limit_count(); |
0 | 6608 _collectorState = Idling; |
6609 } else { | |
6610 // already have the lock | |
6611 assert(_collectorState == Resetting, "just checking"); | |
6612 assert_lock_strong(bitMapLock()); | |
6613 _markBitMap.clear_all(); | |
6614 _collectorState = Idling; | |
6615 } | |
6616 | |
6617 // Stop incremental mode after a cycle completes, so that any future cycles | |
6618 // are triggered by allocation. | |
6619 stop_icms(); | |
6620 | |
6621 NOT_PRODUCT( | |
6622 if (RotateCMSCollectionTypes) { | |
6623 _cmsGen->rotate_debug_collection_type(); | |
6624 } | |
6625 ) | |
10405 | 6626 |
6627 register_gc_end(); | |
0 | 6628 } |
6629 | |
6064
9d679effd28c
7166894: Add gc cause to GC logging for all collectors
brutisso
parents:
6028
diff
changeset
|
6630 void CMSCollector::do_CMS_operation(CMS_op_type op, GCCause::Cause gc_cause) { |
0 | 6631 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); |
6632 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6633 GCTraceTime t(GCCauseString("GC", gc_cause), PrintGC, !PrintGCDetails, NULL, _gc_tracer_cm->gc_id()); |
0 | 6634 TraceCollectorStats tcs(counters()); |
6635 | |
6636 switch (op) { | |
6637 case CMS_op_checkpointRootsInitial: { | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
6638 SvcGCMarker sgcm(SvcGCMarker::OTHER); |
0 | 6639 checkpointRootsInitial(true); // asynch |
6640 if (PrintGC) { | |
6641 _cmsGen->printOccupancy("initial-mark"); | |
6642 } | |
6643 break; | |
6644 } | |
6645 case CMS_op_checkpointRootsFinal: { | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
6646 SvcGCMarker sgcm(SvcGCMarker::OTHER); |
0 | 6647 checkpointRootsFinal(true, // asynch |
6648 false, // !clear_all_soft_refs | |
6649 false); // !init_mark_was_synchronous | |
6650 if (PrintGC) { | |
6651 _cmsGen->printOccupancy("remark"); | |
6652 } | |
6653 break; | |
6654 } | |
6655 default: | |
6656 fatal("No such CMS_op"); | |
6657 } | |
6658 } | |
6659 | |
6660 #ifndef PRODUCT | |
6661 size_t const CMSCollector::skip_header_HeapWords() { | |
6662 return FreeChunk::header_size(); | |
6663 } | |
6664 | |
6665 // Try and collect here conditions that should hold when | |
6666 // CMS thread is exiting. The idea is that the foreground GC | |
6667 // thread should not be blocked if it wants to terminate | |
6668 // the CMS thread and yet continue to run the VM for a while | |
6669 // after that. | |
6670 void CMSCollector::verify_ok_to_terminate() const { | |
6671 assert(Thread::current()->is_ConcurrentGC_thread(), | |
6672 "should be called by CMS thread"); | |
6673 assert(!_foregroundGCShouldWait, "should be false"); | |
6674 // We could check here that all the various low-level locks | |
6675 // are not held by the CMS thread, but that is overkill; see | |
6676 // also CMSThread::verify_ok_to_terminate() where the CGC_lock | |
6677 // is checked. | |
6678 } | |
6679 #endif | |
6680 | |
6681 size_t CMSCollector::block_size_using_printezis_bits(HeapWord* addr) const { | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6682 assert(_markBitMap.isMarked(addr) && _markBitMap.isMarked(addr + 1), |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6683 "missing Printezis mark?"); |
0 | 6684 HeapWord* nextOneAddr = _markBitMap.getNextMarkedWordAddress(addr + 2); |
6685 size_t size = pointer_delta(nextOneAddr + 1, addr); | |
6686 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6687 "alignment problem"); | |
6688 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6689 return size; | |
6690 } | |
6691 | |
6692 // A variant of the above (block_size_using_printezis_bits()) except | |
6693 // that we return 0 if the P-bits are not yet set. | |
6694 size_t CMSCollector::block_size_if_printezis_bits(HeapWord* addr) const { | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6695 if (_markBitMap.isMarked(addr + 1)) { |
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6696 assert(_markBitMap.isMarked(addr), "P-bit can be set only for marked objects"); |
0 | 6697 HeapWord* nextOneAddr = _markBitMap.getNextMarkedWordAddress(addr + 2); |
6698 size_t size = pointer_delta(nextOneAddr + 1, addr); | |
6699 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6700 "alignment problem"); | |
6701 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6702 return size; | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6703 } |
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6704 return 0; |
0 | 6705 } |
6706 | |
6707 HeapWord* CMSCollector::next_card_start_after_block(HeapWord* addr) const { | |
6708 size_t sz = 0; | |
6709 oop p = (oop)addr; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6710 if (p->klass_or_null() != NULL) { |
0 | 6711 sz = CompactibleFreeListSpace::adjustObjectSize(p->size()); |
6712 } else { | |
6713 sz = block_size_using_printezis_bits(addr); | |
6714 } | |
6715 assert(sz > 0, "size must be nonzero"); | |
6716 HeapWord* next_block = addr + sz; | |
6717 HeapWord* next_card = (HeapWord*)round_to((uintptr_t)next_block, | |
6718 CardTableModRefBS::card_size); | |
6719 assert(round_down((uintptr_t)addr, CardTableModRefBS::card_size) < | |
6720 round_down((uintptr_t)next_card, CardTableModRefBS::card_size), | |
6721 "must be different cards"); | |
6722 return next_card; | |
6723 } | |
6724 | |
6725 | |
6726 // CMS Bit Map Wrapper ///////////////////////////////////////// | |
6727 | |
6728 // Construct a CMS bit map infrastructure, but don't create the | |
6729 // bit vector itself. That is done by a separate call CMSBitMap::allocate() | |
6730 // further below. | |
6731 CMSBitMap::CMSBitMap(int shifter, int mutex_rank, const char* mutex_name): | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
6732 _bm(), |
0 | 6733 _shifter(shifter), |
6734 _lock(mutex_rank >= 0 ? new Mutex(mutex_rank, mutex_name, true) : NULL) | |
6735 { | |
6736 _bmStartWord = 0; | |
6737 _bmWordSize = 0; | |
6738 } | |
6739 | |
6740 bool CMSBitMap::allocate(MemRegion mr) { | |
6741 _bmStartWord = mr.start(); | |
6742 _bmWordSize = mr.word_size(); | |
6743 ReservedSpace brs(ReservedSpace::allocation_align_size_up( | |
6744 (_bmWordSize >> (_shifter + LogBitsPerByte)) + 1)); | |
6745 if (!brs.is_reserved()) { | |
6746 warning("CMS bit map allocation failure"); | |
6747 return false; | |
6748 } | |
6749 // For now we'll just commit all of the bit map up fromt. | |
6750 // Later on we'll try to be more parsimonious with swap. | |
6751 if (!_virtual_space.initialize(brs, brs.size())) { | |
6752 warning("CMS bit map backing store failure"); | |
6753 return false; | |
6754 } | |
6755 assert(_virtual_space.committed_size() == brs.size(), | |
6756 "didn't reserve backing store for all of CMS bit map?"); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
6757 _bm.set_map((BitMap::bm_word_t*)_virtual_space.low()); |
0 | 6758 assert(_virtual_space.committed_size() << (_shifter + LogBitsPerByte) >= |
6759 _bmWordSize, "inconsistency in bit map sizing"); | |
6760 _bm.set_size(_bmWordSize >> _shifter); | |
6761 | |
6762 // bm.clear(); // can we rely on getting zero'd memory? verify below | |
6763 assert(isAllClear(), | |
6764 "Expected zero'd memory from ReservedSpace constructor"); | |
6765 assert(_bm.size() == heapWordDiffToOffsetDiff(sizeInWords()), | |
6766 "consistency check"); | |
6767 return true; | |
6768 } | |
6769 | |
6770 void CMSBitMap::dirty_range_iterate_clear(MemRegion mr, MemRegionClosure* cl) { | |
6771 HeapWord *next_addr, *end_addr, *last_addr; | |
6772 assert_locked(); | |
6773 assert(covers(mr), "out-of-range error"); | |
6774 // XXX assert that start and end are appropriately aligned | |
6775 for (next_addr = mr.start(), end_addr = mr.end(); | |
6776 next_addr < end_addr; next_addr = last_addr) { | |
6777 MemRegion dirty_region = getAndClearMarkedRegion(next_addr, end_addr); | |
6778 last_addr = dirty_region.end(); | |
6779 if (!dirty_region.is_empty()) { | |
6780 cl->do_MemRegion(dirty_region); | |
6781 } else { | |
6782 assert(last_addr == end_addr, "program logic"); | |
6783 return; | |
6784 } | |
6785 } | |
6786 } | |
6787 | |
9076
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6788 void CMSBitMap::print_on_error(outputStream* st, const char* prefix) const { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6789 _bm.print_on_error(st, prefix); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6790 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6791 |
0 | 6792 #ifndef PRODUCT |
6793 void CMSBitMap::assert_locked() const { | |
6794 CMSLockVerifier::assert_locked(lock()); | |
6795 } | |
6796 | |
6797 bool CMSBitMap::covers(MemRegion mr) const { | |
6798 // assert(_bm.map() == _virtual_space.low(), "map inconsistency"); | |
6799 assert((size_t)_bm.size() == (_bmWordSize >> _shifter), | |
6800 "size inconsistency"); | |
6801 return (mr.start() >= _bmStartWord) && | |
6802 (mr.end() <= endWord()); | |
6803 } | |
6804 | |
6805 bool CMSBitMap::covers(HeapWord* start, size_t size) const { | |
6806 return (start >= _bmStartWord && (start + size) <= endWord()); | |
6807 } | |
6808 | |
6809 void CMSBitMap::verifyNoOneBitsInRange(HeapWord* left, HeapWord* right) { | |
6810 // verify that there are no 1 bits in the interval [left, right) | |
6811 FalseBitMapClosure falseBitMapClosure; | |
6812 iterate(&falseBitMapClosure, left, right); | |
6813 } | |
6814 | |
6815 void CMSBitMap::region_invariant(MemRegion mr) | |
6816 { | |
6817 assert_locked(); | |
6818 // mr = mr.intersection(MemRegion(_bmStartWord, _bmWordSize)); | |
6819 assert(!mr.is_empty(), "unexpected empty region"); | |
6820 assert(covers(mr), "mr should be covered by bit map"); | |
6821 // convert address range into offset range | |
6822 size_t start_ofs = heapWordToOffset(mr.start()); | |
6823 // Make sure that end() is appropriately aligned | |
6824 assert(mr.end() == (HeapWord*)round_to((intptr_t)mr.end(), | |
6825 (1 << (_shifter+LogHeapWordSize))), | |
6826 "Misaligned mr.end()"); | |
6827 size_t end_ofs = heapWordToOffset(mr.end()); | |
6828 assert(end_ofs > start_ofs, "Should mark at least one bit"); | |
6829 } | |
6830 | |
6831 #endif | |
6832 | |
6833 bool CMSMarkStack::allocate(size_t size) { | |
6834 // allocate a stack of the requisite depth | |
6835 ReservedSpace rs(ReservedSpace::allocation_align_size_up( | |
6836 size * sizeof(oop))); | |
6837 if (!rs.is_reserved()) { | |
6838 warning("CMSMarkStack allocation failure"); | |
6839 return false; | |
6840 } | |
6841 if (!_virtual_space.initialize(rs, rs.size())) { | |
6842 warning("CMSMarkStack backing store failure"); | |
6843 return false; | |
6844 } | |
6845 assert(_virtual_space.committed_size() == rs.size(), | |
6846 "didn't reserve backing store for all of CMS stack?"); | |
6847 _base = (oop*)(_virtual_space.low()); | |
6848 _index = 0; | |
6849 _capacity = size; | |
6850 NOT_PRODUCT(_max_depth = 0); | |
6851 return true; | |
6852 } | |
6853 | |
6854 // XXX FIX ME !!! In the MT case we come in here holding a | |
6855 // leaf lock. For printing we need to take a further lock | |
6856 // which has lower rank. We need to recallibrate the two | |
6857 // lock-ranks involved in order to be able to rpint the | |
6858 // messages below. (Or defer the printing to the caller. | |
6859 // For now we take the expedient path of just disabling the | |
6860 // messages for the problematic case.) | |
6861 void CMSMarkStack::expand() { | |
1284 | 6862 assert(_capacity <= MarkStackSizeMax, "stack bigger than permitted"); |
6863 if (_capacity == MarkStackSizeMax) { | |
0 | 6864 if (_hit_limit++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) { |
6865 // We print a warning message only once per CMS cycle. | |
6866 gclog_or_tty->print_cr(" (benign) Hit CMSMarkStack max size limit"); | |
6867 } | |
6868 return; | |
6869 } | |
6870 // Double capacity if possible | |
1284 | 6871 size_t new_capacity = MIN2(_capacity*2, MarkStackSizeMax); |
0 | 6872 // Do not give up existing stack until we have managed to |
6873 // get the double capacity that we desired. | |
6874 ReservedSpace rs(ReservedSpace::allocation_align_size_up( | |
6875 new_capacity * sizeof(oop))); | |
6876 if (rs.is_reserved()) { | |
6877 // Release the backing store associated with old stack | |
6878 _virtual_space.release(); | |
6879 // Reinitialize virtual space for new stack | |
6880 if (!_virtual_space.initialize(rs, rs.size())) { | |
6881 fatal("Not enough swap for expanded marking stack"); | |
6882 } | |
6883 _base = (oop*)(_virtual_space.low()); | |
6884 _index = 0; | |
6885 _capacity = new_capacity; | |
6886 } else if (_failed_double++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) { | |
6887 // Failed to double capacity, continue; | |
6888 // we print a detail message only once per CMS cycle. | |
6889 gclog_or_tty->print(" (benign) Failed to expand marking stack from "SIZE_FORMAT"K to " | |
6890 SIZE_FORMAT"K", | |
6891 _capacity / K, new_capacity / K); | |
6892 } | |
6893 } | |
6894 | |
6895 | |
6896 // Closures | |
6897 // XXX: there seems to be a lot of code duplication here; | |
6898 // should refactor and consolidate common code. | |
6899 | |
6900 // This closure is used to mark refs into the CMS generation in | |
6901 // the CMS bit map. Called at the first checkpoint. This closure | |
6902 // assumes that we do not need to re-mark dirty cards; if the CMS | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6903 // generation on which this is used is not an oldest |
0 | 6904 // generation then this will lose younger_gen cards! |
6905 | |
6906 MarkRefsIntoClosure::MarkRefsIntoClosure( | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6907 MemRegion span, CMSBitMap* bitMap): |
0 | 6908 _span(span), |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6909 _bitMap(bitMap) |
0 | 6910 { |
6911 assert(_ref_processor == NULL, "deliberately left NULL"); | |
6912 assert(_bitMap->covers(_span), "_bitMap/_span mismatch"); | |
6913 } | |
6914 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6915 void MarkRefsIntoClosure::do_oop(oop obj) { |
0 | 6916 // if p points into _span, then mark corresponding bit in _markBitMap |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6917 assert(obj->is_oop(), "expected an oop"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6918 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6919 if (_span.contains(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6920 // this should be made more efficient |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6921 _bitMap->mark(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6922 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6923 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6924 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6925 void MarkRefsIntoClosure::do_oop(oop* p) { MarkRefsIntoClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6926 void MarkRefsIntoClosure::do_oop(narrowOop* p) { MarkRefsIntoClosure::do_oop_work(p); } |
0 | 6927 |
11975 | 6928 Par_MarkRefsIntoClosure::Par_MarkRefsIntoClosure( |
6929 MemRegion span, CMSBitMap* bitMap): | |
6930 _span(span), | |
6931 _bitMap(bitMap) | |
6932 { | |
6933 assert(_ref_processor == NULL, "deliberately left NULL"); | |
6934 assert(_bitMap->covers(_span), "_bitMap/_span mismatch"); | |
6935 } | |
6936 | |
6937 void Par_MarkRefsIntoClosure::do_oop(oop obj) { | |
6938 // if p points into _span, then mark corresponding bit in _markBitMap | |
6939 assert(obj->is_oop(), "expected an oop"); | |
6940 HeapWord* addr = (HeapWord*)obj; | |
6941 if (_span.contains(addr)) { | |
6942 // this should be made more efficient | |
6943 _bitMap->par_mark(addr); | |
6944 } | |
6945 } | |
6946 | |
6947 void Par_MarkRefsIntoClosure::do_oop(oop* p) { Par_MarkRefsIntoClosure::do_oop_work(p); } | |
6948 void Par_MarkRefsIntoClosure::do_oop(narrowOop* p) { Par_MarkRefsIntoClosure::do_oop_work(p); } | |
6949 | |
0 | 6950 // A variant of the above, used for CMS marking verification. |
6951 MarkRefsIntoVerifyClosure::MarkRefsIntoVerifyClosure( | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6952 MemRegion span, CMSBitMap* verification_bm, CMSBitMap* cms_bm): |
0 | 6953 _span(span), |
6954 _verification_bm(verification_bm), | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6955 _cms_bm(cms_bm) |
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6956 { |
0 | 6957 assert(_ref_processor == NULL, "deliberately left NULL"); |
6958 assert(_verification_bm->covers(_span), "_verification_bm/_span mismatch"); | |
6959 } | |
6960 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6961 void MarkRefsIntoVerifyClosure::do_oop(oop obj) { |
0 | 6962 // if p points into _span, then mark corresponding bit in _markBitMap |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6963 assert(obj->is_oop(), "expected an oop"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6964 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6965 if (_span.contains(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6966 _verification_bm->mark(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6967 if (!_cms_bm->isMarked(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6968 oop(addr)->print(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6969 gclog_or_tty->print_cr(" (" INTPTR_FORMAT " should have been marked)", addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6970 fatal("... aborting"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6971 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6972 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6973 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6974 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6975 void MarkRefsIntoVerifyClosure::do_oop(oop* p) { MarkRefsIntoVerifyClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6976 void MarkRefsIntoVerifyClosure::do_oop(narrowOop* p) { MarkRefsIntoVerifyClosure::do_oop_work(p); } |
0 | 6977 |
6978 ////////////////////////////////////////////////// | |
6979 // MarkRefsIntoAndScanClosure | |
6980 ////////////////////////////////////////////////// | |
6981 | |
6982 MarkRefsIntoAndScanClosure::MarkRefsIntoAndScanClosure(MemRegion span, | |
6983 ReferenceProcessor* rp, | |
6984 CMSBitMap* bit_map, | |
6985 CMSBitMap* mod_union_table, | |
6986 CMSMarkStack* mark_stack, | |
6987 CMSCollector* collector, | |
6988 bool should_yield, | |
6989 bool concurrent_precleaning): | |
6990 _collector(collector), | |
6991 _span(span), | |
6992 _bit_map(bit_map), | |
6993 _mark_stack(mark_stack), | |
6994 _pushAndMarkClosure(collector, span, rp, bit_map, mod_union_table, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6995 mark_stack, concurrent_precleaning), |
0 | 6996 _yield(should_yield), |
6997 _concurrent_precleaning(concurrent_precleaning), | |
6998 _freelistLock(NULL) | |
6999 { | |
7000 _ref_processor = rp; | |
7001 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7002 } | |
7003 | |
7004 // This closure is used to mark refs into the CMS generation at the | |
7005 // second (final) checkpoint, and to scan and transitively follow | |
7006 // the unmarked oops. It is also used during the concurrent precleaning | |
7007 // phase while scanning objects on dirty cards in the CMS generation. | |
7008 // The marks are made in the marking bit map and the marking stack is | |
7009 // used for keeping the (newly) grey objects during the scan. | |
7010 // The parallel version (Par_...) appears further below. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7011 void MarkRefsIntoAndScanClosure::do_oop(oop obj) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7012 if (obj != NULL) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7013 assert(obj->is_oop(), "expected an oop"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7014 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7015 assert(_mark_stack->isEmpty(), "pre-condition (eager drainage)"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7016 assert(_collector->overflow_list_is_empty(), |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7017 "overflow list should be empty"); |
0 | 7018 if (_span.contains(addr) && |
7019 !_bit_map->isMarked(addr)) { | |
7020 // mark bit map (object is now grey) | |
7021 _bit_map->mark(addr); | |
7022 // push on marking stack (stack should be empty), and drain the | |
7023 // stack by applying this closure to the oops in the oops popped | |
7024 // from the stack (i.e. blacken the grey objects) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7025 bool res = _mark_stack->push(obj); |
0 | 7026 assert(res, "Should have space to push on empty stack"); |
7027 do { | |
7028 oop new_oop = _mark_stack->pop(); | |
7029 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
7030 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
7031 "only grey objects on this stack"); | |
7032 // iterate over the oops in this oop, marking and pushing | |
7033 // the ones in CMS heap (i.e. in _span). | |
7034 new_oop->oop_iterate(&_pushAndMarkClosure); | |
7035 // check if it's time to yield | |
7036 do_yield_check(); | |
7037 } while (!_mark_stack->isEmpty() || | |
7038 (!_concurrent_precleaning && take_from_overflow_list())); | |
7039 // if marking stack is empty, and we are not doing this | |
7040 // during precleaning, then check the overflow list | |
7041 } | |
7042 assert(_mark_stack->isEmpty(), "post-condition (eager drainage)"); | |
7043 assert(_collector->overflow_list_is_empty(), | |
7044 "overflow list was drained above"); | |
7045 // We could restore evacuated mark words, if any, used for | |
7046 // overflow list links here because the overflow list is | |
7047 // provably empty here. That would reduce the maximum | |
7048 // size requirements for preserved_{oop,mark}_stack. | |
7049 // But we'll just postpone it until we are all done | |
7050 // so we can just stream through. | |
7051 if (!_concurrent_precleaning && CMSOverflowEarlyRestoration) { | |
7052 _collector->restore_preserved_marks_if_any(); | |
7053 assert(_collector->no_preserved_marks(), "No preserved marks"); | |
7054 } | |
7055 assert(!CMSOverflowEarlyRestoration || _collector->no_preserved_marks(), | |
7056 "All preserved marks should have been restored above"); | |
7057 } | |
7058 } | |
7059 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7060 void MarkRefsIntoAndScanClosure::do_oop(oop* p) { MarkRefsIntoAndScanClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7061 void MarkRefsIntoAndScanClosure::do_oop(narrowOop* p) { MarkRefsIntoAndScanClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7062 |
0 | 7063 void MarkRefsIntoAndScanClosure::do_yield_work() { |
7064 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7065 "CMS thread should hold CMS token"); | |
7066 assert_lock_strong(_freelistLock); | |
7067 assert_lock_strong(_bit_map->lock()); | |
7068 // relinquish the free_list_lock and bitMaplock() | |
7069 _bit_map->lock()->unlock(); | |
7070 _freelistLock->unlock(); | |
7071 ConcurrentMarkSweepThread::desynchronize(true); | |
7072 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7073 _collector->stopTimer(); | |
7074 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7075 if (PrintCMSStatistics != 0) { | |
7076 _collector->incrementYields(); | |
7077 } | |
7078 _collector->icms_wait(); | |
7079 | |
7080 // See the comment in coordinator_yield() | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7081 for (unsigned i = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7082 i < CMSYieldSleepCount && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7083 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7084 !CMSCollector::foregroundGCIsActive(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7085 ++i) { |
0 | 7086 os::sleep(Thread::current(), 1, false); |
7087 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7088 } | |
7089 | |
7090 ConcurrentMarkSweepThread::synchronize(true); | |
7091 _freelistLock->lock_without_safepoint_check(); | |
7092 _bit_map->lock()->lock_without_safepoint_check(); | |
7093 _collector->startTimer(); | |
7094 } | |
7095 | |
7096 /////////////////////////////////////////////////////////// | |
7097 // Par_MarkRefsIntoAndScanClosure: a parallel version of | |
7098 // MarkRefsIntoAndScanClosure | |
7099 /////////////////////////////////////////////////////////// | |
7100 Par_MarkRefsIntoAndScanClosure::Par_MarkRefsIntoAndScanClosure( | |
7101 CMSCollector* collector, MemRegion span, ReferenceProcessor* rp, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7102 CMSBitMap* bit_map, OopTaskQueue* work_queue): |
0 | 7103 _span(span), |
7104 _bit_map(bit_map), | |
7105 _work_queue(work_queue), | |
7106 _low_water_mark(MIN2((uint)(work_queue->max_elems()/4), | |
7107 (uint)(CMSWorkQueueDrainThreshold * ParallelGCThreads))), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7108 _par_pushAndMarkClosure(collector, span, rp, bit_map, work_queue) |
0 | 7109 { |
7110 _ref_processor = rp; | |
7111 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7112 } | |
7113 | |
7114 // This closure is used to mark refs into the CMS generation at the | |
7115 // second (final) checkpoint, and to scan and transitively follow | |
7116 // the unmarked oops. The marks are made in the marking bit map and | |
7117 // the work_queue is used for keeping the (newly) grey objects during | |
7118 // the scan phase whence they are also available for stealing by parallel | |
7119 // threads. Since the marking bit map is shared, updates are | |
7120 // synchronized (via CAS). | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7121 void Par_MarkRefsIntoAndScanClosure::do_oop(oop obj) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7122 if (obj != NULL) { |
0 | 7123 // Ignore mark word because this could be an already marked oop |
7124 // that may be chained at the end of the overflow list. | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7125 assert(obj->is_oop(true), "expected an oop"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7126 HeapWord* addr = (HeapWord*)obj; |
0 | 7127 if (_span.contains(addr) && |
7128 !_bit_map->isMarked(addr)) { | |
7129 // mark bit map (object will become grey): | |
7130 // It is possible for several threads to be | |
7131 // trying to "claim" this object concurrently; | |
7132 // the unique thread that succeeds in marking the | |
7133 // object first will do the subsequent push on | |
7134 // to the work queue (or overflow list). | |
7135 if (_bit_map->par_mark(addr)) { | |
7136 // push on work_queue (which may not be empty), and trim the | |
7137 // queue to an appropriate length by applying this closure to | |
7138 // the oops in the oops popped from the stack (i.e. blacken the | |
7139 // grey objects) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7140 bool res = _work_queue->push(obj); |
0 | 7141 assert(res, "Low water mark should be less than capacity?"); |
7142 trim_queue(_low_water_mark); | |
7143 } // Else, another thread claimed the object | |
7144 } | |
7145 } | |
7146 } | |
7147 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7148 void Par_MarkRefsIntoAndScanClosure::do_oop(oop* p) { Par_MarkRefsIntoAndScanClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7149 void Par_MarkRefsIntoAndScanClosure::do_oop(narrowOop* p) { Par_MarkRefsIntoAndScanClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7150 |
0 | 7151 // This closure is used to rescan the marked objects on the dirty cards |
7152 // in the mod union table and the card table proper. | |
7153 size_t ScanMarkedObjectsAgainCarefullyClosure::do_object_careful_m( | |
7154 oop p, MemRegion mr) { | |
7155 | |
7156 size_t size = 0; | |
7157 HeapWord* addr = (HeapWord*)p; | |
7158 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7159 assert(_span.contains(addr), "we are scanning the CMS generation"); | |
7160 // check if it's time to yield | |
7161 if (do_yield_check()) { | |
7162 // We yielded for some foreground stop-world work, | |
7163 // and we have been asked to abort this ongoing preclean cycle. | |
7164 return 0; | |
7165 } | |
7166 if (_bitMap->isMarked(addr)) { | |
7167 // it's marked; is it potentially uninitialized? | |
187 | 7168 if (p->klass_or_null() != NULL) { |
0 | 7169 // an initialized object; ignore mark word in verification below |
7170 // since we are running concurrent with mutators | |
7171 assert(p->is_oop(true), "should be an oop"); | |
7172 if (p->is_objArray()) { | |
7173 // objArrays are precisely marked; restrict scanning | |
7174 // to dirty cards only. | |
187 | 7175 size = CompactibleFreeListSpace::adjustObjectSize( |
7176 p->oop_iterate(_scanningClosure, mr)); | |
0 | 7177 } else { |
7178 // A non-array may have been imprecisely marked; we need | |
7179 // to scan object in its entirety. | |
7180 size = CompactibleFreeListSpace::adjustObjectSize( | |
7181 p->oop_iterate(_scanningClosure)); | |
7182 } | |
9152 | 7183 #ifdef ASSERT |
0 | 7184 size_t direct_size = |
7185 CompactibleFreeListSpace::adjustObjectSize(p->size()); | |
7186 assert(size == direct_size, "Inconsistency in size"); | |
7187 assert(size >= 3, "Necessary for Printezis marks to work"); | |
7188 if (!_bitMap->isMarked(addr+1)) { | |
7189 _bitMap->verifyNoOneBitsInRange(addr+2, addr+size); | |
7190 } else { | |
7191 _bitMap->verifyNoOneBitsInRange(addr+2, addr+size-1); | |
7192 assert(_bitMap->isMarked(addr+size-1), | |
7193 "inconsistent Printezis mark"); | |
7194 } | |
9152 | 7195 #endif // ASSERT |
0 | 7196 } else { |
7197 // an unitialized object | |
7198 assert(_bitMap->isMarked(addr+1), "missing Printezis mark?"); | |
7199 HeapWord* nextOneAddr = _bitMap->getNextMarkedWordAddress(addr + 2); | |
7200 size = pointer_delta(nextOneAddr + 1, addr); | |
7201 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
7202 "alignment problem"); | |
7203 // Note that pre-cleaning needn't redirty the card. OopDesc::set_klass() | |
7204 // will dirty the card when the klass pointer is installed in the | |
7205 // object (signalling the completion of initialization). | |
7206 } | |
7207 } else { | |
7208 // Either a not yet marked object or an uninitialized object | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7209 if (p->klass_or_null() == NULL) { |
0 | 7210 // An uninitialized object, skip to the next card, since |
7211 // we may not be able to read its P-bits yet. | |
7212 assert(size == 0, "Initial value"); | |
7213 } else { | |
7214 // An object not (yet) reached by marking: we merely need to | |
7215 // compute its size so as to go look at the next block. | |
7216 assert(p->is_oop(true), "should be an oop"); | |
7217 size = CompactibleFreeListSpace::adjustObjectSize(p->size()); | |
7218 } | |
7219 } | |
7220 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7221 return size; | |
7222 } | |
7223 | |
7224 void ScanMarkedObjectsAgainCarefullyClosure::do_yield_work() { | |
7225 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7226 "CMS thread should hold CMS token"); | |
7227 assert_lock_strong(_freelistLock); | |
7228 assert_lock_strong(_bitMap->lock()); | |
7229 // relinquish the free_list_lock and bitMaplock() | |
7230 _bitMap->lock()->unlock(); | |
7231 _freelistLock->unlock(); | |
7232 ConcurrentMarkSweepThread::desynchronize(true); | |
7233 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7234 _collector->stopTimer(); | |
7235 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7236 if (PrintCMSStatistics != 0) { | |
7237 _collector->incrementYields(); | |
7238 } | |
7239 _collector->icms_wait(); | |
7240 | |
7241 // See the comment in coordinator_yield() | |
7242 for (unsigned i = 0; i < CMSYieldSleepCount && | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7243 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7244 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 7245 os::sleep(Thread::current(), 1, false); |
7246 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7247 } | |
7248 | |
7249 ConcurrentMarkSweepThread::synchronize(true); | |
7250 _freelistLock->lock_without_safepoint_check(); | |
7251 _bitMap->lock()->lock_without_safepoint_check(); | |
7252 _collector->startTimer(); | |
7253 } | |
7254 | |
7255 | |
7256 ////////////////////////////////////////////////////////////////// | |
7257 // SurvivorSpacePrecleanClosure | |
7258 ////////////////////////////////////////////////////////////////// | |
7259 // This (single-threaded) closure is used to preclean the oops in | |
7260 // the survivor spaces. | |
7261 size_t SurvivorSpacePrecleanClosure::do_object_careful(oop p) { | |
7262 | |
7263 HeapWord* addr = (HeapWord*)p; | |
7264 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7265 assert(!_span.contains(addr), "we are scanning the survivor spaces"); | |
187 | 7266 assert(p->klass_or_null() != NULL, "object should be initializd"); |
0 | 7267 // an initialized object; ignore mark word in verification below |
7268 // since we are running concurrent with mutators | |
7269 assert(p->is_oop(true), "should be an oop"); | |
7270 // Note that we do not yield while we iterate over | |
7271 // the interior oops of p, pushing the relevant ones | |
7272 // on our marking stack. | |
7273 size_t size = p->oop_iterate(_scanning_closure); | |
7274 do_yield_check(); | |
7275 // Observe that below, we do not abandon the preclean | |
7276 // phase as soon as we should; rather we empty the | |
7277 // marking stack before returning. This is to satisfy | |
7278 // some existing assertions. In general, it may be a | |
7279 // good idea to abort immediately and complete the marking | |
7280 // from the grey objects at a later time. | |
7281 while (!_mark_stack->isEmpty()) { | |
7282 oop new_oop = _mark_stack->pop(); | |
7283 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
7284 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
7285 "only grey objects on this stack"); | |
7286 // iterate over the oops in this oop, marking and pushing | |
7287 // the ones in CMS heap (i.e. in _span). | |
7288 new_oop->oop_iterate(_scanning_closure); | |
7289 // check if it's time to yield | |
7290 do_yield_check(); | |
7291 } | |
7292 unsigned int after_count = | |
7293 GenCollectedHeap::heap()->total_collections(); | |
7294 bool abort = (_before_count != after_count) || | |
7295 _collector->should_abort_preclean(); | |
7296 return abort ? 0 : size; | |
7297 } | |
7298 | |
7299 void SurvivorSpacePrecleanClosure::do_yield_work() { | |
7300 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7301 "CMS thread should hold CMS token"); | |
7302 assert_lock_strong(_bit_map->lock()); | |
7303 // Relinquish the bit map lock | |
7304 _bit_map->lock()->unlock(); | |
7305 ConcurrentMarkSweepThread::desynchronize(true); | |
7306 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7307 _collector->stopTimer(); | |
7308 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7309 if (PrintCMSStatistics != 0) { | |
7310 _collector->incrementYields(); | |
7311 } | |
7312 _collector->icms_wait(); | |
7313 | |
7314 // See the comment in coordinator_yield() | |
7315 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7316 ConcurrentMarkSweepThread::should_yield() && | |
7317 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7318 os::sleep(Thread::current(), 1, false); | |
7319 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7320 } | |
7321 | |
7322 ConcurrentMarkSweepThread::synchronize(true); | |
7323 _bit_map->lock()->lock_without_safepoint_check(); | |
7324 _collector->startTimer(); | |
7325 } | |
7326 | |
7327 // This closure is used to rescan the marked objects on the dirty cards | |
7328 // in the mod union table and the card table proper. In the parallel | |
7329 // case, although the bitMap is shared, we do a single read so the | |
7330 // isMarked() query is "safe". | |
7331 bool ScanMarkedObjectsAgainClosure::do_object_bm(oop p, MemRegion mr) { | |
7332 // Ignore mark word because we are running concurrent with mutators | |
7333 assert(p->is_oop_or_null(true), "expected an oop or null"); | |
7334 HeapWord* addr = (HeapWord*)p; | |
7335 assert(_span.contains(addr), "we are scanning the CMS generation"); | |
7336 bool is_obj_array = false; | |
9152 | 7337 #ifdef ASSERT |
0 | 7338 if (!_parallel) { |
7339 assert(_mark_stack->isEmpty(), "pre-condition (eager drainage)"); | |
7340 assert(_collector->overflow_list_is_empty(), | |
7341 "overflow list should be empty"); | |
7342 | |
7343 } | |
9152 | 7344 #endif // ASSERT |
0 | 7345 if (_bit_map->isMarked(addr)) { |
7346 // Obj arrays are precisely marked, non-arrays are not; | |
7347 // so we scan objArrays precisely and non-arrays in their | |
7348 // entirety. | |
7349 if (p->is_objArray()) { | |
7350 is_obj_array = true; | |
7351 if (_parallel) { | |
7352 p->oop_iterate(_par_scan_closure, mr); | |
7353 } else { | |
7354 p->oop_iterate(_scan_closure, mr); | |
7355 } | |
7356 } else { | |
7357 if (_parallel) { | |
7358 p->oop_iterate(_par_scan_closure); | |
7359 } else { | |
7360 p->oop_iterate(_scan_closure); | |
7361 } | |
7362 } | |
7363 } | |
9152 | 7364 #ifdef ASSERT |
0 | 7365 if (!_parallel) { |
7366 assert(_mark_stack->isEmpty(), "post-condition (eager drainage)"); | |
7367 assert(_collector->overflow_list_is_empty(), | |
7368 "overflow list should be empty"); | |
7369 | |
7370 } | |
9152 | 7371 #endif // ASSERT |
0 | 7372 return is_obj_array; |
7373 } | |
7374 | |
7375 MarkFromRootsClosure::MarkFromRootsClosure(CMSCollector* collector, | |
7376 MemRegion span, | |
7377 CMSBitMap* bitMap, CMSMarkStack* markStack, | |
7378 bool should_yield, bool verifying): | |
7379 _collector(collector), | |
7380 _span(span), | |
7381 _bitMap(bitMap), | |
7382 _mut(&collector->_modUnionTable), | |
7383 _markStack(markStack), | |
7384 _yield(should_yield), | |
7385 _skipBits(0) | |
7386 { | |
7387 assert(_markStack->isEmpty(), "stack should be empty"); | |
7388 _finger = _bitMap->startWord(); | |
7389 _threshold = _finger; | |
7390 assert(_collector->_restart_addr == NULL, "Sanity check"); | |
7391 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7392 DEBUG_ONLY(_verifying = verifying;) | |
7393 } | |
7394 | |
7395 void MarkFromRootsClosure::reset(HeapWord* addr) { | |
7396 assert(_markStack->isEmpty(), "would cause duplicates on stack"); | |
7397 assert(_span.contains(addr), "Out of bounds _finger?"); | |
7398 _finger = addr; | |
7399 _threshold = (HeapWord*)round_to( | |
7400 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7401 } | |
7402 | |
7403 // Should revisit to see if this should be restructured for | |
7404 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7405 bool MarkFromRootsClosure::do_bit(size_t offset) { |
0 | 7406 if (_skipBits > 0) { |
7407 _skipBits--; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7408 return true; |
0 | 7409 } |
7410 // convert offset into a HeapWord* | |
7411 HeapWord* addr = _bitMap->startWord() + offset; | |
7412 assert(_bitMap->endWord() && addr < _bitMap->endWord(), | |
7413 "address out of range"); | |
7414 assert(_bitMap->isMarked(addr), "tautology"); | |
7415 if (_bitMap->isMarked(addr+1)) { | |
7416 // this is an allocated but not yet initialized object | |
7417 assert(_skipBits == 0, "tautology"); | |
7418 _skipBits = 2; // skip next two marked bits ("Printezis-marks") | |
7419 oop p = oop(addr); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7420 if (p->klass_or_null() == NULL) { |
0 | 7421 DEBUG_ONLY(if (!_verifying) {) |
7422 // We re-dirty the cards on which this object lies and increase | |
7423 // the _threshold so that we'll come back to scan this object | |
7424 // during the preclean or remark phase. (CMSCleanOnEnter) | |
7425 if (CMSCleanOnEnter) { | |
7426 size_t sz = _collector->block_size_using_printezis_bits(addr); | |
7427 HeapWord* end_card_addr = (HeapWord*)round_to( | |
7428 (intptr_t)(addr+sz), CardTableModRefBS::card_size); | |
283
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7429 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
0 | 7430 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
7431 // Bump _threshold to end_card_addr; note that | |
7432 // _threshold cannot possibly exceed end_card_addr, anyhow. | |
7433 // This prevents future clearing of the card as the scan proceeds | |
7434 // to the right. | |
7435 assert(_threshold <= end_card_addr, | |
7436 "Because we are just scanning into this object"); | |
7437 if (_threshold < end_card_addr) { | |
7438 _threshold = end_card_addr; | |
7439 } | |
187 | 7440 if (p->klass_or_null() != NULL) { |
0 | 7441 // Redirty the range of cards... |
7442 _mut->mark_range(redirty_range); | |
7443 } // ...else the setting of klass will dirty the card anyway. | |
7444 } | |
7445 DEBUG_ONLY(}) | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7446 return true; |
0 | 7447 } |
7448 } | |
7449 scanOopsInOop(addr); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7450 return true; |
0 | 7451 } |
7452 | |
7453 // We take a break if we've been at this for a while, | |
7454 // so as to avoid monopolizing the locks involved. | |
7455 void MarkFromRootsClosure::do_yield_work() { | |
7456 // First give up the locks, then yield, then re-lock | |
7457 // We should probably use a constructor/destructor idiom to | |
7458 // do this unlock/lock or modify the MutexUnlocker class to | |
7459 // serve our purpose. XXX | |
7460 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7461 "CMS thread should hold CMS token"); | |
7462 assert_lock_strong(_bitMap->lock()); | |
7463 _bitMap->lock()->unlock(); | |
7464 ConcurrentMarkSweepThread::desynchronize(true); | |
7465 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7466 _collector->stopTimer(); | |
7467 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7468 if (PrintCMSStatistics != 0) { | |
7469 _collector->incrementYields(); | |
7470 } | |
7471 _collector->icms_wait(); | |
7472 | |
7473 // See the comment in coordinator_yield() | |
7474 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7475 ConcurrentMarkSweepThread::should_yield() && | |
7476 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7477 os::sleep(Thread::current(), 1, false); | |
7478 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7479 } | |
7480 | |
7481 ConcurrentMarkSweepThread::synchronize(true); | |
7482 _bitMap->lock()->lock_without_safepoint_check(); | |
7483 _collector->startTimer(); | |
7484 } | |
7485 | |
7486 void MarkFromRootsClosure::scanOopsInOop(HeapWord* ptr) { | |
7487 assert(_bitMap->isMarked(ptr), "expected bit to be set"); | |
7488 assert(_markStack->isEmpty(), | |
7489 "should drain stack to limit stack usage"); | |
7490 // convert ptr to an oop preparatory to scanning | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7491 oop obj = oop(ptr); |
0 | 7492 // Ignore mark word in verification below, since we |
7493 // may be running concurrent with mutators. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7494 assert(obj->is_oop(true), "should be an oop"); |
0 | 7495 assert(_finger <= ptr, "_finger runneth ahead"); |
7496 // advance the finger to right end of this object | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7497 _finger = ptr + obj->size(); |
0 | 7498 assert(_finger > ptr, "we just incremented it above"); |
7499 // On large heaps, it may take us some time to get through | |
7500 // the marking phase (especially if running iCMS). During | |
7501 // this time it's possible that a lot of mutations have | |
7502 // accumulated in the card table and the mod union table -- | |
7503 // these mutation records are redundant until we have | |
7504 // actually traced into the corresponding card. | |
7505 // Here, we check whether advancing the finger would make | |
7506 // us cross into a new card, and if so clear corresponding | |
7507 // cards in the MUT (preclean them in the card-table in the | |
7508 // future). | |
7509 | |
7510 DEBUG_ONLY(if (!_verifying) {) | |
7511 // The clean-on-enter optimization is disabled by default, | |
7512 // until we fix 6178663. | |
7513 if (CMSCleanOnEnter && (_finger > _threshold)) { | |
7514 // [_threshold, _finger) represents the interval | |
7515 // of cards to be cleared in MUT (or precleaned in card table). | |
7516 // The set of cards to be cleared is all those that overlap | |
7517 // with the interval [_threshold, _finger); note that | |
7518 // _threshold is always kept card-aligned but _finger isn't | |
7519 // always card-aligned. | |
7520 HeapWord* old_threshold = _threshold; | |
7521 assert(old_threshold == (HeapWord*)round_to( | |
7522 (intptr_t)old_threshold, CardTableModRefBS::card_size), | |
7523 "_threshold should always be card-aligned"); | |
7524 _threshold = (HeapWord*)round_to( | |
7525 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7526 MemRegion mr(old_threshold, _threshold); | |
7527 assert(!mr.is_empty(), "Control point invariant"); | |
7528 assert(_span.contains(mr), "Should clear within span"); | |
7529 _mut->clear_range(mr); | |
7530 } | |
7531 DEBUG_ONLY(}) | |
7532 // Note: the finger doesn't advance while we drain | |
7533 // the stack below. | |
7534 PushOrMarkClosure pushOrMarkClosure(_collector, | |
7535 _span, _bitMap, _markStack, | |
7536 _finger, this); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7537 bool res = _markStack->push(obj); |
0 | 7538 assert(res, "Empty non-zero size stack should have space for single push"); |
7539 while (!_markStack->isEmpty()) { | |
7540 oop new_oop = _markStack->pop(); | |
7541 // Skip verifying header mark word below because we are | |
7542 // running concurrent with mutators. | |
7543 assert(new_oop->is_oop(true), "Oops! expected to pop an oop"); | |
7544 // now scan this oop's oops | |
7545 new_oop->oop_iterate(&pushOrMarkClosure); | |
7546 do_yield_check(); | |
7547 } | |
7548 assert(_markStack->isEmpty(), "tautology, emphasizing post-condition"); | |
7549 } | |
7550 | |
7551 Par_MarkFromRootsClosure::Par_MarkFromRootsClosure(CMSConcMarkingTask* task, | |
7552 CMSCollector* collector, MemRegion span, | |
7553 CMSBitMap* bit_map, | |
7554 OopTaskQueue* work_queue, | |
7555 CMSMarkStack* overflow_stack, | |
7556 bool should_yield): | |
7557 _collector(collector), | |
7558 _whole_span(collector->_span), | |
7559 _span(span), | |
7560 _bit_map(bit_map), | |
7561 _mut(&collector->_modUnionTable), | |
7562 _work_queue(work_queue), | |
7563 _overflow_stack(overflow_stack), | |
7564 _yield(should_yield), | |
7565 _skip_bits(0), | |
7566 _task(task) | |
7567 { | |
7568 assert(_work_queue->size() == 0, "work_queue should be empty"); | |
7569 _finger = span.start(); | |
7570 _threshold = _finger; // XXX Defer clear-on-enter optimization for now | |
7571 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7572 } | |
7573 | |
7574 // Should revisit to see if this should be restructured for | |
7575 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7576 bool Par_MarkFromRootsClosure::do_bit(size_t offset) { |
0 | 7577 if (_skip_bits > 0) { |
7578 _skip_bits--; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7579 return true; |
0 | 7580 } |
7581 // convert offset into a HeapWord* | |
7582 HeapWord* addr = _bit_map->startWord() + offset; | |
7583 assert(_bit_map->endWord() && addr < _bit_map->endWord(), | |
7584 "address out of range"); | |
7585 assert(_bit_map->isMarked(addr), "tautology"); | |
7586 if (_bit_map->isMarked(addr+1)) { | |
7587 // this is an allocated object that might not yet be initialized | |
7588 assert(_skip_bits == 0, "tautology"); | |
7589 _skip_bits = 2; // skip next two marked bits ("Printezis-marks") | |
7590 oop p = oop(addr); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7591 if (p->klass_or_null() == NULL) { |
0 | 7592 // in the case of Clean-on-Enter optimization, redirty card |
7593 // and avoid clearing card by increasing the threshold. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7594 return true; |
0 | 7595 } |
7596 } | |
7597 scan_oops_in_oop(addr); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7598 return true; |
0 | 7599 } |
7600 | |
7601 void Par_MarkFromRootsClosure::scan_oops_in_oop(HeapWord* ptr) { | |
7602 assert(_bit_map->isMarked(ptr), "expected bit to be set"); | |
7603 // Should we assert that our work queue is empty or | |
7604 // below some drain limit? | |
7605 assert(_work_queue->size() == 0, | |
7606 "should drain stack to limit stack usage"); | |
7607 // convert ptr to an oop preparatory to scanning | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7608 oop obj = oop(ptr); |
0 | 7609 // Ignore mark word in verification below, since we |
7610 // may be running concurrent with mutators. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7611 assert(obj->is_oop(true), "should be an oop"); |
0 | 7612 assert(_finger <= ptr, "_finger runneth ahead"); |
7613 // advance the finger to right end of this object | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7614 _finger = ptr + obj->size(); |
0 | 7615 assert(_finger > ptr, "we just incremented it above"); |
7616 // On large heaps, it may take us some time to get through | |
7617 // the marking phase (especially if running iCMS). During | |
7618 // this time it's possible that a lot of mutations have | |
7619 // accumulated in the card table and the mod union table -- | |
7620 // these mutation records are redundant until we have | |
7621 // actually traced into the corresponding card. | |
7622 // Here, we check whether advancing the finger would make | |
7623 // us cross into a new card, and if so clear corresponding | |
7624 // cards in the MUT (preclean them in the card-table in the | |
7625 // future). | |
7626 | |
7627 // The clean-on-enter optimization is disabled by default, | |
7628 // until we fix 6178663. | |
7629 if (CMSCleanOnEnter && (_finger > _threshold)) { | |
7630 // [_threshold, _finger) represents the interval | |
7631 // of cards to be cleared in MUT (or precleaned in card table). | |
7632 // The set of cards to be cleared is all those that overlap | |
7633 // with the interval [_threshold, _finger); note that | |
7634 // _threshold is always kept card-aligned but _finger isn't | |
7635 // always card-aligned. | |
7636 HeapWord* old_threshold = _threshold; | |
7637 assert(old_threshold == (HeapWord*)round_to( | |
7638 (intptr_t)old_threshold, CardTableModRefBS::card_size), | |
7639 "_threshold should always be card-aligned"); | |
7640 _threshold = (HeapWord*)round_to( | |
7641 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7642 MemRegion mr(old_threshold, _threshold); | |
7643 assert(!mr.is_empty(), "Control point invariant"); | |
7644 assert(_span.contains(mr), "Should clear within span"); // _whole_span ?? | |
7645 _mut->clear_range(mr); | |
7646 } | |
7647 | |
7648 // Note: the local finger doesn't advance while we drain | |
7649 // the stack below, but the global finger sure can and will. | |
7650 HeapWord** gfa = _task->global_finger_addr(); | |
7651 Par_PushOrMarkClosure pushOrMarkClosure(_collector, | |
7652 _span, _bit_map, | |
7653 _work_queue, | |
7654 _overflow_stack, | |
7655 _finger, | |
7656 gfa, this); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7657 bool res = _work_queue->push(obj); // overflow could occur here |
0 | 7658 assert(res, "Will hold once we use workqueues"); |
7659 while (true) { | |
7660 oop new_oop; | |
7661 if (!_work_queue->pop_local(new_oop)) { | |
7662 // We emptied our work_queue; check if there's stuff that can | |
7663 // be gotten from the overflow stack. | |
7664 if (CMSConcMarkingTask::get_work_from_overflow_stack( | |
7665 _overflow_stack, _work_queue)) { | |
7666 do_yield_check(); | |
7667 continue; | |
7668 } else { // done | |
7669 break; | |
7670 } | |
7671 } | |
7672 // Skip verifying header mark word below because we are | |
7673 // running concurrent with mutators. | |
7674 assert(new_oop->is_oop(true), "Oops! expected to pop an oop"); | |
7675 // now scan this oop's oops | |
7676 new_oop->oop_iterate(&pushOrMarkClosure); | |
7677 do_yield_check(); | |
7678 } | |
7679 assert(_work_queue->size() == 0, "tautology, emphasizing post-condition"); | |
7680 } | |
7681 | |
7682 // Yield in response to a request from VM Thread or | |
7683 // from mutators. | |
7684 void Par_MarkFromRootsClosure::do_yield_work() { | |
7685 assert(_task != NULL, "sanity"); | |
7686 _task->yield(); | |
7687 } | |
7688 | |
7689 // A variant of the above used for verifying CMS marking work. | |
7690 MarkFromRootsVerifyClosure::MarkFromRootsVerifyClosure(CMSCollector* collector, | |
7691 MemRegion span, | |
7692 CMSBitMap* verification_bm, CMSBitMap* cms_bm, | |
7693 CMSMarkStack* mark_stack): | |
7694 _collector(collector), | |
7695 _span(span), | |
7696 _verification_bm(verification_bm), | |
7697 _cms_bm(cms_bm), | |
7698 _mark_stack(mark_stack), | |
7699 _pam_verify_closure(collector, span, verification_bm, cms_bm, | |
7700 mark_stack) | |
7701 { | |
7702 assert(_mark_stack->isEmpty(), "stack should be empty"); | |
7703 _finger = _verification_bm->startWord(); | |
7704 assert(_collector->_restart_addr == NULL, "Sanity check"); | |
7705 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7706 } | |
7707 | |
7708 void MarkFromRootsVerifyClosure::reset(HeapWord* addr) { | |
7709 assert(_mark_stack->isEmpty(), "would cause duplicates on stack"); | |
7710 assert(_span.contains(addr), "Out of bounds _finger?"); | |
7711 _finger = addr; | |
7712 } | |
7713 | |
7714 // Should revisit to see if this should be restructured for | |
7715 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7716 bool MarkFromRootsVerifyClosure::do_bit(size_t offset) { |
0 | 7717 // convert offset into a HeapWord* |
7718 HeapWord* addr = _verification_bm->startWord() + offset; | |
7719 assert(_verification_bm->endWord() && addr < _verification_bm->endWord(), | |
7720 "address out of range"); | |
7721 assert(_verification_bm->isMarked(addr), "tautology"); | |
7722 assert(_cms_bm->isMarked(addr), "tautology"); | |
7723 | |
7724 assert(_mark_stack->isEmpty(), | |
7725 "should drain stack to limit stack usage"); | |
7726 // convert addr to an oop preparatory to scanning | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7727 oop obj = oop(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7728 assert(obj->is_oop(), "should be an oop"); |
0 | 7729 assert(_finger <= addr, "_finger runneth ahead"); |
7730 // advance the finger to right end of this object | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7731 _finger = addr + obj->size(); |
0 | 7732 assert(_finger > addr, "we just incremented it above"); |
7733 // Note: the finger doesn't advance while we drain | |
7734 // the stack below. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7735 bool res = _mark_stack->push(obj); |
0 | 7736 assert(res, "Empty non-zero size stack should have space for single push"); |
7737 while (!_mark_stack->isEmpty()) { | |
7738 oop new_oop = _mark_stack->pop(); | |
7739 assert(new_oop->is_oop(), "Oops! expected to pop an oop"); | |
7740 // now scan this oop's oops | |
7741 new_oop->oop_iterate(&_pam_verify_closure); | |
7742 } | |
7743 assert(_mark_stack->isEmpty(), "tautology, emphasizing post-condition"); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7744 return true; |
0 | 7745 } |
7746 | |
7747 PushAndMarkVerifyClosure::PushAndMarkVerifyClosure( | |
7748 CMSCollector* collector, MemRegion span, | |
7749 CMSBitMap* verification_bm, CMSBitMap* cms_bm, | |
7750 CMSMarkStack* mark_stack): | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7751 MetadataAwareOopClosure(collector->ref_processor()), |
0 | 7752 _collector(collector), |
7753 _span(span), | |
7754 _verification_bm(verification_bm), | |
7755 _cms_bm(cms_bm), | |
7756 _mark_stack(mark_stack) | |
7757 { } | |
7758 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7759 void PushAndMarkVerifyClosure::do_oop(oop* p) { PushAndMarkVerifyClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7760 void PushAndMarkVerifyClosure::do_oop(narrowOop* p) { PushAndMarkVerifyClosure::do_oop_work(p); } |
0 | 7761 |
7762 // Upon stack overflow, we discard (part of) the stack, | |
7763 // remembering the least address amongst those discarded | |
7764 // in CMSCollector's _restart_address. | |
7765 void PushAndMarkVerifyClosure::handle_stack_overflow(HeapWord* lost) { | |
7766 // Remember the least grey address discarded | |
7767 HeapWord* ra = (HeapWord*)_mark_stack->least_value(lost); | |
7768 _collector->lower_restart_addr(ra); | |
7769 _mark_stack->reset(); // discard stack contents | |
7770 _mark_stack->expand(); // expand the stack if possible | |
7771 } | |
7772 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7773 void PushAndMarkVerifyClosure::do_oop(oop obj) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7774 assert(obj->is_oop_or_null(), "expected an oop or NULL"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7775 HeapWord* addr = (HeapWord*)obj; |
0 | 7776 if (_span.contains(addr) && !_verification_bm->isMarked(addr)) { |
7777 // Oop lies in _span and isn't yet grey or black | |
7778 _verification_bm->mark(addr); // now grey | |
7779 if (!_cms_bm->isMarked(addr)) { | |
7780 oop(addr)->print(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7781 gclog_or_tty->print_cr(" (" INTPTR_FORMAT " should have been marked)", |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7782 addr); |
0 | 7783 fatal("... aborting"); |
7784 } | |
7785 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7786 if (!_mark_stack->push(obj)) { // stack overflow |
0 | 7787 if (PrintCMSStatistics != 0) { |
7788 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7789 SIZE_FORMAT, _mark_stack->capacity()); | |
7790 } | |
7791 assert(_mark_stack->isFull(), "Else push should have succeeded"); | |
7792 handle_stack_overflow(addr); | |
7793 } | |
7794 // anything including and to the right of _finger | |
7795 // will be scanned as we iterate over the remainder of the | |
7796 // bit map | |
7797 } | |
7798 } | |
7799 | |
7800 PushOrMarkClosure::PushOrMarkClosure(CMSCollector* collector, | |
7801 MemRegion span, | |
7802 CMSBitMap* bitMap, CMSMarkStack* markStack, | |
7803 HeapWord* finger, MarkFromRootsClosure* parent) : | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7804 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7805 _collector(collector), |
0 | 7806 _span(span), |
7807 _bitMap(bitMap), | |
7808 _markStack(markStack), | |
7809 _finger(finger), | |
935 | 7810 _parent(parent) |
0 | 7811 { } |
7812 | |
7813 Par_PushOrMarkClosure::Par_PushOrMarkClosure(CMSCollector* collector, | |
7814 MemRegion span, | |
7815 CMSBitMap* bit_map, | |
7816 OopTaskQueue* work_queue, | |
7817 CMSMarkStack* overflow_stack, | |
7818 HeapWord* finger, | |
7819 HeapWord** global_finger_addr, | |
7820 Par_MarkFromRootsClosure* parent) : | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7821 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7822 _collector(collector), |
0 | 7823 _whole_span(collector->_span), |
7824 _span(span), | |
7825 _bit_map(bit_map), | |
7826 _work_queue(work_queue), | |
7827 _overflow_stack(overflow_stack), | |
7828 _finger(finger), | |
7829 _global_finger_addr(global_finger_addr), | |
935 | 7830 _parent(parent) |
0 | 7831 { } |
7832 | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7833 // Assumes thread-safe access by callers, who are |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7834 // responsible for mutual exclusion. |
0 | 7835 void CMSCollector::lower_restart_addr(HeapWord* low) { |
7836 assert(_span.contains(low), "Out of bounds addr"); | |
7837 if (_restart_addr == NULL) { | |
7838 _restart_addr = low; | |
7839 } else { | |
7840 _restart_addr = MIN2(_restart_addr, low); | |
7841 } | |
7842 } | |
7843 | |
7844 // Upon stack overflow, we discard (part of) the stack, | |
7845 // remembering the least address amongst those discarded | |
7846 // in CMSCollector's _restart_address. | |
7847 void PushOrMarkClosure::handle_stack_overflow(HeapWord* lost) { | |
7848 // Remember the least grey address discarded | |
7849 HeapWord* ra = (HeapWord*)_markStack->least_value(lost); | |
7850 _collector->lower_restart_addr(ra); | |
7851 _markStack->reset(); // discard stack contents | |
7852 _markStack->expand(); // expand the stack if possible | |
7853 } | |
7854 | |
7855 // Upon stack overflow, we discard (part of) the stack, | |
7856 // remembering the least address amongst those discarded | |
7857 // in CMSCollector's _restart_address. | |
7858 void Par_PushOrMarkClosure::handle_stack_overflow(HeapWord* lost) { | |
7859 // We need to do this under a mutex to prevent other | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7860 // workers from interfering with the work done below. |
0 | 7861 MutexLockerEx ml(_overflow_stack->par_lock(), |
7862 Mutex::_no_safepoint_check_flag); | |
7863 // Remember the least grey address discarded | |
7864 HeapWord* ra = (HeapWord*)_overflow_stack->least_value(lost); | |
7865 _collector->lower_restart_addr(ra); | |
7866 _overflow_stack->reset(); // discard stack contents | |
7867 _overflow_stack->expand(); // expand the stack if possible | |
7868 } | |
7869 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7870 void PushOrMarkClosure::do_oop(oop obj) { |
0 | 7871 // Ignore mark word because we are running concurrent with mutators. |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7872 assert(obj->is_oop_or_null(true), "expected an oop or NULL"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7873 HeapWord* addr = (HeapWord*)obj; |
0 | 7874 if (_span.contains(addr) && !_bitMap->isMarked(addr)) { |
7875 // Oop lies in _span and isn't yet grey or black | |
7876 _bitMap->mark(addr); // now grey | |
7877 if (addr < _finger) { | |
7878 // the bit map iteration has already either passed, or | |
7879 // sampled, this bit in the bit map; we'll need to | |
7880 // use the marking stack to scan this oop's oops. | |
7881 bool simulate_overflow = false; | |
7882 NOT_PRODUCT( | |
7883 if (CMSMarkStackOverflowALot && | |
7884 _collector->simulate_overflow()) { | |
7885 // simulate a stack overflow | |
7886 simulate_overflow = true; | |
7887 } | |
7888 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7889 if (simulate_overflow || !_markStack->push(obj)) { // stack overflow |
0 | 7890 if (PrintCMSStatistics != 0) { |
7891 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7892 SIZE_FORMAT, _markStack->capacity()); | |
7893 } | |
7894 assert(simulate_overflow || _markStack->isFull(), "Else push should have succeeded"); | |
7895 handle_stack_overflow(addr); | |
7896 } | |
7897 } | |
7898 // anything including and to the right of _finger | |
7899 // will be scanned as we iterate over the remainder of the | |
7900 // bit map | |
7901 do_yield_check(); | |
7902 } | |
7903 } | |
7904 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7905 void PushOrMarkClosure::do_oop(oop* p) { PushOrMarkClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7906 void PushOrMarkClosure::do_oop(narrowOop* p) { PushOrMarkClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7907 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7908 void Par_PushOrMarkClosure::do_oop(oop obj) { |
0 | 7909 // Ignore mark word because we are running concurrent with mutators. |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7910 assert(obj->is_oop_or_null(true), "expected an oop or NULL"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7911 HeapWord* addr = (HeapWord*)obj; |
0 | 7912 if (_whole_span.contains(addr) && !_bit_map->isMarked(addr)) { |
7913 // Oop lies in _span and isn't yet grey or black | |
7914 // We read the global_finger (volatile read) strictly after marking oop | |
7915 bool res = _bit_map->par_mark(addr); // now grey | |
7916 volatile HeapWord** gfa = (volatile HeapWord**)_global_finger_addr; | |
7917 // Should we push this marked oop on our stack? | |
7918 // -- if someone else marked it, nothing to do | |
7919 // -- if target oop is above global finger nothing to do | |
7920 // -- if target oop is in chunk and above local finger | |
7921 // then nothing to do | |
7922 // -- else push on work queue | |
7923 if ( !res // someone else marked it, they will deal with it | |
7924 || (addr >= *gfa) // will be scanned in a later task | |
7925 || (_span.contains(addr) && addr >= _finger)) { // later in this chunk | |
7926 return; | |
7927 } | |
7928 // the bit map iteration has already either passed, or | |
7929 // sampled, this bit in the bit map; we'll need to | |
7930 // use the marking stack to scan this oop's oops. | |
7931 bool simulate_overflow = false; | |
7932 NOT_PRODUCT( | |
7933 if (CMSMarkStackOverflowALot && | |
7934 _collector->simulate_overflow()) { | |
7935 // simulate a stack overflow | |
7936 simulate_overflow = true; | |
7937 } | |
7938 ) | |
7939 if (simulate_overflow || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7940 !(_work_queue->push(obj) || _overflow_stack->par_push(obj))) { |
0 | 7941 // stack overflow |
7942 if (PrintCMSStatistics != 0) { | |
7943 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7944 SIZE_FORMAT, _overflow_stack->capacity()); | |
7945 } | |
7946 // We cannot assert that the overflow stack is full because | |
7947 // it may have been emptied since. | |
7948 assert(simulate_overflow || | |
7949 _work_queue->size() == _work_queue->max_elems(), | |
7950 "Else push should have succeeded"); | |
7951 handle_stack_overflow(addr); | |
7952 } | |
7953 do_yield_check(); | |
7954 } | |
7955 } | |
7956 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7957 void Par_PushOrMarkClosure::do_oop(oop* p) { Par_PushOrMarkClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7958 void Par_PushOrMarkClosure::do_oop(narrowOop* p) { Par_PushOrMarkClosure::do_oop_work(p); } |
0 | 7959 |
7960 PushAndMarkClosure::PushAndMarkClosure(CMSCollector* collector, | |
7961 MemRegion span, | |
7962 ReferenceProcessor* rp, | |
7963 CMSBitMap* bit_map, | |
7964 CMSBitMap* mod_union_table, | |
7965 CMSMarkStack* mark_stack, | |
7966 bool concurrent_precleaning): | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7967 MetadataAwareOopClosure(rp), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7968 _collector(collector), |
0 | 7969 _span(span), |
7970 _bit_map(bit_map), | |
7971 _mod_union_table(mod_union_table), | |
7972 _mark_stack(mark_stack), | |
935 | 7973 _concurrent_precleaning(concurrent_precleaning) |
0 | 7974 { |
7975 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7976 } | |
7977 | |
7978 // Grey object rescan during pre-cleaning and second checkpoint phases -- | |
7979 // the non-parallel version (the parallel version appears further below.) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7980 void PushAndMarkClosure::do_oop(oop obj) { |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7981 // Ignore mark word verification. If during concurrent precleaning, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7982 // the object monitor may be locked. If during the checkpoint |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7983 // phases, the object may already have been reached by a different |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7984 // path and may be at the end of the global overflow list (so |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7985 // the mark word may be NULL). |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7986 assert(obj->is_oop_or_null(true /* ignore mark word */), |
0 | 7987 "expected an oop or NULL"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7988 HeapWord* addr = (HeapWord*)obj; |
0 | 7989 // Check if oop points into the CMS generation |
7990 // and is not marked | |
7991 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
7992 // a white object ... | |
7993 _bit_map->mark(addr); // ... now grey | |
7994 // push on the marking stack (grey set) | |
7995 bool simulate_overflow = false; | |
7996 NOT_PRODUCT( | |
7997 if (CMSMarkStackOverflowALot && | |
7998 _collector->simulate_overflow()) { | |
7999 // simulate a stack overflow | |
8000 simulate_overflow = true; | |
8001 } | |
8002 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8003 if (simulate_overflow || !_mark_stack->push(obj)) { |
0 | 8004 if (_concurrent_precleaning) { |
283
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8005 // During precleaning we can just dirty the appropriate card(s) |
0 | 8006 // in the mod union table, thus ensuring that the object remains |
283
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8007 // in the grey set and continue. In the case of object arrays |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8008 // we need to dirty all of the cards that the object spans, |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8009 // since the rescan of object arrays will be limited to the |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8010 // dirty cards. |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8011 // Note that no one can be intefering with us in this action |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8012 // of dirtying the mod union table, so no locking or atomics |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8013 // are required. |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8014 if (obj->is_objArray()) { |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8015 size_t sz = obj->size(); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8016 HeapWord* end_card_addr = (HeapWord*)round_to( |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8017 (intptr_t)(addr+sz), CardTableModRefBS::card_size); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8018 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8019 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8020 _mod_union_table->mark_range(redirty_range); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8021 } else { |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8022 _mod_union_table->mark(addr); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
8023 } |
0 | 8024 _collector->_ser_pmc_preclean_ovflw++; |
8025 } else { | |
8026 // During the remark phase, we need to remember this oop | |
8027 // in the overflow list. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8028 _collector->push_on_overflow_list(obj); |
0 | 8029 _collector->_ser_pmc_remark_ovflw++; |
8030 } | |
8031 } | |
8032 } | |
8033 } | |
8034 | |
8035 Par_PushAndMarkClosure::Par_PushAndMarkClosure(CMSCollector* collector, | |
8036 MemRegion span, | |
8037 ReferenceProcessor* rp, | |
8038 CMSBitMap* bit_map, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8039 OopTaskQueue* work_queue): |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
8040 MetadataAwareOopClosure(rp), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8041 _collector(collector), |
0 | 8042 _span(span), |
8043 _bit_map(bit_map), | |
935 | 8044 _work_queue(work_queue) |
0 | 8045 { |
8046 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
8047 } | |
8048 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8049 void PushAndMarkClosure::do_oop(oop* p) { PushAndMarkClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8050 void PushAndMarkClosure::do_oop(narrowOop* p) { PushAndMarkClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8051 |
0 | 8052 // Grey object rescan during second checkpoint phase -- |
8053 // the parallel version. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8054 void Par_PushAndMarkClosure::do_oop(oop obj) { |
0 | 8055 // In the assert below, we ignore the mark word because |
8056 // this oop may point to an already visited object that is | |
8057 // on the overflow stack (in which case the mark word has | |
8058 // been hijacked for chaining into the overflow stack -- | |
8059 // if this is the last object in the overflow stack then | |
8060 // its mark word will be NULL). Because this object may | |
8061 // have been subsequently popped off the global overflow | |
8062 // stack, and the mark word possibly restored to the prototypical | |
8063 // value, by the time we get to examined this failing assert in | |
8064 // the debugger, is_oop_or_null(false) may subsequently start | |
8065 // to hold. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8066 assert(obj->is_oop_or_null(true), |
0 | 8067 "expected an oop or NULL"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8068 HeapWord* addr = (HeapWord*)obj; |
0 | 8069 // Check if oop points into the CMS generation |
8070 // and is not marked | |
8071 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
8072 // a white object ... | |
8073 // If we manage to "claim" the object, by being the | |
8074 // first thread to mark it, then we push it on our | |
8075 // marking stack | |
8076 if (_bit_map->par_mark(addr)) { // ... now grey | |
8077 // push on work queue (grey set) | |
8078 bool simulate_overflow = false; | |
8079 NOT_PRODUCT( | |
8080 if (CMSMarkStackOverflowALot && | |
8081 _collector->par_simulate_overflow()) { | |
8082 // simulate a stack overflow | |
8083 simulate_overflow = true; | |
8084 } | |
8085 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8086 if (simulate_overflow || !_work_queue->push(obj)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8087 _collector->par_push_on_overflow_list(obj); |
0 | 8088 _collector->_par_pmc_remark_ovflw++; // imprecise OK: no need to CAS |
8089 } | |
8090 } // Else, some other thread got there first | |
8091 } | |
8092 } | |
8093 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8094 void Par_PushAndMarkClosure::do_oop(oop* p) { Par_PushAndMarkClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8095 void Par_PushAndMarkClosure::do_oop(narrowOop* p) { Par_PushAndMarkClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8096 |
0 | 8097 void CMSPrecleanRefsYieldClosure::do_yield_work() { |
8098 Mutex* bml = _collector->bitMapLock(); | |
8099 assert_lock_strong(bml); | |
8100 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
8101 "CMS thread should hold CMS token"); | |
8102 | |
8103 bml->unlock(); | |
8104 ConcurrentMarkSweepThread::desynchronize(true); | |
8105 | |
8106 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8107 | |
8108 _collector->stopTimer(); | |
8109 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
8110 if (PrintCMSStatistics != 0) { | |
8111 _collector->incrementYields(); | |
8112 } | |
8113 _collector->icms_wait(); | |
8114 | |
8115 // See the comment in coordinator_yield() | |
8116 for (unsigned i = 0; i < CMSYieldSleepCount && | |
8117 ConcurrentMarkSweepThread::should_yield() && | |
8118 !CMSCollector::foregroundGCIsActive(); ++i) { | |
8119 os::sleep(Thread::current(), 1, false); | |
8120 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8121 } | |
8122 | |
8123 ConcurrentMarkSweepThread::synchronize(true); | |
8124 bml->lock(); | |
8125 | |
8126 _collector->startTimer(); | |
8127 } | |
8128 | |
8129 bool CMSPrecleanRefsYieldClosure::should_return() { | |
8130 if (ConcurrentMarkSweepThread::should_yield()) { | |
8131 do_yield_work(); | |
8132 } | |
8133 return _collector->foregroundGCIsActive(); | |
8134 } | |
8135 | |
8136 void MarkFromDirtyCardsClosure::do_MemRegion(MemRegion mr) { | |
8137 assert(((size_t)mr.start())%CardTableModRefBS::card_size_in_words == 0, | |
8138 "mr should be aligned to start at a card boundary"); | |
8139 // We'd like to assert: | |
8140 // assert(mr.word_size()%CardTableModRefBS::card_size_in_words == 0, | |
8141 // "mr should be a range of cards"); | |
8142 // However, that would be too strong in one case -- the last | |
8143 // partition ends at _unallocated_block which, in general, can be | |
8144 // an arbitrary boundary, not necessarily card aligned. | |
8145 if (PrintCMSStatistics != 0) { | |
8146 _num_dirty_cards += | |
8147 mr.word_size()/CardTableModRefBS::card_size_in_words; | |
8148 } | |
8149 _space->object_iterate_mem(mr, &_scan_cl); | |
8150 } | |
8151 | |
8152 SweepClosure::SweepClosure(CMSCollector* collector, | |
8153 ConcurrentMarkSweepGeneration* g, | |
8154 CMSBitMap* bitMap, bool should_yield) : | |
8155 _collector(collector), | |
8156 _g(g), | |
8157 _sp(g->cmsSpace()), | |
8158 _limit(_sp->sweep_limit()), | |
8159 _freelistLock(_sp->freelistLock()), | |
8160 _bitMap(bitMap), | |
8161 _yield(should_yield), | |
8162 _inFreeRange(false), // No free range at beginning of sweep | |
8163 _freeRangeInFreeLists(false), // No free range at beginning of sweep | |
8164 _lastFreeRangeCoalesced(false), | |
8165 _freeFinger(g->used_region().start()) | |
8166 { | |
8167 NOT_PRODUCT( | |
8168 _numObjectsFreed = 0; | |
8169 _numWordsFreed = 0; | |
8170 _numObjectsLive = 0; | |
8171 _numWordsLive = 0; | |
8172 _numObjectsAlreadyFree = 0; | |
8173 _numWordsAlreadyFree = 0; | |
8174 _last_fc = NULL; | |
8175 | |
8176 _sp->initializeIndexedFreeListArrayReturnedBytes(); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8177 _sp->dictionary()->initialize_dict_returned_bytes(); |
0 | 8178 ) |
8179 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), | |
8180 "sweep _limit out of bounds"); | |
8181 if (CMSTraceSweeper) { | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8182 gclog_or_tty->print_cr("\n====================\nStarting new sweep with limit " PTR_FORMAT, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8183 _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8184 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8185 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8186 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8187 void SweepClosure::print_on(outputStream* st) const { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8188 tty->print_cr("_sp = [" PTR_FORMAT "," PTR_FORMAT ")", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8189 _sp->bottom(), _sp->end()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8190 tty->print_cr("_limit = " PTR_FORMAT, _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8191 tty->print_cr("_freeFinger = " PTR_FORMAT, _freeFinger); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8192 NOT_PRODUCT(tty->print_cr("_last_fc = " PTR_FORMAT, _last_fc);) |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8193 tty->print_cr("_inFreeRange = %d, _freeRangeInFreeLists = %d, _lastFreeRangeCoalesced = %d", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8194 _inFreeRange, _freeRangeInFreeLists, _lastFreeRangeCoalesced); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8195 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8196 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8197 #ifndef PRODUCT |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8198 // Assertion checking only: no useful work in product mode -- |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8199 // however, if any of the flags below become product flags, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8200 // you may need to review this code to see if it needs to be |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8201 // enabled in product mode. |
0 | 8202 SweepClosure::~SweepClosure() { |
8203 assert_lock_strong(_freelistLock); | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8204 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8205 "sweep _limit out of bounds"); |
0 | 8206 if (inFreeRange()) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8207 warning("inFreeRange() should have been reset; dumping state of SweepClosure"); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8208 print(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8209 ShouldNotReachHere(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8210 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8211 if (Verbose && PrintGC) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8212 gclog_or_tty->print("Collected "SIZE_FORMAT" objects, " SIZE_FORMAT " bytes", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8213 _numObjectsFreed, _numWordsFreed*sizeof(HeapWord)); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8214 gclog_or_tty->print_cr("\nLive "SIZE_FORMAT" objects, " |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8215 SIZE_FORMAT" bytes " |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8216 "Already free "SIZE_FORMAT" objects, "SIZE_FORMAT" bytes", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8217 _numObjectsLive, _numWordsLive*sizeof(HeapWord), |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8218 _numObjectsAlreadyFree, _numWordsAlreadyFree*sizeof(HeapWord)); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8219 size_t totalBytes = (_numWordsFreed + _numWordsLive + _numWordsAlreadyFree) |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8220 * sizeof(HeapWord); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8221 gclog_or_tty->print_cr("Total sweep: "SIZE_FORMAT" bytes", totalBytes); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8222 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8223 if (PrintCMSStatistics && CMSVerifyReturnedBytes) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8224 size_t indexListReturnedBytes = _sp->sumIndexedFreeListArrayReturnedBytes(); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8225 size_t dict_returned_bytes = _sp->dictionary()->sum_dict_returned_bytes(); |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8226 size_t returned_bytes = indexListReturnedBytes + dict_returned_bytes; |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8227 gclog_or_tty->print("Returned "SIZE_FORMAT" bytes", returned_bytes); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8228 gclog_or_tty->print(" Indexed List Returned "SIZE_FORMAT" bytes", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8229 indexListReturnedBytes); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8230 gclog_or_tty->print_cr(" Dictionary Returned "SIZE_FORMAT" bytes", |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8231 dict_returned_bytes); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8232 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8233 } |
0 | 8234 if (CMSTraceSweeper) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8235 gclog_or_tty->print_cr("end of sweep with _limit = " PTR_FORMAT "\n================", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8236 _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8237 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8238 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8239 #endif // PRODUCT |
0 | 8240 |
8241 void SweepClosure::initialize_free_range(HeapWord* freeFinger, | |
8242 bool freeRangeInFreeLists) { | |
8243 if (CMSTraceSweeper) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8244 gclog_or_tty->print("---- Start free range at 0x%x with free block (%d)\n", |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8245 freeFinger, freeRangeInFreeLists); |
0 | 8246 } |
8247 assert(!inFreeRange(), "Trampling existing free range"); | |
8248 set_inFreeRange(true); | |
8249 set_lastFreeRangeCoalesced(false); | |
8250 | |
8251 set_freeFinger(freeFinger); | |
8252 set_freeRangeInFreeLists(freeRangeInFreeLists); | |
8253 if (CMSTestInFreeList) { | |
8254 if (freeRangeInFreeLists) { | |
8255 FreeChunk* fc = (FreeChunk*) freeFinger; | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8256 assert(fc->is_free(), "A chunk on the free list should be free."); |
0 | 8257 assert(fc->size() > 0, "Free range should have a size"); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8258 assert(_sp->verify_chunk_in_free_list(fc), "Chunk is not in free lists"); |
0 | 8259 } |
8260 } | |
8261 } | |
8262 | |
8263 // Note that the sweeper runs concurrently with mutators. Thus, | |
8264 // it is possible for direct allocation in this generation to happen | |
8265 // in the middle of the sweep. Note that the sweeper also coalesces | |
8266 // contiguous free blocks. Thus, unless the sweeper and the allocator | |
8267 // synchronize appropriately freshly allocated blocks may get swept up. | |
8268 // This is accomplished by the sweeper locking the free lists while | |
8269 // it is sweeping. Thus blocks that are determined to be free are | |
8270 // indeed free. There is however one additional complication: | |
8271 // blocks that have been allocated since the final checkpoint and | |
8272 // mark, will not have been marked and so would be treated as | |
8273 // unreachable and swept up. To prevent this, the allocator marks | |
8274 // the bit map when allocating during the sweep phase. This leads, | |
8275 // however, to a further complication -- objects may have been allocated | |
8276 // but not yet initialized -- in the sense that the header isn't yet | |
8277 // installed. The sweeper can not then determine the size of the block | |
8278 // in order to skip over it. To deal with this case, we use a technique | |
8279 // (due to Printezis) to encode such uninitialized block sizes in the | |
8280 // bit map. Since the bit map uses a bit per every HeapWord, but the | |
8281 // CMS generation has a minimum object size of 3 HeapWords, it follows | |
8282 // that "normal marks" won't be adjacent in the bit map (there will | |
8283 // always be at least two 0 bits between successive 1 bits). We make use | |
8284 // of these "unused" bits to represent uninitialized blocks -- the bit | |
8285 // corresponding to the start of the uninitialized object and the next | |
8286 // bit are both set. Finally, a 1 bit marks the end of the object that | |
8287 // started with the two consecutive 1 bits to indicate its potentially | |
8288 // uninitialized state. | |
8289 | |
8290 size_t SweepClosure::do_blk_careful(HeapWord* addr) { | |
8291 FreeChunk* fc = (FreeChunk*)addr; | |
8292 size_t res; | |
8293 | |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8294 // Check if we are done sweeping. Below we check "addr >= _limit" rather |
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8295 // than "addr == _limit" because although _limit was a block boundary when |
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8296 // we started the sweep, it may no longer be one because heap expansion |
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8297 // may have caused us to coalesce the block ending at the address _limit |
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8298 // with a newly expanded chunk (this happens when _limit was set to the |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8299 // previous _end of the space), so we may have stepped past _limit: |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8300 // see the following Zeno-like trail of CRs 6977970, 7008136, 7042740. |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8301 if (addr >= _limit) { // we have swept up to or past the limit: finish up |
0 | 8302 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
8303 "sweep _limit out of bounds"); | |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8304 assert(addr < _sp->end(), "addr out of bounds"); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8305 // Flush any free range we might be holding as a single |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8306 // coalesced chunk to the appropriate free list. |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8307 if (inFreeRange()) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8308 assert(freeFinger() >= _sp->bottom() && freeFinger() < _limit, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8309 err_msg("freeFinger() " PTR_FORMAT" is out-of-bounds", freeFinger())); |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8310 flush_cur_free_chunk(freeFinger(), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8311 pointer_delta(addr, freeFinger())); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8312 if (CMSTraceSweeper) { |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8313 gclog_or_tty->print("Sweep: last chunk: "); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8314 gclog_or_tty->print("put_free_blk 0x%x ("SIZE_FORMAT") " |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8315 "[coalesced:"SIZE_FORMAT"]\n", |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8316 freeFinger(), pointer_delta(addr, freeFinger()), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8317 lastFreeRangeCoalesced()); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8318 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8319 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8320 |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8321 // help the iterator loop finish |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8322 return pointer_delta(_sp->end(), addr); |
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8323 } |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8324 |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8325 assert(addr < _limit, "sweep invariant"); |
0 | 8326 // check if we should yield |
8327 do_yield_check(addr); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8328 if (fc->is_free()) { |
0 | 8329 // Chunk that is already free |
8330 res = fc->size(); | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8331 do_already_free_chunk(fc); |
0 | 8332 debug_only(_sp->verifyFreeLists()); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8333 // If we flush the chunk at hand in lookahead_and_flush() |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8334 // and it's coalesced with a preceding chunk, then the |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8335 // process of "mangling" the payload of the coalesced block |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8336 // will cause erasure of the size information from the |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8337 // (erstwhile) header of all the coalesced blocks but the |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8338 // first, so the first disjunct in the assert will not hold |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8339 // in that specific case (in which case the second disjunct |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8340 // will hold). |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8341 assert(res == fc->size() || ((HeapWord*)fc) + res >= _limit, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8342 "Otherwise the size info doesn't change at this step"); |
0 | 8343 NOT_PRODUCT( |
8344 _numObjectsAlreadyFree++; | |
8345 _numWordsAlreadyFree += res; | |
8346 ) | |
8347 NOT_PRODUCT(_last_fc = fc;) | |
8348 } else if (!_bitMap->isMarked(addr)) { | |
8349 // Chunk is fresh garbage | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8350 res = do_garbage_chunk(fc); |
0 | 8351 debug_only(_sp->verifyFreeLists()); |
8352 NOT_PRODUCT( | |
8353 _numObjectsFreed++; | |
8354 _numWordsFreed += res; | |
8355 ) | |
8356 } else { | |
8357 // Chunk that is alive. | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8358 res = do_live_chunk(fc); |
0 | 8359 debug_only(_sp->verifyFreeLists()); |
8360 NOT_PRODUCT( | |
8361 _numObjectsLive++; | |
8362 _numWordsLive += res; | |
8363 ) | |
8364 } | |
8365 return res; | |
8366 } | |
8367 | |
8368 // For the smart allocation, record following | |
8369 // split deaths - a free chunk is removed from its free list because | |
8370 // it is being split into two or more chunks. | |
8371 // split birth - a free chunk is being added to its free list because | |
8372 // a larger free chunk has been split and resulted in this free chunk. | |
8373 // coal death - a free chunk is being removed from its free list because | |
8374 // it is being coalesced into a large free chunk. | |
8375 // coal birth - a free chunk is being added to its free list because | |
8376 // it was created when two or more free chunks where coalesced into | |
8377 // this free chunk. | |
8378 // | |
8379 // These statistics are used to determine the desired number of free | |
8380 // chunks of a given size. The desired number is chosen to be relative | |
8381 // to the end of a CMS sweep. The desired number at the end of a sweep | |
8382 // is the | |
8383 // count-at-end-of-previous-sweep (an amount that was enough) | |
8384 // - count-at-beginning-of-current-sweep (the excess) | |
8385 // + split-births (gains in this size during interval) | |
8386 // - split-deaths (demands on this size during interval) | |
8387 // where the interval is from the end of one sweep to the end of the | |
8388 // next. | |
8389 // | |
8390 // When sweeping the sweeper maintains an accumulated chunk which is | |
8391 // the chunk that is made up of chunks that have been coalesced. That | |
8392 // will be termed the left-hand chunk. A new chunk of garbage that | |
8393 // is being considered for coalescing will be referred to as the | |
8394 // right-hand chunk. | |
8395 // | |
8396 // When making a decision on whether to coalesce a right-hand chunk with | |
8397 // the current left-hand chunk, the current count vs. the desired count | |
8398 // of the left-hand chunk is considered. Also if the right-hand chunk | |
8399 // is near the large chunk at the end of the heap (see | |
8400 // ConcurrentMarkSweepGeneration::isNearLargestChunk()), then the | |
8401 // left-hand chunk is coalesced. | |
8402 // | |
8403 // When making a decision about whether to split a chunk, the desired count | |
8404 // vs. the current count of the candidate to be split is also considered. | |
8405 // If the candidate is underpopulated (currently fewer chunks than desired) | |
8406 // a chunk of an overpopulated (currently more chunks than desired) size may | |
8407 // be chosen. The "hint" associated with a free list, if non-null, points | |
8408 // to a free list which may be overpopulated. | |
8409 // | |
8410 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8411 void SweepClosure::do_already_free_chunk(FreeChunk* fc) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8412 const size_t size = fc->size(); |
0 | 8413 // Chunks that cannot be coalesced are not in the |
8414 // free lists. | |
8415 if (CMSTestInFreeList && !fc->cantCoalesce()) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8416 assert(_sp->verify_chunk_in_free_list(fc), |
0 | 8417 "free chunk should be in free lists"); |
8418 } | |
8419 // a chunk that is already free, should not have been | |
8420 // marked in the bit map | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8421 HeapWord* const addr = (HeapWord*) fc; |
0 | 8422 assert(!_bitMap->isMarked(addr), "free chunk should be unmarked"); |
8423 // Verify that the bit map has no bits marked between | |
8424 // addr and purported end of this block. | |
8425 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8426 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8427 // Some chunks cannot be coalesced under any circumstances. |
0 | 8428 // See the definition of cantCoalesce(). |
8429 if (!fc->cantCoalesce()) { | |
8430 // This chunk can potentially be coalesced. | |
8431 if (_sp->adaptive_freelists()) { | |
8432 // All the work is done in | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8433 do_post_free_or_garbage_chunk(fc, size); |
0 | 8434 } else { // Not adaptive free lists |
8435 // this is a free chunk that can potentially be coalesced by the sweeper; | |
8436 if (!inFreeRange()) { | |
8437 // if the next chunk is a free block that can't be coalesced | |
8438 // it doesn't make sense to remove this chunk from the free lists | |
8439 FreeChunk* nextChunk = (FreeChunk*)(addr + size); | |
2136
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8440 assert((HeapWord*)nextChunk <= _sp->end(), "Chunk size out of bounds?"); |
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8441 if ((HeapWord*)nextChunk < _sp->end() && // There is another free chunk to the right ... |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8442 nextChunk->is_free() && // ... which is free... |
2136
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8443 nextChunk->cantCoalesce()) { // ... but can't be coalesced |
0 | 8444 // nothing to do |
8445 } else { | |
8446 // Potentially the start of a new free range: | |
8447 // Don't eagerly remove it from the free lists. | |
8448 // No need to remove it if it will just be put | |
8449 // back again. (Also from a pragmatic point of view | |
8450 // if it is a free block in a region that is beyond | |
8451 // any allocated blocks, an assertion will fail) | |
8452 // Remember the start of a free run. | |
8453 initialize_free_range(addr, true); | |
8454 // end - can coalesce with next chunk | |
8455 } | |
8456 } else { | |
8457 // the midst of a free range, we are coalescing | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8458 print_free_block_coalesced(fc); |
0 | 8459 if (CMSTraceSweeper) { |
8460 gclog_or_tty->print(" -- pick up free block 0x%x (%d)\n", fc, size); | |
8461 } | |
8462 // remove it from the free lists | |
8463 _sp->removeFreeChunkFromFreeLists(fc); | |
8464 set_lastFreeRangeCoalesced(true); | |
8465 // If the chunk is being coalesced and the current free range is | |
8466 // in the free lists, remove the current free range so that it | |
8467 // will be returned to the free lists in its entirety - all | |
8468 // the coalesced pieces included. | |
8469 if (freeRangeInFreeLists()) { | |
8470 FreeChunk* ffc = (FreeChunk*) freeFinger(); | |
8471 assert(ffc->size() == pointer_delta(addr, freeFinger()), | |
8472 "Size of free range is inconsistent with chunk size."); | |
8473 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8474 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8475 "free range is not in free lists"); |
8476 } | |
8477 _sp->removeFreeChunkFromFreeLists(ffc); | |
8478 set_freeRangeInFreeLists(false); | |
8479 } | |
8480 } | |
8481 } | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8482 // Note that if the chunk is not coalescable (the else arm |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8483 // below), we unconditionally flush, without needing to do |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8484 // a "lookahead," as we do below. |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8485 if (inFreeRange()) lookahead_and_flush(fc, size); |
0 | 8486 } else { |
8487 // Code path common to both original and adaptive free lists. | |
8488 | |
8489 // cant coalesce with previous block; this should be treated | |
8490 // as the end of a free run if any | |
8491 if (inFreeRange()) { | |
8492 // we kicked some butt; time to pick up the garbage | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8493 assert(freeFinger() < addr, "freeFinger points too high"); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8494 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
0 | 8495 } |
8496 // else, nothing to do, just continue | |
8497 } | |
8498 } | |
8499 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8500 size_t SweepClosure::do_garbage_chunk(FreeChunk* fc) { |
0 | 8501 // This is a chunk of garbage. It is not in any free list. |
8502 // Add it to a free list or let it possibly be coalesced into | |
8503 // a larger chunk. | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8504 HeapWord* const addr = (HeapWord*) fc; |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8505 const size_t size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); |
0 | 8506 |
8507 if (_sp->adaptive_freelists()) { | |
8508 // Verify that the bit map has no bits marked between | |
8509 // addr and purported end of just dead object. | |
8510 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8511 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8512 do_post_free_or_garbage_chunk(fc, size); |
0 | 8513 } else { |
8514 if (!inFreeRange()) { | |
8515 // start of a new free range | |
8516 assert(size > 0, "A free range should have a size"); | |
8517 initialize_free_range(addr, false); | |
8518 } else { | |
8519 // this will be swept up when we hit the end of the | |
8520 // free range | |
8521 if (CMSTraceSweeper) { | |
8522 gclog_or_tty->print(" -- pick up garbage 0x%x (%d) \n", fc, size); | |
8523 } | |
8524 // If the chunk is being coalesced and the current free range is | |
8525 // in the free lists, remove the current free range so that it | |
8526 // will be returned to the free lists in its entirety - all | |
8527 // the coalesced pieces included. | |
8528 if (freeRangeInFreeLists()) { | |
8529 FreeChunk* ffc = (FreeChunk*)freeFinger(); | |
8530 assert(ffc->size() == pointer_delta(addr, freeFinger()), | |
8531 "Size of free range is inconsistent with chunk size."); | |
8532 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8533 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8534 "free range is not in free lists"); |
8535 } | |
8536 _sp->removeFreeChunkFromFreeLists(ffc); | |
8537 set_freeRangeInFreeLists(false); | |
8538 } | |
8539 set_lastFreeRangeCoalesced(true); | |
8540 } | |
8541 // this will be swept up when we hit the end of the free range | |
8542 | |
8543 // Verify that the bit map has no bits marked between | |
8544 // addr and purported end of just dead object. | |
8545 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8546 } | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8547 assert(_limit >= addr + size, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8548 "A freshly garbage chunk can't possibly straddle over _limit"); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8549 if (inFreeRange()) lookahead_and_flush(fc, size); |
0 | 8550 return size; |
8551 } | |
8552 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8553 size_t SweepClosure::do_live_chunk(FreeChunk* fc) { |
0 | 8554 HeapWord* addr = (HeapWord*) fc; |
8555 // The sweeper has just found a live object. Return any accumulated | |
8556 // left hand chunk to the free lists. | |
8557 if (inFreeRange()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8558 assert(freeFinger() < addr, "freeFinger points too high"); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8559 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8560 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8561 |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8562 // This object is live: we'd normally expect this to be |
0 | 8563 // an oop, and like to assert the following: |
8564 // assert(oop(addr)->is_oop(), "live block should be an oop"); | |
8565 // However, as we commented above, this may be an object whose | |
8566 // header hasn't yet been initialized. | |
8567 size_t size; | |
8568 assert(_bitMap->isMarked(addr), "Tautology for this control point"); | |
8569 if (_bitMap->isMarked(addr + 1)) { | |
8570 // Determine the size from the bit map, rather than trying to | |
8571 // compute it from the object header. | |
8572 HeapWord* nextOneAddr = _bitMap->getNextMarkedWordAddress(addr + 2); | |
8573 size = pointer_delta(nextOneAddr + 1, addr); | |
8574 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
8575 "alignment problem"); | |
8576 | |
9152 | 8577 #ifdef ASSERT |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8578 if (oop(addr)->klass_or_null() != NULL) { |
0 | 8579 // Ignore mark word because we are running concurrent with mutators |
8580 assert(oop(addr)->is_oop(true), "live block should be an oop"); | |
8581 assert(size == | |
8582 CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()), | |
8583 "P-mark and computed size do not agree"); | |
8584 } | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8585 #endif |
0 | 8586 |
8587 } else { | |
8588 // This should be an initialized object that's alive. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8589 assert(oop(addr)->klass_or_null() != NULL, |
0 | 8590 "Should be an initialized object"); |
8591 // Ignore mark word because we are running concurrent with mutators | |
8592 assert(oop(addr)->is_oop(true), "live block should be an oop"); | |
8593 // Verify that the bit map has no bits marked between | |
8594 // addr and purported end of this block. | |
8595 size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); | |
8596 assert(size >= 3, "Necessary for Printezis marks to work"); | |
8597 assert(!_bitMap->isMarked(addr+1), "Tautology for this control point"); | |
8598 DEBUG_ONLY(_bitMap->verifyNoOneBitsInRange(addr+2, addr+size);) | |
8599 } | |
8600 return size; | |
8601 } | |
8602 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8603 void SweepClosure::do_post_free_or_garbage_chunk(FreeChunk* fc, |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8604 size_t chunkSize) { |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8605 // do_post_free_or_garbage_chunk() should only be called in the case |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8606 // of the adaptive free list allocator. |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8607 const bool fcInFreeLists = fc->is_free(); |
0 | 8608 assert(_sp->adaptive_freelists(), "Should only be used in this case."); |
8609 assert((HeapWord*)fc <= _limit, "sweep invariant"); | |
8610 if (CMSTestInFreeList && fcInFreeLists) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8611 assert(_sp->verify_chunk_in_free_list(fc), "free chunk is not in free lists"); |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8612 } |
0 | 8613 |
8614 if (CMSTraceSweeper) { | |
8615 gclog_or_tty->print_cr(" -- pick up another chunk at 0x%x (%d)", fc, chunkSize); | |
8616 } | |
8617 | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8618 HeapWord* const fc_addr = (HeapWord*) fc; |
0 | 8619 |
8620 bool coalesce; | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8621 const size_t left = pointer_delta(fc_addr, freeFinger()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8622 const size_t right = chunkSize; |
0 | 8623 switch (FLSCoalescePolicy) { |
8624 // numeric value forms a coalition aggressiveness metric | |
8625 case 0: { // never coalesce | |
8626 coalesce = false; | |
8627 break; | |
8628 } | |
8629 case 1: { // coalesce if left & right chunks on overpopulated lists | |
8630 coalesce = _sp->coalOverPopulated(left) && | |
8631 _sp->coalOverPopulated(right); | |
8632 break; | |
8633 } | |
8634 case 2: { // coalesce if left chunk on overpopulated list (default) | |
8635 coalesce = _sp->coalOverPopulated(left); | |
8636 break; | |
8637 } | |
8638 case 3: { // coalesce if left OR right chunk on overpopulated list | |
8639 coalesce = _sp->coalOverPopulated(left) || | |
8640 _sp->coalOverPopulated(right); | |
8641 break; | |
8642 } | |
8643 case 4: { // always coalesce | |
8644 coalesce = true; | |
8645 break; | |
8646 } | |
8647 default: | |
8648 ShouldNotReachHere(); | |
8649 } | |
8650 | |
8651 // Should the current free range be coalesced? | |
8652 // If the chunk is in a free range and either we decided to coalesce above | |
8653 // or the chunk is near the large block at the end of the heap | |
8654 // (isNearLargestChunk() returns true), then coalesce this chunk. | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8655 const bool doCoalesce = inFreeRange() |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8656 && (coalesce || _g->isNearLargestChunk(fc_addr)); |
0 | 8657 if (doCoalesce) { |
8658 // Coalesce the current free range on the left with the new | |
8659 // chunk on the right. If either is on a free list, | |
8660 // it must be removed from the list and stashed in the closure. | |
8661 if (freeRangeInFreeLists()) { | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8662 FreeChunk* const ffc = (FreeChunk*)freeFinger(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8663 assert(ffc->size() == pointer_delta(fc_addr, freeFinger()), |
0 | 8664 "Size of free range is inconsistent with chunk size."); |
8665 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8666 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8667 "Chunk is not in free lists"); |
8668 } | |
8669 _sp->coalDeath(ffc->size()); | |
8670 _sp->removeFreeChunkFromFreeLists(ffc); | |
8671 set_freeRangeInFreeLists(false); | |
8672 } | |
8673 if (fcInFreeLists) { | |
8674 _sp->coalDeath(chunkSize); | |
8675 assert(fc->size() == chunkSize, | |
8676 "The chunk has the wrong size or is not in the free lists"); | |
8677 _sp->removeFreeChunkFromFreeLists(fc); | |
8678 } | |
8679 set_lastFreeRangeCoalesced(true); | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8680 print_free_block_coalesced(fc); |
0 | 8681 } else { // not in a free range and/or should not coalesce |
8682 // Return the current free range and start a new one. | |
8683 if (inFreeRange()) { | |
8684 // In a free range but cannot coalesce with the right hand chunk. | |
8685 // Put the current free range into the free lists. | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8686 flush_cur_free_chunk(freeFinger(), |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8687 pointer_delta(fc_addr, freeFinger())); |
0 | 8688 } |
8689 // Set up for new free range. Pass along whether the right hand | |
8690 // chunk is in the free lists. | |
8691 initialize_free_range((HeapWord*)fc, fcInFreeLists); | |
8692 } | |
8693 } | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8694 |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8695 // Lookahead flush: |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8696 // If we are tracking a free range, and this is the last chunk that |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8697 // we'll look at because its end crosses past _limit, we'll preemptively |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8698 // flush it along with any free range we may be holding on to. Note that |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8699 // this can be the case only for an already free or freshly garbage |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8700 // chunk. If this block is an object, it can never straddle |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8701 // over _limit. The "straddling" occurs when _limit is set at |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8702 // the previous end of the space when this cycle started, and |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8703 // a subsequent heap expansion caused the previously co-terminal |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8704 // free block to be coalesced with the newly expanded portion, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8705 // thus rendering _limit a non-block-boundary making it dangerous |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8706 // for the sweeper to step over and examine. |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8707 void SweepClosure::lookahead_and_flush(FreeChunk* fc, size_t chunk_size) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8708 assert(inFreeRange(), "Should only be called if currently in a free range."); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8709 HeapWord* const eob = ((HeapWord*)fc) + chunk_size; |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8710 assert(_sp->used_region().contains(eob - 1), |
12112
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
8711 err_msg("eob = " PTR_FORMAT " eob-1 = " PTR_FORMAT " _limit = " PTR_FORMAT |
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
8712 " out of bounds wrt _sp = [" PTR_FORMAT "," PTR_FORMAT ")" |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8713 " when examining fc = " PTR_FORMAT "(" SIZE_FORMAT ")", |
12112
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
8714 eob, eob-1, _limit, _sp->bottom(), _sp->end(), fc, chunk_size)); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8715 if (eob >= _limit) { |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8716 assert(eob == _limit || fc->is_free(), "Only a free chunk should allow us to cross over the limit"); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8717 if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8718 gclog_or_tty->print_cr("_limit " PTR_FORMAT " reached or crossed by block " |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8719 "[" PTR_FORMAT "," PTR_FORMAT ") in space " |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8720 "[" PTR_FORMAT "," PTR_FORMAT ")", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8721 _limit, fc, eob, _sp->bottom(), _sp->end()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8722 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8723 // Return the storage we are tracking back into the free lists. |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8724 if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8725 gclog_or_tty->print_cr("Flushing ... "); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8726 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8727 assert(freeFinger() < eob, "Error"); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8728 flush_cur_free_chunk( freeFinger(), pointer_delta(eob, freeFinger())); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8729 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8730 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8731 |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8732 void SweepClosure::flush_cur_free_chunk(HeapWord* chunk, size_t size) { |
0 | 8733 assert(inFreeRange(), "Should only be called if currently in a free range."); |
8734 assert(size > 0, | |
8735 "A zero sized chunk cannot be added to the free lists."); | |
8736 if (!freeRangeInFreeLists()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8737 if (CMSTestInFreeList) { |
0 | 8738 FreeChunk* fc = (FreeChunk*) chunk; |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8739 fc->set_size(size); |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8740 assert(!_sp->verify_chunk_in_free_list(fc), |
0 | 8741 "chunk should not be in free lists yet"); |
8742 } | |
8743 if (CMSTraceSweeper) { | |
8744 gclog_or_tty->print_cr(" -- add free block 0x%x (%d) to free lists", | |
8745 chunk, size); | |
8746 } | |
8747 // A new free range is going to be starting. The current | |
8748 // free range has not been added to the free lists yet or | |
8749 // was removed so add it back. | |
8750 // If the current free range was coalesced, then the death | |
8751 // of the free range was recorded. Record a birth now. | |
8752 if (lastFreeRangeCoalesced()) { | |
8753 _sp->coalBirth(size); | |
8754 } | |
8755 _sp->addChunkAndRepairOffsetTable(chunk, size, | |
8756 lastFreeRangeCoalesced()); | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8757 } else if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8758 gclog_or_tty->print_cr("Already in free list: nothing to flush"); |
0 | 8759 } |
8760 set_inFreeRange(false); | |
8761 set_freeRangeInFreeLists(false); | |
8762 } | |
8763 | |
8764 // We take a break if we've been at this for a while, | |
8765 // so as to avoid monopolizing the locks involved. | |
8766 void SweepClosure::do_yield_work(HeapWord* addr) { | |
8767 // Return current free chunk being used for coalescing (if any) | |
8768 // to the appropriate freelist. After yielding, the next | |
8769 // free block encountered will start a coalescing range of | |
8770 // free blocks. If the next free block is adjacent to the | |
8771 // chunk just flushed, they will need to wait for the next | |
8772 // sweep to be coalesced. | |
8773 if (inFreeRange()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8774 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
0 | 8775 } |
8776 | |
8777 // First give up the locks, then yield, then re-lock. | |
8778 // We should probably use a constructor/destructor idiom to | |
8779 // do this unlock/lock or modify the MutexUnlocker class to | |
8780 // serve our purpose. XXX | |
8781 assert_lock_strong(_bitMap->lock()); | |
8782 assert_lock_strong(_freelistLock); | |
8783 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
8784 "CMS thread should hold CMS token"); | |
8785 _bitMap->lock()->unlock(); | |
8786 _freelistLock->unlock(); | |
8787 ConcurrentMarkSweepThread::desynchronize(true); | |
8788 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8789 _collector->stopTimer(); | |
8790 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
8791 if (PrintCMSStatistics != 0) { | |
8792 _collector->incrementYields(); | |
8793 } | |
8794 _collector->icms_wait(); | |
8795 | |
8796 // See the comment in coordinator_yield() | |
8797 for (unsigned i = 0; i < CMSYieldSleepCount && | |
8798 ConcurrentMarkSweepThread::should_yield() && | |
8799 !CMSCollector::foregroundGCIsActive(); ++i) { | |
8800 os::sleep(Thread::current(), 1, false); | |
8801 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8802 } | |
8803 | |
8804 ConcurrentMarkSweepThread::synchronize(true); | |
8805 _freelistLock->lock(); | |
8806 _bitMap->lock()->lock_without_safepoint_check(); | |
8807 _collector->startTimer(); | |
8808 } | |
8809 | |
8810 #ifndef PRODUCT | |
8811 // This is actually very useful in a product build if it can | |
8812 // be called from the debugger. Compile it into the product | |
8813 // as needed. | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8814 bool debug_verify_chunk_in_free_list(FreeChunk* fc) { |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8815 return debug_cms_space->verify_chunk_in_free_list(fc); |
0 | 8816 } |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8817 #endif |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8818 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8819 void SweepClosure::print_free_block_coalesced(FreeChunk* fc) const { |
0 | 8820 if (CMSTraceSweeper) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8821 gclog_or_tty->print_cr("Sweep:coal_free_blk " PTR_FORMAT " (" SIZE_FORMAT ")", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8822 fc, fc->size()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8823 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8824 } |
0 | 8825 |
8826 // CMSIsAliveClosure | |
8827 bool CMSIsAliveClosure::do_object_b(oop obj) { | |
8828 HeapWord* addr = (HeapWord*)obj; | |
8829 return addr != NULL && | |
8830 (!_span.contains(addr) || _bit_map->isMarked(addr)); | |
8831 } | |
8832 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8833 |
935 | 8834 CMSKeepAliveClosure::CMSKeepAliveClosure( CMSCollector* collector, |
8835 MemRegion span, | |
8836 CMSBitMap* bit_map, CMSMarkStack* mark_stack, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8837 bool cpc): |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8838 _collector(collector), |
935 | 8839 _span(span), |
8840 _bit_map(bit_map), | |
8841 _mark_stack(mark_stack), | |
8842 _concurrent_precleaning(cpc) { | |
8843 assert(!_span.is_empty(), "Empty span could spell trouble"); | |
8844 } | |
8845 | |
8846 | |
0 | 8847 // CMSKeepAliveClosure: the serial version |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8848 void CMSKeepAliveClosure::do_oop(oop obj) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8849 HeapWord* addr = (HeapWord*)obj; |
0 | 8850 if (_span.contains(addr) && |
8851 !_bit_map->isMarked(addr)) { | |
8852 _bit_map->mark(addr); | |
8853 bool simulate_overflow = false; | |
8854 NOT_PRODUCT( | |
8855 if (CMSMarkStackOverflowALot && | |
8856 _collector->simulate_overflow()) { | |
8857 // simulate a stack overflow | |
8858 simulate_overflow = true; | |
8859 } | |
8860 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8861 if (simulate_overflow || !_mark_stack->push(obj)) { |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8862 if (_concurrent_precleaning) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8863 // We dirty the overflown object and let the remark |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8864 // phase deal with it. |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8865 assert(_collector->overflow_list_is_empty(), "Error"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8866 // In the case of object arrays, we need to dirty all of |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8867 // the cards that the object spans. No locking or atomics |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8868 // are needed since no one else can be mutating the mod union |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8869 // table. |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8870 if (obj->is_objArray()) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8871 size_t sz = obj->size(); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8872 HeapWord* end_card_addr = |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8873 (HeapWord*)round_to((intptr_t)(addr+sz), CardTableModRefBS::card_size); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8874 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8875 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8876 _collector->_modUnionTable.mark_range(redirty_range); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8877 } else { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8878 _collector->_modUnionTable.mark(addr); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8879 } |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8880 _collector->_ser_kac_preclean_ovflw++; |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8881 } else { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8882 _collector->push_on_overflow_list(obj); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8883 _collector->_ser_kac_ovflw++; |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8884 } |
0 | 8885 } |
8886 } | |
8887 } | |
8888 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8889 void CMSKeepAliveClosure::do_oop(oop* p) { CMSKeepAliveClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8890 void CMSKeepAliveClosure::do_oop(narrowOop* p) { CMSKeepAliveClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8891 |
0 | 8892 // CMSParKeepAliveClosure: a parallel version of the above. |
8893 // The work queues are private to each closure (thread), | |
8894 // but (may be) available for stealing by other threads. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8895 void CMSParKeepAliveClosure::do_oop(oop obj) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8896 HeapWord* addr = (HeapWord*)obj; |
0 | 8897 if (_span.contains(addr) && |
8898 !_bit_map->isMarked(addr)) { | |
8899 // In general, during recursive tracing, several threads | |
8900 // may be concurrently getting here; the first one to | |
8901 // "tag" it, claims it. | |
8902 if (_bit_map->par_mark(addr)) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8903 bool res = _work_queue->push(obj); |
0 | 8904 assert(res, "Low water mark should be much less than capacity"); |
8905 // Do a recursive trim in the hope that this will keep | |
8906 // stack usage lower, but leave some oops for potential stealers | |
8907 trim_queue(_low_water_mark); | |
8908 } // Else, another thread got there first | |
8909 } | |
8910 } | |
8911 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8912 void CMSParKeepAliveClosure::do_oop(oop* p) { CMSParKeepAliveClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8913 void CMSParKeepAliveClosure::do_oop(narrowOop* p) { CMSParKeepAliveClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8914 |
0 | 8915 void CMSParKeepAliveClosure::trim_queue(uint max) { |
8916 while (_work_queue->size() > max) { | |
8917 oop new_oop; | |
8918 if (_work_queue->pop_local(new_oop)) { | |
8919 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
8920 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
8921 "no white objects on this stack!"); | |
8922 assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop"); | |
8923 // iterate over the oops in this oop, marking and pushing | |
8924 // the ones in CMS heap (i.e. in _span). | |
8925 new_oop->oop_iterate(&_mark_and_push); | |
8926 } | |
8927 } | |
8928 } | |
8929 | |
935 | 8930 CMSInnerParMarkAndPushClosure::CMSInnerParMarkAndPushClosure( |
8931 CMSCollector* collector, | |
8932 MemRegion span, CMSBitMap* bit_map, | |
8933 OopTaskQueue* work_queue): | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8934 _collector(collector), |
935 | 8935 _span(span), |
8936 _bit_map(bit_map), | |
8937 _work_queue(work_queue) { } | |
8938 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8939 void CMSInnerParMarkAndPushClosure::do_oop(oop obj) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8940 HeapWord* addr = (HeapWord*)obj; |
0 | 8941 if (_span.contains(addr) && |
8942 !_bit_map->isMarked(addr)) { | |
8943 if (_bit_map->par_mark(addr)) { | |
8944 bool simulate_overflow = false; | |
8945 NOT_PRODUCT( | |
8946 if (CMSMarkStackOverflowALot && | |
8947 _collector->par_simulate_overflow()) { | |
8948 // simulate a stack overflow | |
8949 simulate_overflow = true; | |
8950 } | |
8951 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8952 if (simulate_overflow || !_work_queue->push(obj)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8953 _collector->par_push_on_overflow_list(obj); |
0 | 8954 _collector->_par_kac_ovflw++; |
8955 } | |
8956 } // Else another thread got there already | |
8957 } | |
8958 } | |
8959 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8960 void CMSInnerParMarkAndPushClosure::do_oop(oop* p) { CMSInnerParMarkAndPushClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8961 void CMSInnerParMarkAndPushClosure::do_oop(narrowOop* p) { CMSInnerParMarkAndPushClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8962 |
0 | 8963 ////////////////////////////////////////////////////////////////// |
8964 // CMSExpansionCause ///////////////////////////// | |
8965 ////////////////////////////////////////////////////////////////// | |
8966 const char* CMSExpansionCause::to_string(CMSExpansionCause::Cause cause) { | |
8967 switch (cause) { | |
8968 case _no_expansion: | |
8969 return "No expansion"; | |
8970 case _satisfy_free_ratio: | |
8971 return "Free ratio"; | |
8972 case _satisfy_promotion: | |
8973 return "Satisfy promotion"; | |
8974 case _satisfy_allocation: | |
8975 return "allocation"; | |
8976 case _allocate_par_lab: | |
8977 return "Par LAB"; | |
8978 case _allocate_par_spooling_space: | |
8979 return "Par Spooling Space"; | |
8980 case _adaptive_size_policy: | |
8981 return "Ergonomics"; | |
8982 default: | |
8983 return "unknown"; | |
8984 } | |
8985 } | |
8986 | |
8987 void CMSDrainMarkingStackClosure::do_void() { | |
8988 // the max number to take from overflow list at a time | |
8989 const size_t num = _mark_stack->capacity()/4; | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8990 assert(!_concurrent_precleaning || _collector->overflow_list_is_empty(), |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8991 "Overflow list should be NULL during concurrent phases"); |
0 | 8992 while (!_mark_stack->isEmpty() || |
8993 // if stack is empty, check the overflow list | |
8994 _collector->take_from_overflow_list(num, _mark_stack)) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8995 oop obj = _mark_stack->pop(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8996 HeapWord* addr = (HeapWord*)obj; |
0 | 8997 assert(_span.contains(addr), "Should be within span"); |
8998 assert(_bit_map->isMarked(addr), "Should be marked"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8999 assert(obj->is_oop(), "Should be an oop"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
9000 obj->oop_iterate(_keep_alive); |
0 | 9001 } |
9002 } | |
9003 | |
9004 void CMSParDrainMarkingStackClosure::do_void() { | |
9005 // drain queue | |
9006 trim_queue(0); | |
9007 } | |
9008 | |
9009 // Trim our work_queue so its length is below max at return | |
9010 void CMSParDrainMarkingStackClosure::trim_queue(uint max) { | |
9011 while (_work_queue->size() > max) { | |
9012 oop new_oop; | |
9013 if (_work_queue->pop_local(new_oop)) { | |
9014 assert(new_oop->is_oop(), "Expected an oop"); | |
9015 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
9016 "no white objects on this stack!"); | |
9017 assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop"); | |
9018 // iterate over the oops in this oop, marking and pushing | |
9019 // the ones in CMS heap (i.e. in _span). | |
9020 new_oop->oop_iterate(&_mark_and_push); | |
9021 } | |
9022 } | |
9023 } | |
9024 | |
9025 //////////////////////////////////////////////////////////////////// | |
9026 // Support for Marking Stack Overflow list handling and related code | |
9027 //////////////////////////////////////////////////////////////////// | |
9028 // Much of the following code is similar in shape and spirit to the | |
9029 // code used in ParNewGC. We should try and share that code | |
9030 // as much as possible in the future. | |
9031 | |
9032 #ifndef PRODUCT | |
9033 // Debugging support for CMSStackOverflowALot | |
9034 | |
9035 // It's OK to call this multi-threaded; the worst thing | |
9036 // that can happen is that we'll get a bunch of closely | |
9037 // spaced simulated oveflows, but that's OK, in fact | |
9038 // probably good as it would exercise the overflow code | |
9039 // under contention. | |
9040 bool CMSCollector::simulate_overflow() { | |
9041 if (_overflow_counter-- <= 0) { // just being defensive | |
9042 _overflow_counter = CMSMarkStackOverflowInterval; | |
9043 return true; | |
9044 } else { | |
9045 return false; | |
9046 } | |
9047 } | |
9048 | |
9049 bool CMSCollector::par_simulate_overflow() { | |
9050 return simulate_overflow(); | |
9051 } | |
9052 #endif | |
9053 | |
9054 // Single-threaded | |
9055 bool CMSCollector::take_from_overflow_list(size_t num, CMSMarkStack* stack) { | |
9056 assert(stack->isEmpty(), "Expected precondition"); | |
9057 assert(stack->capacity() > num, "Shouldn't bite more than can chew"); | |
9058 size_t i = num; | |
9059 oop cur = _overflow_list; | |
9060 const markOop proto = markOopDesc::prototype(); | |
534 | 9061 NOT_PRODUCT(ssize_t n = 0;) |
0 | 9062 for (oop next; i > 0 && cur != NULL; cur = next, i--) { |
9063 next = oop(cur->mark()); | |
9064 cur->set_mark(proto); // until proven otherwise | |
9065 assert(cur->is_oop(), "Should be an oop"); | |
9066 bool res = stack->push(cur); | |
9067 assert(res, "Bit off more than can chew?"); | |
9068 NOT_PRODUCT(n++;) | |
9069 } | |
9070 _overflow_list = cur; | |
9071 #ifndef PRODUCT | |
9072 assert(_num_par_pushes >= n, "Too many pops?"); | |
9073 _num_par_pushes -=n; | |
9074 #endif | |
9075 return !stack->isEmpty(); | |
9076 } | |
9077 | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9078 #define BUSY (cast_to_oop<intptr_t>(0x1aff1aff)) |
534 | 9079 // (MT-safe) Get a prefix of at most "num" from the list. |
9080 // The overflow list is chained through the mark word of | |
9081 // each object in the list. We fetch the entire list, | |
9082 // break off a prefix of the right size and return the | |
9083 // remainder. If other threads try to take objects from | |
9084 // the overflow list at that time, they will wait for | |
9085 // some time to see if data becomes available. If (and | |
9086 // only if) another thread places one or more object(s) | |
9087 // on the global list before we have returned the suffix | |
9088 // to the global list, we will walk down our local list | |
9089 // to find its end and append the global list to | |
9090 // our suffix before returning it. This suffix walk can | |
9091 // prove to be expensive (quadratic in the amount of traffic) | |
9092 // when there are many objects in the overflow list and | |
9093 // there is much producer-consumer contention on the list. | |
9094 // *NOTE*: The overflow list manipulation code here and | |
9095 // in ParNewGeneration:: are very similar in shape, | |
9096 // except that in the ParNew case we use the old (from/eden) | |
9097 // copy of the object to thread the list via its klass word. | |
9098 // Because of the common code, if you make any changes in | |
9099 // the code below, please check the ParNew version to see if | |
9100 // similar changes might be needed. | |
9101 // CR 6797058 has been filed to consolidate the common code. | |
0 | 9102 bool CMSCollector::par_take_from_overflow_list(size_t num, |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9103 OopTaskQueue* work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9104 int no_of_gc_threads) { |
534 | 9105 assert(work_q->size() == 0, "First empty local work queue"); |
0 | 9106 assert(num < work_q->max_elems(), "Can't bite more than we can chew"); |
9107 if (_overflow_list == NULL) { | |
9108 return false; | |
9109 } | |
9110 // Grab the entire list; we'll put back a suffix | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9111 oop prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list)); |
534 | 9112 Thread* tid = Thread::current(); |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9113 // Before "no_of_gc_threads" was introduced CMSOverflowSpinCount was |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9114 // set to ParallelGCThreads. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9115 size_t CMSOverflowSpinCount = (size_t) no_of_gc_threads; // was ParallelGCThreads; |
534 | 9116 size_t sleep_time_millis = MAX2((size_t)1, num/100); |
9117 // If the list is busy, we spin for a short while, | |
9118 // sleeping between attempts to get the list. | |
9119 for (size_t spin = 0; prefix == BUSY && spin < CMSOverflowSpinCount; spin++) { | |
9120 os::sleep(tid, sleep_time_millis, false); | |
9121 if (_overflow_list == NULL) { | |
9122 // Nothing left to take | |
9123 return false; | |
9124 } else if (_overflow_list != BUSY) { | |
9125 // Try and grab the prefix | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9126 prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list)); |
534 | 9127 } |
9128 } | |
9129 // If the list was found to be empty, or we spun long | |
9130 // enough, we give up and return empty-handed. If we leave | |
9131 // the list in the BUSY state below, it must be the case that | |
9132 // some other thread holds the overflow list and will set it | |
9133 // to a non-BUSY state in the future. | |
9134 if (prefix == NULL || prefix == BUSY) { | |
9135 // Nothing to take or waited long enough | |
9136 if (prefix == NULL) { | |
9137 // Write back the NULL in case we overwrote it with BUSY above | |
9138 // and it is still the same value. | |
9139 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
9140 } | |
9141 return false; | |
9142 } | |
9143 assert(prefix != NULL && prefix != BUSY, "Error"); | |
0 | 9144 size_t i = num; |
9145 oop cur = prefix; | |
534 | 9146 // Walk down the first "num" objects, unless we reach the end. |
0 | 9147 for (; i > 1 && cur->mark() != NULL; cur = oop(cur->mark()), i--); |
534 | 9148 if (cur->mark() == NULL) { |
9149 // We have "num" or fewer elements in the list, so there | |
9150 // is nothing to return to the global list. | |
9151 // Write back the NULL in lieu of the BUSY we wrote | |
9152 // above, if it is still the same value. | |
9153 if (_overflow_list == BUSY) { | |
9154 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
9155 } | |
9156 } else { | |
9157 // Chop off the suffix and rerturn it to the global list. | |
9158 assert(cur->mark() != BUSY, "Error"); | |
0 | 9159 oop suffix_head = cur->mark(); // suffix will be put back on global list |
9160 cur->set_mark(NULL); // break off suffix | |
534 | 9161 // It's possible that the list is still in the empty(busy) state |
9162 // we left it in a short while ago; in that case we may be | |
9163 // able to place back the suffix without incurring the cost | |
9164 // of a walk down the list. | |
0 | 9165 oop observed_overflow_list = _overflow_list; |
534 | 9166 oop cur_overflow_list = observed_overflow_list; |
9167 bool attached = false; | |
9168 while (observed_overflow_list == BUSY || observed_overflow_list == NULL) { | |
0 | 9169 observed_overflow_list = |
534 | 9170 (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list); |
9171 if (cur_overflow_list == observed_overflow_list) { | |
9172 attached = true; | |
9173 break; | |
9174 } else cur_overflow_list = observed_overflow_list; | |
9175 } | |
9176 if (!attached) { | |
9177 // Too bad, someone else sneaked in (at least) an element; we'll need | |
9178 // to do a splice. Find tail of suffix so we can prepend suffix to global | |
9179 // list. | |
9180 for (cur = suffix_head; cur->mark() != NULL; cur = (oop)(cur->mark())); | |
9181 oop suffix_tail = cur; | |
9182 assert(suffix_tail != NULL && suffix_tail->mark() == NULL, | |
9183 "Tautology"); | |
9184 observed_overflow_list = _overflow_list; | |
9185 do { | |
9186 cur_overflow_list = observed_overflow_list; | |
9187 if (cur_overflow_list != BUSY) { | |
9188 // Do the splice ... | |
9189 suffix_tail->set_mark(markOop(cur_overflow_list)); | |
9190 } else { // cur_overflow_list == BUSY | |
9191 suffix_tail->set_mark(NULL); | |
9192 } | |
9193 // ... and try to place spliced list back on overflow_list ... | |
9194 observed_overflow_list = | |
9195 (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list); | |
9196 } while (cur_overflow_list != observed_overflow_list); | |
9197 // ... until we have succeeded in doing so. | |
9198 } | |
0 | 9199 } |
9200 | |
9201 // Push the prefix elements on work_q | |
9202 assert(prefix != NULL, "control point invariant"); | |
9203 const markOop proto = markOopDesc::prototype(); | |
9204 oop next; | |
534 | 9205 NOT_PRODUCT(ssize_t n = 0;) |
0 | 9206 for (cur = prefix; cur != NULL; cur = next) { |
9207 next = oop(cur->mark()); | |
9208 cur->set_mark(proto); // until proven otherwise | |
9209 assert(cur->is_oop(), "Should be an oop"); | |
9210 bool res = work_q->push(cur); | |
9211 assert(res, "Bit off more than we can chew?"); | |
9212 NOT_PRODUCT(n++;) | |
9213 } | |
9214 #ifndef PRODUCT | |
9215 assert(_num_par_pushes >= n, "Too many pops?"); | |
9216 Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes); | |
9217 #endif | |
9218 return true; | |
9219 } | |
9220 | |
9221 // Single-threaded | |
9222 void CMSCollector::push_on_overflow_list(oop p) { | |
9223 NOT_PRODUCT(_num_par_pushes++;) | |
9224 assert(p->is_oop(), "Not an oop"); | |
9225 preserve_mark_if_necessary(p); | |
9226 p->set_mark((markOop)_overflow_list); | |
9227 _overflow_list = p; | |
9228 } | |
9229 | |
9230 // Multi-threaded; use CAS to prepend to overflow list | |
9231 void CMSCollector::par_push_on_overflow_list(oop p) { | |
9232 NOT_PRODUCT(Atomic::inc_ptr(&_num_par_pushes);) | |
9233 assert(p->is_oop(), "Not an oop"); | |
9234 par_preserve_mark_if_necessary(p); | |
9235 oop observed_overflow_list = _overflow_list; | |
9236 oop cur_overflow_list; | |
9237 do { | |
9238 cur_overflow_list = observed_overflow_list; | |
534 | 9239 if (cur_overflow_list != BUSY) { |
9240 p->set_mark(markOop(cur_overflow_list)); | |
9241 } else { | |
9242 p->set_mark(NULL); | |
9243 } | |
0 | 9244 observed_overflow_list = |
9245 (oop) Atomic::cmpxchg_ptr(p, &_overflow_list, cur_overflow_list); | |
9246 } while (cur_overflow_list != observed_overflow_list); | |
9247 } | |
534 | 9248 #undef BUSY |
0 | 9249 |
9250 // Single threaded | |
9251 // General Note on GrowableArray: pushes may silently fail | |
9252 // because we are (temporarily) out of C-heap for expanding | |
9253 // the stack. The problem is quite ubiquitous and affects | |
9254 // a lot of code in the JVM. The prudent thing for GrowableArray | |
9255 // to do (for now) is to exit with an error. However, that may | |
9256 // be too draconian in some cases because the caller may be | |
534 | 9257 // able to recover without much harm. For such cases, we |
0 | 9258 // should probably introduce a "soft_push" method which returns |
9259 // an indication of success or failure with the assumption that | |
9260 // the caller may be able to recover from a failure; code in | |
9261 // the VM can then be changed, incrementally, to deal with such | |
9262 // failures where possible, thus, incrementally hardening the VM | |
9263 // in such low resource situations. | |
9264 void CMSCollector::preserve_mark_work(oop p, markOop m) { | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9265 _preserved_oop_stack.push(p); |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9266 _preserved_mark_stack.push(m); |
0 | 9267 assert(m == p->mark(), "Mark word changed"); |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9268 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
0 | 9269 "bijection"); |
9270 } | |
9271 | |
9272 // Single threaded | |
9273 void CMSCollector::preserve_mark_if_necessary(oop p) { | |
9274 markOop m = p->mark(); | |
9275 if (m->must_be_preserved(p)) { | |
9276 preserve_mark_work(p, m); | |
9277 } | |
9278 } | |
9279 | |
9280 void CMSCollector::par_preserve_mark_if_necessary(oop p) { | |
9281 markOop m = p->mark(); | |
9282 if (m->must_be_preserved(p)) { | |
9283 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
9284 // Even though we read the mark word without holding | |
9285 // the lock, we are assured that it will not change | |
9286 // because we "own" this oop, so no other thread can | |
9287 // be trying to push it on the overflow list; see | |
9288 // the assertion in preserve_mark_work() that checks | |
9289 // that m == p->mark(). | |
9290 preserve_mark_work(p, m); | |
9291 } | |
9292 } | |
9293 | |
9294 // We should be able to do this multi-threaded, | |
9295 // a chunk of stack being a task (this is | |
9296 // correct because each oop only ever appears | |
9297 // once in the overflow list. However, it's | |
9298 // not very easy to completely overlap this with | |
9299 // other operations, so will generally not be done | |
9300 // until all work's been completed. Because we | |
9301 // expect the preserved oop stack (set) to be small, | |
9302 // it's probably fine to do this single-threaded. | |
9303 // We can explore cleverer concurrent/overlapped/parallel | |
9304 // processing of preserved marks if we feel the | |
9305 // need for this in the future. Stack overflow should | |
9306 // be so rare in practice and, when it happens, its | |
9307 // effect on performance so great that this will | |
9308 // likely just be in the noise anyway. | |
9309 void CMSCollector::restore_preserved_marks_if_any() { | |
9310 assert(SafepointSynchronize::is_at_safepoint(), | |
9311 "world should be stopped"); | |
9312 assert(Thread::current()->is_ConcurrentGC_thread() || | |
9313 Thread::current()->is_VM_thread(), | |
9314 "should be single-threaded"); | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9315 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9316 "bijection"); |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9317 |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9318 while (!_preserved_oop_stack.is_empty()) { |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9319 oop p = _preserved_oop_stack.pop(); |
0 | 9320 assert(p->is_oop(), "Should be an oop"); |
9321 assert(_span.contains(p), "oop should be in _span"); | |
9322 assert(p->mark() == markOopDesc::prototype(), | |
9323 "Set when taken from overflow list"); | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9324 markOop m = _preserved_mark_stack.pop(); |
0 | 9325 p->set_mark(m); |
9326 } | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9327 assert(_preserved_mark_stack.is_empty() && _preserved_oop_stack.is_empty(), |
0 | 9328 "stacks were cleared above"); |
9329 } | |
9330 | |
9331 #ifndef PRODUCT | |
9332 bool CMSCollector::no_preserved_marks() const { | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9333 return _preserved_mark_stack.is_empty() && _preserved_oop_stack.is_empty(); |
0 | 9334 } |
9335 #endif | |
9336 | |
9337 CMSAdaptiveSizePolicy* ASConcurrentMarkSweepGeneration::cms_size_policy() const | |
9338 { | |
9339 GenCollectedHeap* gch = (GenCollectedHeap*) GenCollectedHeap::heap(); | |
9340 CMSAdaptiveSizePolicy* size_policy = | |
9341 (CMSAdaptiveSizePolicy*) gch->gen_policy()->size_policy(); | |
9342 assert(size_policy->is_gc_cms_adaptive_size_policy(), | |
9343 "Wrong type for size policy"); | |
9344 return size_policy; | |
9345 } | |
9346 | |
9347 void ASConcurrentMarkSweepGeneration::resize(size_t cur_promo_size, | |
9348 size_t desired_promo_size) { | |
9349 if (cur_promo_size < desired_promo_size) { | |
9350 size_t expand_bytes = desired_promo_size - cur_promo_size; | |
9351 if (PrintAdaptiveSizePolicy && Verbose) { | |
9352 gclog_or_tty->print_cr(" ASConcurrentMarkSweepGeneration::resize " | |
9353 "Expanding tenured generation by " SIZE_FORMAT " (bytes)", | |
9354 expand_bytes); | |
9355 } | |
9356 expand(expand_bytes, | |
9357 MinHeapDeltaBytes, | |
9358 CMSExpansionCause::_adaptive_size_policy); | |
9359 } else if (desired_promo_size < cur_promo_size) { | |
9360 size_t shrink_bytes = cur_promo_size - desired_promo_size; | |
9361 if (PrintAdaptiveSizePolicy && Verbose) { | |
9362 gclog_or_tty->print_cr(" ASConcurrentMarkSweepGeneration::resize " | |
9363 "Shrinking tenured generation by " SIZE_FORMAT " (bytes)", | |
9364 shrink_bytes); | |
9365 } | |
9366 shrink(shrink_bytes); | |
9367 } | |
9368 } | |
9369 | |
9370 CMSGCAdaptivePolicyCounters* ASConcurrentMarkSweepGeneration::gc_adaptive_policy_counters() { | |
9371 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9372 CMSGCAdaptivePolicyCounters* counters = | |
9373 (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters(); | |
9374 assert(counters->kind() == GCPolicyCounters::CMSGCAdaptivePolicyCountersKind, | |
9375 "Wrong kind of counters"); | |
9376 return counters; | |
9377 } | |
9378 | |
9379 | |
9380 void ASConcurrentMarkSweepGeneration::update_counters() { | |
9381 if (UsePerfData) { | |
9382 _space_counters->update_all(); | |
9383 _gen_counters->update_all(); | |
9384 CMSGCAdaptivePolicyCounters* counters = gc_adaptive_policy_counters(); | |
9385 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9386 CMSGCStats* gc_stats_l = (CMSGCStats*) gc_stats(); | |
9387 assert(gc_stats_l->kind() == GCStats::CMSGCStatsKind, | |
9388 "Wrong gc statistics type"); | |
9389 counters->update_counters(gc_stats_l); | |
9390 } | |
9391 } | |
9392 | |
9393 void ASConcurrentMarkSweepGeneration::update_counters(size_t used) { | |
9394 if (UsePerfData) { | |
9395 _space_counters->update_used(used); | |
9396 _space_counters->update_capacity(); | |
9397 _gen_counters->update_all(); | |
9398 | |
9399 CMSGCAdaptivePolicyCounters* counters = gc_adaptive_policy_counters(); | |
9400 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9401 CMSGCStats* gc_stats_l = (CMSGCStats*) gc_stats(); | |
9402 assert(gc_stats_l->kind() == GCStats::CMSGCStatsKind, | |
9403 "Wrong gc statistics type"); | |
9404 counters->update_counters(gc_stats_l); | |
9405 } | |
9406 } | |
9407 | |
9408 void ASConcurrentMarkSweepGeneration::shrink_by(size_t desired_bytes) { | |
9409 assert_locked_or_safepoint(Heap_lock); | |
9410 assert_lock_strong(freelistLock()); | |
9411 HeapWord* old_end = _cmsSpace->end(); | |
9412 HeapWord* unallocated_start = _cmsSpace->unallocated_block(); | |
9413 assert(old_end >= unallocated_start, "Miscalculation of unallocated_start"); | |
9414 FreeChunk* chunk_at_end = find_chunk_at_end(); | |
9415 if (chunk_at_end == NULL) { | |
9416 // No room to shrink | |
9417 if (PrintGCDetails && Verbose) { | |
9418 gclog_or_tty->print_cr("No room to shrink: old_end " | |
9419 PTR_FORMAT " unallocated_start " PTR_FORMAT | |
9420 " chunk_at_end " PTR_FORMAT, | |
9421 old_end, unallocated_start, chunk_at_end); | |
9422 } | |
9423 return; | |
9424 } else { | |
9425 | |
9426 // Find the chunk at the end of the space and determine | |
9427 // how much it can be shrunk. | |
9428 size_t shrinkable_size_in_bytes = chunk_at_end->size(); | |
9429 size_t aligned_shrinkable_size_in_bytes = | |
9430 align_size_down(shrinkable_size_in_bytes, os::vm_page_size()); | |
6885 | 9431 assert(unallocated_start <= (HeapWord*) chunk_at_end->end(), |
0 | 9432 "Inconsistent chunk at end of space"); |
9433 size_t bytes = MIN2(desired_bytes, aligned_shrinkable_size_in_bytes); | |
9434 size_t word_size_before = heap_word_size(_virtual_space.committed_size()); | |
9435 | |
9436 // Shrink the underlying space | |
9437 _virtual_space.shrink_by(bytes); | |
9438 if (PrintGCDetails && Verbose) { | |
9439 gclog_or_tty->print_cr("ConcurrentMarkSweepGeneration::shrink_by:" | |
9440 " desired_bytes " SIZE_FORMAT | |
9441 " shrinkable_size_in_bytes " SIZE_FORMAT | |
9442 " aligned_shrinkable_size_in_bytes " SIZE_FORMAT | |
9443 " bytes " SIZE_FORMAT, | |
9444 desired_bytes, shrinkable_size_in_bytes, | |
9445 aligned_shrinkable_size_in_bytes, bytes); | |
9446 gclog_or_tty->print_cr(" old_end " SIZE_FORMAT | |
9447 " unallocated_start " SIZE_FORMAT, | |
9448 old_end, unallocated_start); | |
9449 } | |
9450 | |
9451 // If the space did shrink (shrinking is not guaranteed), | |
9452 // shrink the chunk at the end by the appropriate amount. | |
9453 if (((HeapWord*)_virtual_space.high()) < old_end) { | |
9454 size_t new_word_size = | |
9455 heap_word_size(_virtual_space.committed_size()); | |
9456 | |
9457 // Have to remove the chunk from the dictionary because it is changing | |
9458 // size and might be someplace elsewhere in the dictionary. | |
9459 | |
9460 // Get the chunk at end, shrink it, and put it | |
9461 // back. | |
9462 _cmsSpace->removeChunkFromDictionary(chunk_at_end); | |
9463 size_t word_size_change = word_size_before - new_word_size; | |
9464 size_t chunk_at_end_old_size = chunk_at_end->size(); | |
9465 assert(chunk_at_end_old_size >= word_size_change, | |
9466 "Shrink is too large"); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
9467 chunk_at_end->set_size(chunk_at_end_old_size - |
0 | 9468 word_size_change); |
9469 _cmsSpace->freed((HeapWord*) chunk_at_end->end(), | |
9470 word_size_change); | |
9471 | |
9472 _cmsSpace->returnChunkToDictionary(chunk_at_end); | |
9473 | |
9474 MemRegion mr(_cmsSpace->bottom(), new_word_size); | |
9475 _bts->resize(new_word_size); // resize the block offset shared array | |
9476 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
9477 _cmsSpace->assert_locked(); | |
9478 _cmsSpace->set_end((HeapWord*)_virtual_space.high()); | |
9479 | |
9480 NOT_PRODUCT(_cmsSpace->dictionary()->verify()); | |
9481 | |
9482 // update the space and generation capacity counters | |
9483 if (UsePerfData) { | |
9484 _space_counters->update_capacity(); | |
9485 _gen_counters->update_all(); | |
9486 } | |
9487 | |
9488 if (Verbose && PrintGCDetails) { | |
9489 size_t new_mem_size = _virtual_space.committed_size(); | |
9490 size_t old_mem_size = new_mem_size + bytes; | |
7623
203f64878aab
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
6885
diff
changeset
|
9491 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
0 | 9492 name(), old_mem_size/K, bytes/K, new_mem_size/K); |
9493 } | |
9494 } | |
9495 | |
9496 assert(_cmsSpace->unallocated_block() <= _cmsSpace->end(), | |
9497 "Inconsistency at end of space"); | |
6885 | 9498 assert(chunk_at_end->end() == (uintptr_t*) _cmsSpace->end(), |
0 | 9499 "Shrinking is inconsistent"); |
9500 return; | |
9501 } | |
9502 } | |
9503 // Transfer some number of overflown objects to usual marking | |
9504 // stack. Return true if some objects were transferred. | |
9505 bool MarkRefsIntoAndScanClosure::take_from_overflow_list() { | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
9506 size_t num = MIN2((size_t)(_mark_stack->capacity() - _mark_stack->length())/4, |
0 | 9507 (size_t)ParGCDesiredObjsFromOverflowList); |
9508 | |
9509 bool res = _collector->take_from_overflow_list(num, _mark_stack); | |
9510 assert(_collector->overflow_list_is_empty() || res, | |
9511 "If list is not empty, we should have taken something"); | |
9512 assert(!res || !_mark_stack->isEmpty(), | |
9513 "If we took something, it should now be on our stack"); | |
9514 return res; | |
9515 } | |
9516 | |
9517 size_t MarkDeadObjectsClosure::do_blk(HeapWord* addr) { | |
9518 size_t res = _sp->block_size_no_stall(addr, _collector); | |
9519 if (_sp->block_is_obj(addr)) { | |
9520 if (_live_bit_map->isMarked(addr)) { | |
9521 // It can't have been dead in a previous cycle | |
9522 guarantee(!_dead_bit_map->isMarked(addr), "No resurrection!"); | |
9523 } else { | |
9524 _dead_bit_map->mark(addr); // mark the dead object | |
9525 } | |
9526 } | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
9527 // Could be 0, if the block size could not be computed without stalling. |
0 | 9528 return res; |
9529 } | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9530 |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9531 TraceCMSMemoryManagerStats::TraceCMSMemoryManagerStats(CMSCollector::CollectorState phase, GCCause::Cause cause): TraceMemoryManagerStats() { |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9532 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9533 switch (phase) { |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9534 case CMSCollector::InitialMarking: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9535 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9536 cause /* cause of the GC */, |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9537 true /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9538 true /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9539 false /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9540 false /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9541 true /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9542 false /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9543 false /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9544 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9545 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9546 case CMSCollector::FinalMarking: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9547 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9548 cause /* cause of the GC */, |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9549 false /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9550 false /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9551 false /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9552 false /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9553 true /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9554 false /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9555 false /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9556 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9557 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9558 case CMSCollector::Sweeping: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9559 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9560 cause /* cause of the GC */, |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9561 false /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9562 false /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9563 true /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9564 true /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9565 false /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9566 true /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9567 true /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9568 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9569 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9570 default: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9571 ShouldNotReachHere(); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9572 } |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9573 } |