Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @ 20278:2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com
author | stefank |
---|---|
date | Mon, 07 Jul 2014 10:12:40 +0200 |
parents | 4c1b88a53c74 |
children | ca8b8e21e2ca |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1521
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1521
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1521
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
26 #include "classfile/classLoaderData.hpp" |
1972 | 27 #include "classfile/symbolTable.hpp" |
28 #include "classfile/systemDictionary.hpp" | |
29 #include "code/codeCache.hpp" | |
30 #include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp" | |
31 #include "gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.hpp" | |
32 #include "gc_implementation/concurrentMarkSweep/cmsGCAdaptivePolicyCounters.hpp" | |
33 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp" | |
34 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" | |
35 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.inline.hpp" | |
36 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" | |
37 #include "gc_implementation/concurrentMarkSweep/vmCMSOperations.hpp" | |
38 #include "gc_implementation/parNew/parNewGeneration.hpp" | |
39 #include "gc_implementation/shared/collectorCounters.hpp" | |
10405 | 40 #include "gc_implementation/shared/gcTimer.hpp" |
41 #include "gc_implementation/shared/gcTrace.hpp" | |
42 #include "gc_implementation/shared/gcTraceTime.hpp" | |
1972 | 43 #include "gc_implementation/shared/isGCActiveMark.hpp" |
44 #include "gc_interface/collectedHeap.inline.hpp" | |
10405 | 45 #include "memory/allocation.hpp" |
1972 | 46 #include "memory/cardTableRS.hpp" |
47 #include "memory/collectorPolicy.hpp" | |
48 #include "memory/gcLocker.inline.hpp" | |
49 #include "memory/genCollectedHeap.hpp" | |
50 #include "memory/genMarkSweep.hpp" | |
51 #include "memory/genOopClosures.inline.hpp" | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
52 #include "memory/iterator.inline.hpp" |
12029
9766f73e770d
8022880: False sharing between PSPromotionManager instances
stefank
parents:
11975
diff
changeset
|
53 #include "memory/padded.hpp" |
1972 | 54 #include "memory/referencePolicy.hpp" |
55 #include "memory/resourceArea.hpp" | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
56 #include "memory/tenuredGeneration.hpp" |
1972 | 57 #include "oops/oop.inline.hpp" |
58 #include "prims/jvmtiExport.hpp" | |
59 #include "runtime/globals_extension.hpp" | |
60 #include "runtime/handles.inline.hpp" | |
61 #include "runtime/java.hpp" | |
20197
ce8f6bb717c9
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
20190
diff
changeset
|
62 #include "runtime/orderAccess.inline.hpp" |
1972 | 63 #include "runtime/vmThread.hpp" |
64 #include "services/memoryService.hpp" | |
65 #include "services/runtimeService.hpp" | |
0 | 66 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
67 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
68 |
0 | 69 // statics |
70 CMSCollector* ConcurrentMarkSweepGeneration::_collector = NULL; | |
10405 | 71 bool CMSCollector::_full_gc_requested = false; |
72 GCCause::Cause CMSCollector::_full_gc_cause = GCCause::_no_gc; | |
0 | 73 |
74 ////////////////////////////////////////////////////////////////// | |
75 // In support of CMS/VM thread synchronization | |
76 ////////////////////////////////////////////////////////////////// | |
77 // We split use of the CGC_lock into 2 "levels". | |
78 // The low-level locking is of the usual CGC_lock monitor. We introduce | |
79 // a higher level "token" (hereafter "CMS token") built on top of the | |
80 // low level monitor (hereafter "CGC lock"). | |
81 // The token-passing protocol gives priority to the VM thread. The | |
82 // CMS-lock doesn't provide any fairness guarantees, but clients | |
83 // should ensure that it is only held for very short, bounded | |
84 // durations. | |
85 // | |
86 // When either of the CMS thread or the VM thread is involved in | |
87 // collection operations during which it does not want the other | |
88 // thread to interfere, it obtains the CMS token. | |
89 // | |
90 // If either thread tries to get the token while the other has | |
91 // it, that thread waits. However, if the VM thread and CMS thread | |
92 // both want the token, then the VM thread gets priority while the | |
93 // CMS thread waits. This ensures, for instance, that the "concurrent" | |
94 // phases of the CMS thread's work do not block out the VM thread | |
95 // for long periods of time as the CMS thread continues to hog | |
96 // the token. (See bug 4616232). | |
97 // | |
98 // The baton-passing functions are, however, controlled by the | |
99 // flags _foregroundGCShouldWait and _foregroundGCIsActive, | |
100 // and here the low-level CMS lock, not the high level token, | |
101 // ensures mutual exclusion. | |
102 // | |
103 // Two important conditions that we have to satisfy: | |
104 // 1. if a thread does a low-level wait on the CMS lock, then it | |
105 // relinquishes the CMS token if it were holding that token | |
106 // when it acquired the low-level CMS lock. | |
107 // 2. any low-level notifications on the low-level lock | |
108 // should only be sent when a thread has relinquished the token. | |
109 // | |
110 // In the absence of either property, we'd have potential deadlock. | |
111 // | |
112 // We protect each of the CMS (concurrent and sequential) phases | |
113 // with the CMS _token_, not the CMS _lock_. | |
114 // | |
115 // The only code protected by CMS lock is the token acquisition code | |
116 // itself, see ConcurrentMarkSweepThread::[de]synchronize(), and the | |
117 // baton-passing code. | |
118 // | |
119 // Unfortunately, i couldn't come up with a good abstraction to factor and | |
120 // hide the naked CGC_lock manipulation in the baton-passing code | |
121 // further below. That's something we should try to do. Also, the proof | |
122 // of correctness of this 2-level locking scheme is far from obvious, | |
123 // and potentially quite slippery. We have an uneasy supsicion, for instance, | |
124 // that there may be a theoretical possibility of delay/starvation in the | |
125 // low-level lock/wait/notify scheme used for the baton-passing because of | |
126 // potential intereference with the priority scheme embodied in the | |
127 // CMS-token-passing protocol. See related comments at a CGC_lock->wait() | |
128 // invocation further below and marked with "XXX 20011219YSR". | |
129 // Indeed, as we note elsewhere, this may become yet more slippery | |
130 // in the presence of multiple CMS and/or multiple VM threads. XXX | |
131 | |
132 class CMSTokenSync: public StackObj { | |
133 private: | |
134 bool _is_cms_thread; | |
135 public: | |
136 CMSTokenSync(bool is_cms_thread): | |
137 _is_cms_thread(is_cms_thread) { | |
138 assert(is_cms_thread == Thread::current()->is_ConcurrentGC_thread(), | |
139 "Incorrect argument to constructor"); | |
140 ConcurrentMarkSweepThread::synchronize(_is_cms_thread); | |
141 } | |
142 | |
143 ~CMSTokenSync() { | |
144 assert(_is_cms_thread ? | |
145 ConcurrentMarkSweepThread::cms_thread_has_cms_token() : | |
146 ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
147 "Incorrect state"); | |
148 ConcurrentMarkSweepThread::desynchronize(_is_cms_thread); | |
149 } | |
150 }; | |
151 | |
152 // Convenience class that does a CMSTokenSync, and then acquires | |
153 // upto three locks. | |
154 class CMSTokenSyncWithLocks: public CMSTokenSync { | |
155 private: | |
156 // Note: locks are acquired in textual declaration order | |
157 // and released in the opposite order | |
158 MutexLockerEx _locker1, _locker2, _locker3; | |
159 public: | |
160 CMSTokenSyncWithLocks(bool is_cms_thread, Mutex* mutex1, | |
161 Mutex* mutex2 = NULL, Mutex* mutex3 = NULL): | |
162 CMSTokenSync(is_cms_thread), | |
163 _locker1(mutex1, Mutex::_no_safepoint_check_flag), | |
164 _locker2(mutex2, Mutex::_no_safepoint_check_flag), | |
165 _locker3(mutex3, Mutex::_no_safepoint_check_flag) | |
166 { } | |
167 }; | |
168 | |
169 | |
170 // Wrapper class to temporarily disable icms during a foreground cms collection. | |
171 class ICMSDisabler: public StackObj { | |
172 public: | |
173 // The ctor disables icms and wakes up the thread so it notices the change; | |
174 // the dtor re-enables icms. Note that the CMSCollector methods will check | |
175 // CMSIncrementalMode. | |
176 ICMSDisabler() { CMSCollector::disable_icms(); CMSCollector::start_icms(); } | |
177 ~ICMSDisabler() { CMSCollector::enable_icms(); } | |
178 }; | |
179 | |
180 ////////////////////////////////////////////////////////////////// | |
181 // Concurrent Mark-Sweep Generation ///////////////////////////// | |
182 ////////////////////////////////////////////////////////////////// | |
183 | |
184 NOT_PRODUCT(CompactibleFreeListSpace* debug_cms_space;) | |
185 | |
186 // This struct contains per-thread things necessary to support parallel | |
187 // young-gen collection. | |
6197 | 188 class CMSParGCThreadState: public CHeapObj<mtGC> { |
0 | 189 public: |
190 CFLS_LAB lab; | |
191 PromotionInfo promo; | |
192 | |
193 // Constructor. | |
194 CMSParGCThreadState(CompactibleFreeListSpace* cfls) : lab(cfls) { | |
195 promo.setSpace(cfls); | |
196 } | |
197 }; | |
198 | |
199 ConcurrentMarkSweepGeneration::ConcurrentMarkSweepGeneration( | |
200 ReservedSpace rs, size_t initial_byte_size, int level, | |
201 CardTableRS* ct, bool use_adaptive_freelists, | |
6026 | 202 FreeBlockDictionary<FreeChunk>::DictionaryChoice dictionaryChoice) : |
0 | 203 CardGeneration(rs, initial_byte_size, level, ct), |
1571
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
1521
diff
changeset
|
204 _dilatation_factor(((double)MinChunkSize)/((double)(CollectedHeap::min_fill_size()))), |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
205 _debug_collection_type(Concurrent_collection_type), |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
206 _did_compact(false) |
0 | 207 { |
208 HeapWord* bottom = (HeapWord*) _virtual_space.low(); | |
209 HeapWord* end = (HeapWord*) _virtual_space.high(); | |
210 | |
211 _direct_allocated_words = 0; | |
212 NOT_PRODUCT( | |
213 _numObjectsPromoted = 0; | |
214 _numWordsPromoted = 0; | |
215 _numObjectsAllocated = 0; | |
216 _numWordsAllocated = 0; | |
217 ) | |
218 | |
219 _cmsSpace = new CompactibleFreeListSpace(_bts, MemRegion(bottom, end), | |
220 use_adaptive_freelists, | |
221 dictionaryChoice); | |
222 NOT_PRODUCT(debug_cms_space = _cmsSpace;) | |
223 if (_cmsSpace == NULL) { | |
224 vm_exit_during_initialization( | |
225 "CompactibleFreeListSpace allocation failure"); | |
226 } | |
227 _cmsSpace->_gen = this; | |
228 | |
229 _gc_stats = new CMSGCStats(); | |
230 | |
231 // Verify the assumption that FreeChunk::_prev and OopDesc::_klass | |
232 // offsets match. The ability to tell free chunks from objects | |
233 // depends on this property. | |
234 debug_only( | |
235 FreeChunk* junk = NULL; | |
12226
7944aba7ba41
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
12112
diff
changeset
|
236 assert(UseCompressedClassPointers || |
187 | 237 junk->prev_addr() == (void*)(oop(junk)->klass_addr()), |
0 | 238 "Offset of FreeChunk::_prev within FreeChunk must match" |
239 " that of OopDesc::_klass within OopDesc"); | |
240 ) | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
241 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 242 typedef CMSParGCThreadState* CMSParGCThreadStatePtr; |
243 _par_gc_thread_states = | |
6197 | 244 NEW_C_HEAP_ARRAY(CMSParGCThreadStatePtr, ParallelGCThreads, mtGC); |
0 | 245 if (_par_gc_thread_states == NULL) { |
246 vm_exit_during_initialization("Could not allocate par gc structs"); | |
247 } | |
248 for (uint i = 0; i < ParallelGCThreads; i++) { | |
249 _par_gc_thread_states[i] = new CMSParGCThreadState(cmsSpace()); | |
250 if (_par_gc_thread_states[i] == NULL) { | |
251 vm_exit_during_initialization("Could not allocate par gc structs"); | |
252 } | |
253 } | |
254 } else { | |
255 _par_gc_thread_states = NULL; | |
256 } | |
257 _incremental_collection_failed = false; | |
258 // The "dilatation_factor" is the expansion that can occur on | |
259 // account of the fact that the minimum object size in the CMS | |
260 // generation may be larger than that in, say, a contiguous young | |
261 // generation. | |
262 // Ideally, in the calculation below, we'd compute the dilatation | |
263 // factor as: MinChunkSize/(promoting_gen's min object size) | |
264 // Since we do not have such a general query interface for the | |
265 // promoting generation, we'll instead just use the mimimum | |
266 // object size (which today is a header's worth of space); | |
267 // note that all arithmetic is in units of HeapWords. | |
1571
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
1521
diff
changeset
|
268 assert(MinChunkSize >= CollectedHeap::min_fill_size(), "just checking"); |
0 | 269 assert(_dilatation_factor >= 1.0, "from previous assert"); |
270 } | |
271 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
272 |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
273 // The field "_initiating_occupancy" represents the occupancy percentage |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
274 // at which we trigger a new collection cycle. Unless explicitly specified |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
275 // via CMSInitiatingOccupancyFraction (argument "io" below), it |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
276 // is calculated by: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
277 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
278 // Let "f" be MinHeapFreeRatio in |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
279 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
280 // _intiating_occupancy = 100-f + |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
281 // f * (CMSTriggerRatio/100) |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
282 // where CMSTriggerRatio is the argument "tr" below. |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
283 // |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
284 // That is, if we assume the heap is at its desired maximum occupancy at the |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
285 // end of a collection, we let CMSTriggerRatio of the (purported) free |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
286 // space be allocated before initiating a new collection cycle. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
287 // |
8035 | 288 void ConcurrentMarkSweepGeneration::init_initiating_occupancy(intx io, uintx tr) { |
289 assert(io <= 100 && tr <= 100, "Check the arguments"); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
290 if (io >= 0) { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
291 _initiating_occupancy = (double)io / 100.0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
292 } else { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
293 _initiating_occupancy = ((100 - MinHeapFreeRatio) + |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
294 (double)(tr * MinHeapFreeRatio) / 100.0) |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
295 / 100.0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
296 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
297 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
298 |
0 | 299 void ConcurrentMarkSweepGeneration::ref_processor_init() { |
300 assert(collector() != NULL, "no collector"); | |
301 collector()->ref_processor_init(); | |
302 } | |
303 | |
304 void CMSCollector::ref_processor_init() { | |
305 if (_ref_processor == NULL) { | |
306 // Allocate and initialize a reference processor | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
307 _ref_processor = |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
308 new ReferenceProcessor(_span, // span |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
309 (ParallelGCThreads > 1) && ParallelRefProcEnabled, // mt processing |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
310 (int) ParallelGCThreads, // mt processing degree |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
311 _cmsGen->refs_discovery_is_mt(), // mt discovery |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
312 (int) MAX2(ConcGCThreads, ParallelGCThreads), // mt discovery degree |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
313 _cmsGen->refs_discovery_is_atomic(), // discovery is not atomic |
17976
8e20ef014b08
8043239: G1: Missing post barrier in processing of j.l.ref.Reference objects
brutisso
parents:
17937
diff
changeset
|
314 &_is_alive_closure); // closure for liveness info |
0 | 315 // Initialize the _ref_processor field of CMSGen |
316 _cmsGen->set_ref_processor(_ref_processor); | |
317 | |
318 } | |
319 } | |
320 | |
321 CMSAdaptiveSizePolicy* CMSCollector::size_policy() { | |
322 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
323 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
324 "Wrong type of heap"); | |
325 CMSAdaptiveSizePolicy* sp = (CMSAdaptiveSizePolicy*) | |
326 gch->gen_policy()->size_policy(); | |
327 assert(sp->is_gc_cms_adaptive_size_policy(), | |
328 "Wrong type of size policy"); | |
329 return sp; | |
330 } | |
331 | |
332 CMSGCAdaptivePolicyCounters* CMSCollector::gc_adaptive_policy_counters() { | |
333 CMSGCAdaptivePolicyCounters* results = | |
334 (CMSGCAdaptivePolicyCounters*) collector_policy()->counters(); | |
335 assert( | |
336 results->kind() == GCPolicyCounters::CMSGCAdaptivePolicyCountersKind, | |
337 "Wrong gc policy counter kind"); | |
338 return results; | |
339 } | |
340 | |
341 | |
342 void ConcurrentMarkSweepGeneration::initialize_performance_counters() { | |
343 | |
344 const char* gen_name = "old"; | |
345 | |
346 // Generation Counters - generation 1, 1 subspace | |
347 _gen_counters = new GenerationCounters(gen_name, 1, 1, &_virtual_space); | |
348 | |
349 _space_counters = new GSpaceCounters(gen_name, 0, | |
350 _virtual_space.reserved_size(), | |
351 this, _gen_counters); | |
352 } | |
353 | |
354 CMSStats::CMSStats(ConcurrentMarkSweepGeneration* cms_gen, unsigned int alpha): | |
355 _cms_gen(cms_gen) | |
356 { | |
357 assert(alpha <= 100, "bad value"); | |
358 _saved_alpha = alpha; | |
359 | |
360 // Initialize the alphas to the bootstrap value of 100. | |
361 _gc0_alpha = _cms_alpha = 100; | |
362 | |
363 _cms_begin_time.update(); | |
364 _cms_end_time.update(); | |
365 | |
366 _gc0_duration = 0.0; | |
367 _gc0_period = 0.0; | |
368 _gc0_promoted = 0; | |
369 | |
370 _cms_duration = 0.0; | |
371 _cms_period = 0.0; | |
372 _cms_allocated = 0; | |
373 | |
374 _cms_used_at_gc0_begin = 0; | |
375 _cms_used_at_gc0_end = 0; | |
376 _allow_duty_cycle_reduction = false; | |
377 _valid_bits = 0; | |
378 _icms_duty_cycle = CMSIncrementalDutyCycle; | |
379 } | |
380 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
381 double CMSStats::cms_free_adjustment_factor(size_t free) const { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
382 // TBD: CR 6909490 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
383 return 1.0; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
384 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
385 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
386 void CMSStats::adjust_cms_free_adjustment_factor(bool fail, size_t free) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
387 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
388 |
0 | 389 // If promotion failure handling is on use |
390 // the padded average size of the promotion for each | |
391 // young generation collection. | |
392 double CMSStats::time_until_cms_gen_full() const { | |
393 size_t cms_free = _cms_gen->cmsSpace()->free(); | |
394 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
395 size_t expected_promotion = MIN2(gch->get_gen(0)->capacity(), |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
396 (size_t) _cms_gen->gc_stats()->avg_promoted()->padded_average()); |
0 | 397 if (cms_free > expected_promotion) { |
398 // Start a cms collection if there isn't enough space to promote | |
399 // for the next minor collection. Use the padded average as | |
400 // a safety factor. | |
401 cms_free -= expected_promotion; | |
402 | |
403 // Adjust by the safety factor. | |
404 double cms_free_dbl = (double)cms_free; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
405 double cms_adjustment = (100.0 - CMSIncrementalSafetyFactor)/100.0; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
406 // Apply a further correction factor which tries to adjust |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
407 // for recent occurance of concurrent mode failures. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
408 cms_adjustment = cms_adjustment * cms_free_adjustment_factor(cms_free); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
409 cms_free_dbl = cms_free_dbl * cms_adjustment; |
0 | 410 |
411 if (PrintGCDetails && Verbose) { | |
412 gclog_or_tty->print_cr("CMSStats::time_until_cms_gen_full: cms_free " | |
413 SIZE_FORMAT " expected_promotion " SIZE_FORMAT, | |
414 cms_free, expected_promotion); | |
415 gclog_or_tty->print_cr(" cms_free_dbl %f cms_consumption_rate %f", | |
416 cms_free_dbl, cms_consumption_rate() + 1.0); | |
417 } | |
418 // Add 1 in case the consumption rate goes to zero. | |
419 return cms_free_dbl / (cms_consumption_rate() + 1.0); | |
420 } | |
421 return 0.0; | |
422 } | |
423 | |
424 // Compare the duration of the cms collection to the | |
425 // time remaining before the cms generation is empty. | |
426 // Note that the time from the start of the cms collection | |
427 // to the start of the cms sweep (less than the total | |
428 // duration of the cms collection) can be used. This | |
429 // has been tried and some applications experienced | |
430 // promotion failures early in execution. This was | |
431 // possibly because the averages were not accurate | |
432 // enough at the beginning. | |
433 double CMSStats::time_until_cms_start() const { | |
434 // We add "gc0_period" to the "work" calculation | |
435 // below because this query is done (mostly) at the | |
436 // end of a scavenge, so we need to conservatively | |
437 // account for that much possible delay | |
438 // in the query so as to avoid concurrent mode failures | |
439 // due to starting the collection just a wee bit too | |
440 // late. | |
441 double work = cms_duration() + gc0_period(); | |
442 double deadline = time_until_cms_gen_full(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
443 // If a concurrent mode failure occurred recently, we want to be |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
444 // more conservative and halve our expected time_until_cms_gen_full() |
0 | 445 if (work > deadline) { |
446 if (Verbose && PrintGCDetails) { | |
447 gclog_or_tty->print( | |
448 " CMSCollector: collect because of anticipated promotion " | |
449 "before full %3.7f + %3.7f > %3.7f ", cms_duration(), | |
450 gc0_period(), time_until_cms_gen_full()); | |
451 } | |
452 return 0.0; | |
453 } | |
454 return work - deadline; | |
455 } | |
456 | |
457 // Return a duty cycle based on old_duty_cycle and new_duty_cycle, limiting the | |
458 // amount of change to prevent wild oscillation. | |
459 unsigned int CMSStats::icms_damped_duty_cycle(unsigned int old_duty_cycle, | |
460 unsigned int new_duty_cycle) { | |
461 assert(old_duty_cycle <= 100, "bad input value"); | |
462 assert(new_duty_cycle <= 100, "bad input value"); | |
463 | |
464 // Note: use subtraction with caution since it may underflow (values are | |
465 // unsigned). Addition is safe since we're in the range 0-100. | |
466 unsigned int damped_duty_cycle = new_duty_cycle; | |
467 if (new_duty_cycle < old_duty_cycle) { | |
468 const unsigned int largest_delta = MAX2(old_duty_cycle / 4, 5U); | |
469 if (new_duty_cycle + largest_delta < old_duty_cycle) { | |
470 damped_duty_cycle = old_duty_cycle - largest_delta; | |
471 } | |
472 } else if (new_duty_cycle > old_duty_cycle) { | |
473 const unsigned int largest_delta = MAX2(old_duty_cycle / 4, 15U); | |
474 if (new_duty_cycle > old_duty_cycle + largest_delta) { | |
475 damped_duty_cycle = MIN2(old_duty_cycle + largest_delta, 100U); | |
476 } | |
477 } | |
478 assert(damped_duty_cycle <= 100, "invalid duty cycle computed"); | |
479 | |
480 if (CMSTraceIncrementalPacing) { | |
481 gclog_or_tty->print(" [icms_damped_duty_cycle(%d,%d) = %d] ", | |
482 old_duty_cycle, new_duty_cycle, damped_duty_cycle); | |
483 } | |
484 return damped_duty_cycle; | |
485 } | |
486 | |
487 unsigned int CMSStats::icms_update_duty_cycle_impl() { | |
488 assert(CMSIncrementalPacing && valid(), | |
489 "should be handled in icms_update_duty_cycle()"); | |
490 | |
491 double cms_time_so_far = cms_timer().seconds(); | |
492 double scaled_duration = cms_duration_per_mb() * _cms_used_at_gc0_end / M; | |
493 double scaled_duration_remaining = fabsd(scaled_duration - cms_time_so_far); | |
494 | |
495 // Avoid division by 0. | |
496 double time_until_full = MAX2(time_until_cms_gen_full(), 0.01); | |
497 double duty_cycle_dbl = 100.0 * scaled_duration_remaining / time_until_full; | |
498 | |
499 unsigned int new_duty_cycle = MIN2((unsigned int)duty_cycle_dbl, 100U); | |
500 if (new_duty_cycle > _icms_duty_cycle) { | |
501 // Avoid very small duty cycles (1 or 2); 0 is allowed. | |
502 if (new_duty_cycle > 2) { | |
503 _icms_duty_cycle = icms_damped_duty_cycle(_icms_duty_cycle, | |
504 new_duty_cycle); | |
505 } | |
506 } else if (_allow_duty_cycle_reduction) { | |
507 // The duty cycle is reduced only once per cms cycle (see record_cms_end()). | |
508 new_duty_cycle = icms_damped_duty_cycle(_icms_duty_cycle, new_duty_cycle); | |
509 // Respect the minimum duty cycle. | |
510 unsigned int min_duty_cycle = (unsigned int)CMSIncrementalDutyCycleMin; | |
511 _icms_duty_cycle = MAX2(new_duty_cycle, min_duty_cycle); | |
512 } | |
513 | |
514 if (PrintGCDetails || CMSTraceIncrementalPacing) { | |
515 gclog_or_tty->print(" icms_dc=%d ", _icms_duty_cycle); | |
516 } | |
517 | |
518 _allow_duty_cycle_reduction = false; | |
519 return _icms_duty_cycle; | |
520 } | |
521 | |
522 #ifndef PRODUCT | |
523 void CMSStats::print_on(outputStream *st) const { | |
524 st->print(" gc0_alpha=%d,cms_alpha=%d", _gc0_alpha, _cms_alpha); | |
525 st->print(",gc0_dur=%g,gc0_per=%g,gc0_promo=" SIZE_FORMAT, | |
526 gc0_duration(), gc0_period(), gc0_promoted()); | |
527 st->print(",cms_dur=%g,cms_dur_per_mb=%g,cms_per=%g,cms_alloc=" SIZE_FORMAT, | |
528 cms_duration(), cms_duration_per_mb(), | |
529 cms_period(), cms_allocated()); | |
530 st->print(",cms_since_beg=%g,cms_since_end=%g", | |
531 cms_time_since_begin(), cms_time_since_end()); | |
532 st->print(",cms_used_beg=" SIZE_FORMAT ",cms_used_end=" SIZE_FORMAT, | |
533 _cms_used_at_gc0_begin, _cms_used_at_gc0_end); | |
534 if (CMSIncrementalMode) { | |
535 st->print(",dc=%d", icms_duty_cycle()); | |
536 } | |
537 | |
538 if (valid()) { | |
539 st->print(",promo_rate=%g,cms_alloc_rate=%g", | |
540 promotion_rate(), cms_allocation_rate()); | |
541 st->print(",cms_consumption_rate=%g,time_until_full=%g", | |
542 cms_consumption_rate(), time_until_cms_gen_full()); | |
543 } | |
544 st->print(" "); | |
545 } | |
546 #endif // #ifndef PRODUCT | |
547 | |
548 CMSCollector::CollectorState CMSCollector::_collectorState = | |
549 CMSCollector::Idling; | |
550 bool CMSCollector::_foregroundGCIsActive = false; | |
551 bool CMSCollector::_foregroundGCShouldWait = false; | |
552 | |
553 CMSCollector::CMSCollector(ConcurrentMarkSweepGeneration* cmsGen, | |
554 CardTableRS* ct, | |
555 ConcurrentMarkSweepPolicy* cp): | |
556 _cmsGen(cmsGen), | |
557 _ct(ct), | |
558 _ref_processor(NULL), // will be set later | |
559 _conc_workers(NULL), // may be set later | |
560 _abort_preclean(false), | |
561 _start_sampling(false), | |
562 _between_prologue_and_epilogue(false), | |
563 _markBitMap(0, Mutex::leaf + 1, "CMS_markBitMap_lock"), | |
564 _modUnionTable((CardTableModRefBS::card_shift - LogHeapWordSize), | |
565 -1 /* lock-free */, "No_lock" /* dummy */), | |
566 _modUnionClosure(&_modUnionTable), | |
567 _modUnionClosurePar(&_modUnionTable), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
568 // Adjust my span to cover old (cms) gen |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
569 _span(cmsGen->reserved()), |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
570 // Construct the is_alive_closure with _span & markBitMap |
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
571 _is_alive_closure(_span, &_markBitMap), |
0 | 572 _restart_addr(NULL), |
573 _overflow_list(NULL), | |
574 _stats(cmsGen), | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
575 _eden_chunk_lock(new Mutex(Mutex::leaf + 1, "CMS_eden_chunk_lock", true)), |
0 | 576 _eden_chunk_array(NULL), // may be set in ctor body |
577 _eden_chunk_capacity(0), // -- ditto -- | |
578 _eden_chunk_index(0), // -- ditto -- | |
579 _survivor_plab_array(NULL), // -- ditto -- | |
580 _survivor_chunk_array(NULL), // -- ditto -- | |
581 _survivor_chunk_capacity(0), // -- ditto -- | |
582 _survivor_chunk_index(0), // -- ditto -- | |
583 _ser_pmc_preclean_ovflw(0), | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
584 _ser_kac_preclean_ovflw(0), |
0 | 585 _ser_pmc_remark_ovflw(0), |
586 _par_pmc_remark_ovflw(0), | |
587 _ser_kac_ovflw(0), | |
588 _par_kac_ovflw(0), | |
589 #ifndef PRODUCT | |
590 _num_par_pushes(0), | |
591 #endif | |
592 _collection_count_start(0), | |
593 _verifying(false), | |
594 _icms_start_limit(NULL), | |
595 _icms_stop_limit(NULL), | |
596 _verification_mark_bm(0, Mutex::leaf + 1, "CMS_verification_mark_bm_lock"), | |
597 _completed_initialization(false), | |
598 _collector_policy(cp), | |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
599 _should_unload_classes(CMSClassUnloadingEnabled), |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
600 _concurrent_cycles_since_last_unload(0), |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
601 _roots_scanning_options(SharedHeap::SO_None), |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
602 _inter_sweep_estimate(CMS_SweepWeight, CMS_SweepPadding), |
10405 | 603 _intra_sweep_estimate(CMS_SweepWeight, CMS_SweepPadding), |
604 _gc_tracer_cm(new (ResourceObj::C_HEAP, mtGC) CMSTracer()), | |
605 _gc_timer_cm(new (ResourceObj::C_HEAP, mtGC) ConcurrentGCTimer()), | |
606 _cms_start_registered(false) | |
0 | 607 { |
608 if (ExplicitGCInvokesConcurrentAndUnloadsClasses) { | |
609 ExplicitGCInvokesConcurrent = true; | |
610 } | |
611 // Now expand the span and allocate the collection support structures | |
612 // (MUT, marking bit map etc.) to cover both generations subject to | |
613 // collection. | |
614 | |
615 // For use by dirty card to oop closures. | |
616 _cmsGen->cmsSpace()->set_collector(this); | |
617 | |
618 // Allocate MUT and marking bit map | |
619 { | |
620 MutexLockerEx x(_markBitMap.lock(), Mutex::_no_safepoint_check_flag); | |
621 if (!_markBitMap.allocate(_span)) { | |
622 warning("Failed to allocate CMS Bit Map"); | |
623 return; | |
624 } | |
625 assert(_markBitMap.covers(_span), "_markBitMap inconsistency?"); | |
626 } | |
627 { | |
628 _modUnionTable.allocate(_span); | |
629 assert(_modUnionTable.covers(_span), "_modUnionTable inconsistency?"); | |
630 } | |
631 | |
1284 | 632 if (!_markStack.allocate(MarkStackSize)) { |
0 | 633 warning("Failed to allocate CMS Marking Stack"); |
634 return; | |
635 } | |
636 | |
637 // Support for multi-threaded concurrent phases | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
638 if (CMSConcurrentMTEnabled) { |
1284 | 639 if (FLAG_IS_DEFAULT(ConcGCThreads)) { |
0 | 640 // just for now |
1284 | 641 FLAG_SET_DEFAULT(ConcGCThreads, (ParallelGCThreads + 3)/4); |
642 } | |
643 if (ConcGCThreads > 1) { | |
0 | 644 _conc_workers = new YieldingFlexibleWorkGang("Parallel CMS Threads", |
1284 | 645 ConcGCThreads, true); |
0 | 646 if (_conc_workers == NULL) { |
647 warning("GC/CMS: _conc_workers allocation failure: " | |
648 "forcing -CMSConcurrentMTEnabled"); | |
649 CMSConcurrentMTEnabled = false; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
650 } else { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
651 _conc_workers->initialize_workers(); |
0 | 652 } |
653 } else { | |
654 CMSConcurrentMTEnabled = false; | |
655 } | |
656 } | |
657 if (!CMSConcurrentMTEnabled) { | |
1284 | 658 ConcGCThreads = 0; |
0 | 659 } else { |
660 // Turn off CMSCleanOnEnter optimization temporarily for | |
661 // the MT case where it's not fixed yet; see 6178663. | |
662 CMSCleanOnEnter = false; | |
663 } | |
1284 | 664 assert((_conc_workers != NULL) == (ConcGCThreads > 1), |
0 | 665 "Inconsistency"); |
666 | |
667 // Parallel task queues; these are shared for the | |
668 // concurrent and stop-world phases of CMS, but | |
669 // are not shared with parallel scavenge (ParNew). | |
670 { | |
671 uint i; | |
1284 | 672 uint num_queues = (uint) MAX2(ParallelGCThreads, ConcGCThreads); |
0 | 673 |
674 if ((CMSParallelRemarkEnabled || CMSConcurrentMTEnabled | |
675 || ParallelRefProcEnabled) | |
676 && num_queues > 0) { | |
677 _task_queues = new OopTaskQueueSet(num_queues); | |
678 if (_task_queues == NULL) { | |
679 warning("task_queues allocation failure."); | |
680 return; | |
681 } | |
6197 | 682 _hash_seed = NEW_C_HEAP_ARRAY(int, num_queues, mtGC); |
0 | 683 if (_hash_seed == NULL) { |
684 warning("_hash_seed array allocation failure"); | |
685 return; | |
686 } | |
687 | |
1665 | 688 typedef Padded<OopTaskQueue> PaddedOopTaskQueue; |
0 | 689 for (i = 0; i < num_queues; i++) { |
1665 | 690 PaddedOopTaskQueue *q = new PaddedOopTaskQueue(); |
691 if (q == NULL) { | |
0 | 692 warning("work_queue allocation failure."); |
693 return; | |
694 } | |
1665 | 695 _task_queues->register_queue(i, q); |
0 | 696 } |
697 for (i = 0; i < num_queues; i++) { | |
698 _task_queues->queue(i)->initialize(); | |
699 _hash_seed[i] = 17; // copied from ParNew | |
700 } | |
701 } | |
702 } | |
703 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
704 _cmsGen ->init_initiating_occupancy(CMSInitiatingOccupancyFraction, CMSTriggerRatio); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
705 |
0 | 706 // Clip CMSBootstrapOccupancy between 0 and 100. |
10287
12f651e29f6b
6843347: Boundary values in some public GC options cause crashes
tschatzl
parents:
10244
diff
changeset
|
707 _bootstrap_occupancy = ((double)CMSBootstrapOccupancy)/(double)100; |
0 | 708 |
709 _full_gcs_since_conc_gc = 0; | |
710 | |
711 // Now tell CMS generations the identity of their collector | |
712 ConcurrentMarkSweepGeneration::set_collector(this); | |
713 | |
714 // Create & start a CMS thread for this CMS collector | |
715 _cmsThread = ConcurrentMarkSweepThread::start(this); | |
716 assert(cmsThread() != NULL, "CMS Thread should have been created"); | |
717 assert(cmsThread()->collector() == this, | |
718 "CMS Thread should refer to this gen"); | |
719 assert(CGC_lock != NULL, "Where's the CGC_lock?"); | |
720 | |
721 // Support for parallelizing young gen rescan | |
722 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
723 _young_gen = gch->prev_gen(_cmsGen); | |
724 if (gch->supports_inline_contig_alloc()) { | |
725 _top_addr = gch->top_addr(); | |
726 _end_addr = gch->end_addr(); | |
727 assert(_young_gen != NULL, "no _young_gen"); | |
728 _eden_chunk_index = 0; | |
729 _eden_chunk_capacity = (_young_gen->max_capacity()+CMSSamplingGrain)/CMSSamplingGrain; | |
6197 | 730 _eden_chunk_array = NEW_C_HEAP_ARRAY(HeapWord*, _eden_chunk_capacity, mtGC); |
0 | 731 if (_eden_chunk_array == NULL) { |
732 _eden_chunk_capacity = 0; | |
733 warning("GC/CMS: _eden_chunk_array allocation failure"); | |
734 } | |
735 } | |
736 assert(_eden_chunk_array != NULL || _eden_chunk_capacity == 0, "Error"); | |
737 | |
738 // Support for parallelizing survivor space rescan | |
11975 | 739 if ((CMSParallelRemarkEnabled && CMSParallelSurvivorRemarkEnabled) || CMSParallelInitialMarkEnabled) { |
1289
d47555d7aca8
6910182: CMS: assert(_cursor[j] == _survivor_plab_array[j].end(),"Ctl pt invariant")
jmasa
parents:
1284
diff
changeset
|
740 const size_t max_plab_samples = |
d47555d7aca8
6910182: CMS: assert(_cursor[j] == _survivor_plab_array[j].end(),"Ctl pt invariant")
jmasa
parents:
1284
diff
changeset
|
741 ((DefNewGeneration*)_young_gen)->max_survivor_size()/MinTLABSize; |
d47555d7aca8
6910182: CMS: assert(_cursor[j] == _survivor_plab_array[j].end(),"Ctl pt invariant")
jmasa
parents:
1284
diff
changeset
|
742 |
6197 | 743 _survivor_plab_array = NEW_C_HEAP_ARRAY(ChunkArray, ParallelGCThreads, mtGC); |
744 _survivor_chunk_array = NEW_C_HEAP_ARRAY(HeapWord*, 2*max_plab_samples, mtGC); | |
745 _cursor = NEW_C_HEAP_ARRAY(size_t, ParallelGCThreads, mtGC); | |
0 | 746 if (_survivor_plab_array == NULL || _survivor_chunk_array == NULL |
747 || _cursor == NULL) { | |
748 warning("Failed to allocate survivor plab/chunk array"); | |
749 if (_survivor_plab_array != NULL) { | |
6197 | 750 FREE_C_HEAP_ARRAY(ChunkArray, _survivor_plab_array, mtGC); |
0 | 751 _survivor_plab_array = NULL; |
752 } | |
753 if (_survivor_chunk_array != NULL) { | |
6197 | 754 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_chunk_array, mtGC); |
0 | 755 _survivor_chunk_array = NULL; |
756 } | |
757 if (_cursor != NULL) { | |
6197 | 758 FREE_C_HEAP_ARRAY(size_t, _cursor, mtGC); |
0 | 759 _cursor = NULL; |
760 } | |
761 } else { | |
762 _survivor_chunk_capacity = 2*max_plab_samples; | |
763 for (uint i = 0; i < ParallelGCThreads; i++) { | |
6197 | 764 HeapWord** vec = NEW_C_HEAP_ARRAY(HeapWord*, max_plab_samples, mtGC); |
0 | 765 if (vec == NULL) { |
766 warning("Failed to allocate survivor plab array"); | |
767 for (int j = i; j > 0; j--) { | |
6197 | 768 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_plab_array[j-1].array(), mtGC); |
0 | 769 } |
6197 | 770 FREE_C_HEAP_ARRAY(ChunkArray, _survivor_plab_array, mtGC); |
771 FREE_C_HEAP_ARRAY(HeapWord*, _survivor_chunk_array, mtGC); | |
0 | 772 _survivor_plab_array = NULL; |
773 _survivor_chunk_array = NULL; | |
774 _survivor_chunk_capacity = 0; | |
775 break; | |
776 } else { | |
777 ChunkArray* cur = | |
778 ::new (&_survivor_plab_array[i]) ChunkArray(vec, | |
779 max_plab_samples); | |
780 assert(cur->end() == 0, "Should be 0"); | |
781 assert(cur->array() == vec, "Should be vec"); | |
782 assert(cur->capacity() == max_plab_samples, "Error"); | |
783 } | |
784 } | |
785 } | |
786 } | |
787 assert( ( _survivor_plab_array != NULL | |
788 && _survivor_chunk_array != NULL) | |
789 || ( _survivor_chunk_capacity == 0 | |
790 && _survivor_chunk_index == 0), | |
791 "Error"); | |
792 | |
793 NOT_PRODUCT(_overflow_counter = CMSMarkStackOverflowInterval;) | |
794 _gc_counters = new CollectorCounters("CMS", 1); | |
795 _completed_initialization = true; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
796 _inter_sweep_timer.start(); // start of time |
0 | 797 } |
798 | |
799 const char* ConcurrentMarkSweepGeneration::name() const { | |
800 return "concurrent mark-sweep generation"; | |
801 } | |
802 void ConcurrentMarkSweepGeneration::update_counters() { | |
803 if (UsePerfData) { | |
804 _space_counters->update_all(); | |
805 _gen_counters->update_all(); | |
806 } | |
807 } | |
808 | |
809 // this is an optimized version of update_counters(). it takes the | |
810 // used value as a parameter rather than computing it. | |
811 // | |
812 void ConcurrentMarkSweepGeneration::update_counters(size_t used) { | |
813 if (UsePerfData) { | |
814 _space_counters->update_used(used); | |
815 _space_counters->update_capacity(); | |
816 _gen_counters->update_all(); | |
817 } | |
818 } | |
819 | |
820 void ConcurrentMarkSweepGeneration::print() const { | |
821 Generation::print(); | |
822 cmsSpace()->print(); | |
823 } | |
824 | |
825 #ifndef PRODUCT | |
826 void ConcurrentMarkSweepGeneration::print_statistics() { | |
827 cmsSpace()->printFLCensus(0); | |
828 } | |
829 #endif | |
830 | |
831 void ConcurrentMarkSweepGeneration::printOccupancy(const char *s) { | |
832 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
833 if (PrintGCDetails) { | |
834 if (Verbose) { | |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6885
diff
changeset
|
835 gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"("SIZE_FORMAT")]", |
0 | 836 level(), short_name(), s, used(), capacity()); |
837 } else { | |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6885
diff
changeset
|
838 gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"K("SIZE_FORMAT"K)]", |
0 | 839 level(), short_name(), s, used() / K, capacity() / K); |
840 } | |
841 } | |
842 if (Verbose) { | |
843 gclog_or_tty->print(" "SIZE_FORMAT"("SIZE_FORMAT")", | |
844 gch->used(), gch->capacity()); | |
845 } else { | |
846 gclog_or_tty->print(" "SIZE_FORMAT"K("SIZE_FORMAT"K)", | |
847 gch->used() / K, gch->capacity() / K); | |
848 } | |
849 } | |
850 | |
851 size_t | |
852 ConcurrentMarkSweepGeneration::contiguous_available() const { | |
853 // dld proposes an improvement in precision here. If the committed | |
854 // part of the space ends in a free block we should add that to | |
855 // uncommitted size in the calculation below. Will make this | |
856 // change later, staying with the approximation below for the | |
857 // time being. -- ysr. | |
858 return MAX2(_virtual_space.uncommitted_size(), unsafe_max_alloc_nogc()); | |
859 } | |
860 | |
861 size_t | |
862 ConcurrentMarkSweepGeneration::unsafe_max_alloc_nogc() const { | |
863 return _cmsSpace->max_alloc_in_words() * HeapWordSize; | |
864 } | |
865 | |
866 size_t ConcurrentMarkSweepGeneration::max_available() const { | |
867 return free() + _virtual_space.uncommitted_size(); | |
868 } | |
869 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
870 bool ConcurrentMarkSweepGeneration::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const { |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
871 size_t available = max_available(); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
872 size_t av_promo = (size_t)gc_stats()->avg_promoted()->padded_average(); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
873 bool res = (available >= av_promo) || (available >= max_promotion_in_bytes); |
1994
6cd6d394f280
7001033: assert(gch->gc_cause() == GCCause::_scavenge_alot || !gch->incremental_collection_failed())
ysr
parents:
1972
diff
changeset
|
874 if (Verbose && PrintGCDetails) { |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
875 gclog_or_tty->print_cr( |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
876 "CMS: promo attempt is%s safe: available("SIZE_FORMAT") %s av_promo("SIZE_FORMAT")," |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
877 "max_promo("SIZE_FORMAT")", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
878 res? "":" not", available, res? ">=":"<", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
879 av_promo, max_promotion_in_bytes); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
880 } |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
881 return res; |
0 | 882 } |
883 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
884 // At a promotion failure dump information on block layout in heap |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
885 // (cms old generation). |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
886 void ConcurrentMarkSweepGeneration::promotion_failure_occurred() { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
887 if (CMSDumpAtPromotionFailure) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
888 cmsSpace()->dump_at_safepoint_with_locks(collector(), gclog_or_tty); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
889 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
890 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
891 |
0 | 892 CompactibleSpace* |
893 ConcurrentMarkSweepGeneration::first_compaction_space() const { | |
894 return _cmsSpace; | |
895 } | |
896 | |
897 void ConcurrentMarkSweepGeneration::reset_after_compaction() { | |
898 // Clear the promotion information. These pointers can be adjusted | |
899 // along with all the other pointers into the heap but | |
900 // compaction is expected to be a rare event with | |
901 // a heap using cms so don't do it without seeing the need. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
902 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 903 for (uint i = 0; i < ParallelGCThreads; i++) { |
904 _par_gc_thread_states[i]->promo.reset(); | |
905 } | |
906 } | |
907 } | |
908 | |
909 void ConcurrentMarkSweepGeneration::space_iterate(SpaceClosure* blk, bool usedOnly) { | |
910 blk->do_space(_cmsSpace); | |
911 } | |
912 | |
913 void ConcurrentMarkSweepGeneration::compute_new_size() { | |
914 assert_locked_or_safepoint(Heap_lock); | |
915 | |
916 // If incremental collection failed, we just want to expand | |
917 // to the limit. | |
918 if (incremental_collection_failed()) { | |
919 clear_incremental_collection_failed(); | |
920 grow_to_reserved(); | |
921 return; | |
922 } | |
923 | |
10243
a9d568b7df60
8013032: CMS: assert(used() == used_after_gc && used_after_gc <= capacity()) failed: used: 0 used_after_gc: 292080 capacity: 1431699456
jmasa
parents:
10188
diff
changeset
|
924 // The heap has been compacted but not reset yet. |
a9d568b7df60
8013032: CMS: assert(used() == used_after_gc && used_after_gc <= capacity()) failed: used: 0 used_after_gc: 292080 capacity: 1431699456
jmasa
parents:
10188
diff
changeset
|
925 // Any metric such as free() or used() will be incorrect. |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
926 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
927 CardGeneration::compute_new_size(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
928 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
929 // Reset again after a possible resizing |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
930 if (did_compact()) { |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
931 cmsSpace()->reset_after_compaction(); |
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
932 } |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
933 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
934 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
935 void ConcurrentMarkSweepGeneration::compute_new_size_free_list() { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
936 assert_locked_or_safepoint(Heap_lock); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
937 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
938 // If incremental collection failed, we just want to expand |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
939 // to the limit. |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
940 if (incremental_collection_failed()) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
941 clear_incremental_collection_failed(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
942 grow_to_reserved(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
943 return; |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
944 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
945 |
0 | 946 double free_percentage = ((double) free()) / capacity(); |
947 double desired_free_percentage = (double) MinHeapFreeRatio / 100; | |
948 double maximum_free_percentage = (double) MaxHeapFreeRatio / 100; | |
949 | |
950 // compute expansion delta needed for reaching desired free percentage | |
951 if (free_percentage < desired_free_percentage) { | |
952 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); | |
953 assert(desired_capacity >= capacity(), "invalid expansion size"); | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
954 size_t expand_bytes = MAX2(desired_capacity - capacity(), MinHeapDeltaBytes); |
0 | 955 if (PrintGCDetails && Verbose) { |
956 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); | |
957 gclog_or_tty->print_cr("\nFrom compute_new_size: "); | |
958 gclog_or_tty->print_cr(" Free fraction %f", free_percentage); | |
959 gclog_or_tty->print_cr(" Desired free fraction %f", | |
960 desired_free_percentage); | |
961 gclog_or_tty->print_cr(" Maximum free fraction %f", | |
962 maximum_free_percentage); | |
963 gclog_or_tty->print_cr(" Capactiy "SIZE_FORMAT, capacity()/1000); | |
964 gclog_or_tty->print_cr(" Desired capacity "SIZE_FORMAT, | |
965 desired_capacity/1000); | |
966 int prev_level = level() - 1; | |
967 if (prev_level >= 0) { | |
968 size_t prev_size = 0; | |
969 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
970 Generation* prev_gen = gch->_gens[prev_level]; | |
971 prev_size = prev_gen->capacity(); | |
972 gclog_or_tty->print_cr(" Younger gen size "SIZE_FORMAT, | |
973 prev_size/1000); | |
974 } | |
975 gclog_or_tty->print_cr(" unsafe_max_alloc_nogc "SIZE_FORMAT, | |
976 unsafe_max_alloc_nogc()/1000); | |
977 gclog_or_tty->print_cr(" contiguous available "SIZE_FORMAT, | |
978 contiguous_available()/1000); | |
979 gclog_or_tty->print_cr(" Expand by "SIZE_FORMAT" (bytes)", | |
980 expand_bytes); | |
981 } | |
982 // safe if expansion fails | |
983 expand(expand_bytes, 0, CMSExpansionCause::_satisfy_free_ratio); | |
984 if (PrintGCDetails && Verbose) { | |
985 gclog_or_tty->print_cr(" Expanded free fraction %f", | |
986 ((double) free()) / capacity()); | |
987 } | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
988 } else { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
989 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage)); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
990 assert(desired_capacity <= capacity(), "invalid expansion size"); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
991 size_t shrink_bytes = capacity() - desired_capacity; |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
992 // Don't shrink unless the delta is greater than the minimum shrink we want |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
993 if (shrink_bytes >= MinHeapDeltaBytes) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
994 shrink_free_list_by(shrink_bytes); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
995 } |
0 | 996 } |
997 } | |
998 | |
999 Mutex* ConcurrentMarkSweepGeneration::freelistLock() const { | |
1000 return cmsSpace()->freelistLock(); | |
1001 } | |
1002 | |
1003 HeapWord* ConcurrentMarkSweepGeneration::allocate(size_t size, | |
1004 bool tlab) { | |
1005 CMSSynchronousYieldRequest yr; | |
1006 MutexLockerEx x(freelistLock(), | |
1007 Mutex::_no_safepoint_check_flag); | |
1008 return have_lock_and_allocate(size, tlab); | |
1009 } | |
1010 | |
1011 HeapWord* ConcurrentMarkSweepGeneration::have_lock_and_allocate(size_t size, | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1012 bool tlab /* ignored */) { |
0 | 1013 assert_lock_strong(freelistLock()); |
1014 size_t adjustedSize = CompactibleFreeListSpace::adjustObjectSize(size); | |
1015 HeapWord* res = cmsSpace()->allocate(adjustedSize); | |
1016 // Allocate the object live (grey) if the background collector has | |
1017 // started marking. This is necessary because the marker may | |
1018 // have passed this address and consequently this object will | |
1019 // not otherwise be greyed and would be incorrectly swept up. | |
1020 // Note that if this object contains references, the writing | |
1021 // of those references will dirty the card containing this object | |
1022 // allowing the object to be blackened (and its references scanned) | |
1023 // either during a preclean phase or at the final checkpoint. | |
1024 if (res != NULL) { | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1025 // We may block here with an uninitialized object with |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1026 // its mark-bit or P-bits not yet set. Such objects need |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1027 // to be safely navigable by block_start(). |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1028 assert(oop(res)->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1029 assert(!((FreeChunk*)res)->is_free(), "Error, block will look free but show wrong size"); |
0 | 1030 collector()->direct_allocated(res, adjustedSize); |
1031 _direct_allocated_words += adjustedSize; | |
1032 // allocation counters | |
1033 NOT_PRODUCT( | |
1034 _numObjectsAllocated++; | |
1035 _numWordsAllocated += (int)adjustedSize; | |
1036 ) | |
1037 } | |
1038 return res; | |
1039 } | |
1040 | |
1041 // In the case of direct allocation by mutators in a generation that | |
1042 // is being concurrently collected, the object must be allocated | |
1043 // live (grey) if the background collector has started marking. | |
1044 // This is necessary because the marker may | |
1045 // have passed this address and consequently this object will | |
1046 // not otherwise be greyed and would be incorrectly swept up. | |
1047 // Note that if this object contains references, the writing | |
1048 // of those references will dirty the card containing this object | |
1049 // allowing the object to be blackened (and its references scanned) | |
1050 // either during a preclean phase or at the final checkpoint. | |
1051 void CMSCollector::direct_allocated(HeapWord* start, size_t size) { | |
1052 assert(_markBitMap.covers(start, size), "Out of bounds"); | |
1053 if (_collectorState >= Marking) { | |
1054 MutexLockerEx y(_markBitMap.lock(), | |
1055 Mutex::_no_safepoint_check_flag); | |
1056 // [see comments preceding SweepClosure::do_blk() below for details] | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1057 // |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1058 // Can the P-bits be deleted now? JJJ |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1059 // |
0 | 1060 // 1. need to mark the object as live so it isn't collected |
1061 // 2. need to mark the 2nd bit to indicate the object may be uninitialized | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1062 // 3. need to mark the end of the object so marking, precleaning or sweeping |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1063 // can skip over uninitialized or unparsable objects. An allocated |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1064 // object is considered uninitialized for our purposes as long as |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1065 // its klass word is NULL. All old gen objects are parsable |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1066 // as soon as they are initialized.) |
0 | 1067 _markBitMap.mark(start); // object is live |
1068 _markBitMap.mark(start + 1); // object is potentially uninitialized? | |
1069 _markBitMap.mark(start + size - 1); | |
1070 // mark end of object | |
1071 } | |
1072 // check that oop looks uninitialized | |
187 | 1073 assert(oop(start)->klass_or_null() == NULL, "_klass should be NULL"); |
0 | 1074 } |
1075 | |
1076 void CMSCollector::promoted(bool par, HeapWord* start, | |
1077 bool is_obj_array, size_t obj_size) { | |
1078 assert(_markBitMap.covers(start), "Out of bounds"); | |
1079 // See comment in direct_allocated() about when objects should | |
1080 // be allocated live. | |
1081 if (_collectorState >= Marking) { | |
1082 // we already hold the marking bit map lock, taken in | |
1083 // the prologue | |
1084 if (par) { | |
1085 _markBitMap.par_mark(start); | |
1086 } else { | |
1087 _markBitMap.mark(start); | |
1088 } | |
1089 // We don't need to mark the object as uninitialized (as | |
1090 // in direct_allocated above) because this is being done with the | |
1091 // world stopped and the object will be initialized by the | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1092 // time the marking, precleaning or sweeping get to look at it. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1093 // But see the code for copying objects into the CMS generation, |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1094 // where we need to ensure that concurrent readers of the |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1095 // block offset table are able to safely navigate a block that |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1096 // is in flux from being free to being allocated (and in |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1097 // transition while being copied into) and subsequently |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1098 // becoming a bona-fide object when the copy/promotion is complete. |
0 | 1099 assert(SafepointSynchronize::is_at_safepoint(), |
1100 "expect promotion only at safepoints"); | |
1101 | |
1102 if (_collectorState < Sweeping) { | |
1103 // Mark the appropriate cards in the modUnionTable, so that | |
1104 // this object gets scanned before the sweep. If this is | |
1105 // not done, CMS generation references in the object might | |
1106 // not get marked. | |
1107 // For the case of arrays, which are otherwise precisely | |
1108 // marked, we need to dirty the entire array, not just its head. | |
1109 if (is_obj_array) { | |
1110 // The [par_]mark_range() method expects mr.end() below to | |
1111 // be aligned to the granularity of a bit's representation | |
1112 // in the heap. In the case of the MUT below, that's a | |
1113 // card size. | |
1114 MemRegion mr(start, | |
1115 (HeapWord*)round_to((intptr_t)(start + obj_size), | |
1116 CardTableModRefBS::card_size /* bytes */)); | |
1117 if (par) { | |
1118 _modUnionTable.par_mark_range(mr); | |
1119 } else { | |
1120 _modUnionTable.mark_range(mr); | |
1121 } | |
1122 } else { // not an obj array; we can just mark the head | |
1123 if (par) { | |
1124 _modUnionTable.par_mark(start); | |
1125 } else { | |
1126 _modUnionTable.mark(start); | |
1127 } | |
1128 } | |
1129 } | |
1130 } | |
1131 } | |
1132 | |
1133 static inline size_t percent_of_space(Space* space, HeapWord* addr) | |
1134 { | |
1135 size_t delta = pointer_delta(addr, space->bottom()); | |
1136 return (size_t)(delta * 100.0 / (space->capacity() / HeapWordSize)); | |
1137 } | |
1138 | |
1139 void CMSCollector::icms_update_allocation_limits() | |
1140 { | |
1141 Generation* gen0 = GenCollectedHeap::heap()->get_gen(0); | |
1142 EdenSpace* eden = gen0->as_DefNewGeneration()->eden(); | |
1143 | |
1144 const unsigned int duty_cycle = stats().icms_update_duty_cycle(); | |
1145 if (CMSTraceIncrementalPacing) { | |
1146 stats().print(); | |
1147 } | |
1148 | |
1149 assert(duty_cycle <= 100, "invalid duty cycle"); | |
1150 if (duty_cycle != 0) { | |
1151 // The duty_cycle is a percentage between 0 and 100; convert to words and | |
1152 // then compute the offset from the endpoints of the space. | |
1153 size_t free_words = eden->free() / HeapWordSize; | |
1154 double free_words_dbl = (double)free_words; | |
1155 size_t duty_cycle_words = (size_t)(free_words_dbl * duty_cycle / 100.0); | |
1156 size_t offset_words = (free_words - duty_cycle_words) / 2; | |
1157 | |
1158 _icms_start_limit = eden->top() + offset_words; | |
1159 _icms_stop_limit = eden->end() - offset_words; | |
1160 | |
1161 // The limits may be adjusted (shifted to the right) by | |
1162 // CMSIncrementalOffset, to allow the application more mutator time after a | |
1163 // young gen gc (when all mutators were stopped) and before CMS starts and | |
1164 // takes away one or more cpus. | |
1165 if (CMSIncrementalOffset != 0) { | |
1166 double adjustment_dbl = free_words_dbl * CMSIncrementalOffset / 100.0; | |
1167 size_t adjustment = (size_t)adjustment_dbl; | |
1168 HeapWord* tmp_stop = _icms_stop_limit + adjustment; | |
1169 if (tmp_stop > _icms_stop_limit && tmp_stop < eden->end()) { | |
1170 _icms_start_limit += adjustment; | |
1171 _icms_stop_limit = tmp_stop; | |
1172 } | |
1173 } | |
1174 } | |
1175 if (duty_cycle == 0 || (_icms_start_limit == _icms_stop_limit)) { | |
1176 _icms_start_limit = _icms_stop_limit = eden->end(); | |
1177 } | |
1178 | |
1179 // Install the new start limit. | |
1180 eden->set_soft_end(_icms_start_limit); | |
1181 | |
1182 if (CMSTraceIncrementalMode) { | |
1183 gclog_or_tty->print(" icms alloc limits: " | |
1184 PTR_FORMAT "," PTR_FORMAT | |
1185 " (" SIZE_FORMAT "%%," SIZE_FORMAT "%%) ", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1186 p2i(_icms_start_limit), p2i(_icms_stop_limit), |
0 | 1187 percent_of_space(eden, _icms_start_limit), |
1188 percent_of_space(eden, _icms_stop_limit)); | |
1189 if (Verbose) { | |
1190 gclog_or_tty->print("eden: "); | |
1191 eden->print_on(gclog_or_tty); | |
1192 } | |
1193 } | |
1194 } | |
1195 | |
1196 // Any changes here should try to maintain the invariant | |
1197 // that if this method is called with _icms_start_limit | |
1198 // and _icms_stop_limit both NULL, then it should return NULL | |
1199 // and not notify the icms thread. | |
1200 HeapWord* | |
1201 CMSCollector::allocation_limit_reached(Space* space, HeapWord* top, | |
1202 size_t word_size) | |
1203 { | |
1204 // A start_limit equal to end() means the duty cycle is 0, so treat that as a | |
1205 // nop. | |
1206 if (CMSIncrementalMode && _icms_start_limit != space->end()) { | |
1207 if (top <= _icms_start_limit) { | |
1208 if (CMSTraceIncrementalMode) { | |
1209 space->print_on(gclog_or_tty); | |
1210 gclog_or_tty->stamp(); | |
1211 gclog_or_tty->print_cr(" start limit top=" PTR_FORMAT | |
1212 ", new limit=" PTR_FORMAT | |
1213 " (" SIZE_FORMAT "%%)", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1214 p2i(top), p2i(_icms_stop_limit), |
0 | 1215 percent_of_space(space, _icms_stop_limit)); |
1216 } | |
1217 ConcurrentMarkSweepThread::start_icms(); | |
1218 assert(top < _icms_stop_limit, "Tautology"); | |
1219 if (word_size < pointer_delta(_icms_stop_limit, top)) { | |
1220 return _icms_stop_limit; | |
1221 } | |
1222 | |
1223 // The allocation will cross both the _start and _stop limits, so do the | |
1224 // stop notification also and return end(). | |
1225 if (CMSTraceIncrementalMode) { | |
1226 space->print_on(gclog_or_tty); | |
1227 gclog_or_tty->stamp(); | |
1228 gclog_or_tty->print_cr(" +stop limit top=" PTR_FORMAT | |
1229 ", new limit=" PTR_FORMAT | |
1230 " (" SIZE_FORMAT "%%)", | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1231 p2i(top), p2i(space->end()), |
0 | 1232 percent_of_space(space, space->end())); |
1233 } | |
1234 ConcurrentMarkSweepThread::stop_icms(); | |
1235 return space->end(); | |
1236 } | |
1237 | |
1238 if (top <= _icms_stop_limit) { | |
1239 if (CMSTraceIncrementalMode) { | |
1240 space->print_on(gclog_or_tty); | |
1241 gclog_or_tty->stamp(); | |
1242 gclog_or_tty->print_cr(" stop limit top=" PTR_FORMAT | |
1243 ", new limit=" PTR_FORMAT | |
1244 " (" SIZE_FORMAT "%%)", | |
1245 top, space->end(), | |
1246 percent_of_space(space, space->end())); | |
1247 } | |
1248 ConcurrentMarkSweepThread::stop_icms(); | |
1249 return space->end(); | |
1250 } | |
1251 | |
1252 if (CMSTraceIncrementalMode) { | |
1253 space->print_on(gclog_or_tty); | |
1254 gclog_or_tty->stamp(); | |
1255 gclog_or_tty->print_cr(" end limit top=" PTR_FORMAT | |
1256 ", new limit=" PTR_FORMAT, | |
1257 top, NULL); | |
1258 } | |
1259 } | |
1260 | |
1261 return NULL; | |
1262 } | |
1263 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1264 oop ConcurrentMarkSweepGeneration::promote(oop obj, size_t obj_size) { |
0 | 1265 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
1266 // allocate, copy and if necessary update promoinfo -- | |
1267 // delegate to underlying space. | |
1268 assert_lock_strong(freelistLock()); | |
1269 | |
1270 #ifndef PRODUCT | |
1271 if (Universe::heap()->promotion_should_fail()) { | |
1272 return NULL; | |
1273 } | |
1274 #endif // #ifndef PRODUCT | |
1275 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1276 oop res = _cmsSpace->promote(obj, obj_size); |
0 | 1277 if (res == NULL) { |
1278 // expand and retry | |
1279 size_t s = _cmsSpace->expansionSpaceRequired(obj_size); // HeapWords | |
1280 expand(s*HeapWordSize, MinHeapDeltaBytes, | |
1281 CMSExpansionCause::_satisfy_promotion); | |
1282 // Since there's currently no next generation, we don't try to promote | |
1283 // into a more senior generation. | |
1284 assert(next_gen() == NULL, "assumption, based upon which no attempt " | |
1285 "is made to pass on a possibly failing " | |
1286 "promotion to next generation"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
1287 res = _cmsSpace->promote(obj, obj_size); |
0 | 1288 } |
1289 if (res != NULL) { | |
1290 // See comment in allocate() about when objects should | |
1291 // be allocated live. | |
1292 assert(obj->is_oop(), "Will dereference klass pointer below"); | |
1293 collector()->promoted(false, // Not parallel | |
1294 (HeapWord*)res, obj->is_objArray(), obj_size); | |
1295 // promotion counters | |
1296 NOT_PRODUCT( | |
1297 _numObjectsPromoted++; | |
1298 _numWordsPromoted += | |
1299 (int)(CompactibleFreeListSpace::adjustObjectSize(obj->size())); | |
1300 ) | |
1301 } | |
1302 return res; | |
1303 } | |
1304 | |
1305 | |
1306 HeapWord* | |
1307 ConcurrentMarkSweepGeneration::allocation_limit_reached(Space* space, | |
1308 HeapWord* top, | |
1309 size_t word_sz) | |
1310 { | |
1311 return collector()->allocation_limit_reached(space, top, word_sz); | |
1312 } | |
1313 | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1314 // IMPORTANT: Notes on object size recognition in CMS. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1315 // --------------------------------------------------- |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1316 // A block of storage in the CMS generation is always in |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1317 // one of three states. A free block (FREE), an allocated |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1318 // object (OBJECT) whose size() method reports the correct size, |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1319 // and an intermediate state (TRANSIENT) in which its size cannot |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1320 // be accurately determined. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1321 // STATE IDENTIFICATION: (32 bit and 64 bit w/o COOPS) |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1322 // ----------------------------------------------------- |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1323 // FREE: klass_word & 1 == 1; mark_word holds block size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1324 // |
1777
179464550c7d
6983930: CMS: Various small cleanups ca September 2010
ysr
parents:
1720
diff
changeset
|
1325 // OBJECT: klass_word installed; klass_word != 0 && klass_word & 1 == 0; |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1326 // obj->size() computes correct size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1327 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1328 // TRANSIENT: klass_word == 0; size is indeterminate until we become an OBJECT |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1329 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1330 // STATE IDENTIFICATION: (64 bit+COOPS) |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1331 // ------------------------------------ |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1332 // FREE: mark_word & CMS_FREE_BIT == 1; mark_word & ~CMS_FREE_BIT gives block_size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1333 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1334 // OBJECT: klass_word installed; klass_word != 0; |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1335 // obj->size() computes correct size |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1336 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1337 // TRANSIENT: klass_word == 0; size is indeterminate until we become an OBJECT |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1338 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1339 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1340 // STATE TRANSITION DIAGRAM |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1341 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1342 // mut / parnew mut / parnew |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1343 // FREE --------------------> TRANSIENT ---------------------> OBJECT --| |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1344 // ^ | |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1345 // |------------------------ DEAD <------------------------------------| |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1346 // sweep mut |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1347 // |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1348 // While a block is in TRANSIENT state its size cannot be determined |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1349 // so readers will either need to come back later or stall until |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1350 // the size can be determined. Note that for the case of direct |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1351 // allocation, P-bits, when available, may be used to determine the |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1352 // size of an object that may not yet have been initialized. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1353 |
0 | 1354 // Things to support parallel young-gen collection. |
1355 oop | |
1356 ConcurrentMarkSweepGeneration::par_promote(int thread_num, | |
1357 oop old, markOop m, | |
1358 size_t word_sz) { | |
1359 #ifndef PRODUCT | |
1360 if (Universe::heap()->promotion_should_fail()) { | |
1361 return NULL; | |
1362 } | |
1363 #endif // #ifndef PRODUCT | |
1364 | |
1365 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1366 PromotionInfo* promoInfo = &ps->promo; | |
1367 // if we are tracking promotions, then first ensure space for | |
1368 // promotion (including spooling space for saving header if necessary). | |
1369 // then allocate and copy, then track promoted info if needed. | |
1370 // When tracking (see PromotionInfo::track()), the mark word may | |
1371 // be displaced and in this case restoration of the mark word | |
1372 // occurs in the (oop_since_save_marks_)iterate phase. | |
1373 if (promoInfo->tracking() && !promoInfo->ensure_spooling_space()) { | |
1374 // Out of space for allocating spooling buffers; | |
1375 // try expanding and allocating spooling buffers. | |
1376 if (!expand_and_ensure_spooling_space(promoInfo)) { | |
1377 return NULL; | |
1378 } | |
1379 } | |
1380 assert(promoInfo->has_spooling_space(), "Control point invariant"); | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1381 const size_t alloc_sz = CompactibleFreeListSpace::adjustObjectSize(word_sz); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1382 HeapWord* obj_ptr = ps->lab.alloc(alloc_sz); |
0 | 1383 if (obj_ptr == NULL) { |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1384 obj_ptr = expand_and_par_lab_allocate(ps, alloc_sz); |
0 | 1385 if (obj_ptr == NULL) { |
1386 return NULL; | |
1387 } | |
1388 } | |
1389 oop obj = oop(obj_ptr); | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1390 OrderAccess::storestore(); |
187 | 1391 assert(obj->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1392 assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size"); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1393 // IMPORTANT: See note on object initialization for CMS above. |
0 | 1394 // Otherwise, copy the object. Here we must be careful to insert the |
1395 // klass pointer last, since this marks the block as an allocated object. | |
187 | 1396 // Except with compressed oops it's the mark word. |
0 | 1397 HeapWord* old_ptr = (HeapWord*)old; |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1398 // Restore the mark word copied above. |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1399 obj->set_mark(m); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1400 assert(obj->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1401 assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size"); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1402 OrderAccess::storestore(); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1403 |
12226
7944aba7ba41
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
12112
diff
changeset
|
1404 if (UseCompressedClassPointers) { |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1405 // Copy gap missed by (aligned) header size calculation below |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1406 obj->set_klass_gap(old->klass_gap()); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1407 } |
0 | 1408 if (word_sz > (size_t)oopDesc::header_size()) { |
1409 Copy::aligned_disjoint_words(old_ptr + oopDesc::header_size(), | |
1410 obj_ptr + oopDesc::header_size(), | |
1411 word_sz - oopDesc::header_size()); | |
1412 } | |
187 | 1413 |
0 | 1414 // Now we can track the promoted object, if necessary. We take care |
1521 | 1415 // to delay the transition from uninitialized to full object |
0 | 1416 // (i.e., insertion of klass pointer) until after, so that it |
1417 // atomically becomes a promoted object. | |
1418 if (promoInfo->tracking()) { | |
1419 promoInfo->track((PromotedObject*)obj, old->klass()); | |
1420 } | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1421 assert(obj->klass_or_null() == NULL, "Object should be uninitialized here."); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
1422 assert(!((FreeChunk*)obj_ptr)->is_free(), "Error, block will look free but show wrong size"); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1423 assert(old->is_oop(), "Will use and dereference old klass ptr below"); |
187 | 1424 |
1425 // Finally, install the klass pointer (this should be volatile). | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1426 OrderAccess::storestore(); |
0 | 1427 obj->set_klass(old->klass()); |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1428 // We should now be able to calculate the right size for this object |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1429 assert(obj->is_oop() && obj->size() == (int)word_sz, "Error, incorrect size computed for promoted object"); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1430 |
0 | 1431 collector()->promoted(true, // parallel |
1432 obj_ptr, old->is_objArray(), word_sz); | |
1433 | |
1434 NOT_PRODUCT( | |
1716
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1435 Atomic::inc_ptr(&_numObjectsPromoted); |
be3f9c242c9d
6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents:
1704
diff
changeset
|
1436 Atomic::add_ptr(alloc_sz, &_numWordsPromoted); |
0 | 1437 ) |
1438 | |
1439 return obj; | |
1440 } | |
1441 | |
1442 void | |
1443 ConcurrentMarkSweepGeneration:: | |
1444 par_promote_alloc_undo(int thread_num, | |
1445 HeapWord* obj, size_t word_sz) { | |
1446 // CMS does not support promotion undo. | |
1447 ShouldNotReachHere(); | |
1448 } | |
1449 | |
1450 void | |
1451 ConcurrentMarkSweepGeneration:: | |
1452 par_promote_alloc_done(int thread_num) { | |
1453 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
1454 ps->lab.retire(thread_num); |
0 | 1455 } |
1456 | |
1457 void | |
1458 ConcurrentMarkSweepGeneration:: | |
1459 par_oop_since_save_marks_iterate_done(int thread_num) { | |
1460 CMSParGCThreadState* ps = _par_gc_thread_states[thread_num]; | |
1461 ParScanWithoutBarrierClosure* dummy_cl = NULL; | |
1462 ps->promo.promoted_oops_iterate_nv(dummy_cl); | |
1463 } | |
1464 | |
1465 bool ConcurrentMarkSweepGeneration::should_collect(bool full, | |
1466 size_t size, | |
1467 bool tlab) | |
1468 { | |
1469 // We allow a STW collection only if a full | |
1470 // collection was requested. | |
1471 return full || should_allocate(size, tlab); // FIX ME !!! | |
1472 // This and promotion failure handling are connected at the | |
1473 // hip and should be fixed by untying them. | |
1474 } | |
1475 | |
1476 bool CMSCollector::shouldConcurrentCollect() { | |
1477 if (_full_gc_requested) { | |
1478 if (Verbose && PrintGCDetails) { | |
1479 gclog_or_tty->print_cr("CMSCollector: collect because of explicit " | |
1520
bb843ebc7c55
6919638: CMS: ExplicitGCInvokesConcurrent misinteracts with gc locker
ysr
parents:
1518
diff
changeset
|
1480 " gc request (or gc_locker)"); |
0 | 1481 } |
1482 return true; | |
1483 } | |
1484 | |
1485 // For debugging purposes, change the type of collection. | |
1486 // If the rotation is not on the concurrent collection | |
1487 // type, don't start a concurrent collection. | |
1488 NOT_PRODUCT( | |
1489 if (RotateCMSCollectionTypes && | |
1490 (_cmsGen->debug_collection_type() != | |
1491 ConcurrentMarkSweepGeneration::Concurrent_collection_type)) { | |
1492 assert(_cmsGen->debug_collection_type() != | |
1493 ConcurrentMarkSweepGeneration::Unknown_collection_type, | |
1494 "Bad cms collection type"); | |
1495 return false; | |
1496 } | |
1497 ) | |
1498 | |
1499 FreelistLocker x(this); | |
1500 // ------------------------------------------------------------------ | |
1501 // Print out lots of information which affects the initiation of | |
1502 // a collection. | |
1503 if (PrintCMSInitiationStatistics && stats().valid()) { | |
1504 gclog_or_tty->print("CMSCollector shouldConcurrentCollect: "); | |
1505 gclog_or_tty->stamp(); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
1506 gclog_or_tty->cr(); |
0 | 1507 stats().print_on(gclog_or_tty); |
1508 gclog_or_tty->print_cr("time_until_cms_gen_full %3.7f", | |
1509 stats().time_until_cms_gen_full()); | |
1510 gclog_or_tty->print_cr("free="SIZE_FORMAT, _cmsGen->free()); | |
1511 gclog_or_tty->print_cr("contiguous_available="SIZE_FORMAT, | |
1512 _cmsGen->contiguous_available()); | |
1513 gclog_or_tty->print_cr("promotion_rate=%g", stats().promotion_rate()); | |
1514 gclog_or_tty->print_cr("cms_allocation_rate=%g", stats().cms_allocation_rate()); | |
1515 gclog_or_tty->print_cr("occupancy=%3.7f", _cmsGen->occupancy()); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1516 gclog_or_tty->print_cr("initiatingOccupancy=%3.7f", _cmsGen->initiating_occupancy()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1517 gclog_or_tty->print_cr("metadata initialized %d", |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1518 MetaspaceGC::should_concurrent_collect()); |
0 | 1519 } |
1520 // ------------------------------------------------------------------ | |
1521 | |
1522 // If the estimated time to complete a cms collection (cms_duration()) | |
1523 // is less than the estimated time remaining until the cms generation | |
1524 // is full, start a collection. | |
1525 if (!UseCMSInitiatingOccupancyOnly) { | |
1526 if (stats().valid()) { | |
1527 if (stats().time_until_cms_start() == 0.0) { | |
1528 return true; | |
1529 } | |
1530 } else { | |
1531 // We want to conservatively collect somewhat early in order | |
1532 // to try and "bootstrap" our CMS/promotion statistics; | |
1533 // this branch will not fire after the first successful CMS | |
1534 // collection because the stats should then be valid. | |
1535 if (_cmsGen->occupancy() >= _bootstrap_occupancy) { | |
1536 if (Verbose && PrintGCDetails) { | |
1537 gclog_or_tty->print_cr( | |
1538 " CMSCollector: collect for bootstrapping statistics:" | |
1539 " occupancy = %f, boot occupancy = %f", _cmsGen->occupancy(), | |
1540 _bootstrap_occupancy); | |
1541 } | |
1542 return true; | |
1543 } | |
1544 } | |
1545 } | |
1546 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1547 // Otherwise, we start a collection cycle if |
0 | 1548 // old gen want a collection cycle started. Each may use |
1549 // an appropriate criterion for making this decision. | |
1550 // 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
|
1551 // 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
|
1552 if (_cmsGen->should_concurrent_collect()) { |
0 | 1553 if (Verbose && PrintGCDetails) { |
1554 gclog_or_tty->print_cr("CMS old gen initiated"); | |
1555 } | |
1556 return true; | |
1557 } | |
1558 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1559 // 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
|
1560 // 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
|
1561 // late anyway. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1562 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1563 assert(gch->collector_policy()->is_two_generation_policy(), |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1564 "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
|
1565 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
|
1566 if (Verbose && PrintGCDetails) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1567 gclog_or_tty->print("CMSCollector: collect because incremental collection will fail "); |
0 | 1568 } |
1569 return true; | |
1570 } | |
1571 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1572 if (MetaspaceGC::should_concurrent_collect()) { |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1573 if (Verbose && PrintGCDetails) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1574 gclog_or_tty->print("CMSCollector: collect for metadata allocation "); |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1575 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1576 return true; |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
1577 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1578 |
0 | 1579 return false; |
1580 } | |
1581 | |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1582 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
|
1583 |
0 | 1584 // Clear _expansion_cause fields of constituent generations |
1585 void CMSCollector::clear_expansion_cause() { | |
1586 _cmsGen->clear_expansion_cause(); | |
1587 } | |
1588 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1589 // 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
|
1590 // 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
|
1591 // 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
|
1592 // 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
|
1593 // 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
|
1594 // UseCMSInitiatingOccupancyOnly. This also has the advantage of |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1595 // 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
|
1596 // collections. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1597 // 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
|
1598 // conditions hold: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1599 // . our current occupancy exceeds the configured initiating occupancy |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1600 // for this generation, or |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1601 // . 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
|
1602 // expansion, done a collection of this generation, or |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1603 // . 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
|
1604 // 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
|
1605 // 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
|
1606 // 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
|
1607 // the generation, etc... or ... |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1608 // [.(currently done by CMSCollector::shouldConcurrentCollect() only for |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1609 // 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
|
1610 // 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
|
1611 // 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
|
1612 bool ConcurrentMarkSweepGeneration::should_concurrent_collect() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1613 |
0 | 1614 assert_lock_strong(freelistLock()); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1615 if (occupancy() > initiating_occupancy()) { |
0 | 1616 if (PrintGCDetails && Verbose) { |
1617 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
|
1618 short_name(), occupancy(), initiating_occupancy()); |
0 | 1619 } |
1620 return true; | |
1621 } | |
1622 if (UseCMSInitiatingOccupancyOnly) { | |
1623 return false; | |
1624 } | |
1625 if (expansion_cause() == CMSExpansionCause::_satisfy_allocation) { | |
1626 if (PrintGCDetails && Verbose) { | |
1627 gclog_or_tty->print(" %s: collect because expanded for allocation ", | |
1628 short_name()); | |
1629 } | |
1630 return true; | |
1631 } | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1632 if (_cmsSpace->should_concurrent_collect()) { |
0 | 1633 if (PrintGCDetails && Verbose) { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
1634 gclog_or_tty->print(" %s: collect because cmsSpace says so ", |
0 | 1635 short_name()); |
1636 } | |
1637 return true; | |
1638 } | |
1639 return false; | |
1640 } | |
1641 | |
1642 void ConcurrentMarkSweepGeneration::collect(bool full, | |
1643 bool clear_all_soft_refs, | |
1644 size_t size, | |
1645 bool tlab) | |
1646 { | |
1647 collector()->collect(full, clear_all_soft_refs, size, tlab); | |
1648 } | |
1649 | |
1650 void CMSCollector::collect(bool full, | |
1651 bool clear_all_soft_refs, | |
1652 size_t size, | |
1653 bool tlab) | |
1654 { | |
1655 if (!UseCMSCollectionPassing && _collectorState > Idling) { | |
1656 // For debugging purposes skip the collection if the state | |
1657 // is not currently idle | |
1658 if (TraceCMSState) { | |
1659 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " skipped full:%d CMS state %d", | |
1660 Thread::current(), full, _collectorState); | |
1661 } | |
1662 return; | |
1663 } | |
1664 | |
1665 // The following "if" branch is present for defensive reasons. | |
1666 // In the current uses of this interface, it can be replaced with: | |
1667 // assert(!GC_locker.is_active(), "Can't be called otherwise"); | |
1668 // But I am not placing that assert here to allow future | |
1669 // generality in invoking this interface. | |
1670 if (GC_locker::is_active()) { | |
1671 // A consistency test for GC_locker | |
1672 assert(GC_locker::needs_gc(), "Should have been set already"); | |
1673 // Skip this foreground collection, instead | |
1674 // expanding the heap if necessary. | |
1675 // Need the free list locks for the call to free() in compute_new_size() | |
1676 compute_new_size(); | |
1677 return; | |
1678 } | |
1679 acquire_control_and_collect(full, clear_all_soft_refs); | |
1680 _full_gcs_since_conc_gc++; | |
1681 } | |
1682 | |
10405 | 1683 void CMSCollector::request_full_gc(unsigned int full_gc_count, GCCause::Cause cause) { |
0 | 1684 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
1685 unsigned int gc_count = gch->total_full_collections(); | |
1686 if (gc_count == full_gc_count) { | |
1687 MutexLockerEx y(CGC_lock, Mutex::_no_safepoint_check_flag); | |
1688 _full_gc_requested = true; | |
10405 | 1689 _full_gc_cause = cause; |
0 | 1690 CGC_lock->notify(); // nudge CMS thread |
2365
a181f3a124dd
6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents:
2226
diff
changeset
|
1691 } else { |
a181f3a124dd
6987703: iCMS: Intermittent hang with gc/gctests/CallGC/CallGC01 and +ExplicitGCInvokesConcurrent
ysr
parents:
2226
diff
changeset
|
1692 assert(gc_count > full_gc_count, "Error: causal loop"); |
0 | 1693 } |
1694 } | |
1695 | |
10405 | 1696 bool CMSCollector::is_external_interruption() { |
1697 GCCause::Cause cause = GenCollectedHeap::heap()->gc_cause(); | |
1698 return GCCause::is_user_requested_gc(cause) || | |
1699 GCCause::is_serviceability_requested_gc(cause); | |
1700 } | |
1701 | |
1702 void CMSCollector::report_concurrent_mode_interruption() { | |
1703 if (is_external_interruption()) { | |
1704 if (PrintGCDetails) { | |
1705 gclog_or_tty->print(" (concurrent mode interrupted)"); | |
1706 } | |
1707 } else { | |
1708 if (PrintGCDetails) { | |
1709 gclog_or_tty->print(" (concurrent mode failure)"); | |
1710 } | |
1711 _gc_tracer_cm->report_concurrent_mode_failure(); | |
1712 } | |
1713 } | |
1714 | |
0 | 1715 |
1716 // The foreground and background collectors need to coordinate in order | |
1717 // to make sure that they do not mutually interfere with CMS collections. | |
1718 // When a background collection is active, | |
1719 // the foreground collector may need to take over (preempt) and | |
1720 // synchronously complete an ongoing collection. Depending on the | |
1721 // frequency of the background collections and the heap usage | |
1722 // of the application, this preemption can be seldom or frequent. | |
1723 // There are only certain | |
1724 // points in the background collection that the "collection-baton" | |
1725 // can be passed to the foreground collector. | |
1726 // | |
1727 // The foreground collector will wait for the baton before | |
1728 // starting any part of the collection. The foreground collector | |
1729 // will only wait at one location. | |
1730 // | |
1731 // The background collector will yield the baton before starting a new | |
1732 // phase of the collection (e.g., before initial marking, marking from roots, | |
1733 // precleaning, final re-mark, sweep etc.) This is normally done at the head | |
1734 // of the loop which switches the phases. The background collector does some | |
1735 // of the phases (initial mark, final re-mark) with the world stopped. | |
1736 // Because of locking involved in stopping the world, | |
1737 // the foreground collector should not block waiting for the background | |
1738 // collector when it is doing a stop-the-world phase. The background | |
1739 // collector will yield the baton at an additional point just before | |
1740 // it enters a stop-the-world phase. Once the world is stopped, the | |
1741 // background collector checks the phase of the collection. If the | |
1742 // phase has not changed, it proceeds with the collection. If the | |
1743 // phase has changed, it skips that phase of the collection. See | |
1744 // the comments on the use of the Heap_lock in collect_in_background(). | |
1745 // | |
1746 // Variable used in baton passing. | |
1747 // _foregroundGCIsActive - Set to true by the foreground collector when | |
1748 // it wants the baton. The foreground clears it when it has finished | |
1749 // the collection. | |
1750 // _foregroundGCShouldWait - Set to true by the background collector | |
1751 // when it is running. The foreground collector waits while | |
1752 // _foregroundGCShouldWait is true. | |
1753 // CGC_lock - monitor used to protect access to the above variables | |
1754 // and to notify the foreground and background collectors. | |
1755 // _collectorState - current state of the CMS collection. | |
1756 // | |
1757 // The foreground collector | |
1758 // acquires the CGC_lock | |
1759 // sets _foregroundGCIsActive | |
1760 // waits on the CGC_lock for _foregroundGCShouldWait to be false | |
1761 // various locks acquired in preparation for the collection | |
1762 // are released so as not to block the background collector | |
1763 // that is in the midst of a collection | |
1764 // proceeds with the collection | |
1765 // clears _foregroundGCIsActive | |
1766 // returns | |
1767 // | |
1768 // The background collector in a loop iterating on the phases of the | |
1769 // collection | |
1770 // acquires the CGC_lock | |
1771 // sets _foregroundGCShouldWait | |
1772 // if _foregroundGCIsActive is set | |
1773 // clears _foregroundGCShouldWait, notifies _CGC_lock | |
1774 // waits on _CGC_lock for _foregroundGCIsActive to become false | |
1775 // and exits the loop. | |
1776 // otherwise | |
1777 // proceed with that phase of the collection | |
1778 // if the phase is a stop-the-world phase, | |
1779 // yield the baton once more just before enqueueing | |
1780 // the stop-world CMS operation (executed by the VM thread). | |
1781 // returns after all phases of the collection are done | |
1782 // | |
1783 | |
1784 void CMSCollector::acquire_control_and_collect(bool full, | |
1785 bool clear_all_soft_refs) { | |
1786 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint"); | |
1787 assert(!Thread::current()->is_ConcurrentGC_thread(), | |
1788 "shouldn't try to acquire control from self!"); | |
1789 | |
1790 // Start the protocol for acquiring control of the | |
1791 // collection from the background collector (aka CMS thread). | |
1792 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
1793 "VM thread should have CMS token"); | |
1794 // Remember the possibly interrupted state of an ongoing | |
1795 // concurrent collection | |
1796 CollectorState first_state = _collectorState; | |
1797 | |
1798 // Signal to a possibly ongoing concurrent collection that | |
1799 // we want to do a foreground collection. | |
1800 _foregroundGCIsActive = true; | |
1801 | |
1802 // Disable incremental mode during a foreground collection. | |
1803 ICMSDisabler icms_disabler; | |
1804 | |
1805 // release locks and wait for a notify from the background collector | |
1806 // releasing the locks in only necessary for phases which | |
1807 // do yields to improve the granularity of the collection. | |
1808 assert_lock_strong(bitMapLock()); | |
1809 // We need to lock the Free list lock for the space that we are | |
1810 // currently collecting. | |
1811 assert(haveFreelistLocks(), "Must be holding free list locks"); | |
1812 bitMapLock()->unlock(); | |
1813 releaseFreelistLocks(); | |
1814 { | |
1815 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
1816 if (_foregroundGCShouldWait) { | |
1817 // We are going to be waiting for action for the CMS thread; | |
1818 // it had better not be gone (for instance at shutdown)! | |
1819 assert(ConcurrentMarkSweepThread::cmst() != NULL, | |
1820 "CMS thread must be running"); | |
1821 // Wait here until the background collector gives us the go-ahead | |
1822 ConcurrentMarkSweepThread::clear_CMS_flag( | |
1823 ConcurrentMarkSweepThread::CMS_vm_has_token); // release token | |
1824 // Get a possibly blocked CMS thread going: | |
1825 // Note that we set _foregroundGCIsActive true above, | |
1826 // without protection of the CGC_lock. | |
1827 CGC_lock->notify(); | |
1828 assert(!ConcurrentMarkSweepThread::vm_thread_wants_cms_token(), | |
1829 "Possible deadlock"); | |
1830 while (_foregroundGCShouldWait) { | |
1831 // wait for notification | |
1832 CGC_lock->wait(Mutex::_no_safepoint_check_flag); | |
1833 // Possibility of delay/starvation here, since CMS token does | |
1834 // not know to give priority to VM thread? Actually, i think | |
1835 // there wouldn't be any delay/starvation, but the proof of | |
1836 // that "fact" (?) appears non-trivial. XXX 20011219YSR | |
1837 } | |
1838 ConcurrentMarkSweepThread::set_CMS_flag( | |
1839 ConcurrentMarkSweepThread::CMS_vm_has_token); | |
1840 } | |
1841 } | |
1842 // The CMS_token is already held. Get back the other locks. | |
1843 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
1844 "VM thread should have CMS token"); | |
1845 getFreelistLocks(); | |
1846 bitMapLock()->lock_without_safepoint_check(); | |
1847 if (TraceCMSState) { | |
1848 gclog_or_tty->print_cr("CMS foreground collector has asked for control " | |
1849 INTPTR_FORMAT " with first state %d", Thread::current(), first_state); | |
1850 gclog_or_tty->print_cr(" gets control with state %d", _collectorState); | |
1851 } | |
1852 | |
1853 // Check if we need to do a compaction, or if not, whether | |
1854 // we need to start the mark-sweep from scratch. | |
1855 bool should_compact = false; | |
1856 bool should_start_over = false; | |
1857 decide_foreground_collection_type(clear_all_soft_refs, | |
1858 &should_compact, &should_start_over); | |
1859 | |
1860 NOT_PRODUCT( | |
1861 if (RotateCMSCollectionTypes) { | |
1862 if (_cmsGen->debug_collection_type() == | |
1863 ConcurrentMarkSweepGeneration::MSC_foreground_collection_type) { | |
1864 should_compact = true; | |
1865 } else if (_cmsGen->debug_collection_type() == | |
1866 ConcurrentMarkSweepGeneration::MS_foreground_collection_type) { | |
1867 should_compact = false; | |
1868 } | |
1869 } | |
1870 ) | |
1871 | |
10405 | 1872 if (first_state > Idling) { |
1873 report_concurrent_mode_interruption(); | |
0 | 1874 } |
1875 | |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
1876 set_did_compact(should_compact); |
0 | 1877 if (should_compact) { |
1878 // If the collection is being acquired from the background | |
1879 // collector, there may be references on the discovered | |
1880 // references lists that have NULL referents (being those | |
1881 // that were concurrently cleared by a mutator) or | |
1882 // that are no longer active (having been enqueued concurrently | |
1883 // by the mutator). | |
1884 // Scrub the list of those references because Mark-Sweep-Compact | |
1885 // code assumes referents are not NULL and that all discovered | |
1886 // Reference objects are active. | |
1887 ref_processor()->clean_up_discovered_references(); | |
1888 | |
10405 | 1889 if (first_state > Idling) { |
1890 save_heap_summary(); | |
1891 } | |
1892 | |
0 | 1893 do_compaction_work(clear_all_soft_refs); |
1894 | |
1895 // 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
|
1896 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
|
1897 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
|
1898 young_gen->to()->capacity() - |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1899 young_gen->from()->capacity(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1900 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1901 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
|
1902 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
|
1903 young_gen->eden()->used(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1904 _cmsGen->max_capacity(), |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1905 max_eden_size, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1906 full, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1907 gc_cause, |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
1908 gch->collector_policy()); |
0 | 1909 } else { |
1910 do_mark_sweep_work(clear_all_soft_refs, first_state, | |
1911 should_start_over); | |
1912 } | |
1913 // Reset the expansion cause, now that we just completed | |
1914 // a collection cycle. | |
1915 clear_expansion_cause(); | |
1916 _foregroundGCIsActive = false; | |
1917 return; | |
1918 } | |
1919 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1920 // Resize the tenured generation |
0 | 1921 // after obtaining the free list locks for the |
1922 // two generations. | |
1923 void CMSCollector::compute_new_size() { | |
1924 assert_locked_or_safepoint(Heap_lock); | |
1925 FreelistLocker z(this); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1926 MetaspaceGC::compute_new_size(); |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
1927 _cmsGen->compute_new_size_free_list(); |
0 | 1928 } |
1929 | |
1930 // A work method used by foreground collection to determine | |
1931 // what type of collection (compacting or not, continuing or fresh) | |
1932 // it should do. | |
1933 // NOTE: the intent is to make UseCMSCompactAtFullCollection | |
1934 // and CMSCompactWhenClearAllSoftRefs the default in the future | |
1935 // and do away with the flags after a suitable period. | |
1936 void CMSCollector::decide_foreground_collection_type( | |
1937 bool clear_all_soft_refs, bool* should_compact, | |
1938 bool* should_start_over) { | |
1939 // Normally, we'll compact only if the UseCMSCompactAtFullCollection | |
1940 // flag is set, and we have either requested a System.gc() or | |
1941 // the number of full gc's since the last concurrent cycle | |
1942 // has exceeded the threshold set by CMSFullGCsBeforeCompaction, | |
1943 // or if an incremental collection has failed | |
1944 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1945 assert(gch->collector_policy()->is_two_generation_policy(), | |
1946 "You may want to check the correctness of the following"); | |
1947 // Inform cms gen if this was due to partial collection failing. | |
1948 // 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
|
1949 if (gch->incremental_collection_will_fail(false /* don't consult_young */)) { |
0 | 1950 assert(!_cmsGen->incremental_collection_failed(), |
1951 "Should have been noticed, reacted to and cleared"); | |
1952 _cmsGen->set_incremental_collection_failed(); | |
1953 } | |
1954 *should_compact = | |
1955 UseCMSCompactAtFullCollection && | |
1956 ((_full_gcs_since_conc_gc >= CMSFullGCsBeforeCompaction) || | |
1957 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
|
1958 gch->incremental_collection_will_fail(true /* consult_young */)); |
0 | 1959 *should_start_over = false; |
1960 if (clear_all_soft_refs && !*should_compact) { | |
1961 // We are about to do a last ditch collection attempt | |
1962 // so it would normally make sense to do a compaction | |
1963 // to reclaim as much space as possible. | |
1964 if (CMSCompactWhenClearAllSoftRefs) { | |
1965 // Default: The rationale is that in this case either | |
1966 // we are past the final marking phase, in which case | |
1967 // we'd have to start over, or so little has been done | |
1968 // that there's little point in saving that work. Compaction | |
1969 // appears to be the sensible choice in either case. | |
1970 *should_compact = true; | |
1971 } else { | |
1972 // We have been asked to clear all soft refs, but not to | |
1973 // compact. Make sure that we aren't past the final checkpoint | |
1974 // phase, for that is where we process soft refs. If we are already | |
1975 // past that phase, we'll need to redo the refs discovery phase and | |
1976 // if necessary clear soft refs that weren't previously | |
1977 // cleared. We do so by remembering the phase in which | |
1978 // we came in, and if we are past the refs processing | |
1979 // phase, we'll choose to just redo the mark-sweep | |
1980 // collection from scratch. | |
1981 if (_collectorState > FinalMarking) { | |
1982 // We are past the refs processing phase; | |
1983 // start over and do a fresh synchronous CMS cycle | |
1984 _collectorState = Resetting; // skip to reset to start new cycle | |
1985 reset(false /* == !asynch */); | |
1986 *should_start_over = true; | |
1987 } // else we can continue a possibly ongoing current cycle | |
1988 } | |
1989 } | |
1990 } | |
1991 | |
1992 // A work method used by the foreground collector to do | |
1993 // a mark-sweep-compact. | |
1994 void CMSCollector::do_compaction_work(bool clear_all_soft_refs) { | |
1995 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
10405 | 1996 |
1997 STWGCTimer* gc_timer = GenMarkSweep::gc_timer(); | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
1998 gc_timer->register_gc_start(); |
10405 | 1999 |
2000 SerialOldTracer* gc_tracer = GenMarkSweep::gc_tracer(); | |
2001 gc_tracer->report_gc_start(gch->gc_cause(), gc_timer->gc_start()); | |
2002 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2003 GCTraceTime t("CMS:MSC ", PrintGCDetails && Verbose, true, NULL, gc_tracer->gc_id()); |
0 | 2004 if (PrintGC && Verbose && !(GCCause::is_user_requested_gc(gch->gc_cause()))) { |
2005 gclog_or_tty->print_cr("Compact ConcurrentMarkSweepGeneration after %d " | |
2006 "collections passed to foreground collector", _full_gcs_since_conc_gc); | |
2007 } | |
2008 | |
2009 // Sample collection interval time and reset for collection pause. | |
2010 if (UseAdaptiveSizePolicy) { | |
2011 size_policy()->msc_collection_begin(); | |
2012 } | |
2013 | |
2014 // Temporarily widen the span of the weak reference processing to | |
2015 // the entire heap. | |
2016 MemRegion new_span(GenCollectedHeap::heap()->reserved_region()); | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2017 ReferenceProcessorSpanMutator rp_mut_span(ref_processor(), new_span); |
0 | 2018 // Temporarily, clear the "is_alive_non_header" field of the |
2019 // reference processor. | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2020 ReferenceProcessorIsAliveMutator rp_mut_closure(ref_processor(), NULL); |
0 | 2021 // Temporarily make reference _processing_ single threaded (non-MT). |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2022 ReferenceProcessorMTProcMutator rp_mut_mt_processing(ref_processor(), false); |
0 | 2023 // Temporarily make refs discovery atomic |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2024 ReferenceProcessorAtomicMutator rp_mut_atomic(ref_processor(), true); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2025 // Temporarily make reference _discovery_ single threaded (non-MT) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
2026 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(ref_processor(), false); |
0 | 2027 |
2028 ref_processor()->set_enqueuing_is_done(false); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
2029 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
|
2030 ref_processor()->setup_policy(clear_all_soft_refs); |
0 | 2031 // If an asynchronous collection finishes, the _modUnionTable is |
2032 // all clear. If we are assuming the collection from an asynchronous | |
2033 // collection, clear the _modUnionTable. | |
2034 assert(_collectorState != Idling || _modUnionTable.isAllClear(), | |
2035 "_modUnionTable should be clear if the baton was not passed"); | |
2036 _modUnionTable.clear_all(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2037 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
|
2038 "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
|
2039 _ct->klass_rem_set()->clear_mod_union(); |
0 | 2040 |
2041 // We must adjust the allocation statistics being maintained | |
2042 // in the free list space. We do so by reading and clearing | |
2043 // 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
|
2044 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
|
2045 if (_inter_sweep_timer.is_active()) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2046 _inter_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2047 // 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
|
2048 _cmsGen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2049 _inter_sweep_estimate.padded_average(), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2050 _intra_sweep_estimate.padded_average()); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2051 } |
0 | 2052 |
2053 GenMarkSweep::invoke_at_safepoint(_cmsGen->level(), | |
2054 ref_processor(), clear_all_soft_refs); | |
2055 #ifdef ASSERT | |
2056 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); | |
2057 size_t free_size = cms_space->free(); | |
2058 assert(free_size == | |
2059 pointer_delta(cms_space->end(), cms_space->compaction_top()) | |
2060 * HeapWordSize, | |
2061 "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
|
2062 assert(cms_space->dictionary()->total_chunk_size( |
0 | 2063 debug_only(cms_space->freelistLock())) == 0 || |
2064 cms_space->totalSizeInIndexedFreeLists() == 0, | |
2065 "All the free space should be in a single chunk"); | |
2066 size_t num = cms_space->totalCount(); | |
2067 assert((free_size == 0 && num == 0) || | |
2068 (free_size > 0 && (num == 1 || num == 2)), | |
2069 "There should be at most 2 free chunks after compaction"); | |
2070 #endif // ASSERT | |
2071 _collectorState = Resetting; | |
2072 assert(_restart_addr == NULL, | |
2073 "Should have been NULL'd before baton was passed"); | |
2074 reset(false /* == !asynch */); | |
2075 _cmsGen->reset_after_compaction(); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2076 _concurrent_cycles_since_last_unload = 0; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2077 |
0 | 2078 // Clear any data recorded in the PLAB chunk arrays. |
2079 if (_survivor_plab_array != NULL) { | |
2080 reset_survivor_plab_arrays(); | |
2081 } | |
2082 | |
2083 // Adjust the per-size allocation stats for the next epoch. | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2084 _cmsGen->cmsSpace()->endSweepFLCensus(sweep_count() /* fake */); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2085 // Restart the "inter sweep timer" for the next epoch. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2086 _inter_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2087 _inter_sweep_timer.start(); |
0 | 2088 |
2089 // Sample collection pause time and reset for collection interval. | |
2090 if (UseAdaptiveSizePolicy) { | |
2091 size_policy()->msc_collection_end(gch->gc_cause()); | |
2092 } | |
2093 | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2094 gc_timer->register_gc_end(); |
10405 | 2095 |
2096 gc_tracer->report_gc_end(gc_timer->gc_end(), gc_timer->time_partitions()); | |
2097 | |
0 | 2098 // For a mark-sweep-compact, compute_new_size() will be called |
2099 // in the heap's do_collection() method. | |
2100 } | |
2101 | |
2102 // A work method used by the foreground collector to do | |
2103 // a mark-sweep, after taking over from a possibly on-going | |
2104 // concurrent mark-sweep collection. | |
2105 void CMSCollector::do_mark_sweep_work(bool clear_all_soft_refs, | |
2106 CollectorState first_state, bool should_start_over) { | |
2107 if (PrintGC && Verbose) { | |
2108 gclog_or_tty->print_cr("Pass concurrent collection to foreground " | |
2109 "collector with count %d", | |
2110 _full_gcs_since_conc_gc); | |
2111 } | |
2112 switch (_collectorState) { | |
2113 case Idling: | |
2114 if (first_state == Idling || should_start_over) { | |
2115 // The background GC was not active, or should | |
2116 // restarted from scratch; start the cycle. | |
2117 _collectorState = InitialMarking; | |
2118 } | |
2119 // If first_state was not Idling, then a background GC | |
2120 // was in progress and has now finished. No need to do it | |
2121 // again. Leave the state as Idling. | |
2122 break; | |
2123 case Precleaning: | |
2124 // In the foreground case don't do the precleaning since | |
2125 // it is not done concurrently and there is extra work | |
2126 // required. | |
2127 _collectorState = FinalMarking; | |
2128 } | |
10405 | 2129 collect_in_foreground(clear_all_soft_refs, GenCollectedHeap::heap()->gc_cause()); |
0 | 2130 |
2131 // For a mark-sweep, compute_new_size() will be called | |
2132 // in the heap's do_collection() method. | |
2133 } | |
2134 | |
2135 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2136 void CMSCollector::print_eden_and_survivor_chunk_arrays() { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2137 DefNewGeneration* dng = _young_gen->as_DefNewGeneration(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2138 EdenSpace* eden_space = dng->eden(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2139 ContiguousSpace* from_space = dng->from(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2140 ContiguousSpace* to_space = dng->to(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2141 // Eden |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2142 if (_eden_chunk_array != NULL) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2143 gclog_or_tty->print_cr("eden " PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "(" SIZE_FORMAT ")", |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2144 eden_space->bottom(), eden_space->top(), |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2145 eden_space->end(), eden_space->capacity()); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2146 gclog_or_tty->print_cr("_eden_chunk_index=" SIZE_FORMAT ", " |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2147 "_eden_chunk_capacity=" SIZE_FORMAT, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2148 _eden_chunk_index, _eden_chunk_capacity); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2149 for (size_t i = 0; i < _eden_chunk_index; i++) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2150 gclog_or_tty->print_cr("_eden_chunk_array[" SIZE_FORMAT "]=" PTR_FORMAT, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2151 i, _eden_chunk_array[i]); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2152 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2153 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2154 // Survivor |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2155 if (_survivor_chunk_array != NULL) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2156 gclog_or_tty->print_cr("survivor " PTR_FORMAT "-" PTR_FORMAT "-" PTR_FORMAT "(" SIZE_FORMAT ")", |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2157 from_space->bottom(), from_space->top(), |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2158 from_space->end(), from_space->capacity()); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2159 gclog_or_tty->print_cr("_survivor_chunk_index=" SIZE_FORMAT ", " |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2160 "_survivor_chunk_capacity=" SIZE_FORMAT, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2161 _survivor_chunk_index, _survivor_chunk_capacity); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2162 for (size_t i = 0; i < _survivor_chunk_index; i++) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2163 gclog_or_tty->print_cr("_survivor_chunk_array[" SIZE_FORMAT "]=" PTR_FORMAT, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2164 i, _survivor_chunk_array[i]); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2165 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2166 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2167 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
2168 |
0 | 2169 void CMSCollector::getFreelistLocks() const { |
2170 // Get locks for all free lists in all generations that this | |
2171 // collector is responsible for | |
2172 _cmsGen->freelistLock()->lock_without_safepoint_check(); | |
2173 } | |
2174 | |
2175 void CMSCollector::releaseFreelistLocks() const { | |
2176 // Release locks for all free lists in all generations that this | |
2177 // collector is responsible for | |
2178 _cmsGen->freelistLock()->unlock(); | |
2179 } | |
2180 | |
2181 bool CMSCollector::haveFreelistLocks() const { | |
2182 // Check locks for all free lists in all generations that this | |
2183 // collector is responsible for | |
2184 assert_lock_strong(_cmsGen->freelistLock()); | |
2185 PRODUCT_ONLY(ShouldNotReachHere()); | |
2186 return true; | |
2187 } | |
2188 | |
2189 // A utility class that is used by the CMS collector to | |
2190 // temporarily "release" the foreground collector from its | |
2191 // usual obligation to wait for the background collector to | |
2192 // complete an ongoing phase before proceeding. | |
2193 class ReleaseForegroundGC: public StackObj { | |
2194 private: | |
2195 CMSCollector* _c; | |
2196 public: | |
2197 ReleaseForegroundGC(CMSCollector* c) : _c(c) { | |
2198 assert(_c->_foregroundGCShouldWait, "Else should not need to call"); | |
2199 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2200 // allow a potentially blocked foreground collector to proceed | |
2201 _c->_foregroundGCShouldWait = false; | |
2202 if (_c->_foregroundGCIsActive) { | |
2203 CGC_lock->notify(); | |
2204 } | |
2205 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2206 "Possible deadlock"); | |
2207 } | |
2208 | |
2209 ~ReleaseForegroundGC() { | |
2210 assert(!_c->_foregroundGCShouldWait, "Usage protocol violation?"); | |
2211 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2212 _c->_foregroundGCShouldWait = true; | |
2213 } | |
2214 }; | |
2215 | |
2216 // There are separate collect_in_background and collect_in_foreground because of | |
2217 // the different locking requirements of the background collector and the | |
2218 // foreground collector. There was originally an attempt to share | |
2219 // one "collect" method between the background collector and the foreground | |
2220 // collector but the if-then-else required made it cleaner to have | |
2221 // separate methods. | |
10405 | 2222 void CMSCollector::collect_in_background(bool clear_all_soft_refs, GCCause::Cause cause) { |
0 | 2223 assert(Thread::current()->is_ConcurrentGC_thread(), |
2224 "A CMS asynchronous collection is only allowed on a CMS thread."); | |
2225 | |
2226 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2227 { | |
2228 bool safepoint_check = Mutex::_no_safepoint_check_flag; | |
2229 MutexLockerEx hl(Heap_lock, safepoint_check); | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2230 FreelistLocker fll(this); |
0 | 2231 MutexLockerEx x(CGC_lock, safepoint_check); |
2232 if (_foregroundGCIsActive || !UseAsyncConcMarkSweepGC) { | |
2233 // The foreground collector is active or we're | |
2234 // not using asynchronous collections. Skip this | |
2235 // background collection. | |
2236 assert(!_foregroundGCShouldWait, "Should be clear"); | |
2237 return; | |
2238 } else { | |
2239 assert(_collectorState == Idling, "Should be idling before start."); | |
2240 _collectorState = InitialMarking; | |
10405 | 2241 register_gc_start(cause); |
0 | 2242 // Reset the expansion cause, now that we are about to begin |
2243 // a new cycle. | |
2244 clear_expansion_cause(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2245 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2246 // Clear the MetaspaceGC flag since a concurrent collection |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2247 // 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
|
2248 MetaspaceGC::set_should_concurrent_collect(false); |
0 | 2249 } |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2250 // 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
|
2251 // ensuing concurrent GC cycle. |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
2252 update_should_unload_classes(); |
0 | 2253 _full_gc_requested = false; // acks all outstanding full gc requests |
10405 | 2254 _full_gc_cause = GCCause::_no_gc; |
0 | 2255 // Signal that we are about to start a collection |
2256 gch->increment_total_full_collections(); // ... starting a collection cycle | |
2257 _collection_count_start = gch->total_full_collections(); | |
2258 } | |
2259 | |
2260 // Used for PrintGC | |
2261 size_t prev_used; | |
2262 if (PrintGC && Verbose) { | |
2263 prev_used = _cmsGen->used(); // XXXPERM | |
2264 } | |
2265 | |
2266 // The change of the collection state is normally done at this level; | |
2267 // the exceptions are phases that are executed while the world is | |
2268 // stopped. For those phases the change of state is done while the | |
2269 // world is stopped. For baton passing purposes this allows the | |
2270 // background collector to finish the phase and change state atomically. | |
2271 // The foreground collector cannot wait on a phase that is done | |
2272 // while the world is stopped because the foreground collector already | |
2273 // has the world stopped and would deadlock. | |
2274 while (_collectorState != Idling) { | |
2275 if (TraceCMSState) { | |
2276 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", | |
2277 Thread::current(), _collectorState); | |
2278 } | |
2279 // The foreground collector | |
2280 // holds the Heap_lock throughout its collection. | |
2281 // holds the CMS token (but not the lock) | |
2282 // except while it is waiting for the background collector to yield. | |
2283 // | |
2284 // The foreground collector should be blocked (not for long) | |
2285 // if the background collector is about to start a phase | |
2286 // executed with world stopped. If the background | |
2287 // collector has already started such a phase, the | |
2288 // foreground collector is blocked waiting for the | |
2289 // Heap_lock. The stop-world phases (InitialMarking and FinalMarking) | |
2290 // are executed in the VM thread. | |
2291 // | |
2292 // The locking order is | |
2293 // PendingListLock (PLL) -- if applicable (FinalMarking) | |
2294 // Heap_lock (both this & PLL locked in VM_CMS_Operation::prologue()) | |
2295 // CMS token (claimed in | |
2296 // stop_world_and_do() --> | |
2297 // safepoint_synchronize() --> | |
2298 // CMSThread::synchronize()) | |
2299 | |
2300 { | |
2301 // Check if the FG collector wants us to yield. | |
2302 CMSTokenSync x(true); // is cms thread | |
2303 if (waitForForegroundGC()) { | |
2304 // We yielded to a foreground GC, nothing more to be | |
2305 // done this round. | |
2306 assert(_foregroundGCShouldWait == false, "We set it to false in " | |
2307 "waitForForegroundGC()"); | |
2308 if (TraceCMSState) { | |
2309 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2310 " exiting collection CMS state %d", | |
2311 Thread::current(), _collectorState); | |
2312 } | |
2313 return; | |
2314 } else { | |
2315 // The background collector can run but check to see if the | |
2316 // foreground collector has done a collection while the | |
2317 // background collector was waiting to get the CGC_lock | |
2318 // above. If yes, break so that _foregroundGCShouldWait | |
2319 // is cleared before returning. | |
2320 if (_collectorState == Idling) { | |
2321 break; | |
2322 } | |
2323 } | |
2324 } | |
2325 | |
2326 assert(_foregroundGCShouldWait, "Foreground collector, if active, " | |
2327 "should be waiting"); | |
2328 | |
2329 switch (_collectorState) { | |
2330 case InitialMarking: | |
2331 { | |
2332 ReleaseForegroundGC x(this); | |
2333 stats().record_cms_begin(); | |
2334 VM_CMS_Initial_Mark initial_mark_op(this); | |
2335 VMThread::execute(&initial_mark_op); | |
2336 } | |
2337 // The collector state may be any legal state at this point | |
2338 // since the background collector may have yielded to the | |
2339 // foreground collector. | |
2340 break; | |
2341 case Marking: | |
2342 // initial marking in checkpointRootsInitialWork has been completed | |
2343 if (markFromRoots(true)) { // we were successful | |
2344 assert(_collectorState == Precleaning, "Collector state should " | |
2345 "have changed"); | |
2346 } else { | |
2347 assert(_foregroundGCIsActive, "Internal state inconsistency"); | |
2348 } | |
2349 break; | |
2350 case Precleaning: | |
2351 if (UseAdaptiveSizePolicy) { | |
2352 size_policy()->concurrent_precleaning_begin(); | |
2353 } | |
2354 // marking from roots in markFromRoots has been completed | |
2355 preclean(); | |
2356 if (UseAdaptiveSizePolicy) { | |
2357 size_policy()->concurrent_precleaning_end(); | |
2358 } | |
2359 assert(_collectorState == AbortablePreclean || | |
2360 _collectorState == FinalMarking, | |
2361 "Collector state should have changed"); | |
2362 break; | |
2363 case AbortablePreclean: | |
2364 if (UseAdaptiveSizePolicy) { | |
2365 size_policy()->concurrent_phases_resume(); | |
2366 } | |
2367 abortable_preclean(); | |
2368 if (UseAdaptiveSizePolicy) { | |
2369 size_policy()->concurrent_precleaning_end(); | |
2370 } | |
2371 assert(_collectorState == FinalMarking, "Collector state should " | |
2372 "have changed"); | |
2373 break; | |
2374 case FinalMarking: | |
2375 { | |
2376 ReleaseForegroundGC x(this); | |
2377 | |
2378 VM_CMS_Final_Remark final_remark_op(this); | |
2379 VMThread::execute(&final_remark_op); | |
935 | 2380 } |
0 | 2381 assert(_foregroundGCShouldWait, "block post-condition"); |
2382 break; | |
2383 case Sweeping: | |
2384 if (UseAdaptiveSizePolicy) { | |
2385 size_policy()->concurrent_sweeping_begin(); | |
2386 } | |
2387 // final marking in checkpointRootsFinal has been completed | |
2388 sweep(true); | |
2389 assert(_collectorState == Resizing, "Collector state change " | |
2390 "to Resizing must be done under the free_list_lock"); | |
2391 _full_gcs_since_conc_gc = 0; | |
2392 | |
2393 // Stop the timers for adaptive size policy for the concurrent phases | |
2394 if (UseAdaptiveSizePolicy) { | |
2395 size_policy()->concurrent_sweeping_end(); | |
2396 size_policy()->concurrent_phases_end(gch->gc_cause(), | |
2397 gch->prev_gen(_cmsGen)->capacity(), | |
2398 _cmsGen->free()); | |
2399 } | |
2400 | |
2401 case Resizing: { | |
2402 // Sweeping has been completed... | |
2403 // At this point the background collection has completed. | |
2404 // Don't move the call to compute_new_size() down | |
2405 // into code that might be executed if the background | |
2406 // collection was preempted. | |
2407 { | |
2408 ReleaseForegroundGC x(this); // unblock FG collection | |
2409 MutexLockerEx y(Heap_lock, Mutex::_no_safepoint_check_flag); | |
2410 CMSTokenSync z(true); // not strictly needed. | |
2411 if (_collectorState == Resizing) { | |
2412 compute_new_size(); | |
10405 | 2413 save_heap_summary(); |
0 | 2414 _collectorState = Resetting; |
2415 } else { | |
2416 assert(_collectorState == Idling, "The state should only change" | |
2417 " because the foreground collector has finished the collection"); | |
2418 } | |
2419 } | |
2420 break; | |
2421 } | |
2422 case Resetting: | |
2423 // CMS heap resizing has been completed | |
2424 reset(true); | |
2425 assert(_collectorState == Idling, "Collector state should " | |
2426 "have changed"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2427 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2428 MetaspaceGC::set_should_concurrent_collect(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2429 |
0 | 2430 stats().record_cms_end(); |
2431 // Don't move the concurrent_phases_end() and compute_new_size() | |
2432 // calls to here because a preempted background collection | |
2433 // has it's state set to "Resetting". | |
2434 break; | |
2435 case Idling: | |
2436 default: | |
2437 ShouldNotReachHere(); | |
2438 break; | |
2439 } | |
2440 if (TraceCMSState) { | |
2441 gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", | |
2442 Thread::current(), _collectorState); | |
2443 } | |
2444 assert(_foregroundGCShouldWait, "block post-condition"); | |
2445 } | |
2446 | |
2447 // Should this be in gc_epilogue? | |
2448 collector_policy()->counters()->update_counters(); | |
2449 | |
2450 { | |
2451 // Clear _foregroundGCShouldWait and, in the event that the | |
2452 // foreground collector is waiting, notify it, before | |
2453 // returning. | |
2454 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2455 _foregroundGCShouldWait = false; | |
2456 if (_foregroundGCIsActive) { | |
2457 CGC_lock->notify(); | |
2458 } | |
2459 assert(!ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2460 "Possible deadlock"); | |
2461 } | |
2462 if (TraceCMSState) { | |
2463 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2464 " exiting collection CMS state %d", | |
2465 Thread::current(), _collectorState); | |
2466 } | |
2467 if (PrintGC && Verbose) { | |
2468 _cmsGen->print_heap_change(prev_used); | |
2469 } | |
2470 } | |
2471 | |
10405 | 2472 void CMSCollector::register_foreground_gc_start(GCCause::Cause cause) { |
2473 if (!_cms_start_registered) { | |
2474 register_gc_start(cause); | |
2475 } | |
2476 } | |
2477 | |
2478 void CMSCollector::register_gc_start(GCCause::Cause cause) { | |
2479 _cms_start_registered = true; | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2480 _gc_timer_cm->register_gc_start(); |
10405 | 2481 _gc_tracer_cm->report_gc_start(cause, _gc_timer_cm->gc_start()); |
2482 } | |
2483 | |
2484 void CMSCollector::register_gc_end() { | |
2485 if (_cms_start_registered) { | |
2486 report_heap_summary(GCWhen::AfterGC); | |
2487 | |
13400
86e6d691f2e1
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
13064
diff
changeset
|
2488 _gc_timer_cm->register_gc_end(); |
10405 | 2489 _gc_tracer_cm->report_gc_end(_gc_timer_cm->gc_end(), _gc_timer_cm->time_partitions()); |
2490 _cms_start_registered = false; | |
2491 } | |
2492 } | |
2493 | |
2494 void CMSCollector::save_heap_summary() { | |
2495 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2496 _last_heap_summary = gch->create_heap_summary(); | |
2497 _last_metaspace_summary = gch->create_metaspace_summary(); | |
2498 } | |
2499 | |
2500 void CMSCollector::report_heap_summary(GCWhen::Type when) { | |
17771
9fdaa79b0c27
8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents:
13400
diff
changeset
|
2501 _gc_tracer_cm->report_gc_heap_summary(when, _last_heap_summary); |
9fdaa79b0c27
8036703: Add trace event with statistics for the metaspace chunk free lists
ehelin
parents:
13400
diff
changeset
|
2502 _gc_tracer_cm->report_metaspace_summary(when, _last_metaspace_summary); |
10405 | 2503 } |
2504 | |
2505 void CMSCollector::collect_in_foreground(bool clear_all_soft_refs, GCCause::Cause cause) { | |
0 | 2506 assert(_foregroundGCIsActive && !_foregroundGCShouldWait, |
2507 "Foreground collector should be waiting, not executing"); | |
2508 assert(Thread::current()->is_VM_thread(), "A foreground collection" | |
2509 "may only be done by the VM Thread with the world stopped"); | |
2510 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), | |
2511 "VM thread should have CMS token"); | |
2512 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2513 // The gc id is created in register_foreground_gc_start if this collection is synchronous |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2514 const GCId gc_id = _collectorState == InitialMarking ? GCId::peek() : _gc_tracer_cm->gc_id(); |
10405 | 2515 NOT_PRODUCT(GCTraceTime t("CMS:MS (foreground) ", PrintGCDetails && Verbose, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
2516 true, NULL, gc_id);) |
0 | 2517 if (UseAdaptiveSizePolicy) { |
2518 size_policy()->ms_collection_begin(); | |
2519 } | |
2520 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact); | |
2521 | |
2522 HandleMark hm; // Discard invalid handles created during verification | |
2523 | |
2524 if (VerifyBeforeGC && | |
2525 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
2526 Universe::verify(); |
0 | 2527 } |
2528 | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
2529 // 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
|
2530 ref_processor()->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
2531 |
13064
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2532 // Decide if class unloading should be done |
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2533 update_should_unload_classes(); |
592d8b01fedd
8024483: assertion failure: (!mirror_alive || loader_alive) failed:
jmasa
parents:
13063
diff
changeset
|
2534 |
0 | 2535 bool init_mark_was_synchronous = false; // until proven otherwise |
2536 while (_collectorState != Idling) { | |
2537 if (TraceCMSState) { | |
2538 gclog_or_tty->print_cr("Thread " INTPTR_FORMAT " in CMS state %d", | |
2539 Thread::current(), _collectorState); | |
2540 } | |
2541 switch (_collectorState) { | |
2542 case InitialMarking: | |
10405 | 2543 register_foreground_gc_start(cause); |
0 | 2544 init_mark_was_synchronous = true; // fact to be exploited in re-mark |
2545 checkpointRootsInitial(false); | |
2546 assert(_collectorState == Marking, "Collector state should have changed" | |
2547 " within checkpointRootsInitial()"); | |
2548 break; | |
2549 case Marking: | |
2550 // initial marking in checkpointRootsInitialWork has been completed | |
2551 if (VerifyDuringGC && | |
2552 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
|
2553 Universe::verify("Verify before initial mark: "); |
0 | 2554 } |
2555 { | |
2556 bool res = markFromRoots(false); | |
2557 assert(res && _collectorState == FinalMarking, "Collector state should " | |
2558 "have changed"); | |
2559 break; | |
2560 } | |
2561 case FinalMarking: | |
2562 if (VerifyDuringGC && | |
2563 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
|
2564 Universe::verify("Verify before re-mark: "); |
0 | 2565 } |
2566 checkpointRootsFinal(false, clear_all_soft_refs, | |
2567 init_mark_was_synchronous); | |
2568 assert(_collectorState == Sweeping, "Collector state should not " | |
2569 "have changed within checkpointRootsFinal()"); | |
2570 break; | |
2571 case Sweeping: | |
2572 // final marking in checkpointRootsFinal has been completed | |
2573 if (VerifyDuringGC && | |
2574 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
|
2575 Universe::verify("Verify before sweep: "); |
0 | 2576 } |
2577 sweep(false); | |
2578 assert(_collectorState == Resizing, "Incorrect state"); | |
2579 break; | |
2580 case Resizing: { | |
2581 // Sweeping has been completed; the actual resize in this case | |
2582 // is done separately; nothing to be done in this state. | |
2583 _collectorState = Resetting; | |
2584 break; | |
2585 } | |
2586 case Resetting: | |
2587 // The heap has been resized. | |
2588 if (VerifyDuringGC && | |
2589 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
|
2590 Universe::verify("Verify before reset: "); |
0 | 2591 } |
10405 | 2592 save_heap_summary(); |
0 | 2593 reset(false); |
2594 assert(_collectorState == Idling, "Collector state should " | |
2595 "have changed"); | |
2596 break; | |
2597 case Precleaning: | |
2598 case AbortablePreclean: | |
2599 // Elide the preclean phase | |
2600 _collectorState = FinalMarking; | |
2601 break; | |
2602 default: | |
2603 ShouldNotReachHere(); | |
2604 } | |
2605 if (TraceCMSState) { | |
2606 gclog_or_tty->print_cr(" Thread " INTPTR_FORMAT " done - next CMS state %d", | |
2607 Thread::current(), _collectorState); | |
2608 } | |
2609 } | |
2610 | |
2611 if (UseAdaptiveSizePolicy) { | |
2612 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
2613 size_policy()->ms_collection_end(gch->gc_cause()); | |
2614 } | |
2615 | |
2616 if (VerifyAfterGC && | |
2617 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
2618 Universe::verify(); |
0 | 2619 } |
2620 if (TraceCMSState) { | |
2621 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT | |
2622 " exiting collection CMS state %d", | |
2623 Thread::current(), _collectorState); | |
2624 } | |
2625 } | |
2626 | |
2627 bool CMSCollector::waitForForegroundGC() { | |
2628 bool res = false; | |
2629 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
2630 "CMS thread should have CMS token"); | |
2631 // Block the foreground collector until the | |
2632 // background collectors decides whether to | |
2633 // yield. | |
2634 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); | |
2635 _foregroundGCShouldWait = true; | |
2636 if (_foregroundGCIsActive) { | |
2637 // The background collector yields to the | |
2638 // foreground collector and returns a value | |
2639 // indicating that it has yielded. The foreground | |
2640 // collector can proceed. | |
2641 res = true; | |
2642 _foregroundGCShouldWait = false; | |
2643 ConcurrentMarkSweepThread::clear_CMS_flag( | |
2644 ConcurrentMarkSweepThread::CMS_cms_has_token); | |
2645 ConcurrentMarkSweepThread::set_CMS_flag( | |
2646 ConcurrentMarkSweepThread::CMS_cms_wants_token); | |
2647 // Get a possibly blocked foreground thread going | |
2648 CGC_lock->notify(); | |
2649 if (TraceCMSState) { | |
2650 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " waiting at CMS state %d", | |
2651 Thread::current(), _collectorState); | |
2652 } | |
2653 while (_foregroundGCIsActive) { | |
2654 CGC_lock->wait(Mutex::_no_safepoint_check_flag); | |
2655 } | |
2656 ConcurrentMarkSweepThread::set_CMS_flag( | |
2657 ConcurrentMarkSweepThread::CMS_cms_has_token); | |
2658 ConcurrentMarkSweepThread::clear_CMS_flag( | |
2659 ConcurrentMarkSweepThread::CMS_cms_wants_token); | |
2660 } | |
2661 if (TraceCMSState) { | |
2662 gclog_or_tty->print_cr("CMS Thread " INTPTR_FORMAT " continuing at CMS state %d", | |
2663 Thread::current(), _collectorState); | |
2664 } | |
2665 return res; | |
2666 } | |
2667 | |
2668 // Because of the need to lock the free lists and other structures in | |
2669 // the collector, common to all the generations that the collector is | |
2670 // collecting, we need the gc_prologues of individual CMS generations | |
2671 // delegate to their collector. It may have been simpler had the | |
2672 // current infrastructure allowed one to call a prologue on a | |
2673 // collector. In the absence of that we have the generation's | |
2674 // prologue delegate to the collector, which delegates back | |
2675 // some "local" work to a worker method in the individual generations | |
2676 // that it's responsible for collecting, while itself doing any | |
2677 // work common to all generations it's responsible for. A similar | |
2678 // comment applies to the gc_epilogue()'s. | |
2679 // The role of the varaible _between_prologue_and_epilogue is to | |
2680 // enforce the invocation protocol. | |
2681 void CMSCollector::gc_prologue(bool full) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2682 // Call gc_prologue_work() for the CMSGen |
0 | 2683 // we are responsible for. |
2684 | |
2685 // The following locking discipline assumes that we are only called | |
2686 // when the world is stopped. | |
2687 assert(SafepointSynchronize::is_at_safepoint(), "world is stopped assumption"); | |
2688 | |
2689 // 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
|
2690 // "generations" that it's responsible |
0 | 2691 // for. |
2692 | |
2693 assert( Thread::current()->is_VM_thread() | |
2694 || ( CMSScavengeBeforeRemark | |
2695 && Thread::current()->is_ConcurrentGC_thread()), | |
2696 "Incorrect thread type for prologue execution"); | |
2697 | |
2698 if (_between_prologue_and_epilogue) { | |
2699 // We have already been invoked; this is a gc_prologue delegation | |
2700 // from yet another CMS generation that we are responsible for, just | |
2701 // ignore it since all relevant work has already been done. | |
2702 return; | |
2703 } | |
2704 | |
2705 // set a bit saying prologue has been called; cleared in epilogue | |
2706 _between_prologue_and_epilogue = true; | |
2707 // 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
|
2708 // for each CMSGen. |
0 | 2709 |
2710 getFreelistLocks(); // gets free list locks on constituent spaces | |
2711 bitMapLock()->lock_without_safepoint_check(); | |
2712 | |
2713 // 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
|
2714 bool duringMarking = _collectorState >= Marking |
0 | 2715 && _collectorState < Sweeping; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2716 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2717 // 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
|
2718 // 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
|
2719 // 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
|
2720 // modified klasses. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2721 if (duringMarking) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2722 _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
|
2723 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2724 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2725 bool registerClosure = duringMarking; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2726 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2727 ModUnionClosure* muc = CollectedHeap::use_parallel_gc_threads() ? |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2728 &_modUnionClosurePar |
0 | 2729 : &_modUnionClosure; |
2730 _cmsGen->gc_prologue_work(full, registerClosure, muc); | |
2731 | |
2732 if (!full) { | |
2733 stats().record_gc0_begin(); | |
2734 } | |
2735 } | |
2736 | |
2737 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
|
2738 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2739 _capacity_at_prologue = capacity(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2740 _used_at_prologue = used(); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
2741 |
0 | 2742 // Delegate to CMScollector which knows how to coordinate between |
2743 // this and any other CMS generations that it is responsible for | |
2744 // collecting. | |
2745 collector()->gc_prologue(full); | |
2746 } | |
2747 | |
2748 // This is a "private" interface for use by this generation's CMSCollector. | |
2749 // Not to be called directly by any other entity (for instance, | |
2750 // GenCollectedHeap, which calls the "public" gc_prologue method above). | |
2751 void ConcurrentMarkSweepGeneration::gc_prologue_work(bool full, | |
2752 bool registerClosure, ModUnionClosure* modUnionClosure) { | |
2753 assert(!incremental_collection_failed(), "Shouldn't be set yet"); | |
2754 assert(cmsSpace()->preconsumptionDirtyCardClosure() == NULL, | |
2755 "Should be NULL"); | |
2756 if (registerClosure) { | |
2757 cmsSpace()->setPreconsumptionDirtyCardClosure(modUnionClosure); | |
2758 } | |
2759 cmsSpace()->gc_prologue(); | |
2760 // Clear stat counters | |
2761 NOT_PRODUCT( | |
2762 assert(_numObjectsPromoted == 0, "check"); | |
2763 assert(_numWordsPromoted == 0, "check"); | |
2764 if (Verbose && PrintGC) { | |
2765 gclog_or_tty->print("Allocated "SIZE_FORMAT" objects, " | |
2766 SIZE_FORMAT" bytes concurrently", | |
2767 _numObjectsAllocated, _numWordsAllocated*sizeof(HeapWord)); | |
2768 } | |
2769 _numObjectsAllocated = 0; | |
2770 _numWordsAllocated = 0; | |
2771 ) | |
2772 } | |
2773 | |
2774 void CMSCollector::gc_epilogue(bool full) { | |
2775 // The following locking discipline assumes that we are only called | |
2776 // when the world is stopped. | |
2777 assert(SafepointSynchronize::is_at_safepoint(), | |
2778 "world is stopped assumption"); | |
2779 | |
2780 // Currently the CMS epilogue (see CompactibleFreeListSpace) merely checks | |
2781 // if linear allocation blocks need to be appropriately marked to allow the | |
2782 // the blocks to be parsable. We also check here whether we need to nudge the | |
2783 // CMS collector thread to start a new cycle (if it's not already active). | |
2784 assert( Thread::current()->is_VM_thread() | |
2785 || ( CMSScavengeBeforeRemark | |
2786 && Thread::current()->is_ConcurrentGC_thread()), | |
2787 "Incorrect thread type for epilogue execution"); | |
2788 | |
2789 if (!_between_prologue_and_epilogue) { | |
2790 // We have already been invoked; this is a gc_epilogue delegation | |
2791 // from yet another CMS generation that we are responsible for, just | |
2792 // ignore it since all relevant work has already been done. | |
2793 return; | |
2794 } | |
2795 assert(haveFreelistLocks(), "must have freelist locks"); | |
2796 assert_lock_strong(bitMapLock()); | |
2797 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
2798 _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
|
2799 |
0 | 2800 _cmsGen->gc_epilogue_work(full); |
2801 | |
2802 if (_collectorState == AbortablePreclean || _collectorState == Precleaning) { | |
2803 // in case sampling was not already enabled, enable it | |
2804 _start_sampling = true; | |
2805 } | |
2806 // reset _eden_chunk_array so sampling starts afresh | |
2807 _eden_chunk_index = 0; | |
2808 | |
2809 size_t cms_used = _cmsGen->cmsSpace()->used(); | |
2810 | |
2811 // update performance counters - this uses a special version of | |
2812 // update_counters() that allows the utilization to be passed as a | |
2813 // parameter, avoiding multiple calls to used(). | |
2814 // | |
2815 _cmsGen->update_counters(cms_used); | |
2816 | |
2817 if (CMSIncrementalMode) { | |
2818 icms_update_allocation_limits(); | |
2819 } | |
2820 | |
2821 bitMapLock()->unlock(); | |
2822 releaseFreelistLocks(); | |
2823 | |
3799
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2824 if (!CleanChunkPoolAsync) { |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2825 Chunk::clean_chunk_pool(); |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2826 } |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3746
diff
changeset
|
2827 |
10244
06ab37f08701
8013184: CMS: Call reset_after_compaction() only if a compaction has been done
jmasa
parents:
10243
diff
changeset
|
2828 set_did_compact(false); |
0 | 2829 _between_prologue_and_epilogue = false; // ready for next cycle |
2830 } | |
2831 | |
2832 void ConcurrentMarkSweepGeneration::gc_epilogue(bool full) { | |
2833 collector()->gc_epilogue(full); | |
2834 | |
2835 // Also reset promotion tracking in par gc thread states. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
2836 if (CollectedHeap::use_parallel_gc_threads()) { |
0 | 2837 for (uint i = 0; i < ParallelGCThreads; i++) { |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2838 _par_gc_thread_states[i]->promo.stopTrackingPromotions(i); |
0 | 2839 } |
2840 } | |
2841 } | |
2842 | |
2843 void ConcurrentMarkSweepGeneration::gc_epilogue_work(bool full) { | |
2844 assert(!incremental_collection_failed(), "Should have been cleared"); | |
2845 cmsSpace()->setPreconsumptionDirtyCardClosure(NULL); | |
2846 cmsSpace()->gc_epilogue(); | |
2847 // Print stat counters | |
2848 NOT_PRODUCT( | |
2849 assert(_numObjectsAllocated == 0, "check"); | |
2850 assert(_numWordsAllocated == 0, "check"); | |
2851 if (Verbose && PrintGC) { | |
2852 gclog_or_tty->print("Promoted "SIZE_FORMAT" objects, " | |
2853 SIZE_FORMAT" bytes", | |
2854 _numObjectsPromoted, _numWordsPromoted*sizeof(HeapWord)); | |
2855 } | |
2856 _numObjectsPromoted = 0; | |
2857 _numWordsPromoted = 0; | |
2858 ) | |
2859 | |
2860 if (PrintGC && Verbose) { | |
2861 // Call down the chain in contiguous_available needs the freelistLock | |
2862 // so print this out before releasing the freeListLock. | |
2863 gclog_or_tty->print(" Contiguous available "SIZE_FORMAT" bytes ", | |
2864 contiguous_available()); | |
2865 } | |
2866 } | |
2867 | |
2868 #ifndef PRODUCT | |
2869 bool CMSCollector::have_cms_token() { | |
2870 Thread* thr = Thread::current(); | |
2871 if (thr->is_VM_thread()) { | |
2872 return ConcurrentMarkSweepThread::vm_thread_has_cms_token(); | |
2873 } else if (thr->is_ConcurrentGC_thread()) { | |
2874 return ConcurrentMarkSweepThread::cms_thread_has_cms_token(); | |
2875 } else if (thr->is_GC_task_thread()) { | |
2876 return ConcurrentMarkSweepThread::vm_thread_has_cms_token() && | |
2877 ParGCRareEvent_lock->owned_by_self(); | |
2878 } | |
2879 return false; | |
2880 } | |
2881 #endif | |
2882 | |
2883 // Check reachability of the given heap address in CMS generation, | |
2884 // treating all other generations as roots. | |
2885 bool CMSCollector::is_cms_reachable(HeapWord* addr) { | |
2886 // We could "guarantee" below, rather than assert, but i'll | |
2887 // leave these as "asserts" so that an adventurous debugger | |
2888 // could try this in the product build provided some subset of | |
2889 // the conditions were met, provided they were intersted in the | |
2890 // results and knew that the computation below wouldn't interfere | |
2891 // with other concurrent computations mutating the structures | |
2892 // being read or written. | |
2893 assert(SafepointSynchronize::is_at_safepoint(), | |
2894 "Else mutations in object graph will make answer suspect"); | |
2895 assert(have_cms_token(), "Should hold cms token"); | |
2896 assert(haveFreelistLocks(), "must hold free list locks"); | |
2897 assert_lock_strong(bitMapLock()); | |
2898 | |
2899 // Clear the marking bit map array before starting, but, just | |
2900 // for kicks, first report if the given address is already marked | |
2901 gclog_or_tty->print_cr("Start: Address 0x%x is%s marked", addr, | |
2902 _markBitMap.isMarked(addr) ? "" : " not"); | |
2903 | |
2904 if (verify_after_remark()) { | |
2905 MutexLockerEx x(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); | |
2906 bool result = verification_mark_bm()->isMarked(addr); | |
2907 gclog_or_tty->print_cr("TransitiveMark: Address 0x%x %s marked", addr, | |
2908 result ? "IS" : "is NOT"); | |
2909 return result; | |
2910 } else { | |
2911 gclog_or_tty->print_cr("Could not compute result"); | |
2912 return false; | |
2913 } | |
2914 } | |
2915 | |
9076
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2916 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2917 void |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2918 CMSCollector::print_on_error(outputStream* st) { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2919 CMSCollector* collector = ConcurrentMarkSweepGeneration::_collector; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2920 if (collector != NULL) { |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2921 CMSBitMap* bitmap = &collector->_markBitMap; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2922 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
|
2923 bitmap->print_on_error(st, " Bits: "); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2924 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2925 st->cr(); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2926 |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2927 CMSBitMap* mut_bitmap = &collector->_modUnionTable; |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2928 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
|
2929 mut_bitmap->print_on_error(st, " Bits: "); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2930 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2931 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
2932 |
0 | 2933 //////////////////////////////////////////////////////// |
2934 // CMS Verification Support | |
2935 //////////////////////////////////////////////////////// | |
2936 // Following the remark phase, the following invariant | |
2937 // should hold -- each object in the CMS heap which is | |
2938 // marked in markBitMap() should be marked in the verification_mark_bm(). | |
2939 | |
2940 class VerifyMarkedClosure: public BitMapClosure { | |
2941 CMSBitMap* _marks; | |
2942 bool _failed; | |
2943 | |
2944 public: | |
2945 VerifyMarkedClosure(CMSBitMap* bm): _marks(bm), _failed(false) {} | |
2946 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
2947 bool do_bit(size_t offset) { |
0 | 2948 HeapWord* addr = _marks->offsetToHeapWord(offset); |
2949 if (!_marks->isMarked(addr)) { | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2950 oop(addr)->print_on(gclog_or_tty); |
0 | 2951 gclog_or_tty->print_cr(" ("INTPTR_FORMAT" should have been marked)", addr); |
2952 _failed = true; | |
2953 } | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
2954 return true; |
0 | 2955 } |
2956 | |
2957 bool failed() { return _failed; } | |
2958 }; | |
2959 | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
2960 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
|
2961 if (!silent) gclog_or_tty->print(" [Verifying CMS Marking... "); |
0 | 2962 MutexLockerEx ml(verification_mark_bm()->lock(), Mutex::_no_safepoint_check_flag); |
2963 static bool init = false; | |
2964 | |
2965 assert(SafepointSynchronize::is_at_safepoint(), | |
2966 "Else mutations in object graph will make answer suspect"); | |
2967 assert(have_cms_token(), | |
2968 "Else there may be mutual interference in use of " | |
2969 " verification data structures"); | |
2970 assert(_collectorState > Marking && _collectorState <= Sweeping, | |
2971 "Else marking info checked here may be obsolete"); | |
2972 assert(haveFreelistLocks(), "must hold free list locks"); | |
2973 assert_lock_strong(bitMapLock()); | |
2974 | |
2975 | |
2976 // Allocate marking bit map if not already allocated | |
2977 if (!init) { // first time | |
2978 if (!verification_mark_bm()->allocate(_span)) { | |
2979 return false; | |
2980 } | |
2981 init = true; | |
2982 } | |
2983 | |
2984 assert(verification_mark_stack()->isEmpty(), "Should be empty"); | |
2985 | |
2986 // Turn off refs discovery -- so we will be tracing through refs. | |
2987 // This is as intended, because by this time | |
2988 // GC must already have cleared any refs that need to be cleared, | |
2989 // and traced those that need to be marked; moreover, | |
2990 // the marking done here is not going to intefere in any | |
2991 // way with the marking information used by GC. | |
2992 NoRefDiscovery no_discovery(ref_processor()); | |
2993 | |
2994 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
2995 | |
2996 // Clear any marks from a previous round | |
2997 verification_mark_bm()->clear_all(); | |
2998 assert(verification_mark_stack()->isEmpty(), "markStack should be empty"); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
2999 verify_work_stacks_empty(); |
0 | 3000 |
3001 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3002 gch->ensure_parsability(false); // fill TLABs, but no need to retire them | |
3003 // Update the saved marks which may affect the root scans. | |
3004 gch->save_marks(); | |
3005 | |
3006 if (CMSRemarkVerifyVariant == 1) { | |
3007 // In this first variant of verification, we complete | |
3008 // all marking, then check if the new marks-verctor is | |
3009 // a subset of the CMS marks-vector. | |
3010 verify_after_remark_work_1(); | |
3011 } else if (CMSRemarkVerifyVariant == 2) { | |
3012 // In this second variant of verification, we flag an error | |
3013 // (i.e. an object reachable in the new marks-vector not reachable | |
3014 // in the CMS marks-vector) immediately, also indicating the | |
3015 // identify of an object (A) that references the unmarked object (B) -- | |
3016 // presumably, a mutation to A failed to be picked up by preclean/remark? | |
3017 verify_after_remark_work_2(); | |
3018 } else { | |
3019 warning("Unrecognized value %d for CMSRemarkVerifyVariant", | |
3020 CMSRemarkVerifyVariant); | |
3021 } | |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
10180
diff
changeset
|
3022 if (!silent) gclog_or_tty->print(" done] "); |
0 | 3023 return true; |
3024 } | |
3025 | |
3026 void CMSCollector::verify_after_remark_work_1() { | |
3027 ResourceMark rm; | |
3028 HandleMark hm; | |
3029 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3030 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3031 // Get a clear set of claim bits for the roots processing to work with. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3032 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3033 |
0 | 3034 // 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
|
3035 MarkRefsIntoClosure notOlder(_span, verification_mark_bm()); |
0 | 3036 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
3037 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3038 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3039 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3040 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3041 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3042 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3043 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3044 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3045 NULL); // SSS: Provide correct closure |
0 | 3046 |
3047 // Now mark from the roots | |
3048 MarkFromRootsClosure markFromRootsClosure(this, _span, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3049 verification_mark_bm(), verification_mark_stack(), |
0 | 3050 false /* don't yield */, true /* verifying */); |
3051 assert(_restart_addr == NULL, "Expected pre-condition"); | |
3052 verification_mark_bm()->iterate(&markFromRootsClosure); | |
3053 while (_restart_addr != NULL) { | |
3054 // Deal with stack overflow: by restarting at the indicated | |
3055 // address. | |
3056 HeapWord* ra = _restart_addr; | |
3057 markFromRootsClosure.reset(ra); | |
3058 _restart_addr = NULL; | |
3059 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end()); | |
3060 } | |
3061 assert(verification_mark_stack()->isEmpty(), "Should have been drained"); | |
3062 verify_work_stacks_empty(); | |
3063 | |
3064 // Marking completed -- now verify that each bit marked in | |
3065 // verification_mark_bm() is also marked in markBitMap(); flag all | |
3066 // errors by printing corresponding objects. | |
3067 VerifyMarkedClosure vcl(markBitMap()); | |
3068 verification_mark_bm()->iterate(&vcl); | |
3069 if (vcl.failed()) { | |
3070 gclog_or_tty->print("Verification failed"); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3071 Universe::heap()->print_on(gclog_or_tty); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3072 fatal("CMS: failed marking verification after remark"); |
0 | 3073 } |
3074 } | |
3075 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3076 class VerifyKlassOopsKlassClosure : public KlassClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3077 class VerifyKlassOopsClosure : public OopClosure { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3078 CMSBitMap* _bitmap; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3079 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3080 VerifyKlassOopsClosure(CMSBitMap* bitmap) : _bitmap(bitmap) { } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3081 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
|
3082 void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3083 } _oop_closure; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3084 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3085 VerifyKlassOopsKlassClosure(CMSBitMap* bitmap) : _oop_closure(bitmap) {} |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3086 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3087 k->oops_do(&_oop_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3088 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3089 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3090 |
0 | 3091 void CMSCollector::verify_after_remark_work_2() { |
3092 ResourceMark rm; | |
3093 HandleMark hm; | |
3094 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3095 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3096 // Get a clear set of claim bits for the roots processing to work with. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3097 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3098 |
0 | 3099 // Mark from roots one level into CMS |
3100 MarkRefsIntoVerifyClosure notOlder(_span, verification_mark_bm(), | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3101 markBitMap()); |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3102 CLDToOopClosure cld_closure(¬Older, true); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3103 |
0 | 3104 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3105 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3106 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3107 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3108 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3109 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3110 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3111 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3112 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3113 &cld_closure); |
0 | 3114 |
3115 // Now mark from the roots | |
3116 MarkFromRootsVerifyClosure markFromRootsClosure(this, _span, | |
3117 verification_mark_bm(), markBitMap(), verification_mark_stack()); | |
3118 assert(_restart_addr == NULL, "Expected pre-condition"); | |
3119 verification_mark_bm()->iterate(&markFromRootsClosure); | |
3120 while (_restart_addr != NULL) { | |
3121 // Deal with stack overflow: by restarting at the indicated | |
3122 // address. | |
3123 HeapWord* ra = _restart_addr; | |
3124 markFromRootsClosure.reset(ra); | |
3125 _restart_addr = NULL; | |
3126 verification_mark_bm()->iterate(&markFromRootsClosure, ra, _span.end()); | |
3127 } | |
3128 assert(verification_mark_stack()->isEmpty(), "Should have been drained"); | |
3129 verify_work_stacks_empty(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3130 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3131 VerifyKlassOopsKlassClosure verify_klass_oops(verification_mark_bm()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3132 ClassLoaderDataGraph::classes_do(&verify_klass_oops); |
0 | 3133 |
3134 // Marking completed -- now verify that each bit marked in | |
3135 // verification_mark_bm() is also marked in markBitMap(); flag all | |
3136 // errors by printing corresponding objects. | |
3137 VerifyMarkedClosure vcl(markBitMap()); | |
3138 verification_mark_bm()->iterate(&vcl); | |
3139 assert(!vcl.failed(), "Else verification above should not have succeeded"); | |
3140 } | |
3141 | |
3142 void ConcurrentMarkSweepGeneration::save_marks() { | |
3143 // delegate to CMS space | |
3144 cmsSpace()->save_marks(); | |
3145 for (uint i = 0; i < ParallelGCThreads; i++) { | |
3146 _par_gc_thread_states[i]->promo.startTrackingPromotions(); | |
3147 } | |
3148 } | |
3149 | |
3150 bool ConcurrentMarkSweepGeneration::no_allocs_since_save_marks() { | |
3151 return cmsSpace()->no_allocs_since_save_marks(); | |
3152 } | |
3153 | |
3154 #define CMS_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ | |
3155 \ | |
3156 void ConcurrentMarkSweepGeneration:: \ | |
3157 oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ | |
3158 cl->set_generation(this); \ | |
3159 cmsSpace()->oop_since_save_marks_iterate##nv_suffix(cl); \ | |
3160 cl->reset_generation(); \ | |
3161 save_marks(); \ | |
3162 } | |
3163 | |
3164 ALL_SINCE_SAVE_MARKS_CLOSURES(CMS_SINCE_SAVE_MARKS_DEFN) | |
3165 | |
3166 void | |
3167 ConcurrentMarkSweepGeneration::younger_refs_iterate(OopsInGenClosure* cl) { | |
3168 cl->set_generation(this); | |
3169 younger_refs_in_space_iterate(_cmsSpace, cl); | |
3170 cl->reset_generation(); | |
3171 } | |
3172 | |
3173 void | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3174 ConcurrentMarkSweepGeneration::oop_iterate(ExtendedOopClosure* cl) { |
0 | 3175 if (freelistLock()->owned_by_self()) { |
3176 Generation::oop_iterate(cl); | |
3177 } else { | |
3178 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3179 Generation::oop_iterate(cl); | |
3180 } | |
3181 } | |
3182 | |
3183 void | |
3184 ConcurrentMarkSweepGeneration::object_iterate(ObjectClosure* cl) { | |
3185 if (freelistLock()->owned_by_self()) { | |
3186 Generation::object_iterate(cl); | |
3187 } else { | |
3188 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3189 Generation::object_iterate(cl); | |
3190 } | |
3191 } | |
3192 | |
3193 void | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3194 ConcurrentMarkSweepGeneration::safe_object_iterate(ObjectClosure* cl) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3195 if (freelistLock()->owned_by_self()) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3196 Generation::safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3197 } else { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3198 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3199 Generation::safe_object_iterate(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3200 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3201 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3202 |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
457
diff
changeset
|
3203 void |
0 | 3204 ConcurrentMarkSweepGeneration::post_compact() { |
3205 } | |
3206 | |
3207 void | |
3208 ConcurrentMarkSweepGeneration::prepare_for_verify() { | |
3209 // Fix the linear allocation blocks to look like free blocks. | |
3210 | |
3211 // Locks are normally acquired/released in gc_prologue/gc_epilogue, but those | |
3212 // are not called when the heap is verified during universe initialization and | |
3213 // at vm shutdown. | |
3214 if (freelistLock()->owned_by_self()) { | |
3215 cmsSpace()->prepare_for_verify(); | |
3216 } else { | |
3217 MutexLockerEx fll(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3218 cmsSpace()->prepare_for_verify(); | |
3219 } | |
3220 } | |
3221 | |
3222 void | |
6008 | 3223 ConcurrentMarkSweepGeneration::verify() { |
0 | 3224 // Locks are normally acquired/released in gc_prologue/gc_epilogue, but those |
3225 // are not called when the heap is verified during universe initialization and | |
3226 // at vm shutdown. | |
3227 if (freelistLock()->owned_by_self()) { | |
6008 | 3228 cmsSpace()->verify(); |
0 | 3229 } else { |
3230 MutexLockerEx fll(freelistLock(), Mutex::_no_safepoint_check_flag); | |
6008 | 3231 cmsSpace()->verify(); |
3232 } | |
3233 } | |
3234 | |
3235 void CMSCollector::verify() { | |
3236 _cmsGen->verify(); | |
0 | 3237 } |
3238 | |
3239 #ifndef PRODUCT | |
3240 bool CMSCollector::overflow_list_is_empty() const { | |
3241 assert(_num_par_pushes >= 0, "Inconsistency"); | |
3242 if (_overflow_list == NULL) { | |
3243 assert(_num_par_pushes == 0, "Inconsistency"); | |
3244 } | |
3245 return _overflow_list == NULL; | |
3246 } | |
3247 | |
3248 // The methods verify_work_stacks_empty() and verify_overflow_empty() | |
3249 // merely consolidate assertion checks that appear to occur together frequently. | |
3250 void CMSCollector::verify_work_stacks_empty() const { | |
3251 assert(_markStack.isEmpty(), "Marking stack should be empty"); | |
3252 assert(overflow_list_is_empty(), "Overflow list should be empty"); | |
3253 } | |
3254 | |
3255 void CMSCollector::verify_overflow_empty() const { | |
3256 assert(overflow_list_is_empty(), "Overflow list should be empty"); | |
3257 assert(no_preserved_marks(), "No preserved marks"); | |
3258 } | |
3259 #endif // PRODUCT | |
3260 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3261 // 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
|
3262 // ensuing concurrent GC cycle. We will collect and |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3263 // unload classes if it's the case that: |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3264 // (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
|
3265 // ExplicitGCInvokesConcurrentAndUnloadsClasses is set, OR |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3266 // (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
|
3267 // (b) old gen is getting really full |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3268 // 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
|
3269 // 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
|
3270 // 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
|
3271 // 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
|
3272 // 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
|
3273 // the property that concurrent_cycles_since_last_unload() |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3274 // 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
|
3275 // _cmsGen->is_too_full() are |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3276 // themselves also monotonic in that sense. See check_monotonicity() |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3277 // below. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3278 void CMSCollector::update_should_unload_classes() { |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3279 _should_unload_classes = false; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3280 // Condition 1 above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3281 if (_full_gc_requested && ExplicitGCInvokesConcurrentAndUnloadsClasses) { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3282 _should_unload_classes = true; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3283 } else if (CMSClassUnloadingEnabled) { // Condition 2.a above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3284 // Disjuncts 2.b.(i,ii,iii) above |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3285 _should_unload_classes = (concurrent_cycles_since_last_unload() >= |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3286 CMSClassUnloadingMaxInterval) |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3287 || _cmsGen->is_too_full(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3288 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3289 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3290 |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3291 bool ConcurrentMarkSweepGeneration::is_too_full() const { |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3292 bool res = should_concurrent_collect(); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3293 res = res && (occupancy() > (double)CMSIsTooFullPercentage/100.0); |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3294 return res; |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3295 } |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3296 |
0 | 3297 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
|
3298 const bool should_verify = VerifyBeforeGC || VerifyAfterGC || VerifyDuringGC |
0 | 3299 || VerifyBeforeExit; |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3300 const int rso = SharedHeap::SO_AllCodeCache; |
0 | 3301 |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
3302 // We set the proper root for this CMS cycle here. |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3303 if (should_unload_classes()) { // Should unload classes this cycle |
0 | 3304 remove_root_scanning_option(rso); // Shrink the root set appropriately |
3305 set_verifying(should_verify); // Set verification state for this cycle | |
3306 return; // Nothing else needs to be done at this time | |
3307 } | |
3308 | |
3309 // Not unloading classes this cycle | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3310 assert(!should_unload_classes(), "Inconsitency!"); |
13063
40b8c6bad703
8024954: CMS: CMSClassUnloadingMaxInterval is not implemented correctly. This change is also part of the fix for 8024483.
jmasa
parents:
12316
diff
changeset
|
3311 |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
3312 if ((!verifying() || unloaded_classes_last_cycle()) && should_verify) { |
0 | 3313 // Include symbols, strings and code cache elements to prevent their resurrection. |
3314 add_root_scanning_option(rso); | |
3315 set_verifying(true); | |
3316 } else if (verifying() && !should_verify) { | |
3317 // We were verifying, but some verification flags got disabled. | |
3318 set_verifying(false); | |
3319 // Exclude symbols, strings and code cache elements from root scanning to | |
3320 // reduce IM and RM pauses. | |
3321 remove_root_scanning_option(rso); | |
3322 } | |
3323 } | |
3324 | |
3325 | |
3326 #ifndef PRODUCT | |
3327 HeapWord* CMSCollector::block_start(const void* p) const { | |
3328 const HeapWord* addr = (HeapWord*)p; | |
3329 if (_span.contains(p)) { | |
3330 if (_cmsGen->cmsSpace()->is_in_reserved(addr)) { | |
3331 return _cmsGen->cmsSpace()->block_start(p); | |
3332 } | |
3333 } | |
3334 return NULL; | |
3335 } | |
3336 #endif | |
3337 | |
3338 HeapWord* | |
3339 ConcurrentMarkSweepGeneration::expand_and_allocate(size_t word_size, | |
3340 bool tlab, | |
3341 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
|
3342 CMSSynchronousYieldRequest yr; |
0 | 3343 assert(!tlab, "Can't deal with TLAB allocation"); |
3344 MutexLockerEx x(freelistLock(), Mutex::_no_safepoint_check_flag); | |
3345 expand(word_size*HeapWordSize, MinHeapDeltaBytes, | |
3346 CMSExpansionCause::_satisfy_allocation); | |
3347 if (GCExpandToAllocateDelayMillis > 0) { | |
3348 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3349 } | |
9
173195ff483a
6642634: Test nsk/regression/b6186200 crashed with SIGSEGV
ysr
parents:
7
diff
changeset
|
3350 return have_lock_and_allocate(word_size, tlab); |
0 | 3351 } |
3352 | |
3353 // YSR: All of this generation expansion/shrinking stuff is an exact copy of | |
3354 // OneContigSpaceCardGeneration, which makes me wonder if we should move this | |
3355 // to CardGeneration and share it... | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3356 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
|
3357 return CardGeneration::expand(bytes, expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3358 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3359 |
0 | 3360 void ConcurrentMarkSweepGeneration::expand(size_t bytes, size_t expand_bytes, |
3361 CMSExpansionCause::Cause cause) | |
3362 { | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3363 |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3364 bool success = expand(bytes, expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
196
diff
changeset
|
3365 |
0 | 3366 // remember why we expanded; this information is used |
3367 // by shouldConcurrentCollect() when making decisions on whether to start | |
3368 // a new CMS cycle. | |
3369 if (success) { | |
3370 set_expansion_cause(cause); | |
3371 if (PrintGCDetails && Verbose) { | |
3372 gclog_or_tty->print_cr("Expanded CMS gen for %s", | |
3373 CMSExpansionCause::to_string(cause)); | |
3374 } | |
3375 } | |
3376 } | |
3377 | |
3378 HeapWord* ConcurrentMarkSweepGeneration::expand_and_par_lab_allocate(CMSParGCThreadState* ps, size_t word_sz) { | |
3379 HeapWord* res = NULL; | |
3380 MutexLocker x(ParGCRareEvent_lock); | |
3381 while (true) { | |
3382 // Expansion by some other thread might make alloc OK now: | |
3383 res = ps->lab.alloc(word_sz); | |
3384 if (res != NULL) return res; | |
3385 // If there's not enough expansion space available, give up. | |
3386 if (_virtual_space.uncommitted_size() < (word_sz * HeapWordSize)) { | |
3387 return NULL; | |
3388 } | |
3389 // Otherwise, we try expansion. | |
3390 expand(word_sz*HeapWordSize, MinHeapDeltaBytes, | |
3391 CMSExpansionCause::_allocate_par_lab); | |
3392 // Now go around the loop and try alloc again; | |
3393 // A competing par_promote might beat us to the expansion space, | |
3394 // so we may go around the loop again if promotion fails agaion. | |
3395 if (GCExpandToAllocateDelayMillis > 0) { | |
3396 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3397 } | |
3398 } | |
3399 } | |
3400 | |
3401 | |
3402 bool ConcurrentMarkSweepGeneration::expand_and_ensure_spooling_space( | |
3403 PromotionInfo* promo) { | |
3404 MutexLocker x(ParGCRareEvent_lock); | |
3405 size_t refill_size_bytes = promo->refillSize() * HeapWordSize; | |
3406 while (true) { | |
3407 // Expansion by some other thread might make alloc OK now: | |
3408 if (promo->ensure_spooling_space()) { | |
3409 assert(promo->has_spooling_space(), | |
3410 "Post-condition of successful ensure_spooling_space()"); | |
3411 return true; | |
3412 } | |
3413 // If there's not enough expansion space available, give up. | |
3414 if (_virtual_space.uncommitted_size() < refill_size_bytes) { | |
3415 return false; | |
3416 } | |
3417 // Otherwise, we try expansion. | |
3418 expand(refill_size_bytes, MinHeapDeltaBytes, | |
3419 CMSExpansionCause::_allocate_par_spooling_space); | |
3420 // Now go around the loop and try alloc again; | |
3421 // A competing allocation might beat us to the expansion space, | |
3422 // so we may go around the loop again if allocation fails again. | |
3423 if (GCExpandToAllocateDelayMillis > 0) { | |
3424 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
3425 } | |
3426 } | |
3427 } | |
3428 | |
3429 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3430 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
|
3431 assert_locked_or_safepoint(ExpandHeap_lock); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3432 // Shrink committed space |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3433 _virtual_space.shrink_by(bytes); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3434 // 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
|
3435 _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
|
3436 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
|
3437 // Shrink the shared block offset array |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3438 _bts->resize(new_word_size); |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3439 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
|
3440 // Shrink the card table |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3441 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
|
3442 |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3443 if (Verbose && PrintGC) { |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3444 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
|
3445 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
|
3446 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
|
3447 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
|
3448 } |
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3449 } |
0 | 3450 |
3451 void ConcurrentMarkSweepGeneration::shrink(size_t bytes) { | |
3452 assert_locked_or_safepoint(Heap_lock); | |
3453 size_t size = ReservedSpace::page_align_size_down(bytes); | |
12112
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
3454 // Only shrink if a compaction was done so that all the free space |
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
3455 // in the generation is in a contiguous block at the end. |
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
3456 if (size > 0 && did_compact()) { |
0 | 3457 shrink_by(size); |
3458 } | |
3459 } | |
3460 | |
3461 bool ConcurrentMarkSweepGeneration::grow_by(size_t bytes) { | |
3462 assert_locked_or_safepoint(Heap_lock); | |
3463 bool result = _virtual_space.expand_by(bytes); | |
3464 if (result) { | |
3465 size_t new_word_size = | |
3466 heap_word_size(_virtual_space.committed_size()); | |
3467 MemRegion mr(_cmsSpace->bottom(), new_word_size); | |
3468 _bts->resize(new_word_size); // resize the block offset shared array | |
3469 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
3470 // Hmmmm... why doesn't CFLS::set_end verify locking? | |
3471 // This is quite ugly; FIX ME XXX | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
3472 _cmsSpace->assert_locked(freelistLock()); |
0 | 3473 _cmsSpace->set_end((HeapWord*)_virtual_space.high()); |
3474 | |
3475 // update the space and generation capacity counters | |
3476 if (UsePerfData) { | |
3477 _space_counters->update_capacity(); | |
3478 _gen_counters->update_all(); | |
3479 } | |
3480 | |
3481 if (Verbose && PrintGC) { | |
3482 size_t new_mem_size = _virtual_space.committed_size(); | |
3483 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
|
3484 gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
0 | 3485 name(), old_mem_size/K, bytes/K, new_mem_size/K); |
3486 } | |
3487 } | |
3488 return result; | |
3489 } | |
3490 | |
3491 bool ConcurrentMarkSweepGeneration::grow_to_reserved() { | |
3492 assert_locked_or_safepoint(Heap_lock); | |
3493 bool success = true; | |
3494 const size_t remaining_bytes = _virtual_space.uncommitted_size(); | |
3495 if (remaining_bytes > 0) { | |
3496 success = grow_by(remaining_bytes); | |
3497 DEBUG_ONLY(if (!success) warning("grow to reserved failed");) | |
3498 } | |
3499 return success; | |
3500 } | |
3501 | |
9072
8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
jmasa
parents:
8784
diff
changeset
|
3502 void ConcurrentMarkSweepGeneration::shrink_free_list_by(size_t bytes) { |
0 | 3503 assert_locked_or_safepoint(Heap_lock); |
3504 assert_lock_strong(freelistLock()); | |
10180
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3505 if (PrintGCDetails && Verbose) { |
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3506 warning("Shrinking of CMS not yet implemented"); |
ebded0261dfc
8012111: Remove warning about CMS generation shrinking.
jmasa
parents:
9152
diff
changeset
|
3507 } |
0 | 3508 return; |
3509 } | |
3510 | |
3511 | |
3512 // Simple ctor/dtor wrapper for accounting & timer chores around concurrent | |
3513 // phases. | |
3514 class CMSPhaseAccounting: public StackObj { | |
3515 public: | |
3516 CMSPhaseAccounting(CMSCollector *collector, | |
3517 const char *phase, | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3518 const GCId gc_id, |
0 | 3519 bool print_cr = true); |
3520 ~CMSPhaseAccounting(); | |
3521 | |
3522 private: | |
3523 CMSCollector *_collector; | |
3524 const char *_phase; | |
3525 elapsedTimer _wallclock; | |
3526 bool _print_cr; | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3527 const GCId _gc_id; |
0 | 3528 |
3529 public: | |
3530 // Not MT-safe; so do not pass around these StackObj's | |
3531 // where they may be accessed by other threads. | |
3532 jlong wallclock_millis() { | |
3533 assert(_wallclock.is_active(), "Wall clock should not stop"); | |
3534 _wallclock.stop(); // to record time | |
3535 jlong ret = _wallclock.milliseconds(); | |
3536 _wallclock.start(); // restart | |
3537 return ret; | |
3538 } | |
3539 }; | |
3540 | |
3541 CMSPhaseAccounting::CMSPhaseAccounting(CMSCollector *collector, | |
3542 const char *phase, | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3543 const GCId gc_id, |
0 | 3544 bool print_cr) : |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3545 _collector(collector), _phase(phase), _print_cr(print_cr), _gc_id(gc_id) { |
0 | 3546 |
3547 if (PrintCMSStatistics != 0) { | |
3548 _collector->resetYields(); | |
3549 } | |
8740
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3550 if (PrintGCDetails) { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3551 gclog_or_tty->gclog_stamp(_gc_id); |
8740
62609ffa2fc6
8008684: CMS: concurrent phase start markers should always be printed
tschatzl
parents:
8736
diff
changeset
|
3552 gclog_or_tty->print_cr("[%s-concurrent-%s-start]", |
0 | 3553 _collector->cmsGen()->short_name(), _phase); |
3554 } | |
3555 _collector->resetTimer(); | |
3556 _wallclock.start(); | |
3557 _collector->startTimer(); | |
3558 } | |
3559 | |
3560 CMSPhaseAccounting::~CMSPhaseAccounting() { | |
3561 assert(_wallclock.is_active(), "Wall clock should not have stopped"); | |
3562 _collector->stopTimer(); | |
3563 _wallclock.stop(); | |
3564 if (PrintGCDetails) { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3565 gclog_or_tty->gclog_stamp(_gc_id); |
0 | 3566 gclog_or_tty->print("[%s-concurrent-%s: %3.3f/%3.3f secs]", |
3567 _collector->cmsGen()->short_name(), | |
3568 _phase, _collector->timerValue(), _wallclock.seconds()); | |
3569 if (_print_cr) { | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
3570 gclog_or_tty->cr(); |
0 | 3571 } |
3572 if (PrintCMSStatistics != 0) { | |
3573 gclog_or_tty->print_cr(" (CMS-concurrent-%s yielded %d times)", _phase, | |
3574 _collector->yields()); | |
3575 } | |
3576 } | |
3577 } | |
3578 | |
3579 // CMS work | |
3580 | |
11975 | 3581 // The common parts of CMSParInitialMarkTask and CMSParRemarkTask. |
3582 class CMSParMarkTask : public AbstractGangTask { | |
3583 protected: | |
3584 CMSCollector* _collector; | |
3585 int _n_workers; | |
3586 CMSParMarkTask(const char* name, CMSCollector* collector, int n_workers) : | |
3587 AbstractGangTask(name), | |
3588 _collector(collector), | |
3589 _n_workers(n_workers) {} | |
3590 // Work method in support of parallel rescan ... of young gen spaces | |
3591 void do_young_space_rescan(uint worker_id, OopsInGenClosure* cl, | |
3592 ContiguousSpace* space, | |
3593 HeapWord** chunk_array, size_t chunk_top); | |
3594 void work_on_young_gen_roots(uint worker_id, OopsInGenClosure* cl); | |
3595 }; | |
3596 | |
3597 // Parallel initial mark task | |
3598 class CMSParInitialMarkTask: public CMSParMarkTask { | |
3599 public: | |
3600 CMSParInitialMarkTask(CMSCollector* collector, int n_workers) : | |
3601 CMSParMarkTask("Scan roots and young gen for initial mark in parallel", | |
3602 collector, n_workers) {} | |
3603 void work(uint worker_id); | |
3604 }; | |
3605 | |
0 | 3606 // Checkpoint the roots into this generation from outside |
3607 // this generation. [Note this initial checkpoint need only | |
3608 // be approximate -- we'll do a catch up phase subsequently.] | |
3609 void CMSCollector::checkpointRootsInitial(bool asynch) { | |
3610 assert(_collectorState == InitialMarking, "Wrong collector state"); | |
3611 check_correct_thread_executing(); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
3612 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
3613 |
10405 | 3614 save_heap_summary(); |
3615 report_heap_summary(GCWhen::BeforeGC); | |
3616 | |
0 | 3617 ReferenceProcessor* rp = ref_processor(); |
3618 SpecializationStats::clear(); | |
3619 assert(_restart_addr == NULL, "Control point invariant"); | |
3620 if (asynch) { | |
3621 // acquire locks for subsequent manipulations | |
3622 MutexLockerEx x(bitMapLock(), | |
3623 Mutex::_no_safepoint_check_flag); | |
3624 checkpointRootsInitialWork(asynch); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3625 // enable ("weak") refs discovery |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3626 rp->enable_discovery(true /*verify_disabled*/, true /*check_no_refs*/); |
0 | 3627 _collectorState = Marking; |
3628 } else { | |
3629 // (Weak) Refs discovery: this is controlled from genCollectedHeap::do_collection | |
3630 // which recognizes if we are a CMS generation, and doesn't try to turn on | |
3631 // discovery; verify that they aren't meddling. | |
3632 assert(!rp->discovery_is_atomic(), | |
3633 "incorrect setting of discovery predicate"); | |
3634 assert(!rp->discovery_enabled(), "genCollectedHeap shouldn't control " | |
3635 "ref discovery for this generation kind"); | |
3636 // already have locks | |
3637 checkpointRootsInitialWork(asynch); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3638 // now enable ("weak") refs discovery |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3827
diff
changeset
|
3639 rp->enable_discovery(true /*verify_disabled*/, false /*verify_no_refs*/); |
0 | 3640 _collectorState = Marking; |
3641 } | |
3642 SpecializationStats::print(); | |
3643 } | |
3644 | |
3645 void CMSCollector::checkpointRootsInitialWork(bool asynch) { | |
3646 assert(SafepointSynchronize::is_at_safepoint(), "world should be stopped"); | |
3647 assert(_collectorState == InitialMarking, "just checking"); | |
3648 | |
3649 // If there has not been a GC[n-1] since last GC[n] cycle completed, | |
3650 // precede our marking with a collection of all | |
3651 // younger generations to keep floating garbage to a minimum. | |
3652 // XXX: we won't do this for now -- it's an optimization to be done later. | |
3653 | |
3654 // already have locks | |
3655 assert_lock_strong(bitMapLock()); | |
3656 assert(_markBitMap.isAllClear(), "was reset at end of previous cycle"); | |
3657 | |
3658 // Setup the verification and class unloading state for this | |
3659 // CMS collection cycle. | |
3660 setup_cms_unloading_and_verification_state(); | |
3661 | |
10405 | 3662 NOT_PRODUCT(GCTraceTime t("\ncheckpointRootsInitialWork", |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3663 PrintGCDetails && Verbose, true, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 3664 if (UseAdaptiveSizePolicy) { |
3665 size_policy()->checkpoint_roots_initial_begin(); | |
3666 } | |
3667 | |
3668 // Reset all the PLAB chunk arrays if necessary. | |
3669 if (_survivor_plab_array != NULL && !CMSPLABRecordAlways) { | |
3670 reset_survivor_plab_arrays(); | |
3671 } | |
3672 | |
3673 ResourceMark rm; | |
3674 HandleMark hm; | |
3675 | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
3676 MarkRefsIntoClosure notOlder(_span, &_markBitMap); |
0 | 3677 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
3678 | |
3679 verify_work_stacks_empty(); | |
3680 verify_overflow_empty(); | |
3681 | |
3682 gch->ensure_parsability(false); // fill TLABs, but no need to retire them | |
3683 // Update the saved marks which may affect the root scans. | |
3684 gch->save_marks(); | |
3685 | |
3686 // weak reference processing has not started yet. | |
3687 ref_processor()->set_enqueuing_is_done(false); | |
3688 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3689 // Need to remember all newly created CLDs, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3690 // 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
|
3691 ClassLoaderDataGraph::remember_new_clds(true); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3692 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3693 // 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
|
3694 // 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
|
3695 ClassLoaderDataGraph::clear_claimed_marks(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3696 |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3697 if (CMSPrintEdenSurvivorChunks) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3698 print_eden_and_survivor_chunk_arrays(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3699 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
3700 |
0 | 3701 { |
3702 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
11975 | 3703 if (CMSParallelInitialMarkEnabled && CollectedHeap::use_parallel_gc_threads()) { |
3704 // The parallel version. | |
3705 FlexibleWorkGang* workers = gch->workers(); | |
3706 assert(workers != NULL, "Need parallel worker threads."); | |
3707 int n_workers = workers->active_workers(); | |
3708 CMSParInitialMarkTask tsk(this, n_workers); | |
3709 gch->set_par_threads(n_workers); | |
3710 initialize_sequential_subtasks_for_young_gen_rescan(n_workers); | |
3711 if (n_workers > 1) { | |
3712 GenCollectedHeap::StrongRootsScope srs(gch); | |
3713 workers->run_task(&tsk); | |
3714 } else { | |
3715 GenCollectedHeap::StrongRootsScope srs(gch); | |
3716 tsk.work(0); | |
3717 } | |
3718 gch->set_par_threads(0); | |
3719 } else { | |
3720 // The serial version. | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3721 CLDToOopClosure cld_closure(¬Older, true); |
11975 | 3722 gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel. |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3723 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3724 true, // younger gens are roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3725 true, // activate StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3726 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3727 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3728 ¬Older, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3729 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
3730 &cld_closure); |
11975 | 3731 } |
0 | 3732 } |
3733 | |
3734 // Clear mod-union table; it will be dirtied in the prologue of | |
3735 // CMS generation per each younger generation collection. | |
3736 | |
3737 assert(_modUnionTable.isAllClear(), | |
3738 "Was cleared in most recent final checkpoint phase" | |
3739 " or no bits are set in the gc_prologue before the start of the next " | |
3740 "subsequent marking phase."); | |
3741 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
3742 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
|
3743 |
0 | 3744 // Save the end of the used_region of the constituent generations |
3745 // to be used to limit the extent of sweep in each generation. | |
3746 save_sweep_limits(); | |
3747 if (UseAdaptiveSizePolicy) { | |
3748 size_policy()->checkpoint_roots_initial_end(gch->gc_cause()); | |
3749 } | |
3750 verify_overflow_empty(); | |
3751 } | |
3752 | |
3753 bool CMSCollector::markFromRoots(bool asynch) { | |
3754 // we might be tempted to assert that: | |
3755 // assert(asynch == !SafepointSynchronize::is_at_safepoint(), | |
3756 // "inconsistent argument?"); | |
3757 // However that wouldn't be right, because it's possible that | |
3758 // a safepoint is indeed in progress as a younger generation | |
3759 // stop-the-world GC happens even as we mark in this generation. | |
3760 assert(_collectorState == Marking, "inconsistent state?"); | |
3761 check_correct_thread_executing(); | |
3762 verify_overflow_empty(); | |
3763 | |
3764 bool res; | |
3765 if (asynch) { | |
3766 | |
3767 // Start the timers for adaptive size policy for the concurrent phases | |
3768 // Do it here so that the foreground MS can use the concurrent | |
3769 // timer since a foreground MS might has the sweep done concurrently | |
3770 // or STW. | |
3771 if (UseAdaptiveSizePolicy) { | |
3772 size_policy()->concurrent_marking_begin(); | |
3773 } | |
3774 | |
3775 // Weak ref discovery note: We may be discovering weak | |
3776 // refs in this generation concurrent (but interleaved) with | |
3777 // weak ref discovery by a younger generation collector. | |
3778 | |
3779 CMSTokenSyncWithLocks ts(true, bitMapLock()); | |
3780 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
3781 CMSPhaseAccounting pa(this, "mark", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 3782 res = markFromRootsWork(asynch); |
3783 if (res) { | |
3784 _collectorState = Precleaning; | |
3785 } else { // We failed and a foreground collection wants to take over | |
3786 assert(_foregroundGCIsActive, "internal state inconsistency"); | |
3787 assert(_restart_addr == NULL, "foreground will restart from scratch"); | |
3788 if (PrintGCDetails) { | |
3789 gclog_or_tty->print_cr("bailing out to foreground collection"); | |
3790 } | |
3791 } | |
3792 if (UseAdaptiveSizePolicy) { | |
3793 size_policy()->concurrent_marking_end(); | |
3794 } | |
3795 } else { | |
3796 assert(SafepointSynchronize::is_at_safepoint(), | |
3797 "inconsistent with asynch == false"); | |
3798 if (UseAdaptiveSizePolicy) { | |
3799 size_policy()->ms_collection_marking_begin(); | |
3800 } | |
3801 // already have locks | |
3802 res = markFromRootsWork(asynch); | |
3803 _collectorState = FinalMarking; | |
3804 if (UseAdaptiveSizePolicy) { | |
3805 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
3806 size_policy()->ms_collection_marking_end(gch->gc_cause()); | |
3807 } | |
3808 } | |
3809 verify_overflow_empty(); | |
3810 return res; | |
3811 } | |
3812 | |
3813 bool CMSCollector::markFromRootsWork(bool asynch) { | |
3814 // iterate over marked bits in bit map, doing a full scan and mark | |
3815 // from these roots using the following algorithm: | |
3816 // . if oop is to the right of the current scan pointer, | |
3817 // mark corresponding bit (we'll process it later) | |
3818 // . else (oop is to left of current scan pointer) | |
3819 // push oop on marking stack | |
3820 // . drain the marking stack | |
3821 | |
3822 // Note that when we do a marking step we need to hold the | |
3823 // bit map lock -- recall that direct allocation (by mutators) | |
3824 // and promotion (by younger generation collectors) is also | |
3825 // marking the bit map. [the so-called allocate live policy.] | |
3826 // Because the implementation of bit map marking is not | |
3827 // robust wrt simultaneous marking of bits in the same word, | |
3828 // we need to make sure that there is no such interference | |
3829 // between concurrent such updates. | |
3830 | |
3831 // already have locks | |
3832 assert_lock_strong(bitMapLock()); | |
3833 | |
3834 verify_work_stacks_empty(); | |
3835 verify_overflow_empty(); | |
3836 bool result = false; | |
1284 | 3837 if (CMSConcurrentMTEnabled && ConcGCThreads > 0) { |
0 | 3838 result = do_marking_mt(asynch); |
3839 } else { | |
3840 result = do_marking_st(asynch); | |
3841 } | |
3842 return result; | |
3843 } | |
3844 | |
3845 // Forward decl | |
3846 class CMSConcMarkingTask; | |
3847 | |
3848 class CMSConcMarkingTerminator: public ParallelTaskTerminator { | |
3849 CMSCollector* _collector; | |
3850 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
|
3851 public: |
0 | 3852 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
|
3853 |
0 | 3854 // "n_threads" is the number of threads to be terminated. |
3855 // "queue_set" is a set of work queues of other threads. | |
3856 // "collector" is the CMS collector associated with this task terminator. | |
3857 // "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
|
3858 CMSConcMarkingTerminator(int n_threads, TaskQueueSetSuper* queue_set, CMSCollector* collector) : |
0 | 3859 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
|
3860 _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
|
3861 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3862 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
|
3863 _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
|
3864 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3865 }; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3866 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3867 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
|
3868 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
|
3869 public: |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3870 bool should_exit_termination(); |
0 | 3871 void set_task(CMSConcMarkingTask* task) { |
3872 _task = task; | |
3873 } | |
3874 }; | |
3875 | |
3876 // MT Concurrent Marking Task | |
3877 class CMSConcMarkingTask: public YieldingFlexibleGangTask { | |
3878 CMSCollector* _collector; | |
3879 int _n_workers; // requested/desired # workers | |
3880 bool _asynch; | |
3881 bool _result; | |
3882 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
|
3883 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
|
3884 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
|
3885 char _pad_back[64]; |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3886 HeapWord* _restart_addr; |
0 | 3887 |
3888 // Exposed here for yielding support | |
3889 Mutex* const _bit_map_lock; | |
3890 | |
3891 // The per thread work queues, available here for stealing | |
3892 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
|
3893 |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3894 // Termination (and yielding) support |
0 | 3895 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
|
3896 CMSConcMarkingTerminatorTerminator _term_term; |
0 | 3897 |
3898 public: | |
3899 CMSConcMarkingTask(CMSCollector* collector, | |
3900 CompactibleFreeListSpace* cms_space, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3901 bool asynch, |
0 | 3902 YieldingFlexibleWorkGang* workers, |
3903 OopTaskQueueSet* task_queues): | |
3904 YieldingFlexibleGangTask("Concurrent marking done multi-threaded"), | |
3905 _collector(collector), | |
3906 _cms_space(cms_space), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3907 _asynch(asynch), _n_workers(0), _result(true), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3908 _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
|
3909 _term(_n_workers, task_queues, _collector), |
0 | 3910 _bit_map_lock(collector->bitMapLock()) |
3911 { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3912 _requested_size = _n_workers; |
0 | 3913 _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
|
3914 _term_term.set_task(this); |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3915 _restart_addr = _global_finger = _cms_space->bottom(); |
0 | 3916 } |
3917 | |
3918 | |
3919 OopTaskQueueSet* task_queues() { return _task_queues; } | |
3920 | |
3921 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
3922 | |
3923 HeapWord** global_finger_addr() { return &_global_finger; } | |
3924 | |
3925 CMSConcMarkingTerminator* terminator() { return &_term; } | |
3926 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3927 virtual void set_for_termination(int active_workers) { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3928 terminator()->reset_for_reuse(active_workers); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3929 } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
3930 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
3931 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
|
3932 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
|
3933 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
|
3934 && !_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
|
3935 && _asynch; |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3936 } |
0 | 3937 |
3938 virtual void coordinator_yield(); // stuff done by coordinator | |
3939 bool result() { return _result; } | |
3940 | |
3941 void reset(HeapWord* ra) { | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
3942 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
|
3943 _restart_addr = _global_finger = ra; |
0 | 3944 _term.reset_for_reuse(); |
3945 } | |
3946 | |
3947 static bool get_work_from_overflow_stack(CMSMarkStack* ovflw_stk, | |
3948 OopTaskQueue* work_q); | |
3949 | |
3950 private: | |
3951 void do_scan_and_mark(int i, CompactibleFreeListSpace* sp); | |
3952 void do_work_steal(int i); | |
3953 void bump_global_finger(HeapWord* f); | |
3954 }; | |
3955 | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3956 bool 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
|
3957 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
|
3958 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
|
3959 // 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
|
3960 // 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
|
3961 // 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
|
3962 // 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
|
3963 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
3964 |
0 | 3965 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
|
3966 if (_task->should_yield()) { |
0 | 3967 _task->yield(); |
3968 } else { | |
3969 ParallelTaskTerminator::yield(); | |
3970 } | |
3971 } | |
3972 | |
3973 //////////////////////////////////////////////////////////////// | |
3974 // Concurrent Marking Algorithm Sketch | |
3975 //////////////////////////////////////////////////////////////// | |
3976 // Until all tasks exhausted (both spaces): | |
3977 // -- claim next available chunk | |
3978 // -- bump global finger via CAS | |
3979 // -- find first object that starts in this chunk | |
3980 // and start scanning bitmap from that position | |
3981 // -- scan marked objects for oops | |
3982 // -- CAS-mark target, and if successful: | |
3983 // . if target oop is above global finger (volatile read) | |
3984 // nothing to do | |
3985 // . if target oop is in chunk and above local finger | |
3986 // then nothing to do | |
3987 // . else push on work-queue | |
3988 // -- Deal with possible overflow issues: | |
3989 // . local work-queue overflow causes stuff to be pushed on | |
3990 // global (common) overflow queue | |
3991 // . always first empty local work queue | |
3992 // . then get a batch of oops from global work queue if any | |
3993 // . then do work stealing | |
3994 // -- When all tasks claimed (both spaces) | |
3995 // and local work queue empty, | |
3996 // then in a loop do: | |
3997 // . check global overflow stack; steal a batch of oops and trace | |
3998 // . try to steal from other threads oif GOS is empty | |
3999 // . if neither is available, offer termination | |
4000 // -- Terminate and return result | |
4001 // | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4002 void CMSConcMarkingTask::work(uint worker_id) { |
0 | 4003 elapsedTimer _timer; |
4004 ResourceMark rm; | |
4005 HandleMark hm; | |
4006 | |
4007 DEBUG_ONLY(_collector->verify_overflow_empty();) | |
4008 | |
4009 // 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
|
4010 assert(work_queue(worker_id)->size() == 0, "Expected to be empty"); |
0 | 4011 // Scan the bitmap covering _cms_space, tracing through grey objects. |
4012 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4013 do_scan_and_mark(worker_id, _cms_space); |
0 | 4014 _timer.stop(); |
4015 if (PrintCMSStatistics != 0) { | |
4016 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
|
4017 worker_id, _timer.seconds()); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4018 // XXX: need xxx/xxx type of notation, two timers |
0 | 4019 } |
4020 | |
4021 // ... do work stealing | |
4022 _timer.reset(); | |
4023 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4024 do_work_steal(worker_id); |
0 | 4025 _timer.stop(); |
4026 if (PrintCMSStatistics != 0) { | |
4027 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
|
4028 worker_id, _timer.seconds()); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
4029 // XXX: need xxx/xxx type of notation, two timers |
0 | 4030 } |
4031 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
|
4032 assert(work_queue(worker_id)->size() == 0, "Should have been emptied"); |
0 | 4033 // Note that under the current task protocol, the |
4034 // following assertion is true even of the spaces | |
4035 // expanded since the completion of the concurrent | |
4036 // marking. XXX This will likely change under a strict | |
4037 // ABORT semantics. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4038 // After perm removal the comparison was changed to |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4039 // 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
|
4040 // Before perm removal the highest address sweep would |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4041 // 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
|
4042 // end of the tenured gen. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4043 assert(_global_finger >= _cms_space->end(), |
0 | 4044 "All tasks have been completed"); |
4045 DEBUG_ONLY(_collector->verify_overflow_empty();) | |
4046 } | |
4047 | |
4048 void CMSConcMarkingTask::bump_global_finger(HeapWord* f) { | |
4049 HeapWord* read = _global_finger; | |
4050 HeapWord* cur = read; | |
4051 while (f > read) { | |
4052 cur = read; | |
4053 read = (HeapWord*) Atomic::cmpxchg_ptr(f, &_global_finger, cur); | |
4054 if (cur == read) { | |
4055 // our cas succeeded | |
4056 assert(_global_finger >= f, "protocol consistency"); | |
4057 break; | |
4058 } | |
4059 } | |
4060 } | |
4061 | |
4062 // This is really inefficient, and should be redone by | |
4063 // using (not yet available) block-read and -write interfaces to the | |
4064 // stack and the work_queue. XXX FIX ME !!! | |
4065 bool CMSConcMarkingTask::get_work_from_overflow_stack(CMSMarkStack* ovflw_stk, | |
4066 OopTaskQueue* work_q) { | |
4067 // Fast lock-free check | |
4068 if (ovflw_stk->length() == 0) { | |
4069 return false; | |
4070 } | |
4071 assert(work_q->size() == 0, "Shouldn't steal"); | |
4072 MutexLockerEx ml(ovflw_stk->par_lock(), | |
4073 Mutex::_no_safepoint_check_flag); | |
4074 // 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
|
4075 size_t num = MIN2((size_t)(work_q->max_elems() - work_q->size())/4, |
0 | 4076 (size_t)ParGCDesiredObjsFromOverflowList); |
4077 num = MIN2(num, ovflw_stk->length()); | |
4078 for (int i = (int) num; i > 0; i--) { | |
4079 oop cur = ovflw_stk->pop(); | |
4080 assert(cur != NULL, "Counted wrong?"); | |
4081 work_q->push(cur); | |
4082 } | |
4083 return num > 0; | |
4084 } | |
4085 | |
4086 void CMSConcMarkingTask::do_scan_and_mark(int i, CompactibleFreeListSpace* sp) { | |
4087 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); | |
4088 int n_tasks = pst->n_tasks(); | |
4089 // We allow that there may be no tasks to do here because | |
4090 // we are restarting after a stack overflow. | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4091 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
|
4092 uint nth_task = 0; |
0 | 4093 |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4094 HeapWord* aligned_start = sp->bottom(); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4095 if (sp->used_region().contains(_restart_addr)) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4096 // 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
|
4097 // for this space. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4098 aligned_start = |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4099 (HeapWord*)align_size_down((uintptr_t)_restart_addr, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4100 CardTableModRefBS::card_size); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4101 } |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4102 |
0 | 4103 size_t chunk_size = sp->marking_task_size(); |
4104 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
4105 // Having claimed the nth task in this space, | |
4106 // compute the chunk that it corresponds to: | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4107 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
|
4108 aligned_start + (nth_task+1)*chunk_size); |
0 | 4109 // Try and bump the global finger via a CAS; |
4110 // note that we need to do the global finger bump | |
4111 // _before_ taking the intersection below, because | |
4112 // the task corresponding to that region will be | |
4113 // deemed done even if the used_region() expands | |
4114 // because of allocation -- as it almost certainly will | |
4115 // during start-up while the threads yield in the | |
4116 // closure below. | |
4117 HeapWord* finger = span.end(); | |
4118 bump_global_finger(finger); // atomically | |
4119 // There are null tasks here corresponding to chunks | |
4120 // beyond the "top" address of the space. | |
4121 span = span.intersection(sp->used_region()); | |
4122 if (!span.is_empty()) { // Non-null task | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4123 HeapWord* prev_obj; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4124 assert(!span.contains(_restart_addr) || nth_task == 0, |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4125 "Inconsistency"); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4126 if (nth_task == 0) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4127 // 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
|
4128 if (span.contains(_restart_addr)) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4129 // 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
|
4130 // we might additionally skip a chunk prefix. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4131 prev_obj = _restart_addr; |
0 | 4132 } else { |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4133 prev_obj = span.start(); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4134 } |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4135 } else { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4136 // We want to skip the first object because |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4137 // 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
|
4138 // that _starts_ in this span; a fortiori, any |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4139 // object starting in an earlier span is scanned |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4140 // as part of an earlier claimed task. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4141 // 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
|
4142 // 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
|
4143 prev_obj = sp->block_start_careful(span.start()); |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4144 // 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
|
4145 // Printezis bits to avoid waiting for allocated |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4146 // objects to become initialized/parsable. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4147 while (prev_obj < span.start()) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4148 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
|
4149 if (sz > 0) { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4150 prev_obj += sz; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4151 } else { |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4152 // 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
|
4153 // scanning, but that appears unavoidable, short of |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4154 // locking the free list locks; see bug 6324141. |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4155 break; |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4156 } |
0 | 4157 } |
4158 } | |
4159 if (prev_obj < span.end()) { | |
4160 MemRegion my_span = MemRegion(prev_obj, span.end()); | |
4161 // Do the marking work within a non-empty span -- | |
4162 // the last argument to the constructor indicates whether the | |
4163 // iteration should be incremental with periodic yields. | |
4164 Par_MarkFromRootsClosure cl(this, _collector, my_span, | |
4165 &_collector->_markBitMap, | |
4166 work_queue(i), | |
4167 &_collector->_markStack, | |
4168 _asynch); | |
4169 _collector->_markBitMap.iterate(&cl, my_span.start(), my_span.end()); | |
4170 } // else nothing to do for this task | |
4171 } // else nothing to do for this task | |
4172 } | |
4173 // We'd be tempted to assert here that since there are no | |
4174 // more tasks left to claim in this space, the global_finger | |
4175 // must exceed space->top() and a fortiori space->end(). However, | |
4176 // that would not quite be correct because the bumping of | |
4177 // global_finger occurs strictly after the claiming of a task, | |
4178 // so by the time we reach here the global finger may not yet | |
4179 // have been bumped up by the thread that claimed the last | |
4180 // task. | |
4181 pst->all_tasks_completed(); | |
4182 } | |
4183 | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
4184 class Par_ConcMarkingClosure: public MetadataAwareOopClosure { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4185 private: |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4186 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
|
4187 CMSConcMarkingTask* _task; |
0 | 4188 MemRegion _span; |
4189 CMSBitMap* _bit_map; | |
4190 CMSMarkStack* _overflow_stack; | |
4191 OopTaskQueue* _work_queue; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4192 protected: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4193 DO_OOP_WORK_DEFN |
0 | 4194 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
|
4195 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
|
4196 CMSBitMap* bit_map, CMSMarkStack* overflow_stack): |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
4197 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4198 _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
|
4199 _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
|
4200 _span(collector->_span), |
0 | 4201 _work_queue(work_queue), |
4202 _bit_map(bit_map), | |
935 | 4203 _overflow_stack(overflow_stack) |
4204 { } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4205 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
|
4206 virtual void do_oop(narrowOop* p); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4207 |
0 | 4208 void trim_queue(size_t max); |
4209 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
|
4210 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
|
4211 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
|
4212 _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
|
4213 } |
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1836
diff
changeset
|
4214 } |
0 | 4215 }; |
4216 | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4217 // Grey object scanning during work stealing phase -- |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4218 // the salient assumption here is that any references |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4219 // 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
|
4220 // 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
|
4221 // 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
|
4222 // 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
|
4223 void Par_ConcMarkingClosure::do_oop(oop obj) { |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
4224 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
|
4225 HeapWord* addr = (HeapWord*)obj; |
0 | 4226 // Check if oop points into the CMS generation |
4227 // and is not marked | |
4228 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
4229 // a white object ... | |
4230 // If we manage to "claim" the object, by being the | |
4231 // first thread to mark it, then we push it on our | |
4232 // marking stack | |
4233 if (_bit_map->par_mark(addr)) { // ... now grey | |
4234 // push on work queue (grey set) | |
4235 bool simulate_overflow = false; | |
4236 NOT_PRODUCT( | |
4237 if (CMSMarkStackOverflowALot && | |
4238 _collector->simulate_overflow()) { | |
4239 // simulate a stack overflow | |
4240 simulate_overflow = true; | |
4241 } | |
4242 ) | |
4243 if (simulate_overflow || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4244 !(_work_queue->push(obj) || _overflow_stack->par_push(obj))) { |
0 | 4245 // stack overflow |
4246 if (PrintCMSStatistics != 0) { | |
4247 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
4248 SIZE_FORMAT, _overflow_stack->capacity()); | |
4249 } | |
4250 // We cannot assert that the overflow stack is full because | |
4251 // it may have been emptied since. | |
4252 assert(simulate_overflow || | |
4253 _work_queue->size() == _work_queue->max_elems(), | |
4254 "Else push should have succeeded"); | |
4255 handle_stack_overflow(addr); | |
4256 } | |
4257 } // 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
|
4258 do_yield_check(); |
0 | 4259 } |
4260 } | |
4261 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4262 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
|
4263 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
|
4264 |
0 | 4265 void Par_ConcMarkingClosure::trim_queue(size_t max) { |
4266 while (_work_queue->size() > max) { | |
4267 oop new_oop; | |
4268 if (_work_queue->pop_local(new_oop)) { | |
4269 assert(new_oop->is_oop(), "Should be an oop"); | |
4270 assert(_bit_map->isMarked((HeapWord*)new_oop), "Grey object"); | |
4271 assert(_span.contains((HeapWord*)new_oop), "Not in span"); | |
4272 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
|
4273 do_yield_check(); |
0 | 4274 } |
4275 } | |
4276 } | |
4277 | |
4278 // Upon stack overflow, we discard (part of) the stack, | |
4279 // remembering the least address amongst those discarded | |
4280 // in CMSCollector's _restart_address. | |
4281 void Par_ConcMarkingClosure::handle_stack_overflow(HeapWord* lost) { | |
4282 // 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
|
4283 // workers from interfering with the work done below. |
0 | 4284 MutexLockerEx ml(_overflow_stack->par_lock(), |
4285 Mutex::_no_safepoint_check_flag); | |
4286 // Remember the least grey address discarded | |
4287 HeapWord* ra = (HeapWord*)_overflow_stack->least_value(lost); | |
4288 _collector->lower_restart_addr(ra); | |
4289 _overflow_stack->reset(); // discard stack contents | |
4290 _overflow_stack->expand(); // expand the stack if possible | |
4291 } | |
4292 | |
4293 | |
4294 void CMSConcMarkingTask::do_work_steal(int i) { | |
4295 OopTaskQueue* work_q = work_queue(i); | |
4296 oop obj_to_scan; | |
4297 CMSBitMap* bm = &(_collector->_markBitMap); | |
4298 CMSMarkStack* ovflw = &(_collector->_markStack); | |
4299 int* seed = _collector->hash_seed(i); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4300 Par_ConcMarkingClosure cl(_collector, this, work_q, bm, ovflw); |
0 | 4301 while (true) { |
4302 cl.trim_queue(0); | |
4303 assert(work_q->size() == 0, "Should have been emptied above"); | |
4304 if (get_work_from_overflow_stack(ovflw, work_q)) { | |
4305 // Can't assert below because the work obtained from the | |
4306 // overflow stack may already have been stolen from us. | |
4307 // assert(work_q->size() > 0, "Work from overflow stack"); | |
4308 continue; | |
4309 } else if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
4310 assert(obj_to_scan->is_oop(), "Should be an oop"); | |
4311 assert(bm->isMarked((HeapWord*)obj_to_scan), "Grey object"); | |
4312 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
|
4313 } else if (terminator()->offer_termination(&_term_term)) { |
0 | 4314 assert(work_q->size() == 0, "Impossible!"); |
4315 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
|
4316 } 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
|
4317 yield(); |
0 | 4318 } |
4319 } | |
4320 } | |
4321 | |
4322 // This is run by the CMS (coordinator) thread. | |
4323 void CMSConcMarkingTask::coordinator_yield() { | |
4324 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
4325 "CMS thread should hold CMS token"); | |
4326 // First give up the locks, then yield, then re-lock | |
4327 // We should probably use a constructor/destructor idiom to | |
4328 // do this unlock/lock or modify the MutexUnlocker class to | |
4329 // serve our purpose. XXX | |
4330 assert_lock_strong(_bit_map_lock); | |
4331 _bit_map_lock->unlock(); | |
4332 ConcurrentMarkSweepThread::desynchronize(true); | |
4333 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
4334 _collector->stopTimer(); | |
4335 if (PrintCMSStatistics != 0) { | |
4336 _collector->incrementYields(); | |
4337 } | |
4338 _collector->icms_wait(); | |
4339 | |
4340 // It is possible for whichever thread initiated the yield request | |
4341 // not to get a chance to wake up and take the bitmap lock between | |
4342 // this thread releasing it and reacquiring it. So, while the | |
4343 // should_yield() flag is on, let's sleep for a bit to give the | |
4344 // other thread a chance to wake up. The limit imposed on the number | |
4345 // of iterations is defensive, to avoid any unforseen circumstances | |
4346 // putting us into an infinite loop. Since it's always been this | |
4347 // (coordinator_yield()) method that was observed to cause the | |
4348 // problem, we are using a parameter (CMSCoordinatorYieldSleepCount) | |
4349 // which is by default non-zero. For the other seven methods that | |
4350 // also perform the yield operation, as are using a different | |
4351 // parameter (CMSYieldSleepCount) which is by default zero. This way we | |
4352 // can enable the sleeping for those methods too, if necessary. | |
4353 // See 6442774. | |
4354 // | |
4355 // We really need to reconsider the synchronization between the GC | |
4356 // thread and the yield-requesting threads in the future and we | |
4357 // should really use wait/notify, which is the recommended | |
4358 // way of doing this type of interaction. Additionally, we should | |
4359 // consolidate the eight methods that do the yield operation and they | |
4360 // are almost identical into one for better maintenability and | |
4361 // readability. See 6445193. | |
4362 // | |
4363 // Tony 2006.06.29 | |
4364 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
|
4365 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
4366 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 4367 os::sleep(Thread::current(), 1, false); |
4368 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
4369 } | |
4370 | |
4371 ConcurrentMarkSweepThread::synchronize(true); | |
4372 _bit_map_lock->lock_without_safepoint_check(); | |
4373 _collector->startTimer(); | |
4374 } | |
4375 | |
4376 bool CMSCollector::do_marking_mt(bool asynch) { | |
1284 | 4377 assert(ConcGCThreads > 0 && conc_workers() != NULL, "precondition"); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4378 int num_workers = AdaptiveSizePolicy::calc_active_conc_workers( |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4379 conc_workers()->total_workers(), |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4380 conc_workers()->active_workers(), |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4381 Threads::number_of_non_daemon_threads()); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
4382 conc_workers()->set_active_workers(num_workers); |
0 | 4383 |
4384 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); | |
4385 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4386 CMSConcMarkingTask tsk(this, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4387 cms_space, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4388 asynch, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4389 conc_workers(), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
4390 task_queues()); |
0 | 4391 |
4392 // Since the actual number of workers we get may be different | |
4393 // from the number we requested above, do we need to do anything different | |
4394 // below? In particular, may be we need to subclass the SequantialSubTasksDone | |
4395 // class?? XXX | |
4396 cms_space ->initialize_sequential_subtasks_for_marking(num_workers); | |
4397 | |
4398 // Refs discovery is already non-atomic. | |
4399 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
|
4400 assert(ref_processor()->discovery_is_mt(), "Discovery should be MT"); |
0 | 4401 conc_workers()->start_task(&tsk); |
4402 while (tsk.yielded()) { | |
4403 tsk.coordinator_yield(); | |
4404 conc_workers()->continue_task(&tsk); | |
4405 } | |
4406 // If the task was aborted, _restart_addr will be non-NULL | |
4407 assert(tsk.completed() || _restart_addr != NULL, "Inconsistency"); | |
4408 while (_restart_addr != NULL) { | |
4409 // XXX For now we do not make use of ABORTED state and have not | |
4410 // yet implemented the right abort semantics (even in the original | |
4411 // single-threaded CMS case). That needs some more investigation | |
4412 // and is deferred for now; see CR# TBF. 07252005YSR. XXX | |
4413 assert(!CMSAbortSemantics || tsk.aborted(), "Inconsistency"); | |
4414 // If _restart_addr is non-NULL, a marking stack overflow | |
605 | 4415 // occurred; we need to do a fresh marking iteration from the |
0 | 4416 // indicated restart address. |
4417 if (_foregroundGCIsActive && asynch) { | |
4418 // We may be running into repeated stack overflows, having | |
4419 // reached the limit of the stack size, while making very | |
4420 // slow forward progress. It may be best to bail out and | |
4421 // let the foreground collector do its job. | |
4422 // Clear _restart_addr, so that foreground GC | |
4423 // works from scratch. This avoids the headache of | |
4424 // a "rescan" which would otherwise be needed because | |
4425 // of the dirty mod union table & card table. | |
4426 _restart_addr = NULL; | |
4427 return false; | |
4428 } | |
4429 // Adjust the task to restart from _restart_addr | |
4430 tsk.reset(_restart_addr); | |
4431 cms_space ->initialize_sequential_subtasks_for_marking(num_workers, | |
4432 _restart_addr); | |
4433 _restart_addr = NULL; | |
4434 // Get the workers going again | |
4435 conc_workers()->start_task(&tsk); | |
4436 while (tsk.yielded()) { | |
4437 tsk.coordinator_yield(); | |
4438 conc_workers()->continue_task(&tsk); | |
4439 } | |
4440 } | |
4441 assert(tsk.completed(), "Inconsistency"); | |
4442 assert(tsk.result() == true, "Inconsistency"); | |
4443 return true; | |
4444 } | |
4445 | |
4446 bool CMSCollector::do_marking_st(bool asynch) { | |
4447 ResourceMark rm; | |
4448 HandleMark hm; | |
4449 | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4450 // Temporarily make refs discovery single threaded (non-MT) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4451 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(ref_processor(), false); |
0 | 4452 MarkFromRootsClosure markFromRootsClosure(this, _span, &_markBitMap, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4453 &_markStack, CMSYield && asynch); |
0 | 4454 // the last argument to iterate indicates whether the iteration |
4455 // should be incremental with periodic yields. | |
4456 _markBitMap.iterate(&markFromRootsClosure); | |
4457 // If _restart_addr is non-NULL, a marking stack overflow | |
605 | 4458 // occurred; we need to do a fresh iteration from the |
0 | 4459 // indicated restart address. |
4460 while (_restart_addr != NULL) { | |
4461 if (_foregroundGCIsActive && asynch) { | |
4462 // We may be running into repeated stack overflows, having | |
4463 // reached the limit of the stack size, while making very | |
4464 // slow forward progress. It may be best to bail out and | |
4465 // let the foreground collector do its job. | |
4466 // Clear _restart_addr, so that foreground GC | |
4467 // works from scratch. This avoids the headache of | |
4468 // a "rescan" which would otherwise be needed because | |
4469 // of the dirty mod union table & card table. | |
4470 _restart_addr = NULL; | |
4471 return false; // indicating failure to complete marking | |
4472 } | |
4473 // Deal with stack overflow: | |
4474 // we restart marking from _restart_addr | |
4475 HeapWord* ra = _restart_addr; | |
4476 markFromRootsClosure.reset(ra); | |
4477 _restart_addr = NULL; | |
4478 _markBitMap.iterate(&markFromRootsClosure, ra, _span.end()); | |
4479 } | |
4480 return true; | |
4481 } | |
4482 | |
4483 void CMSCollector::preclean() { | |
4484 check_correct_thread_executing(); | |
4485 assert(Thread::current()->is_ConcurrentGC_thread(), "Wrong thread"); | |
4486 verify_work_stacks_empty(); | |
4487 verify_overflow_empty(); | |
4488 _abort_preclean = false; | |
4489 if (CMSPrecleaningEnabled) { | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4490 if (!CMSEdenChunksRecordAlways) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4491 _eden_chunk_index = 0; |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4492 } |
0 | 4493 size_t used = get_eden_used(); |
4494 size_t capacity = get_eden_capacity(); | |
4495 // Don't start sampling unless we will get sufficiently | |
4496 // many samples. | |
4497 if (used < (capacity/(CMSScheduleRemarkSamplingRatio * 100) | |
4498 * CMSScheduleRemarkEdenPenetration)) { | |
4499 _start_sampling = true; | |
4500 } else { | |
4501 _start_sampling = false; | |
4502 } | |
4503 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
4504 CMSPhaseAccounting pa(this, "preclean", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 4505 preclean_work(CMSPrecleanRefLists1, CMSPrecleanSurvivors1); |
4506 } | |
4507 CMSTokenSync x(true); // is cms thread | |
4508 if (CMSPrecleaningEnabled) { | |
4509 sample_eden(); | |
4510 _collectorState = AbortablePreclean; | |
4511 } else { | |
4512 _collectorState = FinalMarking; | |
4513 } | |
4514 verify_work_stacks_empty(); | |
4515 verify_overflow_empty(); | |
4516 } | |
4517 | |
4518 // Try and schedule the remark such that young gen | |
4519 // occupancy is CMSScheduleRemarkEdenPenetration %. | |
4520 void CMSCollector::abortable_preclean() { | |
4521 check_correct_thread_executing(); | |
4522 assert(CMSPrecleaningEnabled, "Inconsistent control state"); | |
4523 assert(_collectorState == AbortablePreclean, "Inconsistent control state"); | |
4524 | |
4525 // If Eden's current occupancy is below this threshold, | |
4526 // immediately schedule the remark; else preclean | |
4527 // past the next scavenge in an effort to | |
4528 // schedule the pause as described avove. By choosing | |
4529 // CMSScheduleRemarkEdenSizeThreshold >= max eden size | |
4530 // we will never do an actual abortable preclean cycle. | |
4531 if (get_eden_used() > CMSScheduleRemarkEdenSizeThreshold) { | |
4532 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
4533 CMSPhaseAccounting pa(this, "abortable-preclean", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 4534 // We need more smarts in the abortable preclean |
4535 // loop below to deal with cases where allocation | |
4536 // in young gen is very very slow, and our precleaning | |
4537 // is running a losing race against a horde of | |
4538 // mutators intent on flooding us with CMS updates | |
4539 // (dirty cards). | |
4540 // One, admittedly dumb, strategy is to give up | |
4541 // after a certain number of abortable precleaning loops | |
4542 // or after a certain maximum time. We want to make | |
4543 // this smarter in the next iteration. | |
4544 // XXX FIX ME!!! YSR | |
4545 size_t loops = 0, workdone = 0, cumworkdone = 0, waited = 0; | |
4546 while (!(should_abort_preclean() || | |
4547 ConcurrentMarkSweepThread::should_terminate())) { | |
4548 workdone = preclean_work(CMSPrecleanRefLists2, CMSPrecleanSurvivors2); | |
4549 cumworkdone += workdone; | |
4550 loops++; | |
4551 // Voluntarily terminate abortable preclean phase if we have | |
4552 // been at it for too long. | |
4553 if ((CMSMaxAbortablePrecleanLoops != 0) && | |
4554 loops >= CMSMaxAbortablePrecleanLoops) { | |
4555 if (PrintGCDetails) { | |
4556 gclog_or_tty->print(" CMS: abort preclean due to loops "); | |
4557 } | |
4558 break; | |
4559 } | |
4560 if (pa.wallclock_millis() > CMSMaxAbortablePrecleanTime) { | |
4561 if (PrintGCDetails) { | |
4562 gclog_or_tty->print(" CMS: abort preclean due to time "); | |
4563 } | |
4564 break; | |
4565 } | |
4566 // If we are doing little work each iteration, we should | |
4567 // take a short break. | |
4568 if (workdone < CMSAbortablePrecleanMinWorkPerIteration) { | |
4569 // Sleep for some time, waiting for work to accumulate | |
4570 stopTimer(); | |
4571 cmsThread()->wait_on_cms_lock(CMSAbortablePrecleanWaitMillis); | |
4572 startTimer(); | |
4573 waited++; | |
4574 } | |
4575 } | |
4576 if (PrintCMSStatistics > 0) { | |
4577 gclog_or_tty->print(" [%d iterations, %d waits, %d cards)] ", | |
4578 loops, waited, cumworkdone); | |
4579 } | |
4580 } | |
4581 CMSTokenSync x(true); // is cms thread | |
4582 if (_collectorState != Idling) { | |
4583 assert(_collectorState == AbortablePreclean, | |
4584 "Spontaneous state transition?"); | |
4585 _collectorState = FinalMarking; | |
4586 } // Else, a foreground collection completed this CMS cycle. | |
4587 return; | |
4588 } | |
4589 | |
4590 // Respond to an Eden sampling opportunity | |
4591 void CMSCollector::sample_eden() { | |
4592 // Make sure a young gc cannot sneak in between our | |
4593 // reading and recording of a sample. | |
4594 assert(Thread::current()->is_ConcurrentGC_thread(), | |
4595 "Only the cms thread may collect Eden samples"); | |
4596 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
4597 "Should collect samples while holding CMS token"); | |
4598 if (!_start_sampling) { | |
4599 return; | |
4600 } | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4601 // When CMSEdenChunksRecordAlways is true, the eden chunk array |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4602 // is populated by the young generation. |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
4603 if (_eden_chunk_array != NULL && !CMSEdenChunksRecordAlways) { |
0 | 4604 if (_eden_chunk_index < _eden_chunk_capacity) { |
4605 _eden_chunk_array[_eden_chunk_index] = *_top_addr; // take sample | |
4606 assert(_eden_chunk_array[_eden_chunk_index] <= *_end_addr, | |
4607 "Unexpected state of Eden"); | |
4608 // We'd like to check that what we just sampled is an oop-start address; | |
4609 // however, we cannot do that here since the object may not yet have been | |
4610 // initialized. So we'll instead do the check when we _use_ this sample | |
4611 // later. | |
4612 if (_eden_chunk_index == 0 || | |
4613 (pointer_delta(_eden_chunk_array[_eden_chunk_index], | |
4614 _eden_chunk_array[_eden_chunk_index-1]) | |
4615 >= CMSSamplingGrain)) { | |
4616 _eden_chunk_index++; // commit sample | |
4617 } | |
4618 } | |
4619 } | |
4620 if ((_collectorState == AbortablePreclean) && !_abort_preclean) { | |
4621 size_t used = get_eden_used(); | |
4622 size_t capacity = get_eden_capacity(); | |
4623 assert(used <= capacity, "Unexpected state of Eden"); | |
4624 if (used > (capacity/100 * CMSScheduleRemarkEdenPenetration)) { | |
4625 _abort_preclean = true; | |
4626 } | |
4627 } | |
4628 } | |
4629 | |
4630 | |
4631 size_t CMSCollector::preclean_work(bool clean_refs, bool clean_survivor) { | |
4632 assert(_collectorState == Precleaning || | |
4633 _collectorState == AbortablePreclean, "incorrect state"); | |
4634 ResourceMark rm; | |
4635 HandleMark hm; | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4636 |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4637 // Precleaning is currently not MT but the reference processor |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4638 // may be set for MT. Disable it temporarily here. |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4639 ReferenceProcessor* rp = ref_processor(); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4640 ReferenceProcessorMTDiscoveryMutator rp_mut_discovery(rp, false); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
4641 |
0 | 4642 // Do one pass of scrubbing the discovered reference lists |
4643 // to remove any reference objects with strongly-reachable | |
4644 // referents. | |
4645 if (clean_refs) { | |
4646 CMSPrecleanRefsYieldClosure yield_cl(this); | |
4647 assert(rp->span().equals(_span), "Spans should be equal"); | |
4648 CMSKeepAliveClosure keep_alive(this, _span, &_markBitMap, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4649 &_markStack, true /* preclean */); |
0 | 4650 CMSDrainMarkingStackClosure complete_trace(this, |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
4651 _span, &_markBitMap, &_markStack, |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
4652 &keep_alive, true /* preclean */); |
0 | 4653 |
4654 // We don't want this step to interfere with a young | |
4655 // collection because we don't want to take CPU | |
4656 // or memory bandwidth away from the young GC threads | |
4657 // (which may be as many as there are CPUs). | |
4658 // Note that we don't need to protect ourselves from | |
4659 // interference with mutators because they can't | |
4660 // manipulate the discovered reference lists nor affect | |
4661 // the computed reachability of the referents, the | |
4662 // only properties manipulated by the precleaning | |
4663 // of these reference lists. | |
4664 stopTimer(); | |
4665 CMSTokenSyncWithLocks x(true /* is cms thread */, | |
4666 bitMapLock()); | |
4667 startTimer(); | |
4668 sample_eden(); | |
935 | 4669 |
0 | 4670 // The following will yield to allow foreground |
4671 // collection to proceed promptly. XXX YSR: | |
4672 // The code in this method may need further | |
4673 // tweaking for better performance and some restructuring | |
4674 // for cleaner interfaces. | |
10405 | 4675 GCTimer *gc_timer = NULL; // Currently not tracing concurrent phases |
0 | 4676 rp->preclean_discovered_references( |
10405 | 4677 rp->is_alive_non_header(), &keep_alive, &complete_trace, &yield_cl, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
4678 gc_timer, _gc_tracer_cm->gc_id()); |
0 | 4679 } |
4680 | |
4681 if (clean_survivor) { // preclean the active survivor space(s) | |
4682 assert(_young_gen->kind() == Generation::DefNew || | |
4683 _young_gen->kind() == Generation::ParNew || | |
4684 _young_gen->kind() == Generation::ASParNew, | |
4685 "incorrect type for cast"); | |
4686 DefNewGeneration* dng = (DefNewGeneration*)_young_gen; | |
4687 PushAndMarkClosure pam_cl(this, _span, ref_processor(), | |
4688 &_markBitMap, &_modUnionTable, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4689 &_markStack, true /* precleaning phase */); |
0 | 4690 stopTimer(); |
4691 CMSTokenSyncWithLocks ts(true /* is cms thread */, | |
4692 bitMapLock()); | |
4693 startTimer(); | |
4694 unsigned int before_count = | |
4695 GenCollectedHeap::heap()->total_collections(); | |
4696 SurvivorSpacePrecleanClosure | |
4697 sss_cl(this, _span, &_markBitMap, &_markStack, | |
4698 &pam_cl, before_count, CMSYield); | |
4699 dng->from()->object_iterate_careful(&sss_cl); | |
4700 dng->to()->object_iterate_careful(&sss_cl); | |
4701 } | |
4702 MarkRefsIntoAndScanClosure | |
4703 mrias_cl(_span, ref_processor(), &_markBitMap, &_modUnionTable, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4704 &_markStack, this, CMSYield, |
0 | 4705 true /* precleaning phase */); |
4706 // CAUTION: The following closure has persistent state that may need to | |
4707 // be reset upon a decrease in the sequence of addresses it | |
4708 // processes. | |
4709 ScanMarkedObjectsAgainCarefullyClosure | |
4710 smoac_cl(this, _span, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4711 &_markBitMap, &_markStack, &mrias_cl, CMSYield); |
0 | 4712 |
4713 // Preclean dirty cards in ModUnionTable and CardTable using | |
4714 // appropriate convergence criterion; | |
4715 // repeat CMSPrecleanIter times unless we find that | |
4716 // we are losing. | |
4717 assert(CMSPrecleanIter < 10, "CMSPrecleanIter is too large"); | |
4718 assert(CMSPrecleanNumerator < CMSPrecleanDenominator, | |
4719 "Bad convergence multiplier"); | |
4720 assert(CMSPrecleanThreshold >= 100, | |
4721 "Unreasonably low CMSPrecleanThreshold"); | |
4722 | |
4723 size_t numIter, cumNumCards, lastNumCards, curNumCards; | |
4724 for (numIter = 0, cumNumCards = lastNumCards = curNumCards = 0; | |
4725 numIter < CMSPrecleanIter; | |
4726 numIter++, lastNumCards = curNumCards, cumNumCards += curNumCards) { | |
4727 curNumCards = preclean_mod_union_table(_cmsGen, &smoac_cl); | |
4728 if (Verbose && PrintGCDetails) { | |
4729 gclog_or_tty->print(" (modUnionTable: %d cards)", curNumCards); | |
4730 } | |
4731 // Either there are very few dirty cards, so re-mark | |
4732 // pause will be small anyway, or our pre-cleaning isn't | |
4733 // that much faster than the rate at which cards are being | |
4734 // dirtied, so we might as well stop and re-mark since | |
4735 // precleaning won't improve our re-mark time by much. | |
4736 if (curNumCards <= CMSPrecleanThreshold || | |
4737 (numIter > 0 && | |
4738 (curNumCards * CMSPrecleanDenominator > | |
4739 lastNumCards * CMSPrecleanNumerator))) { | |
4740 numIter++; | |
4741 cumNumCards += curNumCards; | |
4742 break; | |
4743 } | |
4744 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4745 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4746 preclean_klasses(&mrias_cl, _cmsGen->freelistLock()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4747 |
0 | 4748 curNumCards = preclean_card_table(_cmsGen, &smoac_cl); |
4749 cumNumCards += curNumCards; | |
4750 if (PrintGCDetails && PrintCMSStatistics != 0) { | |
4751 gclog_or_tty->print_cr(" (cardTable: %d cards, re-scanned %d cards, %d iterations)", | |
4752 curNumCards, cumNumCards, numIter); | |
4753 } | |
4754 return cumNumCards; // as a measure of useful work done | |
4755 } | |
4756 | |
4757 // PRECLEANING NOTES: | |
4758 // Precleaning involves: | |
4759 // . reading the bits of the modUnionTable and clearing the set bits. | |
4760 // . For the cards corresponding to the set bits, we scan the | |
4761 // objects on those cards. This means we need the free_list_lock | |
4762 // so that we can safely iterate over the CMS space when scanning | |
4763 // for oops. | |
4764 // . When we scan the objects, we'll be both reading and setting | |
4765 // marks in the marking bit map, so we'll need the marking bit map. | |
4766 // . For protecting _collector_state transitions, we take the CGC_lock. | |
4767 // Note that any races in the reading of of card table entries by the | |
4768 // CMS thread on the one hand and the clearing of those entries by the | |
4769 // VM thread or the setting of those entries by the mutator threads on the | |
4770 // other are quite benign. However, for efficiency it makes sense to keep | |
4771 // the VM thread from racing with the CMS thread while the latter is | |
4772 // dirty card info to the modUnionTable. We therefore also use the | |
4773 // CGC_lock to protect the reading of the card table and the mod union | |
4774 // table by the CM thread. | |
4775 // . We run concurrently with mutator updates, so scanning | |
4776 // needs to be done carefully -- we should not try to scan | |
4777 // potentially uninitialized objects. | |
4778 // | |
4779 // Locking strategy: While holding the CGC_lock, we scan over and | |
4780 // reset a maximal dirty range of the mod union / card tables, then lock | |
4781 // the free_list_lock and bitmap lock to do a full marking, then | |
4782 // release these locks; and repeat the cycle. This allows for a | |
4783 // certain amount of fairness in the sharing of these locks between | |
4784 // the CMS collector on the one hand, and the VM thread and the | |
4785 // mutators on the other. | |
4786 | |
4787 // NOTE: preclean_mod_union_table() and preclean_card_table() | |
4788 // further below are largely identical; if you need to modify | |
4789 // one of these methods, please check the other method too. | |
4790 | |
4791 size_t CMSCollector::preclean_mod_union_table( | |
4792 ConcurrentMarkSweepGeneration* gen, | |
4793 ScanMarkedObjectsAgainCarefullyClosure* cl) { | |
4794 verify_work_stacks_empty(); | |
4795 verify_overflow_empty(); | |
4796 | |
4797 // strategy: starting with the first card, accumulate contiguous | |
4798 // ranges of dirty cards; clear these cards, then scan the region | |
4799 // covered by these cards. | |
4800 | |
4801 // Since all of the MUT is committed ahead, we can just use | |
4802 // that, in case the generations expand while we are precleaning. | |
4803 // It might also be fine to just use the committed part of the | |
4804 // generation, but we might potentially miss cards when the | |
4805 // generation is rapidly expanding while we are in the midst | |
4806 // of precleaning. | |
4807 HeapWord* startAddr = gen->reserved().start(); | |
4808 HeapWord* endAddr = gen->reserved().end(); | |
4809 | |
4810 cl->setFreelistLock(gen->freelistLock()); // needed for yielding | |
4811 | |
4812 size_t numDirtyCards, cumNumDirtyCards; | |
4813 HeapWord *nextAddr, *lastAddr; | |
4814 for (cumNumDirtyCards = numDirtyCards = 0, | |
4815 nextAddr = lastAddr = startAddr; | |
4816 nextAddr < endAddr; | |
4817 nextAddr = lastAddr, cumNumDirtyCards += numDirtyCards) { | |
4818 | |
4819 ResourceMark rm; | |
4820 HandleMark hm; | |
4821 | |
4822 MemRegion dirtyRegion; | |
4823 { | |
4824 stopTimer(); | |
935 | 4825 // Potential yield point |
0 | 4826 CMSTokenSync ts(true); |
4827 startTimer(); | |
4828 sample_eden(); | |
4829 // Get dirty region starting at nextOffset (inclusive), | |
4830 // simultaneously clearing it. | |
4831 dirtyRegion = | |
4832 _modUnionTable.getAndClearMarkedRegion(nextAddr, endAddr); | |
4833 assert(dirtyRegion.start() >= nextAddr, | |
4834 "returned region inconsistent?"); | |
4835 } | |
4836 // Remember where the next search should begin. | |
4837 // The returned region (if non-empty) is a right open interval, | |
4838 // so lastOffset is obtained from the right end of that | |
4839 // interval. | |
4840 lastAddr = dirtyRegion.end(); | |
4841 // Should do something more transparent and less hacky XXX | |
4842 numDirtyCards = | |
4843 _modUnionTable.heapWordDiffToOffsetDiff(dirtyRegion.word_size()); | |
4844 | |
4845 // We'll scan the cards in the dirty region (with periodic | |
4846 // yields for foreground GC as needed). | |
4847 if (!dirtyRegion.is_empty()) { | |
4848 assert(numDirtyCards > 0, "consistency check"); | |
4849 HeapWord* stop_point = NULL; | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4850 stopTimer(); |
935 | 4851 // Potential yield point |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4852 CMSTokenSyncWithLocks ts(true, gen->freelistLock(), |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4853 bitMapLock()); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
4854 startTimer(); |
0 | 4855 { |
4856 verify_work_stacks_empty(); | |
4857 verify_overflow_empty(); | |
4858 sample_eden(); | |
4859 stop_point = | |
4860 gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); | |
4861 } | |
4862 if (stop_point != NULL) { | |
4863 // The careful iteration stopped early either because it found an | |
4864 // uninitialized object, or because we were in the midst of an | |
4865 // "abortable preclean", which should now be aborted. Redirty | |
4866 // the bits corresponding to the partially-scanned or unscanned | |
4867 // cards. We'll either restart at the next block boundary or | |
4868 // abort the preclean. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4869 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4870 "Should only be AbortablePreclean."); |
0 | 4871 _modUnionTable.mark_range(MemRegion(stop_point, dirtyRegion.end())); |
4872 if (should_abort_preclean()) { | |
4873 break; // out of preclean loop | |
4874 } else { | |
4875 // Compute the next address at which preclean should pick up; | |
4876 // might need bitMapLock in order to read P-bits. | |
4877 lastAddr = next_card_start_after_block(stop_point); | |
4878 } | |
4879 } | |
4880 } else { | |
4881 assert(lastAddr == endAddr, "consistency check"); | |
4882 assert(numDirtyCards == 0, "consistency check"); | |
4883 break; | |
4884 } | |
4885 } | |
4886 verify_work_stacks_empty(); | |
4887 verify_overflow_empty(); | |
4888 return cumNumDirtyCards; | |
4889 } | |
4890 | |
4891 // NOTE: preclean_mod_union_table() above and preclean_card_table() | |
4892 // below are largely identical; if you need to modify | |
4893 // one of these methods, please check the other method too. | |
4894 | |
4895 size_t CMSCollector::preclean_card_table(ConcurrentMarkSweepGeneration* gen, | |
4896 ScanMarkedObjectsAgainCarefullyClosure* cl) { | |
4897 // strategy: it's similar to precleamModUnionTable above, in that | |
4898 // we accumulate contiguous ranges of dirty cards, mark these cards | |
4899 // precleaned, then scan the region covered by these cards. | |
4900 HeapWord* endAddr = (HeapWord*)(gen->_virtual_space.high()); | |
4901 HeapWord* startAddr = (HeapWord*)(gen->_virtual_space.low()); | |
4902 | |
4903 cl->setFreelistLock(gen->freelistLock()); // needed for yielding | |
4904 | |
4905 size_t numDirtyCards, cumNumDirtyCards; | |
4906 HeapWord *lastAddr, *nextAddr; | |
4907 | |
4908 for (cumNumDirtyCards = numDirtyCards = 0, | |
4909 nextAddr = lastAddr = startAddr; | |
4910 nextAddr < endAddr; | |
4911 nextAddr = lastAddr, cumNumDirtyCards += numDirtyCards) { | |
4912 | |
4913 ResourceMark rm; | |
4914 HandleMark hm; | |
4915 | |
4916 MemRegion dirtyRegion; | |
4917 { | |
4918 // See comments in "Precleaning notes" above on why we | |
4919 // do this locking. XXX Could the locking overheads be | |
4920 // too high when dirty cards are sparse? [I don't think so.] | |
4921 stopTimer(); | |
4922 CMSTokenSync x(true); // is cms thread | |
4923 startTimer(); | |
4924 sample_eden(); | |
4925 // Get and clear dirty region from card table | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4926 dirtyRegion = _ct->ct_bs()->dirty_card_range_after_reset( |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4927 MemRegion(nextAddr, endAddr), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4928 true, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4929 CardTableModRefBS::precleaned_card_val()); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
4930 |
0 | 4931 assert(dirtyRegion.start() >= nextAddr, |
4932 "returned region inconsistent?"); | |
4933 } | |
4934 lastAddr = dirtyRegion.end(); | |
4935 numDirtyCards = | |
4936 dirtyRegion.word_size()/CardTableModRefBS::card_size_in_words; | |
4937 | |
4938 if (!dirtyRegion.is_empty()) { | |
4939 stopTimer(); | |
4940 CMSTokenSyncWithLocks ts(true, gen->freelistLock(), bitMapLock()); | |
4941 startTimer(); | |
4942 sample_eden(); | |
4943 verify_work_stacks_empty(); | |
4944 verify_overflow_empty(); | |
4945 HeapWord* stop_point = | |
4946 gen->cmsSpace()->object_iterate_careful_m(dirtyRegion, cl); | |
4947 if (stop_point != NULL) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4948 assert((_collectorState == AbortablePreclean && should_abort_preclean()), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4949 "Should only be AbortablePreclean."); |
0 | 4950 _ct->ct_bs()->invalidate(MemRegion(stop_point, dirtyRegion.end())); |
4951 if (should_abort_preclean()) { | |
4952 break; // out of preclean loop | |
4953 } else { | |
4954 // Compute the next address at which preclean should pick up. | |
4955 lastAddr = next_card_start_after_block(stop_point); | |
4956 } | |
4957 } | |
4958 } else { | |
4959 break; | |
4960 } | |
4961 } | |
4962 verify_work_stacks_empty(); | |
4963 verify_overflow_empty(); | |
4964 return cumNumDirtyCards; | |
4965 } | |
4966 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4967 class PrecleanKlassClosure : public KlassClosure { |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
4968 KlassToOopClosure _cm_klass_closure; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4969 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4970 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
|
4971 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4972 if (k->has_accumulated_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4973 k->clear_accumulated_modified_oops(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4974 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4975 _cm_klass_closure.do_klass(k); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4976 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4977 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4978 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4979 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4980 // 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
|
4981 void CMSCollector::preclean_klasses(MarkRefsIntoAndScanClosure* cl, Mutex* freelistLock) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4982 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4983 cl->set_freelistLock(freelistLock); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4984 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4985 CMSTokenSyncWithLocks ts(true, freelistLock, bitMapLock()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4986 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4987 // 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
|
4988 // 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
|
4989 PrecleanKlassClosure preclean_klass_closure(cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4990 ClassLoaderDataGraph::classes_do(&preclean_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4991 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4992 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4993 verify_overflow_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4994 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
4995 |
0 | 4996 void CMSCollector::checkpointRootsFinal(bool asynch, |
4997 bool clear_all_soft_refs, bool init_mark_was_synchronous) { | |
4998 assert(_collectorState == FinalMarking, "incorrect state transition?"); | |
4999 check_correct_thread_executing(); | |
5000 // world is stopped at this checkpoint | |
5001 assert(SafepointSynchronize::is_at_safepoint(), | |
5002 "world should be stopped"); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
5003 TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause()); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
5004 |
0 | 5005 verify_work_stacks_empty(); |
5006 verify_overflow_empty(); | |
5007 | |
5008 SpecializationStats::clear(); | |
5009 if (PrintGCDetails) { | |
5010 gclog_or_tty->print("[YG occupancy: "SIZE_FORMAT" K ("SIZE_FORMAT" K)]", | |
5011 _young_gen->used() / K, | |
5012 _young_gen->capacity() / K); | |
5013 } | |
5014 if (asynch) { | |
5015 if (CMSScavengeBeforeRemark) { | |
5016 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5017 // Temporarily set flag to false, GCH->do_collection will | |
5018 // expect it to be false and set to true | |
5019 FlagSetting fl(gch->_is_gc_active, false); | |
10405 | 5020 NOT_PRODUCT(GCTraceTime t("Scavenge-Before-Remark", |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5021 PrintGCDetails && Verbose, true, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5022 int level = _cmsGen->level() - 1; |
5023 if (level >= 0) { | |
5024 gch->do_collection(true, // full (i.e. force, see below) | |
5025 false, // !clear_all_soft_refs | |
5026 0, // size | |
5027 false, // is_tlab | |
5028 level // max_level | |
5029 ); | |
5030 } | |
5031 } | |
5032 FreelistLocker x(this); | |
5033 MutexLockerEx y(bitMapLock(), | |
5034 Mutex::_no_safepoint_check_flag); | |
5035 assert(!init_mark_was_synchronous, "but that's impossible!"); | |
5036 checkpointRootsFinalWork(asynch, clear_all_soft_refs, false); | |
5037 } else { | |
5038 // already have all the locks | |
5039 checkpointRootsFinalWork(asynch, clear_all_soft_refs, | |
5040 init_mark_was_synchronous); | |
5041 } | |
5042 verify_work_stacks_empty(); | |
5043 verify_overflow_empty(); | |
5044 SpecializationStats::print(); | |
5045 } | |
5046 | |
5047 void CMSCollector::checkpointRootsFinalWork(bool asynch, | |
5048 bool clear_all_soft_refs, bool init_mark_was_synchronous) { | |
5049 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5050 NOT_PRODUCT(GCTraceTime tr("checkpointRootsFinalWork", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5051 |
5052 assert(haveFreelistLocks(), "must have free list locks"); | |
5053 assert_lock_strong(bitMapLock()); | |
5054 | |
5055 if (UseAdaptiveSizePolicy) { | |
5056 size_policy()->checkpoint_roots_final_begin(); | |
5057 } | |
5058 | |
5059 ResourceMark rm; | |
5060 HandleMark hm; | |
5061 | |
5062 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5063 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
5064 if (should_unload_classes()) { |
0 | 5065 CodeCache::gc_prologue(); |
5066 } | |
5067 assert(haveFreelistLocks(), "must have free list locks"); | |
5068 assert_lock_strong(bitMapLock()); | |
5069 | |
5070 if (!init_mark_was_synchronous) { | |
5071 // We might assume that we need not fill TLAB's when | |
5072 // CMSScavengeBeforeRemark is set, because we may have just done | |
5073 // a scavenge which would have filled all TLAB's -- and besides | |
5074 // Eden would be empty. This however may not always be the case -- | |
5075 // for instance although we asked for a scavenge, it may not have | |
5076 // happened because of a JNI critical section. We probably need | |
5077 // a policy for deciding whether we can in that case wait until | |
5078 // the critical section releases and then do the remark following | |
5079 // the scavenge, and skip it here. In the absence of that policy, | |
5080 // or of an indication of whether the scavenge did indeed occur, | |
5081 // we cannot rely on TLAB's having been filled and must do | |
5082 // so here just in case a scavenge did not happen. | |
5083 gch->ensure_parsability(false); // fill TLAB's, but no need to retire them | |
5084 // Update the saved marks which may affect the root scans. | |
5085 gch->save_marks(); | |
5086 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5087 if (CMSPrintEdenSurvivorChunks) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5088 print_eden_and_survivor_chunk_arrays(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5089 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5090 |
0 | 5091 { |
5092 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact;) | |
5093 | |
5094 // Note on the role of the mod union table: | |
5095 // Since the marker in "markFromRoots" marks concurrently with | |
5096 // mutators, it is possible for some reachable objects not to have been | |
5097 // scanned. For instance, an only reference to an object A was | |
5098 // placed in object B after the marker scanned B. Unless B is rescanned, | |
5099 // A would be collected. Such updates to references in marked objects | |
5100 // are detected via the mod union table which is the set of all cards | |
5101 // dirtied since the first checkpoint in this GC cycle and prior to | |
5102 // the most recent young generation GC, minus those cleaned up by the | |
5103 // concurrent precleaning. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5104 if (CMSParallelRemarkEnabled && CollectedHeap::use_parallel_gc_threads()) { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5105 GCTraceTime t("Rescan (parallel) ", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5106 do_remark_parallel(); |
5107 } else { | |
10405 | 5108 GCTraceTime t("Rescan (non-parallel) ", PrintGCDetails, false, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5109 _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5110 do_remark_non_parallel(); |
5111 } | |
5112 } | |
5113 } else { | |
5114 assert(!asynch, "Can't have init_mark_was_synchronous in asynch mode"); | |
5115 // The initial mark was stop-world, so there's no rescanning to | |
5116 // do; go straight on to the next step below. | |
5117 } | |
5118 verify_work_stacks_empty(); | |
5119 verify_overflow_empty(); | |
5120 | |
5121 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5122 NOT_PRODUCT(GCTraceTime ts("refProcessingWork", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id());) |
0 | 5123 refProcessingWork(asynch, clear_all_soft_refs); |
5124 } | |
5125 verify_work_stacks_empty(); | |
5126 verify_overflow_empty(); | |
5127 | |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
5128 if (should_unload_classes()) { |
0 | 5129 CodeCache::gc_epilogue(); |
5130 } | |
2147
9afee0b9fc1d
7012505: BreakpointWithFullGC.sh fails with Internal Error (src/share/vm/oops/methodOop.cpp:220)
kamg
parents:
2137
diff
changeset
|
5131 JvmtiExport::gc_epilogue(); |
0 | 5132 |
5133 // If we encountered any (marking stack / work queue) overflow | |
5134 // events during the current CMS cycle, take appropriate | |
5135 // remedial measures, where possible, so as to try and avoid | |
5136 // recurrence of that condition. | |
5137 assert(_markStack.isEmpty(), "No grey objects"); | |
5138 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
|
5139 _ser_kac_ovflw + _ser_kac_preclean_ovflw; |
0 | 5140 if (ser_ovflw > 0) { |
5141 if (PrintCMSStatistics != 0) { | |
5142 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
|
5143 "(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
|
5144 ", kac_preclean="SIZE_FORMAT")", |
0 | 5145 _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
|
5146 _ser_kac_ovflw, _ser_kac_preclean_ovflw); |
0 | 5147 } |
5148 _markStack.expand(); | |
5149 _ser_pmc_remark_ovflw = 0; | |
5150 _ser_pmc_preclean_ovflw = 0; | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
5151 _ser_kac_preclean_ovflw = 0; |
0 | 5152 _ser_kac_ovflw = 0; |
5153 } | |
5154 if (_par_pmc_remark_ovflw > 0 || _par_kac_ovflw > 0) { | |
5155 if (PrintCMSStatistics != 0) { | |
5156 gclog_or_tty->print_cr("Work queue overflow (benign) " | |
5157 "(pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT")", | |
5158 _par_pmc_remark_ovflw, _par_kac_ovflw); | |
5159 } | |
5160 _par_pmc_remark_ovflw = 0; | |
5161 _par_kac_ovflw = 0; | |
5162 } | |
5163 if (PrintCMSStatistics != 0) { | |
5164 if (_markStack._hit_limit > 0) { | |
5165 gclog_or_tty->print_cr(" (benign) Hit max stack size limit ("SIZE_FORMAT")", | |
5166 _markStack._hit_limit); | |
5167 } | |
5168 if (_markStack._failed_double > 0) { | |
5169 gclog_or_tty->print_cr(" (benign) Failed stack doubling ("SIZE_FORMAT")," | |
5170 " current capacity "SIZE_FORMAT, | |
5171 _markStack._failed_double, | |
5172 _markStack.capacity()); | |
5173 } | |
5174 } | |
5175 _markStack._hit_limit = 0; | |
5176 _markStack._failed_double = 0; | |
5177 | |
5178 if ((VerifyAfterGC || VerifyDuringGC) && | |
5179 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
5180 verify_after_remark(); | |
5181 } | |
5182 | |
10405 | 5183 _gc_tracer_cm->report_object_count_after_gc(&_is_alive_closure); |
5184 | |
0 | 5185 // Change under the freelistLocks. |
5186 _collectorState = Sweeping; | |
5187 // Call isAllClear() under bitMapLock | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5188 assert(_modUnionTable.isAllClear(), |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5189 "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
|
5190 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
|
5191 "Should be clear by end of the final marking"); |
0 | 5192 if (UseAdaptiveSizePolicy) { |
5193 size_policy()->checkpoint_roots_final_end(gch->gc_cause()); | |
5194 } | |
5195 } | |
5196 | |
11975 | 5197 void CMSParInitialMarkTask::work(uint worker_id) { |
5198 elapsedTimer _timer; | |
5199 ResourceMark rm; | |
5200 HandleMark hm; | |
5201 | |
5202 // ---------- scan from roots -------------- | |
5203 _timer.start(); | |
5204 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5205 Par_MarkRefsIntoClosure par_mri_cl(_collector->_span, &(_collector->_markBitMap)); | |
5206 | |
5207 // ---------- young gen roots -------------- | |
5208 { | |
5209 work_on_young_gen_roots(worker_id, &par_mri_cl); | |
5210 _timer.stop(); | |
5211 if (PrintCMSStatistics != 0) { | |
5212 gclog_or_tty->print_cr( | |
5213 "Finished young gen initial mark scan work in %dth thread: %3.3f sec", | |
5214 worker_id, _timer.seconds()); | |
5215 } | |
5216 } | |
5217 | |
5218 // ---------- remaining roots -------------- | |
5219 _timer.reset(); | |
5220 _timer.start(); | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5221 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5222 CLDToOopClosure cld_closure(&par_mri_cl, true); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5223 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5224 gch->gen_process_roots(_collector->_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5225 false, // yg was scanned above |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5226 false, // this is parallel code |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5227 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5228 _collector->should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5229 &par_mri_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5230 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5231 &cld_closure); |
11975 | 5232 assert(_collector->should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
5233 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
11975 | 5234 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
5235 _timer.stop(); | |
5236 if (PrintCMSStatistics != 0) { | |
5237 gclog_or_tty->print_cr( | |
5238 "Finished remaining root initial mark scan work in %dth thread: %3.3f sec", | |
5239 worker_id, _timer.seconds()); | |
5240 } | |
5241 } | |
5242 | |
0 | 5243 // Parallel remark task |
11975 | 5244 class CMSParRemarkTask: public CMSParMarkTask { |
0 | 5245 CompactibleFreeListSpace* _cms_space; |
5246 | |
5247 // The per-thread work queues, available here for stealing. | |
5248 OopTaskQueueSet* _task_queues; | |
5249 ParallelTaskTerminator _term; | |
5250 | |
5251 public: | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5252 // 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
|
5253 // workers to be taken from the active workers in the work gang. |
0 | 5254 CMSParRemarkTask(CMSCollector* collector, |
5255 CompactibleFreeListSpace* cms_space, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5256 int n_workers, FlexibleWorkGang* workers, |
0 | 5257 OopTaskQueueSet* task_queues): |
11975 | 5258 CMSParMarkTask("Rescan roots and grey objects in parallel", |
5259 collector, n_workers), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5260 _cms_space(cms_space), |
0 | 5261 _task_queues(task_queues), |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5262 _term(n_workers, task_queues) { } |
0 | 5263 |
5264 OopTaskQueueSet* task_queues() { return _task_queues; } | |
5265 | |
5266 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
5267 | |
5268 ParallelTaskTerminator* terminator() { return &_term; } | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5269 int n_workers() { return _n_workers; } |
0 | 5270 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5271 void work(uint worker_id); |
0 | 5272 |
5273 private: | |
5274 // ... of dirty cards in old space | |
5275 void do_dirty_card_rescan_tasks(CompactibleFreeListSpace* sp, int i, | |
5276 Par_MarkRefsIntoAndScanClosure* cl); | |
5277 | |
5278 // ... work stealing for the above | |
5279 void do_work_steal(int i, Par_MarkRefsIntoAndScanClosure* cl, int* seed); | |
5280 }; | |
5281 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5282 class RemarkKlassClosure : public KlassClosure { |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
5283 KlassToOopClosure _cm_klass_closure; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5284 public: |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5285 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
|
5286 void do_klass(Klass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5287 // 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
|
5288 if (k->has_accumulated_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5289 k->clear_accumulated_modified_oops(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5290 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5291 // 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
|
5292 // 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
|
5293 } else if (k->has_modified_oops()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5294 // 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
|
5295 } else { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5296 // No modified oops in the Klass. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5297 return; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5298 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5299 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5300 // 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
|
5301 _cm_klass_closure.do_klass(k); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5302 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5303 }; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5304 |
11975 | 5305 void CMSParMarkTask::work_on_young_gen_roots(uint worker_id, OopsInGenClosure* cl) { |
5306 DefNewGeneration* dng = _collector->_young_gen->as_DefNewGeneration(); | |
5307 EdenSpace* eden_space = dng->eden(); | |
5308 ContiguousSpace* from_space = dng->from(); | |
5309 ContiguousSpace* to_space = dng->to(); | |
5310 | |
5311 HeapWord** eca = _collector->_eden_chunk_array; | |
5312 size_t ect = _collector->_eden_chunk_index; | |
5313 HeapWord** sca = _collector->_survivor_chunk_array; | |
5314 size_t sct = _collector->_survivor_chunk_index; | |
5315 | |
5316 assert(ect <= _collector->_eden_chunk_capacity, "out of bounds"); | |
5317 assert(sct <= _collector->_survivor_chunk_capacity, "out of bounds"); | |
5318 | |
5319 do_young_space_rescan(worker_id, cl, to_space, NULL, 0); | |
5320 do_young_space_rescan(worker_id, cl, from_space, sca, sct); | |
5321 do_young_space_rescan(worker_id, cl, eden_space, eca, ect); | |
5322 } | |
5323 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5324 // work_queue(i) is passed to the closure |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5325 // Par_MarkRefsIntoAndScanClosure. The "i" parameter |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5326 // 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
|
5327 // do_work_steal() to select the i-th task_queue. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5328 |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5329 void CMSParRemarkTask::work(uint worker_id) { |
0 | 5330 elapsedTimer _timer; |
5331 ResourceMark rm; | |
5332 HandleMark hm; | |
5333 | |
5334 // ---------- rescan from roots -------------- | |
5335 _timer.start(); | |
5336 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
5337 Par_MarkRefsIntoAndScanClosure par_mrias_cl(_collector, | |
5338 _collector->_span, _collector->ref_processor(), | |
5339 &(_collector->_markBitMap), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5340 work_queue(worker_id)); |
0 | 5341 |
5342 // Rescan young gen roots first since these are likely | |
5343 // coarsely partitioned and may, on that account, constitute | |
5344 // the critical path; thus, it's best to start off that | |
5345 // work first. | |
5346 // ---------- young gen roots -------------- | |
5347 { | |
11975 | 5348 work_on_young_gen_roots(worker_id, &par_mrias_cl); |
0 | 5349 _timer.stop(); |
5350 if (PrintCMSStatistics != 0) { | |
5351 gclog_or_tty->print_cr( | |
5352 "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
|
5353 worker_id, _timer.seconds()); |
0 | 5354 } |
5355 } | |
5356 | |
5357 // ---------- remaining roots -------------- | |
5358 _timer.reset(); | |
5359 _timer.start(); | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5360 gch->gen_process_roots(_collector->_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5361 false, // yg was scanned above |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5362 false, // this is parallel code |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5363 SharedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5364 _collector->should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5365 &par_mrias_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5366 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5367 NULL); // The dirty klasses will be handled below |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5368 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5369 assert(_collector->should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
5370 || (_collector->CMSCollector::roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5371 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
0 | 5372 _timer.stop(); |
5373 if (PrintCMSStatistics != 0) { | |
5374 gclog_or_tty->print_cr( | |
5375 "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
|
5376 worker_id, _timer.seconds()); |
0 | 5377 } |
5378 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5379 // ---------- unhandled CLD scanning ---------- |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5380 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
|
5381 _timer.reset(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5382 _timer.start(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5383 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5384 // 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
|
5385 // introduced during concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5386 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5387 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5388 for (int i = 0; i < array->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5389 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
|
5390 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5391 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5392 // 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
|
5393 ClassLoaderDataGraph::remember_new_clds(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5394 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5395 _timer.stop(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5396 if (PrintCMSStatistics != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5397 gclog_or_tty->print_cr( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5398 "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
|
5399 worker_id, _timer.seconds()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5400 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5401 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5402 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5403 // ---------- dirty klass scanning ---------- |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5404 if (worker_id == 0) { // Single threaded at the moment. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5405 _timer.reset(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5406 _timer.start(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5407 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5408 // Scan all 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
|
5409 RemarkKlassClosure remark_klass_closure(&par_mrias_cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5410 ClassLoaderDataGraph::classes_do(&remark_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5411 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5412 _timer.stop(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5413 if (PrintCMSStatistics != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5414 gclog_or_tty->print_cr( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5415 "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
|
5416 worker_id, _timer.seconds()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5417 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5418 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5419 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5420 // 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
|
5421 // 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
|
5422 // that are guaranteed to be kept alive. Either by the direct allocation |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5423 // code, or when the young collector processes the roots. Hence, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5424 // 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
|
5425 |
0 | 5426 // ---------- rescan dirty cards ------------ |
5427 _timer.reset(); | |
5428 _timer.start(); | |
5429 | |
5430 // 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
|
5431 // (cms_space) in turn. |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5432 // "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
|
5433 do_dirty_card_rescan_tasks(_cms_space, worker_id, &par_mrias_cl); |
0 | 5434 _timer.stop(); |
5435 if (PrintCMSStatistics != 0) { | |
5436 gclog_or_tty->print_cr( | |
5437 "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
|
5438 worker_id, _timer.seconds()); |
0 | 5439 } |
5440 | |
5441 // ---------- steal work from other threads ... | |
5442 // ---------- ... and drain overflow list. | |
5443 _timer.reset(); | |
5444 _timer.start(); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5445 do_work_steal(worker_id, &par_mrias_cl, _collector->hash_seed(worker_id)); |
0 | 5446 _timer.stop(); |
5447 if (PrintCMSStatistics != 0) { | |
5448 gclog_or_tty->print_cr( | |
5449 "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
|
5450 worker_id, _timer.seconds()); |
0 | 5451 } |
5452 } | |
5453 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5454 // Note that parameter "i" is not used. |
0 | 5455 void |
11975 | 5456 CMSParMarkTask::do_young_space_rescan(uint worker_id, |
5457 OopsInGenClosure* cl, ContiguousSpace* space, | |
0 | 5458 HeapWord** chunk_array, size_t chunk_top) { |
5459 // Until all tasks completed: | |
5460 // . claim an unclaimed task | |
5461 // . compute region boundaries corresponding to task claimed | |
5462 // using chunk_array | |
5463 // . par_oop_iterate(cl) over that region | |
5464 | |
5465 ResourceMark rm; | |
5466 HandleMark hm; | |
5467 | |
5468 SequentialSubTasksDone* pst = space->par_seq_tasks(); | |
5469 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5470 uint nth_task = 0; |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5471 uint n_tasks = pst->n_tasks(); |
0 | 5472 |
12088
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5473 if (n_tasks > 0) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5474 assert(pst->valid(), "Uninitialized use?"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5475 HeapWord *start, *end; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5476 while (!pst->is_task_claimed(/* reference */ nth_task)) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5477 // We claimed task # nth_task; compute its boundaries. |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5478 if (chunk_top == 0) { // no samples were taken |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5479 assert(nth_task == 0 && n_tasks == 1, "Can have only 1 EdenSpace task"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5480 start = space->bottom(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5481 end = space->top(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5482 } else if (nth_task == 0) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5483 start = space->bottom(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5484 end = chunk_array[nth_task]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5485 } else if (nth_task < (uint)chunk_top) { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5486 assert(nth_task >= 1, "Control point invariant"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5487 start = chunk_array[nth_task - 1]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5488 end = chunk_array[nth_task]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5489 } else { |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5490 assert(nth_task == (uint)chunk_top, "Control point invariant"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5491 start = chunk_array[chunk_top - 1]; |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5492 end = space->top(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5493 } |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5494 MemRegion mr(start, end); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5495 // Verify that mr is in space |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5496 assert(mr.is_empty() || space->used_region().contains(mr), |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5497 "Should be in space"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5498 // Verify that "start" is an object boundary |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5499 assert(mr.is_empty() || oop(mr.start())->is_oop(), |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5500 "Should be an oop"); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5501 space->par_oop_iterate(mr, cl); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5502 } |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5503 pst->all_tasks_completed(); |
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5504 } |
0 | 5505 } |
5506 | |
5507 void | |
5508 CMSParRemarkTask::do_dirty_card_rescan_tasks( | |
5509 CompactibleFreeListSpace* sp, int i, | |
5510 Par_MarkRefsIntoAndScanClosure* cl) { | |
5511 // Until all tasks completed: | |
5512 // . claim an unclaimed task | |
5513 // . compute region boundaries corresponding to task claimed | |
5514 // . transfer dirty bits ct->mut for that region | |
5515 // . apply rescanclosure to dirty mut bits for that region | |
5516 | |
5517 ResourceMark rm; | |
5518 HandleMark hm; | |
5519 | |
5520 OopTaskQueue* work_q = work_queue(i); | |
5521 ModUnionClosure modUnionClosure(&(_collector->_modUnionTable)); | |
5522 // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! | |
5523 // CAUTION: This closure has state that persists across calls to | |
5524 // the work method dirty_range_iterate_clear() in that it has | |
5525 // imbedded in it a (subtype of) UpwardsObjectClosure. The | |
5526 // use of that state in the imbedded UpwardsObjectClosure instance | |
5527 // assumes that the cards are always iterated (even if in parallel | |
5528 // by several threads) in monotonically increasing order per each | |
5529 // thread. This is true of the implementation below which picks | |
5530 // card ranges (chunks) in monotonically increasing order globally | |
5531 // and, a-fortiori, in monotonically increasing order per thread | |
5532 // (the latter order being a subsequence of the former). | |
5533 // If the work code below is ever reorganized into a more chaotic | |
5534 // work-partitioning form than the current "sequential tasks" | |
5535 // paradigm, the use of that persistent state will have to be | |
5536 // revisited and modified appropriately. See also related | |
5537 // bug 4756801 work on which should examine this code to make | |
5538 // sure that the changes there do not run counter to the | |
5539 // assumptions made here and necessary for correctness and | |
5540 // efficiency. Note also that this code might yield inefficient | |
5541 // behaviour in the case of very large objects that span one or | |
5542 // more work chunks. Such objects would potentially be scanned | |
5543 // several times redundantly. Work on 4756801 should try and | |
5544 // address that performance anomaly if at all possible. XXX | |
5545 MemRegion full_span = _collector->_span; | |
5546 CMSBitMap* bm = &(_collector->_markBitMap); // shared | |
5547 MarkFromDirtyCardsClosure | |
5548 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
|
5549 sp, bm, work_q, cl); |
0 | 5550 |
5551 SequentialSubTasksDone* pst = sp->conc_par_seq_tasks(); | |
5552 assert(pst->valid(), "Uninitialized use?"); | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
5553 uint nth_task = 0; |
0 | 5554 const int alignment = CardTableModRefBS::card_size * BitsPerWord; |
5555 MemRegion span = sp->used_region(); | |
5556 HeapWord* start_addr = span.start(); | |
5557 HeapWord* end_addr = (HeapWord*)round_to((intptr_t)span.end(), | |
5558 alignment); | |
5559 const size_t chunk_size = sp->rescan_task_size(); // in HeapWord units | |
5560 assert((HeapWord*)round_to((intptr_t)start_addr, alignment) == | |
5561 start_addr, "Check alignment"); | |
5562 assert((size_t)round_to((intptr_t)chunk_size, alignment) == | |
5563 chunk_size, "Check alignment"); | |
5564 | |
5565 while (!pst->is_task_claimed(/* reference */ nth_task)) { | |
5566 // Having claimed the nth_task, compute corresponding mem-region, | |
5567 // which is a-fortiori aligned correctly (i.e. at a MUT bopundary). | |
5568 // The alignment restriction ensures that we do not need any | |
5569 // synchronization with other gang-workers while setting or | |
5570 // clearing bits in thus chunk of the MUT. | |
5571 MemRegion this_span = MemRegion(start_addr + nth_task*chunk_size, | |
5572 start_addr + (nth_task+1)*chunk_size); | |
5573 // The last chunk's end might be way beyond end of the | |
5574 // used region. In that case pull back appropriately. | |
5575 if (this_span.end() > end_addr) { | |
5576 this_span.set_end(end_addr); | |
5577 assert(!this_span.is_empty(), "Program logic (calculation of n_tasks)"); | |
5578 } | |
5579 // Iterate over the dirty cards covering this chunk, marking them | |
5580 // precleaned, and setting the corresponding bits in the mod union | |
5581 // table. Since we have been careful to partition at Card and MUT-word | |
5582 // boundaries no synchronization is needed between parallel threads. | |
5583 _collector->_ct->ct_bs()->dirty_card_iterate(this_span, | |
5584 &modUnionClosure); | |
5585 | |
5586 // Having transferred these marks into the modUnionTable, | |
5587 // rescan the marked objects on the dirty cards in the modUnionTable. | |
5588 // Even if this is at a synchronous collection, the initial marking | |
5589 // may have been done during an asynchronous collection so there | |
5590 // may be dirty bits in the mod-union table. | |
5591 _collector->_modUnionTable.dirty_range_iterate_clear( | |
5592 this_span, &greyRescanClosure); | |
5593 _collector->_modUnionTable.verifyNoOneBitsInRange( | |
5594 this_span.start(), | |
5595 this_span.end()); | |
5596 } | |
5597 pst->all_tasks_completed(); // declare that i am done | |
5598 } | |
5599 | |
5600 // . see if we can share work_queues with ParNew? XXX | |
5601 void | |
5602 CMSParRemarkTask::do_work_steal(int i, Par_MarkRefsIntoAndScanClosure* cl, | |
5603 int* seed) { | |
5604 OopTaskQueue* work_q = work_queue(i); | |
5605 NOT_PRODUCT(int num_steals = 0;) | |
5606 oop obj_to_scan; | |
5607 CMSBitMap* bm = &(_collector->_markBitMap); | |
5608 | |
5609 while (true) { | |
5610 // Completely finish any left over work from (an) earlier round(s) | |
5611 cl->trim_queue(0); | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
5612 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
|
5613 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 5614 // 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
|
5615 // Passing ParallelGCThreads as the third parameter, no_of_gc_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5616 // 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
|
5617 // 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
|
5618 // pass ParallelGCThreads so this behavior is unchanged. |
0 | 5619 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
|
5620 work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5621 ParallelGCThreads)) { |
0 | 5622 // found something in global overflow list; |
5623 // not yet ready to go stealing work from others. | |
5624 // We'd like to assert(work_q->size() != 0, ...) | |
5625 // because we just took work from the overflow list, | |
5626 // but of course we can't since all of that could have | |
5627 // been already stolen from us. | |
5628 // "He giveth and He taketh away." | |
5629 continue; | |
5630 } | |
5631 // Verify that we have no work before we resort to stealing | |
5632 assert(work_q->size() == 0, "Have work, shouldn't steal"); | |
5633 // Try to steal from other queues that have work | |
5634 if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
5635 NOT_PRODUCT(num_steals++;) | |
5636 assert(obj_to_scan->is_oop(), "Oops, not an oop!"); | |
5637 assert(bm->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?"); | |
5638 // Do scanning work | |
5639 obj_to_scan->oop_iterate(cl); | |
5640 // Loop around, finish this work, and try to steal some more | |
5641 } else if (terminator()->offer_termination()) { | |
5642 break; // nirvana from the infinite cycle | |
5643 } | |
5644 } | |
5645 NOT_PRODUCT( | |
5646 if (PrintCMSStatistics != 0) { | |
5647 gclog_or_tty->print("\n\t(%d: stole %d oops)", i, num_steals); | |
5648 } | |
5649 ) | |
5650 assert(work_q->size() == 0 && _collector->overflow_list_is_empty(), | |
5651 "Else our work is not yet done"); | |
5652 } | |
5653 | |
11973
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5654 // Record object boundaries in _eden_chunk_array by sampling the eden |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5655 // top in the slow-path eden object allocation code path and record |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5656 // the boundaries, if CMSEdenChunksRecordAlways is true. If |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5657 // CMSEdenChunksRecordAlways is false, we use the other asynchronous |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5658 // sampling in sample_eden() that activates during the part of the |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5659 // preclean phase. |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5660 void CMSCollector::sample_eden_chunk() { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5661 if (CMSEdenChunksRecordAlways && _eden_chunk_array != NULL) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5662 if (_eden_chunk_lock->try_lock()) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5663 // Record a sample. This is the critical section. The contents |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5664 // of the _eden_chunk_array have to be non-decreasing in the |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5665 // address order. |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5666 _eden_chunk_array[_eden_chunk_index] = *_top_addr; |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5667 assert(_eden_chunk_array[_eden_chunk_index] <= *_end_addr, |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5668 "Unexpected state of Eden"); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5669 if (_eden_chunk_index == 0 || |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5670 ((_eden_chunk_array[_eden_chunk_index] > _eden_chunk_array[_eden_chunk_index-1]) && |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5671 (pointer_delta(_eden_chunk_array[_eden_chunk_index], |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5672 _eden_chunk_array[_eden_chunk_index-1]) >= CMSSamplingGrain))) { |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5673 _eden_chunk_index++; // commit sample |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5674 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5675 _eden_chunk_lock->unlock(); |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5676 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5677 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5678 } |
7b06ae405d7b
6990419: CMS Remaining work for 6572569: consistently skewed work distribution in (long) re-mark pauses
jmasa
parents:
11096
diff
changeset
|
5679 |
0 | 5680 // Return a thread-local PLAB recording array, as appropriate. |
5681 void* CMSCollector::get_data_recorder(int thr_num) { | |
5682 if (_survivor_plab_array != NULL && | |
5683 (CMSPLABRecordAlways || | |
5684 (_collectorState > Marking && _collectorState < FinalMarking))) { | |
5685 assert(thr_num < (int)ParallelGCThreads, "thr_num is out of bounds"); | |
5686 ChunkArray* ca = &_survivor_plab_array[thr_num]; | |
5687 ca->reset(); // clear it so that fresh data is recorded | |
5688 return (void*) ca; | |
5689 } else { | |
5690 return NULL; | |
5691 } | |
5692 } | |
5693 | |
5694 // Reset all the thread-local PLAB recording arrays | |
5695 void CMSCollector::reset_survivor_plab_arrays() { | |
5696 for (uint i = 0; i < ParallelGCThreads; i++) { | |
5697 _survivor_plab_array[i].reset(); | |
5698 } | |
5699 } | |
5700 | |
5701 // Merge the per-thread plab arrays into the global survivor chunk | |
5702 // array which will provide the partitioning of the survivor space | |
11975 | 5703 // for CMS initial scan and rescan. |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5704 void CMSCollector::merge_survivor_plab_arrays(ContiguousSpace* surv, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5705 int no_of_gc_threads) { |
0 | 5706 assert(_survivor_plab_array != NULL, "Error"); |
5707 assert(_survivor_chunk_array != NULL, "Error"); | |
11975 | 5708 assert(_collectorState == FinalMarking || |
5709 (CMSParallelInitialMarkEnabled && _collectorState == InitialMarking), "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5710 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5711 _cursor[j] = 0; |
5712 } | |
5713 HeapWord* top = surv->top(); | |
5714 size_t i; | |
5715 for (i = 0; i < _survivor_chunk_capacity; i++) { // all sca entries | |
5716 HeapWord* min_val = top; // Higher than any PLAB address | |
5717 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
|
5718 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5719 ChunkArray* cur_sca = &_survivor_plab_array[j]; |
5720 if (_cursor[j] == cur_sca->end()) { | |
5721 continue; | |
5722 } | |
5723 assert(_cursor[j] < cur_sca->end(), "ctl pt invariant"); | |
5724 HeapWord* cur_val = cur_sca->nth(_cursor[j]); | |
5725 assert(surv->used_region().contains(cur_val), "Out of bounds value"); | |
5726 if (cur_val < min_val) { | |
5727 min_tid = j; | |
5728 min_val = cur_val; | |
5729 } else { | |
5730 assert(cur_val < top, "All recorded addresses should be less"); | |
5731 } | |
5732 } | |
5733 // At this point min_val and min_tid are respectively | |
5734 // the least address in _survivor_plab_array[j]->nth(_cursor[j]) | |
5735 // and the thread (j) that witnesses that address. | |
5736 // We record this address in the _survivor_chunk_array[i] | |
5737 // and increment _cursor[min_tid] prior to the next round i. | |
5738 if (min_val == top) { | |
5739 break; | |
5740 } | |
5741 _survivor_chunk_array[i] = min_val; | |
5742 _cursor[min_tid]++; | |
5743 } | |
5744 // We are all done; record the size of the _survivor_chunk_array | |
5745 _survivor_chunk_index = i; // exclusive: [0, i) | |
5746 if (PrintCMSStatistics > 0) { | |
5747 gclog_or_tty->print(" (Survivor:" SIZE_FORMAT "chunks) ", i); | |
5748 } | |
5749 // Verify that we used up all the recorded entries | |
5750 #ifdef ASSERT | |
5751 size_t total = 0; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5752 for (int j = 0; j < no_of_gc_threads; j++) { |
0 | 5753 assert(_cursor[j] == _survivor_plab_array[j].end(), "Ctl pt invariant"); |
5754 total += _cursor[j]; | |
5755 } | |
5756 assert(total == _survivor_chunk_index, "Ctl Pt Invariant"); | |
5757 // Check that the merged array is in sorted order | |
5758 if (total > 0) { | |
5759 for (size_t i = 0; i < total - 1; i++) { | |
5760 if (PrintCMSStatistics > 0) { | |
5761 gclog_or_tty->print(" (chunk" SIZE_FORMAT ":" INTPTR_FORMAT ") ", | |
5762 i, _survivor_chunk_array[i]); | |
5763 } | |
5764 assert(_survivor_chunk_array[i] < _survivor_chunk_array[i+1], | |
5765 "Not sorted"); | |
5766 } | |
5767 } | |
5768 #endif // ASSERT | |
5769 } | |
5770 | |
5771 // Set up the space's par_seq_tasks structure for work claiming | |
11975 | 5772 // for parallel initial scan and rescan of young gen. |
0 | 5773 // See ParRescanTask where this is currently used. |
5774 void | |
5775 CMSCollector:: | |
5776 initialize_sequential_subtasks_for_young_gen_rescan(int n_threads) { | |
5777 assert(n_threads > 0, "Unexpected n_threads argument"); | |
5778 DefNewGeneration* dng = (DefNewGeneration*)_young_gen; | |
5779 | |
5780 // Eden space | |
12088
cb9da55b1990
8021809: Partitioning based on eden sampling during allocation not reset correctly
jmasa
parents:
12029
diff
changeset
|
5781 if (!dng->eden()->is_empty()) { |
0 | 5782 SequentialSubTasksDone* pst = dng->eden()->par_seq_tasks(); |
5783 assert(!pst->valid(), "Clobbering existing data?"); | |
5784 // Each valid entry in [0, _eden_chunk_index) represents a task. | |
5785 size_t n_tasks = _eden_chunk_index + 1; | |
5786 assert(n_tasks == 1 || _eden_chunk_array != NULL, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5787 // 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
|
5788 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5789 pst->set_n_threads(n_threads); |
0 | 5790 pst->set_n_tasks((int)n_tasks); |
5791 } | |
5792 | |
5793 // Merge the survivor plab arrays into _survivor_chunk_array | |
5794 if (_survivor_plab_array != NULL) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5795 merge_survivor_plab_arrays(dng->from(), n_threads); |
0 | 5796 } else { |
5797 assert(_survivor_chunk_index == 0, "Error"); | |
5798 } | |
5799 | |
5800 // To space | |
5801 { | |
5802 SequentialSubTasksDone* pst = dng->to()->par_seq_tasks(); | |
5803 assert(!pst->valid(), "Clobbering existing data?"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5804 // 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
|
5805 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5806 pst->set_n_threads(n_threads); |
0 | 5807 pst->set_n_tasks(1); |
5808 assert(pst->valid(), "Error"); | |
5809 } | |
5810 | |
5811 // From space | |
5812 { | |
5813 SequentialSubTasksDone* pst = dng->from()->par_seq_tasks(); | |
5814 assert(!pst->valid(), "Clobbering existing data?"); | |
5815 size_t n_tasks = _survivor_chunk_index + 1; | |
5816 assert(n_tasks == 1 || _survivor_chunk_array != NULL, "Error"); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5817 // 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
|
5818 // need to finish in order to be done). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5819 pst->set_n_threads(n_threads); |
0 | 5820 pst->set_n_tasks((int)n_tasks); |
5821 assert(pst->valid(), "Error"); | |
5822 } | |
5823 } | |
5824 | |
5825 // Parallel version of remark | |
5826 void CMSCollector::do_remark_parallel() { | |
5827 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
5828 FlexibleWorkGang* workers = gch->workers(); |
0 | 5829 assert(workers != NULL, "Need parallel worker threads."); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5830 // 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
|
5831 // 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
|
5832 // to ParallelGCThreads. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5833 int n_workers = workers->active_workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5834 if (n_workers == 0) { |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5835 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
|
5836 n_workers = ParallelGCThreads; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5837 workers->set_active_workers(n_workers); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
5838 } |
0 | 5839 CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace(); |
5840 | |
5841 CMSParRemarkTask tsk(this, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5842 cms_space, |
0 | 5843 n_workers, workers, task_queues()); |
5844 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5845 // Set up for parallel process_roots work. |
0 | 5846 gch->set_par_threads(n_workers); |
5847 // We won't be iterating over the cards in the card table updating | |
5848 // the younger_gen cards, so we shouldn't call the following else | |
5849 // the verification code as well as subsequent younger_refs_iterate | |
5850 // code would get confused. XXX | |
5851 // gch->rem_set()->prepare_for_younger_refs_iterate(true); // parallel | |
5852 | |
5853 // The young gen rescan work will not be done as part of | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5854 // process_roots (which currently doesn't know how to |
0 | 5855 // parallelize such a scan), but rather will be broken up into |
5856 // a set of parallel tasks (via the sampling that the [abortable] | |
5857 // preclean phase did of EdenSpace, plus the [two] tasks of | |
5858 // scanning the [two] survivor spaces. Further fine-grain | |
5859 // parallelization of the scanning of the survivor spaces | |
5860 // themselves, and of precleaning of the younger gen itself | |
5861 // is deferred to the future. | |
5862 initialize_sequential_subtasks_for_young_gen_rescan(n_workers); | |
5863 | |
5864 // The dirty card rescan work is broken up into a "sequence" | |
5865 // of parallel tasks (per constituent space) that are dynamically | |
5866 // claimed by the parallel threads. | |
5867 cms_space->initialize_sequential_subtasks_for_rescan(n_workers); | |
5868 | |
5869 // It turns out that even when we're using 1 thread, doing the work in a | |
5870 // separate thread causes wide variance in run times. We can't help this | |
5871 // in the multi-threaded case, but we special-case n=1 here to get | |
5872 // repeatable measurements of the 1-thread overhead of the parallel code. | |
5873 if (n_workers > 1) { | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5874 // 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
|
5875 // 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
|
5876 // ST marking. |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
5877 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), true); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5878 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5879 workers->run_task(&tsk); |
5880 } else { | |
4876
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5881 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5882 GenCollectedHeap::StrongRootsScope srs(gch); |
0 | 5883 tsk.work(0); |
5884 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5885 |
0 | 5886 gch->set_par_threads(0); // 0 ==> non-parallel. |
5887 // restore, single-threaded for now, any preserved marks | |
5888 // as a result of work_q overflow | |
5889 restore_preserved_marks_if_any(); | |
5890 } | |
5891 | |
5892 // Non-parallel version of remark | |
5893 void CMSCollector::do_remark_non_parallel() { | |
5894 ResourceMark rm; | |
5895 HandleMark hm; | |
5896 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
4876
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5897 ReferenceProcessorMTDiscoveryMutator mt(ref_processor(), false); |
be649fefcdc2
7134655: Crash in reference processing when doing single-threaded remarking
stefank
parents:
4728
diff
changeset
|
5898 |
0 | 5899 MarkRefsIntoAndScanClosure |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5900 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
|
5901 &_markStack, this, |
0 | 5902 false /* should_yield */, false /* not precleaning */); |
5903 MarkFromDirtyCardsClosure | |
5904 markFromDirtyCardsClosure(this, _span, | |
5905 NULL, // space is set further below | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5906 &_markBitMap, &_markStack, &mrias_cl); |
0 | 5907 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5908 GCTraceTime t("grey object rescan", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
5909 // 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
|
5910 // mod union table. |
0 | 5911 { |
5912 ModUnionClosure modUnionClosure(&_modUnionTable); | |
5913 _ct->ct_bs()->dirty_card_iterate( | |
5914 _cmsGen->used_region(), | |
5915 &modUnionClosure); | |
5916 } | |
5917 // Having transferred these marks into the modUnionTable, we just need | |
5918 // to rescan the marked objects on the dirty cards in the modUnionTable. | |
5919 // The initial marking may have been done during an asynchronous | |
5920 // collection so there may be dirty bits in the mod-union table. | |
5921 const int alignment = | |
5922 CardTableModRefBS::card_size * BitsPerWord; | |
5923 { | |
5924 // ... First handle dirty cards in CMS gen | |
5925 markFromDirtyCardsClosure.set_space(_cmsGen->cmsSpace()); | |
5926 MemRegion ur = _cmsGen->used_region(); | |
5927 HeapWord* lb = ur.start(); | |
5928 HeapWord* ub = (HeapWord*)round_to((intptr_t)ur.end(), alignment); | |
5929 MemRegion cms_span(lb, ub); | |
5930 _modUnionTable.dirty_range_iterate_clear(cms_span, | |
5931 &markFromDirtyCardsClosure); | |
5932 verify_work_stacks_empty(); | |
5933 if (PrintCMSStatistics != 0) { | |
5934 gclog_or_tty->print(" (re-scanned "SIZE_FORMAT" dirty cards in cms gen) ", | |
5935 markFromDirtyCardsClosure.num_dirty_cards()); | |
5936 } | |
5937 } | |
5938 } | |
5939 if (VerifyDuringGC && | |
5940 GenCollectedHeap::heap()->total_collections() >= VerifyGCStartAt) { | |
5941 HandleMark hm; // Discard invalid handles created during verification | |
6865
4202510ee0fe
8000831: Heap verification output incorrect/incomplete
johnc
parents:
6787
diff
changeset
|
5942 Universe::verify(); |
0 | 5943 } |
5944 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5945 GCTraceTime t("root rescan", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 5946 |
5947 verify_work_stacks_empty(); | |
5948 | |
5949 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
|
5950 GenCollectedHeap::StrongRootsScope srs(gch); |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5951 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5952 gch->gen_process_roots(_cmsGen->level(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5953 true, // younger gens as roots |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5954 false, // use the local StrongRootsScope |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5955 SharedHeap::ScanningOption(roots_scanning_options()), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5956 should_unload_classes(), |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5957 &mrias_cl, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5958 NULL, |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5959 NULL); // The dirty klasses will be handled below |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5960 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5961 assert(should_unload_classes() |
20254
9fec19bb0659
8032379: Remove the is_scavenging flag to process_strong_roots
mgerdin
parents:
20197
diff
changeset
|
5962 || (roots_scanning_options() & SharedHeap::SO_AllCodeCache), |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
798
diff
changeset
|
5963 "if we didn't scan the code cache, we have to be ready to drop nmethods with expired weak oops"); |
0 | 5964 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5965 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5966 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5967 GCTraceTime t("visit unhandled CLDs", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5968 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5969 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5970 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5971 // 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
|
5972 // during concurrent marking. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5973 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5974 GrowableArray<ClassLoaderData*>* array = ClassLoaderDataGraph::new_clds(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5975 for (int i = 0; i < array->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5976 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
|
5977 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5978 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5979 // 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
|
5980 ClassLoaderDataGraph::remember_new_clds(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5981 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5982 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5983 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5984 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5985 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
5986 GCTraceTime t("dirty klass scan", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5987 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5988 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5989 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5990 RemarkKlassClosure remark_klass_closure(&mrias_cl); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5991 ClassLoaderDataGraph::classes_do(&remark_klass_closure); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5992 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5993 verify_work_stacks_empty(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5994 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5995 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
5996 // 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
|
5997 // 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
|
5998 // that are guaranteed to be kept alive. Either by the direct allocation |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
5999 // code, or when the young collector processes the roots. Hence, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6000 // 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
|
6001 |
0 | 6002 verify_work_stacks_empty(); |
6003 // Restore evacuated mark words, if any, used for overflow list links | |
6004 if (!CMSOverflowEarlyRestoration) { | |
6005 restore_preserved_marks_if_any(); | |
6006 } | |
6007 verify_overflow_empty(); | |
6008 } | |
6009 | |
6010 //////////////////////////////////////////////////////// | |
6011 // Parallel Reference Processing Task Proxy Class | |
6012 //////////////////////////////////////////////////////// | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6013 class CMSRefProcTaskProxy: public AbstractGangTaskWOopQueues { |
0 | 6014 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; |
6015 CMSCollector* _collector; | |
6016 CMSBitMap* _mark_bit_map; | |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6017 const MemRegion _span; |
0 | 6018 ProcessTask& _task; |
6019 | |
6020 public: | |
6021 CMSRefProcTaskProxy(ProcessTask& task, | |
6022 CMSCollector* collector, | |
6023 const MemRegion& span, | |
6024 CMSBitMap* mark_bit_map, | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6025 AbstractWorkGang* workers, |
0 | 6026 OopTaskQueueSet* task_queues): |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6027 // 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
|
6028 // 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
|
6029 // the terminator() object. See 6984287. The set_for_termination() |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6030 // 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
|
6031 AbstractGangTaskWOopQueues("Process referents by policy in parallel", |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6032 task_queues), |
0 | 6033 _task(task), |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6034 _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
|
6035 { |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6036 assert(_collector->_span.equals(_span) && !_span.is_empty(), |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6037 "Inconsistency in _span"); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6038 set_for_termination(workers->active_workers()); |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
2365
diff
changeset
|
6039 } |
0 | 6040 |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6041 OopTaskQueueSet* task_queues() { return queues(); } |
0 | 6042 |
6043 OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); } | |
6044 | |
6045 void do_work_steal(int i, | |
6046 CMSParDrainMarkingStackClosure* drain, | |
6047 CMSParKeepAliveClosure* keep_alive, | |
6048 int* seed); | |
6049 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6050 virtual void work(uint worker_id); |
0 | 6051 }; |
6052 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6053 void CMSRefProcTaskProxy::work(uint worker_id) { |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6054 assert(_collector->_span.equals(_span), "Inconsistency in _span"); |
0 | 6055 CMSParKeepAliveClosure par_keep_alive(_collector, _span, |
935 | 6056 _mark_bit_map, |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6057 work_queue(worker_id)); |
0 | 6058 CMSParDrainMarkingStackClosure par_drain_stack(_collector, _span, |
935 | 6059 _mark_bit_map, |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6060 work_queue(worker_id)); |
143
b5489bb705c9
6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents:
113
diff
changeset
|
6061 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
|
6062 _task.work(worker_id, is_alive_closure, par_keep_alive, par_drain_stack); |
0 | 6063 if (_task.marks_oops_alive()) { |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6064 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
|
6065 _collector->hash_seed(worker_id)); |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6066 } |
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6067 assert(work_queue(worker_id)->size() == 0, "work_queue should be empty"); |
0 | 6068 assert(_collector->_overflow_list == NULL, "non-empty _overflow_list"); |
6069 } | |
6070 | |
6071 class CMSRefEnqueueTaskProxy: public AbstractGangTask { | |
6072 typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask; | |
6073 EnqueueTask& _task; | |
6074 | |
6075 public: | |
6076 CMSRefEnqueueTaskProxy(EnqueueTask& task) | |
6077 : AbstractGangTask("Enqueue reference objects in parallel"), | |
6078 _task(task) | |
6079 { } | |
6080 | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6081 virtual void work(uint worker_id) |
0 | 6082 { |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4128
diff
changeset
|
6083 _task.work(worker_id); |
0 | 6084 } |
6085 }; | |
6086 | |
6087 CMSParKeepAliveClosure::CMSParKeepAliveClosure(CMSCollector* collector, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6088 MemRegion span, CMSBitMap* bit_map, OopTaskQueue* work_queue): |
0 | 6089 _span(span), |
6090 _bit_map(bit_map), | |
6091 _work_queue(work_queue), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6092 _mark_and_push(collector, span, bit_map, work_queue), |
0 | 6093 _low_water_mark(MIN2((uint)(work_queue->max_elems()/4), |
6094 (uint)(CMSWorkQueueDrainThreshold * ParallelGCThreads))) | |
6095 { } | |
6096 | |
6097 // . see if we can share work_queues with ParNew? XXX | |
6098 void CMSRefProcTaskProxy::do_work_steal(int i, | |
6099 CMSParDrainMarkingStackClosure* drain, | |
6100 CMSParKeepAliveClosure* keep_alive, | |
6101 int* seed) { | |
6102 OopTaskQueue* work_q = work_queue(i); | |
6103 NOT_PRODUCT(int num_steals = 0;) | |
6104 oop obj_to_scan; | |
6105 | |
6106 while (true) { | |
6107 // Completely finish any left over work from (an) earlier round(s) | |
6108 drain->trim_queue(0); | |
679
cea947c8a988
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
ysr
parents:
628
diff
changeset
|
6109 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
|
6110 (size_t)ParGCDesiredObjsFromOverflowList); |
0 | 6111 // 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
|
6112 // Passing ParallelGCThreads as the third parameter, no_of_gc_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6113 // 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
|
6114 // 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
|
6115 // pass ParallelGCThreads so this behavior is unchanged. |
0 | 6116 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
|
6117 work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6118 ParallelGCThreads)) { |
0 | 6119 // Found something in global overflow list; |
6120 // not yet ready to go stealing work from others. | |
6121 // We'd like to assert(work_q->size() != 0, ...) | |
6122 // because we just took work from the overflow list, | |
6123 // but of course we can't, since all of that might have | |
6124 // been already stolen from us. | |
6125 continue; | |
6126 } | |
6127 // Verify that we have no work before we resort to stealing | |
6128 assert(work_q->size() == 0, "Have work, shouldn't steal"); | |
6129 // Try to steal from other queues that have work | |
6130 if (task_queues()->steal(i, seed, /* reference */ obj_to_scan)) { | |
6131 NOT_PRODUCT(num_steals++;) | |
6132 assert(obj_to_scan->is_oop(), "Oops, not an oop!"); | |
6133 assert(_mark_bit_map->isMarked((HeapWord*)obj_to_scan), "Stole an unmarked oop?"); | |
6134 // Do scanning work | |
6135 obj_to_scan->oop_iterate(keep_alive); | |
6136 // Loop around, finish this work, and try to steal some more | |
6137 } else if (terminator()->offer_termination()) { | |
6138 break; // nirvana from the infinite cycle | |
6139 } | |
6140 } | |
6141 NOT_PRODUCT( | |
6142 if (PrintCMSStatistics != 0) { | |
6143 gclog_or_tty->print("\n\t(%d: stole %d oops)", i, num_steals); | |
6144 } | |
6145 ) | |
6146 } | |
6147 | |
6148 void CMSRefProcTaskExecutor::execute(ProcessTask& task) | |
6149 { | |
6150 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6151 FlexibleWorkGang* workers = gch->workers(); |
0 | 6152 assert(workers != NULL, "Need parallel worker threads."); |
6153 CMSRefProcTaskProxy rp_task(task, &_collector, | |
6154 _collector.ref_processor()->span(), | |
6155 _collector.markBitMap(), | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6156 workers, _collector.task_queues()); |
0 | 6157 workers->run_task(&rp_task); |
6158 } | |
6159 | |
6160 void CMSRefProcTaskExecutor::execute(EnqueueTask& task) | |
6161 { | |
6162 | |
6163 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6164 FlexibleWorkGang* workers = gch->workers(); |
0 | 6165 assert(workers != NULL, "Need parallel worker threads."); |
6166 CMSRefEnqueueTaskProxy enq_task(task); | |
6167 workers->run_task(&enq_task); | |
6168 } | |
6169 | |
6170 void CMSCollector::refProcessingWork(bool asynch, bool clear_all_soft_refs) { | |
6171 | |
6172 ResourceMark rm; | |
6173 HandleMark hm; | |
6174 | |
6175 ReferenceProcessor* rp = ref_processor(); | |
6176 assert(rp->span().equals(_span), "Spans should be equal"); | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6177 assert(!rp->enqueuing_is_done(), "Enqueuing should not be complete"); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6178 // Process weak references. |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
6179 rp->setup_policy(clear_all_soft_refs); |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6180 verify_work_stacks_empty(); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6181 |
0 | 6182 CMSKeepAliveClosure cmsKeepAliveClosure(this, _span, &_markBitMap, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6183 &_markStack, false /* !preclean */); |
0 | 6184 CMSDrainMarkingStackClosure cmsDrainMarkingStackClosure(this, |
6185 _span, &_markBitMap, &_markStack, | |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
6186 &cmsKeepAliveClosure, false /* !preclean */); |
0 | 6187 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6188 GCTraceTime t("weak refs processing", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
10405 | 6189 |
6190 ReferenceProcessorStats stats; | |
0 | 6191 if (rp->processing_is_mt()) { |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6192 // 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
|
6193 // 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
|
6194 // 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
|
6195 // 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
|
6196 // balance_all_queues() and balance_queues()). |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6197 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6198 int active_workers = ParallelGCThreads; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6199 FlexibleWorkGang* workers = gch->workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6200 if (workers != NULL) { |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6201 active_workers = workers->active_workers(); |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6202 // The expectation is that active_workers will have already |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6203 // 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
|
6204 // investigate. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6205 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
|
6206 } |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3979
diff
changeset
|
6207 rp->set_active_mt_degree(active_workers); |
0 | 6208 CMSRefProcTaskExecutor task_executor(*this); |
10405 | 6209 stats = rp->process_discovered_references(&_is_alive_closure, |
0 | 6210 &cmsKeepAliveClosure, |
6211 &cmsDrainMarkingStackClosure, | |
10405 | 6212 &task_executor, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6213 _gc_timer_cm, |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6214 _gc_tracer_cm->gc_id()); |
0 | 6215 } else { |
10405 | 6216 stats = rp->process_discovered_references(&_is_alive_closure, |
0 | 6217 &cmsKeepAliveClosure, |
6218 &cmsDrainMarkingStackClosure, | |
10405 | 6219 NULL, |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6220 _gc_timer_cm, |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6221 _gc_tracer_cm->gc_id()); |
10405 | 6222 } |
6223 _gc_tracer_cm->report_gc_reference_stats(stats); | |
6224 | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6225 } |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6226 |
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6227 // 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
|
6228 verify_work_stacks_empty(); |
0 | 6229 |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6230 if (should_unload_classes()) { |
0 | 6231 { |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6232 GCTraceTime t("class unloading", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
0 | 6233 |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6234 // Unload classes and purge the SystemDictionary. |
0 | 6235 bool purged_class = SystemDictionary::do_unloading(&_is_alive_closure); |
6236 | |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6237 // Unload nmethods. |
6787
8966c2d65d96
7200470: KeepAliveClosure not needed in CodeCache::do_unloading
brutisso
parents:
6755
diff
changeset
|
6238 CodeCache::do_unloading(&_is_alive_closure, purged_class); |
0 | 6239 |
10188
2f50bc369470
8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading
stefank
parents:
10186
diff
changeset
|
6240 // 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
|
6241 Klass::clean_weak_klass_links(&_is_alive_closure); |
0 | 6242 } |
6243 | |
6244 { | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6245 GCTraceTime t("scrub symbol table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2147
diff
changeset
|
6246 // Clean up unreferenced symbols in symbol table. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2147
diff
changeset
|
6247 SymbolTable::unlink(); |
0 | 6248 } |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6249 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6250 { |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6251 GCTraceTime t("scrub string table", PrintGCDetails, false, _gc_timer_cm, _gc_tracer_cm->gc_id()); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6252 // Delete entries for dead interned strings. |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6253 StringTable::unlink(&_is_alive_closure); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6254 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6255 } |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20268
diff
changeset
|
6256 |
2379
b099aaf51bf8
6962931: move interned strings out of the perm gen
jcoomes
parents:
2369
diff
changeset
|
6257 |
0 | 6258 // Restore any preserved marks as a result of mark stack or |
6259 // work queue overflow | |
6260 restore_preserved_marks_if_any(); // done single-threaded for now | |
6261 | |
6262 rp->set_enqueuing_is_done(true); | |
6263 if (rp->processing_is_mt()) { | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
6264 rp->balance_all_queues(); |
0 | 6265 CMSRefProcTaskExecutor task_executor(*this); |
6266 rp->enqueue_discovered_references(&task_executor); | |
6267 } else { | |
6268 rp->enqueue_discovered_references(NULL); | |
6269 } | |
6270 rp->verify_no_references_recorded(); | |
6271 assert(!rp->discovery_enabled(), "should have been disabled"); | |
6272 } | |
6273 | |
6274 #ifndef PRODUCT | |
6275 void CMSCollector::check_correct_thread_executing() { | |
6276 Thread* t = Thread::current(); | |
6277 // Only the VM thread or the CMS thread should be here. | |
6278 assert(t->is_ConcurrentGC_thread() || t->is_VM_thread(), | |
6279 "Unexpected thread type"); | |
6280 // If this is the vm thread, the foreground process | |
6281 // should not be waiting. Note that _foregroundGCIsActive is | |
6282 // true while the foreground collector is waiting. | |
6283 if (_foregroundGCShouldWait) { | |
6284 // We cannot be the VM thread | |
6285 assert(t->is_ConcurrentGC_thread(), | |
6286 "Should be CMS thread"); | |
6287 } else { | |
6288 // We can be the CMS thread only if we are in a stop-world | |
6289 // phase of CMS collection. | |
6290 if (t->is_ConcurrentGC_thread()) { | |
6291 assert(_collectorState == InitialMarking || | |
6292 _collectorState == FinalMarking, | |
6293 "Should be a stop-world phase"); | |
6294 // The CMS thread should be holding the CMS_token. | |
6295 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6296 "Potential interference with concurrently " | |
6297 "executing VM thread"); | |
6298 } | |
6299 } | |
6300 } | |
6301 #endif | |
6302 | |
6303 void CMSCollector::sweep(bool asynch) { | |
6304 assert(_collectorState == Sweeping, "just checking"); | |
6305 check_correct_thread_executing(); | |
6306 verify_work_stacks_empty(); | |
6307 verify_overflow_empty(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6308 increment_sweep_count(); |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
6309 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
|
6310 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6311 _inter_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6312 _inter_sweep_estimate.sample(_inter_sweep_timer.seconds()); |
0 | 6313 size_policy()->avg_cms_free_at_sweep()->sample(_cmsGen->free()); |
6314 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6315 assert(!_intra_sweep_timer.is_active(), "Should not be active"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6316 _intra_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6317 _intra_sweep_timer.start(); |
0 | 6318 if (asynch) { |
6319 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6320 CMSPhaseAccounting pa(this, "sweep", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6321 // First sweep the old gen |
0 | 6322 { |
6323 CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock(), | |
6324 bitMapLock()); | |
6325 sweepWork(_cmsGen, asynch); | |
6326 } | |
6327 | |
6328 // Update Universe::_heap_*_at_gc figures. | |
6329 // We need all the free list locks to make the abstract state | |
6330 // transition from Sweeping to Resetting. See detailed note | |
6331 // further below. | |
6332 { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6333 CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock()); |
0 | 6334 // Update heap occupancy information which is used as |
6335 // input to soft ref clearing policy at the next gc. | |
6336 Universe::update_heap_info_at_gc(); | |
6337 _collectorState = Resizing; | |
6338 } | |
6339 } else { | |
6340 // already have needed locks | |
6341 sweepWork(_cmsGen, asynch); | |
6342 // Update heap occupancy information which is used as | |
6343 // input to soft ref clearing policy at the next gc. | |
6344 Universe::update_heap_info_at_gc(); | |
6345 _collectorState = Resizing; | |
6346 } | |
6347 verify_work_stacks_empty(); | |
6348 verify_overflow_empty(); | |
6349 | |
8784
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6350 if (should_unload_classes()) { |
17935
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17771
diff
changeset
|
6351 // Delay purge to the beginning of the next safepoint. Metaspace::contains |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17771
diff
changeset
|
6352 // requires that the virtual spaces are stable and not deleted. |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17771
diff
changeset
|
6353 ClassLoaderDataGraph::set_should_purge(true); |
8784
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6354 } |
79af1312fc2c
8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents:
8740
diff
changeset
|
6355 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6356 _intra_sweep_timer.stop(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6357 _intra_sweep_estimate.sample(_intra_sweep_timer.seconds()); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6358 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6359 _inter_sweep_timer.reset(); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6360 _inter_sweep_timer.start(); |
0 | 6361 |
4911 | 6362 // We need to use a monotonically non-deccreasing time in ms |
6363 // or we will see time-warp warnings and os::javaTimeMillis() | |
6364 // does not guarantee monotonicity. | |
6365 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; | |
6366 update_time_of_last_gc(now); | |
0 | 6367 |
6368 // NOTE on abstract state transitions: | |
6369 // Mutators allocate-live and/or mark the mod-union table dirty | |
6370 // based on the state of the collection. The former is done in | |
6371 // the interval [Marking, Sweeping] and the latter in the interval | |
6372 // [Marking, Sweeping). Thus the transitions into the Marking state | |
6373 // and out of the Sweeping state must be synchronously visible | |
6374 // globally to the mutators. | |
6375 // The transition into the Marking state happens with the world | |
6376 // stopped so the mutators will globally see it. Sweeping is | |
6377 // done asynchronously by the background collector so the transition | |
6378 // from the Sweeping state to the Resizing state must be done | |
6379 // under the freelistLock (as is the check for whether to | |
6380 // allocate-live and whether to dirty the mod-union table). | |
6381 assert(_collectorState == Resizing, "Change of collector state to" | |
6382 " Resizing must be done under the freelistLocks (plural)"); | |
6383 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6384 // 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
|
6385 // the incremental_collection_failed flag, |
0 | 6386 // thus inviting a younger gen collection to promote into |
6387 // this generation. If such a promotion may still fail, | |
6388 // the flag will be set again when a young collection is | |
6389 // attempted. | |
6390 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1837
diff
changeset
|
6391 gch->clear_incremental_collection_failed(); // Worth retrying as fresh space may have been freed up |
0 | 6392 gch->update_full_collections_completed(_collection_count_start); |
6393 } | |
6394 | |
6395 // FIX ME!!! Looks like this belongs in CFLSpace, with | |
6396 // CMSGen merely delegating to it. | |
6397 void ConcurrentMarkSweepGeneration::setNearLargestChunk() { | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6398 double nearLargestPercent = FLSLargestBlockCoalesceProximity; |
0 | 6399 HeapWord* minAddr = _cmsSpace->bottom(); |
6400 HeapWord* largestAddr = | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
6401 (HeapWord*) _cmsSpace->dictionary()->find_largest_dict(); |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6402 if (largestAddr == NULL) { |
0 | 6403 // The dictionary appears to be empty. In this case |
6404 // try to coalesce at the end of the heap. | |
6405 largestAddr = _cmsSpace->end(); | |
6406 } | |
6407 size_t largestOffset = pointer_delta(largestAddr, minAddr); | |
6408 size_t nearLargestOffset = | |
6409 (size_t)((double)largestOffset * nearLargestPercent) - MinChunkSize; | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6410 if (PrintFLSStatistics != 0) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6411 gclog_or_tty->print_cr( |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6412 "CMS: Large Block: " PTR_FORMAT ";" |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6413 " Proximity: " PTR_FORMAT " -> " PTR_FORMAT, |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6414 largestAddr, |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6415 _cmsSpace->nearLargestChunk(), minAddr + nearLargestOffset); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6416 } |
0 | 6417 _cmsSpace->set_nearLargestChunk(minAddr + nearLargestOffset); |
6418 } | |
6419 | |
6420 bool ConcurrentMarkSweepGeneration::isNearLargestChunk(HeapWord* addr) { | |
6421 return addr >= _cmsSpace->nearLargestChunk(); | |
6422 } | |
6423 | |
6424 FreeChunk* ConcurrentMarkSweepGeneration::find_chunk_at_end() { | |
6425 return _cmsSpace->find_chunk_at_end(); | |
6426 } | |
6427 | |
6428 void ConcurrentMarkSweepGeneration::update_gc_stats(int current_level, | |
6429 bool full) { | |
6430 // The next lower level has been collected. Gather any statistics | |
6431 // that are of interest at this point. | |
6432 if (!full && (current_level + 1) == level()) { | |
6433 // Gather statistics on the young generation collection. | |
6434 collector()->stats().record_gc0_end(used()); | |
6435 } | |
6436 } | |
6437 | |
6438 CMSAdaptiveSizePolicy* ConcurrentMarkSweepGeneration::size_policy() { | |
6439 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
6440 assert(gch->kind() == CollectedHeap::GenCollectedHeap, | |
6441 "Wrong type of heap"); | |
6442 CMSAdaptiveSizePolicy* sp = (CMSAdaptiveSizePolicy*) | |
6443 gch->gen_policy()->size_policy(); | |
6444 assert(sp->is_gc_cms_adaptive_size_policy(), | |
6445 "Wrong type of size policy"); | |
6446 return sp; | |
6447 } | |
6448 | |
6449 void ConcurrentMarkSweepGeneration::rotate_debug_collection_type() { | |
6450 if (PrintGCDetails && Verbose) { | |
6451 gclog_or_tty->print("Rotate from %d ", _debug_collection_type); | |
6452 } | |
6453 _debug_collection_type = (CollectionTypes) (_debug_collection_type + 1); | |
6454 _debug_collection_type = | |
6455 (CollectionTypes) (_debug_collection_type % Unknown_collection_type); | |
6456 if (PrintGCDetails && Verbose) { | |
6457 gclog_or_tty->print_cr("to %d ", _debug_collection_type); | |
6458 } | |
6459 } | |
6460 | |
6461 void CMSCollector::sweepWork(ConcurrentMarkSweepGeneration* gen, | |
6462 bool asynch) { | |
6463 // We iterate over the space(s) underlying this generation, | |
6464 // checking the mark bit map to see if the bits corresponding | |
6465 // to specific blocks are marked or not. Blocks that are | |
6466 // marked are live and are not swept up. All remaining blocks | |
6467 // are swept up, with coalescing on-the-fly as we sweep up | |
6468 // contiguous free and/or garbage blocks: | |
6469 // We need to ensure that the sweeper synchronizes with allocators | |
6470 // and stop-the-world collectors. In particular, the following | |
6471 // locks are used: | |
6472 // . CMS token: if this is held, a stop the world collection cannot occur | |
6473 // . freelistLock: if this is held no allocation can occur from this | |
6474 // generation by another thread | |
6475 // . bitMapLock: if this is held, no other thread can access or update | |
6476 // | |
6477 | |
6478 // Note that we need to hold the freelistLock if we use | |
6479 // block iterate below; else the iterator might go awry if | |
6480 // a mutator (or promotion) causes block contents to change | |
6481 // (for instance if the allocator divvies up a block). | |
6482 // If we hold the free list lock, for all practical purposes | |
6483 // young generation GC's can't occur (they'll usually need to | |
6484 // promote), so we might as well prevent all young generation | |
6485 // GC's while we do a sweeping step. For the same reason, we might | |
6486 // as well take the bit map lock for the entire duration | |
6487 | |
6488 // check that we hold the requisite locks | |
6489 assert(have_cms_token(), "Should hold cms token"); | |
6490 assert( (asynch && ConcurrentMarkSweepThread::cms_thread_has_cms_token()) | |
6491 || (!asynch && ConcurrentMarkSweepThread::vm_thread_has_cms_token()), | |
6492 "Should possess CMS token to sweep"); | |
6493 assert_lock_strong(gen->freelistLock()); | |
6494 assert_lock_strong(bitMapLock()); | |
6495 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6496 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
|
6497 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
|
6498 gen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6499 _inter_sweep_estimate.padded_average(), |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6500 _intra_sweep_estimate.padded_average()); |
0 | 6501 gen->setNearLargestChunk(); |
6502 | |
6503 { | |
6504 SweepClosure sweepClosure(this, gen, &_markBitMap, | |
6505 CMSYield && asynch); | |
6506 gen->cmsSpace()->blk_iterate_careful(&sweepClosure); | |
6507 // We need to free-up/coalesce garbage/blocks from a | |
6508 // co-terminal free run. This is done in the SweepClosure | |
6509 // destructor; so, do not remove this scope, else the | |
6510 // end-of-sweep-census below will be off by a little bit. | |
6511 } | |
6512 gen->cmsSpace()->sweep_completed(); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1085
diff
changeset
|
6513 gen->cmsSpace()->endSweepFLCensus(sweep_count()); |
94
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6514 if (should_unload_classes()) { // unloaded classes this cycle, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6515 _concurrent_cycles_since_last_unload = 0; // ... reset count |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6516 } else { // did not unload classes, |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6517 _concurrent_cycles_since_last_unload++; // ... increment count |
0834225a7916
6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents:
9
diff
changeset
|
6518 } |
0 | 6519 } |
6520 | |
6521 // Reset CMS data structures (for now just the marking bit map) | |
6522 // preparatory for the next cycle. | |
6523 void CMSCollector::reset(bool asynch) { | |
6524 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
6525 CMSAdaptiveSizePolicy* sp = size_policy(); | |
6526 AdaptiveSizePolicyOutput(sp, gch->total_collections()); | |
6527 if (asynch) { | |
6528 CMSTokenSyncWithLocks ts(true, bitMapLock()); | |
6529 | |
6530 // If the state is not "Resetting", the foreground thread | |
6531 // has done a collection and the resetting. | |
6532 if (_collectorState != Resetting) { | |
6533 assert(_collectorState == Idling, "The state should only change" | |
6534 " because the foreground collector has finished the collection"); | |
6535 return; | |
6536 } | |
6537 | |
6538 // Clear the mark bitmap (no grey objects to start with) | |
6539 // for the next cycle. | |
6540 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6541 CMSPhaseAccounting cmspa(this, "reset", _gc_tracer_cm->gc_id(), !PrintGCDetails); |
0 | 6542 |
6543 HeapWord* curAddr = _markBitMap.startWord(); | |
6544 while (curAddr < _markBitMap.endWord()) { | |
6545 size_t remaining = pointer_delta(_markBitMap.endWord(), curAddr); | |
6546 MemRegion chunk(curAddr, MIN2(CMSBitMapYieldQuantum, remaining)); | |
6547 _markBitMap.clear_large_range(chunk); | |
6548 if (ConcurrentMarkSweepThread::should_yield() && | |
6549 !foregroundGCIsActive() && | |
6550 CMSYield) { | |
6551 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
6552 "CMS thread should hold CMS token"); | |
6553 assert_lock_strong(bitMapLock()); | |
6554 bitMapLock()->unlock(); | |
6555 ConcurrentMarkSweepThread::desynchronize(true); | |
6556 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6557 stopTimer(); | |
6558 if (PrintCMSStatistics != 0) { | |
6559 incrementYields(); | |
6560 } | |
6561 icms_wait(); | |
6562 | |
6563 // See the comment in coordinator_yield() | |
6564 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
|
6565 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6566 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 6567 os::sleep(Thread::current(), 1, false); |
6568 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
6569 } | |
6570 | |
6571 ConcurrentMarkSweepThread::synchronize(true); | |
6572 bitMapLock()->lock_without_safepoint_check(); | |
6573 startTimer(); | |
6574 } | |
6575 curAddr = chunk.end(); | |
6576 } | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6577 // 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
|
6578 // 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
|
6579 // 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
|
6580 // and count. |
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
1289
diff
changeset
|
6581 sp->reset_gc_overhead_limit_count(); |
0 | 6582 _collectorState = Idling; |
6583 } else { | |
6584 // already have the lock | |
6585 assert(_collectorState == Resetting, "just checking"); | |
6586 assert_lock_strong(bitMapLock()); | |
6587 _markBitMap.clear_all(); | |
6588 _collectorState = Idling; | |
6589 } | |
6590 | |
6591 // Stop incremental mode after a cycle completes, so that any future cycles | |
6592 // are triggered by allocation. | |
6593 stop_icms(); | |
6594 | |
6595 NOT_PRODUCT( | |
6596 if (RotateCMSCollectionTypes) { | |
6597 _cmsGen->rotate_debug_collection_type(); | |
6598 } | |
6599 ) | |
10405 | 6600 |
6601 register_gc_end(); | |
0 | 6602 } |
6603 | |
6064
9d679effd28c
7166894: Add gc cause to GC logging for all collectors
brutisso
parents:
6028
diff
changeset
|
6604 void CMSCollector::do_CMS_operation(CMS_op_type op, GCCause::Cause gc_cause) { |
0 | 6605 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); |
6606 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17976
diff
changeset
|
6607 GCTraceTime t(GCCauseString("GC", gc_cause), PrintGC, !PrintGCDetails, NULL, _gc_tracer_cm->gc_id()); |
0 | 6608 TraceCollectorStats tcs(counters()); |
6609 | |
6610 switch (op) { | |
6611 case CMS_op_checkpointRootsInitial: { | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
6612 SvcGCMarker sgcm(SvcGCMarker::OTHER); |
0 | 6613 checkpointRootsInitial(true); // asynch |
6614 if (PrintGC) { | |
6615 _cmsGen->printOccupancy("initial-mark"); | |
6616 } | |
6617 break; | |
6618 } | |
6619 case CMS_op_checkpointRootsFinal: { | |
2125
7246a374a9f2
6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents:
1994
diff
changeset
|
6620 SvcGCMarker sgcm(SvcGCMarker::OTHER); |
0 | 6621 checkpointRootsFinal(true, // asynch |
6622 false, // !clear_all_soft_refs | |
6623 false); // !init_mark_was_synchronous | |
6624 if (PrintGC) { | |
6625 _cmsGen->printOccupancy("remark"); | |
6626 } | |
6627 break; | |
6628 } | |
6629 default: | |
6630 fatal("No such CMS_op"); | |
6631 } | |
6632 } | |
6633 | |
6634 #ifndef PRODUCT | |
6635 size_t const CMSCollector::skip_header_HeapWords() { | |
6636 return FreeChunk::header_size(); | |
6637 } | |
6638 | |
6639 // Try and collect here conditions that should hold when | |
6640 // CMS thread is exiting. The idea is that the foreground GC | |
6641 // thread should not be blocked if it wants to terminate | |
6642 // the CMS thread and yet continue to run the VM for a while | |
6643 // after that. | |
6644 void CMSCollector::verify_ok_to_terminate() const { | |
6645 assert(Thread::current()->is_ConcurrentGC_thread(), | |
6646 "should be called by CMS thread"); | |
6647 assert(!_foregroundGCShouldWait, "should be false"); | |
6648 // We could check here that all the various low-level locks | |
6649 // are not held by the CMS thread, but that is overkill; see | |
6650 // also CMSThread::verify_ok_to_terminate() where the CGC_lock | |
6651 // is checked. | |
6652 } | |
6653 #endif | |
6654 | |
6655 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
|
6656 assert(_markBitMap.isMarked(addr) && _markBitMap.isMarked(addr + 1), |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
452
diff
changeset
|
6657 "missing Printezis mark?"); |
0 | 6658 HeapWord* nextOneAddr = _markBitMap.getNextMarkedWordAddress(addr + 2); |
6659 size_t size = pointer_delta(nextOneAddr + 1, addr); | |
6660 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6661 "alignment problem"); | |
6662 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6663 return size; | |
6664 } | |
6665 | |
6666 // A variant of the above (block_size_using_printezis_bits()) except | |
6667 // that we return 0 if the P-bits are not yet set. | |
6668 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
|
6669 if (_markBitMap.isMarked(addr + 1)) { |
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6670 assert(_markBitMap.isMarked(addr), "P-bit can be set only for marked objects"); |
0 | 6671 HeapWord* nextOneAddr = _markBitMap.getNextMarkedWordAddress(addr + 2); |
6672 size_t size = pointer_delta(nextOneAddr + 1, addr); | |
6673 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
6674 "alignment problem"); | |
6675 assert(size >= 3, "Necessary for Printezis marks to work"); | |
6676 return size; | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6677 } |
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
6678 return 0; |
0 | 6679 } |
6680 | |
6681 HeapWord* CMSCollector::next_card_start_after_block(HeapWord* addr) const { | |
6682 size_t sz = 0; | |
6683 oop p = (oop)addr; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
6684 if (p->klass_or_null() != NULL) { |
0 | 6685 sz = CompactibleFreeListSpace::adjustObjectSize(p->size()); |
6686 } else { | |
6687 sz = block_size_using_printezis_bits(addr); | |
6688 } | |
6689 assert(sz > 0, "size must be nonzero"); | |
6690 HeapWord* next_block = addr + sz; | |
6691 HeapWord* next_card = (HeapWord*)round_to((uintptr_t)next_block, | |
6692 CardTableModRefBS::card_size); | |
6693 assert(round_down((uintptr_t)addr, CardTableModRefBS::card_size) < | |
6694 round_down((uintptr_t)next_card, CardTableModRefBS::card_size), | |
6695 "must be different cards"); | |
6696 return next_card; | |
6697 } | |
6698 | |
6699 | |
6700 // CMS Bit Map Wrapper ///////////////////////////////////////// | |
6701 | |
6702 // Construct a CMS bit map infrastructure, but don't create the | |
6703 // bit vector itself. That is done by a separate call CMSBitMap::allocate() | |
6704 // further below. | |
6705 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
|
6706 _bm(), |
0 | 6707 _shifter(shifter), |
6708 _lock(mutex_rank >= 0 ? new Mutex(mutex_rank, mutex_name, true) : NULL) | |
6709 { | |
6710 _bmStartWord = 0; | |
6711 _bmWordSize = 0; | |
6712 } | |
6713 | |
6714 bool CMSBitMap::allocate(MemRegion mr) { | |
6715 _bmStartWord = mr.start(); | |
6716 _bmWordSize = mr.word_size(); | |
6717 ReservedSpace brs(ReservedSpace::allocation_align_size_up( | |
6718 (_bmWordSize >> (_shifter + LogBitsPerByte)) + 1)); | |
6719 if (!brs.is_reserved()) { | |
6720 warning("CMS bit map allocation failure"); | |
6721 return false; | |
6722 } | |
6723 // For now we'll just commit all of the bit map up fromt. | |
6724 // Later on we'll try to be more parsimonious with swap. | |
6725 if (!_virtual_space.initialize(brs, brs.size())) { | |
6726 warning("CMS bit map backing store failure"); | |
6727 return false; | |
6728 } | |
6729 assert(_virtual_space.committed_size() == brs.size(), | |
6730 "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
|
6731 _bm.set_map((BitMap::bm_word_t*)_virtual_space.low()); |
0 | 6732 assert(_virtual_space.committed_size() << (_shifter + LogBitsPerByte) >= |
6733 _bmWordSize, "inconsistency in bit map sizing"); | |
6734 _bm.set_size(_bmWordSize >> _shifter); | |
6735 | |
6736 // bm.clear(); // can we rely on getting zero'd memory? verify below | |
6737 assert(isAllClear(), | |
6738 "Expected zero'd memory from ReservedSpace constructor"); | |
6739 assert(_bm.size() == heapWordDiffToOffsetDiff(sizeInWords()), | |
6740 "consistency check"); | |
6741 return true; | |
6742 } | |
6743 | |
6744 void CMSBitMap::dirty_range_iterate_clear(MemRegion mr, MemRegionClosure* cl) { | |
6745 HeapWord *next_addr, *end_addr, *last_addr; | |
6746 assert_locked(); | |
6747 assert(covers(mr), "out-of-range error"); | |
6748 // XXX assert that start and end are appropriately aligned | |
6749 for (next_addr = mr.start(), end_addr = mr.end(); | |
6750 next_addr < end_addr; next_addr = last_addr) { | |
6751 MemRegion dirty_region = getAndClearMarkedRegion(next_addr, end_addr); | |
6752 last_addr = dirty_region.end(); | |
6753 if (!dirty_region.is_empty()) { | |
6754 cl->do_MemRegion(dirty_region); | |
6755 } else { | |
6756 assert(last_addr == end_addr, "program logic"); | |
6757 return; | |
6758 } | |
6759 } | |
6760 } | |
6761 | |
9076
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6762 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
|
6763 _bm.print_on_error(st, prefix); |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6764 } |
7b835924c31c
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
9072
diff
changeset
|
6765 |
0 | 6766 #ifndef PRODUCT |
6767 void CMSBitMap::assert_locked() const { | |
6768 CMSLockVerifier::assert_locked(lock()); | |
6769 } | |
6770 | |
6771 bool CMSBitMap::covers(MemRegion mr) const { | |
6772 // assert(_bm.map() == _virtual_space.low(), "map inconsistency"); | |
6773 assert((size_t)_bm.size() == (_bmWordSize >> _shifter), | |
6774 "size inconsistency"); | |
6775 return (mr.start() >= _bmStartWord) && | |
6776 (mr.end() <= endWord()); | |
6777 } | |
6778 | |
6779 bool CMSBitMap::covers(HeapWord* start, size_t size) const { | |
6780 return (start >= _bmStartWord && (start + size) <= endWord()); | |
6781 } | |
6782 | |
6783 void CMSBitMap::verifyNoOneBitsInRange(HeapWord* left, HeapWord* right) { | |
6784 // verify that there are no 1 bits in the interval [left, right) | |
6785 FalseBitMapClosure falseBitMapClosure; | |
6786 iterate(&falseBitMapClosure, left, right); | |
6787 } | |
6788 | |
6789 void CMSBitMap::region_invariant(MemRegion mr) | |
6790 { | |
6791 assert_locked(); | |
6792 // mr = mr.intersection(MemRegion(_bmStartWord, _bmWordSize)); | |
6793 assert(!mr.is_empty(), "unexpected empty region"); | |
6794 assert(covers(mr), "mr should be covered by bit map"); | |
6795 // convert address range into offset range | |
6796 size_t start_ofs = heapWordToOffset(mr.start()); | |
6797 // Make sure that end() is appropriately aligned | |
6798 assert(mr.end() == (HeapWord*)round_to((intptr_t)mr.end(), | |
6799 (1 << (_shifter+LogHeapWordSize))), | |
6800 "Misaligned mr.end()"); | |
6801 size_t end_ofs = heapWordToOffset(mr.end()); | |
6802 assert(end_ofs > start_ofs, "Should mark at least one bit"); | |
6803 } | |
6804 | |
6805 #endif | |
6806 | |
6807 bool CMSMarkStack::allocate(size_t size) { | |
6808 // allocate a stack of the requisite depth | |
6809 ReservedSpace rs(ReservedSpace::allocation_align_size_up( | |
6810 size * sizeof(oop))); | |
6811 if (!rs.is_reserved()) { | |
6812 warning("CMSMarkStack allocation failure"); | |
6813 return false; | |
6814 } | |
6815 if (!_virtual_space.initialize(rs, rs.size())) { | |
6816 warning("CMSMarkStack backing store failure"); | |
6817 return false; | |
6818 } | |
6819 assert(_virtual_space.committed_size() == rs.size(), | |
6820 "didn't reserve backing store for all of CMS stack?"); | |
6821 _base = (oop*)(_virtual_space.low()); | |
6822 _index = 0; | |
6823 _capacity = size; | |
6824 NOT_PRODUCT(_max_depth = 0); | |
6825 return true; | |
6826 } | |
6827 | |
6828 // XXX FIX ME !!! In the MT case we come in here holding a | |
6829 // leaf lock. For printing we need to take a further lock | |
6830 // which has lower rank. We need to recallibrate the two | |
6831 // lock-ranks involved in order to be able to rpint the | |
6832 // messages below. (Or defer the printing to the caller. | |
6833 // For now we take the expedient path of just disabling the | |
6834 // messages for the problematic case.) | |
6835 void CMSMarkStack::expand() { | |
1284 | 6836 assert(_capacity <= MarkStackSizeMax, "stack bigger than permitted"); |
6837 if (_capacity == MarkStackSizeMax) { | |
0 | 6838 if (_hit_limit++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) { |
6839 // We print a warning message only once per CMS cycle. | |
6840 gclog_or_tty->print_cr(" (benign) Hit CMSMarkStack max size limit"); | |
6841 } | |
6842 return; | |
6843 } | |
6844 // Double capacity if possible | |
1284 | 6845 size_t new_capacity = MIN2(_capacity*2, MarkStackSizeMax); |
0 | 6846 // Do not give up existing stack until we have managed to |
6847 // get the double capacity that we desired. | |
6848 ReservedSpace rs(ReservedSpace::allocation_align_size_up( | |
6849 new_capacity * sizeof(oop))); | |
6850 if (rs.is_reserved()) { | |
6851 // Release the backing store associated with old stack | |
6852 _virtual_space.release(); | |
6853 // Reinitialize virtual space for new stack | |
6854 if (!_virtual_space.initialize(rs, rs.size())) { | |
6855 fatal("Not enough swap for expanded marking stack"); | |
6856 } | |
6857 _base = (oop*)(_virtual_space.low()); | |
6858 _index = 0; | |
6859 _capacity = new_capacity; | |
6860 } else if (_failed_double++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) { | |
6861 // Failed to double capacity, continue; | |
6862 // we print a detail message only once per CMS cycle. | |
6863 gclog_or_tty->print(" (benign) Failed to expand marking stack from "SIZE_FORMAT"K to " | |
6864 SIZE_FORMAT"K", | |
6865 _capacity / K, new_capacity / K); | |
6866 } | |
6867 } | |
6868 | |
6869 | |
6870 // Closures | |
6871 // XXX: there seems to be a lot of code duplication here; | |
6872 // should refactor and consolidate common code. | |
6873 | |
6874 // This closure is used to mark refs into the CMS generation in | |
6875 // the CMS bit map. Called at the first checkpoint. This closure | |
6876 // 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
|
6877 // generation on which this is used is not an oldest |
0 | 6878 // generation then this will lose younger_gen cards! |
6879 | |
6880 MarkRefsIntoClosure::MarkRefsIntoClosure( | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6881 MemRegion span, CMSBitMap* bitMap): |
0 | 6882 _span(span), |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6883 _bitMap(bitMap) |
0 | 6884 { |
6885 assert(_ref_processor == NULL, "deliberately left NULL"); | |
6886 assert(_bitMap->covers(_span), "_bitMap/_span mismatch"); | |
6887 } | |
6888 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6889 void MarkRefsIntoClosure::do_oop(oop obj) { |
0 | 6890 // 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
|
6891 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
|
6892 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6893 if (_span.contains(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6894 // 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
|
6895 _bitMap->mark(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6896 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6897 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6898 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6899 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
|
6900 void MarkRefsIntoClosure::do_oop(narrowOop* p) { MarkRefsIntoClosure::do_oop_work(p); } |
0 | 6901 |
11975 | 6902 Par_MarkRefsIntoClosure::Par_MarkRefsIntoClosure( |
6903 MemRegion span, CMSBitMap* bitMap): | |
6904 _span(span), | |
6905 _bitMap(bitMap) | |
6906 { | |
6907 assert(_ref_processor == NULL, "deliberately left NULL"); | |
6908 assert(_bitMap->covers(_span), "_bitMap/_span mismatch"); | |
6909 } | |
6910 | |
6911 void Par_MarkRefsIntoClosure::do_oop(oop obj) { | |
6912 // if p points into _span, then mark corresponding bit in _markBitMap | |
6913 assert(obj->is_oop(), "expected an oop"); | |
6914 HeapWord* addr = (HeapWord*)obj; | |
6915 if (_span.contains(addr)) { | |
6916 // this should be made more efficient | |
6917 _bitMap->par_mark(addr); | |
6918 } | |
6919 } | |
6920 | |
6921 void Par_MarkRefsIntoClosure::do_oop(oop* p) { Par_MarkRefsIntoClosure::do_oop_work(p); } | |
6922 void Par_MarkRefsIntoClosure::do_oop(narrowOop* p) { Par_MarkRefsIntoClosure::do_oop_work(p); } | |
6923 | |
0 | 6924 // A variant of the above, used for CMS marking verification. |
6925 MarkRefsIntoVerifyClosure::MarkRefsIntoVerifyClosure( | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6926 MemRegion span, CMSBitMap* verification_bm, CMSBitMap* cms_bm): |
0 | 6927 _span(span), |
6928 _verification_bm(verification_bm), | |
994
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6929 _cms_bm(cms_bm) |
753cf9794df9
6885169: merge of 4957990 and 6863023 causes conflict on do_nmethods
jrose
parents:
993
diff
changeset
|
6930 { |
0 | 6931 assert(_ref_processor == NULL, "deliberately left NULL"); |
6932 assert(_verification_bm->covers(_span), "_verification_bm/_span mismatch"); | |
6933 } | |
6934 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6935 void MarkRefsIntoVerifyClosure::do_oop(oop obj) { |
0 | 6936 // 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
|
6937 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
|
6938 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6939 if (_span.contains(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6940 _verification_bm->mark(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6941 if (!_cms_bm->isMarked(addr)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6942 oop(addr)->print(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6943 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
|
6944 fatal("... aborting"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6945 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6946 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6947 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6948 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6949 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
|
6950 void MarkRefsIntoVerifyClosure::do_oop(narrowOop* p) { MarkRefsIntoVerifyClosure::do_oop_work(p); } |
0 | 6951 |
6952 ////////////////////////////////////////////////// | |
6953 // MarkRefsIntoAndScanClosure | |
6954 ////////////////////////////////////////////////// | |
6955 | |
6956 MarkRefsIntoAndScanClosure::MarkRefsIntoAndScanClosure(MemRegion span, | |
6957 ReferenceProcessor* rp, | |
6958 CMSBitMap* bit_map, | |
6959 CMSBitMap* mod_union_table, | |
6960 CMSMarkStack* mark_stack, | |
6961 CMSCollector* collector, | |
6962 bool should_yield, | |
6963 bool concurrent_precleaning): | |
6964 _collector(collector), | |
6965 _span(span), | |
6966 _bit_map(bit_map), | |
6967 _mark_stack(mark_stack), | |
6968 _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
|
6969 mark_stack, concurrent_precleaning), |
0 | 6970 _yield(should_yield), |
6971 _concurrent_precleaning(concurrent_precleaning), | |
6972 _freelistLock(NULL) | |
6973 { | |
6974 _ref_processor = rp; | |
6975 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
6976 } | |
6977 | |
6978 // This closure is used to mark refs into the CMS generation at the | |
6979 // second (final) checkpoint, and to scan and transitively follow | |
6980 // the unmarked oops. It is also used during the concurrent precleaning | |
6981 // phase while scanning objects on dirty cards in the CMS generation. | |
6982 // The marks are made in the marking bit map and the marking stack is | |
6983 // used for keeping the (newly) grey objects during the scan. | |
6984 // 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
|
6985 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
|
6986 if (obj != NULL) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6987 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
|
6988 HeapWord* addr = (HeapWord*)obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
6989 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
|
6990 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
|
6991 "overflow list should be empty"); |
0 | 6992 if (_span.contains(addr) && |
6993 !_bit_map->isMarked(addr)) { | |
6994 // mark bit map (object is now grey) | |
6995 _bit_map->mark(addr); | |
6996 // push on marking stack (stack should be empty), and drain the | |
6997 // stack by applying this closure to the oops in the oops popped | |
6998 // 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
|
6999 bool res = _mark_stack->push(obj); |
0 | 7000 assert(res, "Should have space to push on empty stack"); |
7001 do { | |
7002 oop new_oop = _mark_stack->pop(); | |
7003 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
7004 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
7005 "only grey objects on this stack"); | |
7006 // iterate over the oops in this oop, marking and pushing | |
7007 // the ones in CMS heap (i.e. in _span). | |
7008 new_oop->oop_iterate(&_pushAndMarkClosure); | |
7009 // check if it's time to yield | |
7010 do_yield_check(); | |
7011 } while (!_mark_stack->isEmpty() || | |
7012 (!_concurrent_precleaning && take_from_overflow_list())); | |
7013 // if marking stack is empty, and we are not doing this | |
7014 // during precleaning, then check the overflow list | |
7015 } | |
7016 assert(_mark_stack->isEmpty(), "post-condition (eager drainage)"); | |
7017 assert(_collector->overflow_list_is_empty(), | |
7018 "overflow list was drained above"); | |
7019 // We could restore evacuated mark words, if any, used for | |
7020 // overflow list links here because the overflow list is | |
7021 // provably empty here. That would reduce the maximum | |
7022 // size requirements for preserved_{oop,mark}_stack. | |
7023 // But we'll just postpone it until we are all done | |
7024 // so we can just stream through. | |
7025 if (!_concurrent_precleaning && CMSOverflowEarlyRestoration) { | |
7026 _collector->restore_preserved_marks_if_any(); | |
7027 assert(_collector->no_preserved_marks(), "No preserved marks"); | |
7028 } | |
7029 assert(!CMSOverflowEarlyRestoration || _collector->no_preserved_marks(), | |
7030 "All preserved marks should have been restored above"); | |
7031 } | |
7032 } | |
7033 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7034 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
|
7035 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
|
7036 |
0 | 7037 void MarkRefsIntoAndScanClosure::do_yield_work() { |
7038 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7039 "CMS thread should hold CMS token"); | |
7040 assert_lock_strong(_freelistLock); | |
7041 assert_lock_strong(_bit_map->lock()); | |
7042 // relinquish the free_list_lock and bitMaplock() | |
7043 _bit_map->lock()->unlock(); | |
7044 _freelistLock->unlock(); | |
7045 ConcurrentMarkSweepThread::desynchronize(true); | |
7046 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7047 _collector->stopTimer(); | |
7048 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7049 if (PrintCMSStatistics != 0) { | |
7050 _collector->incrementYields(); | |
7051 } | |
7052 _collector->icms_wait(); | |
7053 | |
7054 // 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
|
7055 for (unsigned i = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7056 i < CMSYieldSleepCount && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7057 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7058 !CMSCollector::foregroundGCIsActive(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7059 ++i) { |
0 | 7060 os::sleep(Thread::current(), 1, false); |
7061 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7062 } | |
7063 | |
7064 ConcurrentMarkSweepThread::synchronize(true); | |
7065 _freelistLock->lock_without_safepoint_check(); | |
7066 _bit_map->lock()->lock_without_safepoint_check(); | |
7067 _collector->startTimer(); | |
7068 } | |
7069 | |
7070 /////////////////////////////////////////////////////////// | |
7071 // Par_MarkRefsIntoAndScanClosure: a parallel version of | |
7072 // MarkRefsIntoAndScanClosure | |
7073 /////////////////////////////////////////////////////////// | |
7074 Par_MarkRefsIntoAndScanClosure::Par_MarkRefsIntoAndScanClosure( | |
7075 CMSCollector* collector, MemRegion span, ReferenceProcessor* rp, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7076 CMSBitMap* bit_map, OopTaskQueue* work_queue): |
0 | 7077 _span(span), |
7078 _bit_map(bit_map), | |
7079 _work_queue(work_queue), | |
7080 _low_water_mark(MIN2((uint)(work_queue->max_elems()/4), | |
7081 (uint)(CMSWorkQueueDrainThreshold * ParallelGCThreads))), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7082 _par_pushAndMarkClosure(collector, span, rp, bit_map, work_queue) |
0 | 7083 { |
7084 _ref_processor = rp; | |
7085 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7086 } | |
7087 | |
7088 // This closure is used to mark refs into the CMS generation at the | |
7089 // second (final) checkpoint, and to scan and transitively follow | |
7090 // the unmarked oops. The marks are made in the marking bit map and | |
7091 // the work_queue is used for keeping the (newly) grey objects during | |
7092 // the scan phase whence they are also available for stealing by parallel | |
7093 // threads. Since the marking bit map is shared, updates are | |
7094 // synchronized (via CAS). | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7095 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
|
7096 if (obj != NULL) { |
0 | 7097 // Ignore mark word because this could be an already marked oop |
7098 // 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
|
7099 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
|
7100 HeapWord* addr = (HeapWord*)obj; |
0 | 7101 if (_span.contains(addr) && |
7102 !_bit_map->isMarked(addr)) { | |
7103 // mark bit map (object will become grey): | |
7104 // It is possible for several threads to be | |
7105 // trying to "claim" this object concurrently; | |
7106 // the unique thread that succeeds in marking the | |
7107 // object first will do the subsequent push on | |
7108 // to the work queue (or overflow list). | |
7109 if (_bit_map->par_mark(addr)) { | |
7110 // push on work_queue (which may not be empty), and trim the | |
7111 // queue to an appropriate length by applying this closure to | |
7112 // the oops in the oops popped from the stack (i.e. blacken the | |
7113 // grey objects) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7114 bool res = _work_queue->push(obj); |
0 | 7115 assert(res, "Low water mark should be less than capacity?"); |
7116 trim_queue(_low_water_mark); | |
7117 } // Else, another thread claimed the object | |
7118 } | |
7119 } | |
7120 } | |
7121 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7122 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
|
7123 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
|
7124 |
0 | 7125 // This closure is used to rescan the marked objects on the dirty cards |
7126 // in the mod union table and the card table proper. | |
7127 size_t ScanMarkedObjectsAgainCarefullyClosure::do_object_careful_m( | |
7128 oop p, MemRegion mr) { | |
7129 | |
7130 size_t size = 0; | |
7131 HeapWord* addr = (HeapWord*)p; | |
7132 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7133 assert(_span.contains(addr), "we are scanning the CMS generation"); | |
7134 // check if it's time to yield | |
7135 if (do_yield_check()) { | |
7136 // We yielded for some foreground stop-world work, | |
7137 // and we have been asked to abort this ongoing preclean cycle. | |
7138 return 0; | |
7139 } | |
7140 if (_bitMap->isMarked(addr)) { | |
7141 // it's marked; is it potentially uninitialized? | |
187 | 7142 if (p->klass_or_null() != NULL) { |
0 | 7143 // an initialized object; ignore mark word in verification below |
7144 // since we are running concurrent with mutators | |
7145 assert(p->is_oop(true), "should be an oop"); | |
7146 if (p->is_objArray()) { | |
7147 // objArrays are precisely marked; restrict scanning | |
7148 // to dirty cards only. | |
187 | 7149 size = CompactibleFreeListSpace::adjustObjectSize( |
7150 p->oop_iterate(_scanningClosure, mr)); | |
0 | 7151 } else { |
7152 // A non-array may have been imprecisely marked; we need | |
7153 // to scan object in its entirety. | |
7154 size = CompactibleFreeListSpace::adjustObjectSize( | |
7155 p->oop_iterate(_scanningClosure)); | |
7156 } | |
9152 | 7157 #ifdef ASSERT |
0 | 7158 size_t direct_size = |
7159 CompactibleFreeListSpace::adjustObjectSize(p->size()); | |
7160 assert(size == direct_size, "Inconsistency in size"); | |
7161 assert(size >= 3, "Necessary for Printezis marks to work"); | |
7162 if (!_bitMap->isMarked(addr+1)) { | |
7163 _bitMap->verifyNoOneBitsInRange(addr+2, addr+size); | |
7164 } else { | |
7165 _bitMap->verifyNoOneBitsInRange(addr+2, addr+size-1); | |
7166 assert(_bitMap->isMarked(addr+size-1), | |
7167 "inconsistent Printezis mark"); | |
7168 } | |
9152 | 7169 #endif // ASSERT |
0 | 7170 } else { |
7171 // an unitialized object | |
7172 assert(_bitMap->isMarked(addr+1), "missing Printezis mark?"); | |
7173 HeapWord* nextOneAddr = _bitMap->getNextMarkedWordAddress(addr + 2); | |
7174 size = pointer_delta(nextOneAddr + 1, addr); | |
7175 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
7176 "alignment problem"); | |
7177 // Note that pre-cleaning needn't redirty the card. OopDesc::set_klass() | |
7178 // will dirty the card when the klass pointer is installed in the | |
7179 // object (signalling the completion of initialization). | |
7180 } | |
7181 } else { | |
7182 // 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
|
7183 if (p->klass_or_null() == NULL) { |
0 | 7184 // An uninitialized object, skip to the next card, since |
7185 // we may not be able to read its P-bits yet. | |
7186 assert(size == 0, "Initial value"); | |
7187 } else { | |
7188 // An object not (yet) reached by marking: we merely need to | |
7189 // compute its size so as to go look at the next block. | |
7190 assert(p->is_oop(true), "should be an oop"); | |
7191 size = CompactibleFreeListSpace::adjustObjectSize(p->size()); | |
7192 } | |
7193 } | |
7194 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7195 return size; | |
7196 } | |
7197 | |
7198 void ScanMarkedObjectsAgainCarefullyClosure::do_yield_work() { | |
7199 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7200 "CMS thread should hold CMS token"); | |
7201 assert_lock_strong(_freelistLock); | |
7202 assert_lock_strong(_bitMap->lock()); | |
7203 // relinquish the free_list_lock and bitMaplock() | |
7204 _bitMap->lock()->unlock(); | |
7205 _freelistLock->unlock(); | |
7206 ConcurrentMarkSweepThread::desynchronize(true); | |
7207 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7208 _collector->stopTimer(); | |
7209 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7210 if (PrintCMSStatistics != 0) { | |
7211 _collector->incrementYields(); | |
7212 } | |
7213 _collector->icms_wait(); | |
7214 | |
7215 // See the comment in coordinator_yield() | |
7216 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
|
7217 ConcurrentMarkSweepThread::should_yield() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7218 !CMSCollector::foregroundGCIsActive(); ++i) { |
0 | 7219 os::sleep(Thread::current(), 1, false); |
7220 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7221 } | |
7222 | |
7223 ConcurrentMarkSweepThread::synchronize(true); | |
7224 _freelistLock->lock_without_safepoint_check(); | |
7225 _bitMap->lock()->lock_without_safepoint_check(); | |
7226 _collector->startTimer(); | |
7227 } | |
7228 | |
7229 | |
7230 ////////////////////////////////////////////////////////////////// | |
7231 // SurvivorSpacePrecleanClosure | |
7232 ////////////////////////////////////////////////////////////////// | |
7233 // This (single-threaded) closure is used to preclean the oops in | |
7234 // the survivor spaces. | |
7235 size_t SurvivorSpacePrecleanClosure::do_object_careful(oop p) { | |
7236 | |
7237 HeapWord* addr = (HeapWord*)p; | |
7238 DEBUG_ONLY(_collector->verify_work_stacks_empty();) | |
7239 assert(!_span.contains(addr), "we are scanning the survivor spaces"); | |
187 | 7240 assert(p->klass_or_null() != NULL, "object should be initializd"); |
0 | 7241 // an initialized object; ignore mark word in verification below |
7242 // since we are running concurrent with mutators | |
7243 assert(p->is_oop(true), "should be an oop"); | |
7244 // Note that we do not yield while we iterate over | |
7245 // the interior oops of p, pushing the relevant ones | |
7246 // on our marking stack. | |
7247 size_t size = p->oop_iterate(_scanning_closure); | |
7248 do_yield_check(); | |
7249 // Observe that below, we do not abandon the preclean | |
7250 // phase as soon as we should; rather we empty the | |
7251 // marking stack before returning. This is to satisfy | |
7252 // some existing assertions. In general, it may be a | |
7253 // good idea to abort immediately and complete the marking | |
7254 // from the grey objects at a later time. | |
7255 while (!_mark_stack->isEmpty()) { | |
7256 oop new_oop = _mark_stack->pop(); | |
7257 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
7258 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
7259 "only grey objects on this stack"); | |
7260 // iterate over the oops in this oop, marking and pushing | |
7261 // the ones in CMS heap (i.e. in _span). | |
7262 new_oop->oop_iterate(_scanning_closure); | |
7263 // check if it's time to yield | |
7264 do_yield_check(); | |
7265 } | |
7266 unsigned int after_count = | |
7267 GenCollectedHeap::heap()->total_collections(); | |
7268 bool abort = (_before_count != after_count) || | |
7269 _collector->should_abort_preclean(); | |
7270 return abort ? 0 : size; | |
7271 } | |
7272 | |
7273 void SurvivorSpacePrecleanClosure::do_yield_work() { | |
7274 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7275 "CMS thread should hold CMS token"); | |
7276 assert_lock_strong(_bit_map->lock()); | |
7277 // Relinquish the bit map lock | |
7278 _bit_map->lock()->unlock(); | |
7279 ConcurrentMarkSweepThread::desynchronize(true); | |
7280 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7281 _collector->stopTimer(); | |
7282 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7283 if (PrintCMSStatistics != 0) { | |
7284 _collector->incrementYields(); | |
7285 } | |
7286 _collector->icms_wait(); | |
7287 | |
7288 // See the comment in coordinator_yield() | |
7289 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7290 ConcurrentMarkSweepThread::should_yield() && | |
7291 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7292 os::sleep(Thread::current(), 1, false); | |
7293 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7294 } | |
7295 | |
7296 ConcurrentMarkSweepThread::synchronize(true); | |
7297 _bit_map->lock()->lock_without_safepoint_check(); | |
7298 _collector->startTimer(); | |
7299 } | |
7300 | |
7301 // This closure is used to rescan the marked objects on the dirty cards | |
7302 // in the mod union table and the card table proper. In the parallel | |
7303 // case, although the bitMap is shared, we do a single read so the | |
7304 // isMarked() query is "safe". | |
7305 bool ScanMarkedObjectsAgainClosure::do_object_bm(oop p, MemRegion mr) { | |
7306 // Ignore mark word because we are running concurrent with mutators | |
7307 assert(p->is_oop_or_null(true), "expected an oop or null"); | |
7308 HeapWord* addr = (HeapWord*)p; | |
7309 assert(_span.contains(addr), "we are scanning the CMS generation"); | |
7310 bool is_obj_array = false; | |
9152 | 7311 #ifdef ASSERT |
0 | 7312 if (!_parallel) { |
7313 assert(_mark_stack->isEmpty(), "pre-condition (eager drainage)"); | |
7314 assert(_collector->overflow_list_is_empty(), | |
7315 "overflow list should be empty"); | |
7316 | |
7317 } | |
9152 | 7318 #endif // ASSERT |
0 | 7319 if (_bit_map->isMarked(addr)) { |
7320 // Obj arrays are precisely marked, non-arrays are not; | |
7321 // so we scan objArrays precisely and non-arrays in their | |
7322 // entirety. | |
7323 if (p->is_objArray()) { | |
7324 is_obj_array = true; | |
7325 if (_parallel) { | |
7326 p->oop_iterate(_par_scan_closure, mr); | |
7327 } else { | |
7328 p->oop_iterate(_scan_closure, mr); | |
7329 } | |
7330 } else { | |
7331 if (_parallel) { | |
7332 p->oop_iterate(_par_scan_closure); | |
7333 } else { | |
7334 p->oop_iterate(_scan_closure); | |
7335 } | |
7336 } | |
7337 } | |
9152 | 7338 #ifdef ASSERT |
0 | 7339 if (!_parallel) { |
7340 assert(_mark_stack->isEmpty(), "post-condition (eager drainage)"); | |
7341 assert(_collector->overflow_list_is_empty(), | |
7342 "overflow list should be empty"); | |
7343 | |
7344 } | |
9152 | 7345 #endif // ASSERT |
0 | 7346 return is_obj_array; |
7347 } | |
7348 | |
7349 MarkFromRootsClosure::MarkFromRootsClosure(CMSCollector* collector, | |
7350 MemRegion span, | |
7351 CMSBitMap* bitMap, CMSMarkStack* markStack, | |
7352 bool should_yield, bool verifying): | |
7353 _collector(collector), | |
7354 _span(span), | |
7355 _bitMap(bitMap), | |
7356 _mut(&collector->_modUnionTable), | |
7357 _markStack(markStack), | |
7358 _yield(should_yield), | |
7359 _skipBits(0) | |
7360 { | |
7361 assert(_markStack->isEmpty(), "stack should be empty"); | |
7362 _finger = _bitMap->startWord(); | |
7363 _threshold = _finger; | |
7364 assert(_collector->_restart_addr == NULL, "Sanity check"); | |
7365 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7366 DEBUG_ONLY(_verifying = verifying;) | |
7367 } | |
7368 | |
7369 void MarkFromRootsClosure::reset(HeapWord* addr) { | |
7370 assert(_markStack->isEmpty(), "would cause duplicates on stack"); | |
7371 assert(_span.contains(addr), "Out of bounds _finger?"); | |
7372 _finger = addr; | |
7373 _threshold = (HeapWord*)round_to( | |
7374 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7375 } | |
7376 | |
7377 // Should revisit to see if this should be restructured for | |
7378 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7379 bool MarkFromRootsClosure::do_bit(size_t offset) { |
0 | 7380 if (_skipBits > 0) { |
7381 _skipBits--; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7382 return true; |
0 | 7383 } |
7384 // convert offset into a HeapWord* | |
7385 HeapWord* addr = _bitMap->startWord() + offset; | |
7386 assert(_bitMap->endWord() && addr < _bitMap->endWord(), | |
7387 "address out of range"); | |
7388 assert(_bitMap->isMarked(addr), "tautology"); | |
7389 if (_bitMap->isMarked(addr+1)) { | |
7390 // this is an allocated but not yet initialized object | |
7391 assert(_skipBits == 0, "tautology"); | |
7392 _skipBits = 2; // skip next two marked bits ("Printezis-marks") | |
7393 oop p = oop(addr); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7394 if (p->klass_or_null() == NULL) { |
0 | 7395 DEBUG_ONLY(if (!_verifying) {) |
7396 // We re-dirty the cards on which this object lies and increase | |
7397 // the _threshold so that we'll come back to scan this object | |
7398 // during the preclean or remark phase. (CMSCleanOnEnter) | |
7399 if (CMSCleanOnEnter) { | |
7400 size_t sz = _collector->block_size_using_printezis_bits(addr); | |
7401 HeapWord* end_card_addr = (HeapWord*)round_to( | |
7402 (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
|
7403 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
0 | 7404 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
7405 // Bump _threshold to end_card_addr; note that | |
7406 // _threshold cannot possibly exceed end_card_addr, anyhow. | |
7407 // This prevents future clearing of the card as the scan proceeds | |
7408 // to the right. | |
7409 assert(_threshold <= end_card_addr, | |
7410 "Because we are just scanning into this object"); | |
7411 if (_threshold < end_card_addr) { | |
7412 _threshold = end_card_addr; | |
7413 } | |
187 | 7414 if (p->klass_or_null() != NULL) { |
0 | 7415 // Redirty the range of cards... |
7416 _mut->mark_range(redirty_range); | |
7417 } // ...else the setting of klass will dirty the card anyway. | |
7418 } | |
7419 DEBUG_ONLY(}) | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7420 return true; |
0 | 7421 } |
7422 } | |
7423 scanOopsInOop(addr); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7424 return true; |
0 | 7425 } |
7426 | |
7427 // We take a break if we've been at this for a while, | |
7428 // so as to avoid monopolizing the locks involved. | |
7429 void MarkFromRootsClosure::do_yield_work() { | |
7430 // First give up the locks, then yield, then re-lock | |
7431 // We should probably use a constructor/destructor idiom to | |
7432 // do this unlock/lock or modify the MutexUnlocker class to | |
7433 // serve our purpose. XXX | |
7434 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
7435 "CMS thread should hold CMS token"); | |
7436 assert_lock_strong(_bitMap->lock()); | |
7437 _bitMap->lock()->unlock(); | |
7438 ConcurrentMarkSweepThread::desynchronize(true); | |
7439 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7440 _collector->stopTimer(); | |
7441 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
7442 if (PrintCMSStatistics != 0) { | |
7443 _collector->incrementYields(); | |
7444 } | |
7445 _collector->icms_wait(); | |
7446 | |
7447 // See the comment in coordinator_yield() | |
7448 for (unsigned i = 0; i < CMSYieldSleepCount && | |
7449 ConcurrentMarkSweepThread::should_yield() && | |
7450 !CMSCollector::foregroundGCIsActive(); ++i) { | |
7451 os::sleep(Thread::current(), 1, false); | |
7452 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
7453 } | |
7454 | |
7455 ConcurrentMarkSweepThread::synchronize(true); | |
7456 _bitMap->lock()->lock_without_safepoint_check(); | |
7457 _collector->startTimer(); | |
7458 } | |
7459 | |
7460 void MarkFromRootsClosure::scanOopsInOop(HeapWord* ptr) { | |
7461 assert(_bitMap->isMarked(ptr), "expected bit to be set"); | |
7462 assert(_markStack->isEmpty(), | |
7463 "should drain stack to limit stack usage"); | |
7464 // 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
|
7465 oop obj = oop(ptr); |
0 | 7466 // Ignore mark word in verification below, since we |
7467 // 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
|
7468 assert(obj->is_oop(true), "should be an oop"); |
0 | 7469 assert(_finger <= ptr, "_finger runneth ahead"); |
7470 // 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
|
7471 _finger = ptr + obj->size(); |
0 | 7472 assert(_finger > ptr, "we just incremented it above"); |
7473 // On large heaps, it may take us some time to get through | |
7474 // the marking phase (especially if running iCMS). During | |
7475 // this time it's possible that a lot of mutations have | |
7476 // accumulated in the card table and the mod union table -- | |
7477 // these mutation records are redundant until we have | |
7478 // actually traced into the corresponding card. | |
7479 // Here, we check whether advancing the finger would make | |
7480 // us cross into a new card, and if so clear corresponding | |
7481 // cards in the MUT (preclean them in the card-table in the | |
7482 // future). | |
7483 | |
7484 DEBUG_ONLY(if (!_verifying) {) | |
7485 // The clean-on-enter optimization is disabled by default, | |
7486 // until we fix 6178663. | |
7487 if (CMSCleanOnEnter && (_finger > _threshold)) { | |
7488 // [_threshold, _finger) represents the interval | |
7489 // of cards to be cleared in MUT (or precleaned in card table). | |
7490 // The set of cards to be cleared is all those that overlap | |
7491 // with the interval [_threshold, _finger); note that | |
7492 // _threshold is always kept card-aligned but _finger isn't | |
7493 // always card-aligned. | |
7494 HeapWord* old_threshold = _threshold; | |
7495 assert(old_threshold == (HeapWord*)round_to( | |
7496 (intptr_t)old_threshold, CardTableModRefBS::card_size), | |
7497 "_threshold should always be card-aligned"); | |
7498 _threshold = (HeapWord*)round_to( | |
7499 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7500 MemRegion mr(old_threshold, _threshold); | |
7501 assert(!mr.is_empty(), "Control point invariant"); | |
7502 assert(_span.contains(mr), "Should clear within span"); | |
7503 _mut->clear_range(mr); | |
7504 } | |
7505 DEBUG_ONLY(}) | |
7506 // Note: the finger doesn't advance while we drain | |
7507 // the stack below. | |
7508 PushOrMarkClosure pushOrMarkClosure(_collector, | |
7509 _span, _bitMap, _markStack, | |
7510 _finger, this); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7511 bool res = _markStack->push(obj); |
0 | 7512 assert(res, "Empty non-zero size stack should have space for single push"); |
7513 while (!_markStack->isEmpty()) { | |
7514 oop new_oop = _markStack->pop(); | |
7515 // Skip verifying header mark word below because we are | |
7516 // running concurrent with mutators. | |
7517 assert(new_oop->is_oop(true), "Oops! expected to pop an oop"); | |
7518 // now scan this oop's oops | |
7519 new_oop->oop_iterate(&pushOrMarkClosure); | |
7520 do_yield_check(); | |
7521 } | |
7522 assert(_markStack->isEmpty(), "tautology, emphasizing post-condition"); | |
7523 } | |
7524 | |
7525 Par_MarkFromRootsClosure::Par_MarkFromRootsClosure(CMSConcMarkingTask* task, | |
7526 CMSCollector* collector, MemRegion span, | |
7527 CMSBitMap* bit_map, | |
7528 OopTaskQueue* work_queue, | |
7529 CMSMarkStack* overflow_stack, | |
7530 bool should_yield): | |
7531 _collector(collector), | |
7532 _whole_span(collector->_span), | |
7533 _span(span), | |
7534 _bit_map(bit_map), | |
7535 _mut(&collector->_modUnionTable), | |
7536 _work_queue(work_queue), | |
7537 _overflow_stack(overflow_stack), | |
7538 _yield(should_yield), | |
7539 _skip_bits(0), | |
7540 _task(task) | |
7541 { | |
7542 assert(_work_queue->size() == 0, "work_queue should be empty"); | |
7543 _finger = span.start(); | |
7544 _threshold = _finger; // XXX Defer clear-on-enter optimization for now | |
7545 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7546 } | |
7547 | |
7548 // Should revisit to see if this should be restructured for | |
7549 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7550 bool Par_MarkFromRootsClosure::do_bit(size_t offset) { |
0 | 7551 if (_skip_bits > 0) { |
7552 _skip_bits--; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7553 return true; |
0 | 7554 } |
7555 // convert offset into a HeapWord* | |
7556 HeapWord* addr = _bit_map->startWord() + offset; | |
7557 assert(_bit_map->endWord() && addr < _bit_map->endWord(), | |
7558 "address out of range"); | |
7559 assert(_bit_map->isMarked(addr), "tautology"); | |
7560 if (_bit_map->isMarked(addr+1)) { | |
7561 // this is an allocated object that might not yet be initialized | |
7562 assert(_skip_bits == 0, "tautology"); | |
7563 _skip_bits = 2; // skip next two marked bits ("Printezis-marks") | |
7564 oop p = oop(addr); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7565 if (p->klass_or_null() == NULL) { |
0 | 7566 // in the case of Clean-on-Enter optimization, redirty card |
7567 // and avoid clearing card by increasing the threshold. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7568 return true; |
0 | 7569 } |
7570 } | |
7571 scan_oops_in_oop(addr); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7572 return true; |
0 | 7573 } |
7574 | |
7575 void Par_MarkFromRootsClosure::scan_oops_in_oop(HeapWord* ptr) { | |
7576 assert(_bit_map->isMarked(ptr), "expected bit to be set"); | |
7577 // Should we assert that our work queue is empty or | |
7578 // below some drain limit? | |
7579 assert(_work_queue->size() == 0, | |
7580 "should drain stack to limit stack usage"); | |
7581 // 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
|
7582 oop obj = oop(ptr); |
0 | 7583 // Ignore mark word in verification below, since we |
7584 // 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
|
7585 assert(obj->is_oop(true), "should be an oop"); |
0 | 7586 assert(_finger <= ptr, "_finger runneth ahead"); |
7587 // 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
|
7588 _finger = ptr + obj->size(); |
0 | 7589 assert(_finger > ptr, "we just incremented it above"); |
7590 // On large heaps, it may take us some time to get through | |
7591 // the marking phase (especially if running iCMS). During | |
7592 // this time it's possible that a lot of mutations have | |
7593 // accumulated in the card table and the mod union table -- | |
7594 // these mutation records are redundant until we have | |
7595 // actually traced into the corresponding card. | |
7596 // Here, we check whether advancing the finger would make | |
7597 // us cross into a new card, and if so clear corresponding | |
7598 // cards in the MUT (preclean them in the card-table in the | |
7599 // future). | |
7600 | |
7601 // The clean-on-enter optimization is disabled by default, | |
7602 // until we fix 6178663. | |
7603 if (CMSCleanOnEnter && (_finger > _threshold)) { | |
7604 // [_threshold, _finger) represents the interval | |
7605 // of cards to be cleared in MUT (or precleaned in card table). | |
7606 // The set of cards to be cleared is all those that overlap | |
7607 // with the interval [_threshold, _finger); note that | |
7608 // _threshold is always kept card-aligned but _finger isn't | |
7609 // always card-aligned. | |
7610 HeapWord* old_threshold = _threshold; | |
7611 assert(old_threshold == (HeapWord*)round_to( | |
7612 (intptr_t)old_threshold, CardTableModRefBS::card_size), | |
7613 "_threshold should always be card-aligned"); | |
7614 _threshold = (HeapWord*)round_to( | |
7615 (intptr_t)_finger, CardTableModRefBS::card_size); | |
7616 MemRegion mr(old_threshold, _threshold); | |
7617 assert(!mr.is_empty(), "Control point invariant"); | |
7618 assert(_span.contains(mr), "Should clear within span"); // _whole_span ?? | |
7619 _mut->clear_range(mr); | |
7620 } | |
7621 | |
7622 // Note: the local finger doesn't advance while we drain | |
7623 // the stack below, but the global finger sure can and will. | |
7624 HeapWord** gfa = _task->global_finger_addr(); | |
7625 Par_PushOrMarkClosure pushOrMarkClosure(_collector, | |
7626 _span, _bit_map, | |
7627 _work_queue, | |
7628 _overflow_stack, | |
7629 _finger, | |
7630 gfa, this); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7631 bool res = _work_queue->push(obj); // overflow could occur here |
0 | 7632 assert(res, "Will hold once we use workqueues"); |
7633 while (true) { | |
7634 oop new_oop; | |
7635 if (!_work_queue->pop_local(new_oop)) { | |
7636 // We emptied our work_queue; check if there's stuff that can | |
7637 // be gotten from the overflow stack. | |
7638 if (CMSConcMarkingTask::get_work_from_overflow_stack( | |
7639 _overflow_stack, _work_queue)) { | |
7640 do_yield_check(); | |
7641 continue; | |
7642 } else { // done | |
7643 break; | |
7644 } | |
7645 } | |
7646 // Skip verifying header mark word below because we are | |
7647 // running concurrent with mutators. | |
7648 assert(new_oop->is_oop(true), "Oops! expected to pop an oop"); | |
7649 // now scan this oop's oops | |
7650 new_oop->oop_iterate(&pushOrMarkClosure); | |
7651 do_yield_check(); | |
7652 } | |
7653 assert(_work_queue->size() == 0, "tautology, emphasizing post-condition"); | |
7654 } | |
7655 | |
7656 // Yield in response to a request from VM Thread or | |
7657 // from mutators. | |
7658 void Par_MarkFromRootsClosure::do_yield_work() { | |
7659 assert(_task != NULL, "sanity"); | |
7660 _task->yield(); | |
7661 } | |
7662 | |
7663 // A variant of the above used for verifying CMS marking work. | |
7664 MarkFromRootsVerifyClosure::MarkFromRootsVerifyClosure(CMSCollector* collector, | |
7665 MemRegion span, | |
7666 CMSBitMap* verification_bm, CMSBitMap* cms_bm, | |
7667 CMSMarkStack* mark_stack): | |
7668 _collector(collector), | |
7669 _span(span), | |
7670 _verification_bm(verification_bm), | |
7671 _cms_bm(cms_bm), | |
7672 _mark_stack(mark_stack), | |
7673 _pam_verify_closure(collector, span, verification_bm, cms_bm, | |
7674 mark_stack) | |
7675 { | |
7676 assert(_mark_stack->isEmpty(), "stack should be empty"); | |
7677 _finger = _verification_bm->startWord(); | |
7678 assert(_collector->_restart_addr == NULL, "Sanity check"); | |
7679 assert(_span.contains(_finger), "Out of bounds _finger?"); | |
7680 } | |
7681 | |
7682 void MarkFromRootsVerifyClosure::reset(HeapWord* addr) { | |
7683 assert(_mark_stack->isEmpty(), "would cause duplicates on stack"); | |
7684 assert(_span.contains(addr), "Out of bounds _finger?"); | |
7685 _finger = addr; | |
7686 } | |
7687 | |
7688 // Should revisit to see if this should be restructured for | |
7689 // greater efficiency. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7690 bool MarkFromRootsVerifyClosure::do_bit(size_t offset) { |
0 | 7691 // convert offset into a HeapWord* |
7692 HeapWord* addr = _verification_bm->startWord() + offset; | |
7693 assert(_verification_bm->endWord() && addr < _verification_bm->endWord(), | |
7694 "address out of range"); | |
7695 assert(_verification_bm->isMarked(addr), "tautology"); | |
7696 assert(_cms_bm->isMarked(addr), "tautology"); | |
7697 | |
7698 assert(_mark_stack->isEmpty(), | |
7699 "should drain stack to limit stack usage"); | |
7700 // 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
|
7701 oop obj = oop(addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7702 assert(obj->is_oop(), "should be an oop"); |
0 | 7703 assert(_finger <= addr, "_finger runneth ahead"); |
7704 // 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
|
7705 _finger = addr + obj->size(); |
0 | 7706 assert(_finger > addr, "we just incremented it above"); |
7707 // Note: the finger doesn't advance while we drain | |
7708 // the stack below. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7709 bool res = _mark_stack->push(obj); |
0 | 7710 assert(res, "Empty non-zero size stack should have space for single push"); |
7711 while (!_mark_stack->isEmpty()) { | |
7712 oop new_oop = _mark_stack->pop(); | |
7713 assert(new_oop->is_oop(), "Oops! expected to pop an oop"); | |
7714 // now scan this oop's oops | |
7715 new_oop->oop_iterate(&_pam_verify_closure); | |
7716 } | |
7717 assert(_mark_stack->isEmpty(), "tautology, emphasizing post-condition"); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7718 return true; |
0 | 7719 } |
7720 | |
7721 PushAndMarkVerifyClosure::PushAndMarkVerifyClosure( | |
7722 CMSCollector* collector, MemRegion span, | |
7723 CMSBitMap* verification_bm, CMSBitMap* cms_bm, | |
7724 CMSMarkStack* mark_stack): | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7725 MetadataAwareOopClosure(collector->ref_processor()), |
0 | 7726 _collector(collector), |
7727 _span(span), | |
7728 _verification_bm(verification_bm), | |
7729 _cms_bm(cms_bm), | |
7730 _mark_stack(mark_stack) | |
7731 { } | |
7732 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7733 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
|
7734 void PushAndMarkVerifyClosure::do_oop(narrowOop* p) { PushAndMarkVerifyClosure::do_oop_work(p); } |
0 | 7735 |
7736 // Upon stack overflow, we discard (part of) the stack, | |
7737 // remembering the least address amongst those discarded | |
7738 // in CMSCollector's _restart_address. | |
7739 void PushAndMarkVerifyClosure::handle_stack_overflow(HeapWord* lost) { | |
7740 // Remember the least grey address discarded | |
7741 HeapWord* ra = (HeapWord*)_mark_stack->least_value(lost); | |
7742 _collector->lower_restart_addr(ra); | |
7743 _mark_stack->reset(); // discard stack contents | |
7744 _mark_stack->expand(); // expand the stack if possible | |
7745 } | |
7746 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7747 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
|
7748 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
|
7749 HeapWord* addr = (HeapWord*)obj; |
0 | 7750 if (_span.contains(addr) && !_verification_bm->isMarked(addr)) { |
7751 // Oop lies in _span and isn't yet grey or black | |
7752 _verification_bm->mark(addr); // now grey | |
7753 if (!_cms_bm->isMarked(addr)) { | |
7754 oop(addr)->print(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7755 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
|
7756 addr); |
0 | 7757 fatal("... aborting"); |
7758 } | |
7759 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7760 if (!_mark_stack->push(obj)) { // stack overflow |
0 | 7761 if (PrintCMSStatistics != 0) { |
7762 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7763 SIZE_FORMAT, _mark_stack->capacity()); | |
7764 } | |
7765 assert(_mark_stack->isFull(), "Else push should have succeeded"); | |
7766 handle_stack_overflow(addr); | |
7767 } | |
7768 // anything including and to the right of _finger | |
7769 // will be scanned as we iterate over the remainder of the | |
7770 // bit map | |
7771 } | |
7772 } | |
7773 | |
7774 PushOrMarkClosure::PushOrMarkClosure(CMSCollector* collector, | |
7775 MemRegion span, | |
7776 CMSBitMap* bitMap, CMSMarkStack* markStack, | |
7777 HeapWord* finger, MarkFromRootsClosure* parent) : | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7778 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7779 _collector(collector), |
0 | 7780 _span(span), |
7781 _bitMap(bitMap), | |
7782 _markStack(markStack), | |
7783 _finger(finger), | |
935 | 7784 _parent(parent) |
0 | 7785 { } |
7786 | |
7787 Par_PushOrMarkClosure::Par_PushOrMarkClosure(CMSCollector* collector, | |
7788 MemRegion span, | |
7789 CMSBitMap* bit_map, | |
7790 OopTaskQueue* work_queue, | |
7791 CMSMarkStack* overflow_stack, | |
7792 HeapWord* finger, | |
7793 HeapWord** global_finger_addr, | |
7794 Par_MarkFromRootsClosure* parent) : | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7795 MetadataAwareOopClosure(collector->ref_processor()), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7796 _collector(collector), |
0 | 7797 _whole_span(collector->_span), |
7798 _span(span), | |
7799 _bit_map(bit_map), | |
7800 _work_queue(work_queue), | |
7801 _overflow_stack(overflow_stack), | |
7802 _finger(finger), | |
7803 _global_finger_addr(global_finger_addr), | |
935 | 7804 _parent(parent) |
0 | 7805 { } |
7806 | |
340
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7807 // Assumes thread-safe access by callers, who are |
ebeb6490b814
6722116: CMS: Incorrect overflow handling when using parallel concurrent marking
ysr
parents:
283
diff
changeset
|
7808 // responsible for mutual exclusion. |
0 | 7809 void CMSCollector::lower_restart_addr(HeapWord* low) { |
7810 assert(_span.contains(low), "Out of bounds addr"); | |
7811 if (_restart_addr == NULL) { | |
7812 _restart_addr = low; | |
7813 } else { | |
7814 _restart_addr = MIN2(_restart_addr, low); | |
7815 } | |
7816 } | |
7817 | |
7818 // Upon stack overflow, we discard (part of) the stack, | |
7819 // remembering the least address amongst those discarded | |
7820 // in CMSCollector's _restart_address. | |
7821 void PushOrMarkClosure::handle_stack_overflow(HeapWord* lost) { | |
7822 // Remember the least grey address discarded | |
7823 HeapWord* ra = (HeapWord*)_markStack->least_value(lost); | |
7824 _collector->lower_restart_addr(ra); | |
7825 _markStack->reset(); // discard stack contents | |
7826 _markStack->expand(); // expand the stack if possible | |
7827 } | |
7828 | |
7829 // Upon stack overflow, we discard (part of) the stack, | |
7830 // remembering the least address amongst those discarded | |
7831 // in CMSCollector's _restart_address. | |
7832 void Par_PushOrMarkClosure::handle_stack_overflow(HeapWord* lost) { | |
7833 // 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
|
7834 // workers from interfering with the work done below. |
0 | 7835 MutexLockerEx ml(_overflow_stack->par_lock(), |
7836 Mutex::_no_safepoint_check_flag); | |
7837 // Remember the least grey address discarded | |
7838 HeapWord* ra = (HeapWord*)_overflow_stack->least_value(lost); | |
7839 _collector->lower_restart_addr(ra); | |
7840 _overflow_stack->reset(); // discard stack contents | |
7841 _overflow_stack->expand(); // expand the stack if possible | |
7842 } | |
7843 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7844 void PushOrMarkClosure::do_oop(oop obj) { |
0 | 7845 // 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
|
7846 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
|
7847 HeapWord* addr = (HeapWord*)obj; |
0 | 7848 if (_span.contains(addr) && !_bitMap->isMarked(addr)) { |
7849 // Oop lies in _span and isn't yet grey or black | |
7850 _bitMap->mark(addr); // now grey | |
7851 if (addr < _finger) { | |
7852 // the bit map iteration has already either passed, or | |
7853 // sampled, this bit in the bit map; we'll need to | |
7854 // use the marking stack to scan this oop's oops. | |
7855 bool simulate_overflow = false; | |
7856 NOT_PRODUCT( | |
7857 if (CMSMarkStackOverflowALot && | |
7858 _collector->simulate_overflow()) { | |
7859 // simulate a stack overflow | |
7860 simulate_overflow = true; | |
7861 } | |
7862 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7863 if (simulate_overflow || !_markStack->push(obj)) { // stack overflow |
0 | 7864 if (PrintCMSStatistics != 0) { |
7865 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7866 SIZE_FORMAT, _markStack->capacity()); | |
7867 } | |
7868 assert(simulate_overflow || _markStack->isFull(), "Else push should have succeeded"); | |
7869 handle_stack_overflow(addr); | |
7870 } | |
7871 } | |
7872 // anything including and to the right of _finger | |
7873 // will be scanned as we iterate over the remainder of the | |
7874 // bit map | |
7875 do_yield_check(); | |
7876 } | |
7877 } | |
7878 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7879 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
|
7880 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
|
7881 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7882 void Par_PushOrMarkClosure::do_oop(oop obj) { |
0 | 7883 // 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
|
7884 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
|
7885 HeapWord* addr = (HeapWord*)obj; |
0 | 7886 if (_whole_span.contains(addr) && !_bit_map->isMarked(addr)) { |
7887 // Oop lies in _span and isn't yet grey or black | |
7888 // We read the global_finger (volatile read) strictly after marking oop | |
7889 bool res = _bit_map->par_mark(addr); // now grey | |
7890 volatile HeapWord** gfa = (volatile HeapWord**)_global_finger_addr; | |
7891 // Should we push this marked oop on our stack? | |
7892 // -- if someone else marked it, nothing to do | |
7893 // -- if target oop is above global finger nothing to do | |
7894 // -- if target oop is in chunk and above local finger | |
7895 // then nothing to do | |
7896 // -- else push on work queue | |
7897 if ( !res // someone else marked it, they will deal with it | |
7898 || (addr >= *gfa) // will be scanned in a later task | |
7899 || (_span.contains(addr) && addr >= _finger)) { // later in this chunk | |
7900 return; | |
7901 } | |
7902 // the bit map iteration has already either passed, or | |
7903 // sampled, this bit in the bit map; we'll need to | |
7904 // use the marking stack to scan this oop's oops. | |
7905 bool simulate_overflow = false; | |
7906 NOT_PRODUCT( | |
7907 if (CMSMarkStackOverflowALot && | |
7908 _collector->simulate_overflow()) { | |
7909 // simulate a stack overflow | |
7910 simulate_overflow = true; | |
7911 } | |
7912 ) | |
7913 if (simulate_overflow || | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7914 !(_work_queue->push(obj) || _overflow_stack->par_push(obj))) { |
0 | 7915 // stack overflow |
7916 if (PrintCMSStatistics != 0) { | |
7917 gclog_or_tty->print_cr("CMS marking stack overflow (benign) at " | |
7918 SIZE_FORMAT, _overflow_stack->capacity()); | |
7919 } | |
7920 // We cannot assert that the overflow stack is full because | |
7921 // it may have been emptied since. | |
7922 assert(simulate_overflow || | |
7923 _work_queue->size() == _work_queue->max_elems(), | |
7924 "Else push should have succeeded"); | |
7925 handle_stack_overflow(addr); | |
7926 } | |
7927 do_yield_check(); | |
7928 } | |
7929 } | |
7930 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7931 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
|
7932 void Par_PushOrMarkClosure::do_oop(narrowOop* p) { Par_PushOrMarkClosure::do_oop_work(p); } |
0 | 7933 |
7934 PushAndMarkClosure::PushAndMarkClosure(CMSCollector* collector, | |
7935 MemRegion span, | |
7936 ReferenceProcessor* rp, | |
7937 CMSBitMap* bit_map, | |
7938 CMSBitMap* mod_union_table, | |
7939 CMSMarkStack* mark_stack, | |
7940 bool concurrent_precleaning): | |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
7941 MetadataAwareOopClosure(rp), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
7942 _collector(collector), |
0 | 7943 _span(span), |
7944 _bit_map(bit_map), | |
7945 _mod_union_table(mod_union_table), | |
7946 _mark_stack(mark_stack), | |
935 | 7947 _concurrent_precleaning(concurrent_precleaning) |
0 | 7948 { |
7949 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
7950 } | |
7951 | |
7952 // Grey object rescan during pre-cleaning and second checkpoint phases -- | |
7953 // 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
|
7954 void PushAndMarkClosure::do_oop(oop obj) { |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7955 // Ignore mark word verification. If during concurrent precleaning, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7956 // the object monitor may be locked. If during the checkpoint |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7957 // 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
|
7958 // 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
|
7959 // the mark word may be NULL). |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
143
diff
changeset
|
7960 assert(obj->is_oop_or_null(true /* ignore mark word */), |
0 | 7961 "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
|
7962 HeapWord* addr = (HeapWord*)obj; |
0 | 7963 // Check if oop points into the CMS generation |
7964 // and is not marked | |
7965 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
7966 // a white object ... | |
7967 _bit_map->mark(addr); // ... now grey | |
7968 // push on the marking stack (grey set) | |
7969 bool simulate_overflow = false; | |
7970 NOT_PRODUCT( | |
7971 if (CMSMarkStackOverflowALot && | |
7972 _collector->simulate_overflow()) { | |
7973 // simulate a stack overflow | |
7974 simulate_overflow = true; | |
7975 } | |
7976 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
7977 if (simulate_overflow || !_mark_stack->push(obj)) { |
0 | 7978 if (_concurrent_precleaning) { |
283
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7979 // During precleaning we can just dirty the appropriate card(s) |
0 | 7980 // 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
|
7981 // 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
|
7982 // 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
|
7983 // 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
|
7984 // dirty cards. |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7985 // 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
|
7986 // 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
|
7987 // are required. |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7988 if (obj->is_objArray()) { |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7989 size_t sz = obj->size(); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7990 HeapWord* end_card_addr = (HeapWord*)round_to( |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7991 (intptr_t)(addr+sz), CardTableModRefBS::card_size); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7992 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
|
7993 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7994 _mod_union_table->mark_range(redirty_range); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7995 } else { |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7996 _mod_union_table->mark(addr); |
9199f248b0ee
6722112: CMS: Incorrect encoding of overflown object arrays during concurrent precleaning
ysr
parents:
271
diff
changeset
|
7997 } |
0 | 7998 _collector->_ser_pmc_preclean_ovflw++; |
7999 } else { | |
8000 // During the remark phase, we need to remember this oop | |
8001 // in the overflow list. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8002 _collector->push_on_overflow_list(obj); |
0 | 8003 _collector->_ser_pmc_remark_ovflw++; |
8004 } | |
8005 } | |
8006 } | |
8007 } | |
8008 | |
8009 Par_PushAndMarkClosure::Par_PushAndMarkClosure(CMSCollector* collector, | |
8010 MemRegion span, | |
8011 ReferenceProcessor* rp, | |
8012 CMSBitMap* bit_map, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8013 OopTaskQueue* work_queue): |
20268
4c1b88a53c74
8046670: Make CMS metadata aware closures applicable for other collectors
stefank
parents:
20264
diff
changeset
|
8014 MetadataAwareOopClosure(rp), |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8015 _collector(collector), |
0 | 8016 _span(span), |
8017 _bit_map(bit_map), | |
935 | 8018 _work_queue(work_queue) |
0 | 8019 { |
8020 assert(_ref_processor != NULL, "_ref_processor shouldn't be NULL"); | |
8021 } | |
8022 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8023 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
|
8024 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
|
8025 |
0 | 8026 // Grey object rescan during second checkpoint phase -- |
8027 // the parallel version. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8028 void Par_PushAndMarkClosure::do_oop(oop obj) { |
0 | 8029 // In the assert below, we ignore the mark word because |
8030 // this oop may point to an already visited object that is | |
8031 // on the overflow stack (in which case the mark word has | |
8032 // been hijacked for chaining into the overflow stack -- | |
8033 // if this is the last object in the overflow stack then | |
8034 // its mark word will be NULL). Because this object may | |
8035 // have been subsequently popped off the global overflow | |
8036 // stack, and the mark word possibly restored to the prototypical | |
8037 // value, by the time we get to examined this failing assert in | |
8038 // the debugger, is_oop_or_null(false) may subsequently start | |
8039 // to hold. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8040 assert(obj->is_oop_or_null(true), |
0 | 8041 "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
|
8042 HeapWord* addr = (HeapWord*)obj; |
0 | 8043 // Check if oop points into the CMS generation |
8044 // and is not marked | |
8045 if (_span.contains(addr) && !_bit_map->isMarked(addr)) { | |
8046 // a white object ... | |
8047 // If we manage to "claim" the object, by being the | |
8048 // first thread to mark it, then we push it on our | |
8049 // marking stack | |
8050 if (_bit_map->par_mark(addr)) { // ... now grey | |
8051 // push on work queue (grey set) | |
8052 bool simulate_overflow = false; | |
8053 NOT_PRODUCT( | |
8054 if (CMSMarkStackOverflowALot && | |
8055 _collector->par_simulate_overflow()) { | |
8056 // simulate a stack overflow | |
8057 simulate_overflow = true; | |
8058 } | |
8059 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8060 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
|
8061 _collector->par_push_on_overflow_list(obj); |
0 | 8062 _collector->_par_pmc_remark_ovflw++; // imprecise OK: no need to CAS |
8063 } | |
8064 } // Else, some other thread got there first | |
8065 } | |
8066 } | |
8067 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8068 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
|
8069 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
|
8070 |
0 | 8071 void CMSPrecleanRefsYieldClosure::do_yield_work() { |
8072 Mutex* bml = _collector->bitMapLock(); | |
8073 assert_lock_strong(bml); | |
8074 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
8075 "CMS thread should hold CMS token"); | |
8076 | |
8077 bml->unlock(); | |
8078 ConcurrentMarkSweepThread::desynchronize(true); | |
8079 | |
8080 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8081 | |
8082 _collector->stopTimer(); | |
8083 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
8084 if (PrintCMSStatistics != 0) { | |
8085 _collector->incrementYields(); | |
8086 } | |
8087 _collector->icms_wait(); | |
8088 | |
8089 // See the comment in coordinator_yield() | |
8090 for (unsigned i = 0; i < CMSYieldSleepCount && | |
8091 ConcurrentMarkSweepThread::should_yield() && | |
8092 !CMSCollector::foregroundGCIsActive(); ++i) { | |
8093 os::sleep(Thread::current(), 1, false); | |
8094 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8095 } | |
8096 | |
8097 ConcurrentMarkSweepThread::synchronize(true); | |
8098 bml->lock(); | |
8099 | |
8100 _collector->startTimer(); | |
8101 } | |
8102 | |
8103 bool CMSPrecleanRefsYieldClosure::should_return() { | |
8104 if (ConcurrentMarkSweepThread::should_yield()) { | |
8105 do_yield_work(); | |
8106 } | |
8107 return _collector->foregroundGCIsActive(); | |
8108 } | |
8109 | |
8110 void MarkFromDirtyCardsClosure::do_MemRegion(MemRegion mr) { | |
8111 assert(((size_t)mr.start())%CardTableModRefBS::card_size_in_words == 0, | |
8112 "mr should be aligned to start at a card boundary"); | |
8113 // We'd like to assert: | |
8114 // assert(mr.word_size()%CardTableModRefBS::card_size_in_words == 0, | |
8115 // "mr should be a range of cards"); | |
8116 // However, that would be too strong in one case -- the last | |
8117 // partition ends at _unallocated_block which, in general, can be | |
8118 // an arbitrary boundary, not necessarily card aligned. | |
8119 if (PrintCMSStatistics != 0) { | |
8120 _num_dirty_cards += | |
8121 mr.word_size()/CardTableModRefBS::card_size_in_words; | |
8122 } | |
8123 _space->object_iterate_mem(mr, &_scan_cl); | |
8124 } | |
8125 | |
8126 SweepClosure::SweepClosure(CMSCollector* collector, | |
8127 ConcurrentMarkSweepGeneration* g, | |
8128 CMSBitMap* bitMap, bool should_yield) : | |
8129 _collector(collector), | |
8130 _g(g), | |
8131 _sp(g->cmsSpace()), | |
8132 _limit(_sp->sweep_limit()), | |
8133 _freelistLock(_sp->freelistLock()), | |
8134 _bitMap(bitMap), | |
8135 _yield(should_yield), | |
8136 _inFreeRange(false), // No free range at beginning of sweep | |
8137 _freeRangeInFreeLists(false), // No free range at beginning of sweep | |
8138 _lastFreeRangeCoalesced(false), | |
8139 _freeFinger(g->used_region().start()) | |
8140 { | |
8141 NOT_PRODUCT( | |
8142 _numObjectsFreed = 0; | |
8143 _numWordsFreed = 0; | |
8144 _numObjectsLive = 0; | |
8145 _numWordsLive = 0; | |
8146 _numObjectsAlreadyFree = 0; | |
8147 _numWordsAlreadyFree = 0; | |
8148 _last_fc = NULL; | |
8149 | |
8150 _sp->initializeIndexedFreeListArrayReturnedBytes(); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8151 _sp->dictionary()->initialize_dict_returned_bytes(); |
0 | 8152 ) |
8153 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), | |
8154 "sweep _limit out of bounds"); | |
8155 if (CMSTraceSweeper) { | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8156 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
|
8157 _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8158 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8159 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8160 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8161 void SweepClosure::print_on(outputStream* st) const { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8162 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
|
8163 _sp->bottom(), _sp->end()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8164 tty->print_cr("_limit = " PTR_FORMAT, _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8165 tty->print_cr("_freeFinger = " PTR_FORMAT, _freeFinger); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8166 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
|
8167 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
|
8168 _inFreeRange, _freeRangeInFreeLists, _lastFreeRangeCoalesced); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8169 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8170 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8171 #ifndef PRODUCT |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8172 // 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
|
8173 // 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
|
8174 // 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
|
8175 // enabled in product mode. |
0 | 8176 SweepClosure::~SweepClosure() { |
8177 assert_lock_strong(_freelistLock); | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8178 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8179 "sweep _limit out of bounds"); |
0 | 8180 if (inFreeRange()) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8181 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
|
8182 print(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8183 ShouldNotReachHere(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8184 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8185 if (Verbose && PrintGC) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8186 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
|
8187 _numObjectsFreed, _numWordsFreed*sizeof(HeapWord)); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8188 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
|
8189 SIZE_FORMAT" bytes " |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8190 "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
|
8191 _numObjectsLive, _numWordsLive*sizeof(HeapWord), |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8192 _numObjectsAlreadyFree, _numWordsAlreadyFree*sizeof(HeapWord)); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8193 size_t totalBytes = (_numWordsFreed + _numWordsLive + _numWordsAlreadyFree) |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8194 * sizeof(HeapWord); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8195 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
|
8196 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8197 if (PrintCMSStatistics && CMSVerifyReturnedBytes) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8198 size_t indexListReturnedBytes = _sp->sumIndexedFreeListArrayReturnedBytes(); |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8199 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
|
8200 size_t returned_bytes = indexListReturnedBytes + dict_returned_bytes; |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8201 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
|
8202 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
|
8203 indexListReturnedBytes); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8204 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
|
8205 dict_returned_bytes); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8206 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8207 } |
0 | 8208 if (CMSTraceSweeper) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8209 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
|
8210 _limit); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8211 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8212 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8213 #endif // PRODUCT |
0 | 8214 |
8215 void SweepClosure::initialize_free_range(HeapWord* freeFinger, | |
8216 bool freeRangeInFreeLists) { | |
8217 if (CMSTraceSweeper) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8218 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
|
8219 freeFinger, freeRangeInFreeLists); |
0 | 8220 } |
8221 assert(!inFreeRange(), "Trampling existing free range"); | |
8222 set_inFreeRange(true); | |
8223 set_lastFreeRangeCoalesced(false); | |
8224 | |
8225 set_freeFinger(freeFinger); | |
8226 set_freeRangeInFreeLists(freeRangeInFreeLists); | |
8227 if (CMSTestInFreeList) { | |
8228 if (freeRangeInFreeLists) { | |
8229 FreeChunk* fc = (FreeChunk*) freeFinger; | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8230 assert(fc->is_free(), "A chunk on the free list should be free."); |
0 | 8231 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
|
8232 assert(_sp->verify_chunk_in_free_list(fc), "Chunk is not in free lists"); |
0 | 8233 } |
8234 } | |
8235 } | |
8236 | |
8237 // Note that the sweeper runs concurrently with mutators. Thus, | |
8238 // it is possible for direct allocation in this generation to happen | |
8239 // in the middle of the sweep. Note that the sweeper also coalesces | |
8240 // contiguous free blocks. Thus, unless the sweeper and the allocator | |
8241 // synchronize appropriately freshly allocated blocks may get swept up. | |
8242 // This is accomplished by the sweeper locking the free lists while | |
8243 // it is sweeping. Thus blocks that are determined to be free are | |
8244 // indeed free. There is however one additional complication: | |
8245 // blocks that have been allocated since the final checkpoint and | |
8246 // mark, will not have been marked and so would be treated as | |
8247 // unreachable and swept up. To prevent this, the allocator marks | |
8248 // the bit map when allocating during the sweep phase. This leads, | |
8249 // however, to a further complication -- objects may have been allocated | |
8250 // but not yet initialized -- in the sense that the header isn't yet | |
8251 // installed. The sweeper can not then determine the size of the block | |
8252 // in order to skip over it. To deal with this case, we use a technique | |
8253 // (due to Printezis) to encode such uninitialized block sizes in the | |
8254 // bit map. Since the bit map uses a bit per every HeapWord, but the | |
8255 // CMS generation has a minimum object size of 3 HeapWords, it follows | |
8256 // that "normal marks" won't be adjacent in the bit map (there will | |
8257 // always be at least two 0 bits between successive 1 bits). We make use | |
8258 // of these "unused" bits to represent uninitialized blocks -- the bit | |
8259 // corresponding to the start of the uninitialized object and the next | |
8260 // bit are both set. Finally, a 1 bit marks the end of the object that | |
8261 // started with the two consecutive 1 bits to indicate its potentially | |
8262 // uninitialized state. | |
8263 | |
8264 size_t SweepClosure::do_blk_careful(HeapWord* addr) { | |
8265 FreeChunk* fc = (FreeChunk*)addr; | |
8266 size_t res; | |
8267 | |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8268 // 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
|
8269 // 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
|
8270 // 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
|
8271 // 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
|
8272 // 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
|
8273 // 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
|
8274 // 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
|
8275 if (addr >= _limit) { // we have swept up to or past the limit: finish up |
0 | 8276 assert(_limit >= _sp->bottom() && _limit <= _sp->end(), |
8277 "sweep _limit out of bounds"); | |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8278 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
|
8279 // 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
|
8280 // coalesced chunk to the appropriate free list. |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8281 if (inFreeRange()) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8282 assert(freeFinger() >= _sp->bottom() && freeFinger() < _limit, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8283 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
|
8284 flush_cur_free_chunk(freeFinger(), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8285 pointer_delta(addr, freeFinger())); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8286 if (CMSTraceSweeper) { |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8287 gclog_or_tty->print("Sweep: last chunk: "); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8288 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
|
8289 "[coalesced:"SIZE_FORMAT"]\n", |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8290 freeFinger(), pointer_delta(addr, freeFinger()), |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8291 lastFreeRangeCoalesced()); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8292 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8293 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8294 |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8295 // help the iterator loop finish |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8296 return pointer_delta(_sp->end(), addr); |
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8297 } |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8298 |
1720
5ed703250bff
6977970: CMS: concurrentMarkSweepGeneration.cpp:7947 assert(addr <= _limit) failed: sweep invariant
ysr
parents:
1716
diff
changeset
|
8299 assert(addr < _limit, "sweep invariant"); |
0 | 8300 // check if we should yield |
8301 do_yield_check(addr); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8302 if (fc->is_free()) { |
0 | 8303 // Chunk that is already free |
8304 res = fc->size(); | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8305 do_already_free_chunk(fc); |
0 | 8306 debug_only(_sp->verifyFreeLists()); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8307 // 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
|
8308 // 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
|
8309 // 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
|
8310 // 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
|
8311 // (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
|
8312 // 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
|
8313 // 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
|
8314 // will hold). |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8315 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
|
8316 "Otherwise the size info doesn't change at this step"); |
0 | 8317 NOT_PRODUCT( |
8318 _numObjectsAlreadyFree++; | |
8319 _numWordsAlreadyFree += res; | |
8320 ) | |
8321 NOT_PRODUCT(_last_fc = fc;) | |
8322 } else if (!_bitMap->isMarked(addr)) { | |
8323 // Chunk is fresh garbage | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8324 res = do_garbage_chunk(fc); |
0 | 8325 debug_only(_sp->verifyFreeLists()); |
8326 NOT_PRODUCT( | |
8327 _numObjectsFreed++; | |
8328 _numWordsFreed += res; | |
8329 ) | |
8330 } else { | |
8331 // Chunk that is alive. | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8332 res = do_live_chunk(fc); |
0 | 8333 debug_only(_sp->verifyFreeLists()); |
8334 NOT_PRODUCT( | |
8335 _numObjectsLive++; | |
8336 _numWordsLive += res; | |
8337 ) | |
8338 } | |
8339 return res; | |
8340 } | |
8341 | |
8342 // For the smart allocation, record following | |
8343 // split deaths - a free chunk is removed from its free list because | |
8344 // it is being split into two or more chunks. | |
8345 // split birth - a free chunk is being added to its free list because | |
8346 // a larger free chunk has been split and resulted in this free chunk. | |
8347 // coal death - a free chunk is being removed from its free list because | |
8348 // it is being coalesced into a large free chunk. | |
8349 // coal birth - a free chunk is being added to its free list because | |
8350 // it was created when two or more free chunks where coalesced into | |
8351 // this free chunk. | |
8352 // | |
8353 // These statistics are used to determine the desired number of free | |
8354 // chunks of a given size. The desired number is chosen to be relative | |
8355 // to the end of a CMS sweep. The desired number at the end of a sweep | |
8356 // is the | |
8357 // count-at-end-of-previous-sweep (an amount that was enough) | |
8358 // - count-at-beginning-of-current-sweep (the excess) | |
8359 // + split-births (gains in this size during interval) | |
8360 // - split-deaths (demands on this size during interval) | |
8361 // where the interval is from the end of one sweep to the end of the | |
8362 // next. | |
8363 // | |
8364 // When sweeping the sweeper maintains an accumulated chunk which is | |
8365 // the chunk that is made up of chunks that have been coalesced. That | |
8366 // will be termed the left-hand chunk. A new chunk of garbage that | |
8367 // is being considered for coalescing will be referred to as the | |
8368 // right-hand chunk. | |
8369 // | |
8370 // When making a decision on whether to coalesce a right-hand chunk with | |
8371 // the current left-hand chunk, the current count vs. the desired count | |
8372 // of the left-hand chunk is considered. Also if the right-hand chunk | |
8373 // is near the large chunk at the end of the heap (see | |
8374 // ConcurrentMarkSweepGeneration::isNearLargestChunk()), then the | |
8375 // left-hand chunk is coalesced. | |
8376 // | |
8377 // When making a decision about whether to split a chunk, the desired count | |
8378 // vs. the current count of the candidate to be split is also considered. | |
8379 // If the candidate is underpopulated (currently fewer chunks than desired) | |
8380 // a chunk of an overpopulated (currently more chunks than desired) size may | |
8381 // be chosen. The "hint" associated with a free list, if non-null, points | |
8382 // to a free list which may be overpopulated. | |
8383 // | |
8384 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8385 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
|
8386 const size_t size = fc->size(); |
0 | 8387 // Chunks that cannot be coalesced are not in the |
8388 // free lists. | |
8389 if (CMSTestInFreeList && !fc->cantCoalesce()) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8390 assert(_sp->verify_chunk_in_free_list(fc), |
0 | 8391 "free chunk should be in free lists"); |
8392 } | |
8393 // a chunk that is already free, should not have been | |
8394 // marked in the bit map | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8395 HeapWord* const addr = (HeapWord*) fc; |
0 | 8396 assert(!_bitMap->isMarked(addr), "free chunk should be unmarked"); |
8397 // Verify that the bit map has no bits marked between | |
8398 // addr and purported end of this block. | |
8399 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8400 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8401 // Some chunks cannot be coalesced under any circumstances. |
0 | 8402 // See the definition of cantCoalesce(). |
8403 if (!fc->cantCoalesce()) { | |
8404 // This chunk can potentially be coalesced. | |
8405 if (_sp->adaptive_freelists()) { | |
8406 // All the work is done in | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8407 do_post_free_or_garbage_chunk(fc, size); |
0 | 8408 } else { // Not adaptive free lists |
8409 // this is a free chunk that can potentially be coalesced by the sweeper; | |
8410 if (!inFreeRange()) { | |
8411 // if the next chunk is a free block that can't be coalesced | |
8412 // it doesn't make sense to remove this chunk from the free lists | |
8413 FreeChunk* nextChunk = (FreeChunk*)(addr + size); | |
2136
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8414 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
|
8415 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
|
8416 nextChunk->is_free() && // ... which is free... |
2136
c91cc404ca46
7011940: iCMS: SIGSEGV in SweepClosure::do_already_free_chunk(FreeChunk*)+0x360
ysr
parents:
2132
diff
changeset
|
8417 nextChunk->cantCoalesce()) { // ... but can't be coalesced |
0 | 8418 // nothing to do |
8419 } else { | |
8420 // Potentially the start of a new free range: | |
8421 // Don't eagerly remove it from the free lists. | |
8422 // No need to remove it if it will just be put | |
8423 // back again. (Also from a pragmatic point of view | |
8424 // if it is a free block in a region that is beyond | |
8425 // any allocated blocks, an assertion will fail) | |
8426 // Remember the start of a free run. | |
8427 initialize_free_range(addr, true); | |
8428 // end - can coalesce with next chunk | |
8429 } | |
8430 } else { | |
8431 // 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
|
8432 print_free_block_coalesced(fc); |
0 | 8433 if (CMSTraceSweeper) { |
8434 gclog_or_tty->print(" -- pick up free block 0x%x (%d)\n", fc, size); | |
8435 } | |
8436 // remove it from the free lists | |
8437 _sp->removeFreeChunkFromFreeLists(fc); | |
8438 set_lastFreeRangeCoalesced(true); | |
8439 // If the chunk is being coalesced and the current free range is | |
8440 // in the free lists, remove the current free range so that it | |
8441 // will be returned to the free lists in its entirety - all | |
8442 // the coalesced pieces included. | |
8443 if (freeRangeInFreeLists()) { | |
8444 FreeChunk* ffc = (FreeChunk*) freeFinger(); | |
8445 assert(ffc->size() == pointer_delta(addr, freeFinger()), | |
8446 "Size of free range is inconsistent with chunk size."); | |
8447 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8448 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8449 "free range is not in free lists"); |
8450 } | |
8451 _sp->removeFreeChunkFromFreeLists(ffc); | |
8452 set_freeRangeInFreeLists(false); | |
8453 } | |
8454 } | |
8455 } | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8456 // 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
|
8457 // 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
|
8458 // a "lookahead," as we do below. |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8459 if (inFreeRange()) lookahead_and_flush(fc, size); |
0 | 8460 } else { |
8461 // Code path common to both original and adaptive free lists. | |
8462 | |
8463 // cant coalesce with previous block; this should be treated | |
8464 // as the end of a free run if any | |
8465 if (inFreeRange()) { | |
8466 // 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
|
8467 assert(freeFinger() < addr, "freeFinger points too high"); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8468 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
0 | 8469 } |
8470 // else, nothing to do, just continue | |
8471 } | |
8472 } | |
8473 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8474 size_t SweepClosure::do_garbage_chunk(FreeChunk* fc) { |
0 | 8475 // This is a chunk of garbage. It is not in any free list. |
8476 // Add it to a free list or let it possibly be coalesced into | |
8477 // a larger chunk. | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8478 HeapWord* const addr = (HeapWord*) fc; |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8479 const size_t size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); |
0 | 8480 |
8481 if (_sp->adaptive_freelists()) { | |
8482 // Verify that the bit map has no bits marked between | |
8483 // addr and purported end of just dead object. | |
8484 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8485 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8486 do_post_free_or_garbage_chunk(fc, size); |
0 | 8487 } else { |
8488 if (!inFreeRange()) { | |
8489 // start of a new free range | |
8490 assert(size > 0, "A free range should have a size"); | |
8491 initialize_free_range(addr, false); | |
8492 } else { | |
8493 // this will be swept up when we hit the end of the | |
8494 // free range | |
8495 if (CMSTraceSweeper) { | |
8496 gclog_or_tty->print(" -- pick up garbage 0x%x (%d) \n", fc, size); | |
8497 } | |
8498 // If the chunk is being coalesced and the current free range is | |
8499 // in the free lists, remove the current free range so that it | |
8500 // will be returned to the free lists in its entirety - all | |
8501 // the coalesced pieces included. | |
8502 if (freeRangeInFreeLists()) { | |
8503 FreeChunk* ffc = (FreeChunk*)freeFinger(); | |
8504 assert(ffc->size() == pointer_delta(addr, freeFinger()), | |
8505 "Size of free range is inconsistent with chunk size."); | |
8506 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8507 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8508 "free range is not in free lists"); |
8509 } | |
8510 _sp->removeFreeChunkFromFreeLists(ffc); | |
8511 set_freeRangeInFreeLists(false); | |
8512 } | |
8513 set_lastFreeRangeCoalesced(true); | |
8514 } | |
8515 // this will be swept up when we hit the end of the free range | |
8516 | |
8517 // Verify that the bit map has no bits marked between | |
8518 // addr and purported end of just dead object. | |
8519 _bitMap->verifyNoOneBitsInRange(addr + 1, addr + size); | |
8520 } | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8521 assert(_limit >= addr + size, |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8522 "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
|
8523 if (inFreeRange()) lookahead_and_flush(fc, size); |
0 | 8524 return size; |
8525 } | |
8526 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8527 size_t SweepClosure::do_live_chunk(FreeChunk* fc) { |
0 | 8528 HeapWord* addr = (HeapWord*) fc; |
8529 // The sweeper has just found a live object. Return any accumulated | |
8530 // left hand chunk to the free lists. | |
8531 if (inFreeRange()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8532 assert(freeFinger() < addr, "freeFinger points too high"); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8533 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8534 } |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8535 |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8536 // This object is live: we'd normally expect this to be |
0 | 8537 // an oop, and like to assert the following: |
8538 // assert(oop(addr)->is_oop(), "live block should be an oop"); | |
8539 // However, as we commented above, this may be an object whose | |
8540 // header hasn't yet been initialized. | |
8541 size_t size; | |
8542 assert(_bitMap->isMarked(addr), "Tautology for this control point"); | |
8543 if (_bitMap->isMarked(addr + 1)) { | |
8544 // Determine the size from the bit map, rather than trying to | |
8545 // compute it from the object header. | |
8546 HeapWord* nextOneAddr = _bitMap->getNextMarkedWordAddress(addr + 2); | |
8547 size = pointer_delta(nextOneAddr + 1, addr); | |
8548 assert(size == CompactibleFreeListSpace::adjustObjectSize(size), | |
8549 "alignment problem"); | |
8550 | |
9152 | 8551 #ifdef ASSERT |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8552 if (oop(addr)->klass_or_null() != NULL) { |
0 | 8553 // Ignore mark word because we are running concurrent with mutators |
8554 assert(oop(addr)->is_oop(true), "live block should be an oop"); | |
8555 assert(size == | |
8556 CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()), | |
8557 "P-mark and computed size do not agree"); | |
8558 } | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8559 #endif |
0 | 8560 |
8561 } else { | |
8562 // 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
|
8563 assert(oop(addr)->klass_or_null() != NULL, |
0 | 8564 "Should be an initialized object"); |
8565 // Ignore mark word because we are running concurrent with mutators | |
8566 assert(oop(addr)->is_oop(true), "live block should be an oop"); | |
8567 // Verify that the bit map has no bits marked between | |
8568 // addr and purported end of this block. | |
8569 size = CompactibleFreeListSpace::adjustObjectSize(oop(addr)->size()); | |
8570 assert(size >= 3, "Necessary for Printezis marks to work"); | |
8571 assert(!_bitMap->isMarked(addr+1), "Tautology for this control point"); | |
8572 DEBUG_ONLY(_bitMap->verifyNoOneBitsInRange(addr+2, addr+size);) | |
8573 } | |
8574 return size; | |
8575 } | |
8576 | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8577 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
|
8578 size_t chunkSize) { |
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8579 // 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
|
8580 // of the adaptive free list allocator. |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8581 const bool fcInFreeLists = fc->is_free(); |
0 | 8582 assert(_sp->adaptive_freelists(), "Should only be used in this case."); |
8583 assert((HeapWord*)fc <= _limit, "sweep invariant"); | |
8584 if (CMSTestInFreeList && fcInFreeLists) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8585 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
|
8586 } |
0 | 8587 |
8588 if (CMSTraceSweeper) { | |
8589 gclog_or_tty->print_cr(" -- pick up another chunk at 0x%x (%d)", fc, chunkSize); | |
8590 } | |
8591 | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8592 HeapWord* const fc_addr = (HeapWord*) fc; |
0 | 8593 |
8594 bool coalesce; | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8595 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
|
8596 const size_t right = chunkSize; |
0 | 8597 switch (FLSCoalescePolicy) { |
8598 // numeric value forms a coalition aggressiveness metric | |
8599 case 0: { // never coalesce | |
8600 coalesce = false; | |
8601 break; | |
8602 } | |
8603 case 1: { // coalesce if left & right chunks on overpopulated lists | |
8604 coalesce = _sp->coalOverPopulated(left) && | |
8605 _sp->coalOverPopulated(right); | |
8606 break; | |
8607 } | |
8608 case 2: { // coalesce if left chunk on overpopulated list (default) | |
8609 coalesce = _sp->coalOverPopulated(left); | |
8610 break; | |
8611 } | |
8612 case 3: { // coalesce if left OR right chunk on overpopulated list | |
8613 coalesce = _sp->coalOverPopulated(left) || | |
8614 _sp->coalOverPopulated(right); | |
8615 break; | |
8616 } | |
8617 case 4: { // always coalesce | |
8618 coalesce = true; | |
8619 break; | |
8620 } | |
8621 default: | |
8622 ShouldNotReachHere(); | |
8623 } | |
8624 | |
8625 // Should the current free range be coalesced? | |
8626 // If the chunk is in a free range and either we decided to coalesce above | |
8627 // or the chunk is near the large block at the end of the heap | |
8628 // (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
|
8629 const bool doCoalesce = inFreeRange() |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8630 && (coalesce || _g->isNearLargestChunk(fc_addr)); |
0 | 8631 if (doCoalesce) { |
8632 // Coalesce the current free range on the left with the new | |
8633 // chunk on the right. If either is on a free list, | |
8634 // it must be removed from the list and stashed in the closure. | |
8635 if (freeRangeInFreeLists()) { | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8636 FreeChunk* const ffc = (FreeChunk*)freeFinger(); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8637 assert(ffc->size() == pointer_delta(fc_addr, freeFinger()), |
0 | 8638 "Size of free range is inconsistent with chunk size."); |
8639 if (CMSTestInFreeList) { | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8640 assert(_sp->verify_chunk_in_free_list(ffc), |
0 | 8641 "Chunk is not in free lists"); |
8642 } | |
8643 _sp->coalDeath(ffc->size()); | |
8644 _sp->removeFreeChunkFromFreeLists(ffc); | |
8645 set_freeRangeInFreeLists(false); | |
8646 } | |
8647 if (fcInFreeLists) { | |
8648 _sp->coalDeath(chunkSize); | |
8649 assert(fc->size() == chunkSize, | |
8650 "The chunk has the wrong size or is not in the free lists"); | |
8651 _sp->removeFreeChunkFromFreeLists(fc); | |
8652 } | |
8653 set_lastFreeRangeCoalesced(true); | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8654 print_free_block_coalesced(fc); |
0 | 8655 } else { // not in a free range and/or should not coalesce |
8656 // Return the current free range and start a new one. | |
8657 if (inFreeRange()) { | |
8658 // In a free range but cannot coalesce with the right hand chunk. | |
8659 // 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
|
8660 flush_cur_free_chunk(freeFinger(), |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8661 pointer_delta(fc_addr, freeFinger())); |
0 | 8662 } |
8663 // Set up for new free range. Pass along whether the right hand | |
8664 // chunk is in the free lists. | |
8665 initialize_free_range((HeapWord*)fc, fcInFreeLists); | |
8666 } | |
8667 } | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8668 |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8669 // Lookahead flush: |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8670 // 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
|
8671 // 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
|
8672 // 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
|
8673 // 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
|
8674 // 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
|
8675 // 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
|
8676 // 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
|
8677 // 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
|
8678 // 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
|
8679 // 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
|
8680 // 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
|
8681 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
|
8682 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
|
8683 HeapWord* const eob = ((HeapWord*)fc) + chunk_size; |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8684 assert(_sp->used_region().contains(eob - 1), |
12112
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
8685 err_msg("eob = " PTR_FORMAT " eob-1 = " PTR_FORMAT " _limit = " PTR_FORMAT |
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
8686 " out of bounds wrt _sp = [" PTR_FORMAT "," PTR_FORMAT ")" |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8687 " when examining fc = " PTR_FORMAT "(" SIZE_FORMAT ")", |
12112
1bb10d3170fa
8022817: CMS should not shrink if compaction was not done
jmasa
parents:
12088
diff
changeset
|
8688 eob, eob-1, _limit, _sp->bottom(), _sp->end(), fc, chunk_size)); |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8689 if (eob >= _limit) { |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8690 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
|
8691 if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8692 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
|
8693 "[" PTR_FORMAT "," PTR_FORMAT ") in space " |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8694 "[" PTR_FORMAT "," PTR_FORMAT ")", |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8695 _limit, fc, eob, _sp->bottom(), _sp->end()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8696 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8697 // 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
|
8698 if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8699 gclog_or_tty->print_cr("Flushing ... "); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8700 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8701 assert(freeFinger() < eob, "Error"); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8702 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
|
8703 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8704 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8705 |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8706 void SweepClosure::flush_cur_free_chunk(HeapWord* chunk, size_t size) { |
0 | 8707 assert(inFreeRange(), "Should only be called if currently in a free range."); |
8708 assert(size > 0, | |
8709 "A zero sized chunk cannot be added to the free lists."); | |
8710 if (!freeRangeInFreeLists()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8711 if (CMSTestInFreeList) { |
0 | 8712 FreeChunk* fc = (FreeChunk*) chunk; |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8713 fc->set_size(size); |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8714 assert(!_sp->verify_chunk_in_free_list(fc), |
0 | 8715 "chunk should not be in free lists yet"); |
8716 } | |
8717 if (CMSTraceSweeper) { | |
8718 gclog_or_tty->print_cr(" -- add free block 0x%x (%d) to free lists", | |
8719 chunk, size); | |
8720 } | |
8721 // A new free range is going to be starting. The current | |
8722 // free range has not been added to the free lists yet or | |
8723 // was removed so add it back. | |
8724 // If the current free range was coalesced, then the death | |
8725 // of the free range was recorded. Record a birth now. | |
8726 if (lastFreeRangeCoalesced()) { | |
8727 _sp->coalBirth(size); | |
8728 } | |
8729 _sp->addChunkAndRepairOffsetTable(chunk, size, | |
8730 lastFreeRangeCoalesced()); | |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8731 } else if (CMSTraceSweeper) { |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8732 gclog_or_tty->print_cr("Already in free list: nothing to flush"); |
0 | 8733 } |
8734 set_inFreeRange(false); | |
8735 set_freeRangeInFreeLists(false); | |
8736 } | |
8737 | |
8738 // We take a break if we've been at this for a while, | |
8739 // so as to avoid monopolizing the locks involved. | |
8740 void SweepClosure::do_yield_work(HeapWord* addr) { | |
8741 // Return current free chunk being used for coalescing (if any) | |
8742 // to the appropriate freelist. After yielding, the next | |
8743 // free block encountered will start a coalescing range of | |
8744 // free blocks. If the next free block is adjacent to the | |
8745 // chunk just flushed, they will need to wait for the next | |
8746 // sweep to be coalesced. | |
8747 if (inFreeRange()) { | |
2132
4947ee68d19c
7008136: CMS: assert((HeapWord*)nextChunk <= _limit) failed: sweep invariant
ysr
parents:
1994
diff
changeset
|
8748 flush_cur_free_chunk(freeFinger(), pointer_delta(addr, freeFinger())); |
0 | 8749 } |
8750 | |
8751 // First give up the locks, then yield, then re-lock. | |
8752 // We should probably use a constructor/destructor idiom to | |
8753 // do this unlock/lock or modify the MutexUnlocker class to | |
8754 // serve our purpose. XXX | |
8755 assert_lock_strong(_bitMap->lock()); | |
8756 assert_lock_strong(_freelistLock); | |
8757 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), | |
8758 "CMS thread should hold CMS token"); | |
8759 _bitMap->lock()->unlock(); | |
8760 _freelistLock->unlock(); | |
8761 ConcurrentMarkSweepThread::desynchronize(true); | |
8762 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8763 _collector->stopTimer(); | |
8764 GCPauseTimer p(_collector->size_policy()->concurrent_timer_ptr()); | |
8765 if (PrintCMSStatistics != 0) { | |
8766 _collector->incrementYields(); | |
8767 } | |
8768 _collector->icms_wait(); | |
8769 | |
8770 // See the comment in coordinator_yield() | |
8771 for (unsigned i = 0; i < CMSYieldSleepCount && | |
8772 ConcurrentMarkSweepThread::should_yield() && | |
8773 !CMSCollector::foregroundGCIsActive(); ++i) { | |
8774 os::sleep(Thread::current(), 1, false); | |
8775 ConcurrentMarkSweepThread::acknowledge_yield_request(); | |
8776 } | |
8777 | |
8778 ConcurrentMarkSweepThread::synchronize(true); | |
8779 _freelistLock->lock(); | |
8780 _bitMap->lock()->lock_without_safepoint_check(); | |
8781 _collector->startTimer(); | |
8782 } | |
8783 | |
8784 #ifndef PRODUCT | |
8785 // This is actually very useful in a product build if it can | |
8786 // be called from the debugger. Compile it into the product | |
8787 // as needed. | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8788 bool debug_verify_chunk_in_free_list(FreeChunk* fc) { |
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
8789 return debug_cms_space->verify_chunk_in_free_list(fc); |
0 | 8790 } |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8791 #endif |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8792 |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8793 void SweepClosure::print_free_block_coalesced(FreeChunk* fc) const { |
0 | 8794 if (CMSTraceSweeper) { |
3746
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8795 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
|
8796 fc, fc->size()); |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8797 } |
537a4053b0f9
7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents:
3356
diff
changeset
|
8798 } |
0 | 8799 |
8800 // CMSIsAliveClosure | |
8801 bool CMSIsAliveClosure::do_object_b(oop obj) { | |
8802 HeapWord* addr = (HeapWord*)obj; | |
8803 return addr != NULL && | |
8804 (!_span.contains(addr) || _bit_map->isMarked(addr)); | |
8805 } | |
8806 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8807 |
935 | 8808 CMSKeepAliveClosure::CMSKeepAliveClosure( CMSCollector* collector, |
8809 MemRegion span, | |
8810 CMSBitMap* bit_map, CMSMarkStack* mark_stack, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8811 bool cpc): |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8812 _collector(collector), |
935 | 8813 _span(span), |
8814 _bit_map(bit_map), | |
8815 _mark_stack(mark_stack), | |
8816 _concurrent_precleaning(cpc) { | |
8817 assert(!_span.is_empty(), "Empty span could spell trouble"); | |
8818 } | |
8819 | |
8820 | |
0 | 8821 // CMSKeepAliveClosure: the serial version |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8822 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
|
8823 HeapWord* addr = (HeapWord*)obj; |
0 | 8824 if (_span.contains(addr) && |
8825 !_bit_map->isMarked(addr)) { | |
8826 _bit_map->mark(addr); | |
8827 bool simulate_overflow = false; | |
8828 NOT_PRODUCT( | |
8829 if (CMSMarkStackOverflowALot && | |
8830 _collector->simulate_overflow()) { | |
8831 // simulate a stack overflow | |
8832 simulate_overflow = true; | |
8833 } | |
8834 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8835 if (simulate_overflow || !_mark_stack->push(obj)) { |
452
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8836 if (_concurrent_precleaning) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8837 // 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
|
8838 // phase deal with it. |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8839 assert(_collector->overflow_list_is_empty(), "Error"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8840 // 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
|
8841 // 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
|
8842 // 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
|
8843 // table. |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8844 if (obj->is_objArray()) { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8845 size_t sz = obj->size(); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8846 HeapWord* end_card_addr = |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8847 (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
|
8848 MemRegion redirty_range = MemRegion(addr, end_card_addr); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8849 assert(!redirty_range.is_empty(), "Arithmetical tautology"); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8850 _collector->_modUnionTable.mark_range(redirty_range); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8851 } else { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8852 _collector->_modUnionTable.mark(addr); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8853 } |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8854 _collector->_ser_kac_preclean_ovflw++; |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8855 } else { |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8856 _collector->push_on_overflow_list(obj); |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8857 _collector->_ser_kac_ovflw++; |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8858 } |
0 | 8859 } |
8860 } | |
8861 } | |
8862 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8863 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
|
8864 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
|
8865 |
0 | 8866 // CMSParKeepAliveClosure: a parallel version of the above. |
8867 // The work queues are private to each closure (thread), | |
8868 // 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
|
8869 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
|
8870 HeapWord* addr = (HeapWord*)obj; |
0 | 8871 if (_span.contains(addr) && |
8872 !_bit_map->isMarked(addr)) { | |
8873 // In general, during recursive tracing, several threads | |
8874 // may be concurrently getting here; the first one to | |
8875 // "tag" it, claims it. | |
8876 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
|
8877 bool res = _work_queue->push(obj); |
0 | 8878 assert(res, "Low water mark should be much less than capacity"); |
8879 // Do a recursive trim in the hope that this will keep | |
8880 // stack usage lower, but leave some oops for potential stealers | |
8881 trim_queue(_low_water_mark); | |
8882 } // Else, another thread got there first | |
8883 } | |
8884 } | |
8885 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8886 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
|
8887 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
|
8888 |
0 | 8889 void CMSParKeepAliveClosure::trim_queue(uint max) { |
8890 while (_work_queue->size() > max) { | |
8891 oop new_oop; | |
8892 if (_work_queue->pop_local(new_oop)) { | |
8893 assert(new_oop != NULL && new_oop->is_oop(), "Expected an oop"); | |
8894 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
8895 "no white objects on this stack!"); | |
8896 assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop"); | |
8897 // iterate over the oops in this oop, marking and pushing | |
8898 // the ones in CMS heap (i.e. in _span). | |
8899 new_oop->oop_iterate(&_mark_and_push); | |
8900 } | |
8901 } | |
8902 } | |
8903 | |
935 | 8904 CMSInnerParMarkAndPushClosure::CMSInnerParMarkAndPushClosure( |
8905 CMSCollector* collector, | |
8906 MemRegion span, CMSBitMap* bit_map, | |
8907 OopTaskQueue* work_queue): | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
8908 _collector(collector), |
935 | 8909 _span(span), |
8910 _bit_map(bit_map), | |
8911 _work_queue(work_queue) { } | |
8912 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8913 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
|
8914 HeapWord* addr = (HeapWord*)obj; |
0 | 8915 if (_span.contains(addr) && |
8916 !_bit_map->isMarked(addr)) { | |
8917 if (_bit_map->par_mark(addr)) { | |
8918 bool simulate_overflow = false; | |
8919 NOT_PRODUCT( | |
8920 if (CMSMarkStackOverflowALot && | |
8921 _collector->par_simulate_overflow()) { | |
8922 // simulate a stack overflow | |
8923 simulate_overflow = true; | |
8924 } | |
8925 ) | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8926 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
|
8927 _collector->par_push_on_overflow_list(obj); |
0 | 8928 _collector->_par_kac_ovflw++; |
8929 } | |
8930 } // Else another thread got there already | |
8931 } | |
8932 } | |
8933 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8934 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
|
8935 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
|
8936 |
0 | 8937 ////////////////////////////////////////////////////////////////// |
8938 // CMSExpansionCause ///////////////////////////// | |
8939 ////////////////////////////////////////////////////////////////// | |
8940 const char* CMSExpansionCause::to_string(CMSExpansionCause::Cause cause) { | |
8941 switch (cause) { | |
8942 case _no_expansion: | |
8943 return "No expansion"; | |
8944 case _satisfy_free_ratio: | |
8945 return "Free ratio"; | |
8946 case _satisfy_promotion: | |
8947 return "Satisfy promotion"; | |
8948 case _satisfy_allocation: | |
8949 return "allocation"; | |
8950 case _allocate_par_lab: | |
8951 return "Par LAB"; | |
8952 case _allocate_par_spooling_space: | |
8953 return "Par Spooling Space"; | |
8954 case _adaptive_size_policy: | |
8955 return "Ergonomics"; | |
8956 default: | |
8957 return "unknown"; | |
8958 } | |
8959 } | |
8960 | |
8961 void CMSDrainMarkingStackClosure::do_void() { | |
8962 // the max number to take from overflow list at a time | |
8963 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
|
8964 assert(!_concurrent_precleaning || _collector->overflow_list_is_empty(), |
00b023ae2d78
6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents:
360
diff
changeset
|
8965 "Overflow list should be NULL during concurrent phases"); |
0 | 8966 while (!_mark_stack->isEmpty() || |
8967 // if stack is empty, check the overflow list | |
8968 _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
|
8969 oop obj = _mark_stack->pop(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
94
diff
changeset
|
8970 HeapWord* addr = (HeapWord*)obj; |
0 | 8971 assert(_span.contains(addr), "Should be within span"); |
8972 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
|
8973 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
|
8974 obj->oop_iterate(_keep_alive); |
0 | 8975 } |
8976 } | |
8977 | |
8978 void CMSParDrainMarkingStackClosure::do_void() { | |
8979 // drain queue | |
8980 trim_queue(0); | |
8981 } | |
8982 | |
8983 // Trim our work_queue so its length is below max at return | |
8984 void CMSParDrainMarkingStackClosure::trim_queue(uint max) { | |
8985 while (_work_queue->size() > max) { | |
8986 oop new_oop; | |
8987 if (_work_queue->pop_local(new_oop)) { | |
8988 assert(new_oop->is_oop(), "Expected an oop"); | |
8989 assert(_bit_map->isMarked((HeapWord*)new_oop), | |
8990 "no white objects on this stack!"); | |
8991 assert(_span.contains((HeapWord*)new_oop), "Out of bounds oop"); | |
8992 // iterate over the oops in this oop, marking and pushing | |
8993 // the ones in CMS heap (i.e. in _span). | |
8994 new_oop->oop_iterate(&_mark_and_push); | |
8995 } | |
8996 } | |
8997 } | |
8998 | |
8999 //////////////////////////////////////////////////////////////////// | |
9000 // Support for Marking Stack Overflow list handling and related code | |
9001 //////////////////////////////////////////////////////////////////// | |
9002 // Much of the following code is similar in shape and spirit to the | |
9003 // code used in ParNewGC. We should try and share that code | |
9004 // as much as possible in the future. | |
9005 | |
9006 #ifndef PRODUCT | |
9007 // Debugging support for CMSStackOverflowALot | |
9008 | |
9009 // It's OK to call this multi-threaded; the worst thing | |
9010 // that can happen is that we'll get a bunch of closely | |
9011 // spaced simulated oveflows, but that's OK, in fact | |
9012 // probably good as it would exercise the overflow code | |
9013 // under contention. | |
9014 bool CMSCollector::simulate_overflow() { | |
9015 if (_overflow_counter-- <= 0) { // just being defensive | |
9016 _overflow_counter = CMSMarkStackOverflowInterval; | |
9017 return true; | |
9018 } else { | |
9019 return false; | |
9020 } | |
9021 } | |
9022 | |
9023 bool CMSCollector::par_simulate_overflow() { | |
9024 return simulate_overflow(); | |
9025 } | |
9026 #endif | |
9027 | |
9028 // Single-threaded | |
9029 bool CMSCollector::take_from_overflow_list(size_t num, CMSMarkStack* stack) { | |
9030 assert(stack->isEmpty(), "Expected precondition"); | |
9031 assert(stack->capacity() > num, "Shouldn't bite more than can chew"); | |
9032 size_t i = num; | |
9033 oop cur = _overflow_list; | |
9034 const markOop proto = markOopDesc::prototype(); | |
534 | 9035 NOT_PRODUCT(ssize_t n = 0;) |
0 | 9036 for (oop next; i > 0 && cur != NULL; cur = next, i--) { |
9037 next = oop(cur->mark()); | |
9038 cur->set_mark(proto); // until proven otherwise | |
9039 assert(cur->is_oop(), "Should be an oop"); | |
9040 bool res = stack->push(cur); | |
9041 assert(res, "Bit off more than can chew?"); | |
9042 NOT_PRODUCT(n++;) | |
9043 } | |
9044 _overflow_list = cur; | |
9045 #ifndef PRODUCT | |
9046 assert(_num_par_pushes >= n, "Too many pops?"); | |
9047 _num_par_pushes -=n; | |
9048 #endif | |
9049 return !stack->isEmpty(); | |
9050 } | |
9051 | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9052 #define BUSY (cast_to_oop<intptr_t>(0x1aff1aff)) |
534 | 9053 // (MT-safe) Get a prefix of at most "num" from the list. |
9054 // The overflow list is chained through the mark word of | |
9055 // each object in the list. We fetch the entire list, | |
9056 // break off a prefix of the right size and return the | |
9057 // remainder. If other threads try to take objects from | |
9058 // the overflow list at that time, they will wait for | |
9059 // some time to see if data becomes available. If (and | |
9060 // only if) another thread places one or more object(s) | |
9061 // on the global list before we have returned the suffix | |
9062 // to the global list, we will walk down our local list | |
9063 // to find its end and append the global list to | |
9064 // our suffix before returning it. This suffix walk can | |
9065 // prove to be expensive (quadratic in the amount of traffic) | |
9066 // when there are many objects in the overflow list and | |
9067 // there is much producer-consumer contention on the list. | |
9068 // *NOTE*: The overflow list manipulation code here and | |
9069 // in ParNewGeneration:: are very similar in shape, | |
9070 // except that in the ParNew case we use the old (from/eden) | |
9071 // copy of the object to thread the list via its klass word. | |
9072 // Because of the common code, if you make any changes in | |
9073 // the code below, please check the ParNew version to see if | |
9074 // similar changes might be needed. | |
9075 // CR 6797058 has been filed to consolidate the common code. | |
0 | 9076 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
|
9077 OopTaskQueue* work_q, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9078 int no_of_gc_threads) { |
534 | 9079 assert(work_q->size() == 0, "First empty local work queue"); |
0 | 9080 assert(num < work_q->max_elems(), "Can't bite more than we can chew"); |
9081 if (_overflow_list == NULL) { | |
9082 return false; | |
9083 } | |
9084 // Grab the entire list; we'll put back a suffix | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9085 oop prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list)); |
534 | 9086 Thread* tid = Thread::current(); |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9087 // Before "no_of_gc_threads" was introduced CMSOverflowSpinCount was |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9088 // set to ParallelGCThreads. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1777
diff
changeset
|
9089 size_t CMSOverflowSpinCount = (size_t) no_of_gc_threads; // was ParallelGCThreads; |
534 | 9090 size_t sleep_time_millis = MAX2((size_t)1, num/100); |
9091 // If the list is busy, we spin for a short while, | |
9092 // sleeping between attempts to get the list. | |
9093 for (size_t spin = 0; prefix == BUSY && spin < CMSOverflowSpinCount; spin++) { | |
9094 os::sleep(tid, sleep_time_millis, false); | |
9095 if (_overflow_list == NULL) { | |
9096 // Nothing left to take | |
9097 return false; | |
9098 } else if (_overflow_list != BUSY) { | |
9099 // Try and grab the prefix | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12226
diff
changeset
|
9100 prefix = cast_to_oop(Atomic::xchg_ptr(BUSY, &_overflow_list)); |
534 | 9101 } |
9102 } | |
9103 // If the list was found to be empty, or we spun long | |
9104 // enough, we give up and return empty-handed. If we leave | |
9105 // the list in the BUSY state below, it must be the case that | |
9106 // some other thread holds the overflow list and will set it | |
9107 // to a non-BUSY state in the future. | |
9108 if (prefix == NULL || prefix == BUSY) { | |
9109 // Nothing to take or waited long enough | |
9110 if (prefix == NULL) { | |
9111 // Write back the NULL in case we overwrote it with BUSY above | |
9112 // and it is still the same value. | |
9113 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
9114 } | |
9115 return false; | |
9116 } | |
9117 assert(prefix != NULL && prefix != BUSY, "Error"); | |
0 | 9118 size_t i = num; |
9119 oop cur = prefix; | |
534 | 9120 // Walk down the first "num" objects, unless we reach the end. |
0 | 9121 for (; i > 1 && cur->mark() != NULL; cur = oop(cur->mark()), i--); |
534 | 9122 if (cur->mark() == NULL) { |
9123 // We have "num" or fewer elements in the list, so there | |
9124 // is nothing to return to the global list. | |
9125 // Write back the NULL in lieu of the BUSY we wrote | |
9126 // above, if it is still the same value. | |
9127 if (_overflow_list == BUSY) { | |
9128 (void) Atomic::cmpxchg_ptr(NULL, &_overflow_list, BUSY); | |
9129 } | |
9130 } else { | |
9131 // Chop off the suffix and rerturn it to the global list. | |
9132 assert(cur->mark() != BUSY, "Error"); | |
0 | 9133 oop suffix_head = cur->mark(); // suffix will be put back on global list |
9134 cur->set_mark(NULL); // break off suffix | |
534 | 9135 // It's possible that the list is still in the empty(busy) state |
9136 // we left it in a short while ago; in that case we may be | |
9137 // able to place back the suffix without incurring the cost | |
9138 // of a walk down the list. | |
0 | 9139 oop observed_overflow_list = _overflow_list; |
534 | 9140 oop cur_overflow_list = observed_overflow_list; |
9141 bool attached = false; | |
9142 while (observed_overflow_list == BUSY || observed_overflow_list == NULL) { | |
0 | 9143 observed_overflow_list = |
534 | 9144 (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list); |
9145 if (cur_overflow_list == observed_overflow_list) { | |
9146 attached = true; | |
9147 break; | |
9148 } else cur_overflow_list = observed_overflow_list; | |
9149 } | |
9150 if (!attached) { | |
9151 // Too bad, someone else sneaked in (at least) an element; we'll need | |
9152 // to do a splice. Find tail of suffix so we can prepend suffix to global | |
9153 // list. | |
9154 for (cur = suffix_head; cur->mark() != NULL; cur = (oop)(cur->mark())); | |
9155 oop suffix_tail = cur; | |
9156 assert(suffix_tail != NULL && suffix_tail->mark() == NULL, | |
9157 "Tautology"); | |
9158 observed_overflow_list = _overflow_list; | |
9159 do { | |
9160 cur_overflow_list = observed_overflow_list; | |
9161 if (cur_overflow_list != BUSY) { | |
9162 // Do the splice ... | |
9163 suffix_tail->set_mark(markOop(cur_overflow_list)); | |
9164 } else { // cur_overflow_list == BUSY | |
9165 suffix_tail->set_mark(NULL); | |
9166 } | |
9167 // ... and try to place spliced list back on overflow_list ... | |
9168 observed_overflow_list = | |
9169 (oop) Atomic::cmpxchg_ptr(suffix_head, &_overflow_list, cur_overflow_list); | |
9170 } while (cur_overflow_list != observed_overflow_list); | |
9171 // ... until we have succeeded in doing so. | |
9172 } | |
0 | 9173 } |
9174 | |
9175 // Push the prefix elements on work_q | |
9176 assert(prefix != NULL, "control point invariant"); | |
9177 const markOop proto = markOopDesc::prototype(); | |
9178 oop next; | |
534 | 9179 NOT_PRODUCT(ssize_t n = 0;) |
0 | 9180 for (cur = prefix; cur != NULL; cur = next) { |
9181 next = oop(cur->mark()); | |
9182 cur->set_mark(proto); // until proven otherwise | |
9183 assert(cur->is_oop(), "Should be an oop"); | |
9184 bool res = work_q->push(cur); | |
9185 assert(res, "Bit off more than we can chew?"); | |
9186 NOT_PRODUCT(n++;) | |
9187 } | |
9188 #ifndef PRODUCT | |
9189 assert(_num_par_pushes >= n, "Too many pops?"); | |
9190 Atomic::add_ptr(-(intptr_t)n, &_num_par_pushes); | |
9191 #endif | |
9192 return true; | |
9193 } | |
9194 | |
9195 // Single-threaded | |
9196 void CMSCollector::push_on_overflow_list(oop p) { | |
9197 NOT_PRODUCT(_num_par_pushes++;) | |
9198 assert(p->is_oop(), "Not an oop"); | |
9199 preserve_mark_if_necessary(p); | |
9200 p->set_mark((markOop)_overflow_list); | |
9201 _overflow_list = p; | |
9202 } | |
9203 | |
9204 // Multi-threaded; use CAS to prepend to overflow list | |
9205 void CMSCollector::par_push_on_overflow_list(oop p) { | |
9206 NOT_PRODUCT(Atomic::inc_ptr(&_num_par_pushes);) | |
9207 assert(p->is_oop(), "Not an oop"); | |
9208 par_preserve_mark_if_necessary(p); | |
9209 oop observed_overflow_list = _overflow_list; | |
9210 oop cur_overflow_list; | |
9211 do { | |
9212 cur_overflow_list = observed_overflow_list; | |
534 | 9213 if (cur_overflow_list != BUSY) { |
9214 p->set_mark(markOop(cur_overflow_list)); | |
9215 } else { | |
9216 p->set_mark(NULL); | |
9217 } | |
0 | 9218 observed_overflow_list = |
9219 (oop) Atomic::cmpxchg_ptr(p, &_overflow_list, cur_overflow_list); | |
9220 } while (cur_overflow_list != observed_overflow_list); | |
9221 } | |
534 | 9222 #undef BUSY |
0 | 9223 |
9224 // Single threaded | |
9225 // General Note on GrowableArray: pushes may silently fail | |
9226 // because we are (temporarily) out of C-heap for expanding | |
9227 // the stack. The problem is quite ubiquitous and affects | |
9228 // a lot of code in the JVM. The prudent thing for GrowableArray | |
9229 // to do (for now) is to exit with an error. However, that may | |
9230 // be too draconian in some cases because the caller may be | |
534 | 9231 // able to recover without much harm. For such cases, we |
0 | 9232 // should probably introduce a "soft_push" method which returns |
9233 // an indication of success or failure with the assumption that | |
9234 // the caller may be able to recover from a failure; code in | |
9235 // the VM can then be changed, incrementally, to deal with such | |
9236 // failures where possible, thus, incrementally hardening the VM | |
9237 // in such low resource situations. | |
9238 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
|
9239 _preserved_oop_stack.push(p); |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9240 _preserved_mark_stack.push(m); |
0 | 9241 assert(m == p->mark(), "Mark word changed"); |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9242 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
0 | 9243 "bijection"); |
9244 } | |
9245 | |
9246 // Single threaded | |
9247 void CMSCollector::preserve_mark_if_necessary(oop p) { | |
9248 markOop m = p->mark(); | |
9249 if (m->must_be_preserved(p)) { | |
9250 preserve_mark_work(p, m); | |
9251 } | |
9252 } | |
9253 | |
9254 void CMSCollector::par_preserve_mark_if_necessary(oop p) { | |
9255 markOop m = p->mark(); | |
9256 if (m->must_be_preserved(p)) { | |
9257 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
9258 // Even though we read the mark word without holding | |
9259 // the lock, we are assured that it will not change | |
9260 // because we "own" this oop, so no other thread can | |
9261 // be trying to push it on the overflow list; see | |
9262 // the assertion in preserve_mark_work() that checks | |
9263 // that m == p->mark(). | |
9264 preserve_mark_work(p, m); | |
9265 } | |
9266 } | |
9267 | |
9268 // We should be able to do this multi-threaded, | |
9269 // a chunk of stack being a task (this is | |
9270 // correct because each oop only ever appears | |
9271 // once in the overflow list. However, it's | |
9272 // not very easy to completely overlap this with | |
9273 // other operations, so will generally not be done | |
9274 // until all work's been completed. Because we | |
9275 // expect the preserved oop stack (set) to be small, | |
9276 // it's probably fine to do this single-threaded. | |
9277 // We can explore cleverer concurrent/overlapped/parallel | |
9278 // processing of preserved marks if we feel the | |
9279 // need for this in the future. Stack overflow should | |
9280 // be so rare in practice and, when it happens, its | |
9281 // effect on performance so great that this will | |
9282 // likely just be in the noise anyway. | |
9283 void CMSCollector::restore_preserved_marks_if_any() { | |
9284 assert(SafepointSynchronize::is_at_safepoint(), | |
9285 "world should be stopped"); | |
9286 assert(Thread::current()->is_ConcurrentGC_thread() || | |
9287 Thread::current()->is_VM_thread(), | |
9288 "should be single-threaded"); | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9289 assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9290 "bijection"); |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9291 |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9292 while (!_preserved_oop_stack.is_empty()) { |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9293 oop p = _preserved_oop_stack.pop(); |
0 | 9294 assert(p->is_oop(), "Should be an oop"); |
9295 assert(_span.contains(p), "oop should be in _span"); | |
9296 assert(p->mark() == markOopDesc::prototype(), | |
9297 "Set when taken from overflow list"); | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9298 markOop m = _preserved_mark_stack.pop(); |
0 | 9299 p->set_mark(m); |
9300 } | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9301 assert(_preserved_mark_stack.is_empty() && _preserved_oop_stack.is_empty(), |
0 | 9302 "stacks were cleared above"); |
9303 } | |
9304 | |
9305 #ifndef PRODUCT | |
9306 bool CMSCollector::no_preserved_marks() const { | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1833
diff
changeset
|
9307 return _preserved_mark_stack.is_empty() && _preserved_oop_stack.is_empty(); |
0 | 9308 } |
9309 #endif | |
9310 | |
9311 CMSAdaptiveSizePolicy* ASConcurrentMarkSweepGeneration::cms_size_policy() const | |
9312 { | |
9313 GenCollectedHeap* gch = (GenCollectedHeap*) GenCollectedHeap::heap(); | |
9314 CMSAdaptiveSizePolicy* size_policy = | |
9315 (CMSAdaptiveSizePolicy*) gch->gen_policy()->size_policy(); | |
9316 assert(size_policy->is_gc_cms_adaptive_size_policy(), | |
9317 "Wrong type for size policy"); | |
9318 return size_policy; | |
9319 } | |
9320 | |
9321 void ASConcurrentMarkSweepGeneration::resize(size_t cur_promo_size, | |
9322 size_t desired_promo_size) { | |
9323 if (cur_promo_size < desired_promo_size) { | |
9324 size_t expand_bytes = desired_promo_size - cur_promo_size; | |
9325 if (PrintAdaptiveSizePolicy && Verbose) { | |
9326 gclog_or_tty->print_cr(" ASConcurrentMarkSweepGeneration::resize " | |
9327 "Expanding tenured generation by " SIZE_FORMAT " (bytes)", | |
9328 expand_bytes); | |
9329 } | |
9330 expand(expand_bytes, | |
9331 MinHeapDeltaBytes, | |
9332 CMSExpansionCause::_adaptive_size_policy); | |
9333 } else if (desired_promo_size < cur_promo_size) { | |
9334 size_t shrink_bytes = cur_promo_size - desired_promo_size; | |
9335 if (PrintAdaptiveSizePolicy && Verbose) { | |
9336 gclog_or_tty->print_cr(" ASConcurrentMarkSweepGeneration::resize " | |
9337 "Shrinking tenured generation by " SIZE_FORMAT " (bytes)", | |
9338 shrink_bytes); | |
9339 } | |
9340 shrink(shrink_bytes); | |
9341 } | |
9342 } | |
9343 | |
9344 CMSGCAdaptivePolicyCounters* ASConcurrentMarkSweepGeneration::gc_adaptive_policy_counters() { | |
9345 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9346 CMSGCAdaptivePolicyCounters* counters = | |
9347 (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters(); | |
9348 assert(counters->kind() == GCPolicyCounters::CMSGCAdaptivePolicyCountersKind, | |
9349 "Wrong kind of counters"); | |
9350 return counters; | |
9351 } | |
9352 | |
9353 | |
9354 void ASConcurrentMarkSweepGeneration::update_counters() { | |
9355 if (UsePerfData) { | |
9356 _space_counters->update_all(); | |
9357 _gen_counters->update_all(); | |
9358 CMSGCAdaptivePolicyCounters* counters = gc_adaptive_policy_counters(); | |
9359 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9360 CMSGCStats* gc_stats_l = (CMSGCStats*) gc_stats(); | |
9361 assert(gc_stats_l->kind() == GCStats::CMSGCStatsKind, | |
9362 "Wrong gc statistics type"); | |
9363 counters->update_counters(gc_stats_l); | |
9364 } | |
9365 } | |
9366 | |
9367 void ASConcurrentMarkSweepGeneration::update_counters(size_t used) { | |
9368 if (UsePerfData) { | |
9369 _space_counters->update_used(used); | |
9370 _space_counters->update_capacity(); | |
9371 _gen_counters->update_all(); | |
9372 | |
9373 CMSGCAdaptivePolicyCounters* counters = gc_adaptive_policy_counters(); | |
9374 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
9375 CMSGCStats* gc_stats_l = (CMSGCStats*) gc_stats(); | |
9376 assert(gc_stats_l->kind() == GCStats::CMSGCStatsKind, | |
9377 "Wrong gc statistics type"); | |
9378 counters->update_counters(gc_stats_l); | |
9379 } | |
9380 } | |
9381 | |
9382 void ASConcurrentMarkSweepGeneration::shrink_by(size_t desired_bytes) { | |
9383 assert_locked_or_safepoint(Heap_lock); | |
9384 assert_lock_strong(freelistLock()); | |
9385 HeapWord* old_end = _cmsSpace->end(); | |
9386 HeapWord* unallocated_start = _cmsSpace->unallocated_block(); | |
9387 assert(old_end >= unallocated_start, "Miscalculation of unallocated_start"); | |
9388 FreeChunk* chunk_at_end = find_chunk_at_end(); | |
9389 if (chunk_at_end == NULL) { | |
9390 // No room to shrink | |
9391 if (PrintGCDetails && Verbose) { | |
9392 gclog_or_tty->print_cr("No room to shrink: old_end " | |
9393 PTR_FORMAT " unallocated_start " PTR_FORMAT | |
9394 " chunk_at_end " PTR_FORMAT, | |
9395 old_end, unallocated_start, chunk_at_end); | |
9396 } | |
9397 return; | |
9398 } else { | |
9399 | |
9400 // Find the chunk at the end of the space and determine | |
9401 // how much it can be shrunk. | |
9402 size_t shrinkable_size_in_bytes = chunk_at_end->size(); | |
9403 size_t aligned_shrinkable_size_in_bytes = | |
9404 align_size_down(shrinkable_size_in_bytes, os::vm_page_size()); | |
6885 | 9405 assert(unallocated_start <= (HeapWord*) chunk_at_end->end(), |
0 | 9406 "Inconsistent chunk at end of space"); |
9407 size_t bytes = MIN2(desired_bytes, aligned_shrinkable_size_in_bytes); | |
9408 size_t word_size_before = heap_word_size(_virtual_space.committed_size()); | |
9409 | |
9410 // Shrink the underlying space | |
9411 _virtual_space.shrink_by(bytes); | |
9412 if (PrintGCDetails && Verbose) { | |
9413 gclog_or_tty->print_cr("ConcurrentMarkSweepGeneration::shrink_by:" | |
9414 " desired_bytes " SIZE_FORMAT | |
9415 " shrinkable_size_in_bytes " SIZE_FORMAT | |
9416 " aligned_shrinkable_size_in_bytes " SIZE_FORMAT | |
9417 " bytes " SIZE_FORMAT, | |
9418 desired_bytes, shrinkable_size_in_bytes, | |
9419 aligned_shrinkable_size_in_bytes, bytes); | |
9420 gclog_or_tty->print_cr(" old_end " SIZE_FORMAT | |
9421 " unallocated_start " SIZE_FORMAT, | |
9422 old_end, unallocated_start); | |
9423 } | |
9424 | |
9425 // If the space did shrink (shrinking is not guaranteed), | |
9426 // shrink the chunk at the end by the appropriate amount. | |
9427 if (((HeapWord*)_virtual_space.high()) < old_end) { | |
9428 size_t new_word_size = | |
9429 heap_word_size(_virtual_space.committed_size()); | |
9430 | |
9431 // Have to remove the chunk from the dictionary because it is changing | |
9432 // size and might be someplace elsewhere in the dictionary. | |
9433 | |
9434 // Get the chunk at end, shrink it, and put it | |
9435 // back. | |
9436 _cmsSpace->removeChunkFromDictionary(chunk_at_end); | |
9437 size_t word_size_change = word_size_before - new_word_size; | |
9438 size_t chunk_at_end_old_size = chunk_at_end->size(); | |
9439 assert(chunk_at_end_old_size >= word_size_change, | |
9440 "Shrink is too large"); | |
6028
f69a5d43dc19
7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents:
6026
diff
changeset
|
9441 chunk_at_end->set_size(chunk_at_end_old_size - |
0 | 9442 word_size_change); |
9443 _cmsSpace->freed((HeapWord*) chunk_at_end->end(), | |
9444 word_size_change); | |
9445 | |
9446 _cmsSpace->returnChunkToDictionary(chunk_at_end); | |
9447 | |
9448 MemRegion mr(_cmsSpace->bottom(), new_word_size); | |
9449 _bts->resize(new_word_size); // resize the block offset shared array | |
9450 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
9451 _cmsSpace->assert_locked(); | |
9452 _cmsSpace->set_end((HeapWord*)_virtual_space.high()); | |
9453 | |
9454 NOT_PRODUCT(_cmsSpace->dictionary()->verify()); | |
9455 | |
9456 // update the space and generation capacity counters | |
9457 if (UsePerfData) { | |
9458 _space_counters->update_capacity(); | |
9459 _gen_counters->update_all(); | |
9460 } | |
9461 | |
9462 if (Verbose && PrintGCDetails) { | |
9463 size_t new_mem_size = _virtual_space.committed_size(); | |
9464 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
|
9465 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K", |
0 | 9466 name(), old_mem_size/K, bytes/K, new_mem_size/K); |
9467 } | |
9468 } | |
9469 | |
9470 assert(_cmsSpace->unallocated_block() <= _cmsSpace->end(), | |
9471 "Inconsistency at end of space"); | |
6885 | 9472 assert(chunk_at_end->end() == (uintptr_t*) _cmsSpace->end(), |
0 | 9473 "Shrinking is inconsistent"); |
9474 return; | |
9475 } | |
9476 } | |
9477 // Transfer some number of overflown objects to usual marking | |
9478 // stack. Return true if some objects were transferred. | |
9479 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
|
9480 size_t num = MIN2((size_t)(_mark_stack->capacity() - _mark_stack->length())/4, |
0 | 9481 (size_t)ParGCDesiredObjsFromOverflowList); |
9482 | |
9483 bool res = _collector->take_from_overflow_list(num, _mark_stack); | |
9484 assert(_collector->overflow_list_is_empty() || res, | |
9485 "If list is not empty, we should have taken something"); | |
9486 assert(!res || !_mark_stack->isEmpty(), | |
9487 "If we took something, it should now be on our stack"); | |
9488 return res; | |
9489 } | |
9490 | |
9491 size_t MarkDeadObjectsClosure::do_blk(HeapWord* addr) { | |
9492 size_t res = _sp->block_size_no_stall(addr, _collector); | |
9493 if (_sp->block_is_obj(addr)) { | |
9494 if (_live_bit_map->isMarked(addr)) { | |
9495 // It can't have been dead in a previous cycle | |
9496 guarantee(!_dead_bit_map->isMarked(addr), "No resurrection!"); | |
9497 } else { | |
9498 _dead_bit_map->mark(addr); // mark the dead object | |
9499 } | |
9500 } | |
2226
c5a923563727
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
2177
diff
changeset
|
9501 // Could be 0, if the block size could not be computed without stalling. |
0 | 9502 return res; |
9503 } | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9504 |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9505 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
|
9506 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9507 switch (phase) { |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9508 case CMSCollector::InitialMarking: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9509 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9510 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
|
9511 true /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9512 true /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9513 false /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9514 false /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9515 true /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9516 false /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9517 false /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9518 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9519 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9520 case CMSCollector::FinalMarking: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9521 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9522 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
|
9523 false /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9524 false /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9525 false /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9526 false /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9527 true /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9528 false /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9529 false /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9530 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9531 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9532 case CMSCollector::Sweeping: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9533 initialize(true /* fullGC */ , |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
3293
diff
changeset
|
9534 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
|
9535 false /* recordGCBeginTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9536 false /* recordPreGCUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9537 true /* recordPeakUsage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9538 true /* recordPostGCusage */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9539 false /* recordAccumulatedGCTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9540 true /* recordGCEndTime */, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9541 true /* countCollection */ ); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9542 break; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9543 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9544 default: |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9545 ShouldNotReachHere(); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9546 } |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1579
diff
changeset
|
9547 } |