Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @ 10244:06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
Reviewed-by: mgerdin, johnc, tschatzl
author | jmasa |
---|---|
date | Wed, 08 May 2013 17:12:52 -0700 |
parents | a9d568b7df60 |
children | 12f651e29f6b |
rev | line source |
---|---|
0 | 1 /* |
7623
203f64878aab
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
6885
diff
changeset
|
2 * Copyright (c) 2001, 2013, 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" | |
40 #include "gc_implementation/shared/isGCActiveMark.hpp" | |
41 #include "gc_interface/collectedHeap.inline.hpp" | |
42 #include "memory/cardTableRS.hpp" | |
43 #include "memory/collectorPolicy.hpp" | |
44 #include "memory/gcLocker.inline.hpp" | |
45 #include "memory/genCollectedHeap.hpp" | |
46 #include "memory/genMarkSweep.hpp" | |
47 #include "memory/genOopClosures.inline.hpp" | |
48 #include "memory/iterator.hpp" | |
49 #include "memory/referencePolicy.hpp" | |
50 #include "memory/resourceArea.hpp" | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
51 #include "memory/tenuredGeneration.hpp" |
1972 | 52 #include "oops/oop.inline.hpp" |
53 #include "prims/jvmtiExport.hpp" | |
54 #include "runtime/globals_extension.hpp" | |
55 #include "runtime/handles.inline.hpp" | |
56 #include "runtime/java.hpp" | |
57 #include "runtime/vmThread.hpp" | |
58 #include "services/memoryService.hpp" | |
59 #include "services/runtimeService.hpp" | |
0 | 60 |
61 // statics | |
62 CMSCollector* ConcurrentMarkSweepGeneration::_collector = NULL; | |
63 bool CMSCollector::_full_gc_requested = false; | |
64 | |
65 ////////////////////////////////////////////////////////////////// | |
66 // In support of CMS/VM thread synchronization | |
67 ////////////////////////////////////////////////////////////////// | |
68 // We split use of the CGC_lock into 2 "levels". | |
69 // The low-level locking is of the usual CGC_lock monitor. We introduce | |
70 // a higher level "token" (hereafter "CMS token") built on top of the | |
71 // low level monitor (hereafter "CGC lock"). | |
72 // The token-passing protocol gives priority to the VM thread. The | |
73 // CMS-lock doesn't provide any fairness guarantees, but clients | |
74 // should ensure that it is only held for very short, bounded | |
75 // durations. | |
76 // | |
77 // When either of the CMS thread or the VM thread is involved in | |
78 // collection operations during which it does not want the other | |
79 // thread to interfere, it obtains the CMS token. | |
80 // | |
81 // If either thread tries to get the token while the other has | |
82 // it, that thread waits. However, if the VM thread and CMS thread | |
83 // both want the token, then the VM thread gets priority while the | |
84 // CMS thread waits. This ensures, for instance, that the "concurrent" | |
85 // phases of the CMS thread's work do not block out the VM thread | |
86 // for long periods of time as the CMS thread continues to hog | |
87 // the token. (See bug 4616232). | |
88 // | |
89 // The baton-passing functions are, however, controlled by the | |
90 // flags _foregroundGCShouldWait and _foregroundGCIsActive, | |
91 // and here the low-level CMS lock, not the high level token, | |
92 // ensures mutual exclusion. | |
93 // | |
94 // Two important conditions that we have to satisfy: | |
95 // 1. if a thread does a low-level wait on the CMS lock, then it | |
96 // relinquishes the CMS token if it were holding that token | |
97 // when it acquired the low-level CMS lock. | |
98 // 2. any low-level notifications on the low-level lock | |
99 // should only be sent when a thread has relinquished the token. | |
100 // | |
101 // In the absence of either property, we'd have potential deadlock. | |
102 // | |
103 // We protect each of the CMS (concurrent and sequential) phases | |
104 // with the CMS _token_, not the CMS _lock_. | |
105 // | |
106 // The only code protected by CMS lock is the token acquisition code | |
107 // itself, see ConcurrentMarkSweepThread::[de]synchronize(), and the | |
108 // baton-passing code. | |
109 // | |
110 // Unfortunately, i couldn't come up with a good abstraction to factor and | |
111 // hide the naked CGC_lock manipulation in the baton-passing code | |
112 // further below. That's something we should try to do. Also, the proof | |
113 // of correctness of this 2-level locking scheme is far from obvious, | |
114 // and potentially quite slippery. We have an uneasy supsicion, for instance, | |
115 // that there may be a theoretical possibility of delay/starvation in the | |
116 // low-level lock/wait/notify scheme used for the baton-passing because of | |
117 // potential intereference with the priority scheme embodied in the | |
118 // CMS-token-passing protocol. See related comments at a CGC_lock->wait() | |
119 // invocation further below and marked with "XXX 20011219YSR". | |
120 // Indeed, as we note elsewhere, this may become yet more slippery | |
121 // in the presence of multiple CMS and/or multiple VM threads. XXX | |
122 | |
123 class CMSTokenSync: public StackObj { | |
124 private: | |
125 bool _is_cms_thread; | |
126 public: | |
127 CMSTokenSync(bool is_cms_thread): | |
128 _is_cms_thread(is_cms_thread) { | |
129 assert(is_cms_thread == Thread::current()->is_ConcurrentGC_thread(), | |
130 "Incorrect argument to constructor"); | |
131 ConcurrentMarkSweepThread::synchronize(_is_cms_thread); | |
132 } | |
133 | |
134 ~CMSTokenSync() { | |
135 assert(_is_cms_thread ? | |
136 ConcurrentMarkSweepThread::cms_thread_has_cms_token() : | |
137 ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
138 "Incorrect state"); | |
139 ConcurrentMarkSweepThread::desynchronize(_is_cms_thread); | |
140 } | |
141 }; | |
142 | |
143 // Convenience class that does a CMSTokenSync, and then acquires | |
144 // upto three locks. | |
145 class CMSTokenSyncWithLocks: public CMSTokenSync { | |
146 private: | |
147 // Note: locks are acquired in textual declaration order | |
148 // and released in the opposite order | |
149 MutexLockerEx _locker1, _locker2, _locker3; | |
150 public: | |
151 CMSTokenSyncWithLocks(bool is_cms_thread, Mutex* mutex1, | |
152 Mutex* mutex2 = NULL, Mutex* mutex3 = NULL): | |
153 CMSTokenSync(is_cms_thread), | |
154 _locker1(mutex1, Mutex::_no_safepoint_check_flag), | |
155 _locker2(mutex2, Mutex::_no_safepoint_check_flag), | |
156 _locker3(mutex3, Mutex::_no_safepoint_check_flag) | |
157 { } | |
158 }; | |
159 | |
160 | |
161 // Wrapper class to temporarily disable icms during a foreground cms collection. | |
162 class ICMSDisabler: public StackObj { | |
163 public: | |
164 // The ctor disables icms and wakes up the thread so it notices the change; | |
165 // the dtor re-enables icms. Note that the CMSCollector methods will check | |
166 // CMSIncrementalMode. | |
167 ICMSDisabler() { CMSCollector::disable_icms(); CMSCollector::start_icms(); } | |
168 ~ICMSDisabler() { CMSCollector::enable_icms(); } | |
169 }; | |
170 | |
171 ////////////////////////////////////////////////////////////////// | |
172 // Concurrent Mark-Sweep Generation ///////////////////////////// | |
173 ////////////////////////////////////////////////////////////////// | |
174 | |
175 NOT_PRODUCT(CompactibleFreeListSpace* debug_cms_space;) | |
176 | |
177 // This struct contains per-thread things necessary to support parallel | |
178 // young-gen collection. | |
6197 | 179 class CMSParGCThreadState: public CHeapObj<mtGC> { |
0 | 180 public: |
181 CFLS_LAB lab; | |
182 PromotionInfo promo; | |
183 | |
184 // Constructor. | |
185 CMSParGCThreadState(CompactibleFreeListSpace* cfls) : lab(cfls) { | |
186 promo.setSpace(cfls); | |
187 } | |
188 }; | |
189 | |
190 ConcurrentMarkSweepGeneration::ConcurrentMarkSweepGeneration( | |
191 ReservedSpace rs, size_t initial_byte_size, int level, | |
192 CardTableRS* ct, bool use_adaptive_freelists, | |
6026 | 193 FreeBlockDictionary<FreeChunk>::DictionaryChoice dictionaryChoice) : |
0 | 194 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
|
195 _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
|
196 _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
|
197 _did_compact(false) |
0 | 198 { |
199 HeapWord* bottom = (HeapWord*) _virtual_space.low(); | |
200 HeapWord* end = (HeapWord*) _virtual_space.high(); | |
201 | |
202 _direct_allocated_words = 0; | |
203 NOT_PRODUCT( | |
204 _numObjectsPromoted = 0; | |
205 _numWordsPromoted = 0; | |
206 _numObjectsAllocated = 0; | |
207 _numWordsAllocated = 0; | |
208 ) | |
209 | |
210 _cmsSpace = new CompactibleFreeListSpace(_bts, MemRegion(bottom, end), | |
211 use_adaptive_freelists, | |
212 dictionaryChoice); | |
213 NOT_PRODUCT(debug_cms_space = _cmsSpace;) | |
214 if (_cmsSpace == NULL) { | |
215 vm_exit_during_initialization( | |
216 "CompactibleFreeListSpace allocation failure"); | |
217 } | |
218 _cmsSpace->_gen = this; | |
219 | |
220 _gc_stats = new CMSGCStats(); | |
221 | |
222 // Verify the assumption that FreeChunk::_prev and OopDesc::_klass | |
223 // offsets match. The ability to tell free chunks from objects | |
224 // depends on this property. | |
225 debug_only( | |
226 FreeChunk* junk = NULL; | |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6787
diff
changeset
|
227 assert(UseCompressedKlassPointers || |
187 | 228 junk->prev_addr() == (void*)(oop(junk)->klass_addr()), |
0 | 229 "Offset of FreeChunk::_prev within FreeChunk must match" |
230 " that of OopDesc::_klass within OopDesc"); | |
231 ) | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
232 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 233 typedef CMSParGCThreadState* CMSParGCThreadStatePtr; |
234 _par_gc_thread_states = | |
6197 | 235 NEW_C_HEAP_ARRAY(CMSParGCThreadStatePtr, ParallelGCThreads, mtGC); |
0 | 236 if (_par_gc_thread_states == NULL) { |
237 vm_exit_during_initialization("Could not allocate par gc structs"); | |
238 } | |
239 for (uint i = 0; i < ParallelGCThreads; i++) { | |
240 _par_gc_thread_states[i] = new CMSParGCThreadState(cmsSpace()); | |
241 if (_par_gc_thread_states[i] == NULL) { | |
242 vm_exit_during_initialization("Could not allocate par gc structs"); | |
243 } | |
244 } | |
245 } else { | |
246 _par_gc_thread_states = NULL; | |
247 } | |
248 _incremental_collection_failed = false; | |
249 // The "dilatation_factor" is the expansion that can occur on | |
250 // account of the fact that the minimum object size in the CMS | |
251 // generation may be larger than that in, say, a contiguous young | |
252 // generation. | |
253 // Ideally, in the calculation below, we'd compute the dilatation | |
254 // factor as: MinChunkSize/(promoting_gen's min object size) | |
255 // Since we do not have such a general query interface for the | |
256 // promoting generation, we'll instead just use the mimimum | |
257 // object size (which today is a header's worth of space); | |
258 // 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
|
259 assert(MinChunkSize >= CollectedHeap::min_fill_size(), "just checking"); |
0 | 260 assert(_dilatation_factor >= 1.0, "from previous assert"); |
261 } | |
262 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
263 |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
264 // The field "_initiating_occupancy" represents the occupancy percentage |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
265 // 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
|
266 // via CMSInitiatingOccupancyFraction (argument "io" below), it |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
267 // is calculated by: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
268 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
269 // Let "f" be MinHeapFreeRatio in |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
270 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
271 // _intiating_occupancy = 100-f + |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
272 // f * (CMSTriggerRatio/100) |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
273 // where CMSTriggerRatio is the argument "tr" below. |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
274 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
275 // 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
|
276 // 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
|
277 // space be allocated before initiating a new collection cycle. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
278 // |
8035 | 279 void ConcurrentMarkSweepGeneration::init_initiating_occupancy(intx io, uintx tr) { |
280 assert(io <= 100 && tr <= 100, "Check the arguments"); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
281 if (io >= 0) { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
282 _initiating_occupancy = (double)io / 100.0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
283 } else { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
284 _initiating_occupancy = ((100 - MinHeapFreeRatio) + |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
285 (double)(tr * MinHeapFreeRatio) / 100.0) |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
286 / 100.0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
287 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
288 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
289 |
0 | 290 void ConcurrentMarkSweepGeneration::ref_processor_init() { |
291 assert(collector() != NULL, "no collector"); | |
292 collector()->ref_processor_init(); | |
293 } | |
294 | |
295 void CMSCollector::ref_processor_init() { | |
296 if (_ref_processor == NULL) { | |
297 // Allocate and initialize a reference processor | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
298 _ref_processor = |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
299 new ReferenceProcessor(_span, // span |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
300 (ParallelGCThreads > 1) && ParallelRefProcEnabled, // mt processing |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
301 (int) ParallelGCThreads, // mt processing degree |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
302 _cmsGen->refs_discovery_is_mt(), // mt discovery |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
303 (int) MAX2(ConcGCThreads, ParallelGCThreads), // mt discovery degree |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
304 _cmsGen->refs_discovery_is_atomic(), // discovery is not atomic |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
305 &_is_alive_closure, // closure for liveness info |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
306 false); // next field updates do not need write barrier |
0 | 307 // Initialize the _ref_processor field of CMSGen |
308 _cmsGen->set_ref_processor(_ref_processor); | |
309 | |
310 } | |
311 } | |
312 | |
313 CMSAdaptiveSizePolicy* CMSCollector::size_policy() { | |
314 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
315 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
316 "Wrong type of heap"); | |
317 CMSAdaptiveSizePolicy* sp = (CMSAdaptiveSizePolicy*) | |
318 gch->gen_policy()->size_policy(); | |
319 assert(sp->is_gc_cms_adaptive_size_policy(), | |
320 "Wrong type of size policy"); | |
321 return sp; | |
322 } | |
323 | |
324 CMSGCAdaptivePolicyCounters* CMSCollector::gc_adaptive_policy_counters() { | |
325 CMSGCAdaptivePolicyCounters* results = | |
326 (CMSGCAdaptivePolicyCounters*) collector_policy()->counters(); | |
327 assert( | |
328 results->kind() == GCPolicyCounters::CMSGCAdaptivePolicyCountersKind, | |
329 "Wrong gc policy counter kind"); | |
330 return results; | |
331 } | |
332 | |
333 | |
334 void ConcurrentMarkSweepGeneration::initialize_performance_counters() { | |
335 | |
336 const char* gen_name = "old"; | |
337 | |
338 // Generation Counters - generation 1, 1 subspace | |
339 _gen_counters = new GenerationCounters(gen_name, 1, 1, &_virtual_space); | |
340 | |
341 _space_counters = new GSpaceCounters(gen_name, 0, | |
342 _virtual_space.reserved_size(), | |
343 this, _gen_counters); | |
344 } | |
345 | |
346 CMSStats::CMSStats(ConcurrentMarkSweepGeneration* cms_gen, unsigned int alpha): | |
347 _cms_gen(cms_gen) | |
348 { | |
349 assert(alpha <= 100, "bad value"); | |
350 _saved_alpha = alpha; | |
351 | |
352 // Initialize the alphas to the bootstrap value of 100. | |
353 _gc0_alpha = _cms_alpha = 100; | |
354 | |
355 _cms_begin_time.update(); | |
356 _cms_end_time.update(); | |
357 | |
358 _gc0_duration = 0.0; | |
359 _gc0_period = 0.0; | |
360 _gc0_promoted = 0; | |
361 | |
362 _cms_duration = 0.0; | |
363 _cms_period = 0.0; | |
364 _cms_allocated = 0; | |
365 | |
366 _cms_used_at_gc0_begin = 0; | |
367 _cms_used_at_gc0_end = 0; | |
368 _allow_duty_cycle_reduction = false; | |
369 _valid_bits = 0; | |
370 _icms_duty_cycle = CMSIncrementalDutyCycle; | |
371 } | |
372 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
373 double CMSStats::cms_free_adjustment_factor(size_t free) const { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
374 // TBD: CR 6909490 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
375 return 1.0; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
376 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
377 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
378 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
|
379 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
380 |
0 | 381 // If promotion failure handling is on use |
382 // the padded average size of the promotion for each | |
383 // young generation collection. | |
384 double CMSStats::time_until_cms_gen_full() const { | |
385 size_t cms_free = _cms_gen->cmsSpace()->free(); | |
386 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
387 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
|
388 (size_t) _cms_gen->gc_stats()->avg_promoted()->padded_average()); |
0 | 389 if (cms_free > expected_promotion) { |
390 // Start a cms collection if there isn't enough space to promote | |
391 // for the next minor collection. Use the padded average as | |
392 // a safety factor. | |
393 cms_free -= expected_promotion; | |
394 | |
395 // Adjust by the safety factor. | |
396 double cms_free_dbl = (double)cms_free; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
397 double cms_adjustment = (100.0 - CMSIncrementalSafetyFactor)/100.0; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
398 // Apply a further correction factor which tries to adjust |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
399 // for recent occurance of concurrent mode failures. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
400 cms_adjustment = cms_adjustment * cms_free_adjustment_factor(cms_free); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
401 cms_free_dbl = cms_free_dbl * cms_adjustment; |
0 | 402 |
403 if (PrintGCDetails && Verbose) { | |
404 gclog_or_tty->print_cr("CMSStats::time_until_cms_gen_full: cms_free " | |
405 SIZE_FORMAT " expected_promotion " SIZE_FORMAT, | |
406 cms_free, expected_promotion); | |
407 gclog_or_tty->print_cr(" cms_free_dbl %f cms_consumption_rate %f", | |
408 cms_free_dbl, cms_consumption_rate() + 1.0); | |
409 } | |
410 // Add 1 in case the consumption rate goes to zero. | |
411 return cms_free_dbl / (cms_consumption_rate() + 1.0); | |
412 } | |
413 return 0.0; | |
414 } | |
415 | |
416 // Compare the duration of the cms collection to the | |
417 // time remaining before the cms generation is empty. | |
418 // Note that the time from the start of the cms collection | |
419 // to the start of the cms sweep (less than the total | |
420 // duration of the cms collection) can be used. This | |
421 // has been tried and some applications experienced | |
422 // promotion failures early in execution. This was | |
423 // possibly because the averages were not accurate | |
424 // enough at the beginning. | |
425 double CMSStats::time_until_cms_start() const { | |
426 // We add "gc0_period" to the "work" calculation | |
427 // below because this query is done (mostly) at the | |
428 // end of a scavenge, so we need to conservatively | |
429 // account for that much possible delay | |
430 // in the query so as to avoid concurrent mode failures | |
431 // due to starting the collection just a wee bit too | |
432 // late. | |
433 double work = cms_duration() + gc0_period(); | |
434 double deadline = time_until_cms_gen_full(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
435 // If a concurrent mode failure occurred recently, we want to be |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
436 // more conservative and halve our expected time_until_cms_gen_full() |
0 | 437 if (work > deadline) { |
438 if (Verbose && PrintGCDetails) { | |
439 gclog_or_tty->print( | |
440 " CMSCollector: collect because of anticipated promotion " | |
441 "before full %3.7f + %3.7f > %3.7f ", cms_duration(), | |
442 gc0_period(), time_until_cms_gen_full()); | |
443 } | |
444 return 0.0; | |
445 } | |
446 return work - deadline; | |
447 } | |
448 | |
449 // Return a duty cycle based on old_duty_cycle and new_duty_cycle, limiting the | |
450 // amount of change to prevent wild oscillation. | |
451 unsigned int CMSStats::icms_damped_duty_cycle(unsigned int old_duty_cycle, | |
452 unsigned int new_duty_cycle) { | |
453 assert(old_duty_cycle <= 100, "bad input value"); | |
454 assert(new_duty_cycle <= 100, "bad input value"); | |
455 | |
456 // Note: use subtraction with caution since it may underflow (values are | |
457 // unsigned). Addition is safe since we're in the range 0-100. | |
458 unsigned int damped_duty_cycle = new_duty_cycle; | |
459 if (new_duty_cycle < old_duty_cycle) { | |
460 const unsigned int largest_delta = MAX2(old_duty_cycle / 4, 5U); | |
461 if (new_duty_cycle + largest_delta < old_duty_cycle) { | |
462 damped_duty_cycle = old_duty_cycle - largest_delta; | |
463 } | |
464 } else if (new_duty_cycle > old_duty_cycle) { | |
465 const unsigned int largest_delta = MAX2(old_duty_cycle / 4, 15U); | |
466 if (new_duty_cycle > old_duty_cycle + largest_delta) { | |
467 damped_duty_cycle = MIN2(old_duty_cycle + largest_delta, 100U); | |
468 } | |
469 } | |
470 assert(damped_duty_cycle <= 100, "invalid duty cycle computed"); | |
471 | |
472 if (CMSTraceIncrementalPacing) { | |
473 gclog_or_tty->print(" [icms_damped_duty_cycle(%d,%d) = %d] ", | |
474 old_duty_cycle, new_duty_cycle, damped_duty_cycle); | |
475 } | |
476 return damped_duty_cycle; | |
477 } | |
478 | |
479 unsigned int CMSStats::icms_update_duty_cycle_impl() { | |
480 assert(CMSIncrementalPacing && valid(), | |
481 "should be handled in icms_update_duty_cycle()"); | |
482 | |
483 double cms_time_so_far = cms_timer().seconds(); | |
484 double scaled_duration = cms_duration_per_mb() * _cms_used_at_gc0_end / M; | |
485 double scaled_duration_remaining = fabsd(scaled_duration - cms_time_so_far); | |
486 | |
487 // Avoid division by 0. | |
488 double time_until_full = MAX2(time_until_cms_gen_full(), 0.01); | |
489 double duty_cycle_dbl = 100.0 * scaled_duration_remaining / time_until_full; | |
490 | |
491 unsigned int new_duty_cycle = MIN2((unsigned int)duty_cycle_dbl, 100U); | |
492 if (new_duty_cycle > _icms_duty_cycle) { | |
493 // Avoid very small duty cycles (1 or 2); 0 is allowed. | |
494 if (new_duty_cycle > 2) { | |
495 _icms_duty_cycle = icms_damped_duty_cycle(_icms_duty_cycle, | |
496 new_duty_cycle); | |
497 } | |
498 } else if (_allow_duty_cycle_reduction) { | |
499 // The duty cycle is reduced only once per cms cycle (see record_cms_end()). | |
500 new_duty_cycle = icms_damped_duty_cycle(_icms_duty_cycle, new_duty_cycle); | |
501 // Respect the minimum duty cycle. | |
502 unsigned int min_duty_cycle = (unsigned int)CMSIncrementalDutyCycleMin; | |
503 _icms_duty_cycle = MAX2(new_duty_cycle, min_duty_cycle); | |
504 } | |
505 | |
506 if (PrintGCDetails || CMSTraceIncrementalPacing) { | |
507 gclog_or_tty->print(" icms_dc=%d ", _icms_duty_cycle); | |
508 } | |
509 | |
510 _allow_duty_cycle_reduction = false; | |
511 return _icms_duty_cycle; | |
512 } | |
513 | |
514 #ifndef PRODUCT | |
515 void CMSStats::print_on(outputStream *st) const { | |
516 st->print(" gc0_alpha=%d,cms_alpha=%d", _gc0_alpha, _cms_alpha); | |
517 st->print(",gc0_dur=%g,gc0_per=%g,gc0_promo=" SIZE_FORMAT, | |
518 gc0_duration(), gc0_period(), gc0_promoted()); | |
519 st->print(",cms_dur=%g,cms_dur_per_mb=%g,cms_per=%g,cms_alloc=" SIZE_FORMAT, | |
520 cms_duration(), cms_duration_per_mb(), | |
521 cms_period(), cms_allocated()); | |
522 st->print(",cms_since_beg=%g,cms_since_end=%g", | |
523 cms_time_since_begin(), cms_time_since_end()); | |
524 st->print(",cms_used_beg=" SIZE_FORMAT ",cms_used_end=" SIZE_FORMAT, | |
525 _cms_used_at_gc0_begin, _cms_used_at_gc0_end); | |
526 if (CMSIncrementalMode) { | |
527 st->print(",dc=%d", icms_duty_cycle()); | |
528 } | |
529 | |
530 if (valid()) { | |
531 st->print(",promo_rate=%g,cms_alloc_rate=%g", | |
532 promotion_rate(), cms_allocation_rate()); | |
533 st->print(",cms_consumption_rate=%g,time_until_full=%g", | |
534 cms_consumption_rate(), time_until_cms_gen_full()); | |
535 } | |
536 st->print(" "); | |
537 } | |
538 #endif // #ifndef PRODUCT | |
539 | |
540 CMSCollector::CollectorState CMSCollector::_collectorState = | |
541 CMSCollector::Idling; | |
542 bool CMSCollector::_foregroundGCIsActive = false; | |
543 bool CMSCollector::_foregroundGCShouldWait = false; | |
544 | |
545 CMSCollector::CMSCollector(ConcurrentMarkSweepGeneration* cmsGen, | |
546 CardTableRS* ct, | |
547 ConcurrentMarkSweepPolicy* cp): | |
548 _cmsGen(cmsGen), | |
549 _ct(ct), | |
550 _ref_processor(NULL), // will be set later | |
551 _conc_workers(NULL), // may be set later | |
552 _abort_preclean(false), | |
553 _start_sampling(false), | |
554 _between_prologue_and_epilogue(false), | |
555 _markBitMap(0, Mutex::leaf + 1, "CMS_markBitMap_lock"), | |
556 _modUnionTable((CardTableModRefBS::card_shift - LogHeapWordSize), | |
557 -1 /* lock-free */, "No_lock" /* dummy */), | |
558 _modUnionClosure(&_modUnionTable), | |
559 _modUnionClosurePar(&_modUnionTable), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
560 // Adjust my span to cover old (cms) gen |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
561 _span(cmsGen->reserved()), |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
562 // Construct the is_alive_closure with _span & markBitMap |
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
563 _is_alive_closure(_span, &_markBitMap), |
0 | 564 _restart_addr(NULL), |
565 _overflow_list(NULL), | |
566 _stats(cmsGen), | |
567 _eden_chunk_array(NULL), // may be set in ctor body | |
568 _eden_chunk_capacity(0), // -- ditto -- | |
569 _eden_chunk_index(0), // -- ditto -- | |
570 _survivor_plab_array(NULL), // -- ditto -- | |
571 _survivor_chunk_array(NULL), // -- ditto -- | |
572 _survivor_chunk_capacity(0), // -- ditto -- | |
573 _survivor_chunk_index(0), // -- ditto -- | |
574 _ser_pmc_preclean_ovflw(0), | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
575 _ser_kac_preclean_ovflw(0), |
0 | 576 _ser_pmc_remark_ovflw(0), |
577 _par_pmc_remark_ovflw(0), | |
578 _ser_kac_ovflw(0), | |
579 _par_kac_ovflw(0), | |
580 #ifndef PRODUCT | |
581 _num_par_pushes(0), | |
582 #endif | |
583 _collection_count_start(0), | |
584 _verifying(false), | |
585 _icms_start_limit(NULL), | |
586 _icms_stop_limit(NULL), | |
587 _verification_mark_bm(0, Mutex::leaf + 1, "CMS_verification_mark_bm_lock"), | |
588 _completed_initialization(false), | |
589 _collector_policy(cp), | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
590 _should_unload_classes(false), |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
591 _concurrent_cycles_since_last_unload(0), |
798
fe1574da39fc
6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents:
679
diff
changeset
|
592 _roots_scanning_options(0), |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
593 _inter_sweep_estimate(CMS_SweepWeight, CMS_SweepPadding), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
594 _intra_sweep_estimate(CMS_SweepWeight, CMS_SweepPadding) |
0 | 595 { |
596 if (ExplicitGCInvokesConcurrentAndUnloadsClasses) { | |
597 ExplicitGCInvokesConcurrent = true; | |
598 } | |
599 // Now expand the span and allocate the collection support structures | |
600 // (MUT, marking bit map etc.) to cover both generations subject to | |
601 // collection. | |
602 | |
603 // For use by dirty card to oop closures. | |
604 _cmsGen->cmsSpace()->set_collector(this); | |
605 | |
606 // Allocate MUT and marking bit map | |
607 { | |
608 MutexLockerEx x(_markBitMap.lock(), Mutex::_no_safepoint_check_flag); | |
609 if (!_markBitMap.allocate(_span)) { | |
610 warning("Failed to allocate CMS Bit Map"); | |
611 return; | |
612 } | |
613 assert(_markBitMap.covers(_span), "_markBitMap inconsistency?"); | |
614 } | |
615 { | |
616 _modUnionTable.allocate(_span); | |
617 assert(_modUnionTable.covers(_span), "_modUnionTable inconsistency?"); | |
618 } | |
619 | |
1284 | 620 if (!_markStack.allocate(MarkStackSize)) { |
0 | 621 warning("Failed to allocate CMS Marking Stack"); |
622 return; | |
623 } | |
624 | |
625 // Support for multi-threaded concurrent phases | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
626 if (CMSConcurrentMTEnabled) { |
1284 | 627 if (FLAG_IS_DEFAULT(ConcGCThreads)) { |
0 | 628 // just for now |
1284 | 629 FLAG_SET_DEFAULT(ConcGCThreads, (ParallelGCThreads + 3)/4); |
630 } | |
631 if (ConcGCThreads > 1) { | |
0 | 632 _conc_workers = new YieldingFlexibleWorkGang("Parallel CMS Threads", |
1284 | 633 ConcGCThreads, true); |
0 | 634 if (_conc_workers == NULL) { |
635 warning("GC/CMS: _conc_workers allocation failure: " | |
636 "forcing -CMSConcurrentMTEnabled"); | |
637 CMSConcurrentMTEnabled = false; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
638 } else { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
639 _conc_workers->initialize_workers(); |
0 | 640 } |
641 } else { | |
642 CMSConcurrentMTEnabled = false; | |
643 } | |
644 } | |
645 if (!CMSConcurrentMTEnabled) { | |
1284 | 646 ConcGCThreads = 0; |
0 | 647 } else { |
648 // Turn off CMSCleanOnEnter optimization temporarily for | |
649 // the MT case where it's not fixed yet; see 6178663. | |
650 CMSCleanOnEnter = false; | |
651 } | |
1284 | 652 assert((_conc_workers != NULL) == (ConcGCThreads > 1), |
0 | 653 "Inconsistency"); |
654 | |
655 // Parallel task queues; these are shared for the | |
656 // concurrent and stop-world phases of CMS, but | |
657 // are not shared with parallel scavenge (ParNew). | |
658 { | |
659 uint i; | |
1284 | 660 uint num_queues = (uint) MAX2(ParallelGCThreads, ConcGCThreads); |
0 | 661 |
662 if ((CMSParallelRemarkEnabled || CMSConcurrentMTEnabled | |
663 || ParallelRefProcEnabled) | |
664 && num_queues > 0) { | |
665 _task_queues = new OopTaskQueueSet(num_queues); | |
666 if (_task_queues == NULL) { | |
667 warning("task_queues allocation failure."); | |
668 return; | |
669 } | |
6197 | 670 _hash_seed = NEW_C_HEAP_ARRAY(int, num_queues, mtGC); |
0 | 671 if (_hash_seed == NULL) { |
672 warning("_hash_seed array allocation failure"); | |
673 return; | |
674 } | |
675 | |
1665 | 676 typedef Padded<OopTaskQueue> PaddedOopTaskQueue; |
0 | 677 for (i = 0; i < num_queues; i++) { |
1665 | 678 PaddedOopTaskQueue *q = new PaddedOopTaskQueue(); |
679 if (q == NULL) { | |
0 | 680 warning("work_queue allocation failure."); |
681 return; | |
682 } | |
1665 | 683 _task_queues->register_queue(i, q); |
0 | 684 } |
685 for (i = 0; i < num_queues; i++) { | |
686 _task_queues->queue(i)->initialize(); | |
687 _hash_seed[i] = 17; // copied from ParNew | |
688 } | |
689 } | |
690 } | |
691 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
692 _cmsGen ->init_initiating_occupancy(CMSInitiatingOccupancyFraction, CMSTriggerRatio); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
693 |
0 | 694 // Clip CMSBootstrapOccupancy between 0 and 100. |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
695 _bootstrap_occupancy = ((double)MIN2((uintx)100, MAX2((uintx)0, CMSBootstrapOccupancy))) |
0 | 696 /(double)100; |
697 | |
698 _full_gcs_since_conc_gc = 0; | |
699 | |
700 // Now tell CMS generations the identity of their collector | |
701 ConcurrentMarkSweepGeneration::set_collector(this); | |
702 | |
703 // Create & start a CMS thread for this CMS collector | |
704 _cmsThread = ConcurrentMarkSweepThread::start(this); | |
705 assert(cmsThread() != NULL, "CMS Thread should have been created"); | |
706 assert(cmsThread()->collector() == this, | |
707 "CMS Thread should refer to this gen"); | |
708 assert(CGC_lock != NULL, "Where's the CGC_lock?"); | |
709 | |
710 // Support for parallelizing young gen rescan | |
711 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
712 _young_gen = gch->prev_gen(_cmsGen); | |
713 if (gch->supports_inline_contig_alloc()) { | |
714 _top_addr = gch->top_addr(); | |
715 _end_addr = gch->end_addr(); | |
716 assert(_young_gen != NULL, "no _young_gen"); | |
717 _eden_chunk_index = 0; | |
718 _eden_chunk_capacity = (_young_gen->max_capacity()+CMSSamplingGrain)/CMSSamplingGrain; | |
6197 | 719 _eden_chunk_array = NEW_C_HEAP_ARRAY(HeapWord*, _eden_chunk_capacity, mtGC); |
0 | 720 if (_eden_chunk_array == NULL) { |
721 _eden_chunk_capacity = 0; | |
722 warning("GC/CMS: _eden_chunk_array allocation failure"); | |
723 } | |
724 } | |
725 assert(_eden_chunk_array != NULL || _eden_chunk_capacity == 0, "Error"); | |
726 | |
727 // Support for parallelizing survivor space rescan | |
728 if (CMSParallelRemarkEnabled && CMSParallelSurvivorRemarkEnabled) { | |
1289
d47555d7aca8
6910182: CMS: assert(_cursor[j] == _survivor_plab_array[j].end(),"Ctl pt invariant")
jmasa
parents:
1284
diff
changeset
|
729 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
|
730 ((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
|
731 |
6197 | 732 _survivor_plab_array = NEW_C_HEAP_ARRAY(ChunkArray, ParallelGCThreads, mtGC); |
733 _survivor_chunk_array = NEW_C_HEAP_ARRAY(HeapWord*, 2*max_plab_samples, mtGC); | |
734 _cursor = NEW_C_HEAP_ARRAY(size_t, ParallelGCThreads, mtGC); | |
0 | 735 if (_survivor_plab_array == NULL || _survivor_chunk_array == NULL |
736 || _cursor == NULL) { | |
737 warning("Failed to allocate survivor plab/chunk array"); | |
738 if (_survivor_plab_array != NULL) { | |
6197 | 739 FREE_C_HEAP_ARRAY(ChunkArray, _survivor_plab_array, mtGC); |
0 | 740 _survivor_plab_array = NULL; |
741 } | |
742 if (_survivor_chunk_array != NULL) { | |
6197 | 743 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_chunk_array, mtGC); |
0 | 744 _survivor_chunk_array = NULL; |
745 } | |
746 if (_cursor != NULL) { | |
6197 | 747 FREE_C_HEAP_ARRAY(size_t, _cursor, mtGC); |
0 | 748 _cursor = NULL; |
749 } | |
750 } else { | |
751 _survivor_chunk_capacity = 2*max_plab_samples; | |
752 for (uint i = 0; i < ParallelGCThreads; i++) { | |
6197 | 753 HeapWord** vec = NEW_C_HEAP_ARRAY(HeapWord*, max_plab_samples, mtGC); |
0 | 754 if (vec == NULL) { |
755 warning("Failed to allocate survivor plab array"); | |
756 for (int j = i; j > 0; j--) { | |
6197 | 757 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_plab_array[j-1].array(), mtGC); |
0 | 758 } |
6197 | 759 FREE_C_HEAP_ARRAY(ChunkArray, _survivor_plab_array, mtGC); |
760 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_chunk_array, mtGC); | |
0 | 761 _survivor_plab_array = NULL; |
762 _survivor_chunk_array = NULL; | |
763 _survivor_chunk_capacity = 0; | |
764 break; | |
765 } else { | |
766 ChunkArray* cur = | |
767 ::new (&_survivor_plab_array[i]) ChunkArray(vec, | |
768 max_plab_samples); | |
769 assert(cur->end() == 0, "Should be 0"); | |
770 assert(cur->array() == vec, "Should be vec"); | |
771 assert(cur->capacity() == max_plab_samples, "Error"); | |
772 } | |
773 } | |
774 } | |
775 } | |
776 assert( ( _survivor_plab_array != NULL | |
777 && _survivor_chunk_array != NULL) | |
778 || ( _survivor_chunk_capacity == 0 | |
779 && _survivor_chunk_index == 0), | |
780 "Error"); | |
781 | |
782 // Choose what strong roots should be scanned depending on verification options | |
783 if (!CMSClassUnloadingEnabled) { | |
784 // If class unloading is disabled we want to include all classes into the root set. | |
785 add_root_scanning_option(SharedHeap::SO_AllClasses); | |
786 } else { | |
787 add_root_scanning_option(SharedHeap::SO_SystemClasses); | |
788 } | |
789 | |
790 NOT_PRODUCT(_overflow_counter = CMSMarkStackOverflowInterval;) | |
791 _gc_counters = new CollectorCounters("CMS", 1); | |
792 _completed_initialization = true; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
793 _inter_sweep_timer.start(); // start of time |
0 | 794 } |
795 | |
796 const char* ConcurrentMarkSweepGeneration::name() const { | |
797 return "concurrent mark-sweep generation"; | |
798 } | |
799 void ConcurrentMarkSweepGeneration::update_counters() { | |
800 if (UsePerfData) { | |
801 _space_counters->update_all(); | |
802 _gen_counters->update_all(); | |
803 } | |
804 } | |
805 | |
806 // this is an optimized version of update_counters(). it takes the | |
807 // used value as a parameter rather than computing it. | |
808 // | |
809 void ConcurrentMarkSweepGeneration::update_counters(size_t used) { | |
810 if (UsePerfData) { | |
811 _space_counters->update_used(used); | |
812 _space_counters->update_capacity(); | |
813 _gen_counters->update_all(); | |
814 } | |
815 } | |
816 | |
817 void ConcurrentMarkSweepGeneration::print() const { | |
818 Generation::print(); | |
819 cmsSpace()->print(); | |
820 } | |
821 | |
822 #ifndef PRODUCT | |
823 void ConcurrentMarkSweepGeneration::print_statistics() { | |
824 cmsSpace()->printFLCensus(0); | |
825 } | |
826 #endif | |
827 | |
828 void ConcurrentMarkSweepGeneration::printOccupancy(const char *s) { | |
829 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
830 if (PrintGCDetails) { | |
831 if (Verbose) { | |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6885
diff
changeset
|
832 gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"("SIZE_FORMAT")]", |
0 | 833 level(), short_name(), s, used(), capacity()); |
834 } else { | |
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"K("SIZE_FORMAT"K)]", |
0 | 836 level(), short_name(), s, used() / K, capacity() / K); |
837 } | |
838 } | |
839 if (Verbose) { | |
840 gclog_or_tty->print(" "SIZE_FORMAT"("SIZE_FORMAT")", | |
841 gch->used(), gch->capacity()); | |
842 } else { | |
843 gclog_or_tty->print(" "SIZE_FORMAT"K("SIZE_FORMAT"K)", | |
844 gch->used() / K, gch->capacity() / K); | |
845 } | |
846 } | |
847 | |
848 size_t | |
849 ConcurrentMarkSweepGeneration::contiguous_available() const { | |
850 // dld proposes an improvement in precision here. If the committed | |
851 // part of the space ends in a free block we should add that to | |
852 // uncommitted size in the calculation below. Will make this | |
853 // change later, staying with the approximation below for the | |
854 // time being. -- ysr. | |
855 return MAX2(_virtual_space.uncommitted_size(), unsafe_max_alloc_nogc()); | |
856 } | |
857 | |
858 size_t | |
859 ConcurrentMarkSweepGeneration::unsafe_max_alloc_nogc() const { | |
860 return _cmsSpace->max_alloc_in_words() * HeapWordSize; | |
861 } | |
862 | |
863 size_t ConcurrentMarkSweepGeneration::max_available() const { | |
864 return free() + _virtual_space.uncommitted_size(); | |
865 } | |
866 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
867 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
|
868 size_t available = max_available(); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
869 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
|
870 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
|
871 if (Verbose && PrintGCDetails) { |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
872 gclog_or_tty->print_cr( |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
873 "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
|
874 "max_promo("SIZE_FORMAT")", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
875 res? "":" not", available, res? ">=":"<", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
876 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
|
877 } |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
878 return res; |
0 | 879 } |
880 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
881 // At a promotion failure dump information on block layout in heap |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
882 // (cms old generation). |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
883 void ConcurrentMarkSweepGeneration::promotion_failure_occurred() { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
884 if (CMSDumpAtPromotionFailure) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
885 cmsSpace()->dump_at_safepoint_with_locks(collector(), gclog_or_tty); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
886 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
887 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
888 |
0 | 889 CompactibleSpace* |
890 ConcurrentMarkSweepGeneration::first_compaction_space() const { | |
891 return _cmsSpace; | |
892 } | |
893 | |
894 void ConcurrentMarkSweepGeneration::reset_after_compaction() { | |
895 // Clear the promotion information. These pointers can be adjusted | |
896 // along with all the other pointers into the heap but | |
897 // compaction is expected to be a rare event with | |
898 // 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
|
899 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 900 for (uint i = 0; i < ParallelGCThreads; i++) { |
901 _par_gc_thread_states[i]->promo.reset(); | |
902 } | |
903 } | |
904 } | |
905 | |
906 void ConcurrentMarkSweepGeneration::space_iterate(SpaceClosure* blk, bool usedOnly) { | |
907 blk->do_space(_cmsSpace); | |
908 } | |
909 | |
910 void ConcurrentMarkSweepGeneration::compute_new_size() { | |
911 assert_locked_or_safepoint(Heap_lock); | |
912 | |
913 // If incremental collection failed, we just want to expand | |
914 // to the limit. | |
915 if (incremental_collection_failed()) { | |
916 clear_incremental_collection_failed(); | |
917 grow_to_reserved(); | |
918 return; | |
919 } | |
920 | |
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
|
921 // 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
|
922 // 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
|
923 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
924 CardGeneration::compute_new_size(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
925 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
926 // 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
|
927 if (did_compact()) { |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
928 cmsSpace()->reset_after_compaction(); |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
929 } |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
930 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
931 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
932 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
|
933 assert_locked_or_safepoint(Heap_lock); |
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 // 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
|
936 // to the limit. |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
937 if (incremental_collection_failed()) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
938 clear_incremental_collection_failed(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
939 grow_to_reserved(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
940 return; |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
941 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
942 |
0 | 943 double free_percentage = ((double) free()) / capacity(); |
944 double desired_free_percentage = (double) MinHeapFreeRatio / 100; | |
945 double maximum_free_percentage = (double) MaxHeapFreeRatio / 100; | |
946 | |
947 // compute expansion delta needed for reaching desired free percentage | |
948 if (free_percentage < desired_free_percentage) { | |
949 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); | |
950 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
|
951 size_t expand_bytes = MAX2(desired_capacity - capacity(), MinHeapDeltaBytes); |
0 | 952 if (PrintGCDetails && Verbose) { |
953 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); | |
954 gclog_or_tty->print_cr("\nFrom compute_new_size: "); | |
955 gclog_or_tty->print_cr(" Free fraction %f", free_percentage); | |
956 gclog_or_tty->print_cr(" Desired free fraction %f", | |
957 desired_free_percentage); | |
958 gclog_or_tty->print_cr(" Maximum free fraction %f", | |
959 maximum_free_percentage); | |
960 gclog_or_tty->print_cr(" Capactiy "SIZE_FORMAT, capacity()/1000); | |
961 gclog_or_tty->print_cr(" Desired capacity "SIZE_FORMAT, | |
962 desired_capacity/1000); | |
963 int prev_level = level() - 1; | |
964 if (prev_level >= 0) { | |
965 size_t prev_size = 0; | |
966 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
967 Generation* prev_gen = gch->_gens[prev_level]; | |
968 prev_size = prev_gen->capacity(); | |
969 gclog_or_tty->print_cr(" Younger gen size "SIZE_FORMAT, | |
970 prev_size/1000); | |
971 } | |
972 gclog_or_tty->print_cr(" unsafe_max_alloc_nogc "SIZE_FORMAT, | |
973 unsafe_max_alloc_nogc()/1000); | |
974 gclog_or_tty->print_cr(" contiguous available "SIZE_FORMAT, | |
975 contiguous_available()/1000); | |
976 gclog_or_tty->print_cr(" Expand by "SIZE_FORMAT" (bytes)", | |
977 expand_bytes); | |
978 } | |
979 // safe if expansion fails | |
980 expand(expand_bytes, 0, CMSExpansionCause::_satisfy_free_ratio); | |
981 if (PrintGCDetails && Verbose) { | |
982 gclog_or_tty->print_cr(" Expanded free fraction %f", | |
983 ((double) free()) / capacity()); | |
984 } | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
985 } else { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
986 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
|
987 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
|
988 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
|
989 // 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
|
990 if (shrink_bytes >= MinHeapDeltaBytes) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
991 shrink_free_list_by(shrink_bytes); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
992 } |
0 | 993 } |
994 } | |
995 | |
996 Mutex* ConcurrentMarkSweepGeneration::freelistLock() const { | |
997 return cmsSpace()->freelistLock(); | |
998 } | |
999 | |
1000 HeapWord* ConcurrentMarkSweepGeneration::allocate(size_t size, | |
1001 bool tlab) { | |
1002 CMSSynchronousYieldRequest yr; | |
1003 MutexLockerEx x(freelistLock(), | |
1004 Mutex::_no_safepoint_check_flag); | |
1005 return have_lock_and_allocate(size, tlab); | |
1006 } | |
1007 | |
1008 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
|
1009 bool tlab /* ignored */) { |
0 | 1010 assert_lock_strong(freelistLock()); |
1011 size_t adjustedSize = CompactibleFreeListSpace::adjustObjectSize(size); | |
1012 HeapWord* res = cmsSpace()->allocate(adjustedSize); | |
1013 // Allocate the object live (grey) if the background collector has | |
1014 // started marking. This is necessary because the marker may | |
1015 // have passed this address and consequently this object will | |
1016 // not otherwise be greyed and would be incorrectly swept up. | |
1017 // Note that if this object contains references, the writing | |
1018 // of those references will dirty the card containing this object | |
1019 // allowing the object to be blackened (and its references scanned) | |
1020 // either during a preclean phase or at the final checkpoint. | |
1021 if (res != NULL) { | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1022 // 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
|
1023 // 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
|
1024 // 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
|
1025 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
|
1026 assert(!((FreeChunk*)res)->is_free(), "Error, block will look free but show wrong size"); |
0 | 1027 collector()->direct_allocated(res, adjustedSize); |
1028 _direct_allocated_words += adjustedSize; | |
1029 // allocation counters | |
1030 NOT_PRODUCT( | |
1031 _numObjectsAllocated++; | |
1032 _numWordsAllocated += (int)adjustedSize; | |
1033 ) | |
1034 } | |
1035 return res; | |
1036 } | |
1037 | |
1038 // In the case of direct allocation by mutators in a generation that | |
1039 // is being concurrently collected, the object must be allocated | |
1040 // live (grey) if the background collector has started marking. | |
1041 // This is necessary because the marker may | |
1042 // have passed this address and consequently this object will | |
1043 // not otherwise be greyed and would be incorrectly swept up. | |
1044 // Note that if this object contains references, the writing | |
1045 // of those references will dirty the card containing this object | |
1046 // allowing the object to be blackened (and its references scanned) | |
1047 // either during a preclean phase or at the final checkpoint. | |
1048 void CMSCollector::direct_allocated(HeapWord* start, size_t size) { | |
1049 assert(_markBitMap.covers(start, size), "Out of bounds"); | |
1050 if (_collectorState >= Marking) { | |
1051 MutexLockerEx y(_markBitMap.lock(), | |
1052 Mutex::_no_safepoint_check_flag); | |
1053 // [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
|
1054 // |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1055 // Can the P-bits be deleted now? JJJ |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1056 // |
0 | 1057 // 1. need to mark the object as live so it isn't collected |
1058 // 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
|
1059 // 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
|
1060 // 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
|
1061 // 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
|
1062 // 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
|
1063 // as soon as they are initialized.) |
0 | 1064 _markBitMap.mark(start); // object is live |
1065 _markBitMap.mark(start + 1); // object is potentially uninitialized? | |
1066 _markBitMap.mark(start + size - 1); | |
1067 // mark end of object | |
1068 } | |
1069 // check that oop looks uninitialized | |
187 | 1070 assert(oop(start)->klass_or_null() == NULL, "_klass should be NULL"); |
0 | 1071 } |
1072 | |
1073 void CMSCollector::promoted(bool par, HeapWord* start, | |
1074 bool is_obj_array, size_t obj_size) { | |
1075 assert(_markBitMap.covers(start), "Out of bounds"); | |
1076 // See comment in direct_allocated() about when objects should | |
1077 // be allocated live. | |
1078 if (_collectorState >= Marking) { | |
1079 // we already hold the marking bit map lock, taken in | |
1080 // the prologue | |
1081 if (par) { | |
1082 _markBitMap.par_mark(start); | |
1083 } else { | |
1084 _markBitMap.mark(start); | |
1085 } | |
1086 // We don't need to mark the object as uninitialized (as | |
1087 // in direct_allocated above) because this is being done with the | |
1088 // 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
|
1089 // 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
|
1090 // 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
|
1091 // 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
|
1092 // 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
|
1093 // 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
|
1094 // 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
|
1095 // becoming a bona-fide object when the copy/promotion is complete. |
0 | 1096 assert(SafepointSynchronize::is_at_safepoint(), |
1097 "expect promotion only at safepoints"); | |
1098 | |
1099 if (_collectorState < Sweeping) { | |
1100 // Mark the appropriate cards in the modUnionTable, so that | |
1101 // this object gets scanned before the sweep. If this is | |
1102 // not done, CMS generation references in the object might | |
1103 // not get marked. | |
1104 // For the case of arrays, which are otherwise precisely | |
1105 // marked, we need to dirty the entire array, not just its head. | |
1106 if (is_obj_array) { | |
1107 // The [par_]mark_range() method expects mr.end() below to | |
1108 // be aligned to the granularity of a bit's representation | |
1109 // in the heap. In the case of the MUT below, that's a | |
1110 // card size. | |
1111 MemRegion mr(start, | |
1112 (HeapWord*)round_to((intptr_t)(start + obj_size), | |
1113 CardTableModRefBS::card_size /* bytes */)); | |
1114 if (par) { | |
1115 _modUnionTable.par_mark_range(mr); | |
1116 } else { | |
1117 _modUnionTable.mark_range(mr); | |
1118 } | |
1119 } else { // not an obj array; we can just mark the head | |
1120 if (par) { | |
1121 _modUnionTable.par_mark(start); | |
1122 } else { | |
1123 _modUnionTable.mark(start); | |
1124 } | |
1125 } | |
1126 } | |
1127 } | |
1128 } | |
1129 | |
1130 static inline size_t percent_of_space(Space* space, HeapWord* addr) | |
1131 { | |
1132 size_t delta = pointer_delta(addr, space->bottom()); | |
1133 return (size_t)(delta * 100.0 / (space->capacity() / HeapWordSize)); | |
1134 } | |
1135 | |
1136 void CMSCollector::icms_update_allocation_limits() | |
1137 { | |
1138 Generation* gen0 = GenCollectedHeap::heap()->get_gen(0); | |
1139 EdenSpace* eden = gen0->as_DefNewGeneration()->eden(); | |
1140 | |
1141 const unsigned int duty_cycle = stats().icms_update_duty_cycle(); | |
1142 if (CMSTraceIncrementalPacing) { | |
1143 stats().print(); | |
1144 } | |
1145 | |
1146 assert(duty_cycle <= 100, "invalid duty cycle"); | |
1147 if (duty_cycle != 0) { | |
1148 // The duty_cycle is a percentage between 0 and 100; convert to words and | |
1149 // then compute the offset from the endpoints of the space. | |
1150 size_t free_words = eden->free() / HeapWordSize; | |
1151 double free_words_dbl = (double)free_words; | |
1152 size_t duty_cycle_words = (size_t)(free_words_dbl * duty_cycle / 100.0); | |
1153 size_t offset_words = (free_words - duty_cycle_words) / 2; | |
1154 | |
1155 _icms_start_limit = eden->top() + offset_words; | |
1156 _icms_stop_limit = eden->end() - offset_words; | |
1157 | |
1158 // The limits may be adjusted (shifted to the right) by | |
1159 // CMSIncrementalOffset, to allow the application more mutator time after a | |
1160 // young gen gc (when all mutators were stopped) and before CMS starts and | |
1161 // takes away one or more cpus. | |
1162 if (CMSIncrementalOffset != 0) { | |
1163 double adjustment_dbl = free_words_dbl * CMSIncrementalOffset / 100.0; | |
1164 size_t adjustment = (size_t)adjustment_dbl; | |
1165 HeapWord* tmp_stop = _icms_stop_limit + adjustment; | |
1166 if (tmp_stop > _icms_stop_limit && tmp_stop < eden->end()) { | |
1167 _icms_start_limit += adjustment; | |
1168 _icms_stop_limit = tmp_stop; | |
1169 } | |
1170 } | |
1171 } | |
1172 if (duty_cycle == 0 || (_icms_start_limit == _icms_stop_limit)) { | |
1173 _icms_start_limit = _icms_stop_limit = eden->end(); | |
1174 } | |
1175 | |
1176 // Install the new start limit. | |
1177 eden->set_soft_end(_icms_start_limit); | |
1178 | |
1179 if (CMSTraceIncrementalMode) { | |
1180 gclog_or_tty->print(" icms alloc limits: " | |
1181 PTR_FORMAT "," PTR_FORMAT | |
1182 " (" SIZE_FORMAT "%%," SIZE_FORMAT "%%) ", | |
1183 _icms_start_limit, _icms_stop_limit, | |
1184 percent_of_space(eden, _icms_start_limit), | |
1185 percent_of_space(eden, _icms_stop_limit)); | |
1186 if (Verbose) { | |
1187 gclog_or_tty->print("eden: "); | |
1188 eden->print_on(gclog_or_tty); | |
1189 } | |
1190 } | |
1191 } | |
1192 | |
1193 // Any changes here should try to maintain the invariant | |
1194 // that if this method is called with _icms_start_limit | |
1195 // and _icms_stop_limit both NULL, then it should return NULL | |
1196 // and not notify the icms thread. | |
1197 HeapWord* | |
1198 CMSCollector::allocation_limit_reached(Space* space, HeapWord* top, | |
1199 size_t word_size) | |
1200 { | |
1201 // A start_limit equal to end() means the duty cycle is 0, so treat that as a | |
1202 // nop. | |
1203 if (CMSIncrementalMode && _icms_start_limit != space->end()) { | |
1204 if (top <= _icms_start_limit) { | |
1205 if (CMSTraceIncrementalMode) { | |
1206 space->print_on(gclog_or_tty); | |
1207 gclog_or_tty->stamp(); | |
1208 gclog_or_tty->print_cr(" start limit top=" PTR_FORMAT | |
1209 ", new limit=" PTR_FORMAT | |
1210 " (" SIZE_FORMAT "%%)", | |
1211 top, _icms_stop_limit, | |
1212 percent_of_space(space, _icms_stop_limit)); | |
1213 } | |
1214 ConcurrentMarkSweepThread::start_icms(); | |
1215 assert(top < _icms_stop_limit, "Tautology"); | |
1216 if (word_size < pointer_delta(_icms_stop_limit, top)) { | |
1217 return _icms_stop_limit; | |
1218 } | |
1219 | |
1220 // The allocation will cross both the _start and _stop limits, so do the | |
1221 // stop notification also and return end(). | |
1222 if (CMSTraceIncrementalMode) { | |
1223 space->print_on(gclog_or_tty); | |
1224 gclog_or_tty->stamp(); | |
1225 gclog_or_tty->print_cr(" +stop limit top=" PTR_FORMAT | |
1226 ", new limit=" PTR_FORMAT | |
1227 " (" SIZE_FORMAT "%%)", | |
1228 top, space->end(), | |
1229 percent_of_space(space, space->end())); | |
1230 } | |
1231 ConcurrentMarkSweepThread::stop_icms(); | |
1232 return space->end(); | |
1233 } | |
1234 | |
1235 if (top <= _icms_stop_limit) { | |
1236 if (CMSTraceIncrementalMode) { | |
1237 space->print_on(gclog_or_tty); | |
1238 gclog_or_tty->stamp(); | |
1239 gclog_or_tty->print_cr(" stop limit top=" PTR_FORMAT | |
1240 ", new limit=" PTR_FORMAT | |
1241 " (" SIZE_FORMAT "%%)", | |
1242 top, space->end(), | |
1243 percent_of_space(space, space->end())); | |
1244 } | |
1245 ConcurrentMarkSweepThread::stop_icms(); | |
1246 return space->end(); | |
1247 } | |
1248 | |
1249 if (CMSTraceIncrementalMode) { | |
1250 space->print_on(gclog_or_tty); | |
1251 gclog_or_tty->stamp(); | |
1252 gclog_or_tty->print_cr(" end limit top=" PTR_FORMAT | |
1253 ", new limit=" PTR_FORMAT, | |
1254 top, NULL); | |
1255 } | |
1256 } | |
1257 | |
1258 return NULL; | |
1259 } | |
1260 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1261 oop ConcurrentMarkSweepGeneration::promote(oop obj, size_t obj_size) { |
0 | 1262 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
1263 // allocate, copy and if necessary update promoinfo -- | |
1264 // delegate to underlying space. | |
1265 assert_lock_strong(freelistLock()); | |
1266 | |
1267 #ifndef PRODUCT | |
1268 if (Universe::heap()->promotion_should_fail()) { | |
1269 return NULL; | |
1270 } | |
1271 #endif // #ifndef PRODUCT | |
1272 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1273 oop res = _cmsSpace->promote(obj, obj_size); |
0 | 1274 if (res == NULL) { |
1275 // expand and retry | |
1276 size_t s = _cmsSpace->expansionSpaceRequired(obj_size); // HeapWords | |
1277 expand(s*HeapWordSize, MinHeapDeltaBytes, | |
1278 CMSExpansionCause::_satisfy_promotion); | |
1279 // Since there's currently no next generation, we don't try to promote | |
1280 // into a more senior generation. | |
1281 assert(next_gen() == NULL, "assumption, based upon which no attempt " | |
1282 "is made to pass on a possibly failing " | |
1283 "promotion to next generation"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1284 res = _cmsSpace->promote(obj, obj_size); |
0 | 1285 } |
1286 if (res != NULL) { | |
1287 // See comment in allocate() about when objects should | |
1288 // be allocated live. | |
1289 assert(obj->is_oop(), "Will dereference klass pointer below"); | |
1290 collector()->promoted(false, // Not parallel | |
1291 (HeapWord*)res, obj->is_objArray(), obj_size); | |
1292 // promotion counters | |
1293 NOT_PRODUCT( | |
1294 _numObjectsPromoted++; | |
1295 _numWordsPromoted += | |
1296 (int)(CompactibleFreeListSpace::adjustObjectSize(obj->size())); | |
1297 ) | |
1298 } | |
1299 return res; | |
1300 } | |
1301 | |
1302 | |
1303 HeapWord* | |
1304 ConcurrentMarkSweepGeneration::allocation_limit_reached(Space* space, | |
1305 HeapWord* top, | |
1306 size_t word_sz) | |
1307 { | |
1308 return collector()->allocation_limit_reached(space, top, word_sz); | |
1309 } | |
1310 | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1311 // 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
|
1312 // --------------------------------------------------- |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1313 // 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
|
1314 // 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
|
1315 // 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
|
1316 // 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
|
1317 // be accurately determined. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1318 // 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
|
1319 // ----------------------------------------------------- |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1320 // 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
|
1321 // |
1777
179464550c7d
6983930: CMS: Various small cleanups ca September 2010
ysr
parents:
1720
diff
changeset
|
1322 // 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
|
1323 // obj->size() computes correct size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1324 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1325 // 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
|
1326 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1327 // STATE IDENTIFICATION: (64 bit+COOPS) |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1328 // ------------------------------------ |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1329 // 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
|
1330 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1331 // 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
|
1332 // obj->size() computes correct 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 // 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
|
1335 // |
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 // STATE TRANSITION DIAGRAM |
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 // mut / parnew mut / parnew |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1340 // FREE --------------------> TRANSIENT ---------------------> OBJECT --| |
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 // |------------------------ DEAD <------------------------------------| |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1343 // sweep mut |
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 // 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
|
1346 // 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
|
1347 // 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
|
1348 // 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
|
1349 // 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
|
1350 |
0 | 1351 // Things to support parallel young-gen collection. |
1352 oop | |
1353 ConcurrentMarkSweepGeneration::par_promote(int thread_num, | |
1354 oop old, markOop m, | |
1355 size_t word_sz) { | |
1356 #ifndef PRODUCT | |
1357 if (Universe::heap()->promotion_should_fail()) { | |
1358 return NULL; | |
1359 } | |
1360 #endif // #ifndef PRODUCT | |
1361 | |
1362 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1363 PromotionInfo* promoInfo = &ps->promo; | |
1364 // if we are tracking promotions, then first ensure space for | |
1365 // promotion (including spooling space for saving header if necessary). | |
1366 // then allocate and copy, then track promoted info if needed. | |
1367 // When tracking (see PromotionInfo::track()), the mark word may | |
1368 // be displaced and in this case restoration of the mark word | |
1369 // occurs in the (oop_since_save_marks_)iterate phase. | |
1370 if (promoInfo->tracking() && !promoInfo->ensure_spooling_space()) { | |
1371 // Out of space for allocating spooling buffers; | |
1372 // try expanding and allocating spooling buffers. | |
1373 if (!expand_and_ensure_spooling_space(promoInfo)) { | |
1374 return NULL; | |
1375 } | |
1376 } | |
1377 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
|
1378 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
|
1379 HeapWord* obj_ptr = ps->lab.alloc(alloc_sz); |
0 | 1380 if (obj_ptr == NULL) { |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1381 obj_ptr = expand_and_par_lab_allocate(ps, alloc_sz); |
0 | 1382 if (obj_ptr == NULL) { |
1383 return NULL; | |
1384 } | |
1385 } | |
1386 oop obj = oop(obj_ptr); | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1387 OrderAccess::storestore(); |
187 | 1388 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
|
1389 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
|
1390 // IMPORTANT: See note on object initialization for CMS above. |
0 | 1391 // Otherwise, copy the object. Here we must be careful to insert the |
1392 // klass pointer last, since this marks the block as an allocated object. | |
187 | 1393 // Except with compressed oops it's the mark word. |
0 | 1394 HeapWord* old_ptr = (HeapWord*)old; |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1395 // Restore the mark word copied above. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1396 obj->set_mark(m); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1397 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
|
1398 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
|
1399 OrderAccess::storestore(); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1400 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1401 if (UseCompressedKlassPointers) { |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1402 // 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
|
1403 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
|
1404 } |
0 | 1405 if (word_sz > (size_t)oopDesc::header_size()) { |
1406 Copy::aligned_disjoint_words(old_ptr + oopDesc::header_size(), | |
1407 obj_ptr + oopDesc::header_size(), | |
1408 word_sz - oopDesc::header_size()); | |
1409 } | |
187 | 1410 |
0 | 1411 // Now we can track the promoted object, if necessary. We take care |
1521 | 1412 // to delay the transition from uninitialized to full object |
0 | 1413 // (i.e., insertion of klass pointer) until after, so that it |
1414 // atomically becomes a promoted object. | |
1415 if (promoInfo->tracking()) { | |
1416 promoInfo->track((PromotedObject*)obj, old->klass()); | |
1417 } | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1418 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
|
1419 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
|
1420 assert(old->is_oop(), "Will use and dereference old klass ptr below"); |
187 | 1421 |
1422 // 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
|
1423 OrderAccess::storestore(); |
0 | 1424 obj->set_klass(old->klass()); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1425 // 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
|
1426 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
|
1427 |
0 | 1428 collector()->promoted(true, // parallel |
1429 obj_ptr, old->is_objArray(), word_sz); | |
1430 | |
1431 NOT_PRODUCT( | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1432 Atomic::inc_ptr(&_numObjectsPromoted); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1433 Atomic::add_ptr(alloc_sz, &_numWordsPromoted); |
0 | 1434 ) |
1435 | |
1436 return obj; | |
1437 } | |
1438 | |
1439 void | |
1440 ConcurrentMarkSweepGeneration:: | |
1441 par_promote_alloc_undo(int thread_num, | |
1442 HeapWord* obj, size_t word_sz) { | |
1443 // CMS does not support promotion undo. | |
1444 ShouldNotReachHere(); | |
1445 } | |
1446 | |
1447 void | |
1448 ConcurrentMarkSweepGeneration:: | |
1449 par_promote_alloc_done(int thread_num) { | |
1450 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
1451 ps->lab.retire(thread_num); |
0 | 1452 } |
1453 | |
1454 void | |
1455 ConcurrentMarkSweepGeneration:: | |
1456 par_oop_since_save_marks_iterate_done(int thread_num) { | |
1457 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1458 ParScanWithoutBarrierClosure* dummy_cl = NULL; | |
1459 ps->promo.promoted_oops_iterate_nv(dummy_cl); | |
1460 } | |
1461 | |
1462 bool ConcurrentMarkSweepGeneration::should_collect(bool full, | |
1463 size_t size, | |
1464 bool tlab) | |
1465 { | |
1466 // We allow a STW collection only if a full | |
1467 // collection was requested. | |
1468 return full || should_allocate(size, tlab); // FIX ME !!! | |
1469 // This and promotion failure handling are connected at the | |
1470 // hip and should be fixed by untying them. | |
1471 } | |
1472 | |
1473 bool CMSCollector::shouldConcurrentCollect() { | |
1474 if (_full_gc_requested) { | |
1475 if (Verbose && PrintGCDetails) { | |
1476 gclog_or_tty->print_cr("CMSCollector: collect because of explicit " | |
1520
bb843ebc7c55
6919638: CMS: ExplicitGCInvokesConcurrent misinteracts with gc locker
ysr
parents:
1518
diff
changeset
|
1477 " gc request (or gc_locker)"); |
0 | 1478 } |
1479 return true; | |
1480 } | |
1481 | |
1482 // For debugging purposes, change the type of collection. | |
1483 // If the rotation is not on the concurrent collection | |
1484 // type, don't start a concurrent collection. | |
1485 NOT_PRODUCT( | |
1486 if (RotateCMSCollectionTypes && | |
1487 (_cmsGen->debug_collection_type() != | |
1488 ConcurrentMarkSweepGeneration::Concurrent_collection_type)) { | |
1489 assert(_cmsGen->debug_collection_type() != | |
1490 ConcurrentMarkSweepGeneration::Unknown_collection_type, | |
1491 "Bad cms collection type"); | |
1492 return false; | |
1493 } | |
1494 ) | |
1495 | |
1496 FreelistLocker x(this); | |
1497 // ------------------------------------------------------------------ | |
1498 // Print out lots of information which affects the initiation of | |
1499 // a collection. | |
1500 if (PrintCMSInitiationStatistics && stats().valid()) { | |
1501 gclog_or_tty->print("CMSCollector shouldConcurrentCollect: "); | |
1502 gclog_or_tty->stamp(); | |
1503 gclog_or_tty->print_cr(""); | |
1504 stats().print_on(gclog_or_tty); | |
1505 gclog_or_tty->print_cr("time_until_cms_gen_full %3.7f", | |
1506 stats().time_until_cms_gen_full()); | |
1507 gclog_or_tty->print_cr("free="SIZE_FORMAT, _cmsGen->free()); | |
1508 gclog_or_tty->print_cr("contiguous_available="SIZE_FORMAT, | |
1509 _cmsGen->contiguous_available()); | |
1510 gclog_or_tty->print_cr("promotion_rate=%g", stats().promotion_rate()); | |
1511 gclog_or_tty->print_cr("cms_allocation_rate=%g", stats().cms_allocation_rate()); | |
1512 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
|
1513 gclog_or_tty->print_cr("initiatingOccupancy=%3.7f", _cmsGen->initiating_occupancy()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1514 gclog_or_tty->print_cr("metadata initialized %d", |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1515 MetaspaceGC::should_concurrent_collect()); |
0 | 1516 } |
1517 // ------------------------------------------------------------------ | |
1518 | |
1519 // If the estimated time to complete a cms collection (cms_duration()) | |
1520 // is less than the estimated time remaining until the cms generation | |
1521 // is full, start a collection. | |
1522 if (!UseCMSInitiatingOccupancyOnly) { | |
1523 if (stats().valid()) { | |
1524 if (stats().time_until_cms_start() == 0.0) { | |
1525 return true; | |
1526 } | |
1527 } else { | |
1528 // We want to conservatively collect somewhat early in order | |
1529 // to try and "bootstrap" our CMS/promotion statistics; | |
1530 // this branch will not fire after the first successful CMS | |
1531 // collection because the stats should then be valid. | |
1532 if (_cmsGen->occupancy() >= _bootstrap_occupancy) { | |
1533 if (Verbose && PrintGCDetails) { | |
1534 gclog_or_tty->print_cr( | |
1535 " CMSCollector: collect for bootstrapping statistics:" | |
1536 " occupancy = %f, boot occupancy = %f", _cmsGen->occupancy(), | |
1537 _bootstrap_occupancy); | |
1538 } | |
1539 return true; | |
1540 } | |
1541 } | |
1542 } | |
1543 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1544 // Otherwise, we start a collection cycle if |
0 | 1545 // old gen want a collection cycle started. Each may use |
1546 // an appropriate criterion for making this decision. | |
1547 // 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
|
1548 // 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
|
1549 if (_cmsGen->should_concurrent_collect()) { |
0 | 1550 if (Verbose && PrintGCDetails) { |
1551 gclog_or_tty->print_cr("CMS old gen initiated"); | |
1552 } | |
1553 return true; | |
1554 } | |
1555 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1556 // 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
|
1557 // 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
|
1558 // late anyway. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1559 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1560 assert(gch->collector_policy()->is_two_generation_policy(), |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1561 "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
|
1562 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
|
1563 if (Verbose && PrintGCDetails) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1564 gclog_or_tty->print("CMSCollector: collect because incremental collection will fail "); |
0 | 1565 } |
1566 return true; | |
1567 } | |
1568 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1569 if (MetaspaceGC::should_concurrent_collect()) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1570 if (Verbose && PrintGCDetails) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1571 gclog_or_tty->print("CMSCollector: collect for metadata allocation "); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1572 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1573 return true; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1574 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1575 |
0 | 1576 return false; |
1577 } | |
1578 | |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1579 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
|
1580 |
0 | 1581 // Clear _expansion_cause fields of constituent generations |
1582 void CMSCollector::clear_expansion_cause() { | |
1583 _cmsGen->clear_expansion_cause(); | |
1584 } | |
1585 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1586 // 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
|
1587 // 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
|
1588 // 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
|
1589 // 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
|
1590 // 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
|
1591 // UseCMSInitiatingOccupancyOnly. This also has the advantage of |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1592 // 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
|
1593 // collections. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1594 // 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
|
1595 // conditions hold: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1596 // . our current occupancy exceeds the configured initiating occupancy |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1597 // for this generation, or |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1598 // . 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
|
1599 // expansion, done a collection of this generation, or |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1600 // . 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
|
1601 // 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
|
1602 // 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
|
1603 // 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
|
1604 // the generation, etc... or ... |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1605 // [.(currently done by CMSCollector::shouldConcurrentCollect() only for |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1606 // 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
|
1607 // 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
|
1608 // 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
|
1609 bool ConcurrentMarkSweepGeneration::should_concurrent_collect() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1610 |
0 | 1611 assert_lock_strong(freelistLock()); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1612 if (occupancy() > initiating_occupancy()) { |
0 | 1613 if (PrintGCDetails && Verbose) { |
1614 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
|
1615 short_name(), occupancy(), initiating_occupancy()); |
0 | 1616 } |
1617 return true; | |
1618 } | |
1619 if (UseCMSInitiatingOccupancyOnly) { | |
1620 return false; | |
1621 } | |
1622 if (expansion_cause() == CMSExpansionCause::_satisfy_allocation) { | |
1623 if (PrintGCDetails && Verbose) { | |
1624 gclog_or_tty->print(" %s: collect because expanded for allocation ", | |
1625 short_name()); | |
1626 } | |
1627 return true; | |
1628 } | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1629 if (_cmsSpace->should_concurrent_collect()) { |
0 | 1630 if (PrintGCDetails && Verbose) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1631 gclog_or_tty->print(" %s: collect because cmsSpace says so ", |
0 | 1632 short_name()); |
1633 } | |
1634 return true; | |
1635 } | |
1636 return false; | |
1637 } | |
1638 | |
1639 void ConcurrentMarkSweepGeneration::collect(bool full, | |
1640 bool clear_all_soft_refs, | |
1641 size_t size, | |
1642 bool tlab) | |
1643 { | |
1644 collector()->collect(full, clear_all_soft_refs, size, tlab); | |
1645 } | |
1646 | |
1647 void CMSCollector::collect(bool full, | |
1648 bool clear_all_soft_refs, | |
1649 size_t size, | |
1650 bool tlab) | |
1651 { | |
1652 if (!UseCMSCollectionPassing && _collectorState > Idling) { | |
1653 // For debugging purposes skip the collection if the state | |
1654 // is not currently idle | |
1655 if (TraceCMSState) { | |
1656 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " skipped full:%d CMS state %d", | |
1657 Thread::current(), full, _collectorState); | |
1658 } | |
1659 return; | |
1660 } | |
1661 | |
1662 // The following "if" branch is present for defensive reasons. | |
1663 // In the current uses of this interface, it can be replaced with: | |
1664 // assert(!GC_locker.is_active(), "Can't be called otherwise"); | |
1665 // But I am not placing that assert here to allow future | |
1666 // generality in invoking this interface. | |
1667 if (GC_locker::is_active()) { | |
1668 // A consistency test for GC_locker | |
1669 assert(GC_locker::needs_gc(), "Should have been set already"); | |
1670 // Skip this foreground collection, instead | |
1671 // expanding the heap if necessary. | |
1672 // Need the free list locks for the call to free() in compute_new_size() | |
1673 compute_new_size(); | |
1674 return; | |
1675 } | |
1676 acquire_control_and_collect(full, clear_all_soft_refs); | |
1677 _full_gcs_since_conc_gc++; | |
1678 } | |
1679 | |
1680 void CMSCollector::request_full_gc(unsigned int full_gc_count) { | |
1681 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1682 unsigned int gc_count = gch->total_full_collections(); | |
1683 if (gc_count == full_gc_count) { | |
1684 MutexLockerEx y(CGC_lock, Mutex::_no_safepoint_check_flag); | |
1685 _full_gc_requested = true; | |
1686 CGC_lock->notify(); // nudge CMS thread | |
2365
a181f3a124dd
6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents:
2226
diff
changeset
|
1687 } else { |
a181f3a124dd
6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents:
2226
diff
changeset
|
1688 assert(gc_count > full_gc_count, "Error: causal loop"); |
0 | 1689 } |
1690 } | |
1691 | |
1692 | |
1693 // The foreground and background collectors need to coordinate in order | |
1694 // to make sure that they do not mutually interfere with CMS collections. | |
1695 // When a background collection is active, | |
1696 // the foreground collector may need to take over (preempt) and | |
1697 // synchronously complete an ongoing collection. Depending on the | |
1698 // frequency of the background collections and the heap usage | |
1699 // of the application, this preemption can be seldom or frequent. | |
1700 // There are only certain | |
1701 // points in the background collection that the "collection-baton" | |
1702 // can be passed to the foreground collector. | |
1703 // | |
1704 // The foreground collector will wait for the baton before | |
1705 // starting any part of the collection. The foreground collector | |
1706 // will only wait at one location. | |
1707 // | |
1708 // The background collector will yield the baton before starting a new | |
1709 // phase of the collection (e.g., before initial marking, marking from roots, | |
1710 // precleaning, final re-mark, sweep etc.) This is normally done at the head | |
1711 // of the loop which switches the phases. The background collector does some | |
1712 // of the phases (initial mark, final re-mark) with the world stopped. | |
1713 // Because of locking involved in stopping the world, | |
1714 // the foreground collector should not block waiting for the background | |
1715 // collector when it is doing a stop-the-world phase. The background | |
1716 // collector will yield the baton at an additional point just before | |
1717 // it enters a stop-the-world phase. Once the world is stopped, the | |
1718 // background collector checks the phase of the collection. If the | |
1719 // phase has not changed, it proceeds with the collection. If the | |
1720 // phase has changed, it skips that phase of the collection. See | |
1721 // the comments on the use of the Heap_lock in collect_in_background(). | |
1722 // | |
1723 // Variable used in baton passing. | |
1724 // _foregroundGCIsActive - Set to true by the foreground collector when | |
1725 // it wants the baton. The foreground clears it when it has finished | |
1726 // the collection. | |
1727 // _foregroundGCShouldWait - Set to true by the background collector | |
1728 // when it is running. The foreground collector waits while | |
1729 // _foregroundGCShouldWait is true. | |
1730 // CGC_lock - monitor used to protect access to the above variables | |
1731 // and to notify the foreground and background collectors. | |
1732 // _collectorState - current state of the CMS collection. | |
1733 // | |
1734 // The foreground collector | |
1735 // acquires the CGC_lock | |
1736 // sets _foregroundGCIsActive | |
1737 // waits on the CGC_lock for _foregroundGCShouldWait to be false | |
1738 // various locks acquired in preparation for the collection | |
1739 // are released so as not to block the background collector | |
1740 // that is in the midst of a collection | |
1741 // proceeds with the collection | |
1742 // clears _foregroundGCIsActive | |
1743 // returns | |
1744 // | |
1745 // The background collector in a loop iterating on the phases of the | |
1746 // collection | |
1747 // acquires the CGC_lock | |
1748 // sets _foregroundGCShouldWait | |
1749 // if _foregroundGCIsActive is set | |
1750 // clears _foregroundGCShouldWait, notifies _CGC_lock | |
1751 // waits on _CGC_lock for _foregroundGCIsActive to become false | |
1752 // and exits the loop. | |
1753 // otherwise | |
1754 // proceed with that phase of the collection | |
1755 // if the phase is a stop-the-world phase, | |
1756 // yield the baton once more just before enqueueing | |
1757 // the stop-world CMS operation (executed by the VM thread). | |
1758 // returns after all phases of the collection are done | |
1759 // | |
1760 | |
1761 void CMSCollector::acquire_control_and_collect(bool full, | |
1762 bool clear_all_soft_refs) { | |
1763 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | |
1764 assert(!Thread::current()->is_ConcurrentGC_thread(), | |
1765 "shouldn't try to acquire control from self!"); | |
1766 | |
1767 // Start the protocol for acquiring control of the | |
1768 // collection from the background collector (aka CMS thread). | |
1769 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
1770 "VM thread should have CMS token"); | |
1771 // Remember the possibly interrupted state of an ongoing | |
1772 // concurrent collection | |
1773 CollectorState first_state = _collectorState; | |
1774 | |
1775 // Signal to a possibly ongoing concurrent collection that | |
1776 // we want to do a foreground collection. | |
1777 _foregroundGCIsActive = true; | |
1778 | |
1779 // Disable incremental mode during a foreground collection. | |
1780 ICMSDisabler icms_disabler; | |
1781 | |
1782 // release locks and wait for a notify from the background collector | |
1783 // releasing the locks in only necessary for phases which | |
1784 // do yields to improve the granularity of the collection. | |
1785 assert_lock_strong(bitMapLock()); | |
1786 // We need to lock the Free list lock for the space that we are | |
1787 // currently collecting. | |
1788 assert(haveFreelistLocks(), "Must be holding free list locks"); | |
1789 bitMapLock()->unlock(); | |
1790 releaseFreelistLocks(); | |
1791 { | |
1792 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
1793 if (_foregroundGCShouldWait) { | |
1794 // We are going to be waiting for action for the CMS thread; | |
1795 // it had better not be gone (for instance at shutdown)! | |
1796 assert(ConcurrentMarkSweepThread::cmst() != NULL, | |
1797 "CMS thread must be running"); | |
1798 // Wait here until the background collector gives us the go-ahead | |
1799 ConcurrentMarkSweepThread::clear_CMS_flag( | |
1800 ConcurrentMarkSweepThread::CMS_vm_has_token); // release token | |
1801 // Get a possibly blocked CMS thread going: | |
1802 // Note that we set _foregroundGCIsActive true above, | |
1803 // without protection of the CGC_lock. | |
1804 CGC_lock->notify(); | |
1805 assert(!ConcurrentMarkSweepThread::vm_thread_wants_cms_token(), | |
1806 "Possible deadlock"); | |
1807 while (_foregroundGCShouldWait) { | |
1808 // wait for notification | |
1809 CGC_lock->wait(Mutex::_no_safepoint_check_flag); | |
1810 // Possibility of delay/starvation here, since CMS token does | |
1811 // not know to give priority to VM thread? Actually, i think | |
1812 // there wouldn't be any delay/starvation, but the proof of | |
1813 // that "fact" (?) appears non-trivial. XXX 20011219YSR | |
1814 } | |
1815 ConcurrentMarkSweepThread::set_CMS_flag( | |
1816 ConcurrentMarkSweepThread::CMS_vm_has_token); | |
1817 } | |
1818 } | |
1819 // The CMS_token is already held. Get back the other locks. | |
1820 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
1821 "VM thread should have CMS token"); | |
1822 getFreelistLocks(); | |
1823 bitMapLock()->lock_without_safepoint_check(); | |
1824 if (TraceCMSState) { | |
1825 gclog_or_tty->print_cr("CMS foreground collector has asked for control " | |
1826 INTPTR_FORMAT " with first state %d", Thread::current(), first_state); | |
1827 gclog_or_tty->print_cr(" gets control with state %d", _collectorState); | |
1828 } | |
1829 | |
1830 // Check if we need to do a compaction, or if not, whether | |
1831 // we need to start the mark-sweep from scratch. | |
1832 bool should_compact = false; | |
1833 bool should_start_over = false; | |
1834 decide_foreground_collection_type(clear_all_soft_refs, | |
1835 &should_compact, &should_start_over); | |
1836 | |
1837 NOT_PRODUCT( | |
1838 if (RotateCMSCollectionTypes) { | |
1839 if (_cmsGen->debug_collection_type() == | |
1840 ConcurrentMarkSweepGeneration::MSC_foreground_collection_type) { | |
1841 should_compact = true; | |
1842 } else if (_cmsGen->debug_collection_type() == | |
1843 ConcurrentMarkSweepGeneration::MS_foreground_collection_type) { | |
1844 should_compact = false; | |
1845 } | |
1846 } | |
1847 ) | |
1848 | |
1849 if (PrintGCDetails && first_state > Idling) { | |
1850 GCCause::Cause cause = GenCollectedHeap::heap()->gc_cause(); | |
1851 if (GCCause::is_user_requested_gc(cause) || | |
1852 GCCause::is_serviceability_requested_gc(cause)) { | |
1853 gclog_or_tty->print(" (concurrent mode interrupted)"); | |
1854 } else { | |
1855 gclog_or_tty->print(" (concurrent mode failure)"); | |
1856 } | |
1857 } | |
1858 | |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1859 set_did_compact(should_compact); |
0 | 1860 if (should_compact) { |
1861 // If the collection is being acquired from the background | |
1862 // collector, there may be references on the discovered | |
1863 // references lists that have NULL referents (being those | |
1864 // that were concurrently cleared by a mutator) or | |
1865 // that are no longer active (having been enqueued concurrently | |
1866 // by the mutator). | |
1867 // Scrub the list of those references because Mark-Sweep-Compact | |
1868 // code assumes referents are not NULL and that all discovered | |
1869 // Reference objects are active. | |
1870 ref_processor()->clean_up_discovered_references(); | |
1871 | |
1872 do_compaction_work(clear_all_soft_refs); | |
1873 | |
1874 // 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
|
1875 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
|
1876 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
|
1877 young_gen->to()->capacity() - |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1878 young_gen->from()->capacity(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1879 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1880 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
|
1881 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
|
1882 young_gen->eden()->used(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1883 _cmsGen->max_capacity(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1884 max_eden_size, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1885 full, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1886 gc_cause, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1887 gch->collector_policy()); |
0 | 1888 } else { |
1889 do_mark_sweep_work(clear_all_soft_refs, first_state, | |
1890 should_start_over); | |
1891 } | |
1892 // Reset the expansion cause, now that we just completed | |
1893 // a collection cycle. | |
1894 clear_expansion_cause(); | |
1895 _foregroundGCIsActive = false; | |
1896 return; | |
1897 } | |
1898 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1899 // Resize the tenured generation |
0 | 1900 // after obtaining the free list locks for the |
1901 // two generations. | |
1902 void CMSCollector::compute_new_size() { | |
1903 assert_locked_or_safepoint(Heap_lock); | |
1904 FreelistLocker z(this); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1905 MetaspaceGC::compute_new_size(); |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
1906 _cmsGen->compute_new_size_free_list(); |
0 | 1907 } |
1908 | |
1909 // A work method used by foreground collection to determine | |
1910 // what type of collection (compacting or not, continuing or fresh) | |
1911 // it should do. | |
1912 // NOTE: the intent is to make UseCMSCompactAtFullCollection | |
1913 // and CMSCompactWhenClearAllSoftRefs the default in the future | |
1914 // and do away with the flags after a suitable period. | |
1915 void CMSCollector::decide_foreground_collection_type( | |
1916 bool clear_all_soft_refs, bool* should_compact, | |
1917 bool* should_start_over) { | |
1918 // Normally, we'll compact only if the UseCMSCompactAtFullCollection | |
1919 // flag is set, and we have either requested a System.gc() or | |
1920 // the number of full gc's since the last concurrent cycle | |
1921 // has exceeded the threshold set by CMSFullGCsBeforeCompaction, | |
1922 // or if an incremental collection has failed | |
1923 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1924 assert(gch->collector_policy()->is_two_generation_policy(), | |
1925 "You may want to check the correctness of the following"); | |
1926 // Inform cms gen if this was due to partial collection failing. | |
1927 // 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
|
1928 if (gch->incremental_collection_will_fail(false /* don't consult_young */)) { |
0 | 1929 assert(!_cmsGen->incremental_collection_failed(), |
1930 "Should have been noticed, reacted to and cleared"); | |
1931 _cmsGen->set_incremental_collection_failed(); | |
1932 } | |
1933 *should_compact = | |
1934 UseCMSCompactAtFullCollection && | |
1935 ((_full_gcs_since_conc_gc >= CMSFullGCsBeforeCompaction) || | |
1936 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
|
1937 gch->incremental_collection_will_fail(true /* consult_young */)); |
0 | 1938 *should_start_over = false; |
1939 if (clear_all_soft_refs && !*should_compact) { | |
1940 // We are about to do a last ditch collection attempt | |
1941 // so it would normally make sense to do a compaction | |
1942 // to reclaim as much space as possible. | |
1943 if (CMSCompactWhenClearAllSoftRefs) { | |
1944 // Default: The rationale is that in this case either | |
1945 // we are past the final marking phase, in which case | |
1946 // we'd have to start over, or so little has been done | |
1947 // that there's little point in saving that work. Compaction | |
1948 // appears to be the sensible choice in either case. | |
1949 *should_compact = true; | |
1950 } else { | |
1951 // We have been asked to clear all soft refs, but not to | |
1952 // compact. Make sure that we aren't past the final checkpoint | |
1953 // phase, for that is where we process soft refs. If we are already | |
1954 // past that phase, we'll need to redo the refs discovery phase and | |
1955 // if necessary clear soft refs that weren't previously | |
1956 // cleared. We do so by remembering the phase in which | |
1957 // we came in, and if we are past the refs processing | |
1958 // phase, we'll choose to just redo the mark-sweep | |
1959 // collection from scratch. | |
1960 if (_collectorState > FinalMarking) { | |
1961 // We are past the refs processing phase; | |
1962 // start over and do a fresh synchronous CMS cycle | |
1963 _collectorState = Resetting; // skip to reset to start new cycle | |
1964 reset(false /* == !asynch */); | |
1965 *should_start_over = true; | |
1966 } // else we can continue a possibly ongoing current cycle | |
1967 } | |
1968 } | |
1969 } | |
1970 | |
1971 // A work method used by the foreground collector to do | |
1972 // a mark-sweep-compact. | |
1973 void CMSCollector::do_compaction_work(bool clear_all_soft_refs) { | |
1974 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1975 TraceTime t("CMS:MSC ", PrintGCDetails && Verbose, true, gclog_or_tty); | |
1976 if (PrintGC && Verbose && !(GCCause::is_user_requested_gc(gch->gc_cause()))) { | |
1977 gclog_or_tty->print_cr("Compact ConcurrentMarkSweepGeneration after %d " | |
1978 "collections passed to foreground collector", _full_gcs_since_conc_gc); | |
1979 } | |
1980 | |
1981 // Sample collection interval time and reset for collection pause. | |
1982 if (UseAdaptiveSizePolicy) { | |
1983 size_policy()->msc_collection_begin(); | |
1984 } | |
1985 | |
1986 // Temporarily widen the span of the weak reference processing to | |
1987 // the entire heap. | |
1988 MemRegion new_span(GenCollectedHeap::heap()->reserved_region()); | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
1989 ReferenceProcessorSpanMutator rp_mut_span(ref_processor(), new_span); |
0 | 1990 // Temporarily, clear the "is_alive_non_header" field of the |
1991 // reference processor. | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
1992 ReferenceProcessorIsAliveMutator rp_mut_closure(ref_processor(), NULL); |
0 | 1993 // Temporarily make reference _processing_ single threaded (non-MT). |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
1994 ReferenceProcessorMTProcMutator rp_mut_mt_processing(ref_processor(), false); |
0 | 1995 // Temporarily make refs discovery atomic |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
1996 ReferenceProcessorAtomicMutator rp_mut_atomic(ref_processor(), true); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
1997 // Temporarily make reference _discovery_ single threaded (non-MT) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
1998 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(ref_processor(), false); |
0 | 1999 |
2000 ref_processor()->set_enqueuing_is_done(false); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
2001 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
|
2002 ref_processor()->setup_policy(clear_all_soft_refs); |
0 | 2003 // If an asynchronous collection finishes, the _modUnionTable is |
2004 // all clear. If we are assuming the collection from an asynchronous | |
2005 // collection, clear the _modUnionTable. | |
2006 assert(_collectorState != Idling || _modUnionTable.isAllClear(), | |
2007 "_modUnionTable should be clear if the baton was not passed"); | |
2008 _modUnionTable.clear_all(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2009 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
|
2010 "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
|
2011 _ct->klass_rem_set()->clear_mod_union(); |
0 | 2012 |
2013 // We must adjust the allocation statistics being maintained | |
2014 // in the free list space. We do so by reading and clearing | |
2015 // 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
|
2016 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
|
2017 if (_inter_sweep_timer.is_active()) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2018 _inter_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2019 // 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
|
2020 _cmsGen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2021 _inter_sweep_estimate.padded_average(), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2022 _intra_sweep_estimate.padded_average()); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2023 } |
0 | 2024 |
2025 GenMarkSweep::invoke_at_safepoint(_cmsGen->level(), | |
2026 ref_processor(), clear_all_soft_refs); | |
2027 #ifdef ASSERT | |
2028 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); | |
2029 size_t free_size = cms_space->free(); | |
2030 assert(free_size == | |
2031 pointer_delta(cms_space->end(), cms_space->compaction_top()) | |
2032 * HeapWordSize, | |
2033 "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
|
2034 assert(cms_space->dictionary()->total_chunk_size( |
0 | 2035 debug_only(cms_space->freelistLock())) == 0 || |
2036 cms_space->totalSizeInIndexedFreeLists() == 0, | |
2037 "All the free space should be in a single chunk"); | |
2038 size_t num = cms_space->totalCount(); | |
2039 assert((free_size == 0 && num == 0) || | |
2040 (free_size > 0 && (num == 1 || num == 2)), | |
2041 "There should be at most 2 free chunks after compaction"); | |
2042 #endif // ASSERT | |
2043 _collectorState = Resetting; | |
2044 assert(_restart_addr == NULL, | |
2045 "Should have been NULL'd before baton was passed"); | |
2046 reset(false /* == !asynch */); | |
2047 _cmsGen->reset_after_compaction(); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2048 _concurrent_cycles_since_last_unload = 0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2049 |
0 | 2050 // Clear any data recorded in the PLAB chunk arrays. |
2051 if (_survivor_plab_array != NULL) { | |
2052 reset_survivor_plab_arrays(); | |
2053 } | |
2054 | |
2055 // Adjust the per-size allocation stats for the next epoch. | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2056 _cmsGen->cmsSpace()->endSweepFLCensus(sweep_count() /* fake */); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2057 // Restart the "inter sweep timer" for the next epoch. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2058 _inter_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2059 _inter_sweep_timer.start(); |
0 | 2060 |
2061 // Sample collection pause time and reset for collection interval. | |
2062 if (UseAdaptiveSizePolicy) { | |
2063 size_policy()->msc_collection_end(gch->gc_cause()); | |
2064 } | |
2065 | |
2066 // For a mark-sweep-compact, compute_new_size() will be called | |
2067 // in the heap's do_collection() method. | |
2068 } | |
2069 | |
2070 // A work method used by the foreground collector to do | |
2071 // a mark-sweep, after taking over from a possibly on-going | |
2072 // concurrent mark-sweep collection. | |
2073 void CMSCollector::do_mark_sweep_work(bool clear_all_soft_refs, | |
2074 CollectorState first_state, bool should_start_over) { | |
2075 if (PrintGC && Verbose) { | |
2076 gclog_or_tty->print_cr("Pass concurrent collection to foreground " | |
2077 "collector with count %d", | |
2078 _full_gcs_since_conc_gc); | |
2079 } | |
2080 switch (_collectorState) { | |
2081 case Idling: | |
2082 if (first_state == Idling || should_start_over) { | |
2083 // The background GC was not active, or should | |
2084 // restarted from scratch; start the cycle. | |
2085 _collectorState = InitialMarking; | |
2086 } | |
2087 // If first_state was not Idling, then a background GC | |
2088 // was in progress and has now finished. No need to do it | |
2089 // again. Leave the state as Idling. | |
2090 break; | |
2091 case Precleaning: | |
2092 // In the foreground case don't do the precleaning since | |
2093 // it is not done concurrently and there is extra work | |
2094 // required. | |
2095 _collectorState = FinalMarking; | |
2096 } | |
2097 collect_in_foreground(clear_all_soft_refs); | |
2098 | |
2099 // For a mark-sweep, compute_new_size() will be called | |
2100 // in the heap's do_collection() method. | |
2101 } | |
2102 | |
2103 | |
2104 void CMSCollector::getFreelistLocks() const { | |
2105 // Get locks for all free lists in all generations that this | |
2106 // collector is responsible for | |
2107 _cmsGen->freelistLock()->lock_without_safepoint_check(); | |
2108 } | |
2109 | |
2110 void CMSCollector::releaseFreelistLocks() const { | |
2111 // Release locks for all free lists in all generations that this | |
2112 // collector is responsible for | |
2113 _cmsGen->freelistLock()->unlock(); | |
2114 } | |
2115 | |
2116 bool CMSCollector::haveFreelistLocks() const { | |
2117 // Check locks for all free lists in all generations that this | |
2118 // collector is responsible for | |
2119 assert_lock_strong(_cmsGen->freelistLock()); | |
2120 PRODUCT_ONLY(ShouldNotReachHere()); | |
2121 return true; | |
2122 } | |
2123 | |
2124 // A utility class that is used by the CMS collector to | |
2125 // temporarily "release" the foreground collector from its | |
2126 // usual obligation to wait for the background collector to | |
2127 // complete an ongoing phase before proceeding. | |
2128 class ReleaseForegroundGC: public StackObj { | |
2129 private: | |
2130 CMSCollector* _c; | |
2131 public: | |
2132 ReleaseForegroundGC(CMSCollector* c) : _c(c) { | |
2133 assert(_c->_foregroundGCShouldWait, "Else should not need to call"); | |
2134 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2135 // allow a potentially blocked foreground collector to proceed | |
2136 _c->_foregroundGCShouldWait = false; | |
2137 if (_c->_foregroundGCIsActive) { | |
2138 CGC_lock->notify(); | |
2139 } | |
2140 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2141 "Possible deadlock"); | |
2142 } | |
2143 | |
2144 ~ReleaseForegroundGC() { | |
2145 assert(!_c->_foregroundGCShouldWait, "Usage protocol violation?"); | |
2146 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2147 _c->_foregroundGCShouldWait = true; | |
2148 } | |
2149 }; | |
2150 | |
2151 // There are separate collect_in_background and collect_in_foreground because of | |
2152 // the different locking requirements of the background collector and the | |
2153 // foreground collector. There was originally an attempt to share | |
2154 // one "collect" method between the background collector and the foreground | |
2155 // collector but the if-then-else required made it cleaner to have | |
2156 // separate methods. | |
2157 void CMSCollector::collect_in_background(bool clear_all_soft_refs) { | |
2158 assert(Thread::current()->is_ConcurrentGC_thread(), | |
2159 "A CMS asynchronous collection is only allowed on a CMS thread."); | |
2160 | |
2161 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2162 { | |
2163 bool safepoint_check = Mutex::_no_safepoint_check_flag; | |
2164 MutexLockerEx hl(Heap_lock, safepoint_check); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2165 FreelistLocker fll(this); |
0 | 2166 MutexLockerEx x(CGC_lock, safepoint_check); |
2167 if (_foregroundGCIsActive || !UseAsyncConcMarkSweepGC) { | |
2168 // The foreground collector is active or we're | |
2169 // not using asynchronous collections. Skip this | |
2170 // background collection. | |
2171 assert(!_foregroundGCShouldWait, "Should be clear"); | |
2172 return; | |
2173 } else { | |
2174 assert(_collectorState == Idling, "Should be idling before start."); | |
2175 _collectorState = InitialMarking; | |
2176 // Reset the expansion cause, now that we are about to begin | |
2177 // a new cycle. | |
2178 clear_expansion_cause(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2179 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2180 // Clear the MetaspaceGC flag since a concurrent collection |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2181 // 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
|
2182 MetaspaceGC::set_should_concurrent_collect(false); |
0 | 2183 } |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2184 // 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
|
2185 // ensuing concurrent GC cycle. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2186 update_should_unload_classes(); |
0 | 2187 _full_gc_requested = false; // acks all outstanding full gc requests |
2188 // Signal that we are about to start a collection | |
2189 gch->increment_total_full_collections(); // ... starting a collection cycle | |
2190 _collection_count_start = gch->total_full_collections(); | |
2191 } | |
2192 | |
2193 // Used for PrintGC | |
2194 size_t prev_used; | |
2195 if (PrintGC && Verbose) { | |
2196 prev_used = _cmsGen->used(); // XXXPERM | |
2197 } | |
2198 | |
2199 // The change of the collection state is normally done at this level; | |
2200 // the exceptions are phases that are executed while the world is | |
2201 // stopped. For those phases the change of state is done while the | |
2202 // world is stopped. For baton passing purposes this allows the | |
2203 // background collector to finish the phase and change state atomically. | |
2204 // The foreground collector cannot wait on a phase that is done | |
2205 // while the world is stopped because the foreground collector already | |
2206 // has the world stopped and would deadlock. | |
2207 while (_collectorState != Idling) { | |
2208 if (TraceCMSState) { | |
2209 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", | |
2210 Thread::current(), _collectorState); | |
2211 } | |
2212 // The foreground collector | |
2213 // holds the Heap_lock throughout its collection. | |
2214 // holds the CMS token (but not the lock) | |
2215 // except while it is waiting for the background collector to yield. | |
2216 // | |
2217 // The foreground collector should be blocked (not for long) | |
2218 // if the background collector is about to start a phase | |
2219 // executed with world stopped. If the background | |
2220 // collector has already started such a phase, the | |
2221 // foreground collector is blocked waiting for the | |
2222 // Heap_lock. The stop-world phases (InitialMarking and FinalMarking) | |
2223 // are executed in the VM thread. | |
2224 // | |
2225 // The locking order is | |
2226 // PendingListLock (PLL) -- if applicable (FinalMarking) | |
2227 // Heap_lock (both this & PLL locked in VM_CMS_Operation::prologue()) | |
2228 // CMS token (claimed in | |
2229 // stop_world_and_do() --> | |
2230 // safepoint_synchronize() --> | |
2231 // CMSThread::synchronize()) | |
2232 | |
2233 { | |
2234 // Check if the FG collector wants us to yield. | |
2235 CMSTokenSync x(true); // is cms thread | |
2236 if (waitForForegroundGC()) { | |
2237 // We yielded to a foreground GC, nothing more to be | |
2238 // done this round. | |
2239 assert(_foregroundGCShouldWait == false, "We set it to false in " | |
2240 "waitForForegroundGC()"); | |
2241 if (TraceCMSState) { | |
2242 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2243 " exiting collection CMS state %d", | |
2244 Thread::current(), _collectorState); | |
2245 } | |
2246 return; | |
2247 } else { | |
2248 // The background collector can run but check to see if the | |
2249 // foreground collector has done a collection while the | |
2250 // background collector was waiting to get the CGC_lock | |
2251 // above. If yes, break so that _foregroundGCShouldWait | |
2252 // is cleared before returning. | |
2253 if (_collectorState == Idling) { | |
2254 break; | |
2255 } | |
2256 } | |
2257 } | |
2258 | |
2259 assert(_foregroundGCShouldWait, "Foreground collector, if active, " | |
2260 "should be waiting"); | |
2261 | |
2262 switch (_collectorState) { | |
2263 case InitialMarking: | |
2264 { | |
2265 ReleaseForegroundGC x(this); | |
2266 stats().record_cms_begin(); | |
2267 | |
2268 VM_CMS_Initial_Mark initial_mark_op(this); | |
2269 VMThread::execute(&initial_mark_op); | |
2270 } | |
2271 // The collector state may be any legal state at this point | |
2272 // since the background collector may have yielded to the | |
2273 // foreground collector. | |
2274 break; | |
2275 case Marking: | |
2276 // initial marking in checkpointRootsInitialWork has been completed | |
2277 if (markFromRoots(true)) { // we were successful | |
2278 assert(_collectorState == Precleaning, "Collector state should " | |
2279 "have changed"); | |
2280 } else { | |
2281 assert(_foregroundGCIsActive, "Internal state inconsistency"); | |
2282 } | |
2283 break; | |
2284 case Precleaning: | |
2285 if (UseAdaptiveSizePolicy) { | |
2286 size_policy()->concurrent_precleaning_begin(); | |
2287 } | |
2288 // marking from roots in markFromRoots has been completed | |
2289 preclean(); | |
2290 if (UseAdaptiveSizePolicy) { | |
2291 size_policy()->concurrent_precleaning_end(); | |
2292 } | |
2293 assert(_collectorState == AbortablePreclean || | |
2294 _collectorState == FinalMarking, | |
2295 "Collector state should have changed"); | |
2296 break; | |
2297 case AbortablePreclean: | |
2298 if (UseAdaptiveSizePolicy) { | |
2299 size_policy()->concurrent_phases_resume(); | |
2300 } | |
2301 abortable_preclean(); | |
2302 if (UseAdaptiveSizePolicy) { | |
2303 size_policy()->concurrent_precleaning_end(); | |
2304 } | |
2305 assert(_collectorState == FinalMarking, "Collector state should " | |
2306 "have changed"); | |
2307 break; | |
2308 case FinalMarking: | |
2309 { | |
2310 ReleaseForegroundGC x(this); | |
2311 | |
2312 VM_CMS_Final_Remark final_remark_op(this); | |
2313 VMThread::execute(&final_remark_op); | |
935 | 2314 } |
0 | 2315 assert(_foregroundGCShouldWait, "block post-condition"); |
2316 break; | |
2317 case Sweeping: | |
2318 if (UseAdaptiveSizePolicy) { | |
2319 size_policy()->concurrent_sweeping_begin(); | |
2320 } | |
2321 // final marking in checkpointRootsFinal has been completed | |
2322 sweep(true); | |
2323 assert(_collectorState == Resizing, "Collector state change " | |
2324 "to Resizing must be done under the free_list_lock"); | |
2325 _full_gcs_since_conc_gc = 0; | |
2326 | |
2327 // Stop the timers for adaptive size policy for the concurrent phases | |
2328 if (UseAdaptiveSizePolicy) { | |
2329 size_policy()->concurrent_sweeping_end(); | |
2330 size_policy()->concurrent_phases_end(gch->gc_cause(), | |
2331 gch->prev_gen(_cmsGen)->capacity(), | |
2332 _cmsGen->free()); | |
2333 } | |
2334 | |
2335 case Resizing: { | |
2336 // Sweeping has been completed... | |
2337 // At this point the background collection has completed. | |
2338 // Don't move the call to compute_new_size() down | |
2339 // into code that might be executed if the background | |
2340 // collection was preempted. | |
2341 { | |
2342 ReleaseForegroundGC x(this); // unblock FG collection | |
2343 MutexLockerEx y(Heap_lock, Mutex::_no_safepoint_check_flag); | |
2344 CMSTokenSync z(true); // not strictly needed. | |
2345 if (_collectorState == Resizing) { | |
2346 compute_new_size(); | |
2347 _collectorState = Resetting; | |
2348 } else { | |
2349 assert(_collectorState == Idling, "The state should only change" | |
2350 " because the foreground collector has finished the collection"); | |
2351 } | |
2352 } | |
2353 break; | |
2354 } | |
2355 case Resetting: | |
2356 // CMS heap resizing has been completed | |
2357 reset(true); | |
2358 assert(_collectorState == Idling, "Collector state should " | |
2359 "have changed"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2360 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2361 MetaspaceGC::set_should_concurrent_collect(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2362 |
0 | 2363 stats().record_cms_end(); |
2364 // Don't move the concurrent_phases_end() and compute_new_size() | |
2365 // calls to here because a preempted background collection | |
2366 // has it's state set to "Resetting". | |
2367 break; | |
2368 case Idling: | |
2369 default: | |
2370 ShouldNotReachHere(); | |
2371 break; | |
2372 } | |
2373 if (TraceCMSState) { | |
2374 gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", | |
2375 Thread::current(), _collectorState); | |
2376 } | |
2377 assert(_foregroundGCShouldWait, "block post-condition"); | |
2378 } | |
2379 | |
2380 // Should this be in gc_epilogue? | |
2381 collector_policy()->counters()->update_counters(); | |
2382 | |
2383 { | |
2384 // Clear _foregroundGCShouldWait and, in the event that the | |
2385 // foreground collector is waiting, notify it, before | |
2386 // returning. | |
2387 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2388 _foregroundGCShouldWait = false; | |
2389 if (_foregroundGCIsActive) { | |
2390 CGC_lock->notify(); | |
2391 } | |
2392 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2393 "Possible deadlock"); | |
2394 } | |
2395 if (TraceCMSState) { | |
2396 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2397 " exiting collection CMS state %d", | |
2398 Thread::current(), _collectorState); | |
2399 } | |
2400 if (PrintGC && Verbose) { | |
2401 _cmsGen->print_heap_change(prev_used); | |
2402 } | |
2403 } | |
2404 | |
2405 void CMSCollector::collect_in_foreground(bool clear_all_soft_refs) { | |
2406 assert(_foregroundGCIsActive && !_foregroundGCShouldWait, | |
2407 "Foreground collector should be waiting, not executing"); | |
2408 assert(Thread::current()->is_VM_thread(), "A foreground collection" | |
2409 "may only be done by the VM Thread with the world stopped"); | |
2410 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
2411 "VM thread should have CMS token"); | |
2412 | |
2413 NOT_PRODUCT(TraceTime t("CMS:MS (foreground) ", PrintGCDetails && Verbose, | |
2414 true, gclog_or_tty);) | |
2415 if (UseAdaptiveSizePolicy) { | |
2416 size_policy()->ms_collection_begin(); | |
2417 } | |
2418 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact); | |
2419 | |
2420 HandleMark hm; // Discard invalid handles created during verification | |
2421 | |
2422 if (VerifyBeforeGC && | |
2423 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
2424 Universe::verify(); |
0 | 2425 } |
2426 | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
2427 // 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
|
2428 ref_processor()->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
2429 |
0 | 2430 bool init_mark_was_synchronous = false; // until proven otherwise |
2431 while (_collectorState != Idling) { | |
2432 if (TraceCMSState) { | |
2433 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", | |
2434 Thread::current(), _collectorState); | |
2435 } | |
2436 switch (_collectorState) { | |
2437 case InitialMarking: | |
2438 init_mark_was_synchronous = true; // fact to be exploited in re-mark | |
2439 checkpointRootsInitial(false); | |
2440 assert(_collectorState == Marking, "Collector state should have changed" | |
2441 " within checkpointRootsInitial()"); | |
2442 break; | |
2443 case Marking: | |
2444 // initial marking in checkpointRootsInitialWork has been completed | |
2445 if (VerifyDuringGC && | |
2446 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
|
2447 Universe::verify("Verify before initial mark: "); |
0 | 2448 } |
2449 { | |
2450 bool res = markFromRoots(false); | |
2451 assert(res && _collectorState == FinalMarking, "Collector state should " | |
2452 "have changed"); | |
2453 break; | |
2454 } | |
2455 case FinalMarking: | |
2456 if (VerifyDuringGC && | |
2457 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
|
2458 Universe::verify("Verify before re-mark: "); |
0 | 2459 } |
2460 checkpointRootsFinal(false, clear_all_soft_refs, | |
2461 init_mark_was_synchronous); | |
2462 assert(_collectorState == Sweeping, "Collector state should not " | |
2463 "have changed within checkpointRootsFinal()"); | |
2464 break; | |
2465 case Sweeping: | |
2466 // final marking in checkpointRootsFinal has been completed | |
2467 if (VerifyDuringGC && | |
2468 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
|
2469 Universe::verify("Verify before sweep: "); |
0 | 2470 } |
2471 sweep(false); | |
2472 assert(_collectorState == Resizing, "Incorrect state"); | |
2473 break; | |
2474 case Resizing: { | |
2475 // Sweeping has been completed; the actual resize in this case | |
2476 // is done separately; nothing to be done in this state. | |
2477 _collectorState = Resetting; | |
2478 break; | |
2479 } | |
2480 case Resetting: | |
2481 // The heap has been resized. | |
2482 if (VerifyDuringGC && | |
2483 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
|
2484 Universe::verify("Verify before reset: "); |
0 | 2485 } |
2486 reset(false); | |
2487 assert(_collectorState == Idling, "Collector state should " | |
2488 "have changed"); | |
2489 break; | |
2490 case Precleaning: | |
2491 case AbortablePreclean: | |
2492 // Elide the preclean phase | |
2493 _collectorState = FinalMarking; | |
2494 break; | |
2495 default: | |
2496 ShouldNotReachHere(); | |
2497 } | |
2498 if (TraceCMSState) { | |
2499 gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", | |
2500 Thread::current(), _collectorState); | |
2501 } | |
2502 } | |
2503 | |
2504 if (UseAdaptiveSizePolicy) { | |
2505 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2506 size_policy()->ms_collection_end(gch->gc_cause()); | |
2507 } | |
2508 | |
2509 if (VerifyAfterGC && | |
2510 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
2511 Universe::verify(); |
0 | 2512 } |
2513 if (TraceCMSState) { | |
2514 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2515 " exiting collection CMS state %d", | |
2516 Thread::current(), _collectorState); | |
2517 } | |
2518 } | |
2519 | |
2520 bool CMSCollector::waitForForegroundGC() { | |
2521 bool res = false; | |
2522 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2523 "CMS thread should have CMS token"); | |
2524 // Block the foreground collector until the | |
2525 // background collectors decides whether to | |
2526 // yield. | |
2527 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2528 _foregroundGCShouldWait = true; | |
2529 if (_foregroundGCIsActive) { | |
2530 // The background collector yields to the | |
2531 // foreground collector and returns a value | |
2532 // indicating that it has yielded. The foreground | |
2533 // collector can proceed. | |
2534 res = true; | |
2535 _foregroundGCShouldWait = false; | |
2536 ConcurrentMarkSweepThread::clear_CMS_flag( | |
2537 ConcurrentMarkSweepThread::CMS_cms_has_token); | |
2538 ConcurrentMarkSweepThread::set_CMS_flag( | |
2539 ConcurrentMarkSweepThread::CMS_cms_wants_token); | |
2540 // Get a possibly blocked foreground thread going | |
2541 CGC_lock->notify(); | |
2542 if (TraceCMSState) { | |
2543 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " waiting at CMS state %d", | |
2544 Thread::current(), _collectorState); | |
2545 } | |
2546 while (_foregroundGCIsActive) { | |
2547 CGC_lock->wait(Mutex::_no_safepoint_check_flag); | |
2548 } | |
2549 ConcurrentMarkSweepThread::set_CMS_flag( | |
2550 ConcurrentMarkSweepThread::CMS_cms_has_token); | |
2551 ConcurrentMarkSweepThread::clear_CMS_flag( | |
2552 ConcurrentMarkSweepThread::CMS_cms_wants_token); | |
2553 } | |
2554 if (TraceCMSState) { | |
2555 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " continuing at CMS state %d", | |
2556 Thread::current(), _collectorState); | |
2557 } | |
2558 return res; | |
2559 } | |
2560 | |
2561 // Because of the need to lock the free lists and other structures in | |
2562 // the collector, common to all the generations that the collector is | |
2563 // collecting, we need the gc_prologues of individual CMS generations | |
2564 // delegate to their collector. It may have been simpler had the | |
2565 // current infrastructure allowed one to call a prologue on a | |
2566 // collector. In the absence of that we have the generation's | |
2567 // prologue delegate to the collector, which delegates back | |
2568 // some "local" work to a worker method in the individual generations | |
2569 // that it's responsible for collecting, while itself doing any | |
2570 // work common to all generations it's responsible for. A similar | |
2571 // comment applies to the gc_epilogue()'s. | |
2572 // The role of the varaible _between_prologue_and_epilogue is to | |
2573 // enforce the invocation protocol. | |
2574 void CMSCollector::gc_prologue(bool full) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2575 // Call gc_prologue_work() for the CMSGen |
0 | 2576 // we are responsible for. |
2577 | |
2578 // The following locking discipline assumes that we are only called | |
2579 // when the world is stopped. | |
2580 assert(SafepointSynchronize::is_at_safepoint(), "world is stopped assumption"); | |
2581 | |
2582 // 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
|
2583 // "generations" that it's responsible |
0 | 2584 // for. |
2585 | |
2586 assert( Thread::current()->is_VM_thread() | |
2587 || ( CMSScavengeBeforeRemark | |
2588 && Thread::current()->is_ConcurrentGC_thread()), | |
2589 "Incorrect thread type for prologue execution"); | |
2590 | |
2591 if (_between_prologue_and_epilogue) { | |
2592 // We have already been invoked; this is a gc_prologue delegation | |
2593 // from yet another CMS generation that we are responsible for, just | |
2594 // ignore it since all relevant work has already been done. | |
2595 return; | |
2596 } | |
2597 | |
2598 // set a bit saying prologue has been called; cleared in epilogue | |
2599 _between_prologue_and_epilogue = true; | |
2600 // 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
|
2601 // for each CMSGen. |
0 | 2602 |
2603 getFreelistLocks(); // gets free list locks on constituent spaces | |
2604 bitMapLock()->lock_without_safepoint_check(); | |
2605 | |
2606 // 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
|
2607 bool duringMarking = _collectorState >= Marking |
0 | 2608 && _collectorState < Sweeping; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2609 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2610 // 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
|
2611 // 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
|
2612 // 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
|
2613 // modified klasses. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2614 if (duringMarking) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2615 _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
|
2616 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2617 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2618 bool registerClosure = duringMarking; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2619 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2620 ModUnionClosure* muc = CollectedHeap::use_parallel_gc_threads() ? |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2621 &_modUnionClosurePar |
0 | 2622 : &_modUnionClosure; |
2623 _cmsGen->gc_prologue_work(full, registerClosure, muc); | |
2624 | |
2625 if (!full) { | |
2626 stats().record_gc0_begin(); | |
2627 } | |
2628 } | |
2629 | |
2630 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
|
2631 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2632 _capacity_at_prologue = capacity(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2633 _used_at_prologue = used(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2634 |
0 | 2635 // Delegate to CMScollector which knows how to coordinate between |
2636 // this and any other CMS generations that it is responsible for | |
2637 // collecting. | |
2638 collector()->gc_prologue(full); | |
2639 } | |
2640 | |
2641 // This is a "private" interface for use by this generation's CMSCollector. | |
2642 // Not to be called directly by any other entity (for instance, | |
2643 // GenCollectedHeap, which calls the "public" gc_prologue method above). | |
2644 void ConcurrentMarkSweepGeneration::gc_prologue_work(bool full, | |
2645 bool registerClosure, ModUnionClosure* modUnionClosure) { | |
2646 assert(!incremental_collection_failed(), "Shouldn't be set yet"); | |
2647 assert(cmsSpace()->preconsumptionDirtyCardClosure() == NULL, | |
2648 "Should be NULL"); | |
2649 if (registerClosure) { | |
2650 cmsSpace()->setPreconsumptionDirtyCardClosure(modUnionClosure); | |
2651 } | |
2652 cmsSpace()->gc_prologue(); | |
2653 // Clear stat counters | |
2654 NOT_PRODUCT( | |
2655 assert(_numObjectsPromoted == 0, "check"); | |
2656 assert(_numWordsPromoted == 0, "check"); | |
2657 if (Verbose && PrintGC) { | |
2658 gclog_or_tty->print("Allocated "SIZE_FORMAT" objects, " | |
2659 SIZE_FORMAT" bytes concurrently", | |
2660 _numObjectsAllocated, _numWordsAllocated*sizeof(HeapWord)); | |
2661 } | |
2662 _numObjectsAllocated = 0; | |
2663 _numWordsAllocated = 0; | |
2664 ) | |
2665 } | |
2666 | |
2667 void CMSCollector::gc_epilogue(bool full) { | |
2668 // The following locking discipline assumes that we are only called | |
2669 // when the world is stopped. | |
2670 assert(SafepointSynchronize::is_at_safepoint(), | |
2671 "world is stopped assumption"); | |
2672 | |
2673 // Currently the CMS epilogue (see CompactibleFreeListSpace) merely checks | |
2674 // if linear allocation blocks need to be appropriately marked to allow the | |
2675 // the blocks to be parsable. We also check here whether we need to nudge the | |
2676 // CMS collector thread to start a new cycle (if it's not already active). | |
2677 assert( Thread::current()->is_VM_thread() | |
2678 || ( CMSScavengeBeforeRemark | |
2679 && Thread::current()->is_ConcurrentGC_thread()), | |
2680 "Incorrect thread type for epilogue execution"); | |
2681 | |
2682 if (!_between_prologue_and_epilogue) { | |
2683 // We have already been invoked; this is a gc_epilogue delegation | |
2684 // from yet another CMS generation that we are responsible for, just | |
2685 // ignore it since all relevant work has already been done. | |
2686 return; | |
2687 } | |
2688 assert(haveFreelistLocks(), "must have freelist locks"); | |
2689 assert_lock_strong(bitMapLock()); | |
2690 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2691 _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
|
2692 |
0 | 2693 _cmsGen->gc_epilogue_work(full); |
2694 | |
2695 if (_collectorState == AbortablePreclean || _collectorState == Precleaning) { | |
2696 // in case sampling was not already enabled, enable it | |
2697 _start_sampling = true; | |
2698 } | |
2699 // reset _eden_chunk_array so sampling starts afresh | |
2700 _eden_chunk_index = 0; | |
2701 | |
2702 size_t cms_used = _cmsGen->cmsSpace()->used(); | |
2703 | |
2704 // update performance counters - this uses a special version of | |
2705 // update_counters() that allows the utilization to be passed as a | |
2706 // parameter, avoiding multiple calls to used(). | |
2707 // | |
2708 _cmsGen->update_counters(cms_used); | |
2709 | |
2710 if (CMSIncrementalMode) { | |
2711 icms_update_allocation_limits(); | |
2712 } | |
2713 | |
2714 bitMapLock()->unlock(); | |
2715 releaseFreelistLocks(); | |
2716 | |
3799
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2717 if (!CleanChunkPoolAsync) { |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2718 Chunk::clean_chunk_pool(); |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2719 } |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2720 |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
2721 set_did_compact(false); |
0 | 2722 _between_prologue_and_epilogue = false; // ready for next cycle |
2723 } | |
2724 | |
2725 void ConcurrentMarkSweepGeneration::gc_epilogue(bool full) { | |
2726 collector()->gc_epilogue(full); | |
2727 | |
2728 // Also reset promotion tracking in par gc thread states. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2729 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 2730 for (uint i = 0; i < ParallelGCThreads; i++) { |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2731 _par_gc_thread_states[i]->promo.stopTrackingPromotions(i); |
0 | 2732 } |
2733 } | |
2734 } | |
2735 | |
2736 void ConcurrentMarkSweepGeneration::gc_epilogue_work(bool full) { | |
2737 assert(!incremental_collection_failed(), "Should have been cleared"); | |
2738 cmsSpace()->setPreconsumptionDirtyCardClosure(NULL); | |
2739 cmsSpace()->gc_epilogue(); | |
2740 // Print stat counters | |
2741 NOT_PRODUCT( | |
2742 assert(_numObjectsAllocated == 0, "check"); | |
2743 assert(_numWordsAllocated == 0, "check"); | |
2744 if (Verbose && PrintGC) { | |
2745 gclog_or_tty->print("Promoted "SIZE_FORMAT" objects, " | |
2746 SIZE_FORMAT" bytes", | |
2747 _numObjectsPromoted, _numWordsPromoted*sizeof(HeapWord)); | |
2748 } | |
2749 _numObjectsPromoted = 0; | |
2750 _numWordsPromoted = 0; | |
2751 ) | |
2752 | |
2753 if (PrintGC && Verbose) { | |
2754 // Call down the chain in contiguous_available needs the freelistLock | |
2755 // so print this out before releasing the freeListLock. | |
2756 gclog_or_tty->print(" Contiguous available "SIZE_FORMAT" bytes ", | |
2757 contiguous_available()); | |
2758 } | |
2759 } | |
2760 | |
2761 #ifndef PRODUCT | |
2762 bool CMSCollector::have_cms_token() { | |
2763 Thread* thr = Thread::current(); | |
2764 if (thr->is_VM_thread()) { | |
2765 return ConcurrentMarkSweepThread::vm_thread_has_cms_token(); | |
2766 } else if (thr->is_ConcurrentGC_thread()) { | |
2767 return ConcurrentMarkSweepThread::cms_thread_has_cms_token(); | |
2768 } else if (thr->is_GC_task_thread()) { | |
2769 return ConcurrentMarkSweepThread::vm_thread_has_cms_token() && | |
2770 ParGCRareEvent_lock->owned_by_self(); | |
2771 } | |
2772 return false; | |
2773 } | |
2774 #endif | |
2775 | |
2776 // Check reachability of the given heap address in CMS generation, | |
2777 // treating all other generations as roots. | |
2778 bool CMSCollector::is_cms_reachable(HeapWord* addr) { | |
2779 // We could "guarantee" below, rather than assert, but i'll | |
2780 // leave these as "asserts" so that an adventurous debugger | |
2781 // could try this in the product build provided some subset of | |
2782 // the conditions were met, provided they were intersted in the | |
2783 // results and knew that the computation below wouldn't interfere | |
2784 // with other concurrent computations mutating the structures | |
2785 // being read or written. | |
2786 assert(SafepointSynchronize::is_at_safepoint(), | |
2787 "Else mutations in object graph will make answer suspect"); | |
2788 assert(have_cms_token(), "Should hold cms token"); | |
2789 assert(haveFreelistLocks(), "must hold free list locks"); | |
2790 assert_lock_strong(bitMapLock()); | |
2791 | |
2792 // Clear the marking bit map array before starting, but, just | |
2793 // for kicks, first report if the given address is already marked | |
2794 gclog_or_tty->print_cr("Start: Address 0x%x is%s marked", addr, | |
2795 _markBitMap.isMarked(addr) ? "" : " not"); | |
2796 | |
2797 if (verify_after_remark()) { | |
2798 MutexLockerEx x(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); | |
2799 bool result = verification_mark_bm()->isMarked(addr); | |
2800 gclog_or_tty->print_cr("TransitiveMark: Address 0x%x %s marked", addr, | |
2801 result ? "IS" : "is NOT"); | |
2802 return result; | |
2803 } else { | |
2804 gclog_or_tty->print_cr("Could not compute result"); | |
2805 return false; | |
2806 } | |
2807 } | |
2808 | |
9076
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2809 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2810 void |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2811 CMSCollector::print_on_error(outputStream* st) { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2812 CMSCollector* collector = ConcurrentMarkSweepGeneration::_collector; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2813 if (collector != NULL) { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2814 CMSBitMap* bitmap = &collector->_markBitMap; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2815 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
|
2816 bitmap->print_on_error(st, " Bits: "); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2817 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2818 st->cr(); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2819 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2820 CMSBitMap* mut_bitmap = &collector->_modUnionTable; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2821 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
|
2822 mut_bitmap->print_on_error(st, " Bits: "); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2823 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2824 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2825 |
0 | 2826 //////////////////////////////////////////////////////// |
2827 // CMS Verification Support | |
2828 //////////////////////////////////////////////////////// | |
2829 // Following the remark phase, the following invariant | |
2830 // should hold -- each object in the CMS heap which is | |
2831 // marked in markBitMap() should be marked in the verification_mark_bm(). | |
2832 | |
2833 class VerifyMarkedClosure: public BitMapClosure { | |
2834 CMSBitMap* _marks; | |
2835 bool _failed; | |
2836 | |
2837 public: | |
2838 VerifyMarkedClosure(CMSBitMap* bm): _marks(bm), _failed(false) {} | |
2839 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
2840 bool do_bit(size_t offset) { |
0 | 2841 HeapWord* addr = _marks->offsetToHeapWord(offset); |
2842 if (!_marks->isMarked(addr)) { | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2843 oop(addr)->print_on(gclog_or_tty); |
0 | 2844 gclog_or_tty->print_cr(" ("INTPTR_FORMAT" should have been marked)", addr); |
2845 _failed = true; | |
2846 } | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
2847 return true; |
0 | 2848 } |
2849 | |
2850 bool failed() { return _failed; } | |
2851 }; | |
2852 | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2853 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
|
2854 if (!silent) gclog_or_tty->print(" [Verifying CMS Marking... "); |
0 | 2855 MutexLockerEx ml(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); |
2856 static bool init = false; | |
2857 | |
2858 assert(SafepointSynchronize::is_at_safepoint(), | |
2859 "Else mutations in object graph will make answer suspect"); | |
2860 assert(have_cms_token(), | |
2861 "Else there may be mutual interference in use of " | |
2862 " verification data structures"); | |
2863 assert(_collectorState > Marking && _collectorState <= Sweeping, | |
2864 "Else marking info checked here may be obsolete"); | |
2865 assert(haveFreelistLocks(), "must hold free list locks"); | |
2866 assert_lock_strong(bitMapLock()); | |
2867 | |
2868 | |
2869 // Allocate marking bit map if not already allocated | |
2870 if (!init) { // first time | |
2871 if (!verification_mark_bm()->allocate(_span)) { | |
2872 return false; | |
2873 } | |
2874 init = true; | |
2875 } | |
2876 | |
2877 assert(verification_mark_stack()->isEmpty(), "Should be empty"); | |
2878 | |
2879 // Turn off refs discovery -- so we will be tracing through refs. | |
2880 // This is as intended, because by this time | |
2881 // GC must already have cleared any refs that need to be cleared, | |
2882 // and traced those that need to be marked; moreover, | |
2883 // the marking done here is not going to intefere in any | |
2884 // way with the marking information used by GC. | |
2885 NoRefDiscovery no_discovery(ref_processor()); | |
2886 | |
2887 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
2888 | |
2889 // Clear any marks from a previous round | |
2890 verification_mark_bm()->clear_all(); | |
2891 assert(verification_mark_stack()->isEmpty(), "markStack should be empty"); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2892 verify_work_stacks_empty(); |
0 | 2893 |
2894 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2895 gch->ensure_parsability(false); // fill TLABs, but no need to retire them | |
2896 // Update the saved marks which may affect the root scans. | |
2897 gch->save_marks(); | |
2898 | |
2899 if (CMSRemarkVerifyVariant == 1) { | |
2900 // In this first variant of verification, we complete | |
2901 // all marking, then check if the new marks-verctor is | |
2902 // a subset of the CMS marks-vector. | |
2903 verify_after_remark_work_1(); | |
2904 } else if (CMSRemarkVerifyVariant == 2) { | |
2905 // In this second variant of verification, we flag an error | |
2906 // (i.e. an object reachable in the new marks-vector not reachable | |
2907 // in the CMS marks-vector) immediately, also indicating the | |
2908 // identify of an object (A) that references the unmarked object (B) -- | |
2909 // presumably, a mutation to A failed to be picked up by preclean/remark? | |
2910 verify_after_remark_work_2(); | |
2911 } else { | |
2912 warning("Unrecognized value %d for CMSRemarkVerifyVariant", | |
2913 CMSRemarkVerifyVariant); | |
2914 } | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2915 if (!silent) gclog_or_tty->print(" done] "); |
0 | 2916 return true; |
2917 } | |
2918 | |
2919 void CMSCollector::verify_after_remark_work_1() { | |
2920 ResourceMark rm; | |
2921 HandleMark hm; | |
2922 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2923 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2924 // Get a clear set of claim bits for the strong roots processing to work with. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2925 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2926 |
0 | 2927 // 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
|
2928 MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); |
0 | 2929 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
2930 | |
2931 gch->gen_process_strong_roots(_cmsGen->level(), | |
2932 true, // younger gens are roots | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
2933 true, // activate StrongRootsScope |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2934 false, // not scavenging |
0 | 2935 SharedHeap::ScanningOption(roots_scanning_options()), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
2936 ¬Older, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
2937 true, // walk code active on stacks |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2938 NULL, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2939 NULL); // SSS: Provide correct closure |
0 | 2940 |
2941 // Now mark from the roots | |
2942 MarkFromRootsClosure markFromRootsClosure(this, _span, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2943 verification_mark_bm(), verification_mark_stack(), |
0 | 2944 false /* don't yield */, true /* verifying */); |
2945 assert(_restart_addr == NULL, "Expected pre-condition"); | |
2946 verification_mark_bm()->iterate(&markFromRootsClosure); | |
2947 while (_restart_addr != NULL) { | |
2948 // Deal with stack overflow: by restarting at the indicated | |
2949 // address. | |
2950 HeapWord* ra = _restart_addr; | |
2951 markFromRootsClosure.reset(ra); | |
2952 _restart_addr = NULL; | |
2953 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end()); | |
2954 } | |
2955 assert(verification_mark_stack()->isEmpty(), "Should have been drained"); | |
2956 verify_work_stacks_empty(); | |
2957 | |
2958 // Marking completed -- now verify that each bit marked in | |
2959 // verification_mark_bm() is also marked in markBitMap(); flag all | |
2960 // errors by printing corresponding objects. | |
2961 VerifyMarkedClosure vcl(markBitMap()); | |
2962 verification_mark_bm()->iterate(&vcl); | |
2963 if (vcl.failed()) { | |
2964 gclog_or_tty->print("Verification failed"); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2965 Universe::heap()->print_on(gclog_or_tty); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2966 fatal("CMS: failed marking verification after remark"); |
0 | 2967 } |
2968 } | |
2969 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2970 class VerifyKlassOopsKlassClosure : public KlassClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2971 class VerifyKlassOopsClosure : public OopClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2972 CMSBitMap* _bitmap; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2973 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2974 VerifyKlassOopsClosure(CMSBitMap* bitmap) : _bitmap(bitmap) { } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2975 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
|
2976 void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2977 } _oop_closure; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2978 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2979 VerifyKlassOopsKlassClosure(CMSBitMap* bitmap) : _oop_closure(bitmap) {} |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2980 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2981 k->oops_do(&_oop_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2982 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2983 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2984 |
0 | 2985 void CMSCollector::verify_after_remark_work_2() { |
2986 ResourceMark rm; | |
2987 HandleMark hm; | |
2988 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2989 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2990 // Get a clear set of claim bits for the strong roots processing to work with. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2991 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2992 |
0 | 2993 // Mark from roots one level into CMS |
2994 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(), | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
2995 markBitMap()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2996 CMKlassClosure klass_closure(¬Older); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2997 |
0 | 2998 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
2999 gch->gen_process_strong_roots(_cmsGen->level(), | |
3000 true, // younger gens are roots | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
3001 true, // activate StrongRootsScope |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3002 false, // not scavenging |
0 | 3003 SharedHeap::ScanningOption(roots_scanning_options()), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
3004 ¬Older, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
3005 true, // walk code active on stacks |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3006 NULL, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3007 &klass_closure); |
0 | 3008 |
3009 // Now mark from the roots | |
3010 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, | |
3011 verification_mark_bm(), markBitMap(), verification_mark_stack()); | |
3012 assert(_restart_addr == NULL, "Expected pre-condition"); | |
3013 verification_mark_bm()->iterate(&markFromRootsClosure); | |
3014 while (_restart_addr != NULL) { | |
3015 // Deal with stack overflow: by restarting at the indicated | |
3016 // address. | |
3017 HeapWord* ra = _restart_addr; | |
3018 markFromRootsClosure.reset(ra); | |
3019 _restart_addr = NULL; | |
3020 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end()); | |
3021 } | |
3022 assert(verification_mark_stack()->isEmpty(), "Should have been drained"); | |
3023 verify_work_stacks_empty(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3024 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3025 VerifyKlassOopsKlassClosure verify_klass_oops(verification_mark_bm()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3026 ClassLoaderDataGraph::classes_do(&verify_klass_oops); |
0 | 3027 |
3028 // Marking completed -- now verify that each bit marked in | |
3029 // verification_mark_bm() is also marked in markBitMap(); flag all | |
3030 // errors by printing corresponding objects. | |
3031 VerifyMarkedClosure vcl(markBitMap()); | |
3032 verification_mark_bm()->iterate(&vcl); | |
3033 assert(!vcl.failed(), "Else verification above should not have succeeded"); | |
3034 } | |
3035 | |
3036 void ConcurrentMarkSweepGeneration::save_marks() { | |
3037 // delegate to CMS space | |
3038 cmsSpace()->save_marks(); | |
3039 for (uint i = 0; i < ParallelGCThreads; i++) { | |
3040 _par_gc_thread_states[i]->promo.startTrackingPromotions(); | |
3041 } | |
3042 } | |
3043 | |
3044 bool ConcurrentMarkSweepGeneration::no_allocs_since_save_marks() { | |
3045 return cmsSpace()->no_allocs_since_save_marks(); | |
3046 } | |
3047 | |
3048 #define CMS_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ | |
3049 \ | |
3050 void ConcurrentMarkSweepGeneration:: \ | |
3051 oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ | |
3052 cl->set_generation(this); \ | |
3053 cmsSpace()->oop_since_save_marks_iterate##nv_suffix(cl); \ | |
3054 cl->reset_generation(); \ | |
3055 save_marks(); \ | |
3056 } | |
3057 | |
3058 ALL_SINCE_SAVE_MARKS_CLOSURES(CMS_SINCE_SAVE_MARKS_DEFN) | |
3059 | |
3060 void | |
3061 ConcurrentMarkSweepGeneration::object_iterate_since_last_GC(ObjectClosure* blk) | |
3062 { | |
3063 // Not currently implemented; need to do the following. -- ysr. | |
3064 // dld -- I think that is used for some sort of allocation profiler. So it | |
3065 // really means the objects allocated by the mutator since the last | |
3066 // GC. We could potentially implement this cheaply by recording only | |
3067 // the direct allocations in a side data structure. | |
3068 // | |
3069 // I think we probably ought not to be required to support these | |
3070 // iterations at any arbitrary point; I think there ought to be some | |
3071 // call to enable/disable allocation profiling in a generation/space, | |
3072 // and the iterator ought to return the objects allocated in the | |
3073 // gen/space since the enable call, or the last iterator call (which | |
3074 // will probably be at a GC.) That way, for gens like CM&S that would | |
3075 // require some extra data structure to support this, we only pay the | |
3076 // cost when it's in use... | |
3077 cmsSpace()->object_iterate_since_last_GC(blk); | |
3078 } | |
3079 | |
3080 void | |
3081 ConcurrentMarkSweepGeneration::younger_refs_iterate(OopsInGenClosure* cl) { | |
3082 cl->set_generation(this); | |
3083 younger_refs_in_space_iterate(_cmsSpace, cl); | |
3084 cl->reset_generation(); | |
3085 } | |
3086 | |
3087 void | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3088 ConcurrentMarkSweepGeneration::oop_iterate(MemRegion mr, ExtendedOopClosure* cl) { |
0 | 3089 if (freelistLock()->owned_by_self()) { |
3090 Generation::oop_iterate(mr, cl); | |
3091 } else { | |
3092 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3093 Generation::oop_iterate(mr, cl); | |
3094 } | |
3095 } | |
3096 | |
3097 void | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3098 ConcurrentMarkSweepGeneration::oop_iterate(ExtendedOopClosure* cl) { |
0 | 3099 if (freelistLock()->owned_by_self()) { |
3100 Generation::oop_iterate(cl); | |
3101 } else { | |
3102 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3103 Generation::oop_iterate(cl); | |
3104 } | |
3105 } | |
3106 | |
3107 void | |
3108 ConcurrentMarkSweepGeneration::object_iterate(ObjectClosure* cl) { | |
3109 if (freelistLock()->owned_by_self()) { | |
3110 Generation::object_iterate(cl); | |
3111 } else { | |
3112 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3113 Generation::object_iterate(cl); | |
3114 } | |
3115 } | |
3116 | |
3117 void | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3118 ConcurrentMarkSweepGeneration::safe_object_iterate(ObjectClosure* cl) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3119 if (freelistLock()->owned_by_self()) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3120 Generation::safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3121 } else { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3122 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3123 Generation::safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3124 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3125 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3126 |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3127 void |
0 | 3128 ConcurrentMarkSweepGeneration::post_compact() { |
3129 } | |
3130 | |
3131 void | |
3132 ConcurrentMarkSweepGeneration::prepare_for_verify() { | |
3133 // Fix the linear allocation blocks to look like free blocks. | |
3134 | |
3135 // Locks are normally acquired/released in gc_prologue/gc_epilogue, but those | |
3136 // are not called when the heap is verified during universe initialization and | |
3137 // at vm shutdown. | |
3138 if (freelistLock()->owned_by_self()) { | |
3139 cmsSpace()->prepare_for_verify(); | |
3140 } else { | |
3141 MutexLockerEx fll(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3142 cmsSpace()->prepare_for_verify(); | |
3143 } | |
3144 } | |
3145 | |
3146 void | |
6008 | 3147 ConcurrentMarkSweepGeneration::verify() { |
0 | 3148 // Locks are normally acquired/released in gc_prologue/gc_epilogue, but those |
3149 // are not called when the heap is verified during universe initialization and | |
3150 // at vm shutdown. | |
3151 if (freelistLock()->owned_by_self()) { | |
6008 | 3152 cmsSpace()->verify(); |
0 | 3153 } else { |
3154 MutexLockerEx fll(freelistLock(), Mutex::_no_safepoint_check_flag); | |
6008 | 3155 cmsSpace()->verify(); |
3156 } | |
3157 } | |
3158 | |
3159 void CMSCollector::verify() { | |
3160 _cmsGen->verify(); | |
0 | 3161 } |
3162 | |
3163 #ifndef PRODUCT | |
3164 bool CMSCollector::overflow_list_is_empty() const { | |
3165 assert(_num_par_pushes >= 0, "Inconsistency"); | |
3166 if (_overflow_list == NULL) { | |
3167 assert(_num_par_pushes == 0, "Inconsistency"); | |
3168 } | |
3169 return _overflow_list == NULL; | |
3170 } | |
3171 | |
3172 // The methods verify_work_stacks_empty() and verify_overflow_empty() | |
3173 // merely consolidate assertion checks that appear to occur together frequently. | |
3174 void CMSCollector::verify_work_stacks_empty() const { | |
3175 assert(_markStack.isEmpty(), "Marking stack should be empty"); | |
3176 assert(overflow_list_is_empty(), "Overflow list should be empty"); | |
3177 } | |
3178 | |
3179 void CMSCollector::verify_overflow_empty() const { | |
3180 assert(overflow_list_is_empty(), "Overflow list should be empty"); | |
3181 assert(no_preserved_marks(), "No preserved marks"); | |
3182 } | |
3183 #endif // PRODUCT | |
3184 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3185 // 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
|
3186 // ensuing concurrent GC cycle. We will collect and |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3187 // unload classes if it's the case that: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3188 // (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
|
3189 // ExplicitGCInvokesConcurrentAndUnloadsClasses is set, OR |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3190 // (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
|
3191 // (b) old gen is getting really full |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3192 // 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
|
3193 // 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
|
3194 // 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
|
3195 // 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
|
3196 // 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
|
3197 // the property that concurrent_cycles_since_last_unload() |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3198 // 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
|
3199 // _cmsGen->is_too_full() are |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3200 // themselves also monotonic in that sense. See check_monotonicity() |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3201 // below. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3202 void CMSCollector::update_should_unload_classes() { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3203 _should_unload_classes = false; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3204 // Condition 1 above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3205 if (_full_gc_requested && ExplicitGCInvokesConcurrentAndUnloadsClasses) { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3206 _should_unload_classes = true; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3207 } else if (CMSClassUnloadingEnabled) { // Condition 2.a above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3208 // Disjuncts 2.b.(i,ii,iii) above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3209 _should_unload_classes = (concurrent_cycles_since_last_unload() >= |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3210 CMSClassUnloadingMaxInterval) |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3211 || _cmsGen->is_too_full(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3212 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3213 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3214 |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3215 bool ConcurrentMarkSweepGeneration::is_too_full() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3216 bool res = should_concurrent_collect(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3217 res = res && (occupancy() > (double)CMSIsTooFullPercentage/100.0); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3218 return res; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3219 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3220 |
0 | 3221 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
|
3222 const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC |
0 | 3223 || VerifyBeforeExit; |
3293
1f4413413144
7039089: G1: changeset for 7037276 broke heap verification, and related cleanups
ysr
parents:
2379
diff
changeset
|
3224 const int rso = SharedHeap::SO_Strings | SharedHeap::SO_CodeCache; |
0 | 3225 |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3226 if (should_unload_classes()) { // Should unload classes this cycle |
0 | 3227 remove_root_scanning_option(rso); // Shrink the root set appropriately |
3228 set_verifying(should_verify); // Set verification state for this cycle | |
3229 return; // Nothing else needs to be done at this time | |
3230 } | |
3231 | |
3232 // Not unloading classes this cycle | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3233 assert(!should_unload_classes(), "Inconsitency!"); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3234 if ((!verifying() || unloaded_classes_last_cycle()) && should_verify) { |
0 | 3235 // Include symbols, strings and code cache elements to prevent their resurrection. |
3236 add_root_scanning_option(rso); | |
3237 set_verifying(true); | |
3238 } else if (verifying() && !should_verify) { | |
3239 // We were verifying, but some verification flags got disabled. | |
3240 set_verifying(false); | |
3241 // Exclude symbols, strings and code cache elements from root scanning to | |
3242 // reduce IM and RM pauses. | |
3243 remove_root_scanning_option(rso); | |
3244 } | |
3245 } | |
3246 | |
3247 | |
3248 #ifndef PRODUCT | |
3249 HeapWord* CMSCollector::block_start(const void* p) const { | |
3250 const HeapWord* addr = (HeapWord*)p; | |
3251 if (_span.contains(p)) { | |
3252 if (_cmsGen->cmsSpace()->is_in_reserved(addr)) { | |
3253 return _cmsGen->cmsSpace()->block_start(p); | |
3254 } | |
3255 } | |
3256 return NULL; | |
3257 } | |
3258 #endif | |
3259 | |
3260 HeapWord* | |
3261 ConcurrentMarkSweepGeneration::expand_and_allocate(size_t word_size, | |
3262 bool tlab, | |
3263 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
|
3264 CMSSynchronousYieldRequest yr; |
0 | 3265 assert(!tlab, "Can't deal with TLAB allocation"); |
3266 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3267 expand(word_size*HeapWordSize, MinHeapDeltaBytes, | |
3268 CMSExpansionCause::_satisfy_allocation); | |
3269 if (GCExpandToAllocateDelayMillis > 0) { | |
3270 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3271 } | |
9
173195ff483a
6642634: Test nsk/regression/b6186200 crashed with SIGSEGV
ysr
parents:
7
diff
changeset
|
3272 return have_lock_and_allocate(word_size, tlab); |
0 | 3273 } |
3274 | |
3275 // YSR: All of this generation expansion/shrinking stuff is an exact copy of | |
3276 // OneContigSpaceCardGeneration, which makes me wonder if we should move this | |
3277 // to CardGeneration and share it... | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3278 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
|
3279 return CardGeneration::expand(bytes, expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3280 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3281 |
0 | 3282 void ConcurrentMarkSweepGeneration::expand(size_t bytes, size_t expand_bytes, |
3283 CMSExpansionCause::Cause cause) | |
3284 { | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3285 |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3286 bool success = expand(bytes, expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3287 |
0 | 3288 // remember why we expanded; this information is used |
3289 // by shouldConcurrentCollect() when making decisions on whether to start | |
3290 // a new CMS cycle. | |
3291 if (success) { | |
3292 set_expansion_cause(cause); | |
3293 if (PrintGCDetails && Verbose) { | |
3294 gclog_or_tty->print_cr("Expanded CMS gen for %s", | |
3295 CMSExpansionCause::to_string(cause)); | |
3296 } | |
3297 } | |
3298 } | |
3299 | |
3300 HeapWord* ConcurrentMarkSweepGeneration::expand_and_par_lab_allocate(CMSParGCThreadState* ps, size_t word_sz) { | |
3301 HeapWord* res = NULL; | |
3302 MutexLocker x(ParGCRareEvent_lock); | |
3303 while (true) { | |
3304 // Expansion by some other thread might make alloc OK now: | |
3305 res = ps->lab.alloc(word_sz); | |
3306 if (res != NULL) return res; | |
3307 // If there's not enough expansion space available, give up. | |
3308 if (_virtual_space.uncommitted_size() < (word_sz * HeapWordSize)) { | |
3309 return NULL; | |
3310 } | |
3311 // Otherwise, we try expansion. | |
3312 expand(word_sz*HeapWordSize, MinHeapDeltaBytes, | |
3313 CMSExpansionCause::_allocate_par_lab); | |
3314 // Now go around the loop and try alloc again; | |
3315 // A competing par_promote might beat us to the expansion space, | |
3316 // so we may go around the loop again if promotion fails agaion. | |
3317 if (GCExpandToAllocateDelayMillis > 0) { | |
3318 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3319 } | |
3320 } | |
3321 } | |
3322 | |
3323 | |
3324 bool ConcurrentMarkSweepGeneration::expand_and_ensure_spooling_space( | |
3325 PromotionInfo* promo) { | |
3326 MutexLocker x(ParGCRareEvent_lock); | |
3327 size_t refill_size_bytes = promo->refillSize() * HeapWordSize; | |
3328 while (true) { | |
3329 // Expansion by some other thread might make alloc OK now: | |
3330 if (promo->ensure_spooling_space()) { | |
3331 assert(promo->has_spooling_space(), | |
3332 "Post-condition of successful ensure_spooling_space()"); | |
3333 return true; | |
3334 } | |
3335 // If there's not enough expansion space available, give up. | |
3336 if (_virtual_space.uncommitted_size() < refill_size_bytes) { | |
3337 return false; | |
3338 } | |
3339 // Otherwise, we try expansion. | |
3340 expand(refill_size_bytes, MinHeapDeltaBytes, | |
3341 CMSExpansionCause::_allocate_par_spooling_space); | |
3342 // Now go around the loop and try alloc again; | |
3343 // A competing allocation might beat us to the expansion space, | |
3344 // so we may go around the loop again if allocation fails again. | |
3345 if (GCExpandToAllocateDelayMillis > 0) { | |
3346 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3347 } | |
3348 } | |
3349 } | |
3350 | |
3351 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3352 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
|
3353 assert_locked_or_safepoint(ExpandHeap_lock); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3354 // Shrink committed space |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3355 _virtual_space.shrink_by(bytes); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3356 // 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
|
3357 _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
|
3358 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
|
3359 // Shrink the shared block offset array |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3360 _bts->resize(new_word_size); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3361 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
|
3362 // Shrink the card table |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3363 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
|
3364 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3365 if (Verbose && PrintGC) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3366 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
|
3367 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
|
3368 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
|
3369 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
|
3370 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3371 } |
0 | 3372 |
3373 void ConcurrentMarkSweepGeneration::shrink(size_t bytes) { | |
3374 assert_locked_or_safepoint(Heap_lock); | |
3375 size_t size = ReservedSpace::page_align_size_down(bytes); | |
3376 if (size > 0) { | |
3377 shrink_by(size); | |
3378 } | |
3379 } | |
3380 | |
3381 bool ConcurrentMarkSweepGeneration::grow_by(size_t bytes) { | |
3382 assert_locked_or_safepoint(Heap_lock); | |
3383 bool result = _virtual_space.expand_by(bytes); | |
3384 if (result) { | |
3385 HeapWord* old_end = _cmsSpace->end(); | |
3386 size_t new_word_size = | |
3387 heap_word_size(_virtual_space.committed_size()); | |
3388 MemRegion mr(_cmsSpace->bottom(), new_word_size); | |
3389 _bts->resize(new_word_size); // resize the block offset shared array | |
3390 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
3391 // Hmmmm... why doesn't CFLS::set_end verify locking? | |
3392 // This is quite ugly; FIX ME XXX | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3393 _cmsSpace->assert_locked(freelistLock()); |
0 | 3394 _cmsSpace->set_end((HeapWord*)_virtual_space.high()); |
3395 | |
3396 // update the space and generation capacity counters | |
3397 if (UsePerfData) { | |
3398 _space_counters->update_capacity(); | |
3399 _gen_counters->update_all(); | |
3400 } | |
3401 | |
3402 if (Verbose && PrintGC) { | |
3403 size_t new_mem_size = _virtual_space.committed_size(); | |
3404 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
|
3405 gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
0 | 3406 name(), old_mem_size/K, bytes/K, new_mem_size/K); |
3407 } | |
3408 } | |
3409 return result; | |
3410 } | |
3411 | |
3412 bool ConcurrentMarkSweepGeneration::grow_to_reserved() { | |
3413 assert_locked_or_safepoint(Heap_lock); | |
3414 bool success = true; | |
3415 const size_t remaining_bytes = _virtual_space.uncommitted_size(); | |
3416 if (remaining_bytes > 0) { | |
3417 success = grow_by(remaining_bytes); | |
3418 DEBUG_ONLY(if (!success) warning("grow to reserved failed");) | |
3419 } | |
3420 return success; | |
3421 } | |
3422 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3423 void ConcurrentMarkSweepGeneration::shrink_free_list_by(size_t bytes) { |
0 | 3424 assert_locked_or_safepoint(Heap_lock); |
3425 assert_lock_strong(freelistLock()); | |
10180
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3426 if (PrintGCDetails && Verbose) { |
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3427 warning("Shrinking of CMS not yet implemented"); |
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3428 } |
0 | 3429 return; |
3430 } | |
3431 | |
3432 | |
3433 // Simple ctor/dtor wrapper for accounting & timer chores around concurrent | |
3434 // phases. | |
3435 class CMSPhaseAccounting: public StackObj { | |
3436 public: | |
3437 CMSPhaseAccounting(CMSCollector *collector, | |
3438 const char *phase, | |
3439 bool print_cr = true); | |
3440 ~CMSPhaseAccounting(); | |
3441 | |
3442 private: | |
3443 CMSCollector *_collector; | |
3444 const char *_phase; | |
3445 elapsedTimer _wallclock; | |
3446 bool _print_cr; | |
3447 | |
3448 public: | |
3449 // Not MT-safe; so do not pass around these StackObj's | |
3450 // where they may be accessed by other threads. | |
3451 jlong wallclock_millis() { | |
3452 assert(_wallclock.is_active(), "Wall clock should not stop"); | |
3453 _wallclock.stop(); // to record time | |
3454 jlong ret = _wallclock.milliseconds(); | |
3455 _wallclock.start(); // restart | |
3456 return ret; | |
3457 } | |
3458 }; | |
3459 | |
3460 CMSPhaseAccounting::CMSPhaseAccounting(CMSCollector *collector, | |
3461 const char *phase, | |
3462 bool print_cr) : | |
3463 _collector(collector), _phase(phase), _print_cr(print_cr) { | |
3464 | |
3465 if (PrintCMSStatistics != 0) { | |
3466 _collector->resetYields(); | |
3467 } | |
8740
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3468 if (PrintGCDetails) { |
0 | 3469 gclog_or_tty->date_stamp(PrintGCDateStamps); |
8740
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3470 gclog_or_tty->stamp(PrintGCTimeStamps); |
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3471 gclog_or_tty->print_cr("[%s-concurrent-%s-start]", |
0 | 3472 _collector->cmsGen()->short_name(), _phase); |
3473 } | |
3474 _collector->resetTimer(); | |
3475 _wallclock.start(); | |
3476 _collector->startTimer(); | |
3477 } | |
3478 | |
3479 CMSPhaseAccounting::~CMSPhaseAccounting() { | |
3480 assert(_wallclock.is_active(), "Wall clock should not have stopped"); | |
3481 _collector->stopTimer(); | |
3482 _wallclock.stop(); | |
3483 if (PrintGCDetails) { | |
3484 gclog_or_tty->date_stamp(PrintGCDateStamps); | |
6752
9646b7ff4d14
7198130: G1: PrintReferenceGC output comes out of order
brutisso
parents:
6725
diff
changeset
|
3485 gclog_or_tty->stamp(PrintGCTimeStamps); |
0 | 3486 gclog_or_tty->print("[%s-concurrent-%s: %3.3f/%3.3f secs]", |
3487 _collector->cmsGen()->short_name(), | |
3488 _phase, _collector->timerValue(), _wallclock.seconds()); | |
3489 if (_print_cr) { | |
3490 gclog_or_tty->print_cr(""); | |
3491 } | |
3492 if (PrintCMSStatistics != 0) { | |
3493 gclog_or_tty->print_cr(" (CMS-concurrent-%s yielded %d times)", _phase, | |
3494 _collector->yields()); | |
3495 } | |
3496 } | |
3497 } | |
3498 | |
3499 // CMS work | |
3500 | |
3501 // Checkpoint the roots into this generation from outside | |
3502 // this generation. [Note this initial checkpoint need only | |
3503 // be approximate -- we'll do a catch up phase subsequently.] | |
3504 void CMSCollector::checkpointRootsInitial(bool asynch) { | |
3505 assert(_collectorState == InitialMarking, "Wrong collector state"); | |
3506 check_correct_thread_executing(); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
3507 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
3508 |
0 | 3509 ReferenceProcessor* rp = ref_processor(); |
3510 SpecializationStats::clear(); | |
3511 assert(_restart_addr == NULL, "Control point invariant"); | |
3512 if (asynch) { | |
3513 // acquire locks for subsequent manipulations | |
3514 MutexLockerEx x(bitMapLock(), | |
3515 Mutex::_no_safepoint_check_flag); | |
3516 checkpointRootsInitialWork(asynch); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3517 // enable ("weak") refs discovery |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3518 rp->enable_discovery(true /*verify_disabled*/, true /*check_no_refs*/); |
0 | 3519 _collectorState = Marking; |
3520 } else { | |
3521 // (Weak) Refs discovery: this is controlled from genCollectedHeap::do_collection | |
3522 // which recognizes if we are a CMS generation, and doesn't try to turn on | |
3523 // discovery; verify that they aren't meddling. | |
3524 assert(!rp->discovery_is_atomic(), | |
3525 "incorrect setting of discovery predicate"); | |
3526 assert(!rp->discovery_enabled(), "genCollectedHeap shouldn't control " | |
3527 "ref discovery for this generation kind"); | |
3528 // already have locks | |
3529 checkpointRootsInitialWork(asynch); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3530 // now enable ("weak") refs discovery |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3531 rp->enable_discovery(true /*verify_disabled*/, false /*verify_no_refs*/); |
0 | 3532 _collectorState = Marking; |
3533 } | |
3534 SpecializationStats::print(); | |
3535 } | |
3536 | |
3537 void CMSCollector::checkpointRootsInitialWork(bool asynch) { | |
3538 assert(SafepointSynchronize::is_at_safepoint(), "world should be stopped"); | |
3539 assert(_collectorState == InitialMarking, "just checking"); | |
3540 | |
3541 // If there has not been a GC[n-1] since last GC[n] cycle completed, | |
3542 // precede our marking with a collection of all | |
3543 // younger generations to keep floating garbage to a minimum. | |
3544 // XXX: we won't do this for now -- it's an optimization to be done later. | |
3545 | |
3546 // already have locks | |
3547 assert_lock_strong(bitMapLock()); | |
3548 assert(_markBitMap.isAllClear(), "was reset at end of previous cycle"); | |
3549 | |
3550 // Setup the verification and class unloading state for this | |
3551 // CMS collection cycle. | |
3552 setup_cms_unloading_and_verification_state(); | |
3553 | |
3554 NOT_PRODUCT(TraceTime t("\ncheckpointRootsInitialWork", | |
3555 PrintGCDetails && Verbose, true, gclog_or_tty);) | |
3556 if (UseAdaptiveSizePolicy) { | |
3557 size_policy()->checkpoint_roots_initial_begin(); | |
3558 } | |
3559 | |
3560 // Reset all the PLAB chunk arrays if necessary. | |
3561 if (_survivor_plab_array != NULL && !CMSPLABRecordAlways) { | |
3562 reset_survivor_plab_arrays(); | |
3563 } | |
3564 | |
3565 ResourceMark rm; | |
3566 HandleMark hm; | |
3567 | |
3568 FalseClosure falseClosure; | |
3569 // In the case of a synchronous collection, we will elide the | |
3570 // remark step, so it's important to catch all the nmethod oops | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3571 // in this step. |
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3572 // The final 'true' flag to gen_process_strong_roots will ensure this. |
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3573 // If 'async' is true, we can relax the nmethod tracing. |
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3574 MarkRefsIntoClosure notOlder(_span, &_markBitMap); |
0 | 3575 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3576 | |
3577 verify_work_stacks_empty(); | |
3578 verify_overflow_empty(); | |
3579 | |
3580 gch->ensure_parsability(false); // fill TLABs, but no need to retire them | |
3581 // Update the saved marks which may affect the root scans. | |
3582 gch->save_marks(); | |
3583 | |
3584 // weak reference processing has not started yet. | |
3585 ref_processor()->set_enqueuing_is_done(false); | |
3586 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3587 // Need to remember all newly created CLDs, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3588 // 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
|
3589 ClassLoaderDataGraph::remember_new_clds(true); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3590 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3591 // 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
|
3592 // 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
|
3593 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3594 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3595 CMKlassClosure klass_closure(¬Older); |
0 | 3596 { |
3597 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
3598 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. | |
3599 gch->gen_process_strong_roots(_cmsGen->level(), | |
3600 true, // younger gens are roots | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
3601 true, // activate StrongRootsScope |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3602 false, // not scavenging |
0 | 3603 SharedHeap::ScanningOption(roots_scanning_options()), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
3604 ¬Older, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
3605 true, // walk all of code cache if (so & SO_CodeCache) |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3606 NULL, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3607 &klass_closure); |
0 | 3608 } |
3609 | |
3610 // Clear mod-union table; it will be dirtied in the prologue of | |
3611 // CMS generation per each younger generation collection. | |
3612 | |
3613 assert(_modUnionTable.isAllClear(), | |
3614 "Was cleared in most recent final checkpoint phase" | |
3615 " or no bits are set in the gc_prologue before the start of the next " | |
3616 "subsequent marking phase."); | |
3617 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3618 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
|
3619 |
0 | 3620 // Save the end of the used_region of the constituent generations |
3621 // to be used to limit the extent of sweep in each generation. | |
3622 save_sweep_limits(); | |
3623 if (UseAdaptiveSizePolicy) { | |
3624 size_policy()->checkpoint_roots_initial_end(gch->gc_cause()); | |
3625 } | |
3626 verify_overflow_empty(); | |
3627 } | |
3628 | |
3629 bool CMSCollector::markFromRoots(bool asynch) { | |
3630 // we might be tempted to assert that: | |
3631 // assert(asynch == !SafepointSynchronize::is_at_safepoint(), | |
3632 // "inconsistent argument?"); | |
3633 // However that wouldn't be right, because it's possible that | |
3634 // a safepoint is indeed in progress as a younger generation | |
3635 // stop-the-world GC happens even as we mark in this generation. | |
3636 assert(_collectorState == Marking, "inconsistent state?"); | |
3637 check_correct_thread_executing(); | |
3638 verify_overflow_empty(); | |
3639 | |
3640 bool res; | |
3641 if (asynch) { | |
3642 | |
3643 // Start the timers for adaptive size policy for the concurrent phases | |
3644 // Do it here so that the foreground MS can use the concurrent | |
3645 // timer since a foreground MS might has the sweep done concurrently | |
3646 // or STW. | |
3647 if (UseAdaptiveSizePolicy) { | |
3648 size_policy()->concurrent_marking_begin(); | |
3649 } | |
3650 | |
3651 // Weak ref discovery note: We may be discovering weak | |
3652 // refs in this generation concurrent (but interleaved) with | |
3653 // weak ref discovery by a younger generation collector. | |
3654 | |
3655 CMSTokenSyncWithLocks ts(true, bitMapLock()); | |
3656 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
3657 CMSPhaseAccounting pa(this, "mark", !PrintGCDetails); | |
3658 res = markFromRootsWork(asynch); | |
3659 if (res) { | |
3660 _collectorState = Precleaning; | |
3661 } else { // We failed and a foreground collection wants to take over | |
3662 assert(_foregroundGCIsActive, "internal state inconsistency"); | |
3663 assert(_restart_addr == NULL, "foreground will restart from scratch"); | |
3664 if (PrintGCDetails) { | |
3665 gclog_or_tty->print_cr("bailing out to foreground collection"); | |
3666 } | |
3667 } | |
3668 if (UseAdaptiveSizePolicy) { | |
3669 size_policy()->concurrent_marking_end(); | |
3670 } | |
3671 } else { | |
3672 assert(SafepointSynchronize::is_at_safepoint(), | |
3673 "inconsistent with asynch == false"); | |
3674 if (UseAdaptiveSizePolicy) { | |
3675 size_policy()->ms_collection_marking_begin(); | |
3676 } | |
3677 // already have locks | |
3678 res = markFromRootsWork(asynch); | |
3679 _collectorState = FinalMarking; | |
3680 if (UseAdaptiveSizePolicy) { | |
3681 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3682 size_policy()->ms_collection_marking_end(gch->gc_cause()); | |
3683 } | |
3684 } | |
3685 verify_overflow_empty(); | |
3686 return res; | |
3687 } | |
3688 | |
3689 bool CMSCollector::markFromRootsWork(bool asynch) { | |
3690 // iterate over marked bits in bit map, doing a full scan and mark | |
3691 // from these roots using the following algorithm: | |
3692 // . if oop is to the right of the current scan pointer, | |
3693 // mark corresponding bit (we'll process it later) | |
3694 // . else (oop is to left of current scan pointer) | |
3695 // push oop on marking stack | |
3696 // . drain the marking stack | |
3697 | |
3698 // Note that when we do a marking step we need to hold the | |
3699 // bit map lock -- recall that direct allocation (by mutators) | |
3700 // and promotion (by younger generation collectors) is also | |
3701 // marking the bit map. [the so-called allocate live policy.] | |
3702 // Because the implementation of bit map marking is not | |
3703 // robust wrt simultaneous marking of bits in the same word, | |
3704 // we need to make sure that there is no such interference | |
3705 // between concurrent such updates. | |
3706 | |
3707 // already have locks | |
3708 assert_lock_strong(bitMapLock()); | |
3709 | |
3710 verify_work_stacks_empty(); | |
3711 verify_overflow_empty(); | |
3712 bool result = false; | |
1284 | 3713 if (CMSConcurrentMTEnabled && ConcGCThreads > 0) { |
0 | 3714 result = do_marking_mt(asynch); |
3715 } else { | |
3716 result = do_marking_st(asynch); | |
3717 } | |
3718 return result; | |
3719 } | |
3720 | |
3721 // Forward decl | |
3722 class CMSConcMarkingTask; | |
3723 | |
3724 class CMSConcMarkingTerminator: public ParallelTaskTerminator { | |
3725 CMSCollector* _collector; | |
3726 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
|
3727 public: |
0 | 3728 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
|
3729 |
0 | 3730 // "n_threads" is the number of threads to be terminated. |
3731 // "queue_set" is a set of work queues of other threads. | |
3732 // "collector" is the CMS collector associated with this task terminator. | |
3733 // "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
|
3734 CMSConcMarkingTerminator(int n_threads, TaskQueueSetSuper* queue_set, CMSCollector* collector) : |
0 | 3735 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
|
3736 _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
|
3737 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3738 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
|
3739 _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
|
3740 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3741 }; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3742 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3743 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
|
3744 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
|
3745 public: |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3746 bool should_exit_termination(); |
0 | 3747 void set_task(CMSConcMarkingTask* task) { |
3748 _task = task; | |
3749 } | |
3750 }; | |
3751 | |
3752 // MT Concurrent Marking Task | |
3753 class CMSConcMarkingTask: public YieldingFlexibleGangTask { | |
3754 CMSCollector* _collector; | |
3755 int _n_workers; // requested/desired # workers | |
3756 bool _asynch; | |
3757 bool _result; | |
3758 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
|
3759 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
|
3760 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
|
3761 char _pad_back[64]; |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3762 HeapWord* _restart_addr; |
0 | 3763 |
3764 // Exposed here for yielding support | |
3765 Mutex* const _bit_map_lock; | |
3766 | |
3767 // The per thread work queues, available here for stealing | |
3768 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
|
3769 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3770 // Termination (and yielding) support |
0 | 3771 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
|
3772 CMSConcMarkingTerminatorTerminator _term_term; |
0 | 3773 |
3774 public: | |
3775 CMSConcMarkingTask(CMSCollector* collector, | |
3776 CompactibleFreeListSpace* cms_space, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3777 bool asynch, |
0 | 3778 YieldingFlexibleWorkGang* workers, |
3779 OopTaskQueueSet* task_queues): | |
3780 YieldingFlexibleGangTask("Concurrent marking done multi-threaded"), | |
3781 _collector(collector), | |
3782 _cms_space(cms_space), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3783 _asynch(asynch), _n_workers(0), _result(true), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3784 _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
|
3785 _term(_n_workers, task_queues, _collector), |
0 | 3786 _bit_map_lock(collector->bitMapLock()) |
3787 { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3788 _requested_size = _n_workers; |
0 | 3789 _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
|
3790 _term_term.set_task(this); |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3791 _restart_addr = _global_finger = _cms_space->bottom(); |
0 | 3792 } |
3793 | |
3794 | |
3795 OopTaskQueueSet* task_queues() { return _task_queues; } | |
3796 | |
3797 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
3798 | |
3799 HeapWord** global_finger_addr() { return &_global_finger; } | |
3800 | |
3801 CMSConcMarkingTerminator* terminator() { return &_term; } | |
3802 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3803 virtual void set_for_termination(int active_workers) { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3804 terminator()->reset_for_reuse(active_workers); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3805 } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3806 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3807 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
|
3808 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
|
3809 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
|
3810 && !_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
|
3811 && _asynch; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3812 } |
0 | 3813 |
3814 virtual void coordinator_yield(); // stuff done by coordinator | |
3815 bool result() { return _result; } | |
3816 | |
3817 void reset(HeapWord* ra) { | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3818 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
|
3819 _restart_addr = _global_finger = ra; |
0 | 3820 _term.reset_for_reuse(); |
3821 } | |
3822 | |
3823 static bool get_work_from_overflow_stack(CMSMarkStack* ovflw_stk, | |
3824 OopTaskQueue* work_q); | |
3825 | |
3826 private: | |
3827 void do_scan_and_mark(int i, CompactibleFreeListSpace* sp); | |
3828 void do_work_steal(int i); | |
3829 void bump_global_finger(HeapWord* f); | |
3830 }; | |
3831 | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3832 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
|
3833 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
|
3834 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
|
3835 // 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
|
3836 // 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
|
3837 // 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
|
3838 // 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
|
3839 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3840 |
0 | 3841 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
|
3842 if (_task->should_yield()) { |
0 | 3843 _task->yield(); |
3844 } else { | |
3845 ParallelTaskTerminator::yield(); | |
3846 } | |
3847 } | |
3848 | |
3849 //////////////////////////////////////////////////////////////// | |
3850 // Concurrent Marking Algorithm Sketch | |
3851 //////////////////////////////////////////////////////////////// | |
3852 // Until all tasks exhausted (both spaces): | |
3853 // -- claim next available chunk | |
3854 // -- bump global finger via CAS | |
3855 // -- find first object that starts in this chunk | |
3856 // and start scanning bitmap from that position | |
3857 // -- scan marked objects for oops | |
3858 // -- CAS-mark target, and if successful: | |
3859 // . if target oop is above global finger (volatile read) | |
3860 // nothing to do | |
3861 // . if target oop is in chunk and above local finger | |
3862 // then nothing to do | |
3863 // . else push on work-queue | |
3864 // -- Deal with possible overflow issues: | |
3865 // . local work-queue overflow causes stuff to be pushed on | |
3866 // global (common) overflow queue | |
3867 // . always first empty local work queue | |
3868 // . then get a batch of oops from global work queue if any | |
3869 // . then do work stealing | |
3870 // -- When all tasks claimed (both spaces) | |
3871 // and local work queue empty, | |
3872 // then in a loop do: | |
3873 // . check global overflow stack; steal a batch of oops and trace | |
3874 // . try to steal from other threads oif GOS is empty | |
3875 // . if neither is available, offer termination | |
3876 // -- Terminate and return result | |
3877 // | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3878 void CMSConcMarkingTask::work(uint worker_id) { |
0 | 3879 elapsedTimer _timer; |
3880 ResourceMark rm; | |
3881 HandleMark hm; | |
3882 | |
3883 DEBUG_ONLY(_collector->verify_overflow_empty();) | |
3884 | |
3885 // 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
|
3886 assert(work_queue(worker_id)->size() == 0, "Expected to be empty"); |
0 | 3887 // Scan the bitmap covering _cms_space, tracing through grey objects. |
3888 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3889 do_scan_and_mark(worker_id, _cms_space); |
0 | 3890 _timer.stop(); |
3891 if (PrintCMSStatistics != 0) { | |
3892 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
|
3893 worker_id, _timer.seconds()); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3894 // XXX: need xxx/xxx type of notation, two timers |
0 | 3895 } |
3896 | |
3897 // ... do work stealing | |
3898 _timer.reset(); | |
3899 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3900 do_work_steal(worker_id); |
0 | 3901 _timer.stop(); |
3902 if (PrintCMSStatistics != 0) { | |
3903 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
|
3904 worker_id, _timer.seconds()); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3905 // XXX: need xxx/xxx type of notation, two timers |
0 | 3906 } |
3907 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
|
3908 assert(work_queue(worker_id)->size() == 0, "Should have been emptied"); |
0 | 3909 // Note that under the current task protocol, the |
3910 // following assertion is true even of the spaces | |
3911 // expanded since the completion of the concurrent | |
3912 // marking. XXX This will likely change under a strict | |
3913 // ABORT semantics. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3914 // After perm removal the comparison was changed to |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3915 // 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
|
3916 // Before perm removal the highest address sweep would |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3917 // 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
|
3918 // end of the tenured gen. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3919 assert(_global_finger >= _cms_space->end(), |
0 | 3920 "All tasks have been completed"); |
3921 DEBUG_ONLY(_collector->verify_overflow_empty();) | |
3922 } | |
3923 | |
3924 void CMSConcMarkingTask::bump_global_finger(HeapWord* f) { | |
3925 HeapWord* read = _global_finger; | |
3926 HeapWord* cur = read; | |
3927 while (f > read) { | |
3928 cur = read; | |
3929 read = (HeapWord*) Atomic::cmpxchg_ptr(f, &_global_finger, cur); | |
3930 if (cur == read) { | |
3931 // our cas succeeded | |
3932 assert(_global_finger >= f, "protocol consistency"); | |
3933 break; | |
3934 } | |
3935 } | |
3936 } | |
3937 | |
3938 // This is really inefficient, and should be redone by | |
3939 // using (not yet available) block-read and -write interfaces to the | |
3940 // stack and the work_queue. XXX FIX ME !!! | |
3941 bool CMSConcMarkingTask::get_work_from_overflow_stack(CMSMarkStack* ovflw_stk, | |
3942 OopTaskQueue* work_q) { | |
3943 // Fast lock-free check | |
3944 if (ovflw_stk->length() == 0) { | |
3945 return false; | |
3946 } | |
3947 assert(work_q->size() == 0, "Shouldn't steal"); | |
3948 MutexLockerEx ml(ovflw_stk->par_lock(), | |
3949 Mutex::_no_safepoint_check_flag); | |
3950 // 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
|
3951 size_t num = MIN2((size_t)(work_q->max_elems() - work_q->size())/4, |
0 | 3952 (size_t)ParGCDesiredObjsFromOverflowList); |
3953 num = MIN2(num, ovflw_stk->length()); | |
3954 for (int i = (int) num; i > 0; i--) { | |
3955 oop cur = ovflw_stk->pop(); | |
3956 assert(cur != NULL, "Counted wrong?"); | |
3957 work_q->push(cur); | |
3958 } | |
3959 return num > 0; | |
3960 } | |
3961 | |
3962 void CMSConcMarkingTask::do_scan_and_mark(int i, CompactibleFreeListSpace* sp) { | |
3963 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); | |
3964 int n_tasks = pst->n_tasks(); | |
3965 // We allow that there may be no tasks to do here because | |
3966 // we are restarting after a stack overflow. | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3967 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
|
3968 uint nth_task = 0; |
0 | 3969 |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3970 HeapWord* aligned_start = sp->bottom(); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3971 if (sp->used_region().contains(_restart_addr)) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3972 // 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
|
3973 // for this space. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3974 aligned_start = |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3975 (HeapWord*)align_size_down((uintptr_t)_restart_addr, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3976 CardTableModRefBS::card_size); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3977 } |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3978 |
0 | 3979 size_t chunk_size = sp->marking_task_size(); |
3980 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
3981 // Having claimed the nth task in this space, | |
3982 // compute the chunk that it corresponds to: | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3983 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
|
3984 aligned_start + (nth_task+1)*chunk_size); |
0 | 3985 // Try and bump the global finger via a CAS; |
3986 // note that we need to do the global finger bump | |
3987 // _before_ taking the intersection below, because | |
3988 // the task corresponding to that region will be | |
3989 // deemed done even if the used_region() expands | |
3990 // because of allocation -- as it almost certainly will | |
3991 // during start-up while the threads yield in the | |
3992 // closure below. | |
3993 HeapWord* finger = span.end(); | |
3994 bump_global_finger(finger); // atomically | |
3995 // There are null tasks here corresponding to chunks | |
3996 // beyond the "top" address of the space. | |
3997 span = span.intersection(sp->used_region()); | |
3998 if (!span.is_empty()) { // Non-null task | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3999 HeapWord* prev_obj; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4000 assert(!span.contains(_restart_addr) || nth_task == 0, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4001 "Inconsistency"); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4002 if (nth_task == 0) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4003 // 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
|
4004 if (span.contains(_restart_addr)) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4005 // 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
|
4006 // we might additionally skip a chunk prefix. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4007 prev_obj = _restart_addr; |
0 | 4008 } else { |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4009 prev_obj = span.start(); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4010 } |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4011 } else { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4012 // We want to skip the first object because |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4013 // 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
|
4014 // that _starts_ in this span; a fortiori, any |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4015 // object starting in an earlier span is scanned |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4016 // as part of an earlier claimed task. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4017 // 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
|
4018 // 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
|
4019 prev_obj = sp->block_start_careful(span.start()); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4020 // 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
|
4021 // Printezis bits to avoid waiting for allocated |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4022 // objects to become initialized/parsable. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4023 while (prev_obj < span.start()) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4024 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
|
4025 if (sz > 0) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4026 prev_obj += sz; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4027 } else { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4028 // 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
|
4029 // scanning, but that appears unavoidable, short of |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4030 // locking the free list locks; see bug 6324141. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4031 break; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4032 } |
0 | 4033 } |
4034 } | |
4035 if (prev_obj < span.end()) { | |
4036 MemRegion my_span = MemRegion(prev_obj, span.end()); | |
4037 // Do the marking work within a non-empty span -- | |
4038 // the last argument to the constructor indicates whether the | |
4039 // iteration should be incremental with periodic yields. | |
4040 Par_MarkFromRootsClosure cl(this, _collector, my_span, | |
4041 &_collector->_markBitMap, | |
4042 work_queue(i), | |
4043 &_collector->_markStack, | |
4044 _asynch); | |
4045 _collector->_markBitMap.iterate(&cl, my_span.start(), my_span.end()); | |
4046 } // else nothing to do for this task | |
4047 } // else nothing to do for this task | |
4048 } | |
4049 // We'd be tempted to assert here that since there are no | |
4050 // more tasks left to claim in this space, the global_finger | |
4051 // must exceed space->top() and a fortiori space->end(). However, | |
4052 // that would not quite be correct because the bumping of | |
4053 // global_finger occurs strictly after the claiming of a task, | |
4054 // so by the time we reach here the global finger may not yet | |
4055 // have been bumped up by the thread that claimed the last | |
4056 // task. | |
4057 pst->all_tasks_completed(); | |
4058 } | |
4059 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4060 class Par_ConcMarkingClosure: public CMSOopClosure { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4061 private: |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4062 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
|
4063 CMSConcMarkingTask* _task; |
0 | 4064 MemRegion _span; |
4065 CMSBitMap* _bit_map; | |
4066 CMSMarkStack* _overflow_stack; | |
4067 OopTaskQueue* _work_queue; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4068 protected: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4069 DO_OOP_WORK_DEFN |
0 | 4070 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
|
4071 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
|
4072 CMSBitMap* bit_map, CMSMarkStack* overflow_stack): |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4073 CMSOopClosure(collector->ref_processor()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4074 _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
|
4075 _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
|
4076 _span(collector->_span), |
0 | 4077 _work_queue(work_queue), |
4078 _bit_map(bit_map), | |
935 | 4079 _overflow_stack(overflow_stack) |
4080 { } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4081 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
|
4082 virtual void do_oop(narrowOop* p); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4083 |
0 | 4084 void trim_queue(size_t max); |
4085 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
|
4086 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
|
4087 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
|
4088 _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
|
4089 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4090 } |
0 | 4091 }; |
4092 | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4093 // Grey object scanning during work stealing phase -- |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4094 // the salient assumption here is that any references |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4095 // 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
|
4096 // 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
|
4097 // 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
|
4098 // 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
|
4099 void Par_ConcMarkingClosure::do_oop(oop obj) { |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4100 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
|
4101 HeapWord* addr = (HeapWord*)obj; |
0 | 4102 // Check if oop points into the CMS generation |
4103 // and is not marked | |
4104 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
4105 // a white object ... | |
4106 // If we manage to "claim" the object, by being the | |
4107 // first thread to mark it, then we push it on our | |
4108 // marking stack | |
4109 if (_bit_map->par_mark(addr)) { // ... now grey | |
4110 // push on work queue (grey set) | |
4111 bool simulate_overflow = false; | |
4112 NOT_PRODUCT( | |
4113 if (CMSMarkStackOverflowALot && | |
4114 _collector->simulate_overflow()) { | |
4115 // simulate a stack overflow | |
4116 simulate_overflow = true; | |
4117 } | |
4118 ) | |
4119 if (simulate_overflow || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4120 !(_work_queue->push(obj) || _overflow_stack->par_push(obj))) { |
0 | 4121 // stack overflow |
4122 if (PrintCMSStatistics != 0) { | |
4123 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
4124 SIZE_FORMAT, _overflow_stack->capacity()); | |
4125 } | |
4126 // We cannot assert that the overflow stack is full because | |
4127 // it may have been emptied since. | |
4128 assert(simulate_overflow || | |
4129 _work_queue->size() == _work_queue->max_elems(), | |
4130 "Else push should have succeeded"); | |
4131 handle_stack_overflow(addr); | |
4132 } | |
4133 } // 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
|
4134 do_yield_check(); |
0 | 4135 } |
4136 } | |
4137 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4138 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
|
4139 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
|
4140 |
0 | 4141 void Par_ConcMarkingClosure::trim_queue(size_t max) { |
4142 while (_work_queue->size() > max) { | |
4143 oop new_oop; | |
4144 if (_work_queue->pop_local(new_oop)) { | |
4145 assert(new_oop->is_oop(), "Should be an oop"); | |
4146 assert(_bit_map->isMarked((HeapWord*)new_oop), "Grey object"); | |
4147 assert(_span.contains((HeapWord*)new_oop), "Not in span"); | |
4148 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
|
4149 do_yield_check(); |
0 | 4150 } |
4151 } | |
4152 } | |
4153 | |
4154 // Upon stack overflow, we discard (part of) the stack, | |
4155 // remembering the least address amongst those discarded | |
4156 // in CMSCollector's _restart_address. | |
4157 void Par_ConcMarkingClosure::handle_stack_overflow(HeapWord* lost) { | |
4158 // 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
|
4159 // workers from interfering with the work done below. |
0 | 4160 MutexLockerEx ml(_overflow_stack->par_lock(), |
4161 Mutex::_no_safepoint_check_flag); | |
4162 // Remember the least grey address discarded | |
4163 HeapWord* ra = (HeapWord*)_overflow_stack->least_value(lost); | |
4164 _collector->lower_restart_addr(ra); | |
4165 _overflow_stack->reset(); // discard stack contents | |
4166 _overflow_stack->expand(); // expand the stack if possible | |
4167 } | |
4168 | |
4169 | |
4170 void CMSConcMarkingTask::do_work_steal(int i) { | |
4171 OopTaskQueue* work_q = work_queue(i); | |
4172 oop obj_to_scan; | |
4173 CMSBitMap* bm = &(_collector->_markBitMap); | |
4174 CMSMarkStack* ovflw = &(_collector->_markStack); | |
4175 int* seed = _collector->hash_seed(i); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4176 Par_ConcMarkingClosure cl(_collector, this, work_q, bm, ovflw); |
0 | 4177 while (true) { |
4178 cl.trim_queue(0); | |
4179 assert(work_q->size() == 0, "Should have been emptied above"); | |
4180 if (get_work_from_overflow_stack(ovflw, work_q)) { | |
4181 // Can't assert below because the work obtained from the | |
4182 // overflow stack may already have been stolen from us. | |
4183 // assert(work_q->size() > 0, "Work from overflow stack"); | |
4184 continue; | |
4185 } else if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
4186 assert(obj_to_scan->is_oop(), "Should be an oop"); | |
4187 assert(bm->isMarked((HeapWord*)obj_to_scan), "Grey object"); | |
4188 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
|
4189 } else if (terminator()->offer_termination(&_term_term)) { |
0 | 4190 assert(work_q->size() == 0, "Impossible!"); |
4191 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
|
4192 } 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
|
4193 yield(); |
0 | 4194 } |
4195 } | |
4196 } | |
4197 | |
4198 // This is run by the CMS (coordinator) thread. | |
4199 void CMSConcMarkingTask::coordinator_yield() { | |
4200 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
4201 "CMS thread should hold CMS token"); | |
4202 // First give up the locks, then yield, then re-lock | |
4203 // We should probably use a constructor/destructor idiom to | |
4204 // do this unlock/lock or modify the MutexUnlocker class to | |
4205 // serve our purpose. XXX | |
4206 assert_lock_strong(_bit_map_lock); | |
4207 _bit_map_lock->unlock(); | |
4208 ConcurrentMarkSweepThread::desynchronize(true); | |
4209 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
4210 _collector->stopTimer(); | |
4211 if (PrintCMSStatistics != 0) { | |
4212 _collector->incrementYields(); | |
4213 } | |
4214 _collector->icms_wait(); | |
4215 | |
4216 // It is possible for whichever thread initiated the yield request | |
4217 // not to get a chance to wake up and take the bitmap lock between | |
4218 // this thread releasing it and reacquiring it. So, while the | |
4219 // should_yield() flag is on, let's sleep for a bit to give the | |
4220 // other thread a chance to wake up. The limit imposed on the number | |
4221 // of iterations is defensive, to avoid any unforseen circumstances | |
4222 // putting us into an infinite loop. Since it's always been this | |
4223 // (coordinator_yield()) method that was observed to cause the | |
4224 // problem, we are using a parameter (CMSCoordinatorYieldSleepCount) | |
4225 // which is by default non-zero. For the other seven methods that | |
4226 // also perform the yield operation, as are using a different | |
4227 // parameter (CMSYieldSleepCount) which is by default zero. This way we | |
4228 // can enable the sleeping for those methods too, if necessary. | |
4229 // See 6442774. | |
4230 // | |
4231 // We really need to reconsider the synchronization between the GC | |
4232 // thread and the yield-requesting threads in the future and we | |
4233 // should really use wait/notify, which is the recommended | |
4234 // way of doing this type of interaction. Additionally, we should | |
4235 // consolidate the eight methods that do the yield operation and they | |
4236 // are almost identical into one for better maintenability and | |
4237 // readability. See 6445193. | |
4238 // | |
4239 // Tony 2006.06.29 | |
4240 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
|
4241 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4242 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 4243 os::sleep(Thread::current(), 1, false); |
4244 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
4245 } | |
4246 | |
4247 ConcurrentMarkSweepThread::synchronize(true); | |
4248 _bit_map_lock->lock_without_safepoint_check(); | |
4249 _collector->startTimer(); | |
4250 } | |
4251 | |
4252 bool CMSCollector::do_marking_mt(bool asynch) { | |
1284 | 4253 assert(ConcGCThreads > 0 && conc_workers() != NULL, "precondition"); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4254 int num_workers = AdaptiveSizePolicy::calc_active_conc_workers( |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4255 conc_workers()->total_workers(), |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4256 conc_workers()->active_workers(), |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4257 Threads::number_of_non_daemon_threads()); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4258 conc_workers()->set_active_workers(num_workers); |
0 | 4259 |
4260 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); | |
4261 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4262 CMSConcMarkingTask tsk(this, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4263 cms_space, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4264 asynch, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4265 conc_workers(), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4266 task_queues()); |
0 | 4267 |
4268 // Since the actual number of workers we get may be different | |
4269 // from the number we requested above, do we need to do anything different | |
4270 // below? In particular, may be we need to subclass the SequantialSubTasksDone | |
4271 // class?? XXX | |
4272 cms_space ->initialize_sequential_subtasks_for_marking(num_workers); | |
4273 | |
4274 // Refs discovery is already non-atomic. | |
4275 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
|
4276 assert(ref_processor()->discovery_is_mt(), "Discovery should be MT"); |
0 | 4277 conc_workers()->start_task(&tsk); |
4278 while (tsk.yielded()) { | |
4279 tsk.coordinator_yield(); | |
4280 conc_workers()->continue_task(&tsk); | |
4281 } | |
4282 // If the task was aborted, _restart_addr will be non-NULL | |
4283 assert(tsk.completed() || _restart_addr != NULL, "Inconsistency"); | |
4284 while (_restart_addr != NULL) { | |
4285 // XXX For now we do not make use of ABORTED state and have not | |
4286 // yet implemented the right abort semantics (even in the original | |
4287 // single-threaded CMS case). That needs some more investigation | |
4288 // and is deferred for now; see CR# TBF. 07252005YSR. XXX | |
4289 assert(!CMSAbortSemantics || tsk.aborted(), "Inconsistency"); | |
4290 // If _restart_addr is non-NULL, a marking stack overflow | |
605 | 4291 // occurred; we need to do a fresh marking iteration from the |
0 | 4292 // indicated restart address. |
4293 if (_foregroundGCIsActive && asynch) { | |
4294 // We may be running into repeated stack overflows, having | |
4295 // reached the limit of the stack size, while making very | |
4296 // slow forward progress. It may be best to bail out and | |
4297 // let the foreground collector do its job. | |
4298 // Clear _restart_addr, so that foreground GC | |
4299 // works from scratch. This avoids the headache of | |
4300 // a "rescan" which would otherwise be needed because | |
4301 // of the dirty mod union table & card table. | |
4302 _restart_addr = NULL; | |
4303 return false; | |
4304 } | |
4305 // Adjust the task to restart from _restart_addr | |
4306 tsk.reset(_restart_addr); | |
4307 cms_space ->initialize_sequential_subtasks_for_marking(num_workers, | |
4308 _restart_addr); | |
4309 _restart_addr = NULL; | |
4310 // Get the workers going again | |
4311 conc_workers()->start_task(&tsk); | |
4312 while (tsk.yielded()) { | |
4313 tsk.coordinator_yield(); | |
4314 conc_workers()->continue_task(&tsk); | |
4315 } | |
4316 } | |
4317 assert(tsk.completed(), "Inconsistency"); | |
4318 assert(tsk.result() == true, "Inconsistency"); | |
4319 return true; | |
4320 } | |
4321 | |
4322 bool CMSCollector::do_marking_st(bool asynch) { | |
4323 ResourceMark rm; | |
4324 HandleMark hm; | |
4325 | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4326 // Temporarily make refs discovery single threaded (non-MT) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4327 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(ref_processor(), false); |
0 | 4328 MarkFromRootsClosure markFromRootsClosure(this, _span, &_markBitMap, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4329 &_markStack, CMSYield && asynch); |
0 | 4330 // the last argument to iterate indicates whether the iteration |
4331 // should be incremental with periodic yields. | |
4332 _markBitMap.iterate(&markFromRootsClosure); | |
4333 // If _restart_addr is non-NULL, a marking stack overflow | |
605 | 4334 // occurred; we need to do a fresh iteration from the |
0 | 4335 // indicated restart address. |
4336 while (_restart_addr != NULL) { | |
4337 if (_foregroundGCIsActive && asynch) { | |
4338 // We may be running into repeated stack overflows, having | |
4339 // reached the limit of the stack size, while making very | |
4340 // slow forward progress. It may be best to bail out and | |
4341 // let the foreground collector do its job. | |
4342 // Clear _restart_addr, so that foreground GC | |
4343 // works from scratch. This avoids the headache of | |
4344 // a "rescan" which would otherwise be needed because | |
4345 // of the dirty mod union table & card table. | |
4346 _restart_addr = NULL; | |
4347 return false; // indicating failure to complete marking | |
4348 } | |
4349 // Deal with stack overflow: | |
4350 // we restart marking from _restart_addr | |
4351 HeapWord* ra = _restart_addr; | |
4352 markFromRootsClosure.reset(ra); | |
4353 _restart_addr = NULL; | |
4354 _markBitMap.iterate(&markFromRootsClosure, ra, _span.end()); | |
4355 } | |
4356 return true; | |
4357 } | |
4358 | |
4359 void CMSCollector::preclean() { | |
4360 check_correct_thread_executing(); | |
4361 assert(Thread::current()->is_ConcurrentGC_thread(), "Wrong thread"); | |
4362 verify_work_stacks_empty(); | |
4363 verify_overflow_empty(); | |
4364 _abort_preclean = false; | |
4365 if (CMSPrecleaningEnabled) { | |
4366 _eden_chunk_index = 0; | |
4367 size_t used = get_eden_used(); | |
4368 size_t capacity = get_eden_capacity(); | |
4369 // Don't start sampling unless we will get sufficiently | |
4370 // many samples. | |
4371 if (used < (capacity/(CMSScheduleRemarkSamplingRatio * 100) | |
4372 * CMSScheduleRemarkEdenPenetration)) { | |
4373 _start_sampling = true; | |
4374 } else { | |
4375 _start_sampling = false; | |
4376 } | |
4377 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
4378 CMSPhaseAccounting pa(this, "preclean", !PrintGCDetails); | |
4379 preclean_work(CMSPrecleanRefLists1, CMSPrecleanSurvivors1); | |
4380 } | |
4381 CMSTokenSync x(true); // is cms thread | |
4382 if (CMSPrecleaningEnabled) { | |
4383 sample_eden(); | |
4384 _collectorState = AbortablePreclean; | |
4385 } else { | |
4386 _collectorState = FinalMarking; | |
4387 } | |
4388 verify_work_stacks_empty(); | |
4389 verify_overflow_empty(); | |
4390 } | |
4391 | |
4392 // Try and schedule the remark such that young gen | |
4393 // occupancy is CMSScheduleRemarkEdenPenetration %. | |
4394 void CMSCollector::abortable_preclean() { | |
4395 check_correct_thread_executing(); | |
4396 assert(CMSPrecleaningEnabled, "Inconsistent control state"); | |
4397 assert(_collectorState == AbortablePreclean, "Inconsistent control state"); | |
4398 | |
4399 // If Eden's current occupancy is below this threshold, | |
4400 // immediately schedule the remark; else preclean | |
4401 // past the next scavenge in an effort to | |
4402 // schedule the pause as described avove. By choosing | |
4403 // CMSScheduleRemarkEdenSizeThreshold >= max eden size | |
4404 // we will never do an actual abortable preclean cycle. | |
4405 if (get_eden_used() > CMSScheduleRemarkEdenSizeThreshold) { | |
4406 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
4407 CMSPhaseAccounting pa(this, "abortable-preclean", !PrintGCDetails); | |
4408 // We need more smarts in the abortable preclean | |
4409 // loop below to deal with cases where allocation | |
4410 // in young gen is very very slow, and our precleaning | |
4411 // is running a losing race against a horde of | |
4412 // mutators intent on flooding us with CMS updates | |
4413 // (dirty cards). | |
4414 // One, admittedly dumb, strategy is to give up | |
4415 // after a certain number of abortable precleaning loops | |
4416 // or after a certain maximum time. We want to make | |
4417 // this smarter in the next iteration. | |
4418 // XXX FIX ME!!! YSR | |
4419 size_t loops = 0, workdone = 0, cumworkdone = 0, waited = 0; | |
4420 while (!(should_abort_preclean() || | |
4421 ConcurrentMarkSweepThread::should_terminate())) { | |
4422 workdone = preclean_work(CMSPrecleanRefLists2, CMSPrecleanSurvivors2); | |
4423 cumworkdone += workdone; | |
4424 loops++; | |
4425 // Voluntarily terminate abortable preclean phase if we have | |
4426 // been at it for too long. | |
4427 if ((CMSMaxAbortablePrecleanLoops != 0) && | |
4428 loops >= CMSMaxAbortablePrecleanLoops) { | |
4429 if (PrintGCDetails) { | |
4430 gclog_or_tty->print(" CMS: abort preclean due to loops "); | |
4431 } | |
4432 break; | |
4433 } | |
4434 if (pa.wallclock_millis() > CMSMaxAbortablePrecleanTime) { | |
4435 if (PrintGCDetails) { | |
4436 gclog_or_tty->print(" CMS: abort preclean due to time "); | |
4437 } | |
4438 break; | |
4439 } | |
4440 // If we are doing little work each iteration, we should | |
4441 // take a short break. | |
4442 if (workdone < CMSAbortablePrecleanMinWorkPerIteration) { | |
4443 // Sleep for some time, waiting for work to accumulate | |
4444 stopTimer(); | |
4445 cmsThread()->wait_on_cms_lock(CMSAbortablePrecleanWaitMillis); | |
4446 startTimer(); | |
4447 waited++; | |
4448 } | |
4449 } | |
4450 if (PrintCMSStatistics > 0) { | |
4451 gclog_or_tty->print(" [%d iterations, %d waits, %d cards)] ", | |
4452 loops, waited, cumworkdone); | |
4453 } | |
4454 } | |
4455 CMSTokenSync x(true); // is cms thread | |
4456 if (_collectorState != Idling) { | |
4457 assert(_collectorState == AbortablePreclean, | |
4458 "Spontaneous state transition?"); | |
4459 _collectorState = FinalMarking; | |
4460 } // Else, a foreground collection completed this CMS cycle. | |
4461 return; | |
4462 } | |
4463 | |
4464 // Respond to an Eden sampling opportunity | |
4465 void CMSCollector::sample_eden() { | |
4466 // Make sure a young gc cannot sneak in between our | |
4467 // reading and recording of a sample. | |
4468 assert(Thread::current()->is_ConcurrentGC_thread(), | |
4469 "Only the cms thread may collect Eden samples"); | |
4470 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
4471 "Should collect samples while holding CMS token"); | |
4472 if (!_start_sampling) { | |
4473 return; | |
4474 } | |
4475 if (_eden_chunk_array) { | |
4476 if (_eden_chunk_index < _eden_chunk_capacity) { | |
4477 _eden_chunk_array[_eden_chunk_index] = *_top_addr; // take sample | |
4478 assert(_eden_chunk_array[_eden_chunk_index] <= *_end_addr, | |
4479 "Unexpected state of Eden"); | |
4480 // We'd like to check that what we just sampled is an oop-start address; | |
4481 // however, we cannot do that here since the object may not yet have been | |
4482 // initialized. So we'll instead do the check when we _use_ this sample | |
4483 // later. | |
4484 if (_eden_chunk_index == 0 || | |
4485 (pointer_delta(_eden_chunk_array[_eden_chunk_index], | |
4486 _eden_chunk_array[_eden_chunk_index-1]) | |
4487 >= CMSSamplingGrain)) { | |
4488 _eden_chunk_index++; // commit sample | |
4489 } | |
4490 } | |
4491 } | |
4492 if ((_collectorState == AbortablePreclean) && !_abort_preclean) { | |
4493 size_t used = get_eden_used(); | |
4494 size_t capacity = get_eden_capacity(); | |
4495 assert(used <= capacity, "Unexpected state of Eden"); | |
4496 if (used > (capacity/100 * CMSScheduleRemarkEdenPenetration)) { | |
4497 _abort_preclean = true; | |
4498 } | |
4499 } | |
4500 } | |
4501 | |
4502 | |
4503 size_t CMSCollector::preclean_work(bool clean_refs, bool clean_survivor) { | |
4504 assert(_collectorState == Precleaning || | |
4505 _collectorState == AbortablePreclean, "incorrect state"); | |
4506 ResourceMark rm; | |
4507 HandleMark hm; | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4508 |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4509 // Precleaning is currently not MT but the reference processor |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4510 // may be set for MT. Disable it temporarily here. |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4511 ReferenceProcessor* rp = ref_processor(); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4512 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(rp, false); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4513 |
0 | 4514 // Do one pass of scrubbing the discovered reference lists |
4515 // to remove any reference objects with strongly-reachable | |
4516 // referents. | |
4517 if (clean_refs) { | |
4518 CMSPrecleanRefsYieldClosure yield_cl(this); | |
4519 assert(rp->span().equals(_span), "Spans should be equal"); | |
4520 CMSKeepAliveClosure keep_alive(this, _span, &_markBitMap, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4521 &_markStack, true /* preclean */); |
0 | 4522 CMSDrainMarkingStackClosure complete_trace(this, |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
4523 _span, &_markBitMap, &_markStack, |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
4524 &keep_alive, true /* preclean */); |
0 | 4525 |
4526 // We don't want this step to interfere with a young | |
4527 // collection because we don't want to take CPU | |
4528 // or memory bandwidth away from the young GC threads | |
4529 // (which may be as many as there are CPUs). | |
4530 // Note that we don't need to protect ourselves from | |
4531 // interference with mutators because they can't | |
4532 // manipulate the discovered reference lists nor affect | |
4533 // the computed reachability of the referents, the | |
4534 // only properties manipulated by the precleaning | |
4535 // of these reference lists. | |
4536 stopTimer(); | |
4537 CMSTokenSyncWithLocks x(true /* is cms thread */, | |
4538 bitMapLock()); | |
4539 startTimer(); | |
4540 sample_eden(); | |
935 | 4541 |
0 | 4542 // The following will yield to allow foreground |
4543 // collection to proceed promptly. XXX YSR: | |
4544 // The code in this method may need further | |
4545 // tweaking for better performance and some restructuring | |
4546 // for cleaner interfaces. | |
4547 rp->preclean_discovered_references( | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4548 rp->is_alive_non_header(), &keep_alive, &complete_trace, &yield_cl); |
0 | 4549 } |
4550 | |
4551 if (clean_survivor) { // preclean the active survivor space(s) | |
4552 assert(_young_gen->kind() == Generation::DefNew || | |
4553 _young_gen->kind() == Generation::ParNew || | |
4554 _young_gen->kind() == Generation::ASParNew, | |
4555 "incorrect type for cast"); | |
4556 DefNewGeneration* dng = (DefNewGeneration*)_young_gen; | |
4557 PushAndMarkClosure pam_cl(this, _span, ref_processor(), | |
4558 &_markBitMap, &_modUnionTable, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4559 &_markStack, true /* precleaning phase */); |
0 | 4560 stopTimer(); |
4561 CMSTokenSyncWithLocks ts(true /* is cms thread */, | |
4562 bitMapLock()); | |
4563 startTimer(); | |
4564 unsigned int before_count = | |
4565 GenCollectedHeap::heap()->total_collections(); | |
4566 SurvivorSpacePrecleanClosure | |
4567 sss_cl(this, _span, &_markBitMap, &_markStack, | |
4568 &pam_cl, before_count, CMSYield); | |
4569 dng->from()->object_iterate_careful(&sss_cl); | |
4570 dng->to()->object_iterate_careful(&sss_cl); | |
4571 } | |
4572 MarkRefsIntoAndScanClosure | |
4573 mrias_cl(_span, ref_processor(), &_markBitMap, &_modUnionTable, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4574 &_markStack, this, CMSYield, |
0 | 4575 true /* precleaning phase */); |
4576 // CAUTION: The following closure has persistent state that may need to | |
4577 // be reset upon a decrease in the sequence of addresses it | |
4578 // processes. | |
4579 ScanMarkedObjectsAgainCarefullyClosure | |
4580 smoac_cl(this, _span, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4581 &_markBitMap, &_markStack, &mrias_cl, CMSYield); |
0 | 4582 |
4583 // Preclean dirty cards in ModUnionTable and CardTable using | |
4584 // appropriate convergence criterion; | |
4585 // repeat CMSPrecleanIter times unless we find that | |
4586 // we are losing. | |
4587 assert(CMSPrecleanIter < 10, "CMSPrecleanIter is too large"); | |
4588 assert(CMSPrecleanNumerator < CMSPrecleanDenominator, | |
4589 "Bad convergence multiplier"); | |
4590 assert(CMSPrecleanThreshold >= 100, | |
4591 "Unreasonably low CMSPrecleanThreshold"); | |
4592 | |
4593 size_t numIter, cumNumCards, lastNumCards, curNumCards; | |
4594 for (numIter = 0, cumNumCards = lastNumCards = curNumCards = 0; | |
4595 numIter < CMSPrecleanIter; | |
4596 numIter++, lastNumCards = curNumCards, cumNumCards += curNumCards) { | |
4597 curNumCards = preclean_mod_union_table(_cmsGen, &smoac_cl); | |
4598 if (Verbose && PrintGCDetails) { | |
4599 gclog_or_tty->print(" (modUnionTable: %d cards)", curNumCards); | |
4600 } | |
4601 // Either there are very few dirty cards, so re-mark | |
4602 // pause will be small anyway, or our pre-cleaning isn't | |
4603 // that much faster than the rate at which cards are being | |
4604 // dirtied, so we might as well stop and re-mark since | |
4605 // precleaning won't improve our re-mark time by much. | |
4606 if (curNumCards <= CMSPrecleanThreshold || | |
4607 (numIter > 0 && | |
4608 (curNumCards * CMSPrecleanDenominator > | |
4609 lastNumCards * CMSPrecleanNumerator))) { | |
4610 numIter++; | |
4611 cumNumCards += curNumCards; | |
4612 break; | |
4613 } | |
4614 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4615 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4616 preclean_klasses(&mrias_cl, _cmsGen->freelistLock()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4617 |
0 | 4618 curNumCards = preclean_card_table(_cmsGen, &smoac_cl); |
4619 cumNumCards += curNumCards; | |
4620 if (PrintGCDetails && PrintCMSStatistics != 0) { | |
4621 gclog_or_tty->print_cr(" (cardTable: %d cards, re-scanned %d cards, %d iterations)", | |
4622 curNumCards, cumNumCards, numIter); | |
4623 } | |
4624 return cumNumCards; // as a measure of useful work done | |
4625 } | |
4626 | |
4627 // PRECLEANING NOTES: | |
4628 // Precleaning involves: | |
4629 // . reading the bits of the modUnionTable and clearing the set bits. | |
4630 // . For the cards corresponding to the set bits, we scan the | |
4631 // objects on those cards. This means we need the free_list_lock | |
4632 // so that we can safely iterate over the CMS space when scanning | |
4633 // for oops. | |
4634 // . When we scan the objects, we'll be both reading and setting | |
4635 // marks in the marking bit map, so we'll need the marking bit map. | |
4636 // . For protecting _collector_state transitions, we take the CGC_lock. | |
4637 // Note that any races in the reading of of card table entries by the | |
4638 // CMS thread on the one hand and the clearing of those entries by the | |
4639 // VM thread or the setting of those entries by the mutator threads on the | |
4640 // other are quite benign. However, for efficiency it makes sense to keep | |
4641 // the VM thread from racing with the CMS thread while the latter is | |
4642 // dirty card info to the modUnionTable. We therefore also use the | |
4643 // CGC_lock to protect the reading of the card table and the mod union | |
4644 // table by the CM thread. | |
4645 // . We run concurrently with mutator updates, so scanning | |
4646 // needs to be done carefully -- we should not try to scan | |
4647 // potentially uninitialized objects. | |
4648 // | |
4649 // Locking strategy: While holding the CGC_lock, we scan over and | |
4650 // reset a maximal dirty range of the mod union / card tables, then lock | |
4651 // the free_list_lock and bitmap lock to do a full marking, then | |
4652 // release these locks; and repeat the cycle. This allows for a | |
4653 // certain amount of fairness in the sharing of these locks between | |
4654 // the CMS collector on the one hand, and the VM thread and the | |
4655 // mutators on the other. | |
4656 | |
4657 // NOTE: preclean_mod_union_table() and preclean_card_table() | |
4658 // further below are largely identical; if you need to modify | |
4659 // one of these methods, please check the other method too. | |
4660 | |
4661 size_t CMSCollector::preclean_mod_union_table( | |
4662 ConcurrentMarkSweepGeneration* gen, | |
4663 ScanMarkedObjectsAgainCarefullyClosure* cl) { | |
4664 verify_work_stacks_empty(); | |
4665 verify_overflow_empty(); | |
4666 | |
4667 // strategy: starting with the first card, accumulate contiguous | |
4668 // ranges of dirty cards; clear these cards, then scan the region | |
4669 // covered by these cards. | |
4670 | |
4671 // Since all of the MUT is committed ahead, we can just use | |
4672 // that, in case the generations expand while we are precleaning. | |
4673 // It might also be fine to just use the committed part of the | |
4674 // generation, but we might potentially miss cards when the | |
4675 // generation is rapidly expanding while we are in the midst | |
4676 // of precleaning. | |
4677 HeapWord* startAddr = gen->reserved().start(); | |
4678 HeapWord* endAddr = gen->reserved().end(); | |
4679 | |
4680 cl->setFreelistLock(gen->freelistLock()); // needed for yielding | |
4681 | |
4682 size_t numDirtyCards, cumNumDirtyCards; | |
4683 HeapWord *nextAddr, *lastAddr; | |
4684 for (cumNumDirtyCards = numDirtyCards = 0, | |
4685 nextAddr = lastAddr = startAddr; | |
4686 nextAddr < endAddr; | |
4687 nextAddr = lastAddr, cumNumDirtyCards += numDirtyCards) { | |
4688 | |
4689 ResourceMark rm; | |
4690 HandleMark hm; | |
4691 | |
4692 MemRegion dirtyRegion; | |
4693 { | |
4694 stopTimer(); | |
935 | 4695 // Potential yield point |
0 | 4696 CMSTokenSync ts(true); |
4697 startTimer(); | |
4698 sample_eden(); | |
4699 // Get dirty region starting at nextOffset (inclusive), | |
4700 // simultaneously clearing it. | |
4701 dirtyRegion = | |
4702 _modUnionTable.getAndClearMarkedRegion(nextAddr, endAddr); | |
4703 assert(dirtyRegion.start() >= nextAddr, | |
4704 "returned region inconsistent?"); | |
4705 } | |
4706 // Remember where the next search should begin. | |
4707 // The returned region (if non-empty) is a right open interval, | |
4708 // so lastOffset is obtained from the right end of that | |
4709 // interval. | |
4710 lastAddr = dirtyRegion.end(); | |
4711 // Should do something more transparent and less hacky XXX | |
4712 numDirtyCards = | |
4713 _modUnionTable.heapWordDiffToOffsetDiff(dirtyRegion.word_size()); | |
4714 | |
4715 // We'll scan the cards in the dirty region (with periodic | |
4716 // yields for foreground GC as needed). | |
4717 if (!dirtyRegion.is_empty()) { | |
4718 assert(numDirtyCards > 0, "consistency check"); | |
4719 HeapWord* stop_point = NULL; | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4720 stopTimer(); |
935 | 4721 // Potential yield point |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4722 CMSTokenSyncWithLocks ts(true, gen->freelistLock(), |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4723 bitMapLock()); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4724 startTimer(); |
0 | 4725 { |
4726 verify_work_stacks_empty(); | |
4727 verify_overflow_empty(); | |
4728 sample_eden(); | |
4729 stop_point = | |
4730 gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); | |
4731 } | |
4732 if (stop_point != NULL) { | |
4733 // The careful iteration stopped early either because it found an | |
4734 // uninitialized object, or because we were in the midst of an | |
4735 // "abortable preclean", which should now be aborted. Redirty | |
4736 // the bits corresponding to the partially-scanned or unscanned | |
4737 // cards. We'll either restart at the next block boundary or | |
4738 // abort the preclean. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4739 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4740 "Should only be AbortablePreclean."); |
0 | 4741 _modUnionTable.mark_range(MemRegion(stop_point, dirtyRegion.end())); |
4742 if (should_abort_preclean()) { | |
4743 break; // out of preclean loop | |
4744 } else { | |
4745 // Compute the next address at which preclean should pick up; | |
4746 // might need bitMapLock in order to read P-bits. | |
4747 lastAddr = next_card_start_after_block(stop_point); | |
4748 } | |
4749 } | |
4750 } else { | |
4751 assert(lastAddr == endAddr, "consistency check"); | |
4752 assert(numDirtyCards == 0, "consistency check"); | |
4753 break; | |
4754 } | |
4755 } | |
4756 verify_work_stacks_empty(); | |
4757 verify_overflow_empty(); | |
4758 return cumNumDirtyCards; | |
4759 } | |
4760 | |
4761 // NOTE: preclean_mod_union_table() above and preclean_card_table() | |
4762 // below are largely identical; if you need to modify | |
4763 // one of these methods, please check the other method too. | |
4764 | |
4765 size_t CMSCollector::preclean_card_table(ConcurrentMarkSweepGeneration* gen, | |
4766 ScanMarkedObjectsAgainCarefullyClosure* cl) { | |
4767 // strategy: it's similar to precleamModUnionTable above, in that | |
4768 // we accumulate contiguous ranges of dirty cards, mark these cards | |
4769 // precleaned, then scan the region covered by these cards. | |
4770 HeapWord* endAddr = (HeapWord*)(gen->_virtual_space.high()); | |
4771 HeapWord* startAddr = (HeapWord*)(gen->_virtual_space.low()); | |
4772 | |
4773 cl->setFreelistLock(gen->freelistLock()); // needed for yielding | |
4774 | |
4775 size_t numDirtyCards, cumNumDirtyCards; | |
4776 HeapWord *lastAddr, *nextAddr; | |
4777 | |
4778 for (cumNumDirtyCards = numDirtyCards = 0, | |
4779 nextAddr = lastAddr = startAddr; | |
4780 nextAddr < endAddr; | |
4781 nextAddr = lastAddr, cumNumDirtyCards += numDirtyCards) { | |
4782 | |
4783 ResourceMark rm; | |
4784 HandleMark hm; | |
4785 | |
4786 MemRegion dirtyRegion; | |
4787 { | |
4788 // See comments in "Precleaning notes" above on why we | |
4789 // do this locking. XXX Could the locking overheads be | |
4790 // too high when dirty cards are sparse? [I don't think so.] | |
4791 stopTimer(); | |
4792 CMSTokenSync x(true); // is cms thread | |
4793 startTimer(); | |
4794 sample_eden(); | |
4795 // Get and clear dirty region from card table | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4796 dirtyRegion = _ct->ct_bs()->dirty_card_range_after_reset( |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4797 MemRegion(nextAddr, endAddr), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4798 true, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4799 CardTableModRefBS::precleaned_card_val()); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4800 |
0 | 4801 assert(dirtyRegion.start() >= nextAddr, |
4802 "returned region inconsistent?"); | |
4803 } | |
4804 lastAddr = dirtyRegion.end(); | |
4805 numDirtyCards = | |
4806 dirtyRegion.word_size()/CardTableModRefBS::card_size_in_words; | |
4807 | |
4808 if (!dirtyRegion.is_empty()) { | |
4809 stopTimer(); | |
4810 CMSTokenSyncWithLocks ts(true, gen->freelistLock(), bitMapLock()); | |
4811 startTimer(); | |
4812 sample_eden(); | |
4813 verify_work_stacks_empty(); | |
4814 verify_overflow_empty(); | |
4815 HeapWord* stop_point = | |
4816 gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); | |
4817 if (stop_point != NULL) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4818 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4819 "Should only be AbortablePreclean."); |
0 | 4820 _ct->ct_bs()->invalidate(MemRegion(stop_point, dirtyRegion.end())); |
4821 if (should_abort_preclean()) { | |
4822 break; // out of preclean loop | |
4823 } else { | |
4824 // Compute the next address at which preclean should pick up. | |
4825 lastAddr = next_card_start_after_block(stop_point); | |
4826 } | |
4827 } | |
4828 } else { | |
4829 break; | |
4830 } | |
4831 } | |
4832 verify_work_stacks_empty(); | |
4833 verify_overflow_empty(); | |
4834 return cumNumDirtyCards; | |
4835 } | |
4836 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4837 class PrecleanKlassClosure : public KlassClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4838 CMKlassClosure _cm_klass_closure; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4839 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4840 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
|
4841 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4842 if (k->has_accumulated_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4843 k->clear_accumulated_modified_oops(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4844 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4845 _cm_klass_closure.do_klass(k); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4846 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4847 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4848 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4849 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4850 // 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
|
4851 void CMSCollector::preclean_klasses(MarkRefsIntoAndScanClosure* cl, Mutex* freelistLock) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4852 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4853 cl->set_freelistLock(freelistLock); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4854 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4855 CMSTokenSyncWithLocks ts(true, freelistLock, bitMapLock()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4856 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4857 // 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
|
4858 // 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
|
4859 PrecleanKlassClosure preclean_klass_closure(cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4860 ClassLoaderDataGraph::classes_do(&preclean_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4861 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4862 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4863 verify_overflow_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4864 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4865 |
0 | 4866 void CMSCollector::checkpointRootsFinal(bool asynch, |
4867 bool clear_all_soft_refs, bool init_mark_was_synchronous) { | |
4868 assert(_collectorState == FinalMarking, "incorrect state transition?"); | |
4869 check_correct_thread_executing(); | |
4870 // world is stopped at this checkpoint | |
4871 assert(SafepointSynchronize::is_at_safepoint(), | |
4872 "world should be stopped"); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
4873 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
4874 |
0 | 4875 verify_work_stacks_empty(); |
4876 verify_overflow_empty(); | |
4877 | |
4878 SpecializationStats::clear(); | |
4879 if (PrintGCDetails) { | |
4880 gclog_or_tty->print("[YG occupancy: "SIZE_FORMAT" K ("SIZE_FORMAT" K)]", | |
4881 _young_gen->used() / K, | |
4882 _young_gen->capacity() / K); | |
4883 } | |
4884 if (asynch) { | |
4885 if (CMSScavengeBeforeRemark) { | |
4886 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
4887 // Temporarily set flag to false, GCH->do_collection will | |
4888 // expect it to be false and set to true | |
4889 FlagSetting fl(gch->_is_gc_active, false); | |
4890 NOT_PRODUCT(TraceTime t("Scavenge-Before-Remark", | |
4891 PrintGCDetails && Verbose, true, gclog_or_tty);) | |
4892 int level = _cmsGen->level() - 1; | |
4893 if (level >= 0) { | |
4894 gch->do_collection(true, // full (i.e. force, see below) | |
4895 false, // !clear_all_soft_refs | |
4896 0, // size | |
4897 false, // is_tlab | |
4898 level // max_level | |
4899 ); | |
4900 } | |
4901 } | |
4902 FreelistLocker x(this); | |
4903 MutexLockerEx y(bitMapLock(), | |
4904 Mutex::_no_safepoint_check_flag); | |
4905 assert(!init_mark_was_synchronous, "but that's impossible!"); | |
4906 checkpointRootsFinalWork(asynch, clear_all_soft_refs, false); | |
4907 } else { | |
4908 // already have all the locks | |
4909 checkpointRootsFinalWork(asynch, clear_all_soft_refs, | |
4910 init_mark_was_synchronous); | |
4911 } | |
4912 verify_work_stacks_empty(); | |
4913 verify_overflow_empty(); | |
4914 SpecializationStats::print(); | |
4915 } | |
4916 | |
4917 void CMSCollector::checkpointRootsFinalWork(bool asynch, | |
4918 bool clear_all_soft_refs, bool init_mark_was_synchronous) { | |
4919 | |
4920 NOT_PRODUCT(TraceTime tr("checkpointRootsFinalWork", PrintGCDetails, false, gclog_or_tty);) | |
4921 | |
4922 assert(haveFreelistLocks(), "must have free list locks"); | |
4923 assert_lock_strong(bitMapLock()); | |
4924 | |
4925 if (UseAdaptiveSizePolicy) { | |
4926 size_policy()->checkpoint_roots_final_begin(); | |
4927 } | |
4928 | |
4929 ResourceMark rm; | |
4930 HandleMark hm; | |
4931 | |
4932 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
4933 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
4934 if (should_unload_classes()) { |
0 | 4935 CodeCache::gc_prologue(); |
4936 } | |
4937 assert(haveFreelistLocks(), "must have free list locks"); | |
4938 assert_lock_strong(bitMapLock()); | |
4939 | |
4940 if (!init_mark_was_synchronous) { | |
4941 // We might assume that we need not fill TLAB's when | |
4942 // CMSScavengeBeforeRemark is set, because we may have just done | |
4943 // a scavenge which would have filled all TLAB's -- and besides | |
4944 // Eden would be empty. This however may not always be the case -- | |
4945 // for instance although we asked for a scavenge, it may not have | |
4946 // happened because of a JNI critical section. We probably need | |
4947 // a policy for deciding whether we can in that case wait until | |
4948 // the critical section releases and then do the remark following | |
4949 // the scavenge, and skip it here. In the absence of that policy, | |
4950 // or of an indication of whether the scavenge did indeed occur, | |
4951 // we cannot rely on TLAB's having been filled and must do | |
4952 // so here just in case a scavenge did not happen. | |
4953 gch->ensure_parsability(false); // fill TLAB's, but no need to retire them | |
4954 // Update the saved marks which may affect the root scans. | |
4955 gch->save_marks(); | |
4956 | |
4957 { | |
4958 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
4959 | |
4960 // Note on the role of the mod union table: | |
4961 // Since the marker in "markFromRoots" marks concurrently with | |
4962 // mutators, it is possible for some reachable objects not to have been | |
4963 // scanned. For instance, an only reference to an object A was | |
4964 // placed in object B after the marker scanned B. Unless B is rescanned, | |
4965 // A would be collected. Such updates to references in marked objects | |
4966 // are detected via the mod union table which is the set of all cards | |
4967 // dirtied since the first checkpoint in this GC cycle and prior to | |
4968 // the most recent young generation GC, minus those cleaned up by the | |
4969 // concurrent precleaning. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4970 if (CMSParallelRemarkEnabled && CollectedHeap::use_parallel_gc_threads()) { |
0 | 4971 TraceTime t("Rescan (parallel) ", PrintGCDetails, false, gclog_or_tty); |
4972 do_remark_parallel(); | |
4973 } else { | |
4974 TraceTime t("Rescan (non-parallel) ", PrintGCDetails, false, | |
4975 gclog_or_tty); | |
4976 do_remark_non_parallel(); | |
4977 } | |
4978 } | |
4979 } else { | |
4980 assert(!asynch, "Can't have init_mark_was_synchronous in asynch mode"); | |
4981 // The initial mark was stop-world, so there's no rescanning to | |
4982 // do; go straight on to the next step below. | |
4983 } | |
4984 verify_work_stacks_empty(); | |
4985 verify_overflow_empty(); | |
4986 | |
4987 { | |
4988 NOT_PRODUCT(TraceTime ts("refProcessingWork", PrintGCDetails, false, gclog_or_tty);) | |
4989 refProcessingWork(asynch, clear_all_soft_refs); | |
4990 } | |
4991 verify_work_stacks_empty(); | |
4992 verify_overflow_empty(); | |
4993 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
4994 if (should_unload_classes()) { |
0 | 4995 CodeCache::gc_epilogue(); |
4996 } | |
2147
9afee0b9fc1d
7012505: BreakpointWithFullGC.sh fails with Internal Error (src/share/vm/oops/methodOop.cpp:220)
kamg
parents:
2137
diff
changeset
|
4997 JvmtiExport::gc_epilogue(); |
0 | 4998 |
4999 // If we encountered any (marking stack / work queue) overflow | |
5000 // events during the current CMS cycle, take appropriate | |
5001 // remedial measures, where possible, so as to try and avoid | |
5002 // recurrence of that condition. | |
5003 assert(_markStack.isEmpty(), "No grey objects"); | |
5004 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
|
5005 _ser_kac_ovflw + _ser_kac_preclean_ovflw; |
0 | 5006 if (ser_ovflw > 0) { |
5007 if (PrintCMSStatistics != 0) { | |
5008 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
|
5009 "(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
|
5010 ", kac_preclean="SIZE_FORMAT")", |
0 | 5011 _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
|
5012 _ser_kac_ovflw, _ser_kac_preclean_ovflw); |
0 | 5013 } |
5014 _markStack.expand(); | |
5015 _ser_pmc_remark_ovflw = 0; | |
5016 _ser_pmc_preclean_ovflw = 0; | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5017 _ser_kac_preclean_ovflw = 0; |
0 | 5018 _ser_kac_ovflw = 0; |
5019 } | |
5020 if (_par_pmc_remark_ovflw > 0 || _par_kac_ovflw > 0) { | |
5021 if (PrintCMSStatistics != 0) { | |
5022 gclog_or_tty->print_cr("Work queue overflow (benign) " | |
5023 "(pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT")", | |
5024 _par_pmc_remark_ovflw, _par_kac_ovflw); | |
5025 } | |
5026 _par_pmc_remark_ovflw = 0; | |
5027 _par_kac_ovflw = 0; | |
5028 } | |
5029 if (PrintCMSStatistics != 0) { | |
5030 if (_markStack._hit_limit > 0) { | |
5031 gclog_or_tty->print_cr(" (benign) Hit max stack size limit ("SIZE_FORMAT")", | |
5032 _markStack._hit_limit); | |
5033 } | |
5034 if (_markStack._failed_double > 0) { | |
5035 gclog_or_tty->print_cr(" (benign) Failed stack doubling ("SIZE_FORMAT")," | |
5036 " current capacity "SIZE_FORMAT, | |
5037 _markStack._failed_double, | |
5038 _markStack.capacity()); | |
5039 } | |
5040 } | |
5041 _markStack._hit_limit = 0; | |
5042 _markStack._failed_double = 0; | |
5043 | |
5044 if ((VerifyAfterGC || VerifyDuringGC) && | |
5045 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
5046 verify_after_remark(); | |
5047 } | |
5048 | |
5049 // Change under the freelistLocks. | |
5050 _collectorState = Sweeping; | |
5051 // Call isAllClear() under bitMapLock | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5052 assert(_modUnionTable.isAllClear(), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5053 "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
|
5054 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
|
5055 "Should be clear by end of the final marking"); |
0 | 5056 if (UseAdaptiveSizePolicy) { |
5057 size_policy()->checkpoint_roots_final_end(gch->gc_cause()); | |
5058 } | |
5059 } | |
5060 | |
5061 // Parallel remark task | |
5062 class CMSParRemarkTask: public AbstractGangTask { | |
5063 CMSCollector* _collector; | |
5064 int _n_workers; | |
5065 CompactibleFreeListSpace* _cms_space; | |
5066 | |
5067 // The per-thread work queues, available here for stealing. | |
5068 OopTaskQueueSet* _task_queues; | |
5069 ParallelTaskTerminator _term; | |
5070 | |
5071 public: | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5072 // 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
|
5073 // workers to be taken from the active workers in the work gang. |
0 | 5074 CMSParRemarkTask(CMSCollector* collector, |
5075 CompactibleFreeListSpace* cms_space, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5076 int n_workers, FlexibleWorkGang* workers, |
0 | 5077 OopTaskQueueSet* task_queues): |
5078 AbstractGangTask("Rescan roots and grey objects in parallel"), | |
5079 _collector(collector), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5080 _cms_space(cms_space), |
0 | 5081 _n_workers(n_workers), |
5082 _task_queues(task_queues), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5083 _term(n_workers, task_queues) { } |
0 | 5084 |
5085 OopTaskQueueSet* task_queues() { return _task_queues; } | |
5086 | |
5087 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
5088 | |
5089 ParallelTaskTerminator* terminator() { return &_term; } | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5090 int n_workers() { return _n_workers; } |
0 | 5091 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5092 void work(uint worker_id); |
0 | 5093 |
5094 private: | |
5095 // Work method in support of parallel rescan ... of young gen spaces | |
5096 void do_young_space_rescan(int i, Par_MarkRefsIntoAndScanClosure* cl, | |
5097 ContiguousSpace* space, | |
5098 HeapWord** chunk_array, size_t chunk_top); | |
5099 | |
5100 // ... of dirty cards in old space | |
5101 void do_dirty_card_rescan_tasks(CompactibleFreeListSpace* sp, int i, | |
5102 Par_MarkRefsIntoAndScanClosure* cl); | |
5103 | |
5104 // ... work stealing for the above | |
5105 void do_work_steal(int i, Par_MarkRefsIntoAndScanClosure* cl, int* seed); | |
5106 }; | |
5107 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5108 class RemarkKlassClosure : public KlassClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5109 CMKlassClosure _cm_klass_closure; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5110 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5111 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
|
5112 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5113 // 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
|
5114 if (k->has_accumulated_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5115 k->clear_accumulated_modified_oops(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5116 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5117 // 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
|
5118 // 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
|
5119 } else if (k->has_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5120 // 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
|
5121 } else { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5122 // No modified oops in the Klass. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5123 return; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5124 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5125 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5126 // 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
|
5127 _cm_klass_closure.do_klass(k); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5128 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5129 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5130 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5131 // work_queue(i) is passed to the closure |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5132 // Par_MarkRefsIntoAndScanClosure. The "i" parameter |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5133 // 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
|
5134 // do_work_steal() to select the i-th task_queue. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5135 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5136 void CMSParRemarkTask::work(uint worker_id) { |
0 | 5137 elapsedTimer _timer; |
5138 ResourceMark rm; | |
5139 HandleMark hm; | |
5140 | |
5141 // ---------- rescan from roots -------------- | |
5142 _timer.start(); | |
5143 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5144 Par_MarkRefsIntoAndScanClosure par_mrias_cl(_collector, | |
5145 _collector->_span, _collector->ref_processor(), | |
5146 &(_collector->_markBitMap), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5147 work_queue(worker_id)); |
0 | 5148 |
5149 // Rescan young gen roots first since these are likely | |
5150 // coarsely partitioned and may, on that account, constitute | |
5151 // the critical path; thus, it's best to start off that | |
5152 // work first. | |
5153 // ---------- young gen roots -------------- | |
5154 { | |
5155 DefNewGeneration* dng = _collector->_young_gen->as_DefNewGeneration(); | |
5156 EdenSpace* eden_space = dng->eden(); | |
5157 ContiguousSpace* from_space = dng->from(); | |
5158 ContiguousSpace* to_space = dng->to(); | |
5159 | |
5160 HeapWord** eca = _collector->_eden_chunk_array; | |
5161 size_t ect = _collector->_eden_chunk_index; | |
5162 HeapWord** sca = _collector->_survivor_chunk_array; | |
5163 size_t sct = _collector->_survivor_chunk_index; | |
5164 | |
5165 assert(ect <= _collector->_eden_chunk_capacity, "out of bounds"); | |
5166 assert(sct <= _collector->_survivor_chunk_capacity, "out of bounds"); | |
5167 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5168 do_young_space_rescan(worker_id, &par_mrias_cl, to_space, NULL, 0); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5169 do_young_space_rescan(worker_id, &par_mrias_cl, from_space, sca, sct); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5170 do_young_space_rescan(worker_id, &par_mrias_cl, eden_space, eca, ect); |
0 | 5171 |
5172 _timer.stop(); | |
5173 if (PrintCMSStatistics != 0) { | |
5174 gclog_or_tty->print_cr( | |
5175 "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
|
5176 worker_id, _timer.seconds()); |
0 | 5177 } |
5178 } | |
5179 | |
5180 // ---------- remaining roots -------------- | |
5181 _timer.reset(); | |
5182 _timer.start(); | |
5183 gch->gen_process_strong_roots(_collector->_cmsGen->level(), | |
5184 false, // yg was scanned above | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5185 false, // this is parallel code |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5186 false, // not scavenging |
0 | 5187 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5188 &par_mrias_cl, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5189 true, // walk all of code cache if (so & SO_CodeCache) |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5190 NULL, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5191 NULL); // The dirty klasses will be handled below |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5192 assert(_collector->should_unload_classes() |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5193 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_CodeCache), |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5194 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
0 | 5195 _timer.stop(); |
5196 if (PrintCMSStatistics != 0) { | |
5197 gclog_or_tty->print_cr( | |
5198 "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
|
5199 worker_id, _timer.seconds()); |
0 | 5200 } |
5201 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5202 // ---------- unhandled CLD scanning ---------- |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5203 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
|
5204 _timer.reset(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5205 _timer.start(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5206 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5207 // 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
|
5208 // introduced during concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5209 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5210 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5211 for (int i = 0; i < array->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5212 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
|
5213 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5214 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5215 // 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
|
5216 ClassLoaderDataGraph::remember_new_clds(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5217 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5218 _timer.stop(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5219 if (PrintCMSStatistics != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5220 gclog_or_tty->print_cr( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5221 "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
|
5222 worker_id, _timer.seconds()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5223 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5224 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5225 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5226 // ---------- dirty klass scanning ---------- |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5227 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
|
5228 _timer.reset(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5229 _timer.start(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5230 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5231 // 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
|
5232 RemarkKlassClosure remark_klass_closure(&par_mrias_cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5233 ClassLoaderDataGraph::classes_do(&remark_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5234 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5235 _timer.stop(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5236 if (PrintCMSStatistics != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5237 gclog_or_tty->print_cr( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5238 "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
|
5239 worker_id, _timer.seconds()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5240 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5241 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5242 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5243 // 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
|
5244 // 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
|
5245 // that are guaranteed to be kept alive. Either by the direct allocation |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5246 // code, or when the young collector processes the strong roots. Hence, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5247 // 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
|
5248 |
0 | 5249 // ---------- rescan dirty cards ------------ |
5250 _timer.reset(); | |
5251 _timer.start(); | |
5252 | |
5253 // 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
|
5254 // (cms_space) in turn. |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5255 // "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
|
5256 do_dirty_card_rescan_tasks(_cms_space, worker_id, &par_mrias_cl); |
0 | 5257 _timer.stop(); |
5258 if (PrintCMSStatistics != 0) { | |
5259 gclog_or_tty->print_cr( | |
5260 "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
|
5261 worker_id, _timer.seconds()); |
0 | 5262 } |
5263 | |
5264 // ---------- steal work from other threads ... | |
5265 // ---------- ... and drain overflow list. | |
5266 _timer.reset(); | |
5267 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5268 do_work_steal(worker_id, &par_mrias_cl, _collector->hash_seed(worker_id)); |
0 | 5269 _timer.stop(); |
5270 if (PrintCMSStatistics != 0) { | |
5271 gclog_or_tty->print_cr( | |
5272 "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
|
5273 worker_id, _timer.seconds()); |
0 | 5274 } |
5275 } | |
5276 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5277 // Note that parameter "i" is not used. |
0 | 5278 void |
5279 CMSParRemarkTask::do_young_space_rescan(int i, | |
5280 Par_MarkRefsIntoAndScanClosure* cl, ContiguousSpace* space, | |
5281 HeapWord** chunk_array, size_t chunk_top) { | |
5282 // Until all tasks completed: | |
5283 // . claim an unclaimed task | |
5284 // . compute region boundaries corresponding to task claimed | |
5285 // using chunk_array | |
5286 // . par_oop_iterate(cl) over that region | |
5287 | |
5288 ResourceMark rm; | |
5289 HandleMark hm; | |
5290 | |
5291 SequentialSubTasksDone* pst = space->par_seq_tasks(); | |
5292 assert(pst->valid(), "Uninitialized use?"); | |
5293 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5294 uint nth_task = 0; |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5295 uint n_tasks = pst->n_tasks(); |
0 | 5296 |
5297 HeapWord *start, *end; | |
5298 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
5299 // We claimed task # nth_task; compute its boundaries. | |
5300 if (chunk_top == 0) { // no samples were taken | |
5301 assert(nth_task == 0 && n_tasks == 1, "Can have only 1 EdenSpace task"); | |
5302 start = space->bottom(); | |
5303 end = space->top(); | |
5304 } else if (nth_task == 0) { | |
5305 start = space->bottom(); | |
5306 end = chunk_array[nth_task]; | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5307 } else if (nth_task < (uint)chunk_top) { |
0 | 5308 assert(nth_task >= 1, "Control point invariant"); |
5309 start = chunk_array[nth_task - 1]; | |
5310 end = chunk_array[nth_task]; | |
5311 } else { | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5312 assert(nth_task == (uint)chunk_top, "Control point invariant"); |
0 | 5313 start = chunk_array[chunk_top - 1]; |
5314 end = space->top(); | |
5315 } | |
5316 MemRegion mr(start, end); | |
5317 // Verify that mr is in space | |
5318 assert(mr.is_empty() || space->used_region().contains(mr), | |
5319 "Should be in space"); | |
5320 // Verify that "start" is an object boundary | |
5321 assert(mr.is_empty() || oop(mr.start())->is_oop(), | |
5322 "Should be an oop"); | |
5323 space->par_oop_iterate(mr, cl); | |
5324 } | |
5325 pst->all_tasks_completed(); | |
5326 } | |
5327 | |
5328 void | |
5329 CMSParRemarkTask::do_dirty_card_rescan_tasks( | |
5330 CompactibleFreeListSpace* sp, int i, | |
5331 Par_MarkRefsIntoAndScanClosure* cl) { | |
5332 // Until all tasks completed: | |
5333 // . claim an unclaimed task | |
5334 // . compute region boundaries corresponding to task claimed | |
5335 // . transfer dirty bits ct->mut for that region | |
5336 // . apply rescanclosure to dirty mut bits for that region | |
5337 | |
5338 ResourceMark rm; | |
5339 HandleMark hm; | |
5340 | |
5341 OopTaskQueue* work_q = work_queue(i); | |
5342 ModUnionClosure modUnionClosure(&(_collector->_modUnionTable)); | |
5343 // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! | |
5344 // CAUTION: This closure has state that persists across calls to | |
5345 // the work method dirty_range_iterate_clear() in that it has | |
5346 // imbedded in it a (subtype of) UpwardsObjectClosure. The | |
5347 // use of that state in the imbedded UpwardsObjectClosure instance | |
5348 // assumes that the cards are always iterated (even if in parallel | |
5349 // by several threads) in monotonically increasing order per each | |
5350 // thread. This is true of the implementation below which picks | |
5351 // card ranges (chunks) in monotonically increasing order globally | |
5352 // and, a-fortiori, in monotonically increasing order per thread | |
5353 // (the latter order being a subsequence of the former). | |
5354 // If the work code below is ever reorganized into a more chaotic | |
5355 // work-partitioning form than the current "sequential tasks" | |
5356 // paradigm, the use of that persistent state will have to be | |
5357 // revisited and modified appropriately. See also related | |
5358 // bug 4756801 work on which should examine this code to make | |
5359 // sure that the changes there do not run counter to the | |
5360 // assumptions made here and necessary for correctness and | |
5361 // efficiency. Note also that this code might yield inefficient | |
5362 // behaviour in the case of very large objects that span one or | |
5363 // more work chunks. Such objects would potentially be scanned | |
5364 // several times redundantly. Work on 4756801 should try and | |
5365 // address that performance anomaly if at all possible. XXX | |
5366 MemRegion full_span = _collector->_span; | |
5367 CMSBitMap* bm = &(_collector->_markBitMap); // shared | |
5368 MarkFromDirtyCardsClosure | |
5369 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
|
5370 sp, bm, work_q, cl); |
0 | 5371 |
5372 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); | |
5373 assert(pst->valid(), "Uninitialized use?"); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5374 uint nth_task = 0; |
0 | 5375 const int alignment = CardTableModRefBS::card_size * BitsPerWord; |
5376 MemRegion span = sp->used_region(); | |
5377 HeapWord* start_addr = span.start(); | |
5378 HeapWord* end_addr = (HeapWord*)round_to((intptr_t)span.end(), | |
5379 alignment); | |
5380 const size_t chunk_size = sp->rescan_task_size(); // in HeapWord units | |
5381 assert((HeapWord*)round_to((intptr_t)start_addr, alignment) == | |
5382 start_addr, "Check alignment"); | |
5383 assert((size_t)round_to((intptr_t)chunk_size, alignment) == | |
5384 chunk_size, "Check alignment"); | |
5385 | |
5386 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
5387 // Having claimed the nth_task, compute corresponding mem-region, | |
5388 // which is a-fortiori aligned correctly (i.e. at a MUT bopundary). | |
5389 // The alignment restriction ensures that we do not need any | |
5390 // synchronization with other gang-workers while setting or | |
5391 // clearing bits in thus chunk of the MUT. | |
5392 MemRegion this_span = MemRegion(start_addr + nth_task*chunk_size, | |
5393 start_addr + (nth_task+1)*chunk_size); | |
5394 // The last chunk's end might be way beyond end of the | |
5395 // used region. In that case pull back appropriately. | |
5396 if (this_span.end() > end_addr) { | |
5397 this_span.set_end(end_addr); | |
5398 assert(!this_span.is_empty(), "Program logic (calculation of n_tasks)"); | |
5399 } | |
5400 // Iterate over the dirty cards covering this chunk, marking them | |
5401 // precleaned, and setting the corresponding bits in the mod union | |
5402 // table. Since we have been careful to partition at Card and MUT-word | |
5403 // boundaries no synchronization is needed between parallel threads. | |
5404 _collector->_ct->ct_bs()->dirty_card_iterate(this_span, | |
5405 &modUnionClosure); | |
5406 | |
5407 // Having transferred these marks into the modUnionTable, | |
5408 // rescan the marked objects on the dirty cards in the modUnionTable. | |
5409 // Even if this is at a synchronous collection, the initial marking | |
5410 // may have been done during an asynchronous collection so there | |
5411 // may be dirty bits in the mod-union table. | |
5412 _collector->_modUnionTable.dirty_range_iterate_clear( | |
5413 this_span, &greyRescanClosure); | |
5414 _collector->_modUnionTable.verifyNoOneBitsInRange( | |
5415 this_span.start(), | |
5416 this_span.end()); | |
5417 } | |
5418 pst->all_tasks_completed(); // declare that i am done | |
5419 } | |
5420 | |
5421 // . see if we can share work_queues with ParNew? XXX | |
5422 void | |
5423 CMSParRemarkTask::do_work_steal(int i, Par_MarkRefsIntoAndScanClosure* cl, | |
5424 int* seed) { | |
5425 OopTaskQueue* work_q = work_queue(i); | |
5426 NOT_PRODUCT(int num_steals = 0;) | |
5427 oop obj_to_scan; | |
5428 CMSBitMap* bm = &(_collector->_markBitMap); | |
5429 | |
5430 while (true) { | |
5431 // Completely finish any left over work from (an) earlier round(s) | |
5432 cl->trim_queue(0); | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
5433 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
|
5434 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 5435 // 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
|
5436 // Passing ParallelGCThreads as the third parameter, no_of_gc_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5437 // 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
|
5438 // 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
|
5439 // pass ParallelGCThreads so this behavior is unchanged. |
0 | 5440 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
|
5441 work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5442 ParallelGCThreads)) { |
0 | 5443 // found something in global overflow list; |
5444 // not yet ready to go stealing work from others. | |
5445 // We'd like to assert(work_q->size() != 0, ...) | |
5446 // because we just took work from the overflow list, | |
5447 // but of course we can't since all of that could have | |
5448 // been already stolen from us. | |
5449 // "He giveth and He taketh away." | |
5450 continue; | |
5451 } | |
5452 // Verify that we have no work before we resort to stealing | |
5453 assert(work_q->size() == 0, "Have work, shouldn't steal"); | |
5454 // Try to steal from other queues that have work | |
5455 if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
5456 NOT_PRODUCT(num_steals++;) | |
5457 assert(obj_to_scan->is_oop(), "Oops, not an oop!"); | |
5458 assert(bm->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?"); | |
5459 // Do scanning work | |
5460 obj_to_scan->oop_iterate(cl); | |
5461 // Loop around, finish this work, and try to steal some more | |
5462 } else if (terminator()->offer_termination()) { | |
5463 break; // nirvana from the infinite cycle | |
5464 } | |
5465 } | |
5466 NOT_PRODUCT( | |
5467 if (PrintCMSStatistics != 0) { | |
5468 gclog_or_tty->print("\n\t(%d: stole %d oops)", i, num_steals); | |
5469 } | |
5470 ) | |
5471 assert(work_q->size() == 0 && _collector->overflow_list_is_empty(), | |
5472 "Else our work is not yet done"); | |
5473 } | |
5474 | |
5475 // Return a thread-local PLAB recording array, as appropriate. | |
5476 void* CMSCollector::get_data_recorder(int thr_num) { | |
5477 if (_survivor_plab_array != NULL && | |
5478 (CMSPLABRecordAlways || | |
5479 (_collectorState > Marking && _collectorState < FinalMarking))) { | |
5480 assert(thr_num < (int)ParallelGCThreads, "thr_num is out of bounds"); | |
5481 ChunkArray* ca = &_survivor_plab_array[thr_num]; | |
5482 ca->reset(); // clear it so that fresh data is recorded | |
5483 return (void*) ca; | |
5484 } else { | |
5485 return NULL; | |
5486 } | |
5487 } | |
5488 | |
5489 // Reset all the thread-local PLAB recording arrays | |
5490 void CMSCollector::reset_survivor_plab_arrays() { | |
5491 for (uint i = 0; i < ParallelGCThreads; i++) { | |
5492 _survivor_plab_array[i].reset(); | |
5493 } | |
5494 } | |
5495 | |
5496 // Merge the per-thread plab arrays into the global survivor chunk | |
5497 // array which will provide the partitioning of the survivor space | |
5498 // for CMS rescan. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5499 void CMSCollector::merge_survivor_plab_arrays(ContiguousSpace* surv, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5500 int no_of_gc_threads) { |
0 | 5501 assert(_survivor_plab_array != NULL, "Error"); |
5502 assert(_survivor_chunk_array != NULL, "Error"); | |
5503 assert(_collectorState == FinalMarking, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5504 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5505 _cursor[j] = 0; |
5506 } | |
5507 HeapWord* top = surv->top(); | |
5508 size_t i; | |
5509 for (i = 0; i < _survivor_chunk_capacity; i++) { // all sca entries | |
5510 HeapWord* min_val = top; // Higher than any PLAB address | |
5511 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
|
5512 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5513 ChunkArray* cur_sca = &_survivor_plab_array[j]; |
5514 if (_cursor[j] == cur_sca->end()) { | |
5515 continue; | |
5516 } | |
5517 assert(_cursor[j] < cur_sca->end(), "ctl pt invariant"); | |
5518 HeapWord* cur_val = cur_sca->nth(_cursor[j]); | |
5519 assert(surv->used_region().contains(cur_val), "Out of bounds value"); | |
5520 if (cur_val < min_val) { | |
5521 min_tid = j; | |
5522 min_val = cur_val; | |
5523 } else { | |
5524 assert(cur_val < top, "All recorded addresses should be less"); | |
5525 } | |
5526 } | |
5527 // At this point min_val and min_tid are respectively | |
5528 // the least address in _survivor_plab_array[j]->nth(_cursor[j]) | |
5529 // and the thread (j) that witnesses that address. | |
5530 // We record this address in the _survivor_chunk_array[i] | |
5531 // and increment _cursor[min_tid] prior to the next round i. | |
5532 if (min_val == top) { | |
5533 break; | |
5534 } | |
5535 _survivor_chunk_array[i] = min_val; | |
5536 _cursor[min_tid]++; | |
5537 } | |
5538 // We are all done; record the size of the _survivor_chunk_array | |
5539 _survivor_chunk_index = i; // exclusive: [0, i) | |
5540 if (PrintCMSStatistics > 0) { | |
5541 gclog_or_tty->print(" (Survivor:" SIZE_FORMAT "chunks) ", i); | |
5542 } | |
5543 // Verify that we used up all the recorded entries | |
5544 #ifdef ASSERT | |
5545 size_t total = 0; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5546 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5547 assert(_cursor[j] == _survivor_plab_array[j].end(), "Ctl pt invariant"); |
5548 total += _cursor[j]; | |
5549 } | |
5550 assert(total == _survivor_chunk_index, "Ctl Pt Invariant"); | |
5551 // Check that the merged array is in sorted order | |
5552 if (total > 0) { | |
5553 for (size_t i = 0; i < total - 1; i++) { | |
5554 if (PrintCMSStatistics > 0) { | |
5555 gclog_or_tty->print(" (chunk" SIZE_FORMAT ":" INTPTR_FORMAT ") ", | |
5556 i, _survivor_chunk_array[i]); | |
5557 } | |
5558 assert(_survivor_chunk_array[i] < _survivor_chunk_array[i+1], | |
5559 "Not sorted"); | |
5560 } | |
5561 } | |
5562 #endif // ASSERT | |
5563 } | |
5564 | |
5565 // Set up the space's par_seq_tasks structure for work claiming | |
5566 // for parallel rescan of young gen. | |
5567 // See ParRescanTask where this is currently used. | |
5568 void | |
5569 CMSCollector:: | |
5570 initialize_sequential_subtasks_for_young_gen_rescan(int n_threads) { | |
5571 assert(n_threads > 0, "Unexpected n_threads argument"); | |
5572 DefNewGeneration* dng = (DefNewGeneration*)_young_gen; | |
5573 | |
5574 // Eden space | |
5575 { | |
5576 SequentialSubTasksDone* pst = dng->eden()->par_seq_tasks(); | |
5577 assert(!pst->valid(), "Clobbering existing data?"); | |
5578 // Each valid entry in [0, _eden_chunk_index) represents a task. | |
5579 size_t n_tasks = _eden_chunk_index + 1; | |
5580 assert(n_tasks == 1 || _eden_chunk_array != NULL, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5581 // 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
|
5582 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5583 pst->set_n_threads(n_threads); |
0 | 5584 pst->set_n_tasks((int)n_tasks); |
5585 } | |
5586 | |
5587 // Merge the survivor plab arrays into _survivor_chunk_array | |
5588 if (_survivor_plab_array != NULL) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5589 merge_survivor_plab_arrays(dng->from(), n_threads); |
0 | 5590 } else { |
5591 assert(_survivor_chunk_index == 0, "Error"); | |
5592 } | |
5593 | |
5594 // To space | |
5595 { | |
5596 SequentialSubTasksDone* pst = dng->to()->par_seq_tasks(); | |
5597 assert(!pst->valid(), "Clobbering existing data?"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5598 // 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
|
5599 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5600 pst->set_n_threads(n_threads); |
0 | 5601 pst->set_n_tasks(1); |
5602 assert(pst->valid(), "Error"); | |
5603 } | |
5604 | |
5605 // From space | |
5606 { | |
5607 SequentialSubTasksDone* pst = dng->from()->par_seq_tasks(); | |
5608 assert(!pst->valid(), "Clobbering existing data?"); | |
5609 size_t n_tasks = _survivor_chunk_index + 1; | |
5610 assert(n_tasks == 1 || _survivor_chunk_array != NULL, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5611 // 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
|
5612 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5613 pst->set_n_threads(n_threads); |
0 | 5614 pst->set_n_tasks((int)n_tasks); |
5615 assert(pst->valid(), "Error"); | |
5616 } | |
5617 } | |
5618 | |
5619 // Parallel version of remark | |
5620 void CMSCollector::do_remark_parallel() { | |
5621 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5622 FlexibleWorkGang* workers = gch->workers(); |
0 | 5623 assert(workers != NULL, "Need parallel worker threads."); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5624 // 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
|
5625 // 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
|
5626 // to ParallelGCThreads. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5627 int n_workers = workers->active_workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5628 if (n_workers == 0) { |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5629 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
|
5630 n_workers = ParallelGCThreads; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5631 workers->set_active_workers(n_workers); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5632 } |
0 | 5633 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); |
5634 | |
5635 CMSParRemarkTask tsk(this, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5636 cms_space, |
0 | 5637 n_workers, workers, task_queues()); |
5638 | |
5639 // Set up for parallel process_strong_roots work. | |
5640 gch->set_par_threads(n_workers); | |
5641 // We won't be iterating over the cards in the card table updating | |
5642 // the younger_gen cards, so we shouldn't call the following else | |
5643 // the verification code as well as subsequent younger_refs_iterate | |
5644 // code would get confused. XXX | |
5645 // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel | |
5646 | |
5647 // The young gen rescan work will not be done as part of | |
5648 // process_strong_roots (which currently doesn't knw how to | |
5649 // parallelize such a scan), but rather will be broken up into | |
5650 // a set of parallel tasks (via the sampling that the [abortable] | |
5651 // preclean phase did of EdenSpace, plus the [two] tasks of | |
5652 // scanning the [two] survivor spaces. Further fine-grain | |
5653 // parallelization of the scanning of the survivor spaces | |
5654 // themselves, and of precleaning of the younger gen itself | |
5655 // is deferred to the future. | |
5656 initialize_sequential_subtasks_for_young_gen_rescan(n_workers); | |
5657 | |
5658 // The dirty card rescan work is broken up into a "sequence" | |
5659 // of parallel tasks (per constituent space) that are dynamically | |
5660 // claimed by the parallel threads. | |
5661 cms_space->initialize_sequential_subtasks_for_rescan(n_workers); | |
5662 | |
5663 // It turns out that even when we're using 1 thread, doing the work in a | |
5664 // separate thread causes wide variance in run times. We can't help this | |
5665 // in the multi-threaded case, but we special-case n=1 here to get | |
5666 // repeatable measurements of the 1-thread overhead of the parallel code. | |
5667 if (n_workers > 1) { | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5668 // 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
|
5669 // 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
|
5670 // ST marking. |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5671 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), true); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5672 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5673 workers->run_task(&tsk); |
5674 } else { | |
4876
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5675 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5676 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5677 tsk.work(0); |
5678 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5679 |
0 | 5680 gch->set_par_threads(0); // 0 ==> non-parallel. |
5681 // restore, single-threaded for now, any preserved marks | |
5682 // as a result of work_q overflow | |
5683 restore_preserved_marks_if_any(); | |
5684 } | |
5685 | |
5686 // Non-parallel version of remark | |
5687 void CMSCollector::do_remark_non_parallel() { | |
5688 ResourceMark rm; | |
5689 HandleMark hm; | |
5690 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
4876
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5691 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); |
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5692 |
0 | 5693 MarkRefsIntoAndScanClosure |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5694 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
|
5695 &_markStack, this, |
0 | 5696 false /* should_yield */, false /* not precleaning */); |
5697 MarkFromDirtyCardsClosure | |
5698 markFromDirtyCardsClosure(this, _span, | |
5699 NULL, // space is set further below | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5700 &_markBitMap, &_markStack, &mrias_cl); |
0 | 5701 { |
5702 TraceTime t("grey object rescan", PrintGCDetails, false, gclog_or_tty); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
5703 // 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
|
5704 // mod union table. |
0 | 5705 { |
5706 ModUnionClosure modUnionClosure(&_modUnionTable); | |
5707 _ct->ct_bs()->dirty_card_iterate( | |
5708 _cmsGen->used_region(), | |
5709 &modUnionClosure); | |
5710 } | |
5711 // Having transferred these marks into the modUnionTable, we just need | |
5712 // to rescan the marked objects on the dirty cards in the modUnionTable. | |
5713 // The initial marking may have been done during an asynchronous | |
5714 // collection so there may be dirty bits in the mod-union table. | |
5715 const int alignment = | |
5716 CardTableModRefBS::card_size * BitsPerWord; | |
5717 { | |
5718 // ... First handle dirty cards in CMS gen | |
5719 markFromDirtyCardsClosure.set_space(_cmsGen->cmsSpace()); | |
5720 MemRegion ur = _cmsGen->used_region(); | |
5721 HeapWord* lb = ur.start(); | |
5722 HeapWord* ub = (HeapWord*)round_to((intptr_t)ur.end(), alignment); | |
5723 MemRegion cms_span(lb, ub); | |
5724 _modUnionTable.dirty_range_iterate_clear(cms_span, | |
5725 &markFromDirtyCardsClosure); | |
5726 verify_work_stacks_empty(); | |
5727 if (PrintCMSStatistics != 0) { | |
5728 gclog_or_tty->print(" (re-scanned "SIZE_FORMAT" dirty cards in cms gen) ", | |
5729 markFromDirtyCardsClosure.num_dirty_cards()); | |
5730 } | |
5731 } | |
5732 } | |
5733 if (VerifyDuringGC && | |
5734 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
5735 HandleMark hm; // Discard invalid handles created during verification | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
5736 Universe::verify(); |
0 | 5737 } |
5738 { | |
5739 TraceTime t("root rescan", PrintGCDetails, false, gclog_or_tty); | |
5740 | |
5741 verify_work_stacks_empty(); | |
5742 | |
5743 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
|
5744 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5745 gch->gen_process_strong_roots(_cmsGen->level(), |
5746 true, // younger gens as roots | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5747 false, // use the local StrongRootsScope |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5748 false, // not scavenging |
0 | 5749 SharedHeap::ScanningOption(roots_scanning_options()), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5750 &mrias_cl, |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5751 true, // walk code active on stacks |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5752 NULL, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5753 NULL); // The dirty klasses will be handled below |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5754 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5755 assert(should_unload_classes() |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5756 || (roots_scanning_options() & SharedHeap::SO_CodeCache), |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5757 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
0 | 5758 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5759 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5760 { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5761 TraceTime t("visit unhandled CLDs", PrintGCDetails, false, gclog_or_tty); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5762 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5763 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5764 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5765 // 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
|
5766 // during concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5767 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5768 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5769 for (int i = 0; i < array->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5770 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
|
5771 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5772 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5773 // 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
|
5774 ClassLoaderDataGraph::remember_new_clds(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5775 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5776 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5777 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5778 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5779 { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5780 TraceTime t("dirty klass scan", PrintGCDetails, false, gclog_or_tty); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5781 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5782 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5783 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5784 RemarkKlassClosure remark_klass_closure(&mrias_cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5785 ClassLoaderDataGraph::classes_do(&remark_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5786 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5787 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5788 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5789 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5790 // 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
|
5791 // 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
|
5792 // that are guaranteed to be kept alive. Either by the direct allocation |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5793 // code, or when the young collector processes the strong roots. Hence, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5794 // 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
|
5795 |
0 | 5796 verify_work_stacks_empty(); |
5797 // Restore evacuated mark words, if any, used for overflow list links | |
5798 if (!CMSOverflowEarlyRestoration) { | |
5799 restore_preserved_marks_if_any(); | |
5800 } | |
5801 verify_overflow_empty(); | |
5802 } | |
5803 | |
5804 //////////////////////////////////////////////////////// | |
5805 // Parallel Reference Processing Task Proxy Class | |
5806 //////////////////////////////////////////////////////// | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5807 class CMSRefProcTaskProxy: public AbstractGangTaskWOopQueues { |
0 | 5808 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; |
5809 CMSCollector* _collector; | |
5810 CMSBitMap* _mark_bit_map; | |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
5811 const MemRegion _span; |
0 | 5812 ProcessTask& _task; |
5813 | |
5814 public: | |
5815 CMSRefProcTaskProxy(ProcessTask& task, | |
5816 CMSCollector* collector, | |
5817 const MemRegion& span, | |
5818 CMSBitMap* mark_bit_map, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5819 AbstractWorkGang* workers, |
0 | 5820 OopTaskQueueSet* task_queues): |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5821 // 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
|
5822 // 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
|
5823 // the terminator() object. See 6984287. The set_for_termination() |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5824 // 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
|
5825 AbstractGangTaskWOopQueues("Process referents by policy in parallel", |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5826 task_queues), |
0 | 5827 _task(task), |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5828 _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
|
5829 { |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5830 assert(_collector->_span.equals(_span) && !_span.is_empty(), |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5831 "Inconsistency in _span"); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5832 set_for_termination(workers->active_workers()); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5833 } |
0 | 5834 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5835 OopTaskQueueSet* task_queues() { return queues(); } |
0 | 5836 |
5837 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
5838 | |
5839 void do_work_steal(int i, | |
5840 CMSParDrainMarkingStackClosure* drain, | |
5841 CMSParKeepAliveClosure* keep_alive, | |
5842 int* seed); | |
5843 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5844 virtual void work(uint worker_id); |
0 | 5845 }; |
5846 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5847 void CMSRefProcTaskProxy::work(uint worker_id) { |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
5848 assert(_collector->_span.equals(_span), "Inconsistency in _span"); |
0 | 5849 CMSParKeepAliveClosure par_keep_alive(_collector, _span, |
935 | 5850 _mark_bit_map, |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5851 work_queue(worker_id)); |
0 | 5852 CMSParDrainMarkingStackClosure par_drain_stack(_collector, _span, |
935 | 5853 _mark_bit_map, |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5854 work_queue(worker_id)); |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
5855 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
|
5856 _task.work(worker_id, is_alive_closure, par_keep_alive, par_drain_stack); |
0 | 5857 if (_task.marks_oops_alive()) { |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5858 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
|
5859 _collector->hash_seed(worker_id)); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5860 } |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5861 assert(work_queue(worker_id)->size() == 0, "work_queue should be empty"); |
0 | 5862 assert(_collector->_overflow_list == NULL, "non-empty _overflow_list"); |
5863 } | |
5864 | |
5865 class CMSRefEnqueueTaskProxy: public AbstractGangTask { | |
5866 typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask; | |
5867 EnqueueTask& _task; | |
5868 | |
5869 public: | |
5870 CMSRefEnqueueTaskProxy(EnqueueTask& task) | |
5871 : AbstractGangTask("Enqueue reference objects in parallel"), | |
5872 _task(task) | |
5873 { } | |
5874 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5875 virtual void work(uint worker_id) |
0 | 5876 { |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5877 _task.work(worker_id); |
0 | 5878 } |
5879 }; | |
5880 | |
5881 CMSParKeepAliveClosure::CMSParKeepAliveClosure(CMSCollector* collector, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5882 MemRegion span, CMSBitMap* bit_map, OopTaskQueue* work_queue): |
0 | 5883 _span(span), |
5884 _bit_map(bit_map), | |
5885 _work_queue(work_queue), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5886 _mark_and_push(collector, span, bit_map, work_queue), |
0 | 5887 _low_water_mark(MIN2((uint)(work_queue->max_elems()/4), |
5888 (uint)(CMSWorkQueueDrainThreshold * ParallelGCThreads))) | |
5889 { } | |
5890 | |
5891 // . see if we can share work_queues with ParNew? XXX | |
5892 void CMSRefProcTaskProxy::do_work_steal(int i, | |
5893 CMSParDrainMarkingStackClosure* drain, | |
5894 CMSParKeepAliveClosure* keep_alive, | |
5895 int* seed) { | |
5896 OopTaskQueue* work_q = work_queue(i); | |
5897 NOT_PRODUCT(int num_steals = 0;) | |
5898 oop obj_to_scan; | |
5899 | |
5900 while (true) { | |
5901 // Completely finish any left over work from (an) earlier round(s) | |
5902 drain->trim_queue(0); | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
5903 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
|
5904 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 5905 // 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
|
5906 // Passing ParallelGCThreads as the third parameter, no_of_gc_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5907 // 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
|
5908 // 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
|
5909 // pass ParallelGCThreads so this behavior is unchanged. |
0 | 5910 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
|
5911 work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5912 ParallelGCThreads)) { |
0 | 5913 // Found something in global overflow list; |
5914 // not yet ready to go stealing work from others. | |
5915 // We'd like to assert(work_q->size() != 0, ...) | |
5916 // because we just took work from the overflow list, | |
5917 // but of course we can't, since all of that might have | |
5918 // been already stolen from us. | |
5919 continue; | |
5920 } | |
5921 // Verify that we have no work before we resort to stealing | |
5922 assert(work_q->size() == 0, "Have work, shouldn't steal"); | |
5923 // Try to steal from other queues that have work | |
5924 if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
5925 NOT_PRODUCT(num_steals++;) | |
5926 assert(obj_to_scan->is_oop(), "Oops, not an oop!"); | |
5927 assert(_mark_bit_map->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?"); | |
5928 // Do scanning work | |
5929 obj_to_scan->oop_iterate(keep_alive); | |
5930 // Loop around, finish this work, and try to steal some more | |
5931 } else if (terminator()->offer_termination()) { | |
5932 break; // nirvana from the infinite cycle | |
5933 } | |
5934 } | |
5935 NOT_PRODUCT( | |
5936 if (PrintCMSStatistics != 0) { | |
5937 gclog_or_tty->print("\n\t(%d: stole %d oops)", i, num_steals); | |
5938 } | |
5939 ) | |
5940 } | |
5941 | |
5942 void CMSRefProcTaskExecutor::execute(ProcessTask& task) | |
5943 { | |
5944 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5945 FlexibleWorkGang* workers = gch->workers(); |
0 | 5946 assert(workers != NULL, "Need parallel worker threads."); |
5947 CMSRefProcTaskProxy rp_task(task, &_collector, | |
5948 _collector.ref_processor()->span(), | |
5949 _collector.markBitMap(), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5950 workers, _collector.task_queues()); |
0 | 5951 workers->run_task(&rp_task); |
5952 } | |
5953 | |
5954 void CMSRefProcTaskExecutor::execute(EnqueueTask& task) | |
5955 { | |
5956 | |
5957 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5958 FlexibleWorkGang* workers = gch->workers(); |
0 | 5959 assert(workers != NULL, "Need parallel worker threads."); |
5960 CMSRefEnqueueTaskProxy enq_task(task); | |
5961 workers->run_task(&enq_task); | |
5962 } | |
5963 | |
5964 void CMSCollector::refProcessingWork(bool asynch, bool clear_all_soft_refs) { | |
5965 | |
5966 ResourceMark rm; | |
5967 HandleMark hm; | |
5968 | |
5969 ReferenceProcessor* rp = ref_processor(); | |
5970 assert(rp->span().equals(_span), "Spans should be equal"); | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
5971 assert(!rp->enqueuing_is_done(), "Enqueuing should not be complete"); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
5972 // Process weak references. |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
5973 rp->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
5974 verify_work_stacks_empty(); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
5975 |
0 | 5976 CMSKeepAliveClosure cmsKeepAliveClosure(this, _span, &_markBitMap, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5977 &_markStack, false /* !preclean */); |
0 | 5978 CMSDrainMarkingStackClosure cmsDrainMarkingStackClosure(this, |
5979 _span, &_markBitMap, &_markStack, | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5980 &cmsKeepAliveClosure, false /* !preclean */); |
0 | 5981 { |
5982 TraceTime t("weak refs processing", PrintGCDetails, false, gclog_or_tty); | |
5983 if (rp->processing_is_mt()) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5984 // 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
|
5985 // 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
|
5986 // 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
|
5987 // 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
|
5988 // balance_all_queues() and balance_queues()). |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5989 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5990 int active_workers = ParallelGCThreads; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5991 FlexibleWorkGang* workers = gch->workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5992 if (workers != NULL) { |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5993 active_workers = workers->active_workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5994 // The expectation is that active_workers will have already |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5995 // 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
|
5996 // investigate. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5997 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
|
5998 } |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5999 rp->set_active_mt_degree(active_workers); |
0 | 6000 CMSRefProcTaskExecutor task_executor(*this); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6001 rp->process_discovered_references(&_is_alive_closure, |
0 | 6002 &cmsKeepAliveClosure, |
6003 &cmsDrainMarkingStackClosure, | |
6004 &task_executor); | |
6005 } else { | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6006 rp->process_discovered_references(&_is_alive_closure, |
0 | 6007 &cmsKeepAliveClosure, |
6008 &cmsDrainMarkingStackClosure, | |
6009 NULL); | |
6010 } | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6011 } |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6012 |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6013 // 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
|
6014 verify_work_stacks_empty(); |
0 | 6015 |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6016 if (should_unload_classes()) { |
0 | 6017 { |
6018 TraceTime t("class unloading", PrintGCDetails, false, gclog_or_tty); | |
6019 | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6020 // Unload classes and purge the SystemDictionary. |
0 | 6021 bool purged_class = SystemDictionary::do_unloading(&_is_alive_closure); |
6022 | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6023 // Unload nmethods. |
6787
8966c2d65d96
7200470: KeepAliveClosure not needed in CodeCache::do_unloading
brutisso
parents:
6755
diff
changeset
|
6024 CodeCache::do_unloading(&_is_alive_closure, purged_class); |
0 | 6025 |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6026 // 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
|
6027 Klass::clean_weak_klass_links(&_is_alive_closure); |
0 | 6028 } |
6029 | |
6030 { | |
2379
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2369
diff
changeset
|
6031 TraceTime t("scrub symbol table", PrintGCDetails, false, gclog_or_tty); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2147
diff
changeset
|
6032 // Clean up unreferenced symbols in symbol table. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2147
diff
changeset
|
6033 SymbolTable::unlink(); |
0 | 6034 } |
6035 } | |
6036 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6037 // CMS doesn't use the StringTable as hard roots when class unloading is turned off. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6038 // Need to check if we really scanned the StringTable. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6039 if ((roots_scanning_options() & SharedHeap::SO_Strings) == 0) { |
2379
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2369
diff
changeset
|
6040 TraceTime t("scrub string table", PrintGCDetails, false, gclog_or_tty); |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6041 // Delete entries for dead interned strings. |
2379
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2369
diff
changeset
|
6042 StringTable::unlink(&_is_alive_closure); |
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2369
diff
changeset
|
6043 } |
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2369
diff
changeset
|
6044 |
0 | 6045 // Restore any preserved marks as a result of mark stack or |
6046 // work queue overflow | |
6047 restore_preserved_marks_if_any(); // done single-threaded for now | |
6048 | |
6049 rp->set_enqueuing_is_done(true); | |
6050 if (rp->processing_is_mt()) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6051 rp->balance_all_queues(); |
0 | 6052 CMSRefProcTaskExecutor task_executor(*this); |
6053 rp->enqueue_discovered_references(&task_executor); | |
6054 } else { | |
6055 rp->enqueue_discovered_references(NULL); | |
6056 } | |
6057 rp->verify_no_references_recorded(); | |
6058 assert(!rp->discovery_enabled(), "should have been disabled"); | |
6059 } | |
6060 | |
6061 #ifndef PRODUCT | |
6062 void CMSCollector::check_correct_thread_executing() { | |
6063 Thread* t = Thread::current(); | |
6064 // Only the VM thread or the CMS thread should be here. | |
6065 assert(t->is_ConcurrentGC_thread() || t->is_VM_thread(), | |
6066 "Unexpected thread type"); | |
6067 // If this is the vm thread, the foreground process | |
6068 // should not be waiting. Note that _foregroundGCIsActive is | |
6069 // true while the foreground collector is waiting. | |
6070 if (_foregroundGCShouldWait) { | |
6071 // We cannot be the VM thread | |
6072 assert(t->is_ConcurrentGC_thread(), | |
6073 "Should be CMS thread"); | |
6074 } else { | |
6075 // We can be the CMS thread only if we are in a stop-world | |
6076 // phase of CMS collection. | |
6077 if (t->is_ConcurrentGC_thread()) { | |
6078 assert(_collectorState == InitialMarking || | |
6079 _collectorState == FinalMarking, | |
6080 "Should be a stop-world phase"); | |
6081 // The CMS thread should be holding the CMS_token. | |
6082 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6083 "Potential interference with concurrently " | |
6084 "executing VM thread"); | |
6085 } | |
6086 } | |
6087 } | |
6088 #endif | |
6089 | |
6090 void CMSCollector::sweep(bool asynch) { | |
6091 assert(_collectorState == Sweeping, "just checking"); | |
6092 check_correct_thread_executing(); | |
6093 verify_work_stacks_empty(); | |
6094 verify_overflow_empty(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6095 increment_sweep_count(); |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
6096 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
|
6097 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6098 _inter_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6099 _inter_sweep_estimate.sample(_inter_sweep_timer.seconds()); |
0 | 6100 size_policy()->avg_cms_free_at_sweep()->sample(_cmsGen->free()); |
6101 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6102 assert(!_intra_sweep_timer.is_active(), "Should not be active"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6103 _intra_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6104 _intra_sweep_timer.start(); |
0 | 6105 if (asynch) { |
6106 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
6107 CMSPhaseAccounting pa(this, "sweep", !PrintGCDetails); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6108 // First sweep the old gen |
0 | 6109 { |
6110 CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock(), | |
6111 bitMapLock()); | |
6112 sweepWork(_cmsGen, asynch); | |
6113 } | |
6114 | |
6115 // Update Universe::_heap_*_at_gc figures. | |
6116 // We need all the free list locks to make the abstract state | |
6117 // transition from Sweeping to Resetting. See detailed note | |
6118 // further below. | |
6119 { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6120 CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock()); |
0 | 6121 // Update heap occupancy information which is used as |
6122 // input to soft ref clearing policy at the next gc. | |
6123 Universe::update_heap_info_at_gc(); | |
6124 _collectorState = Resizing; | |
6125 } | |
6126 } else { | |
6127 // already have needed locks | |
6128 sweepWork(_cmsGen, asynch); | |
6129 // Update heap occupancy information which is used as | |
6130 // input to soft ref clearing policy at the next gc. | |
6131 Universe::update_heap_info_at_gc(); | |
6132 _collectorState = Resizing; | |
6133 } | |
6134 verify_work_stacks_empty(); | |
6135 verify_overflow_empty(); | |
6136 | |
8784
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6137 if (should_unload_classes()) { |
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6138 ClassLoaderDataGraph::purge(); |
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6139 } |
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6140 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6141 _intra_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6142 _intra_sweep_estimate.sample(_intra_sweep_timer.seconds()); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6143 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6144 _inter_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6145 _inter_sweep_timer.start(); |
0 | 6146 |
4911 | 6147 // We need to use a monotonically non-deccreasing time in ms |
6148 // or we will see time-warp warnings and os::javaTimeMillis() | |
6149 // does not guarantee monotonicity. | |
6150 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; | |
6151 update_time_of_last_gc(now); | |
0 | 6152 |
6153 // NOTE on abstract state transitions: | |
6154 // Mutators allocate-live and/or mark the mod-union table dirty | |
6155 // based on the state of the collection. The former is done in | |
6156 // the interval [Marking, Sweeping] and the latter in the interval | |
6157 // [Marking, Sweeping). Thus the transitions into the Marking state | |
6158 // and out of the Sweeping state must be synchronously visible | |
6159 // globally to the mutators. | |
6160 // The transition into the Marking state happens with the world | |
6161 // stopped so the mutators will globally see it. Sweeping is | |
6162 // done asynchronously by the background collector so the transition | |
6163 // from the Sweeping state to the Resizing state must be done | |
6164 // under the freelistLock (as is the check for whether to | |
6165 // allocate-live and whether to dirty the mod-union table). | |
6166 assert(_collectorState == Resizing, "Change of collector state to" | |
6167 " Resizing must be done under the freelistLocks (plural)"); | |
6168 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6169 // 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
|
6170 // the incremental_collection_failed flag, |
0 | 6171 // thus inviting a younger gen collection to promote into |
6172 // this generation. If such a promotion may still fail, | |
6173 // the flag will be set again when a young collection is | |
6174 // attempted. | |
6175 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6176 gch->clear_incremental_collection_failed(); // Worth retrying as fresh space may have been freed up |
0 | 6177 gch->update_full_collections_completed(_collection_count_start); |
6178 } | |
6179 | |
6180 // FIX ME!!! Looks like this belongs in CFLSpace, with | |
6181 // CMSGen merely delegating to it. | |
6182 void ConcurrentMarkSweepGeneration::setNearLargestChunk() { | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6183 double nearLargestPercent = FLSLargestBlockCoalesceProximity; |
0 | 6184 HeapWord* minAddr = _cmsSpace->bottom(); |
6185 HeapWord* largestAddr = | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
6186 (HeapWord*) _cmsSpace->dictionary()->find_largest_dict(); |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6187 if (largestAddr == NULL) { |
0 | 6188 // The dictionary appears to be empty. In this case |
6189 // try to coalesce at the end of the heap. | |
6190 largestAddr = _cmsSpace->end(); | |
6191 } | |
6192 size_t largestOffset = pointer_delta(largestAddr, minAddr); | |
6193 size_t nearLargestOffset = | |
6194 (size_t)((double)largestOffset * nearLargestPercent) - MinChunkSize; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6195 if (PrintFLSStatistics != 0) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6196 gclog_or_tty->print_cr( |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6197 "CMS: Large Block: " PTR_FORMAT ";" |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6198 " Proximity: " PTR_FORMAT " -> " PTR_FORMAT, |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6199 largestAddr, |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6200 _cmsSpace->nearLargestChunk(), minAddr + nearLargestOffset); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6201 } |
0 | 6202 _cmsSpace->set_nearLargestChunk(minAddr + nearLargestOffset); |
6203 } | |
6204 | |
6205 bool ConcurrentMarkSweepGeneration::isNearLargestChunk(HeapWord* addr) { | |
6206 return addr >= _cmsSpace->nearLargestChunk(); | |
6207 } | |
6208 | |
6209 FreeChunk* ConcurrentMarkSweepGeneration::find_chunk_at_end() { | |
6210 return _cmsSpace->find_chunk_at_end(); | |
6211 } | |
6212 | |
6213 void ConcurrentMarkSweepGeneration::update_gc_stats(int current_level, | |
6214 bool full) { | |
6215 // The next lower level has been collected. Gather any statistics | |
6216 // that are of interest at this point. | |
6217 if (!full && (current_level + 1) == level()) { | |
6218 // Gather statistics on the young generation collection. | |
6219 collector()->stats().record_gc0_end(used()); | |
6220 } | |
6221 } | |
6222 | |
6223 CMSAdaptiveSizePolicy* ConcurrentMarkSweepGeneration::size_policy() { | |
6224 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
6225 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
6226 "Wrong type of heap"); | |
6227 CMSAdaptiveSizePolicy* sp = (CMSAdaptiveSizePolicy*) | |
6228 gch->gen_policy()->size_policy(); | |
6229 assert(sp->is_gc_cms_adaptive_size_policy(), | |
6230 "Wrong type of size policy"); | |
6231 return sp; | |
6232 } | |
6233 | |
6234 void ConcurrentMarkSweepGeneration::rotate_debug_collection_type() { | |
6235 if (PrintGCDetails && Verbose) { | |
6236 gclog_or_tty->print("Rotate from %d ", _debug_collection_type); | |
6237 } | |
6238 _debug_collection_type = (CollectionTypes) (_debug_collection_type + 1); | |
6239 _debug_collection_type = | |
6240 (CollectionTypes) (_debug_collection_type % Unknown_collection_type); | |
6241 if (PrintGCDetails && Verbose) { | |
6242 gclog_or_tty->print_cr("to %d ", _debug_collection_type); | |
6243 } | |
6244 } | |
6245 | |
6246 void CMSCollector::sweepWork(ConcurrentMarkSweepGeneration* gen, | |
6247 bool asynch) { | |
6248 // We iterate over the space(s) underlying this generation, | |
6249 // checking the mark bit map to see if the bits corresponding | |
6250 // to specific blocks are marked or not. Blocks that are | |
6251 // marked are live and are not swept up. All remaining blocks | |
6252 // are swept up, with coalescing on-the-fly as we sweep up | |
6253 // contiguous free and/or garbage blocks: | |
6254 // We need to ensure that the sweeper synchronizes with allocators | |
6255 // and stop-the-world collectors. In particular, the following | |
6256 // locks are used: | |
6257 // . CMS token: if this is held, a stop the world collection cannot occur | |
6258 // . freelistLock: if this is held no allocation can occur from this | |
6259 // generation by another thread | |
6260 // . bitMapLock: if this is held, no other thread can access or update | |
6261 // | |
6262 | |
6263 // Note that we need to hold the freelistLock if we use | |
6264 // block iterate below; else the iterator might go awry if | |
6265 // a mutator (or promotion) causes block contents to change | |
6266 // (for instance if the allocator divvies up a block). | |
6267 // If we hold the free list lock, for all practical purposes | |
6268 // young generation GC's can't occur (they'll usually need to | |
6269 // promote), so we might as well prevent all young generation | |
6270 // GC's while we do a sweeping step. For the same reason, we might | |
6271 // as well take the bit map lock for the entire duration | |
6272 | |
6273 // check that we hold the requisite locks | |
6274 assert(have_cms_token(), "Should hold cms token"); | |
6275 assert( (asynch && ConcurrentMarkSweepThread::cms_thread_has_cms_token()) | |
6276 || (!asynch && ConcurrentMarkSweepThread::vm_thread_has_cms_token()), | |
6277 "Should possess CMS token to sweep"); | |
6278 assert_lock_strong(gen->freelistLock()); | |
6279 assert_lock_strong(bitMapLock()); | |
6280 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6281 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
|
6282 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
|
6283 gen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6284 _inter_sweep_estimate.padded_average(), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6285 _intra_sweep_estimate.padded_average()); |
0 | 6286 gen->setNearLargestChunk(); |
6287 | |
6288 { | |
6289 SweepClosure sweepClosure(this, gen, &_markBitMap, | |
6290 CMSYield && asynch); | |
6291 gen->cmsSpace()->blk_iterate_careful(&sweepClosure); | |
6292 // We need to free-up/coalesce garbage/blocks from a | |
6293 // co-terminal free run. This is done in the SweepClosure | |
6294 // destructor; so, do not remove this scope, else the | |
6295 // end-of-sweep-census below will be off by a little bit. | |
6296 } | |
6297 gen->cmsSpace()->sweep_completed(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6298 gen->cmsSpace()->endSweepFLCensus(sweep_count()); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6299 if (should_unload_classes()) { // unloaded classes this cycle, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6300 _concurrent_cycles_since_last_unload = 0; // ... reset count |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6301 } else { // did not unload classes, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6302 _concurrent_cycles_since_last_unload++; // ... increment count |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6303 } |
0 | 6304 } |
6305 | |
6306 // Reset CMS data structures (for now just the marking bit map) | |
6307 // preparatory for the next cycle. | |
6308 void CMSCollector::reset(bool asynch) { | |
6309 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
6310 CMSAdaptiveSizePolicy* sp = size_policy(); | |
6311 AdaptiveSizePolicyOutput(sp, gch->total_collections()); | |
6312 if (asynch) { | |
6313 CMSTokenSyncWithLocks ts(true, bitMapLock()); | |
6314 | |
6315 // If the state is not "Resetting", the foreground thread | |
6316 // has done a collection and the resetting. | |
6317 if (_collectorState != Resetting) { | |
6318 assert(_collectorState == Idling, "The state should only change" | |
6319 " because the foreground collector has finished the collection"); | |
6320 return; | |
6321 } | |
6322 | |
6323 // Clear the mark bitmap (no grey objects to start with) | |
6324 // for the next cycle. | |
6325 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
6326 CMSPhaseAccounting cmspa(this, "reset", !PrintGCDetails); | |
6327 | |
6328 HeapWord* curAddr = _markBitMap.startWord(); | |
6329 while (curAddr < _markBitMap.endWord()) { | |
6330 size_t remaining = pointer_delta(_markBitMap.endWord(), curAddr); | |
6331 MemRegion chunk(curAddr, MIN2(CMSBitMapYieldQuantum, remaining)); | |
6332 _markBitMap.clear_large_range(chunk); | |
6333 if (ConcurrentMarkSweepThread::should_yield() && | |
6334 !foregroundGCIsActive() && | |
6335 CMSYield) { | |
6336 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6337 "CMS thread should hold CMS token"); | |
6338 assert_lock_strong(bitMapLock()); | |
6339 bitMapLock()->unlock(); | |
6340 ConcurrentMarkSweepThread::desynchronize(true); | |
6341 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6342 stopTimer(); | |
6343 if (PrintCMSStatistics != 0) { | |
6344 incrementYields(); | |
6345 } | |
6346 icms_wait(); | |
6347 | |
6348 // See the comment in coordinator_yield() | |
6349 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
|
6350 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6351 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 6352 os::sleep(Thread::current(), 1, false); |
6353 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6354 } | |
6355 | |
6356 ConcurrentMarkSweepThread::synchronize(true); | |
6357 bitMapLock()->lock_without_safepoint_check(); | |
6358 startTimer(); | |
6359 } | |
6360 curAddr = chunk.end(); | |
6361 } | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6362 // 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
|
6363 // 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
|
6364 // 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
|
6365 // and count. |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6366 sp->reset_gc_overhead_limit_count(); |
0 | 6367 _collectorState = Idling; |
6368 } else { | |
6369 // already have the lock | |
6370 assert(_collectorState == Resetting, "just checking"); | |
6371 assert_lock_strong(bitMapLock()); | |
6372 _markBitMap.clear_all(); | |
6373 _collectorState = Idling; | |
6374 } | |
6375 | |
6376 // Stop incremental mode after a cycle completes, so that any future cycles | |
6377 // are triggered by allocation. | |
6378 stop_icms(); | |
6379 | |
6380 NOT_PRODUCT( | |
6381 if (RotateCMSCollectionTypes) { | |
6382 _cmsGen->rotate_debug_collection_type(); | |
6383 } | |
6384 ) | |
6385 } | |
6386 | |
6064
9d679effd28c
7166894: Add gc cause to GC logging for all collectors
brutisso
parents:
6028
diff
changeset
|
6387 void CMSCollector::do_CMS_operation(CMS_op_type op, GCCause::Cause gc_cause) { |
0 | 6388 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); |
6389 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
6064
9d679effd28c
7166894: Add gc cause to GC logging for all collectors
brutisso
parents:
6028
diff
changeset
|
6390 TraceTime t(GCCauseString("GC", gc_cause), PrintGC, !PrintGCDetails, gclog_or_tty); |
0 | 6391 TraceCollectorStats tcs(counters()); |
6392 | |
6393 switch (op) { | |
6394 case CMS_op_checkpointRootsInitial: { | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
6395 SvcGCMarker sgcm(SvcGCMarker::OTHER); |
0 | 6396 checkpointRootsInitial(true); // asynch |
6397 if (PrintGC) { | |
6398 _cmsGen->printOccupancy("initial-mark"); | |
6399 } | |
6400 break; | |
6401 } | |
6402 case CMS_op_checkpointRootsFinal: { | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
6403 SvcGCMarker sgcm(SvcGCMarker::OTHER); |
0 | 6404 checkpointRootsFinal(true, // asynch |
6405 false, // !clear_all_soft_refs | |
6406 false); // !init_mark_was_synchronous | |
6407 if (PrintGC) { | |
6408 _cmsGen->printOccupancy("remark"); | |
6409 } | |
6410 break; | |
6411 } | |
6412 default: | |
6413 fatal("No such CMS_op"); | |
6414 } | |
6415 } | |
6416 | |
6417 #ifndef PRODUCT | |
6418 size_t const CMSCollector::skip_header_HeapWords() { | |
6419 return FreeChunk::header_size(); | |
6420 } | |
6421 | |
6422 // Try and collect here conditions that should hold when | |
6423 // CMS thread is exiting. The idea is that the foreground GC | |
6424 // thread should not be blocked if it wants to terminate | |
6425 // the CMS thread and yet continue to run the VM for a while | |
6426 // after that. | |
6427 void CMSCollector::verify_ok_to_terminate() const { | |
6428 assert(Thread::current()->is_ConcurrentGC_thread(), | |
6429 "should be called by CMS thread"); | |
6430 assert(!_foregroundGCShouldWait, "should be false"); | |
6431 // We could check here that all the various low-level locks | |
6432 // are not held by the CMS thread, but that is overkill; see | |
6433 // also CMSThread::verify_ok_to_terminate() where the CGC_lock | |
6434 // is checked. | |
6435 } | |
6436 #endif | |
6437 | |
6438 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
|
6439 assert(_markBitMap.isMarked(addr) && _markBitMap.isMarked(addr + 1), |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6440 "missing Printezis mark?"); |
0 | 6441 HeapWord* nextOneAddr = _markBitMap.getNextMarkedWordAddress(addr + 2); |
6442 size_t size = pointer_delta(nextOneAddr + 1, addr); | |
6443 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6444 "alignment problem"); | |
6445 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6446 return size; | |
6447 } | |
6448 | |
6449 // A variant of the above (block_size_using_printezis_bits()) except | |
6450 // that we return 0 if the P-bits are not yet set. | |
6451 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
|
6452 if (_markBitMap.isMarked(addr + 1)) { |
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6453 assert(_markBitMap.isMarked(addr), "P-bit can be set only for marked objects"); |
0 | 6454 HeapWord* nextOneAddr = _markBitMap.getNextMarkedWordAddress(addr + 2); |
6455 size_t size = pointer_delta(nextOneAddr + 1, addr); | |
6456 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6457 "alignment problem"); | |
6458 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6459 return size; | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6460 } |
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6461 return 0; |
0 | 6462 } |
6463 | |
6464 HeapWord* CMSCollector::next_card_start_after_block(HeapWord* addr) const { | |
6465 size_t sz = 0; | |
6466 oop p = (oop)addr; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6467 if (p->klass_or_null() != NULL) { |
0 | 6468 sz = CompactibleFreeListSpace::adjustObjectSize(p->size()); |
6469 } else { | |
6470 sz = block_size_using_printezis_bits(addr); | |
6471 } | |
6472 assert(sz > 0, "size must be nonzero"); | |
6473 HeapWord* next_block = addr + sz; | |
6474 HeapWord* next_card = (HeapWord*)round_to((uintptr_t)next_block, | |
6475 CardTableModRefBS::card_size); | |
6476 assert(round_down((uintptr_t)addr, CardTableModRefBS::card_size) < | |
6477 round_down((uintptr_t)next_card, CardTableModRefBS::card_size), | |
6478 "must be different cards"); | |
6479 return next_card; | |
6480 } | |
6481 | |
6482 | |
6483 // CMS Bit Map Wrapper ///////////////////////////////////////// | |
6484 | |
6485 // Construct a CMS bit map infrastructure, but don't create the | |
6486 // bit vector itself. That is done by a separate call CMSBitMap::allocate() | |
6487 // further below. | |
6488 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
|
6489 _bm(), |
0 | 6490 _shifter(shifter), |
6491 _lock(mutex_rank >= 0 ? new Mutex(mutex_rank, mutex_name, true) : NULL) | |
6492 { | |
6493 _bmStartWord = 0; | |
6494 _bmWordSize = 0; | |
6495 } | |
6496 | |
6497 bool CMSBitMap::allocate(MemRegion mr) { | |
6498 _bmStartWord = mr.start(); | |
6499 _bmWordSize = mr.word_size(); | |
6500 ReservedSpace brs(ReservedSpace::allocation_align_size_up( | |
6501 (_bmWordSize >> (_shifter + LogBitsPerByte)) + 1)); | |
6502 if (!brs.is_reserved()) { | |
6503 warning("CMS bit map allocation failure"); | |
6504 return false; | |
6505 } | |
6506 // For now we'll just commit all of the bit map up fromt. | |
6507 // Later on we'll try to be more parsimonious with swap. | |
6508 if (!_virtual_space.initialize(brs, brs.size())) { | |
6509 warning("CMS bit map backing store failure"); | |
6510 return false; | |
6511 } | |
6512 assert(_virtual_space.committed_size() == brs.size(), | |
6513 "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
|
6514 _bm.set_map((BitMap::bm_word_t*)_virtual_space.low()); |
0 | 6515 assert(_virtual_space.committed_size() << (_shifter + LogBitsPerByte) >= |
6516 _bmWordSize, "inconsistency in bit map sizing"); | |
6517 _bm.set_size(_bmWordSize >> _shifter); | |
6518 | |
6519 // bm.clear(); // can we rely on getting zero'd memory? verify below | |
6520 assert(isAllClear(), | |
6521 "Expected zero'd memory from ReservedSpace constructor"); | |
6522 assert(_bm.size() == heapWordDiffToOffsetDiff(sizeInWords()), | |
6523 "consistency check"); | |
6524 return true; | |
6525 } | |
6526 | |
6527 void CMSBitMap::dirty_range_iterate_clear(MemRegion mr, MemRegionClosure* cl) { | |
6528 HeapWord *next_addr, *end_addr, *last_addr; | |
6529 assert_locked(); | |
6530 assert(covers(mr), "out-of-range error"); | |
6531 // XXX assert that start and end are appropriately aligned | |
6532 for (next_addr = mr.start(), end_addr = mr.end(); | |
6533 next_addr < end_addr; next_addr = last_addr) { | |
6534 MemRegion dirty_region = getAndClearMarkedRegion(next_addr, end_addr); | |
6535 last_addr = dirty_region.end(); | |
6536 if (!dirty_region.is_empty()) { | |
6537 cl->do_MemRegion(dirty_region); | |
6538 } else { | |
6539 assert(last_addr == end_addr, "program logic"); | |
6540 return; | |
6541 } | |
6542 } | |
6543 } | |
6544 | |
9076
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6545 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
|
6546 _bm.print_on_error(st, prefix); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6547 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6548 |
0 | 6549 #ifndef PRODUCT |
6550 void CMSBitMap::assert_locked() const { | |
6551 CMSLockVerifier::assert_locked(lock()); | |
6552 } | |
6553 | |
6554 bool CMSBitMap::covers(MemRegion mr) const { | |
6555 // assert(_bm.map() == _virtual_space.low(), "map inconsistency"); | |
6556 assert((size_t)_bm.size() == (_bmWordSize >> _shifter), | |
6557 "size inconsistency"); | |
6558 return (mr.start() >= _bmStartWord) && | |
6559 (mr.end() <= endWord()); | |
6560 } | |
6561 | |
6562 bool CMSBitMap::covers(HeapWord* start, size_t size) const { | |
6563 return (start >= _bmStartWord && (start + size) <= endWord()); | |
6564 } | |
6565 | |
6566 void CMSBitMap::verifyNoOneBitsInRange(HeapWord* left, HeapWord* right) { | |
6567 // verify that there are no 1 bits in the interval [left, right) | |
6568 FalseBitMapClosure falseBitMapClosure; | |
6569 iterate(&falseBitMapClosure, left, right); | |
6570 } | |
6571 | |
6572 void CMSBitMap::region_invariant(MemRegion mr) | |
6573 { | |
6574 assert_locked(); | |
6575 // mr = mr.intersection(MemRegion(_bmStartWord, _bmWordSize)); | |
6576 assert(!mr.is_empty(), "unexpected empty region"); | |
6577 assert(covers(mr), "mr should be covered by bit map"); | |
6578 // convert address range into offset range | |
6579 size_t start_ofs = heapWordToOffset(mr.start()); | |
6580 // Make sure that end() is appropriately aligned | |
6581 assert(mr.end() == (HeapWord*)round_to((intptr_t)mr.end(), | |
6582 (1 << (_shifter+LogHeapWordSize))), | |
6583 "Misaligned mr.end()"); | |
6584 size_t end_ofs = heapWordToOffset(mr.end()); | |
6585 assert(end_ofs > start_ofs, "Should mark at least one bit"); | |
6586 } | |
6587 | |
6588 #endif | |
6589 | |
6590 bool CMSMarkStack::allocate(size_t size) { | |
6591 // allocate a stack of the requisite depth | |
6592 ReservedSpace rs(ReservedSpace::allocation_align_size_up( | |
6593 size * sizeof(oop))); | |
6594 if (!rs.is_reserved()) { | |
6595 warning("CMSMarkStack allocation failure"); | |
6596 return false; | |
6597 } | |
6598 if (!_virtual_space.initialize(rs, rs.size())) { | |
6599 warning("CMSMarkStack backing store failure"); | |
6600 return false; | |
6601 } | |
6602 assert(_virtual_space.committed_size() == rs.size(), | |
6603 "didn't reserve backing store for all of CMS stack?"); | |
6604 _base = (oop*)(_virtual_space.low()); | |
6605 _index = 0; | |
6606 _capacity = size; | |
6607 NOT_PRODUCT(_max_depth = 0); | |
6608 return true; | |
6609 } | |
6610 | |
6611 // XXX FIX ME !!! In the MT case we come in here holding a | |
6612 // leaf lock. For printing we need to take a further lock | |
6613 // which has lower rank. We need to recallibrate the two | |
6614 // lock-ranks involved in order to be able to rpint the | |
6615 // messages below. (Or defer the printing to the caller. | |
6616 // For now we take the expedient path of just disabling the | |
6617 // messages for the problematic case.) | |
6618 void CMSMarkStack::expand() { | |
1284 | 6619 assert(_capacity <= MarkStackSizeMax, "stack bigger than permitted"); |
6620 if (_capacity == MarkStackSizeMax) { | |
0 | 6621 if (_hit_limit++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) { |
6622 // We print a warning message only once per CMS cycle. | |
6623 gclog_or_tty->print_cr(" (benign) Hit CMSMarkStack max size limit"); | |
6624 } | |
6625 return; | |
6626 } | |
6627 // Double capacity if possible | |
1284 | 6628 size_t new_capacity = MIN2(_capacity*2, MarkStackSizeMax); |
0 | 6629 // Do not give up existing stack until we have managed to |
6630 // get the double capacity that we desired. | |
6631 ReservedSpace rs(ReservedSpace::allocation_align_size_up( | |
6632 new_capacity * sizeof(oop))); | |
6633 if (rs.is_reserved()) { | |
6634 // Release the backing store associated with old stack | |
6635 _virtual_space.release(); | |
6636 // Reinitialize virtual space for new stack | |
6637 if (!_virtual_space.initialize(rs, rs.size())) { | |
6638 fatal("Not enough swap for expanded marking stack"); | |
6639 } | |
6640 _base = (oop*)(_virtual_space.low()); | |
6641 _index = 0; | |
6642 _capacity = new_capacity; | |
6643 } else if (_failed_double++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) { | |
6644 // Failed to double capacity, continue; | |
6645 // we print a detail message only once per CMS cycle. | |
6646 gclog_or_tty->print(" (benign) Failed to expand marking stack from "SIZE_FORMAT"K to " | |
6647 SIZE_FORMAT"K", | |
6648 _capacity / K, new_capacity / K); | |
6649 } | |
6650 } | |
6651 | |
6652 | |
6653 // Closures | |
6654 // XXX: there seems to be a lot of code duplication here; | |
6655 // should refactor and consolidate common code. | |
6656 | |
6657 // This closure is used to mark refs into the CMS generation in | |
6658 // the CMS bit map. Called at the first checkpoint. This closure | |
6659 // 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
|
6660 // generation on which this is used is not an oldest |
0 | 6661 // generation then this will lose younger_gen cards! |
6662 | |
6663 MarkRefsIntoClosure::MarkRefsIntoClosure( | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6664 MemRegion span, CMSBitMap* bitMap): |
0 | 6665 _span(span), |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6666 _bitMap(bitMap) |
0 | 6667 { |
6668 assert(_ref_processor == NULL, "deliberately left NULL"); | |
6669 assert(_bitMap->covers(_span), "_bitMap/_span mismatch"); | |
6670 } | |
6671 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6672 void MarkRefsIntoClosure::do_oop(oop obj) { |
0 | 6673 // 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
|
6674 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
|
6675 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6676 if (_span.contains(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6677 // 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
|
6678 _bitMap->mark(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6679 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6680 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6681 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6682 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
|
6683 void MarkRefsIntoClosure::do_oop(narrowOop* p) { MarkRefsIntoClosure::do_oop_work(p); } |
0 | 6684 |
6685 // A variant of the above, used for CMS marking verification. | |
6686 MarkRefsIntoVerifyClosure::MarkRefsIntoVerifyClosure( | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6687 MemRegion span, CMSBitMap* verification_bm, CMSBitMap* cms_bm): |
0 | 6688 _span(span), |
6689 _verification_bm(verification_bm), | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6690 _cms_bm(cms_bm) |
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6691 { |
0 | 6692 assert(_ref_processor == NULL, "deliberately left NULL"); |
6693 assert(_verification_bm->covers(_span), "_verification_bm/_span mismatch"); | |
6694 } | |
6695 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6696 void MarkRefsIntoVerifyClosure::do_oop(oop obj) { |
0 | 6697 // 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
|
6698 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
|
6699 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6700 if (_span.contains(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6701 _verification_bm->mark(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6702 if (!_cms_bm->isMarked(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6703 oop(addr)->print(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6704 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
|
6705 fatal("... aborting"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6706 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6707 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6708 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6709 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6710 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
|
6711 void MarkRefsIntoVerifyClosure::do_oop(narrowOop* p) { MarkRefsIntoVerifyClosure::do_oop_work(p); } |
0 | 6712 |
6713 ////////////////////////////////////////////////// | |
6714 // MarkRefsIntoAndScanClosure | |
6715 ////////////////////////////////////////////////// | |
6716 | |
6717 MarkRefsIntoAndScanClosure::MarkRefsIntoAndScanClosure(MemRegion span, | |
6718 ReferenceProcessor* rp, | |
6719 CMSBitMap* bit_map, | |
6720 CMSBitMap* mod_union_table, | |
6721 CMSMarkStack* mark_stack, | |
6722 CMSCollector* collector, | |
6723 bool should_yield, | |
6724 bool concurrent_precleaning): | |
6725 _collector(collector), | |
6726 _span(span), | |
6727 _bit_map(bit_map), | |
6728 _mark_stack(mark_stack), | |
6729 _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
|
6730 mark_stack, concurrent_precleaning), |
0 | 6731 _yield(should_yield), |
6732 _concurrent_precleaning(concurrent_precleaning), | |
6733 _freelistLock(NULL) | |
6734 { | |
6735 _ref_processor = rp; | |
6736 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
6737 } | |
6738 | |
6739 // This closure is used to mark refs into the CMS generation at the | |
6740 // second (final) checkpoint, and to scan and transitively follow | |
6741 // the unmarked oops. It is also used during the concurrent precleaning | |
6742 // phase while scanning objects on dirty cards in the CMS generation. | |
6743 // The marks are made in the marking bit map and the marking stack is | |
6744 // used for keeping the (newly) grey objects during the scan. | |
6745 // 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
|
6746 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
|
6747 if (obj != NULL) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6748 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
|
6749 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6750 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
|
6751 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
|
6752 "overflow list should be empty"); |
0 | 6753 if (_span.contains(addr) && |
6754 !_bit_map->isMarked(addr)) { | |
6755 // mark bit map (object is now grey) | |
6756 _bit_map->mark(addr); | |
6757 // push on marking stack (stack should be empty), and drain the | |
6758 // stack by applying this closure to the oops in the oops popped | |
6759 // 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
|
6760 bool res = _mark_stack->push(obj); |
0 | 6761 assert(res, "Should have space to push on empty stack"); |
6762 do { | |
6763 oop new_oop = _mark_stack->pop(); | |
6764 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
6765 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
6766 "only grey objects on this stack"); | |
6767 // iterate over the oops in this oop, marking and pushing | |
6768 // the ones in CMS heap (i.e. in _span). | |
6769 new_oop->oop_iterate(&_pushAndMarkClosure); | |
6770 // check if it's time to yield | |
6771 do_yield_check(); | |
6772 } while (!_mark_stack->isEmpty() || | |
6773 (!_concurrent_precleaning && take_from_overflow_list())); | |
6774 // if marking stack is empty, and we are not doing this | |
6775 // during precleaning, then check the overflow list | |
6776 } | |
6777 assert(_mark_stack->isEmpty(), "post-condition (eager drainage)"); | |
6778 assert(_collector->overflow_list_is_empty(), | |
6779 "overflow list was drained above"); | |
6780 // We could restore evacuated mark words, if any, used for | |
6781 // overflow list links here because the overflow list is | |
6782 // provably empty here. That would reduce the maximum | |
6783 // size requirements for preserved_{oop,mark}_stack. | |
6784 // But we'll just postpone it until we are all done | |
6785 // so we can just stream through. | |
6786 if (!_concurrent_precleaning && CMSOverflowEarlyRestoration) { | |
6787 _collector->restore_preserved_marks_if_any(); | |
6788 assert(_collector->no_preserved_marks(), "No preserved marks"); | |
6789 } | |
6790 assert(!CMSOverflowEarlyRestoration || _collector->no_preserved_marks(), | |
6791 "All preserved marks should have been restored above"); | |
6792 } | |
6793 } | |
6794 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6795 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
|
6796 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
|
6797 |
0 | 6798 void MarkRefsIntoAndScanClosure::do_yield_work() { |
6799 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6800 "CMS thread should hold CMS token"); | |
6801 assert_lock_strong(_freelistLock); | |
6802 assert_lock_strong(_bit_map->lock()); | |
6803 // relinquish the free_list_lock and bitMaplock() | |
6804 _bit_map->lock()->unlock(); | |
6805 _freelistLock->unlock(); | |
6806 ConcurrentMarkSweepThread::desynchronize(true); | |
6807 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6808 _collector->stopTimer(); | |
6809 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
6810 if (PrintCMSStatistics != 0) { | |
6811 _collector->incrementYields(); | |
6812 } | |
6813 _collector->icms_wait(); | |
6814 | |
6815 // 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
|
6816 for (unsigned i = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6817 i < CMSYieldSleepCount && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6818 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6819 !CMSCollector::foregroundGCIsActive(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6820 ++i) { |
0 | 6821 os::sleep(Thread::current(), 1, false); |
6822 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6823 } | |
6824 | |
6825 ConcurrentMarkSweepThread::synchronize(true); | |
6826 _freelistLock->lock_without_safepoint_check(); | |
6827 _bit_map->lock()->lock_without_safepoint_check(); | |
6828 _collector->startTimer(); | |
6829 } | |
6830 | |
6831 /////////////////////////////////////////////////////////// | |
6832 // Par_MarkRefsIntoAndScanClosure: a parallel version of | |
6833 // MarkRefsIntoAndScanClosure | |
6834 /////////////////////////////////////////////////////////// | |
6835 Par_MarkRefsIntoAndScanClosure::Par_MarkRefsIntoAndScanClosure( | |
6836 CMSCollector* collector, MemRegion span, ReferenceProcessor* rp, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6837 CMSBitMap* bit_map, OopTaskQueue* work_queue): |
0 | 6838 _span(span), |
6839 _bit_map(bit_map), | |
6840 _work_queue(work_queue), | |
6841 _low_water_mark(MIN2((uint)(work_queue->max_elems()/4), | |
6842 (uint)(CMSWorkQueueDrainThreshold * ParallelGCThreads))), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6843 _par_pushAndMarkClosure(collector, span, rp, bit_map, work_queue) |
0 | 6844 { |
6845 _ref_processor = rp; | |
6846 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
6847 } | |
6848 | |
6849 // This closure is used to mark refs into the CMS generation at the | |
6850 // second (final) checkpoint, and to scan and transitively follow | |
6851 // the unmarked oops. The marks are made in the marking bit map and | |
6852 // the work_queue is used for keeping the (newly) grey objects during | |
6853 // the scan phase whence they are also available for stealing by parallel | |
6854 // threads. Since the marking bit map is shared, updates are | |
6855 // synchronized (via CAS). | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6856 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
|
6857 if (obj != NULL) { |
0 | 6858 // Ignore mark word because this could be an already marked oop |
6859 // 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
|
6860 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
|
6861 HeapWord* addr = (HeapWord*)obj; |
0 | 6862 if (_span.contains(addr) && |
6863 !_bit_map->isMarked(addr)) { | |
6864 // mark bit map (object will become grey): | |
6865 // It is possible for several threads to be | |
6866 // trying to "claim" this object concurrently; | |
6867 // the unique thread that succeeds in marking the | |
6868 // object first will do the subsequent push on | |
6869 // to the work queue (or overflow list). | |
6870 if (_bit_map->par_mark(addr)) { | |
6871 // push on work_queue (which may not be empty), and trim the | |
6872 // queue to an appropriate length by applying this closure to | |
6873 // the oops in the oops popped from the stack (i.e. blacken the | |
6874 // grey objects) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6875 bool res = _work_queue->push(obj); |
0 | 6876 assert(res, "Low water mark should be less than capacity?"); |
6877 trim_queue(_low_water_mark); | |
6878 } // Else, another thread claimed the object | |
6879 } | |
6880 } | |
6881 } | |
6882 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6883 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
|
6884 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
|
6885 |
0 | 6886 // This closure is used to rescan the marked objects on the dirty cards |
6887 // in the mod union table and the card table proper. | |
6888 size_t ScanMarkedObjectsAgainCarefullyClosure::do_object_careful_m( | |
6889 oop p, MemRegion mr) { | |
6890 | |
6891 size_t size = 0; | |
6892 HeapWord* addr = (HeapWord*)p; | |
6893 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
6894 assert(_span.contains(addr), "we are scanning the CMS generation"); | |
6895 // check if it's time to yield | |
6896 if (do_yield_check()) { | |
6897 // We yielded for some foreground stop-world work, | |
6898 // and we have been asked to abort this ongoing preclean cycle. | |
6899 return 0; | |
6900 } | |
6901 if (_bitMap->isMarked(addr)) { | |
6902 // it's marked; is it potentially uninitialized? | |
187 | 6903 if (p->klass_or_null() != NULL) { |
0 | 6904 // an initialized object; ignore mark word in verification below |
6905 // since we are running concurrent with mutators | |
6906 assert(p->is_oop(true), "should be an oop"); | |
6907 if (p->is_objArray()) { | |
6908 // objArrays are precisely marked; restrict scanning | |
6909 // to dirty cards only. | |
187 | 6910 size = CompactibleFreeListSpace::adjustObjectSize( |
6911 p->oop_iterate(_scanningClosure, mr)); | |
0 | 6912 } else { |
6913 // A non-array may have been imprecisely marked; we need | |
6914 // to scan object in its entirety. | |
6915 size = CompactibleFreeListSpace::adjustObjectSize( | |
6916 p->oop_iterate(_scanningClosure)); | |
6917 } | |
9152 | 6918 #ifdef ASSERT |
0 | 6919 size_t direct_size = |
6920 CompactibleFreeListSpace::adjustObjectSize(p->size()); | |
6921 assert(size == direct_size, "Inconsistency in size"); | |
6922 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6923 if (!_bitMap->isMarked(addr+1)) { | |
6924 _bitMap->verifyNoOneBitsInRange(addr+2, addr+size); | |
6925 } else { | |
6926 _bitMap->verifyNoOneBitsInRange(addr+2, addr+size-1); | |
6927 assert(_bitMap->isMarked(addr+size-1), | |
6928 "inconsistent Printezis mark"); | |
6929 } | |
9152 | 6930 #endif // ASSERT |
0 | 6931 } else { |
6932 // an unitialized object | |
6933 assert(_bitMap->isMarked(addr+1), "missing Printezis mark?"); | |
6934 HeapWord* nextOneAddr = _bitMap->getNextMarkedWordAddress(addr + 2); | |
6935 size = pointer_delta(nextOneAddr + 1, addr); | |
6936 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6937 "alignment problem"); | |
6938 // Note that pre-cleaning needn't redirty the card. OopDesc::set_klass() | |
6939 // will dirty the card when the klass pointer is installed in the | |
6940 // object (signalling the completion of initialization). | |
6941 } | |
6942 } else { | |
6943 // 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
|
6944 if (p->klass_or_null() == NULL) { |
0 | 6945 // An uninitialized object, skip to the next card, since |
6946 // we may not be able to read its P-bits yet. | |
6947 assert(size == 0, "Initial value"); | |
6948 } else { | |
6949 // An object not (yet) reached by marking: we merely need to | |
6950 // compute its size so as to go look at the next block. | |
6951 assert(p->is_oop(true), "should be an oop"); | |
6952 size = CompactibleFreeListSpace::adjustObjectSize(p->size()); | |
6953 } | |
6954 } | |
6955 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
6956 return size; | |
6957 } | |
6958 | |
6959 void ScanMarkedObjectsAgainCarefullyClosure::do_yield_work() { | |
6960 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6961 "CMS thread should hold CMS token"); | |
6962 assert_lock_strong(_freelistLock); | |
6963 assert_lock_strong(_bitMap->lock()); | |
6964 // relinquish the free_list_lock and bitMaplock() | |
6965 _bitMap->lock()->unlock(); | |
6966 _freelistLock->unlock(); | |
6967 ConcurrentMarkSweepThread::desynchronize(true); | |
6968 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6969 _collector->stopTimer(); | |
6970 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
6971 if (PrintCMSStatistics != 0) { | |
6972 _collector->incrementYields(); | |
6973 } | |
6974 _collector->icms_wait(); | |
6975 | |
6976 // See the comment in coordinator_yield() | |
6977 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
|
6978 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6979 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 6980 os::sleep(Thread::current(), 1, false); |
6981 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6982 } | |
6983 | |
6984 ConcurrentMarkSweepThread::synchronize(true); | |
6985 _freelistLock->lock_without_safepoint_check(); | |
6986 _bitMap->lock()->lock_without_safepoint_check(); | |
6987 _collector->startTimer(); | |
6988 } | |
6989 | |
6990 | |
6991 ////////////////////////////////////////////////////////////////// | |
6992 // SurvivorSpacePrecleanClosure | |
6993 ////////////////////////////////////////////////////////////////// | |
6994 // This (single-threaded) closure is used to preclean the oops in | |
6995 // the survivor spaces. | |
6996 size_t SurvivorSpacePrecleanClosure::do_object_careful(oop p) { | |
6997 | |
6998 HeapWord* addr = (HeapWord*)p; | |
6999 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7000 assert(!_span.contains(addr), "we are scanning the survivor spaces"); | |
187 | 7001 assert(p->klass_or_null() != NULL, "object should be initializd"); |
0 | 7002 // an initialized object; ignore mark word in verification below |
7003 // since we are running concurrent with mutators | |
7004 assert(p->is_oop(true), "should be an oop"); | |
7005 // Note that we do not yield while we iterate over | |
7006 // the interior oops of p, pushing the relevant ones | |
7007 // on our marking stack. | |
7008 size_t size = p->oop_iterate(_scanning_closure); | |
7009 do_yield_check(); | |
7010 // Observe that below, we do not abandon the preclean | |
7011 // phase as soon as we should; rather we empty the | |
7012 // marking stack before returning. This is to satisfy | |
7013 // some existing assertions. In general, it may be a | |
7014 // good idea to abort immediately and complete the marking | |
7015 // from the grey objects at a later time. | |
7016 while (!_mark_stack->isEmpty()) { | |
7017 oop new_oop = _mark_stack->pop(); | |
7018 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
7019 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
7020 "only grey objects on this stack"); | |
7021 // iterate over the oops in this oop, marking and pushing | |
7022 // the ones in CMS heap (i.e. in _span). | |
7023 new_oop->oop_iterate(_scanning_closure); | |
7024 // check if it's time to yield | |
7025 do_yield_check(); | |
7026 } | |
7027 unsigned int after_count = | |
7028 GenCollectedHeap::heap()->total_collections(); | |
7029 bool abort = (_before_count != after_count) || | |
7030 _collector->should_abort_preclean(); | |
7031 return abort ? 0 : size; | |
7032 } | |
7033 | |
7034 void SurvivorSpacePrecleanClosure::do_yield_work() { | |
7035 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7036 "CMS thread should hold CMS token"); | |
7037 assert_lock_strong(_bit_map->lock()); | |
7038 // Relinquish the bit map lock | |
7039 _bit_map->lock()->unlock(); | |
7040 ConcurrentMarkSweepThread::desynchronize(true); | |
7041 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7042 _collector->stopTimer(); | |
7043 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7044 if (PrintCMSStatistics != 0) { | |
7045 _collector->incrementYields(); | |
7046 } | |
7047 _collector->icms_wait(); | |
7048 | |
7049 // See the comment in coordinator_yield() | |
7050 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7051 ConcurrentMarkSweepThread::should_yield() && | |
7052 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7053 os::sleep(Thread::current(), 1, false); | |
7054 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7055 } | |
7056 | |
7057 ConcurrentMarkSweepThread::synchronize(true); | |
7058 _bit_map->lock()->lock_without_safepoint_check(); | |
7059 _collector->startTimer(); | |
7060 } | |
7061 | |
7062 // This closure is used to rescan the marked objects on the dirty cards | |
7063 // in the mod union table and the card table proper. In the parallel | |
7064 // case, although the bitMap is shared, we do a single read so the | |
7065 // isMarked() query is "safe". | |
7066 bool ScanMarkedObjectsAgainClosure::do_object_bm(oop p, MemRegion mr) { | |
7067 // Ignore mark word because we are running concurrent with mutators | |
7068 assert(p->is_oop_or_null(true), "expected an oop or null"); | |
7069 HeapWord* addr = (HeapWord*)p; | |
7070 assert(_span.contains(addr), "we are scanning the CMS generation"); | |
7071 bool is_obj_array = false; | |
9152 | 7072 #ifdef ASSERT |
0 | 7073 if (!_parallel) { |
7074 assert(_mark_stack->isEmpty(), "pre-condition (eager drainage)"); | |
7075 assert(_collector->overflow_list_is_empty(), | |
7076 "overflow list should be empty"); | |
7077 | |
7078 } | |
9152 | 7079 #endif // ASSERT |
0 | 7080 if (_bit_map->isMarked(addr)) { |
7081 // Obj arrays are precisely marked, non-arrays are not; | |
7082 // so we scan objArrays precisely and non-arrays in their | |
7083 // entirety. | |
7084 if (p->is_objArray()) { | |
7085 is_obj_array = true; | |
7086 if (_parallel) { | |
7087 p->oop_iterate(_par_scan_closure, mr); | |
7088 } else { | |
7089 p->oop_iterate(_scan_closure, mr); | |
7090 } | |
7091 } else { | |
7092 if (_parallel) { | |
7093 p->oop_iterate(_par_scan_closure); | |
7094 } else { | |
7095 p->oop_iterate(_scan_closure); | |
7096 } | |
7097 } | |
7098 } | |
9152 | 7099 #ifdef ASSERT |
0 | 7100 if (!_parallel) { |
7101 assert(_mark_stack->isEmpty(), "post-condition (eager drainage)"); | |
7102 assert(_collector->overflow_list_is_empty(), | |
7103 "overflow list should be empty"); | |
7104 | |
7105 } | |
9152 | 7106 #endif // ASSERT |
0 | 7107 return is_obj_array; |
7108 } | |
7109 | |
7110 MarkFromRootsClosure::MarkFromRootsClosure(CMSCollector* collector, | |
7111 MemRegion span, | |
7112 CMSBitMap* bitMap, CMSMarkStack* markStack, | |
7113 bool should_yield, bool verifying): | |
7114 _collector(collector), | |
7115 _span(span), | |
7116 _bitMap(bitMap), | |
7117 _mut(&collector->_modUnionTable), | |
7118 _markStack(markStack), | |
7119 _yield(should_yield), | |
7120 _skipBits(0) | |
7121 { | |
7122 assert(_markStack->isEmpty(), "stack should be empty"); | |
7123 _finger = _bitMap->startWord(); | |
7124 _threshold = _finger; | |
7125 assert(_collector->_restart_addr == NULL, "Sanity check"); | |
7126 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7127 DEBUG_ONLY(_verifying = verifying;) | |
7128 } | |
7129 | |
7130 void MarkFromRootsClosure::reset(HeapWord* addr) { | |
7131 assert(_markStack->isEmpty(), "would cause duplicates on stack"); | |
7132 assert(_span.contains(addr), "Out of bounds _finger?"); | |
7133 _finger = addr; | |
7134 _threshold = (HeapWord*)round_to( | |
7135 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7136 } | |
7137 | |
7138 // Should revisit to see if this should be restructured for | |
7139 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7140 bool MarkFromRootsClosure::do_bit(size_t offset) { |
0 | 7141 if (_skipBits > 0) { |
7142 _skipBits--; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7143 return true; |
0 | 7144 } |
7145 // convert offset into a HeapWord* | |
7146 HeapWord* addr = _bitMap->startWord() + offset; | |
7147 assert(_bitMap->endWord() && addr < _bitMap->endWord(), | |
7148 "address out of range"); | |
7149 assert(_bitMap->isMarked(addr), "tautology"); | |
7150 if (_bitMap->isMarked(addr+1)) { | |
7151 // this is an allocated but not yet initialized object | |
7152 assert(_skipBits == 0, "tautology"); | |
7153 _skipBits = 2; // skip next two marked bits ("Printezis-marks") | |
7154 oop p = oop(addr); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7155 if (p->klass_or_null() == NULL) { |
0 | 7156 DEBUG_ONLY(if (!_verifying) {) |
7157 // We re-dirty the cards on which this object lies and increase | |
7158 // the _threshold so that we'll come back to scan this object | |
7159 // during the preclean or remark phase. (CMSCleanOnEnter) | |
7160 if (CMSCleanOnEnter) { | |
7161 size_t sz = _collector->block_size_using_printezis_bits(addr); | |
7162 HeapWord* end_card_addr = (HeapWord*)round_to( | |
7163 (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
|
7164 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
0 | 7165 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
7166 // Bump _threshold to end_card_addr; note that | |
7167 // _threshold cannot possibly exceed end_card_addr, anyhow. | |
7168 // This prevents future clearing of the card as the scan proceeds | |
7169 // to the right. | |
7170 assert(_threshold <= end_card_addr, | |
7171 "Because we are just scanning into this object"); | |
7172 if (_threshold < end_card_addr) { | |
7173 _threshold = end_card_addr; | |
7174 } | |
187 | 7175 if (p->klass_or_null() != NULL) { |
0 | 7176 // Redirty the range of cards... |
7177 _mut->mark_range(redirty_range); | |
7178 } // ...else the setting of klass will dirty the card anyway. | |
7179 } | |
7180 DEBUG_ONLY(}) | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7181 return true; |
0 | 7182 } |
7183 } | |
7184 scanOopsInOop(addr); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7185 return true; |
0 | 7186 } |
7187 | |
7188 // We take a break if we've been at this for a while, | |
7189 // so as to avoid monopolizing the locks involved. | |
7190 void MarkFromRootsClosure::do_yield_work() { | |
7191 // First give up the locks, then yield, then re-lock | |
7192 // We should probably use a constructor/destructor idiom to | |
7193 // do this unlock/lock or modify the MutexUnlocker class to | |
7194 // serve our purpose. XXX | |
7195 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7196 "CMS thread should hold CMS token"); | |
7197 assert_lock_strong(_bitMap->lock()); | |
7198 _bitMap->lock()->unlock(); | |
7199 ConcurrentMarkSweepThread::desynchronize(true); | |
7200 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7201 _collector->stopTimer(); | |
7202 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7203 if (PrintCMSStatistics != 0) { | |
7204 _collector->incrementYields(); | |
7205 } | |
7206 _collector->icms_wait(); | |
7207 | |
7208 // See the comment in coordinator_yield() | |
7209 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7210 ConcurrentMarkSweepThread::should_yield() && | |
7211 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7212 os::sleep(Thread::current(), 1, false); | |
7213 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7214 } | |
7215 | |
7216 ConcurrentMarkSweepThread::synchronize(true); | |
7217 _bitMap->lock()->lock_without_safepoint_check(); | |
7218 _collector->startTimer(); | |
7219 } | |
7220 | |
7221 void MarkFromRootsClosure::scanOopsInOop(HeapWord* ptr) { | |
7222 assert(_bitMap->isMarked(ptr), "expected bit to be set"); | |
7223 assert(_markStack->isEmpty(), | |
7224 "should drain stack to limit stack usage"); | |
7225 // 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
|
7226 oop obj = oop(ptr); |
0 | 7227 // Ignore mark word in verification below, since we |
7228 // 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
|
7229 assert(obj->is_oop(true), "should be an oop"); |
0 | 7230 assert(_finger <= ptr, "_finger runneth ahead"); |
7231 // 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
|
7232 _finger = ptr + obj->size(); |
0 | 7233 assert(_finger > ptr, "we just incremented it above"); |
7234 // On large heaps, it may take us some time to get through | |
7235 // the marking phase (especially if running iCMS). During | |
7236 // this time it's possible that a lot of mutations have | |
7237 // accumulated in the card table and the mod union table -- | |
7238 // these mutation records are redundant until we have | |
7239 // actually traced into the corresponding card. | |
7240 // Here, we check whether advancing the finger would make | |
7241 // us cross into a new card, and if so clear corresponding | |
7242 // cards in the MUT (preclean them in the card-table in the | |
7243 // future). | |
7244 | |
7245 DEBUG_ONLY(if (!_verifying) {) | |
7246 // The clean-on-enter optimization is disabled by default, | |
7247 // until we fix 6178663. | |
7248 if (CMSCleanOnEnter && (_finger > _threshold)) { | |
7249 // [_threshold, _finger) represents the interval | |
7250 // of cards to be cleared in MUT (or precleaned in card table). | |
7251 // The set of cards to be cleared is all those that overlap | |
7252 // with the interval [_threshold, _finger); note that | |
7253 // _threshold is always kept card-aligned but _finger isn't | |
7254 // always card-aligned. | |
7255 HeapWord* old_threshold = _threshold; | |
7256 assert(old_threshold == (HeapWord*)round_to( | |
7257 (intptr_t)old_threshold, CardTableModRefBS::card_size), | |
7258 "_threshold should always be card-aligned"); | |
7259 _threshold = (HeapWord*)round_to( | |
7260 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7261 MemRegion mr(old_threshold, _threshold); | |
7262 assert(!mr.is_empty(), "Control point invariant"); | |
7263 assert(_span.contains(mr), "Should clear within span"); | |
7264 _mut->clear_range(mr); | |
7265 } | |
7266 DEBUG_ONLY(}) | |
7267 // Note: the finger doesn't advance while we drain | |
7268 // the stack below. | |
7269 PushOrMarkClosure pushOrMarkClosure(_collector, | |
7270 _span, _bitMap, _markStack, | |
7271 _finger, this); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7272 bool res = _markStack->push(obj); |
0 | 7273 assert(res, "Empty non-zero size stack should have space for single push"); |
7274 while (!_markStack->isEmpty()) { | |
7275 oop new_oop = _markStack->pop(); | |
7276 // Skip verifying header mark word below because we are | |
7277 // running concurrent with mutators. | |
7278 assert(new_oop->is_oop(true), "Oops! expected to pop an oop"); | |
7279 // now scan this oop's oops | |
7280 new_oop->oop_iterate(&pushOrMarkClosure); | |
7281 do_yield_check(); | |
7282 } | |
7283 assert(_markStack->isEmpty(), "tautology, emphasizing post-condition"); | |
7284 } | |
7285 | |
7286 Par_MarkFromRootsClosure::Par_MarkFromRootsClosure(CMSConcMarkingTask* task, | |
7287 CMSCollector* collector, MemRegion span, | |
7288 CMSBitMap* bit_map, | |
7289 OopTaskQueue* work_queue, | |
7290 CMSMarkStack* overflow_stack, | |
7291 bool should_yield): | |
7292 _collector(collector), | |
7293 _whole_span(collector->_span), | |
7294 _span(span), | |
7295 _bit_map(bit_map), | |
7296 _mut(&collector->_modUnionTable), | |
7297 _work_queue(work_queue), | |
7298 _overflow_stack(overflow_stack), | |
7299 _yield(should_yield), | |
7300 _skip_bits(0), | |
7301 _task(task) | |
7302 { | |
7303 assert(_work_queue->size() == 0, "work_queue should be empty"); | |
7304 _finger = span.start(); | |
7305 _threshold = _finger; // XXX Defer clear-on-enter optimization for now | |
7306 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7307 } | |
7308 | |
7309 // Should revisit to see if this should be restructured for | |
7310 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7311 bool Par_MarkFromRootsClosure::do_bit(size_t offset) { |
0 | 7312 if (_skip_bits > 0) { |
7313 _skip_bits--; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7314 return true; |
0 | 7315 } |
7316 // convert offset into a HeapWord* | |
7317 HeapWord* addr = _bit_map->startWord() + offset; | |
7318 assert(_bit_map->endWord() && addr < _bit_map->endWord(), | |
7319 "address out of range"); | |
7320 assert(_bit_map->isMarked(addr), "tautology"); | |
7321 if (_bit_map->isMarked(addr+1)) { | |
7322 // this is an allocated object that might not yet be initialized | |
7323 assert(_skip_bits == 0, "tautology"); | |
7324 _skip_bits = 2; // skip next two marked bits ("Printezis-marks") | |
7325 oop p = oop(addr); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7326 if (p->klass_or_null() == NULL) { |
0 | 7327 // in the case of Clean-on-Enter optimization, redirty card |
7328 // and avoid clearing card by increasing the threshold. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7329 return true; |
0 | 7330 } |
7331 } | |
7332 scan_oops_in_oop(addr); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7333 return true; |
0 | 7334 } |
7335 | |
7336 void Par_MarkFromRootsClosure::scan_oops_in_oop(HeapWord* ptr) { | |
7337 assert(_bit_map->isMarked(ptr), "expected bit to be set"); | |
7338 // Should we assert that our work queue is empty or | |
7339 // below some drain limit? | |
7340 assert(_work_queue->size() == 0, | |
7341 "should drain stack to limit stack usage"); | |
7342 // 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
|
7343 oop obj = oop(ptr); |
0 | 7344 // Ignore mark word in verification below, since we |
7345 // 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
|
7346 assert(obj->is_oop(true), "should be an oop"); |
0 | 7347 assert(_finger <= ptr, "_finger runneth ahead"); |
7348 // 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
|
7349 _finger = ptr + obj->size(); |
0 | 7350 assert(_finger > ptr, "we just incremented it above"); |
7351 // On large heaps, it may take us some time to get through | |
7352 // the marking phase (especially if running iCMS). During | |
7353 // this time it's possible that a lot of mutations have | |
7354 // accumulated in the card table and the mod union table -- | |
7355 // these mutation records are redundant until we have | |
7356 // actually traced into the corresponding card. | |
7357 // Here, we check whether advancing the finger would make | |
7358 // us cross into a new card, and if so clear corresponding | |
7359 // cards in the MUT (preclean them in the card-table in the | |
7360 // future). | |
7361 | |
7362 // The clean-on-enter optimization is disabled by default, | |
7363 // until we fix 6178663. | |
7364 if (CMSCleanOnEnter && (_finger > _threshold)) { | |
7365 // [_threshold, _finger) represents the interval | |
7366 // of cards to be cleared in MUT (or precleaned in card table). | |
7367 // The set of cards to be cleared is all those that overlap | |
7368 // with the interval [_threshold, _finger); note that | |
7369 // _threshold is always kept card-aligned but _finger isn't | |
7370 // always card-aligned. | |
7371 HeapWord* old_threshold = _threshold; | |
7372 assert(old_threshold == (HeapWord*)round_to( | |
7373 (intptr_t)old_threshold, CardTableModRefBS::card_size), | |
7374 "_threshold should always be card-aligned"); | |
7375 _threshold = (HeapWord*)round_to( | |
7376 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7377 MemRegion mr(old_threshold, _threshold); | |
7378 assert(!mr.is_empty(), "Control point invariant"); | |
7379 assert(_span.contains(mr), "Should clear within span"); // _whole_span ?? | |
7380 _mut->clear_range(mr); | |
7381 } | |
7382 | |
7383 // Note: the local finger doesn't advance while we drain | |
7384 // the stack below, but the global finger sure can and will. | |
7385 HeapWord** gfa = _task->global_finger_addr(); | |
7386 Par_PushOrMarkClosure pushOrMarkClosure(_collector, | |
7387 _span, _bit_map, | |
7388 _work_queue, | |
7389 _overflow_stack, | |
7390 _finger, | |
7391 gfa, this); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7392 bool res = _work_queue->push(obj); // overflow could occur here |
0 | 7393 assert(res, "Will hold once we use workqueues"); |
7394 while (true) { | |
7395 oop new_oop; | |
7396 if (!_work_queue->pop_local(new_oop)) { | |
7397 // We emptied our work_queue; check if there's stuff that can | |
7398 // be gotten from the overflow stack. | |
7399 if (CMSConcMarkingTask::get_work_from_overflow_stack( | |
7400 _overflow_stack, _work_queue)) { | |
7401 do_yield_check(); | |
7402 continue; | |
7403 } else { // done | |
7404 break; | |
7405 } | |
7406 } | |
7407 // Skip verifying header mark word below because we are | |
7408 // running concurrent with mutators. | |
7409 assert(new_oop->is_oop(true), "Oops! expected to pop an oop"); | |
7410 // now scan this oop's oops | |
7411 new_oop->oop_iterate(&pushOrMarkClosure); | |
7412 do_yield_check(); | |
7413 } | |
7414 assert(_work_queue->size() == 0, "tautology, emphasizing post-condition"); | |
7415 } | |
7416 | |
7417 // Yield in response to a request from VM Thread or | |
7418 // from mutators. | |
7419 void Par_MarkFromRootsClosure::do_yield_work() { | |
7420 assert(_task != NULL, "sanity"); | |
7421 _task->yield(); | |
7422 } | |
7423 | |
7424 // A variant of the above used for verifying CMS marking work. | |
7425 MarkFromRootsVerifyClosure::MarkFromRootsVerifyClosure(CMSCollector* collector, | |
7426 MemRegion span, | |
7427 CMSBitMap* verification_bm, CMSBitMap* cms_bm, | |
7428 CMSMarkStack* mark_stack): | |
7429 _collector(collector), | |
7430 _span(span), | |
7431 _verification_bm(verification_bm), | |
7432 _cms_bm(cms_bm), | |
7433 _mark_stack(mark_stack), | |
7434 _pam_verify_closure(collector, span, verification_bm, cms_bm, | |
7435 mark_stack) | |
7436 { | |
7437 assert(_mark_stack->isEmpty(), "stack should be empty"); | |
7438 _finger = _verification_bm->startWord(); | |
7439 assert(_collector->_restart_addr == NULL, "Sanity check"); | |
7440 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7441 } | |
7442 | |
7443 void MarkFromRootsVerifyClosure::reset(HeapWord* addr) { | |
7444 assert(_mark_stack->isEmpty(), "would cause duplicates on stack"); | |
7445 assert(_span.contains(addr), "Out of bounds _finger?"); | |
7446 _finger = addr; | |
7447 } | |
7448 | |
7449 // Should revisit to see if this should be restructured for | |
7450 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7451 bool MarkFromRootsVerifyClosure::do_bit(size_t offset) { |
0 | 7452 // convert offset into a HeapWord* |
7453 HeapWord* addr = _verification_bm->startWord() + offset; | |
7454 assert(_verification_bm->endWord() && addr < _verification_bm->endWord(), | |
7455 "address out of range"); | |
7456 assert(_verification_bm->isMarked(addr), "tautology"); | |
7457 assert(_cms_bm->isMarked(addr), "tautology"); | |
7458 | |
7459 assert(_mark_stack->isEmpty(), | |
7460 "should drain stack to limit stack usage"); | |
7461 // 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
|
7462 oop obj = oop(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7463 assert(obj->is_oop(), "should be an oop"); |
0 | 7464 assert(_finger <= addr, "_finger runneth ahead"); |
7465 // 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
|
7466 _finger = addr + obj->size(); |
0 | 7467 assert(_finger > addr, "we just incremented it above"); |
7468 // Note: the finger doesn't advance while we drain | |
7469 // the stack below. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7470 bool res = _mark_stack->push(obj); |
0 | 7471 assert(res, "Empty non-zero size stack should have space for single push"); |
7472 while (!_mark_stack->isEmpty()) { | |
7473 oop new_oop = _mark_stack->pop(); | |
7474 assert(new_oop->is_oop(), "Oops! expected to pop an oop"); | |
7475 // now scan this oop's oops | |
7476 new_oop->oop_iterate(&_pam_verify_closure); | |
7477 } | |
7478 assert(_mark_stack->isEmpty(), "tautology, emphasizing post-condition"); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7479 return true; |
0 | 7480 } |
7481 | |
7482 PushAndMarkVerifyClosure::PushAndMarkVerifyClosure( | |
7483 CMSCollector* collector, MemRegion span, | |
7484 CMSBitMap* verification_bm, CMSBitMap* cms_bm, | |
7485 CMSMarkStack* mark_stack): | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7486 CMSOopClosure(collector->ref_processor()), |
0 | 7487 _collector(collector), |
7488 _span(span), | |
7489 _verification_bm(verification_bm), | |
7490 _cms_bm(cms_bm), | |
7491 _mark_stack(mark_stack) | |
7492 { } | |
7493 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7494 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
|
7495 void PushAndMarkVerifyClosure::do_oop(narrowOop* p) { PushAndMarkVerifyClosure::do_oop_work(p); } |
0 | 7496 |
7497 // Upon stack overflow, we discard (part of) the stack, | |
7498 // remembering the least address amongst those discarded | |
7499 // in CMSCollector's _restart_address. | |
7500 void PushAndMarkVerifyClosure::handle_stack_overflow(HeapWord* lost) { | |
7501 // Remember the least grey address discarded | |
7502 HeapWord* ra = (HeapWord*)_mark_stack->least_value(lost); | |
7503 _collector->lower_restart_addr(ra); | |
7504 _mark_stack->reset(); // discard stack contents | |
7505 _mark_stack->expand(); // expand the stack if possible | |
7506 } | |
7507 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7508 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
|
7509 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
|
7510 HeapWord* addr = (HeapWord*)obj; |
0 | 7511 if (_span.contains(addr) && !_verification_bm->isMarked(addr)) { |
7512 // Oop lies in _span and isn't yet grey or black | |
7513 _verification_bm->mark(addr); // now grey | |
7514 if (!_cms_bm->isMarked(addr)) { | |
7515 oop(addr)->print(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7516 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
|
7517 addr); |
0 | 7518 fatal("... aborting"); |
7519 } | |
7520 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7521 if (!_mark_stack->push(obj)) { // stack overflow |
0 | 7522 if (PrintCMSStatistics != 0) { |
7523 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7524 SIZE_FORMAT, _mark_stack->capacity()); | |
7525 } | |
7526 assert(_mark_stack->isFull(), "Else push should have succeeded"); | |
7527 handle_stack_overflow(addr); | |
7528 } | |
7529 // anything including and to the right of _finger | |
7530 // will be scanned as we iterate over the remainder of the | |
7531 // bit map | |
7532 } | |
7533 } | |
7534 | |
7535 PushOrMarkClosure::PushOrMarkClosure(CMSCollector* collector, | |
7536 MemRegion span, | |
7537 CMSBitMap* bitMap, CMSMarkStack* markStack, | |
7538 HeapWord* finger, MarkFromRootsClosure* parent) : | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7539 CMSOopClosure(collector->ref_processor()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7540 _collector(collector), |
0 | 7541 _span(span), |
7542 _bitMap(bitMap), | |
7543 _markStack(markStack), | |
7544 _finger(finger), | |
935 | 7545 _parent(parent) |
0 | 7546 { } |
7547 | |
7548 Par_PushOrMarkClosure::Par_PushOrMarkClosure(CMSCollector* collector, | |
7549 MemRegion span, | |
7550 CMSBitMap* bit_map, | |
7551 OopTaskQueue* work_queue, | |
7552 CMSMarkStack* overflow_stack, | |
7553 HeapWord* finger, | |
7554 HeapWord** global_finger_addr, | |
7555 Par_MarkFromRootsClosure* parent) : | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7556 CMSOopClosure(collector->ref_processor()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7557 _collector(collector), |
0 | 7558 _whole_span(collector->_span), |
7559 _span(span), | |
7560 _bit_map(bit_map), | |
7561 _work_queue(work_queue), | |
7562 _overflow_stack(overflow_stack), | |
7563 _finger(finger), | |
7564 _global_finger_addr(global_finger_addr), | |
935 | 7565 _parent(parent) |
0 | 7566 { } |
7567 | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7568 // Assumes thread-safe access by callers, who are |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7569 // responsible for mutual exclusion. |
0 | 7570 void CMSCollector::lower_restart_addr(HeapWord* low) { |
7571 assert(_span.contains(low), "Out of bounds addr"); | |
7572 if (_restart_addr == NULL) { | |
7573 _restart_addr = low; | |
7574 } else { | |
7575 _restart_addr = MIN2(_restart_addr, low); | |
7576 } | |
7577 } | |
7578 | |
7579 // Upon stack overflow, we discard (part of) the stack, | |
7580 // remembering the least address amongst those discarded | |
7581 // in CMSCollector's _restart_address. | |
7582 void PushOrMarkClosure::handle_stack_overflow(HeapWord* lost) { | |
7583 // Remember the least grey address discarded | |
7584 HeapWord* ra = (HeapWord*)_markStack->least_value(lost); | |
7585 _collector->lower_restart_addr(ra); | |
7586 _markStack->reset(); // discard stack contents | |
7587 _markStack->expand(); // expand the stack if possible | |
7588 } | |
7589 | |
7590 // Upon stack overflow, we discard (part of) the stack, | |
7591 // remembering the least address amongst those discarded | |
7592 // in CMSCollector's _restart_address. | |
7593 void Par_PushOrMarkClosure::handle_stack_overflow(HeapWord* lost) { | |
7594 // 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
|
7595 // workers from interfering with the work done below. |
0 | 7596 MutexLockerEx ml(_overflow_stack->par_lock(), |
7597 Mutex::_no_safepoint_check_flag); | |
7598 // Remember the least grey address discarded | |
7599 HeapWord* ra = (HeapWord*)_overflow_stack->least_value(lost); | |
7600 _collector->lower_restart_addr(ra); | |
7601 _overflow_stack->reset(); // discard stack contents | |
7602 _overflow_stack->expand(); // expand the stack if possible | |
7603 } | |
7604 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7605 void CMKlassClosure::do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7606 assert(_oop_closure != NULL, "Not initialized?"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7607 k->oops_do(_oop_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7608 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7609 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7610 void PushOrMarkClosure::do_oop(oop obj) { |
0 | 7611 // 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
|
7612 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
|
7613 HeapWord* addr = (HeapWord*)obj; |
0 | 7614 if (_span.contains(addr) && !_bitMap->isMarked(addr)) { |
7615 // Oop lies in _span and isn't yet grey or black | |
7616 _bitMap->mark(addr); // now grey | |
7617 if (addr < _finger) { | |
7618 // the bit map iteration has already either passed, or | |
7619 // sampled, this bit in the bit map; we'll need to | |
7620 // use the marking stack to scan this oop's oops. | |
7621 bool simulate_overflow = false; | |
7622 NOT_PRODUCT( | |
7623 if (CMSMarkStackOverflowALot && | |
7624 _collector->simulate_overflow()) { | |
7625 // simulate a stack overflow | |
7626 simulate_overflow = true; | |
7627 } | |
7628 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7629 if (simulate_overflow || !_markStack->push(obj)) { // stack overflow |
0 | 7630 if (PrintCMSStatistics != 0) { |
7631 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7632 SIZE_FORMAT, _markStack->capacity()); | |
7633 } | |
7634 assert(simulate_overflow || _markStack->isFull(), "Else push should have succeeded"); | |
7635 handle_stack_overflow(addr); | |
7636 } | |
7637 } | |
7638 // anything including and to the right of _finger | |
7639 // will be scanned as we iterate over the remainder of the | |
7640 // bit map | |
7641 do_yield_check(); | |
7642 } | |
7643 } | |
7644 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7645 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
|
7646 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
|
7647 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7648 void Par_PushOrMarkClosure::do_oop(oop obj) { |
0 | 7649 // 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
|
7650 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
|
7651 HeapWord* addr = (HeapWord*)obj; |
0 | 7652 if (_whole_span.contains(addr) && !_bit_map->isMarked(addr)) { |
7653 // Oop lies in _span and isn't yet grey or black | |
7654 // We read the global_finger (volatile read) strictly after marking oop | |
7655 bool res = _bit_map->par_mark(addr); // now grey | |
7656 volatile HeapWord** gfa = (volatile HeapWord**)_global_finger_addr; | |
7657 // Should we push this marked oop on our stack? | |
7658 // -- if someone else marked it, nothing to do | |
7659 // -- if target oop is above global finger nothing to do | |
7660 // -- if target oop is in chunk and above local finger | |
7661 // then nothing to do | |
7662 // -- else push on work queue | |
7663 if ( !res // someone else marked it, they will deal with it | |
7664 || (addr >= *gfa) // will be scanned in a later task | |
7665 || (_span.contains(addr) && addr >= _finger)) { // later in this chunk | |
7666 return; | |
7667 } | |
7668 // the bit map iteration has already either passed, or | |
7669 // sampled, this bit in the bit map; we'll need to | |
7670 // use the marking stack to scan this oop's oops. | |
7671 bool simulate_overflow = false; | |
7672 NOT_PRODUCT( | |
7673 if (CMSMarkStackOverflowALot && | |
7674 _collector->simulate_overflow()) { | |
7675 // simulate a stack overflow | |
7676 simulate_overflow = true; | |
7677 } | |
7678 ) | |
7679 if (simulate_overflow || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7680 !(_work_queue->push(obj) || _overflow_stack->par_push(obj))) { |
0 | 7681 // stack overflow |
7682 if (PrintCMSStatistics != 0) { | |
7683 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7684 SIZE_FORMAT, _overflow_stack->capacity()); | |
7685 } | |
7686 // We cannot assert that the overflow stack is full because | |
7687 // it may have been emptied since. | |
7688 assert(simulate_overflow || | |
7689 _work_queue->size() == _work_queue->max_elems(), | |
7690 "Else push should have succeeded"); | |
7691 handle_stack_overflow(addr); | |
7692 } | |
7693 do_yield_check(); | |
7694 } | |
7695 } | |
7696 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7697 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
|
7698 void Par_PushOrMarkClosure::do_oop(narrowOop* p) { Par_PushOrMarkClosure::do_oop_work(p); } |
0 | 7699 |
7700 PushAndMarkClosure::PushAndMarkClosure(CMSCollector* collector, | |
7701 MemRegion span, | |
7702 ReferenceProcessor* rp, | |
7703 CMSBitMap* bit_map, | |
7704 CMSBitMap* mod_union_table, | |
7705 CMSMarkStack* mark_stack, | |
7706 bool concurrent_precleaning): | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7707 CMSOopClosure(rp), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7708 _collector(collector), |
0 | 7709 _span(span), |
7710 _bit_map(bit_map), | |
7711 _mod_union_table(mod_union_table), | |
7712 _mark_stack(mark_stack), | |
935 | 7713 _concurrent_precleaning(concurrent_precleaning) |
0 | 7714 { |
7715 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7716 } | |
7717 | |
7718 // Grey object rescan during pre-cleaning and second checkpoint phases -- | |
7719 // 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
|
7720 void PushAndMarkClosure::do_oop(oop obj) { |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7721 // Ignore mark word verification. If during concurrent precleaning, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7722 // the object monitor may be locked. If during the checkpoint |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7723 // 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
|
7724 // 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
|
7725 // the mark word may be NULL). |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7726 assert(obj->is_oop_or_null(true /* ignore mark word */), |
0 | 7727 "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
|
7728 HeapWord* addr = (HeapWord*)obj; |
0 | 7729 // Check if oop points into the CMS generation |
7730 // and is not marked | |
7731 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
7732 // a white object ... | |
7733 _bit_map->mark(addr); // ... now grey | |
7734 // push on the marking stack (grey set) | |
7735 bool simulate_overflow = false; | |
7736 NOT_PRODUCT( | |
7737 if (CMSMarkStackOverflowALot && | |
7738 _collector->simulate_overflow()) { | |
7739 // simulate a stack overflow | |
7740 simulate_overflow = true; | |
7741 } | |
7742 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7743 if (simulate_overflow || !_mark_stack->push(obj)) { |
0 | 7744 if (_concurrent_precleaning) { |
283
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7745 // During precleaning we can just dirty the appropriate card(s) |
0 | 7746 // 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
|
7747 // 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
|
7748 // 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
|
7749 // 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
|
7750 // dirty cards. |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7751 // 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
|
7752 // 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
|
7753 // are required. |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7754 if (obj->is_objArray()) { |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7755 size_t sz = obj->size(); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7756 HeapWord* end_card_addr = (HeapWord*)round_to( |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7757 (intptr_t)(addr+sz), CardTableModRefBS::card_size); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7758 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
|
7759 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7760 _mod_union_table->mark_range(redirty_range); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7761 } else { |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7762 _mod_union_table->mark(addr); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7763 } |
0 | 7764 _collector->_ser_pmc_preclean_ovflw++; |
7765 } else { | |
7766 // During the remark phase, we need to remember this oop | |
7767 // in the overflow list. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7768 _collector->push_on_overflow_list(obj); |
0 | 7769 _collector->_ser_pmc_remark_ovflw++; |
7770 } | |
7771 } | |
7772 } | |
7773 } | |
7774 | |
7775 Par_PushAndMarkClosure::Par_PushAndMarkClosure(CMSCollector* collector, | |
7776 MemRegion span, | |
7777 ReferenceProcessor* rp, | |
7778 CMSBitMap* bit_map, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7779 OopTaskQueue* work_queue): |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7780 CMSOopClosure(rp), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7781 _collector(collector), |
0 | 7782 _span(span), |
7783 _bit_map(bit_map), | |
935 | 7784 _work_queue(work_queue) |
0 | 7785 { |
7786 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7787 } | |
7788 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7789 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
|
7790 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
|
7791 |
0 | 7792 // Grey object rescan during second checkpoint phase -- |
7793 // the parallel version. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7794 void Par_PushAndMarkClosure::do_oop(oop obj) { |
0 | 7795 // In the assert below, we ignore the mark word because |
7796 // this oop may point to an already visited object that is | |
7797 // on the overflow stack (in which case the mark word has | |
7798 // been hijacked for chaining into the overflow stack -- | |
7799 // if this is the last object in the overflow stack then | |
7800 // its mark word will be NULL). Because this object may | |
7801 // have been subsequently popped off the global overflow | |
7802 // stack, and the mark word possibly restored to the prototypical | |
7803 // value, by the time we get to examined this failing assert in | |
7804 // the debugger, is_oop_or_null(false) may subsequently start | |
7805 // to hold. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7806 assert(obj->is_oop_or_null(true), |
0 | 7807 "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
|
7808 HeapWord* addr = (HeapWord*)obj; |
0 | 7809 // Check if oop points into the CMS generation |
7810 // and is not marked | |
7811 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
7812 // a white object ... | |
7813 // If we manage to "claim" the object, by being the | |
7814 // first thread to mark it, then we push it on our | |
7815 // marking stack | |
7816 if (_bit_map->par_mark(addr)) { // ... now grey | |
7817 // push on work queue (grey set) | |
7818 bool simulate_overflow = false; | |
7819 NOT_PRODUCT( | |
7820 if (CMSMarkStackOverflowALot && | |
7821 _collector->par_simulate_overflow()) { | |
7822 // simulate a stack overflow | |
7823 simulate_overflow = true; | |
7824 } | |
7825 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7826 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
|
7827 _collector->par_push_on_overflow_list(obj); |
0 | 7828 _collector->_par_pmc_remark_ovflw++; // imprecise OK: no need to CAS |
7829 } | |
7830 } // Else, some other thread got there first | |
7831 } | |
7832 } | |
7833 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7834 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
|
7835 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
|
7836 |
0 | 7837 void CMSPrecleanRefsYieldClosure::do_yield_work() { |
7838 Mutex* bml = _collector->bitMapLock(); | |
7839 assert_lock_strong(bml); | |
7840 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7841 "CMS thread should hold CMS token"); | |
7842 | |
7843 bml->unlock(); | |
7844 ConcurrentMarkSweepThread::desynchronize(true); | |
7845 | |
7846 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7847 | |
7848 _collector->stopTimer(); | |
7849 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7850 if (PrintCMSStatistics != 0) { | |
7851 _collector->incrementYields(); | |
7852 } | |
7853 _collector->icms_wait(); | |
7854 | |
7855 // See the comment in coordinator_yield() | |
7856 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7857 ConcurrentMarkSweepThread::should_yield() && | |
7858 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7859 os::sleep(Thread::current(), 1, false); | |
7860 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7861 } | |
7862 | |
7863 ConcurrentMarkSweepThread::synchronize(true); | |
7864 bml->lock(); | |
7865 | |
7866 _collector->startTimer(); | |
7867 } | |
7868 | |
7869 bool CMSPrecleanRefsYieldClosure::should_return() { | |
7870 if (ConcurrentMarkSweepThread::should_yield()) { | |
7871 do_yield_work(); | |
7872 } | |
7873 return _collector->foregroundGCIsActive(); | |
7874 } | |
7875 | |
7876 void MarkFromDirtyCardsClosure::do_MemRegion(MemRegion mr) { | |
7877 assert(((size_t)mr.start())%CardTableModRefBS::card_size_in_words == 0, | |
7878 "mr should be aligned to start at a card boundary"); | |
7879 // We'd like to assert: | |
7880 // assert(mr.word_size()%CardTableModRefBS::card_size_in_words == 0, | |
7881 // "mr should be a range of cards"); | |
7882 // However, that would be too strong in one case -- the last | |
7883 // partition ends at _unallocated_block which, in general, can be | |
7884 // an arbitrary boundary, not necessarily card aligned. | |
7885 if (PrintCMSStatistics != 0) { | |
7886 _num_dirty_cards += | |
7887 mr.word_size()/CardTableModRefBS::card_size_in_words; | |
7888 } | |
7889 _space->object_iterate_mem(mr, &_scan_cl); | |
7890 } | |
7891 | |
7892 SweepClosure::SweepClosure(CMSCollector* collector, | |
7893 ConcurrentMarkSweepGeneration* g, | |
7894 CMSBitMap* bitMap, bool should_yield) : | |
7895 _collector(collector), | |
7896 _g(g), | |
7897 _sp(g->cmsSpace()), | |
7898 _limit(_sp->sweep_limit()), | |
7899 _freelistLock(_sp->freelistLock()), | |
7900 _bitMap(bitMap), | |
7901 _yield(should_yield), | |
7902 _inFreeRange(false), // No free range at beginning of sweep | |
7903 _freeRangeInFreeLists(false), // No free range at beginning of sweep | |
7904 _lastFreeRangeCoalesced(false), | |
7905 _freeFinger(g->used_region().start()) | |
7906 { | |
7907 NOT_PRODUCT( | |
7908 _numObjectsFreed = 0; | |
7909 _numWordsFreed = 0; | |
7910 _numObjectsLive = 0; | |
7911 _numWordsLive = 0; | |
7912 _numObjectsAlreadyFree = 0; | |
7913 _numWordsAlreadyFree = 0; | |
7914 _last_fc = NULL; | |
7915 | |
7916 _sp->initializeIndexedFreeListArrayReturnedBytes(); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
7917 _sp->dictionary()->initialize_dict_returned_bytes(); |
0 | 7918 ) |
7919 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), | |
7920 "sweep _limit out of bounds"); | |
7921 if (CMSTraceSweeper) { | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7922 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
|
7923 _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7924 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7925 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7926 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7927 void SweepClosure::print_on(outputStream* st) const { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7928 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
|
7929 _sp->bottom(), _sp->end()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7930 tty->print_cr("_limit = " PTR_FORMAT, _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7931 tty->print_cr("_freeFinger = " PTR_FORMAT, _freeFinger); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7932 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
|
7933 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
|
7934 _inFreeRange, _freeRangeInFreeLists, _lastFreeRangeCoalesced); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7935 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7936 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7937 #ifndef PRODUCT |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7938 // 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
|
7939 // 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
|
7940 // 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
|
7941 // enabled in product mode. |
0 | 7942 SweepClosure::~SweepClosure() { |
7943 assert_lock_strong(_freelistLock); | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
7944 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
7945 "sweep _limit out of bounds"); |
0 | 7946 if (inFreeRange()) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7947 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
|
7948 print(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7949 ShouldNotReachHere(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7950 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7951 if (Verbose && PrintGC) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7952 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
|
7953 _numObjectsFreed, _numWordsFreed*sizeof(HeapWord)); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7954 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
|
7955 SIZE_FORMAT" bytes " |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7956 "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
|
7957 _numObjectsLive, _numWordsLive*sizeof(HeapWord), |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7958 _numObjectsAlreadyFree, _numWordsAlreadyFree*sizeof(HeapWord)); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7959 size_t totalBytes = (_numWordsFreed + _numWordsLive + _numWordsAlreadyFree) |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7960 * sizeof(HeapWord); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7961 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
|
7962 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7963 if (PrintCMSStatistics && CMSVerifyReturnedBytes) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7964 size_t indexListReturnedBytes = _sp->sumIndexedFreeListArrayReturnedBytes(); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
7965 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
|
7966 size_t returned_bytes = indexListReturnedBytes + dict_returned_bytes; |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
7967 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
|
7968 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
|
7969 indexListReturnedBytes); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7970 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
|
7971 dict_returned_bytes); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7972 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7973 } |
0 | 7974 if (CMSTraceSweeper) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7975 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
|
7976 _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7977 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7978 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
7979 #endif // PRODUCT |
0 | 7980 |
7981 void SweepClosure::initialize_free_range(HeapWord* freeFinger, | |
7982 bool freeRangeInFreeLists) { | |
7983 if (CMSTraceSweeper) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
7984 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
|
7985 freeFinger, freeRangeInFreeLists); |
0 | 7986 } |
7987 assert(!inFreeRange(), "Trampling existing free range"); | |
7988 set_inFreeRange(true); | |
7989 set_lastFreeRangeCoalesced(false); | |
7990 | |
7991 set_freeFinger(freeFinger); | |
7992 set_freeRangeInFreeLists(freeRangeInFreeLists); | |
7993 if (CMSTestInFreeList) { | |
7994 if (freeRangeInFreeLists) { | |
7995 FreeChunk* fc = (FreeChunk*) freeFinger; | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
7996 assert(fc->is_free(), "A chunk on the free list should be free."); |
0 | 7997 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
|
7998 assert(_sp->verify_chunk_in_free_list(fc), "Chunk is not in free lists"); |
0 | 7999 } |
8000 } | |
8001 } | |
8002 | |
8003 // Note that the sweeper runs concurrently with mutators. Thus, | |
8004 // it is possible for direct allocation in this generation to happen | |
8005 // in the middle of the sweep. Note that the sweeper also coalesces | |
8006 // contiguous free blocks. Thus, unless the sweeper and the allocator | |
8007 // synchronize appropriately freshly allocated blocks may get swept up. | |
8008 // This is accomplished by the sweeper locking the free lists while | |
8009 // it is sweeping. Thus blocks that are determined to be free are | |
8010 // indeed free. There is however one additional complication: | |
8011 // blocks that have been allocated since the final checkpoint and | |
8012 // mark, will not have been marked and so would be treated as | |
8013 // unreachable and swept up. To prevent this, the allocator marks | |
8014 // the bit map when allocating during the sweep phase. This leads, | |
8015 // however, to a further complication -- objects may have been allocated | |
8016 // but not yet initialized -- in the sense that the header isn't yet | |
8017 // installed. The sweeper can not then determine the size of the block | |
8018 // in order to skip over it. To deal with this case, we use a technique | |
8019 // (due to Printezis) to encode such uninitialized block sizes in the | |
8020 // bit map. Since the bit map uses a bit per every HeapWord, but the | |
8021 // CMS generation has a minimum object size of 3 HeapWords, it follows | |
8022 // that "normal marks" won't be adjacent in the bit map (there will | |
8023 // always be at least two 0 bits between successive 1 bits). We make use | |
8024 // of these "unused" bits to represent uninitialized blocks -- the bit | |
8025 // corresponding to the start of the uninitialized object and the next | |
8026 // bit are both set. Finally, a 1 bit marks the end of the object that | |
8027 // started with the two consecutive 1 bits to indicate its potentially | |
8028 // uninitialized state. | |
8029 | |
8030 size_t SweepClosure::do_blk_careful(HeapWord* addr) { | |
8031 FreeChunk* fc = (FreeChunk*)addr; | |
8032 size_t res; | |
8033 | |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8034 // 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
|
8035 // 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
|
8036 // 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
|
8037 // 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
|
8038 // 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
|
8039 // 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
|
8040 // 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
|
8041 if (addr >= _limit) { // we have swept up to or past the limit: finish up |
0 | 8042 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
8043 "sweep _limit out of bounds"); | |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8044 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
|
8045 // 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
|
8046 // coalesced chunk to the appropriate free list. |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8047 if (inFreeRange()) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8048 assert(freeFinger() >= _sp->bottom() && freeFinger() < _limit, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8049 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
|
8050 flush_cur_free_chunk(freeFinger(), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8051 pointer_delta(addr, freeFinger())); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8052 if (CMSTraceSweeper) { |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8053 gclog_or_tty->print("Sweep: last chunk: "); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8054 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
|
8055 "[coalesced:"SIZE_FORMAT"]\n", |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8056 freeFinger(), pointer_delta(addr, freeFinger()), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8057 lastFreeRangeCoalesced()); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8058 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8059 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8060 |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8061 // help the iterator loop finish |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8062 return pointer_delta(_sp->end(), addr); |
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8063 } |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8064 |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8065 assert(addr < _limit, "sweep invariant"); |
0 | 8066 // check if we should yield |
8067 do_yield_check(addr); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8068 if (fc->is_free()) { |
0 | 8069 // Chunk that is already free |
8070 res = fc->size(); | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8071 do_already_free_chunk(fc); |
0 | 8072 debug_only(_sp->verifyFreeLists()); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8073 // 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
|
8074 // 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
|
8075 // 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
|
8076 // 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
|
8077 // (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
|
8078 // 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
|
8079 // 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
|
8080 // will hold). |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8081 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
|
8082 "Otherwise the size info doesn't change at this step"); |
0 | 8083 NOT_PRODUCT( |
8084 _numObjectsAlreadyFree++; | |
8085 _numWordsAlreadyFree += res; | |
8086 ) | |
8087 NOT_PRODUCT(_last_fc = fc;) | |
8088 } else if (!_bitMap->isMarked(addr)) { | |
8089 // Chunk is fresh garbage | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8090 res = do_garbage_chunk(fc); |
0 | 8091 debug_only(_sp->verifyFreeLists()); |
8092 NOT_PRODUCT( | |
8093 _numObjectsFreed++; | |
8094 _numWordsFreed += res; | |
8095 ) | |
8096 } else { | |
8097 // Chunk that is alive. | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8098 res = do_live_chunk(fc); |
0 | 8099 debug_only(_sp->verifyFreeLists()); |
8100 NOT_PRODUCT( | |
8101 _numObjectsLive++; | |
8102 _numWordsLive += res; | |
8103 ) | |
8104 } | |
8105 return res; | |
8106 } | |
8107 | |
8108 // For the smart allocation, record following | |
8109 // split deaths - a free chunk is removed from its free list because | |
8110 // it is being split into two or more chunks. | |
8111 // split birth - a free chunk is being added to its free list because | |
8112 // a larger free chunk has been split and resulted in this free chunk. | |
8113 // coal death - a free chunk is being removed from its free list because | |
8114 // it is being coalesced into a large free chunk. | |
8115 // coal birth - a free chunk is being added to its free list because | |
8116 // it was created when two or more free chunks where coalesced into | |
8117 // this free chunk. | |
8118 // | |
8119 // These statistics are used to determine the desired number of free | |
8120 // chunks of a given size. The desired number is chosen to be relative | |
8121 // to the end of a CMS sweep. The desired number at the end of a sweep | |
8122 // is the | |
8123 // count-at-end-of-previous-sweep (an amount that was enough) | |
8124 // - count-at-beginning-of-current-sweep (the excess) | |
8125 // + split-births (gains in this size during interval) | |
8126 // - split-deaths (demands on this size during interval) | |
8127 // where the interval is from the end of one sweep to the end of the | |
8128 // next. | |
8129 // | |
8130 // When sweeping the sweeper maintains an accumulated chunk which is | |
8131 // the chunk that is made up of chunks that have been coalesced. That | |
8132 // will be termed the left-hand chunk. A new chunk of garbage that | |
8133 // is being considered for coalescing will be referred to as the | |
8134 // right-hand chunk. | |
8135 // | |
8136 // When making a decision on whether to coalesce a right-hand chunk with | |
8137 // the current left-hand chunk, the current count vs. the desired count | |
8138 // of the left-hand chunk is considered. Also if the right-hand chunk | |
8139 // is near the large chunk at the end of the heap (see | |
8140 // ConcurrentMarkSweepGeneration::isNearLargestChunk()), then the | |
8141 // left-hand chunk is coalesced. | |
8142 // | |
8143 // When making a decision about whether to split a chunk, the desired count | |
8144 // vs. the current count of the candidate to be split is also considered. | |
8145 // If the candidate is underpopulated (currently fewer chunks than desired) | |
8146 // a chunk of an overpopulated (currently more chunks than desired) size may | |
8147 // be chosen. The "hint" associated with a free list, if non-null, points | |
8148 // to a free list which may be overpopulated. | |
8149 // | |
8150 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8151 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
|
8152 const size_t size = fc->size(); |
0 | 8153 // Chunks that cannot be coalesced are not in the |
8154 // free lists. | |
8155 if (CMSTestInFreeList && !fc->cantCoalesce()) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8156 assert(_sp->verify_chunk_in_free_list(fc), |
0 | 8157 "free chunk should be in free lists"); |
8158 } | |
8159 // a chunk that is already free, should not have been | |
8160 // marked in the bit map | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8161 HeapWord* const addr = (HeapWord*) fc; |
0 | 8162 assert(!_bitMap->isMarked(addr), "free chunk should be unmarked"); |
8163 // Verify that the bit map has no bits marked between | |
8164 // addr and purported end of this block. | |
8165 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8166 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8167 // Some chunks cannot be coalesced under any circumstances. |
0 | 8168 // See the definition of cantCoalesce(). |
8169 if (!fc->cantCoalesce()) { | |
8170 // This chunk can potentially be coalesced. | |
8171 if (_sp->adaptive_freelists()) { | |
8172 // All the work is done in | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8173 do_post_free_or_garbage_chunk(fc, size); |
0 | 8174 } else { // Not adaptive free lists |
8175 // this is a free chunk that can potentially be coalesced by the sweeper; | |
8176 if (!inFreeRange()) { | |
8177 // if the next chunk is a free block that can't be coalesced | |
8178 // it doesn't make sense to remove this chunk from the free lists | |
8179 FreeChunk* nextChunk = (FreeChunk*)(addr + size); | |
2136
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8180 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
|
8181 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
|
8182 nextChunk->is_free() && // ... which is free... |
2136
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8183 nextChunk->cantCoalesce()) { // ... but can't be coalesced |
0 | 8184 // nothing to do |
8185 } else { | |
8186 // Potentially the start of a new free range: | |
8187 // Don't eagerly remove it from the free lists. | |
8188 // No need to remove it if it will just be put | |
8189 // back again. (Also from a pragmatic point of view | |
8190 // if it is a free block in a region that is beyond | |
8191 // any allocated blocks, an assertion will fail) | |
8192 // Remember the start of a free run. | |
8193 initialize_free_range(addr, true); | |
8194 // end - can coalesce with next chunk | |
8195 } | |
8196 } else { | |
8197 // 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
|
8198 print_free_block_coalesced(fc); |
0 | 8199 if (CMSTraceSweeper) { |
8200 gclog_or_tty->print(" -- pick up free block 0x%x (%d)\n", fc, size); | |
8201 } | |
8202 // remove it from the free lists | |
8203 _sp->removeFreeChunkFromFreeLists(fc); | |
8204 set_lastFreeRangeCoalesced(true); | |
8205 // If the chunk is being coalesced and the current free range is | |
8206 // in the free lists, remove the current free range so that it | |
8207 // will be returned to the free lists in its entirety - all | |
8208 // the coalesced pieces included. | |
8209 if (freeRangeInFreeLists()) { | |
8210 FreeChunk* ffc = (FreeChunk*) freeFinger(); | |
8211 assert(ffc->size() == pointer_delta(addr, freeFinger()), | |
8212 "Size of free range is inconsistent with chunk size."); | |
8213 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8214 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8215 "free range is not in free lists"); |
8216 } | |
8217 _sp->removeFreeChunkFromFreeLists(ffc); | |
8218 set_freeRangeInFreeLists(false); | |
8219 } | |
8220 } | |
8221 } | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8222 // 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
|
8223 // 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
|
8224 // a "lookahead," as we do below. |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8225 if (inFreeRange()) lookahead_and_flush(fc, size); |
0 | 8226 } else { |
8227 // Code path common to both original and adaptive free lists. | |
8228 | |
8229 // cant coalesce with previous block; this should be treated | |
8230 // as the end of a free run if any | |
8231 if (inFreeRange()) { | |
8232 // 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
|
8233 assert(freeFinger() < addr, "freeFinger points too high"); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8234 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
0 | 8235 } |
8236 // else, nothing to do, just continue | |
8237 } | |
8238 } | |
8239 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8240 size_t SweepClosure::do_garbage_chunk(FreeChunk* fc) { |
0 | 8241 // This is a chunk of garbage. It is not in any free list. |
8242 // Add it to a free list or let it possibly be coalesced into | |
8243 // a larger chunk. | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8244 HeapWord* const addr = (HeapWord*) fc; |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8245 const size_t size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); |
0 | 8246 |
8247 if (_sp->adaptive_freelists()) { | |
8248 // Verify that the bit map has no bits marked between | |
8249 // addr and purported end of just dead object. | |
8250 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8251 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8252 do_post_free_or_garbage_chunk(fc, size); |
0 | 8253 } else { |
8254 if (!inFreeRange()) { | |
8255 // start of a new free range | |
8256 assert(size > 0, "A free range should have a size"); | |
8257 initialize_free_range(addr, false); | |
8258 } else { | |
8259 // this will be swept up when we hit the end of the | |
8260 // free range | |
8261 if (CMSTraceSweeper) { | |
8262 gclog_or_tty->print(" -- pick up garbage 0x%x (%d) \n", fc, size); | |
8263 } | |
8264 // If the chunk is being coalesced and the current free range is | |
8265 // in the free lists, remove the current free range so that it | |
8266 // will be returned to the free lists in its entirety - all | |
8267 // the coalesced pieces included. | |
8268 if (freeRangeInFreeLists()) { | |
8269 FreeChunk* ffc = (FreeChunk*)freeFinger(); | |
8270 assert(ffc->size() == pointer_delta(addr, freeFinger()), | |
8271 "Size of free range is inconsistent with chunk size."); | |
8272 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8273 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8274 "free range is not in free lists"); |
8275 } | |
8276 _sp->removeFreeChunkFromFreeLists(ffc); | |
8277 set_freeRangeInFreeLists(false); | |
8278 } | |
8279 set_lastFreeRangeCoalesced(true); | |
8280 } | |
8281 // this will be swept up when we hit the end of the free range | |
8282 | |
8283 // Verify that the bit map has no bits marked between | |
8284 // addr and purported end of just dead object. | |
8285 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8286 } | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8287 assert(_limit >= addr + size, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8288 "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
|
8289 if (inFreeRange()) lookahead_and_flush(fc, size); |
0 | 8290 return size; |
8291 } | |
8292 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8293 size_t SweepClosure::do_live_chunk(FreeChunk* fc) { |
0 | 8294 HeapWord* addr = (HeapWord*) fc; |
8295 // The sweeper has just found a live object. Return any accumulated | |
8296 // left hand chunk to the free lists. | |
8297 if (inFreeRange()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8298 assert(freeFinger() < addr, "freeFinger points too high"); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8299 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8300 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8301 |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8302 // This object is live: we'd normally expect this to be |
0 | 8303 // an oop, and like to assert the following: |
8304 // assert(oop(addr)->is_oop(), "live block should be an oop"); | |
8305 // However, as we commented above, this may be an object whose | |
8306 // header hasn't yet been initialized. | |
8307 size_t size; | |
8308 assert(_bitMap->isMarked(addr), "Tautology for this control point"); | |
8309 if (_bitMap->isMarked(addr + 1)) { | |
8310 // Determine the size from the bit map, rather than trying to | |
8311 // compute it from the object header. | |
8312 HeapWord* nextOneAddr = _bitMap->getNextMarkedWordAddress(addr + 2); | |
8313 size = pointer_delta(nextOneAddr + 1, addr); | |
8314 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
8315 "alignment problem"); | |
8316 | |
9152 | 8317 #ifdef ASSERT |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8318 if (oop(addr)->klass_or_null() != NULL) { |
0 | 8319 // Ignore mark word because we are running concurrent with mutators |
8320 assert(oop(addr)->is_oop(true), "live block should be an oop"); | |
8321 assert(size == | |
8322 CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()), | |
8323 "P-mark and computed size do not agree"); | |
8324 } | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8325 #endif |
0 | 8326 |
8327 } else { | |
8328 // 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
|
8329 assert(oop(addr)->klass_or_null() != NULL, |
0 | 8330 "Should be an initialized object"); |
8331 // Ignore mark word because we are running concurrent with mutators | |
8332 assert(oop(addr)->is_oop(true), "live block should be an oop"); | |
8333 // Verify that the bit map has no bits marked between | |
8334 // addr and purported end of this block. | |
8335 size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); | |
8336 assert(size >= 3, "Necessary for Printezis marks to work"); | |
8337 assert(!_bitMap->isMarked(addr+1), "Tautology for this control point"); | |
8338 DEBUG_ONLY(_bitMap->verifyNoOneBitsInRange(addr+2, addr+size);) | |
8339 } | |
8340 return size; | |
8341 } | |
8342 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8343 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
|
8344 size_t chunkSize) { |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8345 // 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
|
8346 // of the adaptive free list allocator. |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8347 const bool fcInFreeLists = fc->is_free(); |
0 | 8348 assert(_sp->adaptive_freelists(), "Should only be used in this case."); |
8349 assert((HeapWord*)fc <= _limit, "sweep invariant"); | |
8350 if (CMSTestInFreeList && fcInFreeLists) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8351 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
|
8352 } |
0 | 8353 |
8354 if (CMSTraceSweeper) { | |
8355 gclog_or_tty->print_cr(" -- pick up another chunk at 0x%x (%d)", fc, chunkSize); | |
8356 } | |
8357 | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8358 HeapWord* const fc_addr = (HeapWord*) fc; |
0 | 8359 |
8360 bool coalesce; | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8361 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
|
8362 const size_t right = chunkSize; |
0 | 8363 switch (FLSCoalescePolicy) { |
8364 // numeric value forms a coalition aggressiveness metric | |
8365 case 0: { // never coalesce | |
8366 coalesce = false; | |
8367 break; | |
8368 } | |
8369 case 1: { // coalesce if left & right chunks on overpopulated lists | |
8370 coalesce = _sp->coalOverPopulated(left) && | |
8371 _sp->coalOverPopulated(right); | |
8372 break; | |
8373 } | |
8374 case 2: { // coalesce if left chunk on overpopulated list (default) | |
8375 coalesce = _sp->coalOverPopulated(left); | |
8376 break; | |
8377 } | |
8378 case 3: { // coalesce if left OR right chunk on overpopulated list | |
8379 coalesce = _sp->coalOverPopulated(left) || | |
8380 _sp->coalOverPopulated(right); | |
8381 break; | |
8382 } | |
8383 case 4: { // always coalesce | |
8384 coalesce = true; | |
8385 break; | |
8386 } | |
8387 default: | |
8388 ShouldNotReachHere(); | |
8389 } | |
8390 | |
8391 // Should the current free range be coalesced? | |
8392 // If the chunk is in a free range and either we decided to coalesce above | |
8393 // or the chunk is near the large block at the end of the heap | |
8394 // (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
|
8395 const bool doCoalesce = inFreeRange() |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8396 && (coalesce || _g->isNearLargestChunk(fc_addr)); |
0 | 8397 if (doCoalesce) { |
8398 // Coalesce the current free range on the left with the new | |
8399 // chunk on the right. If either is on a free list, | |
8400 // it must be removed from the list and stashed in the closure. | |
8401 if (freeRangeInFreeLists()) { | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8402 FreeChunk* const ffc = (FreeChunk*)freeFinger(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8403 assert(ffc->size() == pointer_delta(fc_addr, freeFinger()), |
0 | 8404 "Size of free range is inconsistent with chunk size."); |
8405 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8406 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8407 "Chunk is not in free lists"); |
8408 } | |
8409 _sp->coalDeath(ffc->size()); | |
8410 _sp->removeFreeChunkFromFreeLists(ffc); | |
8411 set_freeRangeInFreeLists(false); | |
8412 } | |
8413 if (fcInFreeLists) { | |
8414 _sp->coalDeath(chunkSize); | |
8415 assert(fc->size() == chunkSize, | |
8416 "The chunk has the wrong size or is not in the free lists"); | |
8417 _sp->removeFreeChunkFromFreeLists(fc); | |
8418 } | |
8419 set_lastFreeRangeCoalesced(true); | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8420 print_free_block_coalesced(fc); |
0 | 8421 } else { // not in a free range and/or should not coalesce |
8422 // Return the current free range and start a new one. | |
8423 if (inFreeRange()) { | |
8424 // In a free range but cannot coalesce with the right hand chunk. | |
8425 // 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
|
8426 flush_cur_free_chunk(freeFinger(), |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8427 pointer_delta(fc_addr, freeFinger())); |
0 | 8428 } |
8429 // Set up for new free range. Pass along whether the right hand | |
8430 // chunk is in the free lists. | |
8431 initialize_free_range((HeapWord*)fc, fcInFreeLists); | |
8432 } | |
8433 } | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8434 |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8435 // Lookahead flush: |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8436 // 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
|
8437 // 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
|
8438 // 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
|
8439 // 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
|
8440 // 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
|
8441 // 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
|
8442 // 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
|
8443 // 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
|
8444 // 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
|
8445 // 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
|
8446 // 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
|
8447 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
|
8448 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
|
8449 HeapWord* const eob = ((HeapWord*)fc) + chunk_size; |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8450 assert(_sp->used_region().contains(eob - 1), |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8451 err_msg("eob = " PTR_FORMAT " out of bounds wrt _sp = [" PTR_FORMAT "," PTR_FORMAT ")" |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8452 " when examining fc = " PTR_FORMAT "(" SIZE_FORMAT ")", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8453 _limit, _sp->bottom(), _sp->end(), fc, chunk_size)); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8454 if (eob >= _limit) { |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8455 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
|
8456 if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8457 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
|
8458 "[" PTR_FORMAT "," PTR_FORMAT ") in space " |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8459 "[" PTR_FORMAT "," PTR_FORMAT ")", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8460 _limit, fc, eob, _sp->bottom(), _sp->end()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8461 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8462 // 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
|
8463 if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8464 gclog_or_tty->print_cr("Flushing ... "); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8465 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8466 assert(freeFinger() < eob, "Error"); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8467 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
|
8468 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8469 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8470 |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8471 void SweepClosure::flush_cur_free_chunk(HeapWord* chunk, size_t size) { |
0 | 8472 assert(inFreeRange(), "Should only be called if currently in a free range."); |
8473 assert(size > 0, | |
8474 "A zero sized chunk cannot be added to the free lists."); | |
8475 if (!freeRangeInFreeLists()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8476 if (CMSTestInFreeList) { |
0 | 8477 FreeChunk* fc = (FreeChunk*) chunk; |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8478 fc->set_size(size); |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8479 assert(!_sp->verify_chunk_in_free_list(fc), |
0 | 8480 "chunk should not be in free lists yet"); |
8481 } | |
8482 if (CMSTraceSweeper) { | |
8483 gclog_or_tty->print_cr(" -- add free block 0x%x (%d) to free lists", | |
8484 chunk, size); | |
8485 } | |
8486 // A new free range is going to be starting. The current | |
8487 // free range has not been added to the free lists yet or | |
8488 // was removed so add it back. | |
8489 // If the current free range was coalesced, then the death | |
8490 // of the free range was recorded. Record a birth now. | |
8491 if (lastFreeRangeCoalesced()) { | |
8492 _sp->coalBirth(size); | |
8493 } | |
8494 _sp->addChunkAndRepairOffsetTable(chunk, size, | |
8495 lastFreeRangeCoalesced()); | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8496 } else if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8497 gclog_or_tty->print_cr("Already in free list: nothing to flush"); |
0 | 8498 } |
8499 set_inFreeRange(false); | |
8500 set_freeRangeInFreeLists(false); | |
8501 } | |
8502 | |
8503 // We take a break if we've been at this for a while, | |
8504 // so as to avoid monopolizing the locks involved. | |
8505 void SweepClosure::do_yield_work(HeapWord* addr) { | |
8506 // Return current free chunk being used for coalescing (if any) | |
8507 // to the appropriate freelist. After yielding, the next | |
8508 // free block encountered will start a coalescing range of | |
8509 // free blocks. If the next free block is adjacent to the | |
8510 // chunk just flushed, they will need to wait for the next | |
8511 // sweep to be coalesced. | |
8512 if (inFreeRange()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8513 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
0 | 8514 } |
8515 | |
8516 // First give up the locks, then yield, then re-lock. | |
8517 // We should probably use a constructor/destructor idiom to | |
8518 // do this unlock/lock or modify the MutexUnlocker class to | |
8519 // serve our purpose. XXX | |
8520 assert_lock_strong(_bitMap->lock()); | |
8521 assert_lock_strong(_freelistLock); | |
8522 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
8523 "CMS thread should hold CMS token"); | |
8524 _bitMap->lock()->unlock(); | |
8525 _freelistLock->unlock(); | |
8526 ConcurrentMarkSweepThread::desynchronize(true); | |
8527 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8528 _collector->stopTimer(); | |
8529 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
8530 if (PrintCMSStatistics != 0) { | |
8531 _collector->incrementYields(); | |
8532 } | |
8533 _collector->icms_wait(); | |
8534 | |
8535 // See the comment in coordinator_yield() | |
8536 for (unsigned i = 0; i < CMSYieldSleepCount && | |
8537 ConcurrentMarkSweepThread::should_yield() && | |
8538 !CMSCollector::foregroundGCIsActive(); ++i) { | |
8539 os::sleep(Thread::current(), 1, false); | |
8540 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8541 } | |
8542 | |
8543 ConcurrentMarkSweepThread::synchronize(true); | |
8544 _freelistLock->lock(); | |
8545 _bitMap->lock()->lock_without_safepoint_check(); | |
8546 _collector->startTimer(); | |
8547 } | |
8548 | |
8549 #ifndef PRODUCT | |
8550 // This is actually very useful in a product build if it can | |
8551 // be called from the debugger. Compile it into the product | |
8552 // as needed. | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8553 bool debug_verify_chunk_in_free_list(FreeChunk* fc) { |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8554 return debug_cms_space->verify_chunk_in_free_list(fc); |
0 | 8555 } |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8556 #endif |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8557 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8558 void SweepClosure::print_free_block_coalesced(FreeChunk* fc) const { |
0 | 8559 if (CMSTraceSweeper) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8560 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
|
8561 fc, fc->size()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8562 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8563 } |
0 | 8564 |
8565 // CMSIsAliveClosure | |
8566 bool CMSIsAliveClosure::do_object_b(oop obj) { | |
8567 HeapWord* addr = (HeapWord*)obj; | |
8568 return addr != NULL && | |
8569 (!_span.contains(addr) || _bit_map->isMarked(addr)); | |
8570 } | |
8571 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8572 |
935 | 8573 CMSKeepAliveClosure::CMSKeepAliveClosure( CMSCollector* collector, |
8574 MemRegion span, | |
8575 CMSBitMap* bit_map, CMSMarkStack* mark_stack, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8576 bool cpc): |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8577 _collector(collector), |
935 | 8578 _span(span), |
8579 _bit_map(bit_map), | |
8580 _mark_stack(mark_stack), | |
8581 _concurrent_precleaning(cpc) { | |
8582 assert(!_span.is_empty(), "Empty span could spell trouble"); | |
8583 } | |
8584 | |
8585 | |
0 | 8586 // CMSKeepAliveClosure: the serial version |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8587 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
|
8588 HeapWord* addr = (HeapWord*)obj; |
0 | 8589 if (_span.contains(addr) && |
8590 !_bit_map->isMarked(addr)) { | |
8591 _bit_map->mark(addr); | |
8592 bool simulate_overflow = false; | |
8593 NOT_PRODUCT( | |
8594 if (CMSMarkStackOverflowALot && | |
8595 _collector->simulate_overflow()) { | |
8596 // simulate a stack overflow | |
8597 simulate_overflow = true; | |
8598 } | |
8599 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8600 if (simulate_overflow || !_mark_stack->push(obj)) { |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8601 if (_concurrent_precleaning) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8602 // 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
|
8603 // phase deal with it. |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8604 assert(_collector->overflow_list_is_empty(), "Error"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8605 // 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
|
8606 // 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
|
8607 // 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
|
8608 // table. |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8609 if (obj->is_objArray()) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8610 size_t sz = obj->size(); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8611 HeapWord* end_card_addr = |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8612 (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
|
8613 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8614 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8615 _collector->_modUnionTable.mark_range(redirty_range); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8616 } else { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8617 _collector->_modUnionTable.mark(addr); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8618 } |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8619 _collector->_ser_kac_preclean_ovflw++; |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8620 } else { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8621 _collector->push_on_overflow_list(obj); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8622 _collector->_ser_kac_ovflw++; |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8623 } |
0 | 8624 } |
8625 } | |
8626 } | |
8627 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8628 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
|
8629 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
|
8630 |
0 | 8631 // CMSParKeepAliveClosure: a parallel version of the above. |
8632 // The work queues are private to each closure (thread), | |
8633 // 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
|
8634 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
|
8635 HeapWord* addr = (HeapWord*)obj; |
0 | 8636 if (_span.contains(addr) && |
8637 !_bit_map->isMarked(addr)) { | |
8638 // In general, during recursive tracing, several threads | |
8639 // may be concurrently getting here; the first one to | |
8640 // "tag" it, claims it. | |
8641 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
|
8642 bool res = _work_queue->push(obj); |
0 | 8643 assert(res, "Low water mark should be much less than capacity"); |
8644 // Do a recursive trim in the hope that this will keep | |
8645 // stack usage lower, but leave some oops for potential stealers | |
8646 trim_queue(_low_water_mark); | |
8647 } // Else, another thread got there first | |
8648 } | |
8649 } | |
8650 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8651 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
|
8652 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
|
8653 |
0 | 8654 void CMSParKeepAliveClosure::trim_queue(uint max) { |
8655 while (_work_queue->size() > max) { | |
8656 oop new_oop; | |
8657 if (_work_queue->pop_local(new_oop)) { | |
8658 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
8659 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
8660 "no white objects on this stack!"); | |
8661 assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop"); | |
8662 // iterate over the oops in this oop, marking and pushing | |
8663 // the ones in CMS heap (i.e. in _span). | |
8664 new_oop->oop_iterate(&_mark_and_push); | |
8665 } | |
8666 } | |
8667 } | |
8668 | |
935 | 8669 CMSInnerParMarkAndPushClosure::CMSInnerParMarkAndPushClosure( |
8670 CMSCollector* collector, | |
8671 MemRegion span, CMSBitMap* bit_map, | |
8672 OopTaskQueue* work_queue): | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8673 _collector(collector), |
935 | 8674 _span(span), |
8675 _bit_map(bit_map), | |
8676 _work_queue(work_queue) { } | |
8677 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8678 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
|
8679 HeapWord* addr = (HeapWord*)obj; |
0 | 8680 if (_span.contains(addr) && |
8681 !_bit_map->isMarked(addr)) { | |
8682 if (_bit_map->par_mark(addr)) { | |
8683 bool simulate_overflow = false; | |
8684 NOT_PRODUCT( | |
8685 if (CMSMarkStackOverflowALot && | |
8686 _collector->par_simulate_overflow()) { | |
8687 // simulate a stack overflow | |
8688 simulate_overflow = true; | |
8689 } | |
8690 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8691 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
|
8692 _collector->par_push_on_overflow_list(obj); |
0 | 8693 _collector->_par_kac_ovflw++; |
8694 } | |
8695 } // Else another thread got there already | |
8696 } | |
8697 } | |
8698 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8699 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
|
8700 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
|
8701 |
0 | 8702 ////////////////////////////////////////////////////////////////// |
8703 // CMSExpansionCause ///////////////////////////// | |
8704 ////////////////////////////////////////////////////////////////// | |
8705 const char* CMSExpansionCause::to_string(CMSExpansionCause::Cause cause) { | |
8706 switch (cause) { | |
8707 case _no_expansion: | |
8708 return "No expansion"; | |
8709 case _satisfy_free_ratio: | |
8710 return "Free ratio"; | |
8711 case _satisfy_promotion: | |
8712 return "Satisfy promotion"; | |
8713 case _satisfy_allocation: | |
8714 return "allocation"; | |
8715 case _allocate_par_lab: | |
8716 return "Par LAB"; | |
8717 case _allocate_par_spooling_space: | |
8718 return "Par Spooling Space"; | |
8719 case _adaptive_size_policy: | |
8720 return "Ergonomics"; | |
8721 default: | |
8722 return "unknown"; | |
8723 } | |
8724 } | |
8725 | |
8726 void CMSDrainMarkingStackClosure::do_void() { | |
8727 // the max number to take from overflow list at a time | |
8728 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
|
8729 assert(!_concurrent_precleaning || _collector->overflow_list_is_empty(), |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8730 "Overflow list should be NULL during concurrent phases"); |
0 | 8731 while (!_mark_stack->isEmpty() || |
8732 // if stack is empty, check the overflow list | |
8733 _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
|
8734 oop obj = _mark_stack->pop(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8735 HeapWord* addr = (HeapWord*)obj; |
0 | 8736 assert(_span.contains(addr), "Should be within span"); |
8737 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
|
8738 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
|
8739 obj->oop_iterate(_keep_alive); |
0 | 8740 } |
8741 } | |
8742 | |
8743 void CMSParDrainMarkingStackClosure::do_void() { | |
8744 // drain queue | |
8745 trim_queue(0); | |
8746 } | |
8747 | |
8748 // Trim our work_queue so its length is below max at return | |
8749 void CMSParDrainMarkingStackClosure::trim_queue(uint max) { | |
8750 while (_work_queue->size() > max) { | |
8751 oop new_oop; | |
8752 if (_work_queue->pop_local(new_oop)) { | |
8753 assert(new_oop->is_oop(), "Expected an oop"); | |
8754 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
8755 "no white objects on this stack!"); | |
8756 assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop"); | |
8757 // iterate over the oops in this oop, marking and pushing | |
8758 // the ones in CMS heap (i.e. in _span). | |
8759 new_oop->oop_iterate(&_mark_and_push); | |
8760 } | |
8761 } | |
8762 } | |
8763 | |
8764 //////////////////////////////////////////////////////////////////// | |
8765 // Support for Marking Stack Overflow list handling and related code | |
8766 //////////////////////////////////////////////////////////////////// | |
8767 // Much of the following code is similar in shape and spirit to the | |
8768 // code used in ParNewGC. We should try and share that code | |
8769 // as much as possible in the future. | |
8770 | |
8771 #ifndef PRODUCT | |
8772 // Debugging support for CMSStackOverflowALot | |
8773 | |
8774 // It's OK to call this multi-threaded; the worst thing | |
8775 // that can happen is that we'll get a bunch of closely | |
8776 // spaced simulated oveflows, but that's OK, in fact | |
8777 // probably good as it would exercise the overflow code | |
8778 // under contention. | |
8779 bool CMSCollector::simulate_overflow() { | |
8780 if (_overflow_counter-- <= 0) { // just being defensive | |
8781 _overflow_counter = CMSMarkStackOverflowInterval; | |
8782 return true; | |
8783 } else { | |
8784 return false; | |
8785 } | |
8786 } | |
8787 | |
8788 bool CMSCollector::par_simulate_overflow() { | |
8789 return simulate_overflow(); | |
8790 } | |
8791 #endif | |
8792 | |
8793 // Single-threaded | |
8794 bool CMSCollector::take_from_overflow_list(size_t num, CMSMarkStack* stack) { | |
8795 assert(stack->isEmpty(), "Expected precondition"); | |
8796 assert(stack->capacity() > num, "Shouldn't bite more than can chew"); | |
8797 size_t i = num; | |
8798 oop cur = _overflow_list; | |
8799 const markOop proto = markOopDesc::prototype(); | |
534 | 8800 NOT_PRODUCT(ssize_t n = 0;) |
0 | 8801 for (oop next; i > 0 && cur != NULL; cur = next, i--) { |
8802 next = oop(cur->mark()); | |
8803 cur->set_mark(proto); // until proven otherwise | |
8804 assert(cur->is_oop(), "Should be an oop"); | |
8805 bool res = stack->push(cur); | |
8806 assert(res, "Bit off more than can chew?"); | |
8807 NOT_PRODUCT(n++;) | |
8808 } | |
8809 _overflow_list = cur; | |
8810 #ifndef PRODUCT | |
8811 assert(_num_par_pushes >= n, "Too many pops?"); | |
8812 _num_par_pushes -=n; | |
8813 #endif | |
8814 return !stack->isEmpty(); | |
8815 } | |
8816 | |
534 | 8817 #define BUSY (oop(0x1aff1aff)) |
8818 // (MT-safe) Get a prefix of at most "num" from the list. | |
8819 // The overflow list is chained through the mark word of | |
8820 // each object in the list. We fetch the entire list, | |
8821 // break off a prefix of the right size and return the | |
8822 // remainder. If other threads try to take objects from | |
8823 // the overflow list at that time, they will wait for | |
8824 // some time to see if data becomes available. If (and | |
8825 // only if) another thread places one or more object(s) | |
8826 // on the global list before we have returned the suffix | |
8827 // to the global list, we will walk down our local list | |
8828 // to find its end and append the global list to | |
8829 // our suffix before returning it. This suffix walk can | |
8830 // prove to be expensive (quadratic in the amount of traffic) | |
8831 // when there are many objects in the overflow list and | |
8832 // there is much producer-consumer contention on the list. | |
8833 // *NOTE*: The overflow list manipulation code here and | |
8834 // in ParNewGeneration:: are very similar in shape, | |
8835 // except that in the ParNew case we use the old (from/eden) | |
8836 // copy of the object to thread the list via its klass word. | |
8837 // Because of the common code, if you make any changes in | |
8838 // the code below, please check the ParNew version to see if | |
8839 // similar changes might be needed. | |
8840 // CR 6797058 has been filed to consolidate the common code. | |
0 | 8841 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
|
8842 OopTaskQueue* work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
8843 int no_of_gc_threads) { |
534 | 8844 assert(work_q->size() == 0, "First empty local work queue"); |
0 | 8845 assert(num < work_q->max_elems(), "Can't bite more than we can chew"); |
8846 if (_overflow_list == NULL) { | |
8847 return false; | |
8848 } | |
8849 // Grab the entire list; we'll put back a suffix | |
534 | 8850 oop prefix = (oop)Atomic::xchg_ptr(BUSY, &_overflow_list); |
8851 Thread* tid = Thread::current(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
8852 // Before "no_of_gc_threads" was introduced CMSOverflowSpinCount was |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
8853 // set to ParallelGCThreads. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
8854 size_t CMSOverflowSpinCount = (size_t) no_of_gc_threads; // was ParallelGCThreads; |
534 | 8855 size_t sleep_time_millis = MAX2((size_t)1, num/100); |
8856 // If the list is busy, we spin for a short while, | |
8857 // sleeping between attempts to get the list. | |
8858 for (size_t spin = 0; prefix == BUSY && spin < CMSOverflowSpinCount; spin++) { | |
8859 os::sleep(tid, sleep_time_millis, false); | |
8860 if (_overflow_list == NULL) { | |
8861 // Nothing left to take | |
8862 return false; | |
8863 } else if (_overflow_list != BUSY) { | |
8864 // Try and grab the prefix | |
8865 prefix = (oop)Atomic::xchg_ptr(BUSY, &_overflow_list); | |
8866 } | |
8867 } | |
8868 // If the list was found to be empty, or we spun long | |
8869 // enough, we give up and return empty-handed. If we leave | |
8870 // the list in the BUSY state below, it must be the case that | |
8871 // some other thread holds the overflow list and will set it | |
8872 // to a non-BUSY state in the future. | |
8873 if (prefix == NULL || prefix == BUSY) { | |
8874 // Nothing to take or waited long enough | |
8875 if (prefix == NULL) { | |
8876 // Write back the NULL in case we overwrote it with BUSY above | |
8877 // and it is still the same value. | |
8878 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
8879 } | |
8880 return false; | |
8881 } | |
8882 assert(prefix != NULL && prefix != BUSY, "Error"); | |
0 | 8883 size_t i = num; |
8884 oop cur = prefix; | |
534 | 8885 // Walk down the first "num" objects, unless we reach the end. |
0 | 8886 for (; i > 1 && cur->mark() != NULL; cur = oop(cur->mark()), i--); |
534 | 8887 if (cur->mark() == NULL) { |
8888 // We have "num" or fewer elements in the list, so there | |
8889 // is nothing to return to the global list. | |
8890 // Write back the NULL in lieu of the BUSY we wrote | |
8891 // above, if it is still the same value. | |
8892 if (_overflow_list == BUSY) { | |
8893 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
8894 } | |
8895 } else { | |
8896 // Chop off the suffix and rerturn it to the global list. | |
8897 assert(cur->mark() != BUSY, "Error"); | |
0 | 8898 oop suffix_head = cur->mark(); // suffix will be put back on global list |
8899 cur->set_mark(NULL); // break off suffix | |
534 | 8900 // It's possible that the list is still in the empty(busy) state |
8901 // we left it in a short while ago; in that case we may be | |
8902 // able to place back the suffix without incurring the cost | |
8903 // of a walk down the list. | |
0 | 8904 oop observed_overflow_list = _overflow_list; |
534 | 8905 oop cur_overflow_list = observed_overflow_list; |
8906 bool attached = false; | |
8907 while (observed_overflow_list == BUSY || observed_overflow_list == NULL) { | |
0 | 8908 observed_overflow_list = |
534 | 8909 (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list); |
8910 if (cur_overflow_list == observed_overflow_list) { | |
8911 attached = true; | |
8912 break; | |
8913 } else cur_overflow_list = observed_overflow_list; | |
8914 } | |
8915 if (!attached) { | |
8916 // Too bad, someone else sneaked in (at least) an element; we'll need | |
8917 // to do a splice. Find tail of suffix so we can prepend suffix to global | |
8918 // list. | |
8919 for (cur = suffix_head; cur->mark() != NULL; cur = (oop)(cur->mark())); | |
8920 oop suffix_tail = cur; | |
8921 assert(suffix_tail != NULL && suffix_tail->mark() == NULL, | |
8922 "Tautology"); | |
8923 observed_overflow_list = _overflow_list; | |
8924 do { | |
8925 cur_overflow_list = observed_overflow_list; | |
8926 if (cur_overflow_list != BUSY) { | |
8927 // Do the splice ... | |
8928 suffix_tail->set_mark(markOop(cur_overflow_list)); | |
8929 } else { // cur_overflow_list == BUSY | |
8930 suffix_tail->set_mark(NULL); | |
8931 } | |
8932 // ... and try to place spliced list back on overflow_list ... | |
8933 observed_overflow_list = | |
8934 (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list); | |
8935 } while (cur_overflow_list != observed_overflow_list); | |
8936 // ... until we have succeeded in doing so. | |
8937 } | |
0 | 8938 } |
8939 | |
8940 // Push the prefix elements on work_q | |
8941 assert(prefix != NULL, "control point invariant"); | |
8942 const markOop proto = markOopDesc::prototype(); | |
8943 oop next; | |
534 | 8944 NOT_PRODUCT(ssize_t n = 0;) |
0 | 8945 for (cur = prefix; cur != NULL; cur = next) { |
8946 next = oop(cur->mark()); | |
8947 cur->set_mark(proto); // until proven otherwise | |
8948 assert(cur->is_oop(), "Should be an oop"); | |
8949 bool res = work_q->push(cur); | |
8950 assert(res, "Bit off more than we can chew?"); | |
8951 NOT_PRODUCT(n++;) | |
8952 } | |
8953 #ifndef PRODUCT | |
8954 assert(_num_par_pushes >= n, "Too many pops?"); | |
8955 Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes); | |
8956 #endif | |
8957 return true; | |
8958 } | |
8959 | |
8960 // Single-threaded | |
8961 void CMSCollector::push_on_overflow_list(oop p) { | |
8962 NOT_PRODUCT(_num_par_pushes++;) | |
8963 assert(p->is_oop(), "Not an oop"); | |
8964 preserve_mark_if_necessary(p); | |
8965 p->set_mark((markOop)_overflow_list); | |
8966 _overflow_list = p; | |
8967 } | |
8968 | |
8969 // Multi-threaded; use CAS to prepend to overflow list | |
8970 void CMSCollector::par_push_on_overflow_list(oop p) { | |
8971 NOT_PRODUCT(Atomic::inc_ptr(&_num_par_pushes);) | |
8972 assert(p->is_oop(), "Not an oop"); | |
8973 par_preserve_mark_if_necessary(p); | |
8974 oop observed_overflow_list = _overflow_list; | |
8975 oop cur_overflow_list; | |
8976 do { | |
8977 cur_overflow_list = observed_overflow_list; | |
534 | 8978 if (cur_overflow_list != BUSY) { |
8979 p->set_mark(markOop(cur_overflow_list)); | |
8980 } else { | |
8981 p->set_mark(NULL); | |
8982 } | |
0 | 8983 observed_overflow_list = |
8984 (oop) Atomic::cmpxchg_ptr(p, &_overflow_list, cur_overflow_list); | |
8985 } while (cur_overflow_list != observed_overflow_list); | |
8986 } | |
534 | 8987 #undef BUSY |
0 | 8988 |
8989 // Single threaded | |
8990 // General Note on GrowableArray: pushes may silently fail | |
8991 // because we are (temporarily) out of C-heap for expanding | |
8992 // the stack. The problem is quite ubiquitous and affects | |
8993 // a lot of code in the JVM. The prudent thing for GrowableArray | |
8994 // to do (for now) is to exit with an error. However, that may | |
8995 // be too draconian in some cases because the caller may be | |
534 | 8996 // able to recover without much harm. For such cases, we |
0 | 8997 // should probably introduce a "soft_push" method which returns |
8998 // an indication of success or failure with the assumption that | |
8999 // the caller may be able to recover from a failure; code in | |
9000 // the VM can then be changed, incrementally, to deal with such | |
9001 // failures where possible, thus, incrementally hardening the VM | |
9002 // in such low resource situations. | |
9003 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
|
9004 _preserved_oop_stack.push(p); |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9005 _preserved_mark_stack.push(m); |
0 | 9006 assert(m == p->mark(), "Mark word changed"); |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9007 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
0 | 9008 "bijection"); |
9009 } | |
9010 | |
9011 // Single threaded | |
9012 void CMSCollector::preserve_mark_if_necessary(oop p) { | |
9013 markOop m = p->mark(); | |
9014 if (m->must_be_preserved(p)) { | |
9015 preserve_mark_work(p, m); | |
9016 } | |
9017 } | |
9018 | |
9019 void CMSCollector::par_preserve_mark_if_necessary(oop p) { | |
9020 markOop m = p->mark(); | |
9021 if (m->must_be_preserved(p)) { | |
9022 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
9023 // Even though we read the mark word without holding | |
9024 // the lock, we are assured that it will not change | |
9025 // because we "own" this oop, so no other thread can | |
9026 // be trying to push it on the overflow list; see | |
9027 // the assertion in preserve_mark_work() that checks | |
9028 // that m == p->mark(). | |
9029 preserve_mark_work(p, m); | |
9030 } | |
9031 } | |
9032 | |
9033 // We should be able to do this multi-threaded, | |
9034 // a chunk of stack being a task (this is | |
9035 // correct because each oop only ever appears | |
9036 // once in the overflow list. However, it's | |
9037 // not very easy to completely overlap this with | |
9038 // other operations, so will generally not be done | |
9039 // until all work's been completed. Because we | |
9040 // expect the preserved oop stack (set) to be small, | |
9041 // it's probably fine to do this single-threaded. | |
9042 // We can explore cleverer concurrent/overlapped/parallel | |
9043 // processing of preserved marks if we feel the | |
9044 // need for this in the future. Stack overflow should | |
9045 // be so rare in practice and, when it happens, its | |
9046 // effect on performance so great that this will | |
9047 // likely just be in the noise anyway. | |
9048 void CMSCollector::restore_preserved_marks_if_any() { | |
9049 assert(SafepointSynchronize::is_at_safepoint(), | |
9050 "world should be stopped"); | |
9051 assert(Thread::current()->is_ConcurrentGC_thread() || | |
9052 Thread::current()->is_VM_thread(), | |
9053 "should be single-threaded"); | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9054 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9055 "bijection"); |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9056 |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9057 while (!_preserved_oop_stack.is_empty()) { |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9058 oop p = _preserved_oop_stack.pop(); |
0 | 9059 assert(p->is_oop(), "Should be an oop"); |
9060 assert(_span.contains(p), "oop should be in _span"); | |
9061 assert(p->mark() == markOopDesc::prototype(), | |
9062 "Set when taken from overflow list"); | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9063 markOop m = _preserved_mark_stack.pop(); |
0 | 9064 p->set_mark(m); |
9065 } | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9066 assert(_preserved_mark_stack.is_empty() && _preserved_oop_stack.is_empty(), |
0 | 9067 "stacks were cleared above"); |
9068 } | |
9069 | |
9070 #ifndef PRODUCT | |
9071 bool CMSCollector::no_preserved_marks() const { | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9072 return _preserved_mark_stack.is_empty() && _preserved_oop_stack.is_empty(); |
0 | 9073 } |
9074 #endif | |
9075 | |
9076 CMSAdaptiveSizePolicy* ASConcurrentMarkSweepGeneration::cms_size_policy() const | |
9077 { | |
9078 GenCollectedHeap* gch = (GenCollectedHeap*) GenCollectedHeap::heap(); | |
9079 CMSAdaptiveSizePolicy* size_policy = | |
9080 (CMSAdaptiveSizePolicy*) gch->gen_policy()->size_policy(); | |
9081 assert(size_policy->is_gc_cms_adaptive_size_policy(), | |
9082 "Wrong type for size policy"); | |
9083 return size_policy; | |
9084 } | |
9085 | |
9086 void ASConcurrentMarkSweepGeneration::resize(size_t cur_promo_size, | |
9087 size_t desired_promo_size) { | |
9088 if (cur_promo_size < desired_promo_size) { | |
9089 size_t expand_bytes = desired_promo_size - cur_promo_size; | |
9090 if (PrintAdaptiveSizePolicy && Verbose) { | |
9091 gclog_or_tty->print_cr(" ASConcurrentMarkSweepGeneration::resize " | |
9092 "Expanding tenured generation by " SIZE_FORMAT " (bytes)", | |
9093 expand_bytes); | |
9094 } | |
9095 expand(expand_bytes, | |
9096 MinHeapDeltaBytes, | |
9097 CMSExpansionCause::_adaptive_size_policy); | |
9098 } else if (desired_promo_size < cur_promo_size) { | |
9099 size_t shrink_bytes = cur_promo_size - desired_promo_size; | |
9100 if (PrintAdaptiveSizePolicy && Verbose) { | |
9101 gclog_or_tty->print_cr(" ASConcurrentMarkSweepGeneration::resize " | |
9102 "Shrinking tenured generation by " SIZE_FORMAT " (bytes)", | |
9103 shrink_bytes); | |
9104 } | |
9105 shrink(shrink_bytes); | |
9106 } | |
9107 } | |
9108 | |
9109 CMSGCAdaptivePolicyCounters* ASConcurrentMarkSweepGeneration::gc_adaptive_policy_counters() { | |
9110 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9111 CMSGCAdaptivePolicyCounters* counters = | |
9112 (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters(); | |
9113 assert(counters->kind() == GCPolicyCounters::CMSGCAdaptivePolicyCountersKind, | |
9114 "Wrong kind of counters"); | |
9115 return counters; | |
9116 } | |
9117 | |
9118 | |
9119 void ASConcurrentMarkSweepGeneration::update_counters() { | |
9120 if (UsePerfData) { | |
9121 _space_counters->update_all(); | |
9122 _gen_counters->update_all(); | |
9123 CMSGCAdaptivePolicyCounters* counters = gc_adaptive_policy_counters(); | |
9124 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9125 CMSGCStats* gc_stats_l = (CMSGCStats*) gc_stats(); | |
9126 assert(gc_stats_l->kind() == GCStats::CMSGCStatsKind, | |
9127 "Wrong gc statistics type"); | |
9128 counters->update_counters(gc_stats_l); | |
9129 } | |
9130 } | |
9131 | |
9132 void ASConcurrentMarkSweepGeneration::update_counters(size_t used) { | |
9133 if (UsePerfData) { | |
9134 _space_counters->update_used(used); | |
9135 _space_counters->update_capacity(); | |
9136 _gen_counters->update_all(); | |
9137 | |
9138 CMSGCAdaptivePolicyCounters* counters = gc_adaptive_policy_counters(); | |
9139 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9140 CMSGCStats* gc_stats_l = (CMSGCStats*) gc_stats(); | |
9141 assert(gc_stats_l->kind() == GCStats::CMSGCStatsKind, | |
9142 "Wrong gc statistics type"); | |
9143 counters->update_counters(gc_stats_l); | |
9144 } | |
9145 } | |
9146 | |
9147 void ASConcurrentMarkSweepGeneration::shrink_by(size_t desired_bytes) { | |
9148 assert_locked_or_safepoint(Heap_lock); | |
9149 assert_lock_strong(freelistLock()); | |
9150 HeapWord* old_end = _cmsSpace->end(); | |
9151 HeapWord* unallocated_start = _cmsSpace->unallocated_block(); | |
9152 assert(old_end >= unallocated_start, "Miscalculation of unallocated_start"); | |
9153 FreeChunk* chunk_at_end = find_chunk_at_end(); | |
9154 if (chunk_at_end == NULL) { | |
9155 // No room to shrink | |
9156 if (PrintGCDetails && Verbose) { | |
9157 gclog_or_tty->print_cr("No room to shrink: old_end " | |
9158 PTR_FORMAT " unallocated_start " PTR_FORMAT | |
9159 " chunk_at_end " PTR_FORMAT, | |
9160 old_end, unallocated_start, chunk_at_end); | |
9161 } | |
9162 return; | |
9163 } else { | |
9164 | |
9165 // Find the chunk at the end of the space and determine | |
9166 // how much it can be shrunk. | |
9167 size_t shrinkable_size_in_bytes = chunk_at_end->size(); | |
9168 size_t aligned_shrinkable_size_in_bytes = | |
9169 align_size_down(shrinkable_size_in_bytes, os::vm_page_size()); | |
6885 | 9170 assert(unallocated_start <= (HeapWord*) chunk_at_end->end(), |
0 | 9171 "Inconsistent chunk at end of space"); |
9172 size_t bytes = MIN2(desired_bytes, aligned_shrinkable_size_in_bytes); | |
9173 size_t word_size_before = heap_word_size(_virtual_space.committed_size()); | |
9174 | |
9175 // Shrink the underlying space | |
9176 _virtual_space.shrink_by(bytes); | |
9177 if (PrintGCDetails && Verbose) { | |
9178 gclog_or_tty->print_cr("ConcurrentMarkSweepGeneration::shrink_by:" | |
9179 " desired_bytes " SIZE_FORMAT | |
9180 " shrinkable_size_in_bytes " SIZE_FORMAT | |
9181 " aligned_shrinkable_size_in_bytes " SIZE_FORMAT | |
9182 " bytes " SIZE_FORMAT, | |
9183 desired_bytes, shrinkable_size_in_bytes, | |
9184 aligned_shrinkable_size_in_bytes, bytes); | |
9185 gclog_or_tty->print_cr(" old_end " SIZE_FORMAT | |
9186 " unallocated_start " SIZE_FORMAT, | |
9187 old_end, unallocated_start); | |
9188 } | |
9189 | |
9190 // If the space did shrink (shrinking is not guaranteed), | |
9191 // shrink the chunk at the end by the appropriate amount. | |
9192 if (((HeapWord*)_virtual_space.high()) < old_end) { | |
9193 size_t new_word_size = | |
9194 heap_word_size(_virtual_space.committed_size()); | |
9195 | |
9196 // Have to remove the chunk from the dictionary because it is changing | |
9197 // size and might be someplace elsewhere in the dictionary. | |
9198 | |
9199 // Get the chunk at end, shrink it, and put it | |
9200 // back. | |
9201 _cmsSpace->removeChunkFromDictionary(chunk_at_end); | |
9202 size_t word_size_change = word_size_before - new_word_size; | |
9203 size_t chunk_at_end_old_size = chunk_at_end->size(); | |
9204 assert(chunk_at_end_old_size >= word_size_change, | |
9205 "Shrink is too large"); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
9206 chunk_at_end->set_size(chunk_at_end_old_size - |
0 | 9207 word_size_change); |
9208 _cmsSpace->freed((HeapWord*) chunk_at_end->end(), | |
9209 word_size_change); | |
9210 | |
9211 _cmsSpace->returnChunkToDictionary(chunk_at_end); | |
9212 | |
9213 MemRegion mr(_cmsSpace->bottom(), new_word_size); | |
9214 _bts->resize(new_word_size); // resize the block offset shared array | |
9215 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
9216 _cmsSpace->assert_locked(); | |
9217 _cmsSpace->set_end((HeapWord*)_virtual_space.high()); | |
9218 | |
9219 NOT_PRODUCT(_cmsSpace->dictionary()->verify()); | |
9220 | |
9221 // update the space and generation capacity counters | |
9222 if (UsePerfData) { | |
9223 _space_counters->update_capacity(); | |
9224 _gen_counters->update_all(); | |
9225 } | |
9226 | |
9227 if (Verbose && PrintGCDetails) { | |
9228 size_t new_mem_size = _virtual_space.committed_size(); | |
9229 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
|
9230 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
0 | 9231 name(), old_mem_size/K, bytes/K, new_mem_size/K); |
9232 } | |
9233 } | |
9234 | |
9235 assert(_cmsSpace->unallocated_block() <= _cmsSpace->end(), | |
9236 "Inconsistency at end of space"); | |
6885 | 9237 assert(chunk_at_end->end() == (uintptr_t*) _cmsSpace->end(), |
0 | 9238 "Shrinking is inconsistent"); |
9239 return; | |
9240 } | |
9241 } | |
9242 | |
9243 // Transfer some number of overflown objects to usual marking | |
9244 // stack. Return true if some objects were transferred. | |
9245 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
|
9246 size_t num = MIN2((size_t)(_mark_stack->capacity() - _mark_stack->length())/4, |
0 | 9247 (size_t)ParGCDesiredObjsFromOverflowList); |
9248 | |
9249 bool res = _collector->take_from_overflow_list(num, _mark_stack); | |
9250 assert(_collector->overflow_list_is_empty() || res, | |
9251 "If list is not empty, we should have taken something"); | |
9252 assert(!res || !_mark_stack->isEmpty(), | |
9253 "If we took something, it should now be on our stack"); | |
9254 return res; | |
9255 } | |
9256 | |
9257 size_t MarkDeadObjectsClosure::do_blk(HeapWord* addr) { | |
9258 size_t res = _sp->block_size_no_stall(addr, _collector); | |
9259 if (_sp->block_is_obj(addr)) { | |
9260 if (_live_bit_map->isMarked(addr)) { | |
9261 // It can't have been dead in a previous cycle | |
9262 guarantee(!_dead_bit_map->isMarked(addr), "No resurrection!"); | |
9263 } else { | |
9264 _dead_bit_map->mark(addr); // mark the dead object | |
9265 } | |
9266 } | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
9267 // Could be 0, if the block size could not be computed without stalling. |
0 | 9268 return res; |
9269 } | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9270 |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9271 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
|
9272 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9273 switch (phase) { |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9274 case CMSCollector::InitialMarking: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9275 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9276 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
|
9277 true /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9278 true /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9279 false /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9280 false /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9281 true /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9282 false /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9283 false /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9284 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9285 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9286 case CMSCollector::FinalMarking: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9287 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9288 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
|
9289 false /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9290 false /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9291 false /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9292 false /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9293 true /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9294 false /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9295 false /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9296 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9297 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9298 case CMSCollector::Sweeping: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9299 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9300 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
|
9301 false /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9302 false /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9303 true /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9304 true /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9305 false /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9306 true /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9307 true /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9308 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9309 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9310 default: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9311 ShouldNotReachHere(); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9312 } |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9313 } |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9314 |